]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.7.8-201302161158.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.7.8-201302161158.patch
CommitLineData
fdf040b6
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 74c25c8..deadba2 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@@ -162,14 +180,15 @@ mach-types.h
131 machtypes.h
132 map
133 map_hugetlb
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@@ -186,6 +205,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@@ -195,6 +216,7 @@ perf-archive
157 piggyback
158 piggy.gzip
159 piggy.S
160+pmu-*
161 pnmtologo
162 ppc_defs.h*
163 pss_boot.h
164@@ -204,7 +226,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@@ -214,8 +239,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@@ -225,6 +253,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@@ -236,13 +265,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@@ -250,9 +283,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 9776f06..18b1856 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@@ -2082,6 +2085,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 ad48987..d808c2d 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@@ -414,8 +415,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@@ -575,6 +576,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@@ -731,7 +786,7 @@ export mod_sign_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@@ -778,6 +833,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@@ -787,7 +844,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@@ -831,6 +888,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@@ -938,6 +996,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@@ -953,7 +1013,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@@ -1013,7 +1073,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
395 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
396 signing_key.priv signing_key.x509 x509.genkey \
397 extra_certificates signing_key.x509.keyid \
398- signing_key.x509.signer
399+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
400
401 # clean - Delete most, but leave enough to build external modules
402 #
403@@ -1053,6 +1113,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@@ -1213,6 +1274,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@@ -1349,17 +1412,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@@ -1369,11 +1436,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 14db93e..47bed62 100644
583--- a/arch/alpha/kernel/osf_sys.c
584+++ b/arch/alpha/kernel/osf_sys.c
585@@ -1295,16 +1295,16 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
586 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
587
588 static unsigned long
589-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
590- unsigned long limit)
591+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
592+ unsigned long limit, unsigned long flags)
593 {
594 struct vm_area_struct *vma = find_vma(current->mm, addr);
595-
596+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
597 while (1) {
598 /* At this point: (!vma || addr < vma->vm_end). */
599 if (limit - len < addr)
600 return -ENOMEM;
601- if (!vma || addr + len <= vma->vm_start)
602+ if (check_heap_stack_gap(vma, addr, len, offset))
603 return addr;
604 addr = vma->vm_end;
605 vma = vma->vm_next;
606@@ -1340,20 +1340,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
607 merely specific addresses, but regions of memory -- perhaps
608 this feature should be incorporated into all ports? */
609
610+#ifdef CONFIG_PAX_RANDMMAP
611+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
612+#endif
613+
614 if (addr) {
615- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
616+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
617 if (addr != (unsigned long) -ENOMEM)
618 return addr;
619 }
620
621 /* Next, try allocating at TASK_UNMAPPED_BASE. */
622- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
623- len, limit);
624+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
625+
626 if (addr != (unsigned long) -ENOMEM)
627 return addr;
628
629 /* Finally, try allocating in low memory. */
630- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
631+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
632
633 return addr;
634 }
635diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
636index 0c4132d..88f0d53 100644
637--- a/arch/alpha/mm/fault.c
638+++ b/arch/alpha/mm/fault.c
639@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
640 __reload_thread(pcb);
641 }
642
643+#ifdef CONFIG_PAX_PAGEEXEC
644+/*
645+ * PaX: decide what to do with offenders (regs->pc = fault address)
646+ *
647+ * returns 1 when task should be killed
648+ * 2 when patched PLT trampoline was detected
649+ * 3 when unpatched PLT trampoline was detected
650+ */
651+static int pax_handle_fetch_fault(struct pt_regs *regs)
652+{
653+
654+#ifdef CONFIG_PAX_EMUPLT
655+ int err;
656+
657+ do { /* PaX: patched PLT emulation #1 */
658+ unsigned int ldah, ldq, jmp;
659+
660+ err = get_user(ldah, (unsigned int *)regs->pc);
661+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
662+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
663+
664+ if (err)
665+ break;
666+
667+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
668+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
669+ jmp == 0x6BFB0000U)
670+ {
671+ unsigned long r27, addr;
672+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
673+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
674+
675+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
676+ err = get_user(r27, (unsigned long *)addr);
677+ if (err)
678+ break;
679+
680+ regs->r27 = r27;
681+ regs->pc = r27;
682+ return 2;
683+ }
684+ } while (0);
685+
686+ do { /* PaX: patched PLT emulation #2 */
687+ unsigned int ldah, lda, br;
688+
689+ err = get_user(ldah, (unsigned int *)regs->pc);
690+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
691+ err |= get_user(br, (unsigned int *)(regs->pc+8));
692+
693+ if (err)
694+ break;
695+
696+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
697+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
698+ (br & 0xFFE00000U) == 0xC3E00000U)
699+ {
700+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
701+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
702+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
703+
704+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
705+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
706+ return 2;
707+ }
708+ } while (0);
709+
710+ do { /* PaX: unpatched PLT emulation */
711+ unsigned int br;
712+
713+ err = get_user(br, (unsigned int *)regs->pc);
714+
715+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
716+ unsigned int br2, ldq, nop, jmp;
717+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
718+
719+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
720+ err = get_user(br2, (unsigned int *)addr);
721+ err |= get_user(ldq, (unsigned int *)(addr+4));
722+ err |= get_user(nop, (unsigned int *)(addr+8));
723+ err |= get_user(jmp, (unsigned int *)(addr+12));
724+ err |= get_user(resolver, (unsigned long *)(addr+16));
725+
726+ if (err)
727+ break;
728+
729+ if (br2 == 0xC3600000U &&
730+ ldq == 0xA77B000CU &&
731+ nop == 0x47FF041FU &&
732+ jmp == 0x6B7B0000U)
733+ {
734+ regs->r28 = regs->pc+4;
735+ regs->r27 = addr+16;
736+ regs->pc = resolver;
737+ return 3;
738+ }
739+ }
740+ } while (0);
741+#endif
742+
743+ return 1;
744+}
745+
746+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
747+{
748+ unsigned long i;
749+
750+ printk(KERN_ERR "PAX: bytes at PC: ");
751+ for (i = 0; i < 5; i++) {
752+ unsigned int c;
753+ if (get_user(c, (unsigned int *)pc+i))
754+ printk(KERN_CONT "???????? ");
755+ else
756+ printk(KERN_CONT "%08x ", c);
757+ }
758+ printk("\n");
759+}
760+#endif
761
762 /*
763 * This routine handles page faults. It determines the address,
764@@ -133,8 +251,29 @@ retry:
765 good_area:
766 si_code = SEGV_ACCERR;
767 if (cause < 0) {
768- if (!(vma->vm_flags & VM_EXEC))
769+ if (!(vma->vm_flags & VM_EXEC)) {
770+
771+#ifdef CONFIG_PAX_PAGEEXEC
772+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
773+ goto bad_area;
774+
775+ up_read(&mm->mmap_sem);
776+ switch (pax_handle_fetch_fault(regs)) {
777+
778+#ifdef CONFIG_PAX_EMUPLT
779+ case 2:
780+ case 3:
781+ return;
782+#endif
783+
784+ }
785+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
786+ do_group_exit(SIGKILL);
787+#else
788 goto bad_area;
789+#endif
790+
791+ }
792 } else if (!cause) {
793 /* Allow reads even for write-only mappings */
794 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
795diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
796index c79f61f..9ac0642 100644
797--- a/arch/arm/include/asm/atomic.h
798+++ b/arch/arm/include/asm/atomic.h
799@@ -17,17 +17,35 @@
800 #include <asm/barrier.h>
801 #include <asm/cmpxchg.h>
802
803+#ifdef CONFIG_GENERIC_ATOMIC64
804+#include <asm-generic/atomic64.h>
805+#endif
806+
807 #define ATOMIC_INIT(i) { (i) }
808
809 #ifdef __KERNEL__
810
811+#define _ASM_EXTABLE(from, to) \
812+" .pushsection __ex_table,\"a\"\n"\
813+" .align 3\n" \
814+" .long " #from ", " #to"\n" \
815+" .popsection"
816+
817 /*
818 * On ARM, ordinary assignment (str instruction) doesn't clear the local
819 * strex/ldrex monitor on some implementations. The reason we can use it for
820 * atomic_set() is the clrex or dummy strex done on every exception return.
821 */
822 #define atomic_read(v) (*(volatile int *)&(v)->counter)
823+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
824+{
825+ return v->counter;
826+}
827 #define atomic_set(v,i) (((v)->counter) = (i))
828+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
829+{
830+ v->counter = i;
831+}
832
833 #if __LINUX_ARM_ARCH__ >= 6
834
835@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
836 int result;
837
838 __asm__ __volatile__("@ atomic_add\n"
839+"1: ldrex %1, [%3]\n"
840+" adds %0, %1, %4\n"
841+
842+#ifdef CONFIG_PAX_REFCOUNT
843+" bvc 3f\n"
844+"2: bkpt 0xf103\n"
845+"3:\n"
846+#endif
847+
848+" strex %1, %0, [%3]\n"
849+" teq %1, #0\n"
850+" bne 1b"
851+
852+#ifdef CONFIG_PAX_REFCOUNT
853+"\n4:\n"
854+ _ASM_EXTABLE(2b, 4b)
855+#endif
856+
857+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
858+ : "r" (&v->counter), "Ir" (i)
859+ : "cc");
860+}
861+
862+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
863+{
864+ unsigned long tmp;
865+ int result;
866+
867+ __asm__ __volatile__("@ atomic_add_unchecked\n"
868 "1: ldrex %0, [%3]\n"
869 " add %0, %0, %4\n"
870 " strex %1, %0, [%3]\n"
871@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
872 smp_mb();
873
874 __asm__ __volatile__("@ atomic_add_return\n"
875+"1: ldrex %1, [%3]\n"
876+" adds %0, %1, %4\n"
877+
878+#ifdef CONFIG_PAX_REFCOUNT
879+" bvc 3f\n"
880+" mov %0, %1\n"
881+"2: bkpt 0xf103\n"
882+"3:\n"
883+#endif
884+
885+" strex %1, %0, [%3]\n"
886+" teq %1, #0\n"
887+" bne 1b"
888+
889+#ifdef CONFIG_PAX_REFCOUNT
890+"\n4:\n"
891+ _ASM_EXTABLE(2b, 4b)
892+#endif
893+
894+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
895+ : "r" (&v->counter), "Ir" (i)
896+ : "cc");
897+
898+ smp_mb();
899+
900+ return result;
901+}
902+
903+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
904+{
905+ unsigned long tmp;
906+ int result;
907+
908+ smp_mb();
909+
910+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
911 "1: ldrex %0, [%3]\n"
912 " add %0, %0, %4\n"
913 " strex %1, %0, [%3]\n"
914@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
915 int result;
916
917 __asm__ __volatile__("@ atomic_sub\n"
918+"1: ldrex %1, [%3]\n"
919+" subs %0, %1, %4\n"
920+
921+#ifdef CONFIG_PAX_REFCOUNT
922+" bvc 3f\n"
923+"2: bkpt 0xf103\n"
924+"3:\n"
925+#endif
926+
927+" strex %1, %0, [%3]\n"
928+" teq %1, #0\n"
929+" bne 1b"
930+
931+#ifdef CONFIG_PAX_REFCOUNT
932+"\n4:\n"
933+ _ASM_EXTABLE(2b, 4b)
934+#endif
935+
936+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937+ : "r" (&v->counter), "Ir" (i)
938+ : "cc");
939+}
940+
941+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
942+{
943+ unsigned long tmp;
944+ int result;
945+
946+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
947 "1: ldrex %0, [%3]\n"
948 " sub %0, %0, %4\n"
949 " strex %1, %0, [%3]\n"
950@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
951 smp_mb();
952
953 __asm__ __volatile__("@ atomic_sub_return\n"
954-"1: ldrex %0, [%3]\n"
955-" sub %0, %0, %4\n"
956+"1: ldrex %1, [%3]\n"
957+" subs %0, %1, %4\n"
958+
959+#ifdef CONFIG_PAX_REFCOUNT
960+" bvc 3f\n"
961+" mov %0, %1\n"
962+"2: bkpt 0xf103\n"
963+"3:\n"
964+#endif
965+
966 " strex %1, %0, [%3]\n"
967 " teq %1, #0\n"
968 " bne 1b"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+"\n4:\n"
972+ _ASM_EXTABLE(2b, 4b)
973+#endif
974+
975 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
976 : "r" (&v->counter), "Ir" (i)
977 : "cc");
978@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
979 return oldval;
980 }
981
982+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
983+{
984+ unsigned long oldval, res;
985+
986+ smp_mb();
987+
988+ do {
989+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
990+ "ldrex %1, [%3]\n"
991+ "mov %0, #0\n"
992+ "teq %1, %4\n"
993+ "strexeq %0, %5, [%3]\n"
994+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
995+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
996+ : "cc");
997+ } while (res);
998+
999+ smp_mb();
1000+
1001+ return oldval;
1002+}
1003+
1004 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1005 {
1006 unsigned long tmp, tmp2;
1007@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1008
1009 return val;
1010 }
1011+
1012+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1013+{
1014+ return atomic_add_return(i, v);
1015+}
1016+
1017 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1018+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1019+{
1020+ (void) atomic_add_return(i, v);
1021+}
1022
1023 static inline int atomic_sub_return(int i, atomic_t *v)
1024 {
1025@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1026 return val;
1027 }
1028 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1029+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1030+{
1031+ (void) atomic_sub_return(i, v);
1032+}
1033
1034 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1035 {
1036@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1037 return ret;
1038 }
1039
1040+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1041+{
1042+ return atomic_cmpxchg(v, old, new);
1043+}
1044+
1045 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1046 {
1047 unsigned long flags;
1048@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1049 #endif /* __LINUX_ARM_ARCH__ */
1050
1051 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1052+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1053+{
1054+ return xchg(&v->counter, new);
1055+}
1056
1057 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1058 {
1059@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1060 }
1061
1062 #define atomic_inc(v) atomic_add(1, v)
1063+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1064+{
1065+ atomic_add_unchecked(1, v);
1066+}
1067 #define atomic_dec(v) atomic_sub(1, v)
1068+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1069+{
1070+ atomic_sub_unchecked(1, v);
1071+}
1072
1073 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1074+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1075+{
1076+ return atomic_add_return_unchecked(1, v) == 0;
1077+}
1078 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1079 #define atomic_inc_return(v) (atomic_add_return(1, v))
1080+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1081+{
1082+ return atomic_add_return_unchecked(1, v);
1083+}
1084 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1085 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1086
1087@@ -241,6 +428,14 @@ typedef struct {
1088 u64 __aligned(8) counter;
1089 } atomic64_t;
1090
1091+#ifdef CONFIG_PAX_REFCOUNT
1092+typedef struct {
1093+ u64 __aligned(8) counter;
1094+} atomic64_unchecked_t;
1095+#else
1096+typedef atomic64_t atomic64_unchecked_t;
1097+#endif
1098+
1099 #define ATOMIC64_INIT(i) { (i) }
1100
1101 static inline u64 atomic64_read(const atomic64_t *v)
1102@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1103 return result;
1104 }
1105
1106+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1107+{
1108+ u64 result;
1109+
1110+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1111+" ldrexd %0, %H0, [%1]"
1112+ : "=&r" (result)
1113+ : "r" (&v->counter), "Qo" (v->counter)
1114+ );
1115+
1116+ return result;
1117+}
1118+
1119 static inline void atomic64_set(atomic64_t *v, u64 i)
1120 {
1121 u64 tmp;
1122@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1123 : "cc");
1124 }
1125
1126+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1127+{
1128+ u64 tmp;
1129+
1130+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1131+"1: ldrexd %0, %H0, [%2]\n"
1132+" strexd %0, %3, %H3, [%2]\n"
1133+" teq %0, #0\n"
1134+" bne 1b"
1135+ : "=&r" (tmp), "=Qo" (v->counter)
1136+ : "r" (&v->counter), "r" (i)
1137+ : "cc");
1138+}
1139+
1140 static inline void atomic64_add(u64 i, atomic64_t *v)
1141 {
1142 u64 result;
1143@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1144 __asm__ __volatile__("@ atomic64_add\n"
1145 "1: ldrexd %0, %H0, [%3]\n"
1146 " adds %0, %0, %4\n"
1147+" adcs %H0, %H0, %H4\n"
1148+
1149+#ifdef CONFIG_PAX_REFCOUNT
1150+" bvc 3f\n"
1151+"2: bkpt 0xf103\n"
1152+"3:\n"
1153+#endif
1154+
1155+" strexd %1, %0, %H0, [%3]\n"
1156+" teq %1, #0\n"
1157+" bne 1b"
1158+
1159+#ifdef CONFIG_PAX_REFCOUNT
1160+"\n4:\n"
1161+ _ASM_EXTABLE(2b, 4b)
1162+#endif
1163+
1164+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1165+ : "r" (&v->counter), "r" (i)
1166+ : "cc");
1167+}
1168+
1169+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1170+{
1171+ u64 result;
1172+ unsigned long tmp;
1173+
1174+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1175+"1: ldrexd %0, %H0, [%3]\n"
1176+" adds %0, %0, %4\n"
1177 " adc %H0, %H0, %H4\n"
1178 " strexd %1, %0, %H0, [%3]\n"
1179 " teq %1, #0\n"
1180@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1181
1182 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1183 {
1184- u64 result;
1185- unsigned long tmp;
1186+ u64 result, tmp;
1187
1188 smp_mb();
1189
1190 __asm__ __volatile__("@ atomic64_add_return\n"
1191+"1: ldrexd %1, %H1, [%3]\n"
1192+" adds %0, %1, %4\n"
1193+" adcs %H0, %H1, %H4\n"
1194+
1195+#ifdef CONFIG_PAX_REFCOUNT
1196+" bvc 3f\n"
1197+" mov %0, %1\n"
1198+" mov %H0, %H1\n"
1199+"2: bkpt 0xf103\n"
1200+"3:\n"
1201+#endif
1202+
1203+" strexd %1, %0, %H0, [%3]\n"
1204+" teq %1, #0\n"
1205+" bne 1b"
1206+
1207+#ifdef CONFIG_PAX_REFCOUNT
1208+"\n4:\n"
1209+ _ASM_EXTABLE(2b, 4b)
1210+#endif
1211+
1212+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1213+ : "r" (&v->counter), "r" (i)
1214+ : "cc");
1215+
1216+ smp_mb();
1217+
1218+ return result;
1219+}
1220+
1221+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1222+{
1223+ u64 result;
1224+ unsigned long tmp;
1225+
1226+ smp_mb();
1227+
1228+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1229 "1: ldrexd %0, %H0, [%3]\n"
1230 " adds %0, %0, %4\n"
1231 " adc %H0, %H0, %H4\n"
1232@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1233 __asm__ __volatile__("@ atomic64_sub\n"
1234 "1: ldrexd %0, %H0, [%3]\n"
1235 " subs %0, %0, %4\n"
1236+" sbcs %H0, %H0, %H4\n"
1237+
1238+#ifdef CONFIG_PAX_REFCOUNT
1239+" bvc 3f\n"
1240+"2: bkpt 0xf103\n"
1241+"3:\n"
1242+#endif
1243+
1244+" strexd %1, %0, %H0, [%3]\n"
1245+" teq %1, #0\n"
1246+" bne 1b"
1247+
1248+#ifdef CONFIG_PAX_REFCOUNT
1249+"\n4:\n"
1250+ _ASM_EXTABLE(2b, 4b)
1251+#endif
1252+
1253+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1254+ : "r" (&v->counter), "r" (i)
1255+ : "cc");
1256+}
1257+
1258+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1259+{
1260+ u64 result;
1261+ unsigned long tmp;
1262+
1263+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1264+"1: ldrexd %0, %H0, [%3]\n"
1265+" subs %0, %0, %4\n"
1266 " sbc %H0, %H0, %H4\n"
1267 " strexd %1, %0, %H0, [%3]\n"
1268 " teq %1, #0\n"
1269@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1270
1271 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1272 {
1273- u64 result;
1274- unsigned long tmp;
1275+ u64 result, tmp;
1276
1277 smp_mb();
1278
1279 __asm__ __volatile__("@ atomic64_sub_return\n"
1280-"1: ldrexd %0, %H0, [%3]\n"
1281-" subs %0, %0, %4\n"
1282-" sbc %H0, %H0, %H4\n"
1283+"1: ldrexd %1, %H1, [%3]\n"
1284+" subs %0, %1, %4\n"
1285+" sbcs %H0, %H1, %H4\n"
1286+
1287+#ifdef CONFIG_PAX_REFCOUNT
1288+" bvc 3f\n"
1289+" mov %0, %1\n"
1290+" mov %H0, %H1\n"
1291+"2: bkpt 0xf103\n"
1292+"3:\n"
1293+#endif
1294+
1295 " strexd %1, %0, %H0, [%3]\n"
1296 " teq %1, #0\n"
1297 " bne 1b"
1298+
1299+#ifdef CONFIG_PAX_REFCOUNT
1300+"\n4:\n"
1301+ _ASM_EXTABLE(2b, 4b)
1302+#endif
1303+
1304 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1305 : "r" (&v->counter), "r" (i)
1306 : "cc");
1307@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1308 return oldval;
1309 }
1310
1311+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1312+{
1313+ u64 oldval;
1314+ unsigned long res;
1315+
1316+ smp_mb();
1317+
1318+ do {
1319+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1320+ "ldrexd %1, %H1, [%3]\n"
1321+ "mov %0, #0\n"
1322+ "teq %1, %4\n"
1323+ "teqeq %H1, %H4\n"
1324+ "strexdeq %0, %5, %H5, [%3]"
1325+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1326+ : "r" (&ptr->counter), "r" (old), "r" (new)
1327+ : "cc");
1328+ } while (res);
1329+
1330+ smp_mb();
1331+
1332+ return oldval;
1333+}
1334+
1335 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1336 {
1337 u64 result;
1338@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1339
1340 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1341 {
1342- u64 result;
1343- unsigned long tmp;
1344+ u64 result, tmp;
1345
1346 smp_mb();
1347
1348 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1349-"1: ldrexd %0, %H0, [%3]\n"
1350-" subs %0, %0, #1\n"
1351-" sbc %H0, %H0, #0\n"
1352+"1: ldrexd %1, %H1, [%3]\n"
1353+" subs %0, %1, #1\n"
1354+" sbcs %H0, %H1, #0\n"
1355+
1356+#ifdef CONFIG_PAX_REFCOUNT
1357+" bvc 3f\n"
1358+" mov %0, %1\n"
1359+" mov %H0, %H1\n"
1360+"2: bkpt 0xf103\n"
1361+"3:\n"
1362+#endif
1363+
1364 " teq %H0, #0\n"
1365-" bmi 2f\n"
1366+" bmi 4f\n"
1367 " strexd %1, %0, %H0, [%3]\n"
1368 " teq %1, #0\n"
1369 " bne 1b\n"
1370-"2:"
1371+"4:\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+ _ASM_EXTABLE(2b, 4b)
1375+#endif
1376+
1377 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1378 : "r" (&v->counter)
1379 : "cc");
1380@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1381 " teq %0, %5\n"
1382 " teqeq %H0, %H5\n"
1383 " moveq %1, #0\n"
1384-" beq 2f\n"
1385+" beq 4f\n"
1386 " adds %0, %0, %6\n"
1387-" adc %H0, %H0, %H6\n"
1388+" adcs %H0, %H0, %H6\n"
1389+
1390+#ifdef CONFIG_PAX_REFCOUNT
1391+" bvc 3f\n"
1392+"2: bkpt 0xf103\n"
1393+"3:\n"
1394+#endif
1395+
1396 " strexd %2, %0, %H0, [%4]\n"
1397 " teq %2, #0\n"
1398 " bne 1b\n"
1399-"2:"
1400+"4:\n"
1401+
1402+#ifdef CONFIG_PAX_REFCOUNT
1403+ _ASM_EXTABLE(2b, 4b)
1404+#endif
1405+
1406 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1407 : "r" (&v->counter), "r" (u), "r" (a)
1408 : "cc");
1409@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1410
1411 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1412 #define atomic64_inc(v) atomic64_add(1LL, (v))
1413+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1414 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1415+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1416 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1417 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1418 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1419+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1420 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1421 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1422 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1423diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1424index 75fe66b..ba3dee4 100644
1425--- a/arch/arm/include/asm/cache.h
1426+++ b/arch/arm/include/asm/cache.h
1427@@ -4,8 +4,10 @@
1428 #ifndef __ASMARM_CACHE_H
1429 #define __ASMARM_CACHE_H
1430
1431+#include <linux/const.h>
1432+
1433 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1434-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1435+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1436
1437 /*
1438 * Memory returned by kmalloc() may be used for DMA, so we must make
1439@@ -24,5 +26,6 @@
1440 #endif
1441
1442 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1443+#define __read_only __attribute__ ((__section__(".data..read_only")))
1444
1445 #endif
1446diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1447index e1489c5..d418304 100644
1448--- a/arch/arm/include/asm/cacheflush.h
1449+++ b/arch/arm/include/asm/cacheflush.h
1450@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1451 void (*dma_unmap_area)(const void *, size_t, int);
1452
1453 void (*dma_flush_range)(const void *, const void *);
1454-};
1455+} __no_const;
1456
1457 /*
1458 * Select the calling method
1459diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1460index 7eb18c1..e38b6d2 100644
1461--- a/arch/arm/include/asm/cmpxchg.h
1462+++ b/arch/arm/include/asm/cmpxchg.h
1463@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1464
1465 #define xchg(ptr,x) \
1466 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1467+#define xchg_unchecked(ptr,x) \
1468+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1469
1470 #include <asm-generic/cmpxchg-local.h>
1471
1472diff --git a/arch/arm/include/asm/delay.h b/arch/arm/include/asm/delay.h
1473index ab98fdd..6b19938 100644
1474--- a/arch/arm/include/asm/delay.h
1475+++ b/arch/arm/include/asm/delay.h
1476@@ -24,9 +24,9 @@ extern struct arm_delay_ops {
1477 void (*delay)(unsigned long);
1478 void (*const_udelay)(unsigned long);
1479 void (*udelay)(unsigned long);
1480-} arm_delay_ops;
1481+} *arm_delay_ops;
1482
1483-#define __delay(n) arm_delay_ops.delay(n)
1484+#define __delay(n) arm_delay_ops->delay(n)
1485
1486 /*
1487 * This function intentionally does not exist; if you see references to
1488@@ -47,8 +47,8 @@ extern void __bad_udelay(void);
1489 * first constant multiplications gets optimized away if the delay is
1490 * a constant)
1491 */
1492-#define __udelay(n) arm_delay_ops.udelay(n)
1493-#define __const_udelay(n) arm_delay_ops.const_udelay(n)
1494+#define __udelay(n) arm_delay_ops->udelay(n)
1495+#define __const_udelay(n) arm_delay_ops->const_udelay(n)
1496
1497 #define udelay(n) \
1498 (__builtin_constant_p(n) ? \
1499diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1500index 38050b1..9d90e8b 100644
1501--- a/arch/arm/include/asm/elf.h
1502+++ b/arch/arm/include/asm/elf.h
1503@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1504 the loader. We need to make sure that it is out of the way of the program
1505 that it will "exec", and that there is sufficient room for the brk. */
1506
1507-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1508+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1509+
1510+#ifdef CONFIG_PAX_ASLR
1511+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1512+
1513+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1514+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1515+#endif
1516
1517 /* When the program starts, a1 contains a pointer to a function to be
1518 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1519@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1520 extern void elf_set_personality(const struct elf32_hdr *);
1521 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1522
1523-struct mm_struct;
1524-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1525-#define arch_randomize_brk arch_randomize_brk
1526-
1527 #endif
1528diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1529index 83eb2f7..ed77159 100644
1530--- a/arch/arm/include/asm/kmap_types.h
1531+++ b/arch/arm/include/asm/kmap_types.h
1532@@ -4,6 +4,6 @@
1533 /*
1534 * This is the "bare minimum". AIO seems to require this.
1535 */
1536-#define KM_TYPE_NR 16
1537+#define KM_TYPE_NR 17
1538
1539 #endif
1540diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1541index 9e614a1..3302cca 100644
1542--- a/arch/arm/include/asm/mach/dma.h
1543+++ b/arch/arm/include/asm/mach/dma.h
1544@@ -22,7 +22,7 @@ struct dma_ops {
1545 int (*residue)(unsigned int, dma_t *); /* optional */
1546 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1547 const char *type;
1548-};
1549+} __do_const;
1550
1551 struct dma_struct {
1552 void *addr; /* single DMA address */
1553diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1554index 195ac2f..2272f0d 100644
1555--- a/arch/arm/include/asm/mach/map.h
1556+++ b/arch/arm/include/asm/mach/map.h
1557@@ -34,6 +34,9 @@ struct map_desc {
1558 #define MT_MEMORY_ITCM 13
1559 #define MT_MEMORY_SO 14
1560 #define MT_MEMORY_DMA_READY 15
1561+#define MT_MEMORY_R 16
1562+#define MT_MEMORY_RW 17
1563+#define MT_MEMORY_RX 18
1564
1565 #ifdef CONFIG_MMU
1566 extern void iotable_init(struct map_desc *, int);
1567diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1568index 53426c6..c7baff3 100644
1569--- a/arch/arm/include/asm/outercache.h
1570+++ b/arch/arm/include/asm/outercache.h
1571@@ -35,7 +35,7 @@ struct outer_cache_fns {
1572 #endif
1573 void (*set_debug)(unsigned long);
1574 void (*resume)(void);
1575-};
1576+} __no_const;
1577
1578 #ifdef CONFIG_OUTER_CACHE
1579
1580diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1581index 812a494..71fc0b6 100644
1582--- a/arch/arm/include/asm/page.h
1583+++ b/arch/arm/include/asm/page.h
1584@@ -114,7 +114,7 @@ struct cpu_user_fns {
1585 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1586 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1587 unsigned long vaddr, struct vm_area_struct *vma);
1588-};
1589+} __no_const;
1590
1591 #ifdef MULTI_USER
1592 extern struct cpu_user_fns cpu_user;
1593diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1594index 943504f..84d0f84 100644
1595--- a/arch/arm/include/asm/pgalloc.h
1596+++ b/arch/arm/include/asm/pgalloc.h
1597@@ -17,6 +17,7 @@
1598 #include <asm/processor.h>
1599 #include <asm/cacheflush.h>
1600 #include <asm/tlbflush.h>
1601+#include <asm/system_info.h>
1602
1603 #define check_pgt_cache() do { } while (0)
1604
1605@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1607 }
1608
1609+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1610+{
1611+ pud_populate(mm, pud, pmd);
1612+}
1613+
1614 #else /* !CONFIG_ARM_LPAE */
1615
1616 /*
1617@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1618 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1619 #define pmd_free(mm, pmd) do { } while (0)
1620 #define pud_populate(mm,pmd,pte) BUG()
1621+#define pud_populate_kernel(mm,pmd,pte) BUG()
1622
1623 #endif /* CONFIG_ARM_LPAE */
1624
1625@@ -126,6 +133,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1626 __free_page(pte);
1627 }
1628
1629+static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1630+{
1631+ pmdval_t pmdval = pmd_val(*pmdp) | prot;
1632+ pmdp[0] = __pmd(pmdval);
1633+#ifndef CONFIG_ARM_LPAE
1634+ pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1635+#endif
1636+ flush_pmd_entry(pmdp);
1637+}
1638+
1639 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1640 pmdval_t prot)
1641 {
1642@@ -155,7 +172,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1643 static inline void
1644 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1645 {
1646- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1647+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1648 }
1649 #define pmd_pgtable(pmd) pmd_page(pmd)
1650
1651diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1652index 5cfba15..d437dc2 100644
1653--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1654+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1655@@ -20,12 +20,15 @@
1656 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1657 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1658 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1659+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1660 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1661 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1662 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1663+
1664 /*
1665 * - section
1666 */
1667+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1668 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1669 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1670 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1671@@ -37,6 +40,7 @@
1672 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1673 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1674 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1675+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1676
1677 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1678 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1679diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1680index 2317a71..1897391 100644
1681--- a/arch/arm/include/asm/pgtable-2level.h
1682+++ b/arch/arm/include/asm/pgtable-2level.h
1683@@ -123,6 +123,7 @@
1684 #define L_PTE_USER (_AT(pteval_t, 1) << 8)
1685 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1686 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1687+#define L_PTE_PXN (_AT(pteval_t, 1) << 11) /* v7*/
1688
1689 /*
1690 * These are the memory types, defined to be compatible with
1691diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1692index d795282..d82ff13 100644
1693--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1694+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1695@@ -32,6 +32,7 @@
1696 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1697 #define PMD_BIT4 (_AT(pmdval_t, 0))
1698 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1699+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1700
1701 /*
1702 * - section
1703@@ -41,9 +42,11 @@
1704 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1705 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1706 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1707+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1708 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1709 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1710 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1711+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1712 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1713
1714 /*
1715@@ -66,6 +69,7 @@
1716 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1717 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1718 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1719+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1720 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1721
1722 /*
1723diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1724index b249035..4ab204b 100644
1725--- a/arch/arm/include/asm/pgtable-3level.h
1726+++ b/arch/arm/include/asm/pgtable-3level.h
1727@@ -73,6 +73,7 @@
1728 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1729 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1730 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1731+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1732 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1733 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1734 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1735@@ -80,6 +81,7 @@
1736 /*
1737 * To be used in assembly code with the upper page attributes.
1738 */
1739+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1740 #define L_PTE_XN_HIGH (1 << (54 - 32))
1741 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1742
1743diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1744index 08c1231..1031bb4 100644
1745--- a/arch/arm/include/asm/pgtable.h
1746+++ b/arch/arm/include/asm/pgtable.h
1747@@ -30,6 +30,9 @@
1748 #include <asm/pgtable-2level.h>
1749 #endif
1750
1751+#define ktla_ktva(addr) (addr)
1752+#define ktva_ktla(addr) (addr)
1753+
1754 /*
1755 * Just any arbitrary offset to the start of the vmalloc VM area: the
1756 * current 8MB value just means that there will be a 8MB "hole" after the
1757@@ -45,6 +48,9 @@
1758 #define LIBRARY_TEXT_START 0x0c000000
1759
1760 #ifndef __ASSEMBLY__
1761+extern pteval_t __supported_pte_mask;
1762+extern pmdval_t __supported_pmd_mask;
1763+
1764 extern void __pte_error(const char *file, int line, pte_t);
1765 extern void __pmd_error(const char *file, int line, pmd_t);
1766 extern void __pgd_error(const char *file, int line, pgd_t);
1767@@ -53,6 +59,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1768 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1769 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1770
1771+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1772+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1773+
1774+#ifdef CONFIG_PAX_KERNEXEC
1775+static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1776+static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1777+#else
1778+static inline unsigned long pax_open_kernel(void) { return 0; }
1779+static inline unsigned long pax_close_kernel(void) { return 0; }
1780+#endif
1781+
1782 /*
1783 * This is the lowest virtual address we can permit any user space
1784 * mapping to be mapped at. This is particularly important for
1785@@ -63,8 +80,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1786 /*
1787 * The pgprot_* and protection_map entries will be fixed up in runtime
1788 * to include the cachable and bufferable bits based on memory policy,
1789- * as well as any architecture dependent bits like global/ASID and SMP
1790- * shared mapping bits.
1791+ * as well as any architecture dependent bits like global/ASID, PXN,
1792+ * and SMP shared mapping bits.
1793 */
1794 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1795
1796@@ -242,7 +259,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1797
1798 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1799 {
1800- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1801+ const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER | __supported_pte_mask;
1802 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1803 return pte;
1804 }
1805diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1806index f3628fb..a0672dd 100644
1807--- a/arch/arm/include/asm/proc-fns.h
1808+++ b/arch/arm/include/asm/proc-fns.h
1809@@ -75,7 +75,7 @@ extern struct processor {
1810 unsigned int suspend_size;
1811 void (*do_suspend)(void *);
1812 void (*do_resume)(void *);
1813-} processor;
1814+} __do_const processor;
1815
1816 #ifndef MULTI_CPU
1817 extern void cpu_proc_init(void);
1818diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1819index 2e3be16..4dc90fc 100644
1820--- a/arch/arm/include/asm/smp.h
1821+++ b/arch/arm/include/asm/smp.h
1822@@ -106,7 +106,7 @@ struct smp_operations {
1823 int (*cpu_disable)(unsigned int cpu);
1824 #endif
1825 #endif
1826-};
1827+} __no_const;
1828
1829 /*
1830 * set platform specific SMP operations
1831diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1832index 8477b4c..801a6a9 100644
1833--- a/arch/arm/include/asm/thread_info.h
1834+++ b/arch/arm/include/asm/thread_info.h
1835@@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1836 #define TIF_SYSCALL_TRACE 8
1837 #define TIF_SYSCALL_AUDIT 9
1838 #define TIF_SYSCALL_TRACEPOINT 10
1839+
1840+/* within 8 bits of TIF_SYSCALL_TRACE
1841+ to meet flexible second operand requirements
1842+*/
1843+#define TIF_GRSEC_SETXID 11
1844+
1845 #define TIF_USING_IWMMXT 17
1846 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1847 #define TIF_RESTORE_SIGMASK 20
1848@@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1849 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1850 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1851 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1852+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1853
1854 /* Checks for any syscall work in entry-common.S */
1855-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1856+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1857+ _TIF_GRSEC_SETXID)
1858
1859 /*
1860 * Change these and you break ASM code in entry-common.S
1861diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1862index 7e1f760..f2c37b1 100644
1863--- a/arch/arm/include/asm/uaccess.h
1864+++ b/arch/arm/include/asm/uaccess.h
1865@@ -418,8 +418,23 @@ do { \
1866
1867
1868 #ifdef CONFIG_MMU
1869-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1870-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1871+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1872+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1873+
1874+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1875+{
1876+ check_object_size(to, n, false);
1877+
1878+ return ___copy_from_user(to, from, n);
1879+}
1880+
1881+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1882+{
1883+ check_object_size(from, n, true);
1884+
1885+ return ___copy_to_user(to, from, n);
1886+}
1887+
1888 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1889 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1890 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1891@@ -431,6 +446,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1892
1893 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1894 {
1895+ if ((long)n < 0)
1896+ return n;
1897+
1898 if (access_ok(VERIFY_READ, from, n))
1899 n = __copy_from_user(to, from, n);
1900 else /* security hole - plug it */
1901@@ -440,6 +458,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1902
1903 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1904 {
1905+ if ((long)n < 0)
1906+ return n;
1907+
1908 if (access_ok(VERIFY_WRITE, to, n))
1909 n = __copy_to_user(to, from, n);
1910 return n;
1911diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1912index 96ee092..37f1844 100644
1913--- a/arch/arm/include/uapi/asm/ptrace.h
1914+++ b/arch/arm/include/uapi/asm/ptrace.h
1915@@ -73,7 +73,7 @@
1916 * ARMv7 groups of PSR bits
1917 */
1918 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1919-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1920+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1921 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1922 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1923
1924diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1925index 60d3b73..9168db0 100644
1926--- a/arch/arm/kernel/armksyms.c
1927+++ b/arch/arm/kernel/armksyms.c
1928@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1929 #ifdef CONFIG_MMU
1930 EXPORT_SYMBOL(copy_page);
1931
1932-EXPORT_SYMBOL(__copy_from_user);
1933-EXPORT_SYMBOL(__copy_to_user);
1934+EXPORT_SYMBOL(___copy_from_user);
1935+EXPORT_SYMBOL(___copy_to_user);
1936 EXPORT_SYMBOL(__clear_user);
1937
1938 EXPORT_SYMBOL(__get_user_1);
1939diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1940index 486a15a..d95523a 100644
1941--- a/arch/arm/kernel/head.S
1942+++ b/arch/arm/kernel/head.S
1943@@ -52,7 +52,9 @@
1944 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1945
1946 .macro pgtbl, rd, phys
1947- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1948+ mov \rd, #TEXT_OFFSET
1949+ sub \rd, #PG_DIR_SIZE
1950+ add \rd, \rd, \phys
1951 .endm
1952
1953 /*
1954diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1955index 1e9be5d..03edbc2 100644
1956--- a/arch/arm/kernel/module.c
1957+++ b/arch/arm/kernel/module.c
1958@@ -37,12 +37,37 @@
1959 #endif
1960
1961 #ifdef CONFIG_MMU
1962-void *module_alloc(unsigned long size)
1963+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1964 {
1965+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
1966+ return NULL;
1967 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1968- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1969+ GFP_KERNEL, prot, -1,
1970 __builtin_return_address(0));
1971 }
1972+
1973+void *module_alloc(unsigned long size)
1974+{
1975+
1976+#ifdef CONFIG_PAX_KERNEXEC
1977+ return __module_alloc(size, PAGE_KERNEL);
1978+#else
1979+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1980+#endif
1981+
1982+}
1983+
1984+#ifdef CONFIG_PAX_KERNEXEC
1985+void module_free_exec(struct module *mod, void *module_region)
1986+{
1987+ module_free(mod, module_region);
1988+}
1989+
1990+void *module_alloc_exec(unsigned long size)
1991+{
1992+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1993+}
1994+#endif
1995 #endif
1996
1997 int
1998diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1999index 90084a6..a8b26bc 100644
2000--- a/arch/arm/kernel/process.c
2001+++ b/arch/arm/kernel/process.c
2002@@ -28,7 +28,6 @@
2003 #include <linux/tick.h>
2004 #include <linux/utsname.h>
2005 #include <linux/uaccess.h>
2006-#include <linux/random.h>
2007 #include <linux/hw_breakpoint.h>
2008 #include <linux/cpuidle.h>
2009 #include <linux/leds.h>
2010@@ -256,9 +255,10 @@ void machine_power_off(void)
2011 machine_shutdown();
2012 if (pm_power_off)
2013 pm_power_off();
2014+ BUG();
2015 }
2016
2017-void machine_restart(char *cmd)
2018+__noreturn void machine_restart(char *cmd)
2019 {
2020 machine_shutdown();
2021
2022@@ -283,8 +283,8 @@ void __show_regs(struct pt_regs *regs)
2023 init_utsname()->release,
2024 (int)strcspn(init_utsname()->version, " "),
2025 init_utsname()->version);
2026- print_symbol("PC is at %s\n", instruction_pointer(regs));
2027- print_symbol("LR is at %s\n", regs->ARM_lr);
2028+ printk("PC is at %pA\n", instruction_pointer(regs));
2029+ printk("LR is at %pA\n", regs->ARM_lr);
2030 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2031 "sp : %08lx ip : %08lx fp : %08lx\n",
2032 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2033@@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2034 return 0;
2035 }
2036
2037-unsigned long arch_randomize_brk(struct mm_struct *mm)
2038-{
2039- unsigned long range_end = mm->brk + 0x02000000;
2040- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2041-}
2042-
2043 #ifdef CONFIG_MMU
2044 /*
2045 * The vectors page is always readable from user space for the
2046diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2047index 739db3a..7f4a272 100644
2048--- a/arch/arm/kernel/ptrace.c
2049+++ b/arch/arm/kernel/ptrace.c
2050@@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2051 PTRACE_SYSCALL_EXIT,
2052 };
2053
2054+#ifdef CONFIG_GRKERNSEC_SETXID
2055+extern void gr_delayed_cred_worker(void);
2056+#endif
2057+
2058 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2059 enum ptrace_syscall_dir dir)
2060 {
2061@@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2062
2063 current_thread_info()->syscall = scno;
2064
2065+#ifdef CONFIG_GRKERNSEC_SETXID
2066+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2067+ gr_delayed_cred_worker();
2068+#endif
2069+
2070 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2071 return scno;
2072
2073diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2074index da1d1aa..ef9bc58 100644
2075--- a/arch/arm/kernel/setup.c
2076+++ b/arch/arm/kernel/setup.c
2077@@ -97,21 +97,23 @@ EXPORT_SYMBOL(system_serial_high);
2078 unsigned int elf_hwcap __read_mostly;
2079 EXPORT_SYMBOL(elf_hwcap);
2080
2081+pteval_t __supported_pte_mask __read_only;
2082+pmdval_t __supported_pmd_mask __read_only;
2083
2084 #ifdef MULTI_CPU
2085-struct processor processor __read_mostly;
2086+struct processor processor;
2087 #endif
2088 #ifdef MULTI_TLB
2089-struct cpu_tlb_fns cpu_tlb __read_mostly;
2090+struct cpu_tlb_fns cpu_tlb __read_only;
2091 #endif
2092 #ifdef MULTI_USER
2093-struct cpu_user_fns cpu_user __read_mostly;
2094+struct cpu_user_fns cpu_user __read_only;
2095 #endif
2096 #ifdef MULTI_CACHE
2097-struct cpu_cache_fns cpu_cache __read_mostly;
2098+struct cpu_cache_fns cpu_cache __read_only;
2099 #endif
2100 #ifdef CONFIG_OUTER_CACHE
2101-struct outer_cache_fns outer_cache __read_mostly;
2102+struct outer_cache_fns outer_cache __read_only;
2103 EXPORT_SYMBOL(outer_cache);
2104 #endif
2105
2106@@ -236,9 +238,13 @@ static int __get_cpu_architecture(void)
2107 asm("mrc p15, 0, %0, c0, c1, 4"
2108 : "=r" (mmfr0));
2109 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2110- (mmfr0 & 0x000000f0) >= 0x00000030)
2111+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2112 cpu_arch = CPU_ARCH_ARMv7;
2113- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2114+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2115+ __supported_pte_mask |= L_PTE_PXN;
2116+ __supported_pmd_mask |= PMD_PXNTABLE;
2117+ }
2118+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2119 (mmfr0 & 0x000000f0) == 0x00000020)
2120 cpu_arch = CPU_ARCH_ARMv6;
2121 else
2122@@ -455,7 +461,7 @@ static void __init setup_processor(void)
2123 __cpu_architecture = __get_cpu_architecture();
2124
2125 #ifdef MULTI_CPU
2126- processor = *list->proc;
2127+ memcpy((void *)&processor, list->proc, sizeof processor);
2128 #endif
2129 #ifdef MULTI_TLB
2130 cpu_tlb = *list->tlb;
2131diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2132index fbc8b26..000ded0 100644
2133--- a/arch/arm/kernel/smp.c
2134+++ b/arch/arm/kernel/smp.c
2135@@ -70,7 +70,7 @@ enum ipi_msg_type {
2136
2137 static DECLARE_COMPLETION(cpu_running);
2138
2139-static struct smp_operations smp_ops;
2140+static struct smp_operations smp_ops __read_only;
2141
2142 void __init smp_set_ops(struct smp_operations *ops)
2143 {
2144diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2145index b0179b8..7713948 100644
2146--- a/arch/arm/kernel/traps.c
2147+++ b/arch/arm/kernel/traps.c
2148@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2149 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2150 {
2151 #ifdef CONFIG_KALLSYMS
2152- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2153+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2154 #else
2155 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2156 #endif
2157@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2158 static int die_owner = -1;
2159 static unsigned int die_nest_count;
2160
2161+extern void gr_handle_kernel_exploit(void);
2162+
2163 static unsigned long oops_begin(void)
2164 {
2165 int cpu;
2166@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2167 panic("Fatal exception in interrupt");
2168 if (panic_on_oops)
2169 panic("Fatal exception");
2170+
2171+ gr_handle_kernel_exploit();
2172+
2173 if (signr)
2174 do_exit(signr);
2175 }
2176diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2177index 36ff15b..75d9e9d 100644
2178--- a/arch/arm/kernel/vmlinux.lds.S
2179+++ b/arch/arm/kernel/vmlinux.lds.S
2180@@ -8,7 +8,11 @@
2181 #include <asm/thread_info.h>
2182 #include <asm/memory.h>
2183 #include <asm/page.h>
2184-
2185+
2186+#ifdef CONFIG_PAX_KERNEXEC
2187+#include <asm/pgtable.h>
2188+#endif
2189+
2190 #define PROC_INFO \
2191 . = ALIGN(4); \
2192 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2193@@ -90,6 +94,11 @@ SECTIONS
2194 _text = .;
2195 HEAD_TEXT
2196 }
2197+
2198+#ifdef CONFIG_PAX_KERNEXEC
2199+ . = ALIGN(1<<SECTION_SHIFT);
2200+#endif
2201+
2202 .text : { /* Real text segment */
2203 _stext = .; /* Text and read-only data */
2204 __exception_text_start = .;
2205@@ -133,6 +142,10 @@ SECTIONS
2206
2207 _etext = .; /* End of text and rodata section */
2208
2209+#ifdef CONFIG_PAX_KERNEXEC
2210+ . = ALIGN(1<<SECTION_SHIFT);
2211+#endif
2212+
2213 #ifndef CONFIG_XIP_KERNEL
2214 . = ALIGN(PAGE_SIZE);
2215 __init_begin = .;
2216@@ -192,6 +205,11 @@ SECTIONS
2217 . = PAGE_OFFSET + TEXT_OFFSET;
2218 #else
2219 __init_end = .;
2220+
2221+#ifdef CONFIG_PAX_KERNEXEC
2222+ . = ALIGN(1<<SECTION_SHIFT);
2223+#endif
2224+
2225 . = ALIGN(THREAD_SIZE);
2226 __data_loc = .;
2227 #endif
2228diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2229index 66a477a..bee61d3 100644
2230--- a/arch/arm/lib/copy_from_user.S
2231+++ b/arch/arm/lib/copy_from_user.S
2232@@ -16,7 +16,7 @@
2233 /*
2234 * Prototype:
2235 *
2236- * size_t __copy_from_user(void *to, const void *from, size_t n)
2237+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
2238 *
2239 * Purpose:
2240 *
2241@@ -84,11 +84,11 @@
2242
2243 .text
2244
2245-ENTRY(__copy_from_user)
2246+ENTRY(___copy_from_user)
2247
2248 #include "copy_template.S"
2249
2250-ENDPROC(__copy_from_user)
2251+ENDPROC(___copy_from_user)
2252
2253 .pushsection .fixup,"ax"
2254 .align 0
2255diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2256index 6ee2f67..d1cce76 100644
2257--- a/arch/arm/lib/copy_page.S
2258+++ b/arch/arm/lib/copy_page.S
2259@@ -10,6 +10,7 @@
2260 * ASM optimised string functions
2261 */
2262 #include <linux/linkage.h>
2263+#include <linux/const.h>
2264 #include <asm/assembler.h>
2265 #include <asm/asm-offsets.h>
2266 #include <asm/cache.h>
2267diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2268index d066df6..df28194 100644
2269--- a/arch/arm/lib/copy_to_user.S
2270+++ b/arch/arm/lib/copy_to_user.S
2271@@ -16,7 +16,7 @@
2272 /*
2273 * Prototype:
2274 *
2275- * size_t __copy_to_user(void *to, const void *from, size_t n)
2276+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
2277 *
2278 * Purpose:
2279 *
2280@@ -88,11 +88,11 @@
2281 .text
2282
2283 ENTRY(__copy_to_user_std)
2284-WEAK(__copy_to_user)
2285+WEAK(___copy_to_user)
2286
2287 #include "copy_template.S"
2288
2289-ENDPROC(__copy_to_user)
2290+ENDPROC(___copy_to_user)
2291 ENDPROC(__copy_to_user_std)
2292
2293 .pushsection .fixup,"ax"
2294diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2295index 0dc5385..45833ef 100644
2296--- a/arch/arm/lib/delay.c
2297+++ b/arch/arm/lib/delay.c
2298@@ -28,12 +28,14 @@
2299 /*
2300 * Default to the loop-based delay implementation.
2301 */
2302-struct arm_delay_ops arm_delay_ops = {
2303+static struct arm_delay_ops arm_loop_delay_ops = {
2304 .delay = __loop_delay,
2305 .const_udelay = __loop_const_udelay,
2306 .udelay = __loop_udelay,
2307 };
2308
2309+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2310+
2311 static const struct delay_timer *delay_timer;
2312 static bool delay_calibrated;
2313
2314@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2315 __timer_const_udelay(usecs * UDELAY_MULT);
2316 }
2317
2318+static struct arm_delay_ops arm_timer_delay_ops = {
2319+ .delay = __timer_delay,
2320+ .const_udelay = __timer_const_udelay,
2321+ .udelay = __timer_udelay,
2322+};
2323+
2324 void __init register_current_timer_delay(const struct delay_timer *timer)
2325 {
2326 if (!delay_calibrated) {
2327@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2328 delay_timer = timer;
2329 lpj_fine = timer->freq / HZ;
2330 loops_per_jiffy = lpj_fine;
2331- arm_delay_ops.delay = __timer_delay;
2332- arm_delay_ops.const_udelay = __timer_const_udelay;
2333- arm_delay_ops.udelay = __timer_udelay;
2334+ arm_delay_ops = &arm_timer_delay_ops;
2335 delay_calibrated = true;
2336 } else {
2337 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2338diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2339index 025f742..8432b08 100644
2340--- a/arch/arm/lib/uaccess_with_memcpy.c
2341+++ b/arch/arm/lib/uaccess_with_memcpy.c
2342@@ -104,7 +104,7 @@ out:
2343 }
2344
2345 unsigned long
2346-__copy_to_user(void __user *to, const void *from, unsigned long n)
2347+___copy_to_user(void __user *to, const void *from, unsigned long n)
2348 {
2349 /*
2350 * This test is stubbed out of the main function above to keep
2351diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2352index 2c6c218..2b87c2d 100644
2353--- a/arch/arm/mach-kirkwood/common.c
2354+++ b/arch/arm/mach-kirkwood/common.c
2355@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2356 clk_gate_ops.disable(hw);
2357 }
2358
2359-static struct clk_ops clk_gate_fn_ops;
2360+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2361+{
2362+ return clk_gate_ops.is_enabled(hw);
2363+}
2364+
2365+static struct clk_ops clk_gate_fn_ops = {
2366+ .enable = clk_gate_fn_enable,
2367+ .disable = clk_gate_fn_disable,
2368+ .is_enabled = clk_gate_fn_is_enabled,
2369+};
2370
2371 static struct clk __init *clk_register_gate_fn(struct device *dev,
2372 const char *name,
2373@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2374 gate_fn->fn_en = fn_en;
2375 gate_fn->fn_dis = fn_dis;
2376
2377- /* ops is the gate ops, but with our enable/disable functions */
2378- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2379- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2380- clk_gate_fn_ops = clk_gate_ops;
2381- clk_gate_fn_ops.enable = clk_gate_fn_enable;
2382- clk_gate_fn_ops.disable = clk_gate_fn_disable;
2383- }
2384-
2385 clk = clk_register(dev, &gate_fn->gate.hw);
2386
2387 if (IS_ERR(clk))
2388diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2389index d95f727..12f10dd 100644
2390--- a/arch/arm/mach-omap2/board-n8x0.c
2391+++ b/arch/arm/mach-omap2/board-n8x0.c
2392@@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2393 }
2394 #endif
2395
2396-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2397+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2398 .late_init = n8x0_menelaus_late_init,
2399 };
2400
2401diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2402index 87cc6d0..fd4f248 100644
2403--- a/arch/arm/mach-omap2/omap_hwmod.c
2404+++ b/arch/arm/mach-omap2/omap_hwmod.c
2405@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2406 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2407 struct omap_hwmod_rst_info *ohri);
2408 int (*init_clkdm)(struct omap_hwmod *oh);
2409-};
2410+} __no_const;
2411
2412 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2413-static struct omap_hwmod_soc_ops soc_ops;
2414+static struct omap_hwmod_soc_ops soc_ops __read_only;
2415
2416 /* omap_hwmod_list contains all registered struct omap_hwmods */
2417 static LIST_HEAD(omap_hwmod_list);
2418diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2419index 5dbf13f..9be36fd 100644
2420--- a/arch/arm/mm/fault.c
2421+++ b/arch/arm/mm/fault.c
2422@@ -25,6 +25,7 @@
2423 #include <asm/system_misc.h>
2424 #include <asm/system_info.h>
2425 #include <asm/tlbflush.h>
2426+#include <asm/sections.h>
2427
2428 #include "fault.h"
2429
2430@@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2431 if (fixup_exception(regs))
2432 return;
2433
2434+#ifdef CONFIG_PAX_KERNEXEC
2435+ if (fsr & FSR_WRITE) {
2436+ if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2437+ if (current->signal->curr_ip)
2438+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2439+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2440+ else
2441+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2442+ current->comm, task_pid_nr(current), current_uid(), current_euid());
2443+ }
2444+ }
2445+#endif
2446+
2447 /*
2448 * No handler, we'll have to terminate things with extreme prejudice.
2449 */
2450@@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2451 }
2452 #endif
2453
2454+#ifdef CONFIG_PAX_PAGEEXEC
2455+ if (fsr & FSR_LNX_PF) {
2456+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2457+ do_group_exit(SIGKILL);
2458+ }
2459+#endif
2460+
2461 tsk->thread.address = addr;
2462 tsk->thread.error_code = fsr;
2463 tsk->thread.trap_no = 14;
2464@@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2465 }
2466 #endif /* CONFIG_MMU */
2467
2468+#ifdef CONFIG_PAX_PAGEEXEC
2469+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2470+{
2471+ long i;
2472+
2473+ printk(KERN_ERR "PAX: bytes at PC: ");
2474+ for (i = 0; i < 20; i++) {
2475+ unsigned char c;
2476+ if (get_user(c, (__force unsigned char __user *)pc+i))
2477+ printk(KERN_CONT "?? ");
2478+ else
2479+ printk(KERN_CONT "%02x ", c);
2480+ }
2481+ printk("\n");
2482+
2483+ printk(KERN_ERR "PAX: bytes at SP-4: ");
2484+ for (i = -1; i < 20; i++) {
2485+ unsigned long c;
2486+ if (get_user(c, (__force unsigned long __user *)sp+i))
2487+ printk(KERN_CONT "???????? ");
2488+ else
2489+ printk(KERN_CONT "%08lx ", c);
2490+ }
2491+ printk("\n");
2492+}
2493+#endif
2494+
2495 /*
2496 * First Level Translation Fault Handler
2497 *
2498@@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2499 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2500 struct siginfo info;
2501
2502+#ifdef CONFIG_PAX_KERNEXEC
2503+ if (!user_mode(regs) && is_xn_fault(ifsr)) {
2504+ if (current->signal->curr_ip)
2505+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2506+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2507+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2508+ else
2509+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2510+ current->comm, task_pid_nr(current), current_uid(), current_euid(),
2511+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2512+ goto die;
2513+ }
2514+#endif
2515+
2516+#ifdef CONFIG_PAX_REFCOUNT
2517+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2518+ unsigned int bkpt;
2519+
2520+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2521+ current->thread.error_code = ifsr;
2522+ current->thread.trap_no = 0;
2523+ pax_report_refcount_overflow(regs);
2524+ fixup_exception(regs);
2525+ return;
2526+ }
2527+ }
2528+#endif
2529+
2530 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2531 return;
2532
2533 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2534 inf->name, ifsr, addr);
2535
2536+die:
2537 info.si_signo = inf->sig;
2538 info.si_errno = 0;
2539 info.si_code = inf->code;
2540diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2541index cf08bdf..f1a0383 100644
2542--- a/arch/arm/mm/fault.h
2543+++ b/arch/arm/mm/fault.h
2544@@ -3,6 +3,7 @@
2545
2546 /*
2547 * Fault status register encodings. We steal bit 31 for our own purposes.
2548+ * Set when the FSR value is from an instruction fault.
2549 */
2550 #define FSR_LNX_PF (1 << 31)
2551 #define FSR_WRITE (1 << 11)
2552@@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2553 }
2554 #endif
2555
2556+/* valid for LPAE and !LPAE */
2557+static inline int is_xn_fault(unsigned int fsr)
2558+{
2559+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
2560+}
2561+
2562 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2563 unsigned long search_exception_table(unsigned long addr);
2564
2565diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2566index ad722f1..46b670e 100644
2567--- a/arch/arm/mm/init.c
2568+++ b/arch/arm/mm/init.c
2569@@ -734,9 +734,43 @@ void __init mem_init(void)
2570
2571 void free_initmem(void)
2572 {
2573+
2574+#ifdef CONFIG_PAX_KERNEXEC
2575+ unsigned long addr;
2576+ pgd_t *pgd;
2577+ pud_t *pud;
2578+ pmd_t *pmd;
2579+#endif
2580+
2581 #ifdef CONFIG_HAVE_TCM
2582 extern char __tcm_start, __tcm_end;
2583+#endif
2584
2585+#ifdef CONFIG_PAX_KERNEXEC
2586+ /* make pages tables, etc before .text NX */
2587+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2588+ pgd = pgd_offset_k(addr);
2589+ pud = pud_offset(pgd, addr);
2590+ pmd = pmd_offset(pud, addr);
2591+ __pmd_update(pmd, PMD_SECT_XN);
2592+ }
2593+ /* make init NX */
2594+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2595+ pgd = pgd_offset_k(addr);
2596+ pud = pud_offset(pgd, addr);
2597+ pmd = pmd_offset(pud, addr);
2598+ __pmd_update(pmd, PMD_SECT_XN);
2599+ }
2600+ /* make kernel code/rodata read-only */
2601+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2602+ pgd = pgd_offset_k(addr);
2603+ pud = pud_offset(pgd, addr);
2604+ pmd = pmd_offset(pud, addr);
2605+ __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2606+ }
2607+#endif
2608+
2609+#ifdef CONFIG_HAVE_TCM
2610 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2611 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2612 __phys_to_pfn(__pa(&__tcm_end)),
2613diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2614index ce8cb19..061aa14 100644
2615--- a/arch/arm/mm/mmap.c
2616+++ b/arch/arm/mm/mmap.c
2617@@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2618 unsigned long start_addr;
2619 int do_align = 0;
2620 int aliasing = cache_is_vipt_aliasing();
2621+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2622
2623 /*
2624 * We only need to do colour alignment if either the I or D
2625@@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2626 if (len > TASK_SIZE)
2627 return -ENOMEM;
2628
2629+#ifdef CONFIG_PAX_RANDMMAP
2630+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2631+#endif
2632+
2633 if (addr) {
2634 if (do_align)
2635 addr = COLOUR_ALIGN(addr, pgoff);
2636@@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2637 addr = PAGE_ALIGN(addr);
2638
2639 vma = find_vma(mm, addr);
2640- if (TASK_SIZE - len >= addr &&
2641- (!vma || addr + len <= vma->vm_start))
2642+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2643 return addr;
2644 }
2645 if (len > mm->cached_hole_size) {
2646- start_addr = addr = mm->free_area_cache;
2647+ start_addr = addr = mm->free_area_cache;
2648 } else {
2649- start_addr = addr = mm->mmap_base;
2650- mm->cached_hole_size = 0;
2651+ start_addr = addr = mm->mmap_base;
2652+ mm->cached_hole_size = 0;
2653 }
2654
2655 full_search:
2656@@ -124,14 +128,14 @@ full_search:
2657 * Start a new search - just in case we missed
2658 * some holes.
2659 */
2660- if (start_addr != TASK_UNMAPPED_BASE) {
2661- start_addr = addr = TASK_UNMAPPED_BASE;
2662+ if (start_addr != mm->mmap_base) {
2663+ start_addr = addr = mm->mmap_base;
2664 mm->cached_hole_size = 0;
2665 goto full_search;
2666 }
2667 return -ENOMEM;
2668 }
2669- if (!vma || addr + len <= vma->vm_start) {
2670+ if (check_heap_stack_gap(vma, addr, len, offset)) {
2671 /*
2672 * Remember the place where we stopped the search:
2673 */
2674@@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2675 unsigned long addr = addr0;
2676 int do_align = 0;
2677 int aliasing = cache_is_vipt_aliasing();
2678+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2679
2680 /*
2681 * We only need to do colour alignment if either the I or D
2682@@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2683 return addr;
2684 }
2685
2686+#ifdef CONFIG_PAX_RANDMMAP
2687+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2688+#endif
2689+
2690 /* requesting a specific address */
2691 if (addr) {
2692 if (do_align)
2693@@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2694 else
2695 addr = PAGE_ALIGN(addr);
2696 vma = find_vma(mm, addr);
2697- if (TASK_SIZE - len >= addr &&
2698- (!vma || addr + len <= vma->vm_start))
2699+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2700 return addr;
2701 }
2702
2703@@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2704 /* make sure it can fit in the remaining address space */
2705 if (addr > len) {
2706 vma = find_vma(mm, addr-len);
2707- if (!vma || addr <= vma->vm_start)
2708+ if (check_heap_stack_gap(vma, addr - len, len, offset))
2709 /* remember the address as a hint for next time */
2710 return (mm->free_area_cache = addr-len);
2711 }
2712@@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2713 goto bottomup;
2714
2715 addr = mm->mmap_base - len;
2716- if (do_align)
2717- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2718
2719 do {
2720+ if (do_align)
2721+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2722 /*
2723 * Lookup failure means no vma is above this address,
2724 * else if new region fits below vma->vm_start,
2725 * return with success:
2726 */
2727 vma = find_vma(mm, addr);
2728- if (!vma || addr+len <= vma->vm_start)
2729+ if (check_heap_stack_gap(vma, addr, len, offset))
2730 /* remember the address as a hint for next time */
2731 return (mm->free_area_cache = addr);
2732
2733@@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2734 mm->cached_hole_size = vma->vm_start - addr;
2735
2736 /* try just below the current vma->vm_start */
2737- addr = vma->vm_start - len;
2738- if (do_align)
2739- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2740- } while (len < vma->vm_start);
2741+ addr = skip_heap_stack_gap(vma, len, offset);
2742+ } while (!IS_ERR_VALUE(addr));
2743
2744 bottomup:
2745 /*
2746@@ -259,6 +265,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2747 {
2748 unsigned long random_factor = 0UL;
2749
2750+#ifdef CONFIG_PAX_RANDMMAP
2751+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2752+#endif
2753+
2754 /* 8 bits of randomness in 20 address space bits */
2755 if ((current->flags & PF_RANDOMIZE) &&
2756 !(current->personality & ADDR_NO_RANDOMIZE))
2757@@ -266,10 +276,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2758
2759 if (mmap_is_legacy()) {
2760 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2761+
2762+#ifdef CONFIG_PAX_RANDMMAP
2763+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2764+ mm->mmap_base += mm->delta_mmap;
2765+#endif
2766+
2767 mm->get_unmapped_area = arch_get_unmapped_area;
2768 mm->unmap_area = arch_unmap_area;
2769 } else {
2770 mm->mmap_base = mmap_base(random_factor);
2771+
2772+#ifdef CONFIG_PAX_RANDMMAP
2773+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2774+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2775+#endif
2776+
2777 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2778 mm->unmap_area = arch_unmap_area_topdown;
2779 }
2780diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2781index 99b47b9..579b667 100644
2782--- a/arch/arm/mm/mmu.c
2783+++ b/arch/arm/mm/mmu.c
2784@@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2785 [MT_UNCACHED] = {
2786 .prot_pte = PROT_PTE_DEVICE,
2787 .prot_l1 = PMD_TYPE_TABLE,
2788- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2789+ .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2790 .domain = DOMAIN_IO,
2791 },
2792 [MT_CACHECLEAN] = {
2793- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2794+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2795 .domain = DOMAIN_KERNEL,
2796 },
2797 #ifndef CONFIG_ARM_LPAE
2798 [MT_MINICLEAN] = {
2799- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2800+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2801 .domain = DOMAIN_KERNEL,
2802 },
2803 #endif
2804@@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2805 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2806 .domain = DOMAIN_KERNEL,
2807 },
2808+ [MT_MEMORY_R] = {
2809+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2810+ .prot_l1 = PMD_TYPE_TABLE,
2811+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2812+ .domain = DOMAIN_KERNEL,
2813+ },
2814+ [MT_MEMORY_RW] = {
2815+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2816+ .prot_l1 = PMD_TYPE_TABLE,
2817+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2818+ .domain = DOMAIN_KERNEL,
2819+ },
2820+ [MT_MEMORY_RX] = {
2821+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2822+ .prot_l1 = PMD_TYPE_TABLE,
2823+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2824+ .domain = DOMAIN_KERNEL,
2825+ },
2826 [MT_ROM] = {
2827- .prot_sect = PMD_TYPE_SECT,
2828+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2829 .domain = DOMAIN_KERNEL,
2830 },
2831 [MT_MEMORY_NONCACHED] = {
2832@@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2833 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2834 L_PTE_XN,
2835 .prot_l1 = PMD_TYPE_TABLE,
2836- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2837+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2838 .domain = DOMAIN_KERNEL,
2839 },
2840 [MT_MEMORY_ITCM] = {
2841@@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2842 * from SVC mode and no access from userspace.
2843 */
2844 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2845+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2846+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2847 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2848 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2849 #endif
2850@@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2851 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2852 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2853 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2854+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2855+ mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2856+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2857+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2858+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2859+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2860 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2861 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2862 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2863@@ -487,6 +513,8 @@ static void __init build_mem_type_table(void)
2864 vecs_pgprot |= PTE_EXT_AF;
2865 #endif
2866
2867+ user_pgprot |= __supported_pte_mask;
2868+
2869 for (i = 0; i < 16; i++) {
2870 pteval_t v = pgprot_val(protection_map[i]);
2871 protection_map[i] = __pgprot(v | user_pgprot);
2872@@ -503,6 +531,12 @@ static void __init build_mem_type_table(void)
2873 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2874 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2875 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2876+ mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2877+ mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2878+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2879+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2880+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2881+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2882 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2883 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2884 mem_types[MT_ROM].prot_sect |= cp->pmd;
2885@@ -1198,7 +1232,41 @@ static void __init map_lowmem(void)
2886 map.pfn = __phys_to_pfn(start);
2887 map.virtual = __phys_to_virt(start);
2888 map.length = end - start;
2889+
2890+#ifdef CONFIG_PAX_KERNEXEC
2891+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2892+ struct map_desc kernel;
2893+ struct map_desc initmap;
2894+
2895+ /* when freeing initmem we will make this RW */
2896+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2897+ initmap.virtual = (unsigned long)__init_begin;
2898+ initmap.length = _sdata - __init_begin;
2899+ initmap.type = MT_MEMORY;
2900+ create_mapping(&initmap);
2901+
2902+ /* when freeing initmem we will make this RX */
2903+ kernel.pfn = __phys_to_pfn(__pa(_stext));
2904+ kernel.virtual = (unsigned long)_stext;
2905+ kernel.length = __init_begin - _stext;
2906+ kernel.type = MT_MEMORY;
2907+ create_mapping(&kernel);
2908+
2909+ if (map.virtual < (unsigned long)_stext) {
2910+ map.length = (unsigned long)_stext - map.virtual;
2911+ map.type = MT_MEMORY;
2912+ create_mapping(&map);
2913+ }
2914+
2915+ map.pfn = __phys_to_pfn(__pa(_sdata));
2916+ map.virtual = (unsigned long)_sdata;
2917+ map.length = end - __pa(_sdata);
2918+ }
2919+
2920+ map.type = MT_MEMORY_RW;
2921+#else
2922 map.type = MT_MEMORY;
2923+#endif
2924
2925 create_mapping(&map);
2926 }
2927diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2928index ec63e4a..62aa5f1d 100644
2929--- a/arch/arm/plat-orion/include/plat/addr-map.h
2930+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2931@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2932 value in bridge_virt_base */
2933 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2934 const int win);
2935-};
2936+} __no_const;
2937
2938 /*
2939 * Information needed to setup one address mapping.
2940diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2941index f5144cd..71f6d1f 100644
2942--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2943+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2944@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2945 int (*started)(unsigned ch);
2946 int (*flush)(unsigned ch);
2947 int (*stop)(unsigned ch);
2948-};
2949+} __no_const;
2950
2951 extern void *samsung_dmadev_get_ops(void);
2952 extern void *s3c_dma_get_ops(void);
2953diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2954index c3a58a1..78fbf54 100644
2955--- a/arch/avr32/include/asm/cache.h
2956+++ b/arch/avr32/include/asm/cache.h
2957@@ -1,8 +1,10 @@
2958 #ifndef __ASM_AVR32_CACHE_H
2959 #define __ASM_AVR32_CACHE_H
2960
2961+#include <linux/const.h>
2962+
2963 #define L1_CACHE_SHIFT 5
2964-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2965+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2966
2967 /*
2968 * Memory returned by kmalloc() may be used for DMA, so we must make
2969diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2970index e2c3287..6c4f98c 100644
2971--- a/arch/avr32/include/asm/elf.h
2972+++ b/arch/avr32/include/asm/elf.h
2973@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2974 the loader. We need to make sure that it is out of the way of the program
2975 that it will "exec", and that there is sufficient room for the brk. */
2976
2977-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2978+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2979
2980+#ifdef CONFIG_PAX_ASLR
2981+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2982+
2983+#define PAX_DELTA_MMAP_LEN 15
2984+#define PAX_DELTA_STACK_LEN 15
2985+#endif
2986
2987 /* This yields a mask that user programs can use to figure out what
2988 instruction set this CPU supports. This could be done in user space,
2989diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2990index 479330b..53717a8 100644
2991--- a/arch/avr32/include/asm/kmap_types.h
2992+++ b/arch/avr32/include/asm/kmap_types.h
2993@@ -2,9 +2,9 @@
2994 #define __ASM_AVR32_KMAP_TYPES_H
2995
2996 #ifdef CONFIG_DEBUG_HIGHMEM
2997-# define KM_TYPE_NR 29
2998+# define KM_TYPE_NR 30
2999 #else
3000-# define KM_TYPE_NR 14
3001+# define KM_TYPE_NR 15
3002 #endif
3003
3004 #endif /* __ASM_AVR32_KMAP_TYPES_H */
3005diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
3006index b2f2d2d..d1c85cb 100644
3007--- a/arch/avr32/mm/fault.c
3008+++ b/arch/avr32/mm/fault.c
3009@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
3010
3011 int exception_trace = 1;
3012
3013+#ifdef CONFIG_PAX_PAGEEXEC
3014+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3015+{
3016+ unsigned long i;
3017+
3018+ printk(KERN_ERR "PAX: bytes at PC: ");
3019+ for (i = 0; i < 20; i++) {
3020+ unsigned char c;
3021+ if (get_user(c, (unsigned char *)pc+i))
3022+ printk(KERN_CONT "???????? ");
3023+ else
3024+ printk(KERN_CONT "%02x ", c);
3025+ }
3026+ printk("\n");
3027+}
3028+#endif
3029+
3030 /*
3031 * This routine handles page faults. It determines the address and the
3032 * problem, and then passes it off to one of the appropriate routines.
3033@@ -174,6 +191,16 @@ bad_area:
3034 up_read(&mm->mmap_sem);
3035
3036 if (user_mode(regs)) {
3037+
3038+#ifdef CONFIG_PAX_PAGEEXEC
3039+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3040+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
3041+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
3042+ do_group_exit(SIGKILL);
3043+ }
3044+ }
3045+#endif
3046+
3047 if (exception_trace && printk_ratelimit())
3048 printk("%s%s[%d]: segfault at %08lx pc %08lx "
3049 "sp %08lx ecr %lu\n",
3050diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
3051index 568885a..f8008df 100644
3052--- a/arch/blackfin/include/asm/cache.h
3053+++ b/arch/blackfin/include/asm/cache.h
3054@@ -7,6 +7,7 @@
3055 #ifndef __ARCH_BLACKFIN_CACHE_H
3056 #define __ARCH_BLACKFIN_CACHE_H
3057
3058+#include <linux/const.h>
3059 #include <linux/linkage.h> /* for asmlinkage */
3060
3061 /*
3062@@ -14,7 +15,7 @@
3063 * Blackfin loads 32 bytes for cache
3064 */
3065 #define L1_CACHE_SHIFT 5
3066-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3067+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3068 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3069
3070 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3071diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3072index aea2718..3639a60 100644
3073--- a/arch/cris/include/arch-v10/arch/cache.h
3074+++ b/arch/cris/include/arch-v10/arch/cache.h
3075@@ -1,8 +1,9 @@
3076 #ifndef _ASM_ARCH_CACHE_H
3077 #define _ASM_ARCH_CACHE_H
3078
3079+#include <linux/const.h>
3080 /* Etrax 100LX have 32-byte cache-lines. */
3081-#define L1_CACHE_BYTES 32
3082 #define L1_CACHE_SHIFT 5
3083+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3084
3085 #endif /* _ASM_ARCH_CACHE_H */
3086diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3087index 7caf25d..ee65ac5 100644
3088--- a/arch/cris/include/arch-v32/arch/cache.h
3089+++ b/arch/cris/include/arch-v32/arch/cache.h
3090@@ -1,11 +1,12 @@
3091 #ifndef _ASM_CRIS_ARCH_CACHE_H
3092 #define _ASM_CRIS_ARCH_CACHE_H
3093
3094+#include <linux/const.h>
3095 #include <arch/hwregs/dma.h>
3096
3097 /* A cache-line is 32 bytes. */
3098-#define L1_CACHE_BYTES 32
3099 #define L1_CACHE_SHIFT 5
3100+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3101
3102 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3103
3104diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3105index b86329d..6709906 100644
3106--- a/arch/frv/include/asm/atomic.h
3107+++ b/arch/frv/include/asm/atomic.h
3108@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3109 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3110 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3111
3112+#define atomic64_read_unchecked(v) atomic64_read(v)
3113+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3114+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3115+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3116+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3117+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3118+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3119+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3120+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3121+
3122 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3123 {
3124 int c, old;
3125diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3126index 2797163..c2a401d 100644
3127--- a/arch/frv/include/asm/cache.h
3128+++ b/arch/frv/include/asm/cache.h
3129@@ -12,10 +12,11 @@
3130 #ifndef __ASM_CACHE_H
3131 #define __ASM_CACHE_H
3132
3133+#include <linux/const.h>
3134
3135 /* bytes per L1 cache line */
3136 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3137-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3138+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3139
3140 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3141 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3142diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3143index 43901f2..0d8b865 100644
3144--- a/arch/frv/include/asm/kmap_types.h
3145+++ b/arch/frv/include/asm/kmap_types.h
3146@@ -2,6 +2,6 @@
3147 #ifndef _ASM_KMAP_TYPES_H
3148 #define _ASM_KMAP_TYPES_H
3149
3150-#define KM_TYPE_NR 17
3151+#define KM_TYPE_NR 18
3152
3153 #endif
3154diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3155index 385fd30..3aaf4fe 100644
3156--- a/arch/frv/mm/elf-fdpic.c
3157+++ b/arch/frv/mm/elf-fdpic.c
3158@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3159 {
3160 struct vm_area_struct *vma;
3161 unsigned long limit;
3162+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3163
3164 if (len > TASK_SIZE)
3165 return -ENOMEM;
3166@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3167 if (addr) {
3168 addr = PAGE_ALIGN(addr);
3169 vma = find_vma(current->mm, addr);
3170- if (TASK_SIZE - len >= addr &&
3171- (!vma || addr + len <= vma->vm_start))
3172+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3173 goto success;
3174 }
3175
3176@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3177 for (; vma; vma = vma->vm_next) {
3178 if (addr > limit)
3179 break;
3180- if (addr + len <= vma->vm_start)
3181+ if (check_heap_stack_gap(vma, addr, len, offset))
3182 goto success;
3183 addr = vma->vm_end;
3184 }
3185@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3186 for (; vma; vma = vma->vm_next) {
3187 if (addr > limit)
3188 break;
3189- if (addr + len <= vma->vm_start)
3190+ if (check_heap_stack_gap(vma, addr, len, offset))
3191 goto success;
3192 addr = vma->vm_end;
3193 }
3194diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3195index f4ca594..adc72fd6 100644
3196--- a/arch/hexagon/include/asm/cache.h
3197+++ b/arch/hexagon/include/asm/cache.h
3198@@ -21,9 +21,11 @@
3199 #ifndef __ASM_CACHE_H
3200 #define __ASM_CACHE_H
3201
3202+#include <linux/const.h>
3203+
3204 /* Bytes per L1 cache line */
3205-#define L1_CACHE_SHIFT (5)
3206-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3207+#define L1_CACHE_SHIFT 5
3208+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3209
3210 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3211 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3212diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3213index 6e6fe18..a6ae668 100644
3214--- a/arch/ia64/include/asm/atomic.h
3215+++ b/arch/ia64/include/asm/atomic.h
3216@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3217 #define atomic64_inc(v) atomic64_add(1, (v))
3218 #define atomic64_dec(v) atomic64_sub(1, (v))
3219
3220+#define atomic64_read_unchecked(v) atomic64_read(v)
3221+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3222+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3223+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3224+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3225+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3226+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3227+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3228+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3229+
3230 /* Atomic operations are already serializing */
3231 #define smp_mb__before_atomic_dec() barrier()
3232 #define smp_mb__after_atomic_dec() barrier()
3233diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3234index 988254a..e1ee885 100644
3235--- a/arch/ia64/include/asm/cache.h
3236+++ b/arch/ia64/include/asm/cache.h
3237@@ -1,6 +1,7 @@
3238 #ifndef _ASM_IA64_CACHE_H
3239 #define _ASM_IA64_CACHE_H
3240
3241+#include <linux/const.h>
3242
3243 /*
3244 * Copyright (C) 1998-2000 Hewlett-Packard Co
3245@@ -9,7 +10,7 @@
3246
3247 /* Bytes per L1 (data) cache line. */
3248 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3249-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3250+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3251
3252 #ifdef CONFIG_SMP
3253 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3254diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3255index b5298eb..67c6e62 100644
3256--- a/arch/ia64/include/asm/elf.h
3257+++ b/arch/ia64/include/asm/elf.h
3258@@ -42,6 +42,13 @@
3259 */
3260 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3261
3262+#ifdef CONFIG_PAX_ASLR
3263+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3264+
3265+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3266+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3267+#endif
3268+
3269 #define PT_IA_64_UNWIND 0x70000001
3270
3271 /* IA-64 relocations: */
3272diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3273index 96a8d92..617a1cf 100644
3274--- a/arch/ia64/include/asm/pgalloc.h
3275+++ b/arch/ia64/include/asm/pgalloc.h
3276@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3277 pgd_val(*pgd_entry) = __pa(pud);
3278 }
3279
3280+static inline void
3281+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3282+{
3283+ pgd_populate(mm, pgd_entry, pud);
3284+}
3285+
3286 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3287 {
3288 return quicklist_alloc(0, GFP_KERNEL, NULL);
3289@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3290 pud_val(*pud_entry) = __pa(pmd);
3291 }
3292
3293+static inline void
3294+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3295+{
3296+ pud_populate(mm, pud_entry, pmd);
3297+}
3298+
3299 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3300 {
3301 return quicklist_alloc(0, GFP_KERNEL, NULL);
3302diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3303index 815810c..d60bd4c 100644
3304--- a/arch/ia64/include/asm/pgtable.h
3305+++ b/arch/ia64/include/asm/pgtable.h
3306@@ -12,7 +12,7 @@
3307 * David Mosberger-Tang <davidm@hpl.hp.com>
3308 */
3309
3310-
3311+#include <linux/const.h>
3312 #include <asm/mman.h>
3313 #include <asm/page.h>
3314 #include <asm/processor.h>
3315@@ -142,6 +142,17 @@
3316 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3317 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3318 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3319+
3320+#ifdef CONFIG_PAX_PAGEEXEC
3321+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3322+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3323+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3324+#else
3325+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3326+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3327+# define PAGE_COPY_NOEXEC PAGE_COPY
3328+#endif
3329+
3330 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3331 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3332 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3333diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3334index 54ff557..70c88b7 100644
3335--- a/arch/ia64/include/asm/spinlock.h
3336+++ b/arch/ia64/include/asm/spinlock.h
3337@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3338 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3339
3340 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3341- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3342+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3343 }
3344
3345 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3346diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3347index 449c8c0..50cdf87 100644
3348--- a/arch/ia64/include/asm/uaccess.h
3349+++ b/arch/ia64/include/asm/uaccess.h
3350@@ -42,6 +42,8 @@
3351 #include <asm/pgtable.h>
3352 #include <asm/io.h>
3353
3354+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3355+
3356 /*
3357 * For historical reasons, the following macros are grossly misnamed:
3358 */
3359@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3360 static inline unsigned long
3361 __copy_to_user (void __user *to, const void *from, unsigned long count)
3362 {
3363+ if (count > INT_MAX)
3364+ return count;
3365+
3366+ if (!__builtin_constant_p(count))
3367+ check_object_size(from, count, true);
3368+
3369 return __copy_user(to, (__force void __user *) from, count);
3370 }
3371
3372 static inline unsigned long
3373 __copy_from_user (void *to, const void __user *from, unsigned long count)
3374 {
3375+ if (count > INT_MAX)
3376+ return count;
3377+
3378+ if (!__builtin_constant_p(count))
3379+ check_object_size(to, count, false);
3380+
3381 return __copy_user((__force void __user *) to, from, count);
3382 }
3383
3384@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3385 ({ \
3386 void __user *__cu_to = (to); \
3387 const void *__cu_from = (from); \
3388- long __cu_len = (n); \
3389+ unsigned long __cu_len = (n); \
3390 \
3391- if (__access_ok(__cu_to, __cu_len, get_fs())) \
3392+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3393+ if (!__builtin_constant_p(n)) \
3394+ check_object_size(__cu_from, __cu_len, true); \
3395 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3396+ } \
3397 __cu_len; \
3398 })
3399
3400@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3401 ({ \
3402 void *__cu_to = (to); \
3403 const void __user *__cu_from = (from); \
3404- long __cu_len = (n); \
3405+ unsigned long __cu_len = (n); \
3406 \
3407 __chk_user_ptr(__cu_from); \
3408- if (__access_ok(__cu_from, __cu_len, get_fs())) \
3409+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3410+ if (!__builtin_constant_p(n)) \
3411+ check_object_size(__cu_to, __cu_len, false); \
3412 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3413+ } \
3414 __cu_len; \
3415 })
3416
3417diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3418index 24603be..948052d 100644
3419--- a/arch/ia64/kernel/module.c
3420+++ b/arch/ia64/kernel/module.c
3421@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3422 void
3423 module_free (struct module *mod, void *module_region)
3424 {
3425- if (mod && mod->arch.init_unw_table &&
3426- module_region == mod->module_init) {
3427+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3428 unw_remove_unwind_table(mod->arch.init_unw_table);
3429 mod->arch.init_unw_table = NULL;
3430 }
3431@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3432 }
3433
3434 static inline int
3435+in_init_rx (const struct module *mod, uint64_t addr)
3436+{
3437+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3438+}
3439+
3440+static inline int
3441+in_init_rw (const struct module *mod, uint64_t addr)
3442+{
3443+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3444+}
3445+
3446+static inline int
3447 in_init (const struct module *mod, uint64_t addr)
3448 {
3449- return addr - (uint64_t) mod->module_init < mod->init_size;
3450+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3451+}
3452+
3453+static inline int
3454+in_core_rx (const struct module *mod, uint64_t addr)
3455+{
3456+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3457+}
3458+
3459+static inline int
3460+in_core_rw (const struct module *mod, uint64_t addr)
3461+{
3462+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3463 }
3464
3465 static inline int
3466 in_core (const struct module *mod, uint64_t addr)
3467 {
3468- return addr - (uint64_t) mod->module_core < mod->core_size;
3469+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3470 }
3471
3472 static inline int
3473@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3474 break;
3475
3476 case RV_BDREL:
3477- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3478+ if (in_init_rx(mod, val))
3479+ val -= (uint64_t) mod->module_init_rx;
3480+ else if (in_init_rw(mod, val))
3481+ val -= (uint64_t) mod->module_init_rw;
3482+ else if (in_core_rx(mod, val))
3483+ val -= (uint64_t) mod->module_core_rx;
3484+ else if (in_core_rw(mod, val))
3485+ val -= (uint64_t) mod->module_core_rw;
3486 break;
3487
3488 case RV_LTV:
3489@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3490 * addresses have been selected...
3491 */
3492 uint64_t gp;
3493- if (mod->core_size > MAX_LTOFF)
3494+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3495 /*
3496 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3497 * at the end of the module.
3498 */
3499- gp = mod->core_size - MAX_LTOFF / 2;
3500+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3501 else
3502- gp = mod->core_size / 2;
3503- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3504+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3505+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3506 mod->arch.gp = gp;
3507 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3508 }
3509diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3510index d9439ef..d0cac6b 100644
3511--- a/arch/ia64/kernel/sys_ia64.c
3512+++ b/arch/ia64/kernel/sys_ia64.c
3513@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3514 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3515 struct mm_struct *mm = current->mm;
3516 struct vm_area_struct *vma;
3517+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3518
3519 if (len > RGN_MAP_LIMIT)
3520 return -ENOMEM;
3521@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3522 if (REGION_NUMBER(addr) == RGN_HPAGE)
3523 addr = 0;
3524 #endif
3525+
3526+#ifdef CONFIG_PAX_RANDMMAP
3527+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3528+ addr = mm->free_area_cache;
3529+ else
3530+#endif
3531+
3532 if (!addr)
3533 addr = mm->free_area_cache;
3534
3535@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3536 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3537 /* At this point: (!vma || addr < vma->vm_end). */
3538 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3539- if (start_addr != TASK_UNMAPPED_BASE) {
3540+ if (start_addr != mm->mmap_base) {
3541 /* Start a new search --- just in case we missed some holes. */
3542- addr = TASK_UNMAPPED_BASE;
3543+ addr = mm->mmap_base;
3544 goto full_search;
3545 }
3546 return -ENOMEM;
3547 }
3548- if (!vma || addr + len <= vma->vm_start) {
3549+ if (check_heap_stack_gap(vma, addr, len, offset)) {
3550 /* Remember the address where we stopped this search: */
3551 mm->free_area_cache = addr + len;
3552 return addr;
3553diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3554index c64460b..4d250a6 100644
3555--- a/arch/ia64/kernel/topology.c
3556+++ b/arch/ia64/kernel/topology.c
3557@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3558 return NOTIFY_OK;
3559 }
3560
3561-static struct notifier_block __cpuinitdata cache_cpu_notifier =
3562+static struct notifier_block cache_cpu_notifier =
3563 {
3564 .notifier_call = cache_cpu_callback
3565 };
3566diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3567index 0ccb28f..8992469 100644
3568--- a/arch/ia64/kernel/vmlinux.lds.S
3569+++ b/arch/ia64/kernel/vmlinux.lds.S
3570@@ -198,7 +198,7 @@ SECTIONS {
3571 /* Per-cpu data: */
3572 . = ALIGN(PERCPU_PAGE_SIZE);
3573 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3574- __phys_per_cpu_start = __per_cpu_load;
3575+ __phys_per_cpu_start = per_cpu_load;
3576 /*
3577 * ensure percpu data fits
3578 * into percpu page size
3579diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3580index 6cf0341..d352594 100644
3581--- a/arch/ia64/mm/fault.c
3582+++ b/arch/ia64/mm/fault.c
3583@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3584 return pte_present(pte);
3585 }
3586
3587+#ifdef CONFIG_PAX_PAGEEXEC
3588+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3589+{
3590+ unsigned long i;
3591+
3592+ printk(KERN_ERR "PAX: bytes at PC: ");
3593+ for (i = 0; i < 8; i++) {
3594+ unsigned int c;
3595+ if (get_user(c, (unsigned int *)pc+i))
3596+ printk(KERN_CONT "???????? ");
3597+ else
3598+ printk(KERN_CONT "%08x ", c);
3599+ }
3600+ printk("\n");
3601+}
3602+#endif
3603+
3604 # define VM_READ_BIT 0
3605 # define VM_WRITE_BIT 1
3606 # define VM_EXEC_BIT 2
3607@@ -149,8 +166,21 @@ retry:
3608 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3609 goto bad_area;
3610
3611- if ((vma->vm_flags & mask) != mask)
3612+ if ((vma->vm_flags & mask) != mask) {
3613+
3614+#ifdef CONFIG_PAX_PAGEEXEC
3615+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3616+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3617+ goto bad_area;
3618+
3619+ up_read(&mm->mmap_sem);
3620+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3621+ do_group_exit(SIGKILL);
3622+ }
3623+#endif
3624+
3625 goto bad_area;
3626+ }
3627
3628 /*
3629 * If for any reason at all we couldn't handle the fault, make
3630diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3631index 5ca674b..127c3cb 100644
3632--- a/arch/ia64/mm/hugetlbpage.c
3633+++ b/arch/ia64/mm/hugetlbpage.c
3634@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3635 unsigned long pgoff, unsigned long flags)
3636 {
3637 struct vm_area_struct *vmm;
3638+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3639
3640 if (len > RGN_MAP_LIMIT)
3641 return -ENOMEM;
3642@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3643 /* At this point: (!vmm || addr < vmm->vm_end). */
3644 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3645 return -ENOMEM;
3646- if (!vmm || (addr + len) <= vmm->vm_start)
3647+ if (check_heap_stack_gap(vmm, addr, len, offset))
3648 return addr;
3649 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3650 }
3651diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3652index 082e383..fb7be80 100644
3653--- a/arch/ia64/mm/init.c
3654+++ b/arch/ia64/mm/init.c
3655@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3656 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3657 vma->vm_end = vma->vm_start + PAGE_SIZE;
3658 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3659+
3660+#ifdef CONFIG_PAX_PAGEEXEC
3661+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3662+ vma->vm_flags &= ~VM_EXEC;
3663+
3664+#ifdef CONFIG_PAX_MPROTECT
3665+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
3666+ vma->vm_flags &= ~VM_MAYEXEC;
3667+#endif
3668+
3669+ }
3670+#endif
3671+
3672 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3673 down_write(&current->mm->mmap_sem);
3674 if (insert_vm_struct(current->mm, vma)) {
3675diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3676index 40b3ee9..8c2c112 100644
3677--- a/arch/m32r/include/asm/cache.h
3678+++ b/arch/m32r/include/asm/cache.h
3679@@ -1,8 +1,10 @@
3680 #ifndef _ASM_M32R_CACHE_H
3681 #define _ASM_M32R_CACHE_H
3682
3683+#include <linux/const.h>
3684+
3685 /* L1 cache line size */
3686 #define L1_CACHE_SHIFT 4
3687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3689
3690 #endif /* _ASM_M32R_CACHE_H */
3691diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3692index 82abd15..d95ae5d 100644
3693--- a/arch/m32r/lib/usercopy.c
3694+++ b/arch/m32r/lib/usercopy.c
3695@@ -14,6 +14,9 @@
3696 unsigned long
3697 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3698 {
3699+ if ((long)n < 0)
3700+ return n;
3701+
3702 prefetch(from);
3703 if (access_ok(VERIFY_WRITE, to, n))
3704 __copy_user(to,from,n);
3705@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3706 unsigned long
3707 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3708 {
3709+ if ((long)n < 0)
3710+ return n;
3711+
3712 prefetchw(to);
3713 if (access_ok(VERIFY_READ, from, n))
3714 __copy_user_zeroing(to,from,n);
3715diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3716index 0395c51..5f26031 100644
3717--- a/arch/m68k/include/asm/cache.h
3718+++ b/arch/m68k/include/asm/cache.h
3719@@ -4,9 +4,11 @@
3720 #ifndef __ARCH_M68K_CACHE_H
3721 #define __ARCH_M68K_CACHE_H
3722
3723+#include <linux/const.h>
3724+
3725 /* bytes per L1 cache line */
3726 #define L1_CACHE_SHIFT 4
3727-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3728+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3729
3730 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3731
3732diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3733index 4efe96a..60e8699 100644
3734--- a/arch/microblaze/include/asm/cache.h
3735+++ b/arch/microblaze/include/asm/cache.h
3736@@ -13,11 +13,12 @@
3737 #ifndef _ASM_MICROBLAZE_CACHE_H
3738 #define _ASM_MICROBLAZE_CACHE_H
3739
3740+#include <linux/const.h>
3741 #include <asm/registers.h>
3742
3743 #define L1_CACHE_SHIFT 5
3744 /* word-granular cache in microblaze */
3745-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3751index 01cc6ba..bcb7a5d 100644
3752--- a/arch/mips/include/asm/atomic.h
3753+++ b/arch/mips/include/asm/atomic.h
3754@@ -21,6 +21,10 @@
3755 #include <asm/cmpxchg.h>
3756 #include <asm/war.h>
3757
3758+#ifdef CONFIG_GENERIC_ATOMIC64
3759+#include <asm-generic/atomic64.h>
3760+#endif
3761+
3762 #define ATOMIC_INIT(i) { (i) }
3763
3764 /*
3765@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3766 */
3767 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3768
3769+#define atomic64_read_unchecked(v) atomic64_read(v)
3770+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3771+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3772+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3773+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3774+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3775+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3776+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3777+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3778+
3779 #endif /* CONFIG_64BIT */
3780
3781 /*
3782diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3783index b4db69f..8f3b093 100644
3784--- a/arch/mips/include/asm/cache.h
3785+++ b/arch/mips/include/asm/cache.h
3786@@ -9,10 +9,11 @@
3787 #ifndef _ASM_CACHE_H
3788 #define _ASM_CACHE_H
3789
3790+#include <linux/const.h>
3791 #include <kmalloc.h>
3792
3793 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3794-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3795+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3796
3797 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3799diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3800index 455c0ac..ad65fbe 100644
3801--- a/arch/mips/include/asm/elf.h
3802+++ b/arch/mips/include/asm/elf.h
3803@@ -372,13 +372,16 @@ extern const char *__elf_platform;
3804 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3805 #endif
3806
3807+#ifdef CONFIG_PAX_ASLR
3808+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3809+
3810+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3811+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3812+#endif
3813+
3814 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3815 struct linux_binprm;
3816 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3817 int uses_interp);
3818
3819-struct mm_struct;
3820-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3821-#define arch_randomize_brk arch_randomize_brk
3822-
3823 #endif /* _ASM_ELF_H */
3824diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3825index c1f6afa..38cc6e9 100644
3826--- a/arch/mips/include/asm/exec.h
3827+++ b/arch/mips/include/asm/exec.h
3828@@ -12,6 +12,6 @@
3829 #ifndef _ASM_EXEC_H
3830 #define _ASM_EXEC_H
3831
3832-extern unsigned long arch_align_stack(unsigned long sp);
3833+#define arch_align_stack(x) ((x) & ~0xfUL)
3834
3835 #endif /* _ASM_EXEC_H */
3836diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3837index da9bd7d..91aa7ab 100644
3838--- a/arch/mips/include/asm/page.h
3839+++ b/arch/mips/include/asm/page.h
3840@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3841 #ifdef CONFIG_CPU_MIPS32
3842 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3843 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3844- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3845+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3846 #else
3847 typedef struct { unsigned long long pte; } pte_t;
3848 #define pte_val(x) ((x).pte)
3849diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3850index 881d18b..cea38bc 100644
3851--- a/arch/mips/include/asm/pgalloc.h
3852+++ b/arch/mips/include/asm/pgalloc.h
3853@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3854 {
3855 set_pud(pud, __pud((unsigned long)pmd));
3856 }
3857+
3858+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3859+{
3860+ pud_populate(mm, pud, pmd);
3861+}
3862 #endif
3863
3864 /*
3865diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3866index 18806a5..141ffcf 100644
3867--- a/arch/mips/include/asm/thread_info.h
3868+++ b/arch/mips/include/asm/thread_info.h
3869@@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3870 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3871 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3872 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3873+/* li takes a 32bit immediate */
3874+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3875 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3876
3877 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3878@@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3879 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3880 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3881 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3882+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3883+
3884+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3885
3886 /* work to do in syscall_trace_leave() */
3887-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3888+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3889
3890 /* work to do on interrupt/exception return */
3891 #define _TIF_WORK_MASK \
3892 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3893 /* work to do on any return to u-space */
3894-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3895+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3896
3897 #endif /* __KERNEL__ */
3898
3899diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3900index 9fdd8bc..4bd7f1a 100644
3901--- a/arch/mips/kernel/binfmt_elfn32.c
3902+++ b/arch/mips/kernel/binfmt_elfn32.c
3903@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3904 #undef ELF_ET_DYN_BASE
3905 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3906
3907+#ifdef CONFIG_PAX_ASLR
3908+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3909+
3910+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3911+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3912+#endif
3913+
3914 #include <asm/processor.h>
3915 #include <linux/module.h>
3916 #include <linux/elfcore.h>
3917diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3918index ff44823..97f8906 100644
3919--- a/arch/mips/kernel/binfmt_elfo32.c
3920+++ b/arch/mips/kernel/binfmt_elfo32.c
3921@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3922 #undef ELF_ET_DYN_BASE
3923 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3924
3925+#ifdef CONFIG_PAX_ASLR
3926+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3927+
3928+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3929+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3930+#endif
3931+
3932 #include <asm/processor.h>
3933
3934 /*
3935diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3936index 69b17a9..9db82f9 100644
3937--- a/arch/mips/kernel/process.c
3938+++ b/arch/mips/kernel/process.c
3939@@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3940 out:
3941 return pc;
3942 }
3943-
3944-/*
3945- * Don't forget that the stack pointer must be aligned on a 8 bytes
3946- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3947- */
3948-unsigned long arch_align_stack(unsigned long sp)
3949-{
3950- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3951- sp -= get_random_int() & ~PAGE_MASK;
3952-
3953- return sp & ALMASK;
3954-}
3955diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3956index 4812c6d..2069554 100644
3957--- a/arch/mips/kernel/ptrace.c
3958+++ b/arch/mips/kernel/ptrace.c
3959@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3960 return arch;
3961 }
3962
3963+#ifdef CONFIG_GRKERNSEC_SETXID
3964+extern void gr_delayed_cred_worker(void);
3965+#endif
3966+
3967 /*
3968 * Notification of system call entry/exit
3969 * - triggered by current->work.syscall_trace
3970@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3971 /* do the secure computing check first */
3972 secure_computing_strict(regs->regs[2]);
3973
3974+#ifdef CONFIG_GRKERNSEC_SETXID
3975+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3976+ gr_delayed_cred_worker();
3977+#endif
3978+
3979 if (!(current->ptrace & PT_PTRACED))
3980 goto out;
3981
3982diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3983index 374f66e..1c882a0 100644
3984--- a/arch/mips/kernel/scall32-o32.S
3985+++ b/arch/mips/kernel/scall32-o32.S
3986@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3987
3988 stack_done:
3989 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3990- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3991+ li t1, _TIF_SYSCALL_WORK
3992 and t0, t1
3993 bnez t0, syscall_trace_entry # -> yes
3994
3995diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3996index 169de6a..f594a89 100644
3997--- a/arch/mips/kernel/scall64-64.S
3998+++ b/arch/mips/kernel/scall64-64.S
3999@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
4000
4001 sd a3, PT_R26(sp) # save a3 for syscall restarting
4002
4003- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4004+ li t1, _TIF_SYSCALL_WORK
4005 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4006 and t0, t1, t0
4007 bnez t0, syscall_trace_entry
4008diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
4009index 86ec03f..1235baf 100644
4010--- a/arch/mips/kernel/scall64-n32.S
4011+++ b/arch/mips/kernel/scall64-n32.S
4012@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
4013
4014 sd a3, PT_R26(sp) # save a3 for syscall restarting
4015
4016- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4017+ li t1, _TIF_SYSCALL_WORK
4018 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4019 and t0, t1, t0
4020 bnez t0, n32_syscall_trace_entry
4021diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
4022index 53c2d72..3734584 100644
4023--- a/arch/mips/kernel/scall64-o32.S
4024+++ b/arch/mips/kernel/scall64-o32.S
4025@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
4026 PTR 4b, bad_stack
4027 .previous
4028
4029- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
4030+ li t1, _TIF_SYSCALL_WORK
4031 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
4032 and t0, t1, t0
4033 bnez t0, trace_a_syscall
4034diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
4035index ddcec1e..c7f983e 100644
4036--- a/arch/mips/mm/fault.c
4037+++ b/arch/mips/mm/fault.c
4038@@ -27,6 +27,23 @@
4039 #include <asm/highmem.h> /* For VMALLOC_END */
4040 #include <linux/kdebug.h>
4041
4042+#ifdef CONFIG_PAX_PAGEEXEC
4043+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4044+{
4045+ unsigned long i;
4046+
4047+ printk(KERN_ERR "PAX: bytes at PC: ");
4048+ for (i = 0; i < 5; i++) {
4049+ unsigned int c;
4050+ if (get_user(c, (unsigned int *)pc+i))
4051+ printk(KERN_CONT "???????? ");
4052+ else
4053+ printk(KERN_CONT "%08x ", c);
4054+ }
4055+ printk("\n");
4056+}
4057+#endif
4058+
4059 /*
4060 * This routine handles page faults. It determines the address,
4061 * and the problem, and then passes it off to one of the appropriate
4062diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
4063index 302d779..6459dc0 100644
4064--- a/arch/mips/mm/mmap.c
4065+++ b/arch/mips/mm/mmap.c
4066@@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4067 struct vm_area_struct *vma;
4068 unsigned long addr = addr0;
4069 int do_color_align;
4070+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4071
4072 if (unlikely(len > TASK_SIZE))
4073 return -ENOMEM;
4074@@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4075 do_color_align = 1;
4076
4077 /* requesting a specific address */
4078+
4079+#ifdef CONFIG_PAX_RANDMMAP
4080+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4081+#endif
4082+
4083 if (addr) {
4084 if (do_color_align)
4085 addr = COLOUR_ALIGN(addr, pgoff);
4086@@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4087 addr = PAGE_ALIGN(addr);
4088
4089 vma = find_vma(mm, addr);
4090- if (TASK_SIZE - len >= addr &&
4091- (!vma || addr + len <= vma->vm_start))
4092+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4093 return addr;
4094 }
4095
4096@@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4097 /* At this point: (!vma || addr < vma->vm_end). */
4098 if (TASK_SIZE - len < addr)
4099 return -ENOMEM;
4100- if (!vma || addr + len <= vma->vm_start)
4101+ if (check_heap_stack_gap(vmm, addr, len, offset))
4102 return addr;
4103 addr = vma->vm_end;
4104 if (do_color_align)
4105@@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4106 /* make sure it can fit in the remaining address space */
4107 if (likely(addr > len)) {
4108 vma = find_vma(mm, addr - len);
4109- if (!vma || addr <= vma->vm_start) {
4110+ if (check_heap_stack_gap(vmm, addr - len, len, offset))
4111 /* cache the address as a hint for next time */
4112 return mm->free_area_cache = addr - len;
4113 }
4114@@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4115 goto bottomup;
4116
4117 addr = mm->mmap_base - len;
4118- if (do_color_align)
4119- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4120
4121 do {
4122+ if (do_color_align)
4123+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4124 /*
4125 * Lookup failure means no vma is above this address,
4126 * else if new region fits below vma->vm_start,
4127 * return with success:
4128 */
4129 vma = find_vma(mm, addr);
4130- if (likely(!vma || addr + len <= vma->vm_start)) {
4131+ if (check_heap_stack_gap(vmm, addr, len, offset)) {
4132 /* cache the address as a hint for next time */
4133 return mm->free_area_cache = addr;
4134 }
4135@@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4136 mm->cached_hole_size = vma->vm_start - addr;
4137
4138 /* try just below the current vma->vm_start */
4139- addr = vma->vm_start - len;
4140- if (do_color_align)
4141- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4142- } while (likely(len < vma->vm_start));
4143+ addr = skip_heap_stack_gap(vma, len, offset);
4144+ } while (!IS_ERR_VALUE(addr));
4145
4146 bottomup:
4147 /*
4148@@ -223,6 +226,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4149 {
4150 unsigned long random_factor = 0UL;
4151
4152+#ifdef CONFIG_PAX_RANDMMAP
4153+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4154+#endif
4155+
4156 if (current->flags & PF_RANDOMIZE) {
4157 random_factor = get_random_int();
4158 random_factor = random_factor << PAGE_SHIFT;
4159@@ -234,38 +241,23 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4160
4161 if (mmap_is_legacy()) {
4162 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4163+
4164+#ifdef CONFIG_PAX_RANDMMAP
4165+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4166+ mm->mmap_base += mm->delta_mmap;
4167+#endif
4168+
4169 mm->get_unmapped_area = arch_get_unmapped_area;
4170 mm->unmap_area = arch_unmap_area;
4171 } else {
4172 mm->mmap_base = mmap_base(random_factor);
4173+
4174+#ifdef CONFIG_PAX_RANDMMAP
4175+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4176+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4177+#endif
4178+
4179 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4180 mm->unmap_area = arch_unmap_area_topdown;
4181 }
4182 }
4183-
4184-static inline unsigned long brk_rnd(void)
4185-{
4186- unsigned long rnd = get_random_int();
4187-
4188- rnd = rnd << PAGE_SHIFT;
4189- /* 8MB for 32bit, 256MB for 64bit */
4190- if (TASK_IS_32BIT_ADDR)
4191- rnd = rnd & 0x7ffffful;
4192- else
4193- rnd = rnd & 0xffffffful;
4194-
4195- return rnd;
4196-}
4197-
4198-unsigned long arch_randomize_brk(struct mm_struct *mm)
4199-{
4200- unsigned long base = mm->brk;
4201- unsigned long ret;
4202-
4203- ret = PAGE_ALIGN(base + brk_rnd());
4204-
4205- if (ret < mm->brk)
4206- return mm->brk;
4207-
4208- return ret;
4209-}
4210diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4211index 967d144..db12197 100644
4212--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4213+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4214@@ -11,12 +11,14 @@
4215 #ifndef _ASM_PROC_CACHE_H
4216 #define _ASM_PROC_CACHE_H
4217
4218+#include <linux/const.h>
4219+
4220 /* L1 cache */
4221
4222 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4223 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4224-#define L1_CACHE_BYTES 16 /* bytes per entry */
4225 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4226+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4227 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4228
4229 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4230diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4231index bcb5df2..84fabd2 100644
4232--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4233+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4234@@ -16,13 +16,15 @@
4235 #ifndef _ASM_PROC_CACHE_H
4236 #define _ASM_PROC_CACHE_H
4237
4238+#include <linux/const.h>
4239+
4240 /*
4241 * L1 cache
4242 */
4243 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4244 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4245-#define L1_CACHE_BYTES 32 /* bytes per entry */
4246 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4247+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4248 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4249
4250 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4251diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4252index 4ce7a01..449202a 100644
4253--- a/arch/openrisc/include/asm/cache.h
4254+++ b/arch/openrisc/include/asm/cache.h
4255@@ -19,11 +19,13 @@
4256 #ifndef __ASM_OPENRISC_CACHE_H
4257 #define __ASM_OPENRISC_CACHE_H
4258
4259+#include <linux/const.h>
4260+
4261 /* FIXME: How can we replace these with values from the CPU...
4262 * they shouldn't be hard-coded!
4263 */
4264
4265-#define L1_CACHE_BYTES 16
4266 #define L1_CACHE_SHIFT 4
4267+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4268
4269 #endif /* __ASM_OPENRISC_CACHE_H */
4270diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4271index af9cf30..2aae9b2 100644
4272--- a/arch/parisc/include/asm/atomic.h
4273+++ b/arch/parisc/include/asm/atomic.h
4274@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4275
4276 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4277
4278+#define atomic64_read_unchecked(v) atomic64_read(v)
4279+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4280+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4281+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4282+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4283+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4284+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4285+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4286+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4287+
4288 #endif /* !CONFIG_64BIT */
4289
4290
4291diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4292index 47f11c7..3420df2 100644
4293--- a/arch/parisc/include/asm/cache.h
4294+++ b/arch/parisc/include/asm/cache.h
4295@@ -5,6 +5,7 @@
4296 #ifndef __ARCH_PARISC_CACHE_H
4297 #define __ARCH_PARISC_CACHE_H
4298
4299+#include <linux/const.h>
4300
4301 /*
4302 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4303@@ -15,13 +16,13 @@
4304 * just ruin performance.
4305 */
4306 #ifdef CONFIG_PA20
4307-#define L1_CACHE_BYTES 64
4308 #define L1_CACHE_SHIFT 6
4309 #else
4310-#define L1_CACHE_BYTES 32
4311 #define L1_CACHE_SHIFT 5
4312 #endif
4313
4314+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4315+
4316 #ifndef __ASSEMBLY__
4317
4318 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4319diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4320index 19f6cb1..6c78cf2 100644
4321--- a/arch/parisc/include/asm/elf.h
4322+++ b/arch/parisc/include/asm/elf.h
4323@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4324
4325 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4326
4327+#ifdef CONFIG_PAX_ASLR
4328+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4329+
4330+#define PAX_DELTA_MMAP_LEN 16
4331+#define PAX_DELTA_STACK_LEN 16
4332+#endif
4333+
4334 /* This yields a mask that user programs can use to figure out what
4335 instruction set this CPU supports. This could be done in user space,
4336 but it's not easy, and we've already done it here. */
4337diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4338index fc987a1..6e068ef 100644
4339--- a/arch/parisc/include/asm/pgalloc.h
4340+++ b/arch/parisc/include/asm/pgalloc.h
4341@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4342 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4343 }
4344
4345+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4346+{
4347+ pgd_populate(mm, pgd, pmd);
4348+}
4349+
4350 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4351 {
4352 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4353@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4354 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4355 #define pmd_free(mm, x) do { } while (0)
4356 #define pgd_populate(mm, pmd, pte) BUG()
4357+#define pgd_populate_kernel(mm, pmd, pte) BUG()
4358
4359 #endif
4360
4361diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4362index ee99f23..802b0a1 100644
4363--- a/arch/parisc/include/asm/pgtable.h
4364+++ b/arch/parisc/include/asm/pgtable.h
4365@@ -212,6 +212,17 @@ struct vm_area_struct;
4366 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4367 #define PAGE_COPY PAGE_EXECREAD
4368 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4369+
4370+#ifdef CONFIG_PAX_PAGEEXEC
4371+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4372+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4373+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4374+#else
4375+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4376+# define PAGE_COPY_NOEXEC PAGE_COPY
4377+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4378+#endif
4379+
4380 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4381 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4382 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4383diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4384index 4ba2c93..f5e3974 100644
4385--- a/arch/parisc/include/asm/uaccess.h
4386+++ b/arch/parisc/include/asm/uaccess.h
4387@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4388 const void __user *from,
4389 unsigned long n)
4390 {
4391- int sz = __compiletime_object_size(to);
4392+ size_t sz = __compiletime_object_size(to);
4393 int ret = -EFAULT;
4394
4395- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4396+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4397 ret = __copy_from_user(to, from, n);
4398 else
4399 copy_from_user_overflow();
4400diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4401index 5e34ccf..672bc9c 100644
4402--- a/arch/parisc/kernel/module.c
4403+++ b/arch/parisc/kernel/module.c
4404@@ -98,16 +98,38 @@
4405
4406 /* three functions to determine where in the module core
4407 * or init pieces the location is */
4408+static inline int in_init_rx(struct module *me, void *loc)
4409+{
4410+ return (loc >= me->module_init_rx &&
4411+ loc < (me->module_init_rx + me->init_size_rx));
4412+}
4413+
4414+static inline int in_init_rw(struct module *me, void *loc)
4415+{
4416+ return (loc >= me->module_init_rw &&
4417+ loc < (me->module_init_rw + me->init_size_rw));
4418+}
4419+
4420 static inline int in_init(struct module *me, void *loc)
4421 {
4422- return (loc >= me->module_init &&
4423- loc <= (me->module_init + me->init_size));
4424+ return in_init_rx(me, loc) || in_init_rw(me, loc);
4425+}
4426+
4427+static inline int in_core_rx(struct module *me, void *loc)
4428+{
4429+ return (loc >= me->module_core_rx &&
4430+ loc < (me->module_core_rx + me->core_size_rx));
4431+}
4432+
4433+static inline int in_core_rw(struct module *me, void *loc)
4434+{
4435+ return (loc >= me->module_core_rw &&
4436+ loc < (me->module_core_rw + me->core_size_rw));
4437 }
4438
4439 static inline int in_core(struct module *me, void *loc)
4440 {
4441- return (loc >= me->module_core &&
4442- loc <= (me->module_core + me->core_size));
4443+ return in_core_rx(me, loc) || in_core_rw(me, loc);
4444 }
4445
4446 static inline int in_local(struct module *me, void *loc)
4447@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4448 }
4449
4450 /* align things a bit */
4451- me->core_size = ALIGN(me->core_size, 16);
4452- me->arch.got_offset = me->core_size;
4453- me->core_size += gots * sizeof(struct got_entry);
4454+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4455+ me->arch.got_offset = me->core_size_rw;
4456+ me->core_size_rw += gots * sizeof(struct got_entry);
4457
4458- me->core_size = ALIGN(me->core_size, 16);
4459- me->arch.fdesc_offset = me->core_size;
4460- me->core_size += fdescs * sizeof(Elf_Fdesc);
4461+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4462+ me->arch.fdesc_offset = me->core_size_rw;
4463+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4464
4465 me->arch.got_max = gots;
4466 me->arch.fdesc_max = fdescs;
4467@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4468
4469 BUG_ON(value == 0);
4470
4471- got = me->module_core + me->arch.got_offset;
4472+ got = me->module_core_rw + me->arch.got_offset;
4473 for (i = 0; got[i].addr; i++)
4474 if (got[i].addr == value)
4475 goto out;
4476@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4477 #ifdef CONFIG_64BIT
4478 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4479 {
4480- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4481+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4482
4483 if (!value) {
4484 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4485@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4486
4487 /* Create new one */
4488 fdesc->addr = value;
4489- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4490+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4491 return (Elf_Addr)fdesc;
4492 }
4493 #endif /* CONFIG_64BIT */
4494@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4495
4496 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4497 end = table + sechdrs[me->arch.unwind_section].sh_size;
4498- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4499+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4500
4501 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4502 me->arch.unwind_section, table, end, gp);
4503diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4504index f76c108..92bad82 100644
4505--- a/arch/parisc/kernel/sys_parisc.c
4506+++ b/arch/parisc/kernel/sys_parisc.c
4507@@ -33,9 +33,11 @@
4508 #include <linux/utsname.h>
4509 #include <linux/personality.h>
4510
4511-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4512+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4513+ unsigned long flags)
4514 {
4515 struct vm_area_struct *vma;
4516+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4517
4518 addr = PAGE_ALIGN(addr);
4519
4520@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4521 /* At this point: (!vma || addr < vma->vm_end). */
4522 if (TASK_SIZE - len < addr)
4523 return -ENOMEM;
4524- if (!vma || addr + len <= vma->vm_start)
4525+ if (check_heap_stack_gap(vma, addr, len, offset))
4526 return addr;
4527 addr = vma->vm_end;
4528 }
4529@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4530 return offset & 0x3FF000;
4531 }
4532
4533-static unsigned long get_shared_area(struct address_space *mapping,
4534- unsigned long addr, unsigned long len, unsigned long pgoff)
4535+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4536+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4537 {
4538 struct vm_area_struct *vma;
4539 int offset = mapping ? get_offset(mapping) : 0;
4540+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4541
4542 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4543
4544@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4545 /* At this point: (!vma || addr < vma->vm_end). */
4546 if (TASK_SIZE - len < addr)
4547 return -ENOMEM;
4548- if (!vma || addr + len <= vma->vm_start)
4549+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
4550 return addr;
4551 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4552 if (addr < vma->vm_end) /* handle wraparound */
4553@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4554 if (flags & MAP_FIXED)
4555 return addr;
4556 if (!addr)
4557- addr = TASK_UNMAPPED_BASE;
4558+ addr = current->mm->mmap_base;
4559
4560 if (filp) {
4561- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4562+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4563 } else if(flags & MAP_SHARED) {
4564- addr = get_shared_area(NULL, addr, len, pgoff);
4565+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4566 } else {
4567- addr = get_unshared_area(addr, len);
4568+ addr = get_unshared_area(filp, addr, len, flags);
4569 }
4570 return addr;
4571 }
4572diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4573index 45ba99f..8e22c33 100644
4574--- a/arch/parisc/kernel/traps.c
4575+++ b/arch/parisc/kernel/traps.c
4576@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4577
4578 down_read(&current->mm->mmap_sem);
4579 vma = find_vma(current->mm,regs->iaoq[0]);
4580- if (vma && (regs->iaoq[0] >= vma->vm_start)
4581- && (vma->vm_flags & VM_EXEC)) {
4582-
4583+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4584 fault_address = regs->iaoq[0];
4585 fault_space = regs->iasq[0];
4586
4587diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4588index 18162ce..94de376 100644
4589--- a/arch/parisc/mm/fault.c
4590+++ b/arch/parisc/mm/fault.c
4591@@ -15,6 +15,7 @@
4592 #include <linux/sched.h>
4593 #include <linux/interrupt.h>
4594 #include <linux/module.h>
4595+#include <linux/unistd.h>
4596
4597 #include <asm/uaccess.h>
4598 #include <asm/traps.h>
4599@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4600 static unsigned long
4601 parisc_acctyp(unsigned long code, unsigned int inst)
4602 {
4603- if (code == 6 || code == 16)
4604+ if (code == 6 || code == 7 || code == 16)
4605 return VM_EXEC;
4606
4607 switch (inst & 0xf0000000) {
4608@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4609 }
4610 #endif
4611
4612+#ifdef CONFIG_PAX_PAGEEXEC
4613+/*
4614+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4615+ *
4616+ * returns 1 when task should be killed
4617+ * 2 when rt_sigreturn trampoline was detected
4618+ * 3 when unpatched PLT trampoline was detected
4619+ */
4620+static int pax_handle_fetch_fault(struct pt_regs *regs)
4621+{
4622+
4623+#ifdef CONFIG_PAX_EMUPLT
4624+ int err;
4625+
4626+ do { /* PaX: unpatched PLT emulation */
4627+ unsigned int bl, depwi;
4628+
4629+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4630+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4631+
4632+ if (err)
4633+ break;
4634+
4635+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4636+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4637+
4638+ err = get_user(ldw, (unsigned int *)addr);
4639+ err |= get_user(bv, (unsigned int *)(addr+4));
4640+ err |= get_user(ldw2, (unsigned int *)(addr+8));
4641+
4642+ if (err)
4643+ break;
4644+
4645+ if (ldw == 0x0E801096U &&
4646+ bv == 0xEAC0C000U &&
4647+ ldw2 == 0x0E881095U)
4648+ {
4649+ unsigned int resolver, map;
4650+
4651+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4652+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4653+ if (err)
4654+ break;
4655+
4656+ regs->gr[20] = instruction_pointer(regs)+8;
4657+ regs->gr[21] = map;
4658+ regs->gr[22] = resolver;
4659+ regs->iaoq[0] = resolver | 3UL;
4660+ regs->iaoq[1] = regs->iaoq[0] + 4;
4661+ return 3;
4662+ }
4663+ }
4664+ } while (0);
4665+#endif
4666+
4667+#ifdef CONFIG_PAX_EMUTRAMP
4668+
4669+#ifndef CONFIG_PAX_EMUSIGRT
4670+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4671+ return 1;
4672+#endif
4673+
4674+ do { /* PaX: rt_sigreturn emulation */
4675+ unsigned int ldi1, ldi2, bel, nop;
4676+
4677+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4678+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4679+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4680+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4681+
4682+ if (err)
4683+ break;
4684+
4685+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4686+ ldi2 == 0x3414015AU &&
4687+ bel == 0xE4008200U &&
4688+ nop == 0x08000240U)
4689+ {
4690+ regs->gr[25] = (ldi1 & 2) >> 1;
4691+ regs->gr[20] = __NR_rt_sigreturn;
4692+ regs->gr[31] = regs->iaoq[1] + 16;
4693+ regs->sr[0] = regs->iasq[1];
4694+ regs->iaoq[0] = 0x100UL;
4695+ regs->iaoq[1] = regs->iaoq[0] + 4;
4696+ regs->iasq[0] = regs->sr[2];
4697+ regs->iasq[1] = regs->sr[2];
4698+ return 2;
4699+ }
4700+ } while (0);
4701+#endif
4702+
4703+ return 1;
4704+}
4705+
4706+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4707+{
4708+ unsigned long i;
4709+
4710+ printk(KERN_ERR "PAX: bytes at PC: ");
4711+ for (i = 0; i < 5; i++) {
4712+ unsigned int c;
4713+ if (get_user(c, (unsigned int *)pc+i))
4714+ printk(KERN_CONT "???????? ");
4715+ else
4716+ printk(KERN_CONT "%08x ", c);
4717+ }
4718+ printk("\n");
4719+}
4720+#endif
4721+
4722 int fixup_exception(struct pt_regs *regs)
4723 {
4724 const struct exception_table_entry *fix;
4725@@ -192,8 +303,33 @@ good_area:
4726
4727 acc_type = parisc_acctyp(code,regs->iir);
4728
4729- if ((vma->vm_flags & acc_type) != acc_type)
4730+ if ((vma->vm_flags & acc_type) != acc_type) {
4731+
4732+#ifdef CONFIG_PAX_PAGEEXEC
4733+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4734+ (address & ~3UL) == instruction_pointer(regs))
4735+ {
4736+ up_read(&mm->mmap_sem);
4737+ switch (pax_handle_fetch_fault(regs)) {
4738+
4739+#ifdef CONFIG_PAX_EMUPLT
4740+ case 3:
4741+ return;
4742+#endif
4743+
4744+#ifdef CONFIG_PAX_EMUTRAMP
4745+ case 2:
4746+ return;
4747+#endif
4748+
4749+ }
4750+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4751+ do_group_exit(SIGKILL);
4752+ }
4753+#endif
4754+
4755 goto bad_area;
4756+ }
4757
4758 /*
4759 * If for any reason at all we couldn't handle the fault, make
4760diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4761index e3b1d41..8e81edf 100644
4762--- a/arch/powerpc/include/asm/atomic.h
4763+++ b/arch/powerpc/include/asm/atomic.h
4764@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4765 return t1;
4766 }
4767
4768+#define atomic64_read_unchecked(v) atomic64_read(v)
4769+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4770+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4771+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4772+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4773+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4774+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4775+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4776+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4777+
4778 #endif /* __powerpc64__ */
4779
4780 #endif /* __KERNEL__ */
4781diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4782index 9e495c9..b6878e5 100644
4783--- a/arch/powerpc/include/asm/cache.h
4784+++ b/arch/powerpc/include/asm/cache.h
4785@@ -3,6 +3,7 @@
4786
4787 #ifdef __KERNEL__
4788
4789+#include <linux/const.h>
4790
4791 /* bytes per L1 cache line */
4792 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4793@@ -22,7 +23,7 @@
4794 #define L1_CACHE_SHIFT 7
4795 #endif
4796
4797-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4801
4802diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4803index 6abf0a1..459d0f1 100644
4804--- a/arch/powerpc/include/asm/elf.h
4805+++ b/arch/powerpc/include/asm/elf.h
4806@@ -28,8 +28,19 @@
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810-extern unsigned long randomize_et_dyn(unsigned long base);
4811-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4812+#define ELF_ET_DYN_BASE (0x20000000)
4813+
4814+#ifdef CONFIG_PAX_ASLR
4815+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4816+
4817+#ifdef __powerpc64__
4818+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4819+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4820+#else
4821+#define PAX_DELTA_MMAP_LEN 15
4822+#define PAX_DELTA_STACK_LEN 15
4823+#endif
4824+#endif
4825
4826 /*
4827 * Our registers are always unsigned longs, whether we're a 32 bit
4828@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4829 (0x7ff >> (PAGE_SHIFT - 12)) : \
4830 (0x3ffff >> (PAGE_SHIFT - 12)))
4831
4832-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4833-#define arch_randomize_brk arch_randomize_brk
4834-
4835-
4836 #ifdef CONFIG_SPU_BASE
4837 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4838 #define NT_SPU 1
4839diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4840index 8196e9c..d83a9f3 100644
4841--- a/arch/powerpc/include/asm/exec.h
4842+++ b/arch/powerpc/include/asm/exec.h
4843@@ -4,6 +4,6 @@
4844 #ifndef _ASM_POWERPC_EXEC_H
4845 #define _ASM_POWERPC_EXEC_H
4846
4847-extern unsigned long arch_align_stack(unsigned long sp);
4848+#define arch_align_stack(x) ((x) & ~0xfUL)
4849
4850 #endif /* _ASM_POWERPC_EXEC_H */
4851diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4852index 5acabbd..7ea14fa 100644
4853--- a/arch/powerpc/include/asm/kmap_types.h
4854+++ b/arch/powerpc/include/asm/kmap_types.h
4855@@ -10,7 +10,7 @@
4856 * 2 of the License, or (at your option) any later version.
4857 */
4858
4859-#define KM_TYPE_NR 16
4860+#define KM_TYPE_NR 17
4861
4862 #endif /* __KERNEL__ */
4863 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4864diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4865index 8565c25..2865190 100644
4866--- a/arch/powerpc/include/asm/mman.h
4867+++ b/arch/powerpc/include/asm/mman.h
4868@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4869 }
4870 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4871
4872-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4873+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4874 {
4875 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4876 }
4877diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4878index f072e97..b436dee 100644
4879--- a/arch/powerpc/include/asm/page.h
4880+++ b/arch/powerpc/include/asm/page.h
4881@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4882 * and needs to be executable. This means the whole heap ends
4883 * up being executable.
4884 */
4885-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4886- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4887+#define VM_DATA_DEFAULT_FLAGS32 \
4888+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4889+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4890
4891 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4892 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4893@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4894 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4895 #endif
4896
4897+#define ktla_ktva(addr) (addr)
4898+#define ktva_ktla(addr) (addr)
4899+
4900 /*
4901 * Use the top bit of the higher-level page table entries to indicate whether
4902 * the entries we point to contain hugepages. This works because we know that
4903diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4904index cd915d6..c10cee8 100644
4905--- a/arch/powerpc/include/asm/page_64.h
4906+++ b/arch/powerpc/include/asm/page_64.h
4907@@ -154,15 +154,18 @@ do { \
4908 * stack by default, so in the absence of a PT_GNU_STACK program header
4909 * we turn execute permission off.
4910 */
4911-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4912- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4913+#define VM_STACK_DEFAULT_FLAGS32 \
4914+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4915+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4916
4917 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4918 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4919
4920+#ifndef CONFIG_PAX_PAGEEXEC
4921 #define VM_STACK_DEFAULT_FLAGS \
4922 (is_32bit_task() ? \
4923 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4924+#endif
4925
4926 #include <asm-generic/getorder.h>
4927
4928diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4929index 292725c..f87ae14 100644
4930--- a/arch/powerpc/include/asm/pgalloc-64.h
4931+++ b/arch/powerpc/include/asm/pgalloc-64.h
4932@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4933 #ifndef CONFIG_PPC_64K_PAGES
4934
4935 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4936+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4937
4938 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4939 {
4940@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4941 pud_set(pud, (unsigned long)pmd);
4942 }
4943
4944+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4945+{
4946+ pud_populate(mm, pud, pmd);
4947+}
4948+
4949 #define pmd_populate(mm, pmd, pte_page) \
4950 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4951 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4952@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4953 #else /* CONFIG_PPC_64K_PAGES */
4954
4955 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4956+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4957
4958 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4959 pte_t *pte)
4960diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4961index a9cbd3b..3b67efa 100644
4962--- a/arch/powerpc/include/asm/pgtable.h
4963+++ b/arch/powerpc/include/asm/pgtable.h
4964@@ -2,6 +2,7 @@
4965 #define _ASM_POWERPC_PGTABLE_H
4966 #ifdef __KERNEL__
4967
4968+#include <linux/const.h>
4969 #ifndef __ASSEMBLY__
4970 #include <asm/processor.h> /* For TASK_SIZE */
4971 #include <asm/mmu.h>
4972diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4973index 4aad413..85d86bf 100644
4974--- a/arch/powerpc/include/asm/pte-hash32.h
4975+++ b/arch/powerpc/include/asm/pte-hash32.h
4976@@ -21,6 +21,7 @@
4977 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4978 #define _PAGE_USER 0x004 /* usermode access allowed */
4979 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4980+#define _PAGE_EXEC _PAGE_GUARDED
4981 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4982 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4983 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4984diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4985index d24c141..b60696e 100644
4986--- a/arch/powerpc/include/asm/reg.h
4987+++ b/arch/powerpc/include/asm/reg.h
4988@@ -215,6 +215,7 @@
4989 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4990 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4991 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4992+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4993 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4994 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4995 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4996diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4997index 406b7b9..af63426 100644
4998--- a/arch/powerpc/include/asm/thread_info.h
4999+++ b/arch/powerpc/include/asm/thread_info.h
5000@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
5001 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
5002 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
5003 #define TIF_SINGLESTEP 8 /* singlestepping active */
5004-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
5005 #define TIF_SECCOMP 10 /* secure computing */
5006 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
5007 #define TIF_NOERROR 12 /* Force successful syscall return */
5008@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
5009 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
5010 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
5011 for stack store? */
5012+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
5013+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
5014+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
5015
5016 /* as above, but as bit values */
5017 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5018@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
5019 #define _TIF_UPROBE (1<<TIF_UPROBE)
5020 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5021 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
5022+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5023 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
5024- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
5025+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
5026+ _TIF_GRSEC_SETXID)
5027
5028 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
5029 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
5030diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
5031index 4db4959..335e00c 100644
5032--- a/arch/powerpc/include/asm/uaccess.h
5033+++ b/arch/powerpc/include/asm/uaccess.h
5034@@ -13,6 +13,8 @@
5035 #define VERIFY_READ 0
5036 #define VERIFY_WRITE 1
5037
5038+extern void check_object_size(const void *ptr, unsigned long n, bool to);
5039+
5040 /*
5041 * The fs value determines whether argument validity checking should be
5042 * performed or not. If get_fs() == USER_DS, checking is performed, with
5043@@ -318,52 +320,6 @@ do { \
5044 extern unsigned long __copy_tofrom_user(void __user *to,
5045 const void __user *from, unsigned long size);
5046
5047-#ifndef __powerpc64__
5048-
5049-static inline unsigned long copy_from_user(void *to,
5050- const void __user *from, unsigned long n)
5051-{
5052- unsigned long over;
5053-
5054- if (access_ok(VERIFY_READ, from, n))
5055- return __copy_tofrom_user((__force void __user *)to, from, n);
5056- if ((unsigned long)from < TASK_SIZE) {
5057- over = (unsigned long)from + n - TASK_SIZE;
5058- return __copy_tofrom_user((__force void __user *)to, from,
5059- n - over) + over;
5060- }
5061- return n;
5062-}
5063-
5064-static inline unsigned long copy_to_user(void __user *to,
5065- const void *from, unsigned long n)
5066-{
5067- unsigned long over;
5068-
5069- if (access_ok(VERIFY_WRITE, to, n))
5070- return __copy_tofrom_user(to, (__force void __user *)from, n);
5071- if ((unsigned long)to < TASK_SIZE) {
5072- over = (unsigned long)to + n - TASK_SIZE;
5073- return __copy_tofrom_user(to, (__force void __user *)from,
5074- n - over) + over;
5075- }
5076- return n;
5077-}
5078-
5079-#else /* __powerpc64__ */
5080-
5081-#define __copy_in_user(to, from, size) \
5082- __copy_tofrom_user((to), (from), (size))
5083-
5084-extern unsigned long copy_from_user(void *to, const void __user *from,
5085- unsigned long n);
5086-extern unsigned long copy_to_user(void __user *to, const void *from,
5087- unsigned long n);
5088-extern unsigned long copy_in_user(void __user *to, const void __user *from,
5089- unsigned long n);
5090-
5091-#endif /* __powerpc64__ */
5092-
5093 static inline unsigned long __copy_from_user_inatomic(void *to,
5094 const void __user *from, unsigned long n)
5095 {
5096@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
5097 if (ret == 0)
5098 return 0;
5099 }
5100+
5101+ if (!__builtin_constant_p(n))
5102+ check_object_size(to, n, false);
5103+
5104 return __copy_tofrom_user((__force void __user *)to, from, n);
5105 }
5106
5107@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5108 if (ret == 0)
5109 return 0;
5110 }
5111+
5112+ if (!__builtin_constant_p(n))
5113+ check_object_size(from, n, true);
5114+
5115 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5116 }
5117
5118@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5119 return __copy_to_user_inatomic(to, from, size);
5120 }
5121
5122+#ifndef __powerpc64__
5123+
5124+static inline unsigned long __must_check copy_from_user(void *to,
5125+ const void __user *from, unsigned long n)
5126+{
5127+ unsigned long over;
5128+
5129+ if ((long)n < 0)
5130+ return n;
5131+
5132+ if (access_ok(VERIFY_READ, from, n)) {
5133+ if (!__builtin_constant_p(n))
5134+ check_object_size(to, n, false);
5135+ return __copy_tofrom_user((__force void __user *)to, from, n);
5136+ }
5137+ if ((unsigned long)from < TASK_SIZE) {
5138+ over = (unsigned long)from + n - TASK_SIZE;
5139+ if (!__builtin_constant_p(n - over))
5140+ check_object_size(to, n - over, false);
5141+ return __copy_tofrom_user((__force void __user *)to, from,
5142+ n - over) + over;
5143+ }
5144+ return n;
5145+}
5146+
5147+static inline unsigned long __must_check copy_to_user(void __user *to,
5148+ const void *from, unsigned long n)
5149+{
5150+ unsigned long over;
5151+
5152+ if ((long)n < 0)
5153+ return n;
5154+
5155+ if (access_ok(VERIFY_WRITE, to, n)) {
5156+ if (!__builtin_constant_p(n))
5157+ check_object_size(from, n, true);
5158+ return __copy_tofrom_user(to, (__force void __user *)from, n);
5159+ }
5160+ if ((unsigned long)to < TASK_SIZE) {
5161+ over = (unsigned long)to + n - TASK_SIZE;
5162+ if (!__builtin_constant_p(n))
5163+ check_object_size(from, n - over, true);
5164+ return __copy_tofrom_user(to, (__force void __user *)from,
5165+ n - over) + over;
5166+ }
5167+ return n;
5168+}
5169+
5170+#else /* __powerpc64__ */
5171+
5172+#define __copy_in_user(to, from, size) \
5173+ __copy_tofrom_user((to), (from), (size))
5174+
5175+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5176+{
5177+ if ((long)n < 0 || n > INT_MAX)
5178+ return n;
5179+
5180+ if (!__builtin_constant_p(n))
5181+ check_object_size(to, n, false);
5182+
5183+ if (likely(access_ok(VERIFY_READ, from, n)))
5184+ n = __copy_from_user(to, from, n);
5185+ else
5186+ memset(to, 0, n);
5187+ return n;
5188+}
5189+
5190+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5191+{
5192+ if ((long)n < 0 || n > INT_MAX)
5193+ return n;
5194+
5195+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
5196+ if (!__builtin_constant_p(n))
5197+ check_object_size(from, n, true);
5198+ n = __copy_to_user(to, from, n);
5199+ }
5200+ return n;
5201+}
5202+
5203+extern unsigned long copy_in_user(void __user *to, const void __user *from,
5204+ unsigned long n);
5205+
5206+#endif /* __powerpc64__ */
5207+
5208 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5209
5210 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5211diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5212index 4684e33..acc4d19e 100644
5213--- a/arch/powerpc/kernel/exceptions-64e.S
5214+++ b/arch/powerpc/kernel/exceptions-64e.S
5215@@ -715,6 +715,7 @@ storage_fault_common:
5216 std r14,_DAR(r1)
5217 std r15,_DSISR(r1)
5218 addi r3,r1,STACK_FRAME_OVERHEAD
5219+ bl .save_nvgprs
5220 mr r4,r14
5221 mr r5,r15
5222 ld r14,PACA_EXGEN+EX_R14(r13)
5223@@ -723,8 +724,7 @@ storage_fault_common:
5224 cmpdi r3,0
5225 bne- 1f
5226 b .ret_from_except_lite
5227-1: bl .save_nvgprs
5228- mr r5,r3
5229+1: mr r5,r3
5230 addi r3,r1,STACK_FRAME_OVERHEAD
5231 ld r4,_DAR(r1)
5232 bl .bad_page_fault
5233diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5234index 10b658a..e542888 100644
5235--- a/arch/powerpc/kernel/exceptions-64s.S
5236+++ b/arch/powerpc/kernel/exceptions-64s.S
5237@@ -1013,10 +1013,10 @@ handle_page_fault:
5238 11: ld r4,_DAR(r1)
5239 ld r5,_DSISR(r1)
5240 addi r3,r1,STACK_FRAME_OVERHEAD
5241+ bl .save_nvgprs
5242 bl .do_page_fault
5243 cmpdi r3,0
5244 beq+ 12f
5245- bl .save_nvgprs
5246 mr r5,r3
5247 addi r3,r1,STACK_FRAME_OVERHEAD
5248 lwz r4,_DAR(r1)
5249diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5250index 2e3200c..72095ce 100644
5251--- a/arch/powerpc/kernel/module_32.c
5252+++ b/arch/powerpc/kernel/module_32.c
5253@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5254 me->arch.core_plt_section = i;
5255 }
5256 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5257- printk("Module doesn't contain .plt or .init.plt sections.\n");
5258+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5259 return -ENOEXEC;
5260 }
5261
5262@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5263
5264 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5265 /* Init, or core PLT? */
5266- if (location >= mod->module_core
5267- && location < mod->module_core + mod->core_size)
5268+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5269+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5270 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5271- else
5272+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5273+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5274 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5275+ else {
5276+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5277+ return ~0UL;
5278+ }
5279
5280 /* Find this entry, or if that fails, the next avail. entry */
5281 while (entry->jump[0]) {
5282diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5283index ba48233..16ac31d 100644
5284--- a/arch/powerpc/kernel/process.c
5285+++ b/arch/powerpc/kernel/process.c
5286@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5287 * Lookup NIP late so we have the best change of getting the
5288 * above info out without failing
5289 */
5290- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5291- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5292+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5293+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5294 #endif
5295 show_stack(current, (unsigned long *) regs->gpr[1]);
5296 if (!user_mode(regs))
5297@@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5298 newsp = stack[0];
5299 ip = stack[STACK_FRAME_LR_SAVE];
5300 if (!firstframe || ip != lr) {
5301- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5302+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5303 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5304 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5305- printk(" (%pS)",
5306+ printk(" (%pA)",
5307 (void *)current->ret_stack[curr_frame].ret);
5308 curr_frame--;
5309 }
5310@@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5311 struct pt_regs *regs = (struct pt_regs *)
5312 (sp + STACK_FRAME_OVERHEAD);
5313 lr = regs->link;
5314- printk("--- Exception: %lx at %pS\n LR = %pS\n",
5315+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
5316 regs->trap, (void *)regs->nip, (void *)lr);
5317 firstframe = 1;
5318 }
5319@@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5320 mtspr(SPRN_CTRLT, ctrl);
5321 }
5322 #endif /* CONFIG_PPC64 */
5323-
5324-unsigned long arch_align_stack(unsigned long sp)
5325-{
5326- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5327- sp -= get_random_int() & ~PAGE_MASK;
5328- return sp & ~0xf;
5329-}
5330-
5331-static inline unsigned long brk_rnd(void)
5332-{
5333- unsigned long rnd = 0;
5334-
5335- /* 8MB for 32bit, 1GB for 64bit */
5336- if (is_32bit_task())
5337- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5338- else
5339- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5340-
5341- return rnd << PAGE_SHIFT;
5342-}
5343-
5344-unsigned long arch_randomize_brk(struct mm_struct *mm)
5345-{
5346- unsigned long base = mm->brk;
5347- unsigned long ret;
5348-
5349-#ifdef CONFIG_PPC_STD_MMU_64
5350- /*
5351- * If we are using 1TB segments and we are allowed to randomise
5352- * the heap, we can put it above 1TB so it is backed by a 1TB
5353- * segment. Otherwise the heap will be in the bottom 1TB
5354- * which always uses 256MB segments and this may result in a
5355- * performance penalty.
5356- */
5357- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5358- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5359-#endif
5360-
5361- ret = PAGE_ALIGN(base + brk_rnd());
5362-
5363- if (ret < mm->brk)
5364- return mm->brk;
5365-
5366- return ret;
5367-}
5368-
5369-unsigned long randomize_et_dyn(unsigned long base)
5370-{
5371- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5372-
5373- if (ret < base)
5374- return base;
5375-
5376- return ret;
5377-}
5378diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5379index 79d8e56..38ffcbb 100644
5380--- a/arch/powerpc/kernel/ptrace.c
5381+++ b/arch/powerpc/kernel/ptrace.c
5382@@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5383 return ret;
5384 }
5385
5386+#ifdef CONFIG_GRKERNSEC_SETXID
5387+extern void gr_delayed_cred_worker(void);
5388+#endif
5389+
5390 /*
5391 * We must return the syscall number to actually look up in the table.
5392 * This can be -1L to skip running any syscall at all.
5393@@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5394
5395 secure_computing_strict(regs->gpr[0]);
5396
5397+#ifdef CONFIG_GRKERNSEC_SETXID
5398+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5399+ gr_delayed_cred_worker();
5400+#endif
5401+
5402 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5403 tracehook_report_syscall_entry(regs))
5404 /*
5405@@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5406 {
5407 int step;
5408
5409+#ifdef CONFIG_GRKERNSEC_SETXID
5410+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5411+ gr_delayed_cred_worker();
5412+#endif
5413+
5414 audit_syscall_exit(regs);
5415
5416 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5417diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5418index 804e323..79181c1 100644
5419--- a/arch/powerpc/kernel/signal_32.c
5420+++ b/arch/powerpc/kernel/signal_32.c
5421@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5422 /* Save user registers on the stack */
5423 frame = &rt_sf->uc.uc_mcontext;
5424 addr = frame;
5425- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5426+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5427 if (save_user_regs(regs, frame, 0, 1))
5428 goto badframe;
5429 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5430diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5431index d183f87..1867f1a 100644
5432--- a/arch/powerpc/kernel/signal_64.c
5433+++ b/arch/powerpc/kernel/signal_64.c
5434@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5435 current->thread.fpscr.val = 0;
5436
5437 /* Set up to return from userspace. */
5438- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5439+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5440 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5441 } else {
5442 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5443diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5444index 3251840..3f7c77a 100644
5445--- a/arch/powerpc/kernel/traps.c
5446+++ b/arch/powerpc/kernel/traps.c
5447@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5448 return flags;
5449 }
5450
5451+extern void gr_handle_kernel_exploit(void);
5452+
5453 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5454 int signr)
5455 {
5456@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5457 panic("Fatal exception in interrupt");
5458 if (panic_on_oops)
5459 panic("Fatal exception");
5460+
5461+ gr_handle_kernel_exploit();
5462+
5463 do_exit(signr);
5464 }
5465
5466diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5467index 1b2076f..835e4be 100644
5468--- a/arch/powerpc/kernel/vdso.c
5469+++ b/arch/powerpc/kernel/vdso.c
5470@@ -34,6 +34,7 @@
5471 #include <asm/firmware.h>
5472 #include <asm/vdso.h>
5473 #include <asm/vdso_datapage.h>
5474+#include <asm/mman.h>
5475
5476 #include "setup.h"
5477
5478@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5479 vdso_base = VDSO32_MBASE;
5480 #endif
5481
5482- current->mm->context.vdso_base = 0;
5483+ current->mm->context.vdso_base = ~0UL;
5484
5485 /* vDSO has a problem and was disabled, just don't "enable" it for the
5486 * process
5487@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5488 vdso_base = get_unmapped_area(NULL, vdso_base,
5489 (vdso_pages << PAGE_SHIFT) +
5490 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5491- 0, 0);
5492+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
5493 if (IS_ERR_VALUE(vdso_base)) {
5494 rc = vdso_base;
5495 goto fail_mmapsem;
5496diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5497index 5eea6f3..5d10396 100644
5498--- a/arch/powerpc/lib/usercopy_64.c
5499+++ b/arch/powerpc/lib/usercopy_64.c
5500@@ -9,22 +9,6 @@
5501 #include <linux/module.h>
5502 #include <asm/uaccess.h>
5503
5504-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5505-{
5506- if (likely(access_ok(VERIFY_READ, from, n)))
5507- n = __copy_from_user(to, from, n);
5508- else
5509- memset(to, 0, n);
5510- return n;
5511-}
5512-
5513-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5514-{
5515- if (likely(access_ok(VERIFY_WRITE, to, n)))
5516- n = __copy_to_user(to, from, n);
5517- return n;
5518-}
5519-
5520 unsigned long copy_in_user(void __user *to, const void __user *from,
5521 unsigned long n)
5522 {
5523@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5524 return n;
5525 }
5526
5527-EXPORT_SYMBOL(copy_from_user);
5528-EXPORT_SYMBOL(copy_to_user);
5529 EXPORT_SYMBOL(copy_in_user);
5530
5531diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5532index 0a6b283..7674925 100644
5533--- a/arch/powerpc/mm/fault.c
5534+++ b/arch/powerpc/mm/fault.c
5535@@ -32,6 +32,10 @@
5536 #include <linux/perf_event.h>
5537 #include <linux/magic.h>
5538 #include <linux/ratelimit.h>
5539+#include <linux/slab.h>
5540+#include <linux/pagemap.h>
5541+#include <linux/compiler.h>
5542+#include <linux/unistd.h>
5543
5544 #include <asm/firmware.h>
5545 #include <asm/page.h>
5546@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5547 }
5548 #endif
5549
5550+#ifdef CONFIG_PAX_PAGEEXEC
5551+/*
5552+ * PaX: decide what to do with offenders (regs->nip = fault address)
5553+ *
5554+ * returns 1 when task should be killed
5555+ */
5556+static int pax_handle_fetch_fault(struct pt_regs *regs)
5557+{
5558+ return 1;
5559+}
5560+
5561+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5562+{
5563+ unsigned long i;
5564+
5565+ printk(KERN_ERR "PAX: bytes at PC: ");
5566+ for (i = 0; i < 5; i++) {
5567+ unsigned int c;
5568+ if (get_user(c, (unsigned int __user *)pc+i))
5569+ printk(KERN_CONT "???????? ");
5570+ else
5571+ printk(KERN_CONT "%08x ", c);
5572+ }
5573+ printk("\n");
5574+}
5575+#endif
5576+
5577 /*
5578 * Check whether the instruction at regs->nip is a store using
5579 * an update addressing form which will update r1.
5580@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5581 * indicate errors in DSISR but can validly be set in SRR1.
5582 */
5583 if (trap == 0x400)
5584- error_code &= 0x48200000;
5585+ error_code &= 0x58200000;
5586 else
5587 is_write = error_code & DSISR_ISSTORE;
5588 #else
5589@@ -367,7 +398,7 @@ good_area:
5590 * "undefined". Of those that can be set, this is the only
5591 * one which seems bad.
5592 */
5593- if (error_code & 0x10000000)
5594+ if (error_code & DSISR_GUARDED)
5595 /* Guarded storage error. */
5596 goto bad_area;
5597 #endif /* CONFIG_8xx */
5598@@ -382,7 +413,7 @@ good_area:
5599 * processors use the same I/D cache coherency mechanism
5600 * as embedded.
5601 */
5602- if (error_code & DSISR_PROTFAULT)
5603+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5604 goto bad_area;
5605 #endif /* CONFIG_PPC_STD_MMU */
5606
5607@@ -465,6 +496,23 @@ bad_area:
5608 bad_area_nosemaphore:
5609 /* User mode accesses cause a SIGSEGV */
5610 if (user_mode(regs)) {
5611+
5612+#ifdef CONFIG_PAX_PAGEEXEC
5613+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5614+#ifdef CONFIG_PPC_STD_MMU
5615+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5616+#else
5617+ if (is_exec && regs->nip == address) {
5618+#endif
5619+ switch (pax_handle_fetch_fault(regs)) {
5620+ }
5621+
5622+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5623+ do_group_exit(SIGKILL);
5624+ }
5625+ }
5626+#endif
5627+
5628 _exception(SIGSEGV, regs, code, address);
5629 return 0;
5630 }
5631diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5632index 67a42ed..c16ef80 100644
5633--- a/arch/powerpc/mm/mmap_64.c
5634+++ b/arch/powerpc/mm/mmap_64.c
5635@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
5636 {
5637 unsigned long rnd = 0;
5638
5639+#ifdef CONFIG_PAX_RANDMMAP
5640+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5641+#endif
5642+
5643 if (current->flags & PF_RANDOMIZE) {
5644 /* 8MB for 32bit, 1GB for 64bit */
5645 if (is_32bit_task())
5646@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5647 */
5648 if (mmap_is_legacy()) {
5649 mm->mmap_base = TASK_UNMAPPED_BASE;
5650+
5651+#ifdef CONFIG_PAX_RANDMMAP
5652+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5653+ mm->mmap_base += mm->delta_mmap;
5654+#endif
5655+
5656 mm->get_unmapped_area = arch_get_unmapped_area;
5657 mm->unmap_area = arch_unmap_area;
5658 } else {
5659 mm->mmap_base = mmap_base();
5660+
5661+#ifdef CONFIG_PAX_RANDMMAP
5662+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5663+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5664+#endif
5665+
5666 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5667 mm->unmap_area = arch_unmap_area_topdown;
5668 }
5669diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5670index 5829d2a..af84242 100644
5671--- a/arch/powerpc/mm/slice.c
5672+++ b/arch/powerpc/mm/slice.c
5673@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5674 if ((mm->task_size - len) < addr)
5675 return 0;
5676 vma = find_vma(mm, addr);
5677- return (!vma || (addr + len) <= vma->vm_start);
5678+ return check_heap_stack_gap(vma, addr, len, 0);
5679 }
5680
5681 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5682@@ -272,7 +272,7 @@ full_search:
5683 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5684 continue;
5685 }
5686- if (!vma || addr + len <= vma->vm_start) {
5687+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5688 /*
5689 * Remember the place where we stopped the search:
5690 */
5691@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5692 }
5693 }
5694
5695- addr = mm->mmap_base;
5696- while (addr > len) {
5697+ if (mm->mmap_base < len)
5698+ addr = -ENOMEM;
5699+ else
5700+ addr = mm->mmap_base - len;
5701+
5702+ while (!IS_ERR_VALUE(addr)) {
5703 /* Go down by chunk size */
5704- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5705+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
5706
5707 /* Check for hit with different page size */
5708 mask = slice_range_to_mask(addr, len);
5709@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5710 * return with success:
5711 */
5712 vma = find_vma(mm, addr);
5713- if (!vma || (addr + len) <= vma->vm_start) {
5714+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5715 /* remember the address as a hint for next time */
5716 if (use_cache)
5717 mm->free_area_cache = addr;
5718@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5719 mm->cached_hole_size = vma->vm_start - addr;
5720
5721 /* try just below the current vma->vm_start */
5722- addr = vma->vm_start;
5723+ addr = skip_heap_stack_gap(vma, len, 0);
5724 }
5725
5726 /*
5727@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5728 if (fixed && addr > (mm->task_size - len))
5729 return -EINVAL;
5730
5731+#ifdef CONFIG_PAX_RANDMMAP
5732+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5733+ addr = 0;
5734+#endif
5735+
5736 /* If hint, make sure it matches our alignment restrictions */
5737 if (!fixed && addr) {
5738 addr = _ALIGN_UP(addr, 1ul << pshift);
5739diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5740index c797832..ce575c8 100644
5741--- a/arch/s390/include/asm/atomic.h
5742+++ b/arch/s390/include/asm/atomic.h
5743@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5744 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5745 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5746
5747+#define atomic64_read_unchecked(v) atomic64_read(v)
5748+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5749+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5750+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5751+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5752+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5753+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5754+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5755+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5756+
5757 #define smp_mb__before_atomic_dec() smp_mb()
5758 #define smp_mb__after_atomic_dec() smp_mb()
5759 #define smp_mb__before_atomic_inc() smp_mb()
5760diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5761index 4d7ccac..d03d0ad 100644
5762--- a/arch/s390/include/asm/cache.h
5763+++ b/arch/s390/include/asm/cache.h
5764@@ -9,8 +9,10 @@
5765 #ifndef __ARCH_S390_CACHE_H
5766 #define __ARCH_S390_CACHE_H
5767
5768-#define L1_CACHE_BYTES 256
5769+#include <linux/const.h>
5770+
5771 #define L1_CACHE_SHIFT 8
5772+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5773 #define NET_SKB_PAD 32
5774
5775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5776diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5777index 178ff96..8c93bd1 100644
5778--- a/arch/s390/include/asm/elf.h
5779+++ b/arch/s390/include/asm/elf.h
5780@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5781 the loader. We need to make sure that it is out of the way of the program
5782 that it will "exec", and that there is sufficient room for the brk. */
5783
5784-extern unsigned long randomize_et_dyn(unsigned long base);
5785-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5786+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5787+
5788+#ifdef CONFIG_PAX_ASLR
5789+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5790+
5791+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5792+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5793+#endif
5794
5795 /* This yields a mask that user programs can use to figure out what
5796 instruction set this CPU supports. */
5797@@ -210,9 +216,6 @@ struct linux_binprm;
5798 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5799 int arch_setup_additional_pages(struct linux_binprm *, int);
5800
5801-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5802-#define arch_randomize_brk arch_randomize_brk
5803-
5804 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5805
5806 #endif
5807diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5808index c4a93d6..4d2a9b4 100644
5809--- a/arch/s390/include/asm/exec.h
5810+++ b/arch/s390/include/asm/exec.h
5811@@ -7,6 +7,6 @@
5812 #ifndef __ASM_EXEC_H
5813 #define __ASM_EXEC_H
5814
5815-extern unsigned long arch_align_stack(unsigned long sp);
5816+#define arch_align_stack(x) ((x) & ~0xfUL)
5817
5818 #endif /* __ASM_EXEC_H */
5819diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5820index 34268df..ea97318 100644
5821--- a/arch/s390/include/asm/uaccess.h
5822+++ b/arch/s390/include/asm/uaccess.h
5823@@ -252,6 +252,10 @@ static inline unsigned long __must_check
5824 copy_to_user(void __user *to, const void *from, unsigned long n)
5825 {
5826 might_fault();
5827+
5828+ if ((long)n < 0)
5829+ return n;
5830+
5831 if (access_ok(VERIFY_WRITE, to, n))
5832 n = __copy_to_user(to, from, n);
5833 return n;
5834@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5835 static inline unsigned long __must_check
5836 __copy_from_user(void *to, const void __user *from, unsigned long n)
5837 {
5838+ if ((long)n < 0)
5839+ return n;
5840+
5841 if (__builtin_constant_p(n) && (n <= 256))
5842 return uaccess.copy_from_user_small(n, from, to);
5843 else
5844@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5845 static inline unsigned long __must_check
5846 copy_from_user(void *to, const void __user *from, unsigned long n)
5847 {
5848- unsigned int sz = __compiletime_object_size(to);
5849+ size_t sz = __compiletime_object_size(to);
5850
5851 might_fault();
5852- if (unlikely(sz != -1 && sz < n)) {
5853+
5854+ if ((long)n < 0)
5855+ return n;
5856+
5857+ if (unlikely(sz != (size_t)-1 && sz < n)) {
5858 copy_from_user_overflow();
5859 return n;
5860 }
5861diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5862index 4610dea..cf0af21 100644
5863--- a/arch/s390/kernel/module.c
5864+++ b/arch/s390/kernel/module.c
5865@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5866
5867 /* Increase core size by size of got & plt and set start
5868 offsets for got and plt. */
5869- me->core_size = ALIGN(me->core_size, 4);
5870- me->arch.got_offset = me->core_size;
5871- me->core_size += me->arch.got_size;
5872- me->arch.plt_offset = me->core_size;
5873- me->core_size += me->arch.plt_size;
5874+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
5875+ me->arch.got_offset = me->core_size_rw;
5876+ me->core_size_rw += me->arch.got_size;
5877+ me->arch.plt_offset = me->core_size_rx;
5878+ me->core_size_rx += me->arch.plt_size;
5879 return 0;
5880 }
5881
5882@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5883 if (info->got_initialized == 0) {
5884 Elf_Addr *gotent;
5885
5886- gotent = me->module_core + me->arch.got_offset +
5887+ gotent = me->module_core_rw + me->arch.got_offset +
5888 info->got_offset;
5889 *gotent = val;
5890 info->got_initialized = 1;
5891@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5892 else if (r_type == R_390_GOTENT ||
5893 r_type == R_390_GOTPLTENT)
5894 *(unsigned int *) loc =
5895- (val + (Elf_Addr) me->module_core - loc) >> 1;
5896+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5897 else if (r_type == R_390_GOT64 ||
5898 r_type == R_390_GOTPLT64)
5899 *(unsigned long *) loc = val;
5900@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5901 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5902 if (info->plt_initialized == 0) {
5903 unsigned int *ip;
5904- ip = me->module_core + me->arch.plt_offset +
5905+ ip = me->module_core_rx + me->arch.plt_offset +
5906 info->plt_offset;
5907 #ifndef CONFIG_64BIT
5908 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5909@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5910 val - loc + 0xffffUL < 0x1ffffeUL) ||
5911 (r_type == R_390_PLT32DBL &&
5912 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5913- val = (Elf_Addr) me->module_core +
5914+ val = (Elf_Addr) me->module_core_rx +
5915 me->arch.plt_offset +
5916 info->plt_offset;
5917 val += rela->r_addend - loc;
5918@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5919 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5920 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5921 val = val + rela->r_addend -
5922- ((Elf_Addr) me->module_core + me->arch.got_offset);
5923+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5924 if (r_type == R_390_GOTOFF16)
5925 *(unsigned short *) loc = val;
5926 else if (r_type == R_390_GOTOFF32)
5927@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5928 break;
5929 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5930 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5931- val = (Elf_Addr) me->module_core + me->arch.got_offset +
5932+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5933 rela->r_addend - loc;
5934 if (r_type == R_390_GOTPC)
5935 *(unsigned int *) loc = val;
5936diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5937index cd31ad4..201c5a3 100644
5938--- a/arch/s390/kernel/process.c
5939+++ b/arch/s390/kernel/process.c
5940@@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5941 }
5942 return 0;
5943 }
5944-
5945-unsigned long arch_align_stack(unsigned long sp)
5946-{
5947- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5948- sp -= get_random_int() & ~PAGE_MASK;
5949- return sp & ~0xf;
5950-}
5951-
5952-static inline unsigned long brk_rnd(void)
5953-{
5954- /* 8MB for 32bit, 1GB for 64bit */
5955- if (is_32bit_task())
5956- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5957- else
5958- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5959-}
5960-
5961-unsigned long arch_randomize_brk(struct mm_struct *mm)
5962-{
5963- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5964-
5965- if (ret < mm->brk)
5966- return mm->brk;
5967- return ret;
5968-}
5969-
5970-unsigned long randomize_et_dyn(unsigned long base)
5971-{
5972- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5973-
5974- if (!(current->flags & PF_RANDOMIZE))
5975- return base;
5976- if (ret < base)
5977- return base;
5978- return ret;
5979-}
5980diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5981index c59a5ef..3fae59c 100644
5982--- a/arch/s390/mm/mmap.c
5983+++ b/arch/s390/mm/mmap.c
5984@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5985 */
5986 if (mmap_is_legacy()) {
5987 mm->mmap_base = TASK_UNMAPPED_BASE;
5988+
5989+#ifdef CONFIG_PAX_RANDMMAP
5990+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5991+ mm->mmap_base += mm->delta_mmap;
5992+#endif
5993+
5994 mm->get_unmapped_area = arch_get_unmapped_area;
5995 mm->unmap_area = arch_unmap_area;
5996 } else {
5997 mm->mmap_base = mmap_base();
5998+
5999+#ifdef CONFIG_PAX_RANDMMAP
6000+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6001+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6002+#endif
6003+
6004 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6005 mm->unmap_area = arch_unmap_area_topdown;
6006 }
6007@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6008 */
6009 if (mmap_is_legacy()) {
6010 mm->mmap_base = TASK_UNMAPPED_BASE;
6011+
6012+#ifdef CONFIG_PAX_RANDMMAP
6013+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6014+ mm->mmap_base += mm->delta_mmap;
6015+#endif
6016+
6017 mm->get_unmapped_area = s390_get_unmapped_area;
6018 mm->unmap_area = arch_unmap_area;
6019 } else {
6020 mm->mmap_base = mmap_base();
6021+
6022+#ifdef CONFIG_PAX_RANDMMAP
6023+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6024+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6025+#endif
6026+
6027 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
6028 mm->unmap_area = arch_unmap_area_topdown;
6029 }
6030diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
6031index ae3d59f..f65f075 100644
6032--- a/arch/score/include/asm/cache.h
6033+++ b/arch/score/include/asm/cache.h
6034@@ -1,7 +1,9 @@
6035 #ifndef _ASM_SCORE_CACHE_H
6036 #define _ASM_SCORE_CACHE_H
6037
6038+#include <linux/const.h>
6039+
6040 #define L1_CACHE_SHIFT 4
6041-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6043
6044 #endif /* _ASM_SCORE_CACHE_H */
6045diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
6046index f9f3cd5..58ff438 100644
6047--- a/arch/score/include/asm/exec.h
6048+++ b/arch/score/include/asm/exec.h
6049@@ -1,6 +1,6 @@
6050 #ifndef _ASM_SCORE_EXEC_H
6051 #define _ASM_SCORE_EXEC_H
6052
6053-extern unsigned long arch_align_stack(unsigned long sp);
6054+#define arch_align_stack(x) (x)
6055
6056 #endif /* _ASM_SCORE_EXEC_H */
6057diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
6058index 637970c..0b6556b 100644
6059--- a/arch/score/kernel/process.c
6060+++ b/arch/score/kernel/process.c
6061@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
6062
6063 return task_pt_regs(task)->cp0_epc;
6064 }
6065-
6066-unsigned long arch_align_stack(unsigned long sp)
6067-{
6068- return sp;
6069-}
6070diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
6071index ef9e555..331bd29 100644
6072--- a/arch/sh/include/asm/cache.h
6073+++ b/arch/sh/include/asm/cache.h
6074@@ -9,10 +9,11 @@
6075 #define __ASM_SH_CACHE_H
6076 #ifdef __KERNEL__
6077
6078+#include <linux/const.h>
6079 #include <linux/init.h>
6080 #include <cpu/cache.h>
6081
6082-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6083+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6084
6085 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
6086
6087diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
6088index afeb710..e8366ef 100644
6089--- a/arch/sh/mm/mmap.c
6090+++ b/arch/sh/mm/mmap.c
6091@@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6092 struct vm_area_struct *vma;
6093 unsigned long start_addr;
6094 int do_colour_align;
6095+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6096
6097 if (flags & MAP_FIXED) {
6098 /* We do not accept a shared mapping if it would violate
6099@@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
6100 addr = PAGE_ALIGN(addr);
6101
6102 vma = find_vma(mm, addr);
6103- if (TASK_SIZE - len >= addr &&
6104- (!vma || addr + len <= vma->vm_start))
6105+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6106 return addr;
6107 }
6108
6109@@ -106,7 +106,7 @@ full_search:
6110 }
6111 return -ENOMEM;
6112 }
6113- if (likely(!vma || addr + len <= vma->vm_start)) {
6114+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6115 /*
6116 * Remember the place where we stopped the search:
6117 */
6118@@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6119 struct mm_struct *mm = current->mm;
6120 unsigned long addr = addr0;
6121 int do_colour_align;
6122+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6123
6124 if (flags & MAP_FIXED) {
6125 /* We do not accept a shared mapping if it would violate
6126@@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6127 addr = PAGE_ALIGN(addr);
6128
6129 vma = find_vma(mm, addr);
6130- if (TASK_SIZE - len >= addr &&
6131- (!vma || addr + len <= vma->vm_start))
6132+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6133 return addr;
6134 }
6135
6136@@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6137 /* make sure it can fit in the remaining address space */
6138 if (likely(addr > len)) {
6139 vma = find_vma(mm, addr-len);
6140- if (!vma || addr <= vma->vm_start) {
6141+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6142 /* remember the address as a hint for next time */
6143 return (mm->free_area_cache = addr-len);
6144 }
6145@@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6146 if (unlikely(mm->mmap_base < len))
6147 goto bottomup;
6148
6149- addr = mm->mmap_base-len;
6150- if (do_colour_align)
6151- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6152+ addr = mm->mmap_base - len;
6153
6154 do {
6155+ if (do_colour_align)
6156+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6157 /*
6158 * Lookup failure means no vma is above this address,
6159 * else if new region fits below vma->vm_start,
6160 * return with success:
6161 */
6162 vma = find_vma(mm, addr);
6163- if (likely(!vma || addr+len <= vma->vm_start)) {
6164+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6165 /* remember the address as a hint for next time */
6166 return (mm->free_area_cache = addr);
6167 }
6168@@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6169 mm->cached_hole_size = vma->vm_start - addr;
6170
6171 /* try just below the current vma->vm_start */
6172- addr = vma->vm_start-len;
6173- if (do_colour_align)
6174- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6175- } while (likely(len < vma->vm_start));
6176+ addr = skip_heap_stack_gap(vma, len, offset);
6177+ } while (!IS_ERR_VALUE(addr));
6178
6179 bottomup:
6180 /*
6181diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6182index be56a24..443328f 100644
6183--- a/arch/sparc/include/asm/atomic_64.h
6184+++ b/arch/sparc/include/asm/atomic_64.h
6185@@ -14,18 +14,40 @@
6186 #define ATOMIC64_INIT(i) { (i) }
6187
6188 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6189+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6190+{
6191+ return v->counter;
6192+}
6193 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6194+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6195+{
6196+ return v->counter;
6197+}
6198
6199 #define atomic_set(v, i) (((v)->counter) = i)
6200+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6201+{
6202+ v->counter = i;
6203+}
6204 #define atomic64_set(v, i) (((v)->counter) = i)
6205+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6206+{
6207+ v->counter = i;
6208+}
6209
6210 extern void atomic_add(int, atomic_t *);
6211+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6212 extern void atomic64_add(long, atomic64_t *);
6213+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6214 extern void atomic_sub(int, atomic_t *);
6215+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6216 extern void atomic64_sub(long, atomic64_t *);
6217+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6218
6219 extern int atomic_add_ret(int, atomic_t *);
6220+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6221 extern long atomic64_add_ret(long, atomic64_t *);
6222+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6223 extern int atomic_sub_ret(int, atomic_t *);
6224 extern long atomic64_sub_ret(long, atomic64_t *);
6225
6226@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6227 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6228
6229 #define atomic_inc_return(v) atomic_add_ret(1, v)
6230+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6231+{
6232+ return atomic_add_ret_unchecked(1, v);
6233+}
6234 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6235+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6236+{
6237+ return atomic64_add_ret_unchecked(1, v);
6238+}
6239
6240 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6241 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6242
6243 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6244+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6245+{
6246+ return atomic_add_ret_unchecked(i, v);
6247+}
6248 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6249+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6250+{
6251+ return atomic64_add_ret_unchecked(i, v);
6252+}
6253
6254 /*
6255 * atomic_inc_and_test - increment and test
6256@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6257 * other cases.
6258 */
6259 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6260+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6261+{
6262+ return atomic_inc_return_unchecked(v) == 0;
6263+}
6264 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6265
6266 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6267@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6268 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6269
6270 #define atomic_inc(v) atomic_add(1, v)
6271+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6272+{
6273+ atomic_add_unchecked(1, v);
6274+}
6275 #define atomic64_inc(v) atomic64_add(1, v)
6276+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6277+{
6278+ atomic64_add_unchecked(1, v);
6279+}
6280
6281 #define atomic_dec(v) atomic_sub(1, v)
6282+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6283+{
6284+ atomic_sub_unchecked(1, v);
6285+}
6286 #define atomic64_dec(v) atomic64_sub(1, v)
6287+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6288+{
6289+ atomic64_sub_unchecked(1, v);
6290+}
6291
6292 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6293 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6294
6295 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6296+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6297+{
6298+ return cmpxchg(&v->counter, old, new);
6299+}
6300 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6301+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6302+{
6303+ return xchg(&v->counter, new);
6304+}
6305
6306 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6307 {
6308- int c, old;
6309+ int c, old, new;
6310 c = atomic_read(v);
6311 for (;;) {
6312- if (unlikely(c == (u)))
6313+ if (unlikely(c == u))
6314 break;
6315- old = atomic_cmpxchg((v), c, c + (a));
6316+
6317+ asm volatile("addcc %2, %0, %0\n"
6318+
6319+#ifdef CONFIG_PAX_REFCOUNT
6320+ "tvs %%icc, 6\n"
6321+#endif
6322+
6323+ : "=r" (new)
6324+ : "0" (c), "ir" (a)
6325+ : "cc");
6326+
6327+ old = atomic_cmpxchg(v, c, new);
6328 if (likely(old == c))
6329 break;
6330 c = old;
6331@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6332 #define atomic64_cmpxchg(v, o, n) \
6333 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6334 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6335+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6336+{
6337+ return xchg(&v->counter, new);
6338+}
6339
6340 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6341 {
6342- long c, old;
6343+ long c, old, new;
6344 c = atomic64_read(v);
6345 for (;;) {
6346- if (unlikely(c == (u)))
6347+ if (unlikely(c == u))
6348 break;
6349- old = atomic64_cmpxchg((v), c, c + (a));
6350+
6351+ asm volatile("addcc %2, %0, %0\n"
6352+
6353+#ifdef CONFIG_PAX_REFCOUNT
6354+ "tvs %%xcc, 6\n"
6355+#endif
6356+
6357+ : "=r" (new)
6358+ : "0" (c), "ir" (a)
6359+ : "cc");
6360+
6361+ old = atomic64_cmpxchg(v, c, new);
6362 if (likely(old == c))
6363 break;
6364 c = old;
6365 }
6366- return c != (u);
6367+ return c != u;
6368 }
6369
6370 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6371diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6372index 5bb6991..5c2132e 100644
6373--- a/arch/sparc/include/asm/cache.h
6374+++ b/arch/sparc/include/asm/cache.h
6375@@ -7,10 +7,12 @@
6376 #ifndef _SPARC_CACHE_H
6377 #define _SPARC_CACHE_H
6378
6379+#include <linux/const.h>
6380+
6381 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6382
6383 #define L1_CACHE_SHIFT 5
6384-#define L1_CACHE_BYTES 32
6385+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6386
6387 #ifdef CONFIG_SPARC32
6388 #define SMP_CACHE_BYTES_SHIFT 5
6389diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6390index ac74a2c..a9e58af 100644
6391--- a/arch/sparc/include/asm/elf_32.h
6392+++ b/arch/sparc/include/asm/elf_32.h
6393@@ -114,6 +114,13 @@ typedef struct {
6394
6395 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6396
6397+#ifdef CONFIG_PAX_ASLR
6398+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6399+
6400+#define PAX_DELTA_MMAP_LEN 16
6401+#define PAX_DELTA_STACK_LEN 16
6402+#endif
6403+
6404 /* This yields a mask that user programs can use to figure out what
6405 instruction set this cpu supports. This can NOT be done in userspace
6406 on Sparc. */
6407diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6408index 370ca1e..d4f4a98 100644
6409--- a/arch/sparc/include/asm/elf_64.h
6410+++ b/arch/sparc/include/asm/elf_64.h
6411@@ -189,6 +189,13 @@ typedef struct {
6412 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6413 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6414
6415+#ifdef CONFIG_PAX_ASLR
6416+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6417+
6418+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6419+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6420+#endif
6421+
6422 extern unsigned long sparc64_elf_hwcap;
6423 #define ELF_HWCAP sparc64_elf_hwcap
6424
6425diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6426index 9b1c36d..209298b 100644
6427--- a/arch/sparc/include/asm/pgalloc_32.h
6428+++ b/arch/sparc/include/asm/pgalloc_32.h
6429@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6430 }
6431
6432 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6433+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6434
6435 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6436 unsigned long address)
6437diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6438index bcfe063..b333142 100644
6439--- a/arch/sparc/include/asm/pgalloc_64.h
6440+++ b/arch/sparc/include/asm/pgalloc_64.h
6441@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6442 }
6443
6444 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6445+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6446
6447 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6448 {
6449diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6450index 6fc1348..390c50a 100644
6451--- a/arch/sparc/include/asm/pgtable_32.h
6452+++ b/arch/sparc/include/asm/pgtable_32.h
6453@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6454 #define PAGE_SHARED SRMMU_PAGE_SHARED
6455 #define PAGE_COPY SRMMU_PAGE_COPY
6456 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6457+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6458+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6459+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6460 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6461
6462 /* Top-level page directory - dummy used by init-mm.
6463@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6464
6465 /* xwr */
6466 #define __P000 PAGE_NONE
6467-#define __P001 PAGE_READONLY
6468-#define __P010 PAGE_COPY
6469-#define __P011 PAGE_COPY
6470+#define __P001 PAGE_READONLY_NOEXEC
6471+#define __P010 PAGE_COPY_NOEXEC
6472+#define __P011 PAGE_COPY_NOEXEC
6473 #define __P100 PAGE_READONLY
6474 #define __P101 PAGE_READONLY
6475 #define __P110 PAGE_COPY
6476 #define __P111 PAGE_COPY
6477
6478 #define __S000 PAGE_NONE
6479-#define __S001 PAGE_READONLY
6480-#define __S010 PAGE_SHARED
6481-#define __S011 PAGE_SHARED
6482+#define __S001 PAGE_READONLY_NOEXEC
6483+#define __S010 PAGE_SHARED_NOEXEC
6484+#define __S011 PAGE_SHARED_NOEXEC
6485 #define __S100 PAGE_READONLY
6486 #define __S101 PAGE_READONLY
6487 #define __S110 PAGE_SHARED
6488diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6489index 79da178..c2eede8 100644
6490--- a/arch/sparc/include/asm/pgtsrmmu.h
6491+++ b/arch/sparc/include/asm/pgtsrmmu.h
6492@@ -115,6 +115,11 @@
6493 SRMMU_EXEC | SRMMU_REF)
6494 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6495 SRMMU_EXEC | SRMMU_REF)
6496+
6497+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6498+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6499+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6500+
6501 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6502 SRMMU_DIRTY | SRMMU_REF)
6503
6504diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6505index 9689176..63c18ea 100644
6506--- a/arch/sparc/include/asm/spinlock_64.h
6507+++ b/arch/sparc/include/asm/spinlock_64.h
6508@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6509
6510 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6511
6512-static void inline arch_read_lock(arch_rwlock_t *lock)
6513+static inline void arch_read_lock(arch_rwlock_t *lock)
6514 {
6515 unsigned long tmp1, tmp2;
6516
6517 __asm__ __volatile__ (
6518 "1: ldsw [%2], %0\n"
6519 " brlz,pn %0, 2f\n"
6520-"4: add %0, 1, %1\n"
6521+"4: addcc %0, 1, %1\n"
6522+
6523+#ifdef CONFIG_PAX_REFCOUNT
6524+" tvs %%icc, 6\n"
6525+#endif
6526+
6527 " cas [%2], %0, %1\n"
6528 " cmp %0, %1\n"
6529 " bne,pn %%icc, 1b\n"
6530@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6531 " .previous"
6532 : "=&r" (tmp1), "=&r" (tmp2)
6533 : "r" (lock)
6534- : "memory");
6535+ : "memory", "cc");
6536 }
6537
6538-static int inline arch_read_trylock(arch_rwlock_t *lock)
6539+static inline int arch_read_trylock(arch_rwlock_t *lock)
6540 {
6541 int tmp1, tmp2;
6542
6543@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6544 "1: ldsw [%2], %0\n"
6545 " brlz,a,pn %0, 2f\n"
6546 " mov 0, %0\n"
6547-" add %0, 1, %1\n"
6548+" addcc %0, 1, %1\n"
6549+
6550+#ifdef CONFIG_PAX_REFCOUNT
6551+" tvs %%icc, 6\n"
6552+#endif
6553+
6554 " cas [%2], %0, %1\n"
6555 " cmp %0, %1\n"
6556 " bne,pn %%icc, 1b\n"
6557@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6558 return tmp1;
6559 }
6560
6561-static void inline arch_read_unlock(arch_rwlock_t *lock)
6562+static inline void arch_read_unlock(arch_rwlock_t *lock)
6563 {
6564 unsigned long tmp1, tmp2;
6565
6566 __asm__ __volatile__(
6567 "1: lduw [%2], %0\n"
6568-" sub %0, 1, %1\n"
6569+" subcc %0, 1, %1\n"
6570+
6571+#ifdef CONFIG_PAX_REFCOUNT
6572+" tvs %%icc, 6\n"
6573+#endif
6574+
6575 " cas [%2], %0, %1\n"
6576 " cmp %0, %1\n"
6577 " bne,pn %%xcc, 1b\n"
6578@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6579 : "memory");
6580 }
6581
6582-static void inline arch_write_lock(arch_rwlock_t *lock)
6583+static inline void arch_write_lock(arch_rwlock_t *lock)
6584 {
6585 unsigned long mask, tmp1, tmp2;
6586
6587@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6588 : "memory");
6589 }
6590
6591-static void inline arch_write_unlock(arch_rwlock_t *lock)
6592+static inline void arch_write_unlock(arch_rwlock_t *lock)
6593 {
6594 __asm__ __volatile__(
6595 " stw %%g0, [%0]"
6596@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6597 : "memory");
6598 }
6599
6600-static int inline arch_write_trylock(arch_rwlock_t *lock)
6601+static inline int arch_write_trylock(arch_rwlock_t *lock)
6602 {
6603 unsigned long mask, tmp1, tmp2, result;
6604
6605diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6606index 25849ae..924c54b 100644
6607--- a/arch/sparc/include/asm/thread_info_32.h
6608+++ b/arch/sparc/include/asm/thread_info_32.h
6609@@ -49,6 +49,8 @@ struct thread_info {
6610 unsigned long w_saved;
6611
6612 struct restart_block restart_block;
6613+
6614+ unsigned long lowest_stack;
6615 };
6616
6617 /*
6618diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6619index a3fe4dc..cae132a 100644
6620--- a/arch/sparc/include/asm/thread_info_64.h
6621+++ b/arch/sparc/include/asm/thread_info_64.h
6622@@ -63,6 +63,8 @@ struct thread_info {
6623 struct pt_regs *kern_una_regs;
6624 unsigned int kern_una_insn;
6625
6626+ unsigned long lowest_stack;
6627+
6628 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6629 };
6630
6631@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6632 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6633 /* flag bit 6 is available */
6634 #define TIF_32BIT 7 /* 32-bit binary */
6635-/* flag bit 8 is available */
6636+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6637 #define TIF_SECCOMP 9 /* secure computing */
6638 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6639 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6640+
6641 /* NOTE: Thread flags >= 12 should be ones we have no interest
6642 * in using in assembly, else we can't use the mask as
6643 * an immediate value in instructions such as andcc.
6644@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6645 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6646 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6647 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6648+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6649
6650 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6651 _TIF_DO_NOTIFY_RESUME_MASK | \
6652 _TIF_NEED_RESCHED)
6653 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6654
6655+#define _TIF_WORK_SYSCALL \
6656+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6657+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6658+
6659+
6660 /*
6661 * Thread-synchronous status.
6662 *
6663diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6664index 0167d26..9acd8ed 100644
6665--- a/arch/sparc/include/asm/uaccess.h
6666+++ b/arch/sparc/include/asm/uaccess.h
6667@@ -1,5 +1,13 @@
6668 #ifndef ___ASM_SPARC_UACCESS_H
6669 #define ___ASM_SPARC_UACCESS_H
6670+
6671+#ifdef __KERNEL__
6672+#ifndef __ASSEMBLY__
6673+#include <linux/types.h>
6674+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6675+#endif
6676+#endif
6677+
6678 #if defined(__sparc__) && defined(__arch64__)
6679 #include <asm/uaccess_64.h>
6680 #else
6681diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6682index 53a28dd..50c38c3 100644
6683--- a/arch/sparc/include/asm/uaccess_32.h
6684+++ b/arch/sparc/include/asm/uaccess_32.h
6685@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6686
6687 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6688 {
6689- if (n && __access_ok((unsigned long) to, n))
6690+ if ((long)n < 0)
6691+ return n;
6692+
6693+ if (n && __access_ok((unsigned long) to, n)) {
6694+ if (!__builtin_constant_p(n))
6695+ check_object_size(from, n, true);
6696 return __copy_user(to, (__force void __user *) from, n);
6697- else
6698+ } else
6699 return n;
6700 }
6701
6702 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6703 {
6704+ if ((long)n < 0)
6705+ return n;
6706+
6707+ if (!__builtin_constant_p(n))
6708+ check_object_size(from, n, true);
6709+
6710 return __copy_user(to, (__force void __user *) from, n);
6711 }
6712
6713 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6714 {
6715- if (n && __access_ok((unsigned long) from, n))
6716+ if ((long)n < 0)
6717+ return n;
6718+
6719+ if (n && __access_ok((unsigned long) from, n)) {
6720+ if (!__builtin_constant_p(n))
6721+ check_object_size(to, n, false);
6722 return __copy_user((__force void __user *) to, from, n);
6723- else
6724+ } else
6725 return n;
6726 }
6727
6728 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6729 {
6730+ if ((long)n < 0)
6731+ return n;
6732+
6733 return __copy_user((__force void __user *) to, from, n);
6734 }
6735
6736diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6737index 73083e1..2bc62a6 100644
6738--- a/arch/sparc/include/asm/uaccess_64.h
6739+++ b/arch/sparc/include/asm/uaccess_64.h
6740@@ -10,6 +10,7 @@
6741 #include <linux/compiler.h>
6742 #include <linux/string.h>
6743 #include <linux/thread_info.h>
6744+#include <linux/kernel.h>
6745 #include <asm/asi.h>
6746 #include <asm/spitfire.h>
6747 #include <asm-generic/uaccess-unaligned.h>
6748@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6749 static inline unsigned long __must_check
6750 copy_from_user(void *to, const void __user *from, unsigned long size)
6751 {
6752- unsigned long ret = ___copy_from_user(to, from, size);
6753+ unsigned long ret;
6754
6755+ if ((long)size < 0 || size > INT_MAX)
6756+ return size;
6757+
6758+ if (!__builtin_constant_p(size))
6759+ check_object_size(to, size, false);
6760+
6761+ ret = ___copy_from_user(to, from, size);
6762 if (unlikely(ret))
6763 ret = copy_from_user_fixup(to, from, size);
6764
6765@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6766 static inline unsigned long __must_check
6767 copy_to_user(void __user *to, const void *from, unsigned long size)
6768 {
6769- unsigned long ret = ___copy_to_user(to, from, size);
6770+ unsigned long ret;
6771
6772+ if ((long)size < 0 || size > INT_MAX)
6773+ return size;
6774+
6775+ if (!__builtin_constant_p(size))
6776+ check_object_size(from, size, true);
6777+
6778+ ret = ___copy_to_user(to, from, size);
6779 if (unlikely(ret))
6780 ret = copy_to_user_fixup(to, from, size);
6781 return ret;
6782diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6783index 6cf591b..b49e65a 100644
6784--- a/arch/sparc/kernel/Makefile
6785+++ b/arch/sparc/kernel/Makefile
6786@@ -3,7 +3,7 @@
6787 #
6788
6789 asflags-y := -ansi
6790-ccflags-y := -Werror
6791+#ccflags-y := -Werror
6792
6793 extra-y := head_$(BITS).o
6794
6795diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6796index 487bffb..955a925 100644
6797--- a/arch/sparc/kernel/process_32.c
6798+++ b/arch/sparc/kernel/process_32.c
6799@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6800
6801 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6802 r->psr, r->pc, r->npc, r->y, print_tainted());
6803- printk("PC: <%pS>\n", (void *) r->pc);
6804+ printk("PC: <%pA>\n", (void *) r->pc);
6805 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6806 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6807 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6808 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6809 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6810 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6811- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6812+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6813
6814 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6815 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6816@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6817 rw = (struct reg_window32 *) fp;
6818 pc = rw->ins[7];
6819 printk("[%08lx : ", pc);
6820- printk("%pS ] ", (void *) pc);
6821+ printk("%pA ] ", (void *) pc);
6822 fp = rw->ins[6];
6823 } while (++count < 16);
6824 printk("\n");
6825diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6826index c6e0c29..052832b 100644
6827--- a/arch/sparc/kernel/process_64.c
6828+++ b/arch/sparc/kernel/process_64.c
6829@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6830 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6831 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6832 if (regs->tstate & TSTATE_PRIV)
6833- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6834+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6835 }
6836
6837 void show_regs(struct pt_regs *regs)
6838 {
6839 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6840 regs->tpc, regs->tnpc, regs->y, print_tainted());
6841- printk("TPC: <%pS>\n", (void *) regs->tpc);
6842+ printk("TPC: <%pA>\n", (void *) regs->tpc);
6843 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6844 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6845 regs->u_regs[3]);
6846@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6847 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6848 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6849 regs->u_regs[15]);
6850- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6851+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6852 show_regwindow(regs);
6853 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6854 }
6855@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6856 ((tp && tp->task) ? tp->task->pid : -1));
6857
6858 if (gp->tstate & TSTATE_PRIV) {
6859- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6860+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6861 (void *) gp->tpc,
6862 (void *) gp->o7,
6863 (void *) gp->i7,
6864diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6865index 7ff45e4..a58f271 100644
6866--- a/arch/sparc/kernel/ptrace_64.c
6867+++ b/arch/sparc/kernel/ptrace_64.c
6868@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6869 return ret;
6870 }
6871
6872+#ifdef CONFIG_GRKERNSEC_SETXID
6873+extern void gr_delayed_cred_worker(void);
6874+#endif
6875+
6876 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6877 {
6878 int ret = 0;
6879@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6880 /* do the secure computing check first */
6881 secure_computing_strict(regs->u_regs[UREG_G1]);
6882
6883+#ifdef CONFIG_GRKERNSEC_SETXID
6884+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6885+ gr_delayed_cred_worker();
6886+#endif
6887+
6888 if (test_thread_flag(TIF_SYSCALL_TRACE))
6889 ret = tracehook_report_syscall_entry(regs);
6890
6891@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6892
6893 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6894 {
6895+#ifdef CONFIG_GRKERNSEC_SETXID
6896+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6897+ gr_delayed_cred_worker();
6898+#endif
6899+
6900 audit_syscall_exit(regs);
6901
6902 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6903diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6904index 0c9b31b..55a8ba6 100644
6905--- a/arch/sparc/kernel/sys_sparc_32.c
6906+++ b/arch/sparc/kernel/sys_sparc_32.c
6907@@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6908 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6909 {
6910 struct vm_area_struct * vmm;
6911+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6912
6913 if (flags & MAP_FIXED) {
6914 /* We do not accept a shared mapping if it would violate
6915@@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6916 if (len > TASK_SIZE - PAGE_SIZE)
6917 return -ENOMEM;
6918 if (!addr)
6919- addr = TASK_UNMAPPED_BASE;
6920+ addr = current->mm->mmap_base;
6921
6922 if (flags & MAP_SHARED)
6923 addr = COLOUR_ALIGN(addr);
6924@@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6925 /* At this point: (!vmm || addr < vmm->vm_end). */
6926 if (TASK_SIZE - PAGE_SIZE - len < addr)
6927 return -ENOMEM;
6928- if (!vmm || addr + len <= vmm->vm_start)
6929+ if (check_heap_stack_gap(vmm, addr, len, offset))
6930 return addr;
6931 addr = vmm->vm_end;
6932 if (flags & MAP_SHARED)
6933diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6934index 878ef3d..f100719 100644
6935--- a/arch/sparc/kernel/sys_sparc_64.c
6936+++ b/arch/sparc/kernel/sys_sparc_64.c
6937@@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6938 unsigned long task_size = TASK_SIZE;
6939 unsigned long start_addr;
6940 int do_color_align;
6941+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6942
6943 if (flags & MAP_FIXED) {
6944 /* We do not accept a shared mapping if it would violate
6945 * cache aliasing constraints.
6946 */
6947- if ((flags & MAP_SHARED) &&
6948+ if ((filp || (flags & MAP_SHARED)) &&
6949 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6950 return -EINVAL;
6951 return addr;
6952@@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6953 if (filp || (flags & MAP_SHARED))
6954 do_color_align = 1;
6955
6956+#ifdef CONFIG_PAX_RANDMMAP
6957+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6958+#endif
6959+
6960 if (addr) {
6961 if (do_color_align)
6962 addr = COLOUR_ALIGN(addr, pgoff);
6963@@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6964 addr = PAGE_ALIGN(addr);
6965
6966 vma = find_vma(mm, addr);
6967- if (task_size - len >= addr &&
6968- (!vma || addr + len <= vma->vm_start))
6969+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6970 return addr;
6971 }
6972
6973 if (len > mm->cached_hole_size) {
6974- start_addr = addr = mm->free_area_cache;
6975+ start_addr = addr = mm->free_area_cache;
6976 } else {
6977- start_addr = addr = TASK_UNMAPPED_BASE;
6978+ start_addr = addr = mm->mmap_base;
6979 mm->cached_hole_size = 0;
6980 }
6981
6982@@ -157,14 +161,14 @@ full_search:
6983 vma = find_vma(mm, VA_EXCLUDE_END);
6984 }
6985 if (unlikely(task_size < addr)) {
6986- if (start_addr != TASK_UNMAPPED_BASE) {
6987- start_addr = addr = TASK_UNMAPPED_BASE;
6988+ if (start_addr != mm->mmap_base) {
6989+ start_addr = addr = mm->mmap_base;
6990 mm->cached_hole_size = 0;
6991 goto full_search;
6992 }
6993 return -ENOMEM;
6994 }
6995- if (likely(!vma || addr + len <= vma->vm_start)) {
6996+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6997 /*
6998 * Remember the place where we stopped the search:
6999 */
7000@@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7001 unsigned long task_size = STACK_TOP32;
7002 unsigned long addr = addr0;
7003 int do_color_align;
7004+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7005
7006 /* This should only ever run for 32-bit processes. */
7007 BUG_ON(!test_thread_flag(TIF_32BIT));
7008@@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7009 /* We do not accept a shared mapping if it would violate
7010 * cache aliasing constraints.
7011 */
7012- if ((flags & MAP_SHARED) &&
7013+ if ((filp || (flags & MAP_SHARED)) &&
7014 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
7015 return -EINVAL;
7016 return addr;
7017@@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7018 addr = PAGE_ALIGN(addr);
7019
7020 vma = find_vma(mm, addr);
7021- if (task_size - len >= addr &&
7022- (!vma || addr + len <= vma->vm_start))
7023+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7024 return addr;
7025 }
7026
7027@@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7028 /* make sure it can fit in the remaining address space */
7029 if (likely(addr > len)) {
7030 vma = find_vma(mm, addr-len);
7031- if (!vma || addr <= vma->vm_start) {
7032+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
7033 /* remember the address as a hint for next time */
7034 return (mm->free_area_cache = addr-len);
7035 }
7036@@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7037 if (unlikely(mm->mmap_base < len))
7038 goto bottomup;
7039
7040- addr = mm->mmap_base-len;
7041- if (do_color_align)
7042- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7043+ addr = mm->mmap_base - len;
7044
7045 do {
7046+ if (do_color_align)
7047+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7048 /*
7049 * Lookup failure means no vma is above this address,
7050 * else if new region fits below vma->vm_start,
7051 * return with success:
7052 */
7053 vma = find_vma(mm, addr);
7054- if (likely(!vma || addr+len <= vma->vm_start)) {
7055+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
7056 /* remember the address as a hint for next time */
7057 return (mm->free_area_cache = addr);
7058 }
7059@@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7060 mm->cached_hole_size = vma->vm_start - addr;
7061
7062 /* try just below the current vma->vm_start */
7063- addr = vma->vm_start-len;
7064- if (do_color_align)
7065- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
7066- } while (likely(len < vma->vm_start));
7067+ addr = skip_heap_stack_gap(vma, len, offset);
7068+ } while (!IS_ERR_VALUE(addr));
7069
7070 bottomup:
7071 /*
7072@@ -348,6 +350,10 @@ static unsigned long mmap_rnd(void)
7073 {
7074 unsigned long rnd = 0UL;
7075
7076+#ifdef CONFIG_PAX_RANDMMAP
7077+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7078+#endif
7079+
7080 if (current->flags & PF_RANDOMIZE) {
7081 unsigned long val = get_random_int();
7082 if (test_thread_flag(TIF_32BIT))
7083@@ -373,6 +379,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7084 gap == RLIM_INFINITY ||
7085 sysctl_legacy_va_layout) {
7086 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7087+
7088+#ifdef CONFIG_PAX_RANDMMAP
7089+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7090+ mm->mmap_base += mm->delta_mmap;
7091+#endif
7092+
7093 mm->get_unmapped_area = arch_get_unmapped_area;
7094 mm->unmap_area = arch_unmap_area;
7095 } else {
7096@@ -385,6 +397,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7097 gap = (task_size / 6 * 5);
7098
7099 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
7100+
7101+#ifdef CONFIG_PAX_RANDMMAP
7102+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7103+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7104+#endif
7105+
7106 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7107 mm->unmap_area = arch_unmap_area_topdown;
7108 }
7109diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
7110index bf23477..b7425a6 100644
7111--- a/arch/sparc/kernel/syscalls.S
7112+++ b/arch/sparc/kernel/syscalls.S
7113@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
7114 #endif
7115 .align 32
7116 1: ldx [%g6 + TI_FLAGS], %l5
7117- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7118+ andcc %l5, _TIF_WORK_SYSCALL, %g0
7119 be,pt %icc, rtrap
7120 nop
7121 call syscall_trace_leave
7122@@ -189,7 +189,7 @@ linux_sparc_syscall32:
7123
7124 srl %i5, 0, %o5 ! IEU1
7125 srl %i2, 0, %o2 ! IEU0 Group
7126- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7127+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7128 bne,pn %icc, linux_syscall_trace32 ! CTI
7129 mov %i0, %l5 ! IEU1
7130 call %l7 ! CTI Group brk forced
7131@@ -212,7 +212,7 @@ linux_sparc_syscall:
7132
7133 mov %i3, %o3 ! IEU1
7134 mov %i4, %o4 ! IEU0 Group
7135- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7136+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7137 bne,pn %icc, linux_syscall_trace ! CTI Group
7138 mov %i0, %l5 ! IEU0
7139 2: call %l7 ! CTI Group brk forced
7140@@ -228,7 +228,7 @@ ret_sys_call:
7141
7142 cmp %o0, -ERESTART_RESTARTBLOCK
7143 bgeu,pn %xcc, 1f
7144- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7145+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7146 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7147
7148 2:
7149diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7150index a5785ea..405c5f7 100644
7151--- a/arch/sparc/kernel/traps_32.c
7152+++ b/arch/sparc/kernel/traps_32.c
7153@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7154 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7155 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7156
7157+extern void gr_handle_kernel_exploit(void);
7158+
7159 void die_if_kernel(char *str, struct pt_regs *regs)
7160 {
7161 static int die_counter;
7162@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7163 count++ < 30 &&
7164 (((unsigned long) rw) >= PAGE_OFFSET) &&
7165 !(((unsigned long) rw) & 0x7)) {
7166- printk("Caller[%08lx]: %pS\n", rw->ins[7],
7167+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
7168 (void *) rw->ins[7]);
7169 rw = (struct reg_window32 *)rw->ins[6];
7170 }
7171 }
7172 printk("Instruction DUMP:");
7173 instruction_dump ((unsigned long *) regs->pc);
7174- if(regs->psr & PSR_PS)
7175+ if(regs->psr & PSR_PS) {
7176+ gr_handle_kernel_exploit();
7177 do_exit(SIGKILL);
7178+ }
7179 do_exit(SIGSEGV);
7180 }
7181
7182diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7183index b66a779..8e8d66c 100644
7184--- a/arch/sparc/kernel/traps_64.c
7185+++ b/arch/sparc/kernel/traps_64.c
7186@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7187 i + 1,
7188 p->trapstack[i].tstate, p->trapstack[i].tpc,
7189 p->trapstack[i].tnpc, p->trapstack[i].tt);
7190- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7191+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7192 }
7193 }
7194
7195@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7196
7197 lvl -= 0x100;
7198 if (regs->tstate & TSTATE_PRIV) {
7199+
7200+#ifdef CONFIG_PAX_REFCOUNT
7201+ if (lvl == 6)
7202+ pax_report_refcount_overflow(regs);
7203+#endif
7204+
7205 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7206 die_if_kernel(buffer, regs);
7207 }
7208@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7209 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7210 {
7211 char buffer[32];
7212-
7213+
7214 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7215 0, lvl, SIGTRAP) == NOTIFY_STOP)
7216 return;
7217
7218+#ifdef CONFIG_PAX_REFCOUNT
7219+ if (lvl == 6)
7220+ pax_report_refcount_overflow(regs);
7221+#endif
7222+
7223 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7224
7225 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7226@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7227 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7228 printk("%s" "ERROR(%d): ",
7229 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7230- printk("TPC<%pS>\n", (void *) regs->tpc);
7231+ printk("TPC<%pA>\n", (void *) regs->tpc);
7232 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7233 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7234 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7235@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7236 smp_processor_id(),
7237 (type & 0x1) ? 'I' : 'D',
7238 regs->tpc);
7239- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7240+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7241 panic("Irrecoverable Cheetah+ parity error.");
7242 }
7243
7244@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7245 smp_processor_id(),
7246 (type & 0x1) ? 'I' : 'D',
7247 regs->tpc);
7248- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7249+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7250 }
7251
7252 struct sun4v_error_entry {
7253@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7254
7255 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7256 regs->tpc, tl);
7257- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7258+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7259 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7260- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7261+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7262 (void *) regs->u_regs[UREG_I7]);
7263 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7264 "pte[%lx] error[%lx]\n",
7265@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7266
7267 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7268 regs->tpc, tl);
7269- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7270+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7271 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7272- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7273+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7274 (void *) regs->u_regs[UREG_I7]);
7275 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7276 "pte[%lx] error[%lx]\n",
7277@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7278 fp = (unsigned long)sf->fp + STACK_BIAS;
7279 }
7280
7281- printk(" [%016lx] %pS\n", pc, (void *) pc);
7282+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7283 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7284 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7285 int index = tsk->curr_ret_stack;
7286 if (tsk->ret_stack && index >= graph) {
7287 pc = tsk->ret_stack[index - graph].ret;
7288- printk(" [%016lx] %pS\n", pc, (void *) pc);
7289+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7290 graph++;
7291 }
7292 }
7293@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7294 return (struct reg_window *) (fp + STACK_BIAS);
7295 }
7296
7297+extern void gr_handle_kernel_exploit(void);
7298+
7299 void die_if_kernel(char *str, struct pt_regs *regs)
7300 {
7301 static int die_counter;
7302@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7303 while (rw &&
7304 count++ < 30 &&
7305 kstack_valid(tp, (unsigned long) rw)) {
7306- printk("Caller[%016lx]: %pS\n", rw->ins[7],
7307+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
7308 (void *) rw->ins[7]);
7309
7310 rw = kernel_stack_up(rw);
7311@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7312 }
7313 user_instruction_dump ((unsigned int __user *) regs->tpc);
7314 }
7315- if (regs->tstate & TSTATE_PRIV)
7316+ if (regs->tstate & TSTATE_PRIV) {
7317+ gr_handle_kernel_exploit();
7318 do_exit(SIGKILL);
7319+ }
7320 do_exit(SIGSEGV);
7321 }
7322 EXPORT_SYMBOL(die_if_kernel);
7323diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7324index 8201c25e..072a2a7 100644
7325--- a/arch/sparc/kernel/unaligned_64.c
7326+++ b/arch/sparc/kernel/unaligned_64.c
7327@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7328 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7329
7330 if (__ratelimit(&ratelimit)) {
7331- printk("Kernel unaligned access at TPC[%lx] %pS\n",
7332+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
7333 regs->tpc, (void *) regs->tpc);
7334 }
7335 }
7336diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7337index 8410065f2..4fd4ca22 100644
7338--- a/arch/sparc/lib/Makefile
7339+++ b/arch/sparc/lib/Makefile
7340@@ -2,7 +2,7 @@
7341 #
7342
7343 asflags-y := -ansi -DST_DIV0=0x02
7344-ccflags-y := -Werror
7345+#ccflags-y := -Werror
7346
7347 lib-$(CONFIG_SPARC32) += ashrdi3.o
7348 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7349diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7350index 85c233d..68500e0 100644
7351--- a/arch/sparc/lib/atomic_64.S
7352+++ b/arch/sparc/lib/atomic_64.S
7353@@ -17,7 +17,12 @@
7354 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7355 BACKOFF_SETUP(%o2)
7356 1: lduw [%o1], %g1
7357- add %g1, %o0, %g7
7358+ addcc %g1, %o0, %g7
7359+
7360+#ifdef CONFIG_PAX_REFCOUNT
7361+ tvs %icc, 6
7362+#endif
7363+
7364 cas [%o1], %g1, %g7
7365 cmp %g1, %g7
7366 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7367@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7368 2: BACKOFF_SPIN(%o2, %o3, 1b)
7369 ENDPROC(atomic_add)
7370
7371+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7372+ BACKOFF_SETUP(%o2)
7373+1: lduw [%o1], %g1
7374+ add %g1, %o0, %g7
7375+ cas [%o1], %g1, %g7
7376+ cmp %g1, %g7
7377+ bne,pn %icc, 2f
7378+ nop
7379+ retl
7380+ nop
7381+2: BACKOFF_SPIN(%o2, %o3, 1b)
7382+ENDPROC(atomic_add_unchecked)
7383+
7384 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7385 BACKOFF_SETUP(%o2)
7386 1: lduw [%o1], %g1
7387- sub %g1, %o0, %g7
7388+ subcc %g1, %o0, %g7
7389+
7390+#ifdef CONFIG_PAX_REFCOUNT
7391+ tvs %icc, 6
7392+#endif
7393+
7394 cas [%o1], %g1, %g7
7395 cmp %g1, %g7
7396 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7397@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7398 2: BACKOFF_SPIN(%o2, %o3, 1b)
7399 ENDPROC(atomic_sub)
7400
7401+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7402+ BACKOFF_SETUP(%o2)
7403+1: lduw [%o1], %g1
7404+ sub %g1, %o0, %g7
7405+ cas [%o1], %g1, %g7
7406+ cmp %g1, %g7
7407+ bne,pn %icc, 2f
7408+ nop
7409+ retl
7410+ nop
7411+2: BACKOFF_SPIN(%o2, %o3, 1b)
7412+ENDPROC(atomic_sub_unchecked)
7413+
7414 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7415 BACKOFF_SETUP(%o2)
7416 1: lduw [%o1], %g1
7417- add %g1, %o0, %g7
7418+ addcc %g1, %o0, %g7
7419+
7420+#ifdef CONFIG_PAX_REFCOUNT
7421+ tvs %icc, 6
7422+#endif
7423+
7424 cas [%o1], %g1, %g7
7425 cmp %g1, %g7
7426 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7427@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7428 2: BACKOFF_SPIN(%o2, %o3, 1b)
7429 ENDPROC(atomic_add_ret)
7430
7431+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7432+ BACKOFF_SETUP(%o2)
7433+1: lduw [%o1], %g1
7434+ addcc %g1, %o0, %g7
7435+ cas [%o1], %g1, %g7
7436+ cmp %g1, %g7
7437+ bne,pn %icc, 2f
7438+ add %g7, %o0, %g7
7439+ sra %g7, 0, %o0
7440+ retl
7441+ nop
7442+2: BACKOFF_SPIN(%o2, %o3, 1b)
7443+ENDPROC(atomic_add_ret_unchecked)
7444+
7445 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7446 BACKOFF_SETUP(%o2)
7447 1: lduw [%o1], %g1
7448- sub %g1, %o0, %g7
7449+ subcc %g1, %o0, %g7
7450+
7451+#ifdef CONFIG_PAX_REFCOUNT
7452+ tvs %icc, 6
7453+#endif
7454+
7455 cas [%o1], %g1, %g7
7456 cmp %g1, %g7
7457 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7458@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7459 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7460 BACKOFF_SETUP(%o2)
7461 1: ldx [%o1], %g1
7462- add %g1, %o0, %g7
7463+ addcc %g1, %o0, %g7
7464+
7465+#ifdef CONFIG_PAX_REFCOUNT
7466+ tvs %xcc, 6
7467+#endif
7468+
7469 casx [%o1], %g1, %g7
7470 cmp %g1, %g7
7471 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7472@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7473 2: BACKOFF_SPIN(%o2, %o3, 1b)
7474 ENDPROC(atomic64_add)
7475
7476+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7477+ BACKOFF_SETUP(%o2)
7478+1: ldx [%o1], %g1
7479+ addcc %g1, %o0, %g7
7480+ casx [%o1], %g1, %g7
7481+ cmp %g1, %g7
7482+ bne,pn %xcc, 2f
7483+ nop
7484+ retl
7485+ nop
7486+2: BACKOFF_SPIN(%o2, %o3, 1b)
7487+ENDPROC(atomic64_add_unchecked)
7488+
7489 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7490 BACKOFF_SETUP(%o2)
7491 1: ldx [%o1], %g1
7492- sub %g1, %o0, %g7
7493+ subcc %g1, %o0, %g7
7494+
7495+#ifdef CONFIG_PAX_REFCOUNT
7496+ tvs %xcc, 6
7497+#endif
7498+
7499 casx [%o1], %g1, %g7
7500 cmp %g1, %g7
7501 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7502@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7503 2: BACKOFF_SPIN(%o2, %o3, 1b)
7504 ENDPROC(atomic64_sub)
7505
7506+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7507+ BACKOFF_SETUP(%o2)
7508+1: ldx [%o1], %g1
7509+ subcc %g1, %o0, %g7
7510+ casx [%o1], %g1, %g7
7511+ cmp %g1, %g7
7512+ bne,pn %xcc, 2f
7513+ nop
7514+ retl
7515+ nop
7516+2: BACKOFF_SPIN(%o2, %o3, 1b)
7517+ENDPROC(atomic64_sub_unchecked)
7518+
7519 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7520 BACKOFF_SETUP(%o2)
7521 1: ldx [%o1], %g1
7522- add %g1, %o0, %g7
7523+ addcc %g1, %o0, %g7
7524+
7525+#ifdef CONFIG_PAX_REFCOUNT
7526+ tvs %xcc, 6
7527+#endif
7528+
7529 casx [%o1], %g1, %g7
7530 cmp %g1, %g7
7531 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7532@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7533 2: BACKOFF_SPIN(%o2, %o3, 1b)
7534 ENDPROC(atomic64_add_ret)
7535
7536+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7537+ BACKOFF_SETUP(%o2)
7538+1: ldx [%o1], %g1
7539+ addcc %g1, %o0, %g7
7540+ casx [%o1], %g1, %g7
7541+ cmp %g1, %g7
7542+ bne,pn %xcc, 2f
7543+ add %g7, %o0, %g7
7544+ mov %g7, %o0
7545+ retl
7546+ nop
7547+2: BACKOFF_SPIN(%o2, %o3, 1b)
7548+ENDPROC(atomic64_add_ret_unchecked)
7549+
7550 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7551 BACKOFF_SETUP(%o2)
7552 1: ldx [%o1], %g1
7553- sub %g1, %o0, %g7
7554+ subcc %g1, %o0, %g7
7555+
7556+#ifdef CONFIG_PAX_REFCOUNT
7557+ tvs %xcc, 6
7558+#endif
7559+
7560 casx [%o1], %g1, %g7
7561 cmp %g1, %g7
7562 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7563diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7564index 0c4e35e..745d3e4 100644
7565--- a/arch/sparc/lib/ksyms.c
7566+++ b/arch/sparc/lib/ksyms.c
7567@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7568
7569 /* Atomic counter implementation. */
7570 EXPORT_SYMBOL(atomic_add);
7571+EXPORT_SYMBOL(atomic_add_unchecked);
7572 EXPORT_SYMBOL(atomic_add_ret);
7573+EXPORT_SYMBOL(atomic_add_ret_unchecked);
7574 EXPORT_SYMBOL(atomic_sub);
7575+EXPORT_SYMBOL(atomic_sub_unchecked);
7576 EXPORT_SYMBOL(atomic_sub_ret);
7577 EXPORT_SYMBOL(atomic64_add);
7578+EXPORT_SYMBOL(atomic64_add_unchecked);
7579 EXPORT_SYMBOL(atomic64_add_ret);
7580+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7581 EXPORT_SYMBOL(atomic64_sub);
7582+EXPORT_SYMBOL(atomic64_sub_unchecked);
7583 EXPORT_SYMBOL(atomic64_sub_ret);
7584 EXPORT_SYMBOL(atomic64_dec_if_positive);
7585
7586diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7587index 30c3ecc..736f015 100644
7588--- a/arch/sparc/mm/Makefile
7589+++ b/arch/sparc/mm/Makefile
7590@@ -2,7 +2,7 @@
7591 #
7592
7593 asflags-y := -ansi
7594-ccflags-y := -Werror
7595+#ccflags-y := -Werror
7596
7597 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7598 obj-y += fault_$(BITS).o
7599diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7600index e98bfda..ea8d221 100644
7601--- a/arch/sparc/mm/fault_32.c
7602+++ b/arch/sparc/mm/fault_32.c
7603@@ -21,6 +21,9 @@
7604 #include <linux/perf_event.h>
7605 #include <linux/interrupt.h>
7606 #include <linux/kdebug.h>
7607+#include <linux/slab.h>
7608+#include <linux/pagemap.h>
7609+#include <linux/compiler.h>
7610
7611 #include <asm/page.h>
7612 #include <asm/pgtable.h>
7613@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7614 return safe_compute_effective_address(regs, insn);
7615 }
7616
7617+#ifdef CONFIG_PAX_PAGEEXEC
7618+#ifdef CONFIG_PAX_DLRESOLVE
7619+static void pax_emuplt_close(struct vm_area_struct *vma)
7620+{
7621+ vma->vm_mm->call_dl_resolve = 0UL;
7622+}
7623+
7624+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7625+{
7626+ unsigned int *kaddr;
7627+
7628+ vmf->page = alloc_page(GFP_HIGHUSER);
7629+ if (!vmf->page)
7630+ return VM_FAULT_OOM;
7631+
7632+ kaddr = kmap(vmf->page);
7633+ memset(kaddr, 0, PAGE_SIZE);
7634+ kaddr[0] = 0x9DE3BFA8U; /* save */
7635+ flush_dcache_page(vmf->page);
7636+ kunmap(vmf->page);
7637+ return VM_FAULT_MAJOR;
7638+}
7639+
7640+static const struct vm_operations_struct pax_vm_ops = {
7641+ .close = pax_emuplt_close,
7642+ .fault = pax_emuplt_fault
7643+};
7644+
7645+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7646+{
7647+ int ret;
7648+
7649+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7650+ vma->vm_mm = current->mm;
7651+ vma->vm_start = addr;
7652+ vma->vm_end = addr + PAGE_SIZE;
7653+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7654+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7655+ vma->vm_ops = &pax_vm_ops;
7656+
7657+ ret = insert_vm_struct(current->mm, vma);
7658+ if (ret)
7659+ return ret;
7660+
7661+ ++current->mm->total_vm;
7662+ return 0;
7663+}
7664+#endif
7665+
7666+/*
7667+ * PaX: decide what to do with offenders (regs->pc = fault address)
7668+ *
7669+ * returns 1 when task should be killed
7670+ * 2 when patched PLT trampoline was detected
7671+ * 3 when unpatched PLT trampoline was detected
7672+ */
7673+static int pax_handle_fetch_fault(struct pt_regs *regs)
7674+{
7675+
7676+#ifdef CONFIG_PAX_EMUPLT
7677+ int err;
7678+
7679+ do { /* PaX: patched PLT emulation #1 */
7680+ unsigned int sethi1, sethi2, jmpl;
7681+
7682+ err = get_user(sethi1, (unsigned int *)regs->pc);
7683+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7684+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7685+
7686+ if (err)
7687+ break;
7688+
7689+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7690+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7691+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7692+ {
7693+ unsigned int addr;
7694+
7695+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7696+ addr = regs->u_regs[UREG_G1];
7697+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7698+ regs->pc = addr;
7699+ regs->npc = addr+4;
7700+ return 2;
7701+ }
7702+ } while (0);
7703+
7704+ do { /* PaX: patched PLT emulation #2 */
7705+ unsigned int ba;
7706+
7707+ err = get_user(ba, (unsigned int *)regs->pc);
7708+
7709+ if (err)
7710+ break;
7711+
7712+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7713+ unsigned int addr;
7714+
7715+ if ((ba & 0xFFC00000U) == 0x30800000U)
7716+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7717+ else
7718+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7719+ regs->pc = addr;
7720+ regs->npc = addr+4;
7721+ return 2;
7722+ }
7723+ } while (0);
7724+
7725+ do { /* PaX: patched PLT emulation #3 */
7726+ unsigned int sethi, bajmpl, nop;
7727+
7728+ err = get_user(sethi, (unsigned int *)regs->pc);
7729+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7730+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7731+
7732+ if (err)
7733+ break;
7734+
7735+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7736+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7737+ nop == 0x01000000U)
7738+ {
7739+ unsigned int addr;
7740+
7741+ addr = (sethi & 0x003FFFFFU) << 10;
7742+ regs->u_regs[UREG_G1] = addr;
7743+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7744+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7745+ else
7746+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7747+ regs->pc = addr;
7748+ regs->npc = addr+4;
7749+ return 2;
7750+ }
7751+ } while (0);
7752+
7753+ do { /* PaX: unpatched PLT emulation step 1 */
7754+ unsigned int sethi, ba, nop;
7755+
7756+ err = get_user(sethi, (unsigned int *)regs->pc);
7757+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
7758+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7759+
7760+ if (err)
7761+ break;
7762+
7763+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7764+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7765+ nop == 0x01000000U)
7766+ {
7767+ unsigned int addr, save, call;
7768+
7769+ if ((ba & 0xFFC00000U) == 0x30800000U)
7770+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7771+ else
7772+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7773+
7774+ err = get_user(save, (unsigned int *)addr);
7775+ err |= get_user(call, (unsigned int *)(addr+4));
7776+ err |= get_user(nop, (unsigned int *)(addr+8));
7777+ if (err)
7778+ break;
7779+
7780+#ifdef CONFIG_PAX_DLRESOLVE
7781+ if (save == 0x9DE3BFA8U &&
7782+ (call & 0xC0000000U) == 0x40000000U &&
7783+ nop == 0x01000000U)
7784+ {
7785+ struct vm_area_struct *vma;
7786+ unsigned long call_dl_resolve;
7787+
7788+ down_read(&current->mm->mmap_sem);
7789+ call_dl_resolve = current->mm->call_dl_resolve;
7790+ up_read(&current->mm->mmap_sem);
7791+ if (likely(call_dl_resolve))
7792+ goto emulate;
7793+
7794+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7795+
7796+ down_write(&current->mm->mmap_sem);
7797+ if (current->mm->call_dl_resolve) {
7798+ call_dl_resolve = current->mm->call_dl_resolve;
7799+ up_write(&current->mm->mmap_sem);
7800+ if (vma)
7801+ kmem_cache_free(vm_area_cachep, vma);
7802+ goto emulate;
7803+ }
7804+
7805+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7806+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7807+ up_write(&current->mm->mmap_sem);
7808+ if (vma)
7809+ kmem_cache_free(vm_area_cachep, vma);
7810+ return 1;
7811+ }
7812+
7813+ if (pax_insert_vma(vma, call_dl_resolve)) {
7814+ up_write(&current->mm->mmap_sem);
7815+ kmem_cache_free(vm_area_cachep, vma);
7816+ return 1;
7817+ }
7818+
7819+ current->mm->call_dl_resolve = call_dl_resolve;
7820+ up_write(&current->mm->mmap_sem);
7821+
7822+emulate:
7823+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7824+ regs->pc = call_dl_resolve;
7825+ regs->npc = addr+4;
7826+ return 3;
7827+ }
7828+#endif
7829+
7830+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7831+ if ((save & 0xFFC00000U) == 0x05000000U &&
7832+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7833+ nop == 0x01000000U)
7834+ {
7835+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7836+ regs->u_regs[UREG_G2] = addr + 4;
7837+ addr = (save & 0x003FFFFFU) << 10;
7838+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7839+ regs->pc = addr;
7840+ regs->npc = addr+4;
7841+ return 3;
7842+ }
7843+ }
7844+ } while (0);
7845+
7846+ do { /* PaX: unpatched PLT emulation step 2 */
7847+ unsigned int save, call, nop;
7848+
7849+ err = get_user(save, (unsigned int *)(regs->pc-4));
7850+ err |= get_user(call, (unsigned int *)regs->pc);
7851+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
7852+ if (err)
7853+ break;
7854+
7855+ if (save == 0x9DE3BFA8U &&
7856+ (call & 0xC0000000U) == 0x40000000U &&
7857+ nop == 0x01000000U)
7858+ {
7859+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7860+
7861+ regs->u_regs[UREG_RETPC] = regs->pc;
7862+ regs->pc = dl_resolve;
7863+ regs->npc = dl_resolve+4;
7864+ return 3;
7865+ }
7866+ } while (0);
7867+#endif
7868+
7869+ return 1;
7870+}
7871+
7872+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7873+{
7874+ unsigned long i;
7875+
7876+ printk(KERN_ERR "PAX: bytes at PC: ");
7877+ for (i = 0; i < 8; i++) {
7878+ unsigned int c;
7879+ if (get_user(c, (unsigned int *)pc+i))
7880+ printk(KERN_CONT "???????? ");
7881+ else
7882+ printk(KERN_CONT "%08x ", c);
7883+ }
7884+ printk("\n");
7885+}
7886+#endif
7887+
7888 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7889 int text_fault)
7890 {
7891@@ -230,6 +504,24 @@ good_area:
7892 if (!(vma->vm_flags & VM_WRITE))
7893 goto bad_area;
7894 } else {
7895+
7896+#ifdef CONFIG_PAX_PAGEEXEC
7897+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7898+ up_read(&mm->mmap_sem);
7899+ switch (pax_handle_fetch_fault(regs)) {
7900+
7901+#ifdef CONFIG_PAX_EMUPLT
7902+ case 2:
7903+ case 3:
7904+ return;
7905+#endif
7906+
7907+ }
7908+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7909+ do_group_exit(SIGKILL);
7910+ }
7911+#endif
7912+
7913 /* Allow reads even for write-only mappings */
7914 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7915 goto bad_area;
7916diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7917index 097aee7..5ca6697 100644
7918--- a/arch/sparc/mm/fault_64.c
7919+++ b/arch/sparc/mm/fault_64.c
7920@@ -21,6 +21,9 @@
7921 #include <linux/kprobes.h>
7922 #include <linux/kdebug.h>
7923 #include <linux/percpu.h>
7924+#include <linux/slab.h>
7925+#include <linux/pagemap.h>
7926+#include <linux/compiler.h>
7927
7928 #include <asm/page.h>
7929 #include <asm/pgtable.h>
7930@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7931 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7932 regs->tpc);
7933 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7934- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7935+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7936 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7937 dump_stack();
7938 unhandled_fault(regs->tpc, current, regs);
7939@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7940 show_regs(regs);
7941 }
7942
7943+#ifdef CONFIG_PAX_PAGEEXEC
7944+#ifdef CONFIG_PAX_DLRESOLVE
7945+static void pax_emuplt_close(struct vm_area_struct *vma)
7946+{
7947+ vma->vm_mm->call_dl_resolve = 0UL;
7948+}
7949+
7950+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7951+{
7952+ unsigned int *kaddr;
7953+
7954+ vmf->page = alloc_page(GFP_HIGHUSER);
7955+ if (!vmf->page)
7956+ return VM_FAULT_OOM;
7957+
7958+ kaddr = kmap(vmf->page);
7959+ memset(kaddr, 0, PAGE_SIZE);
7960+ kaddr[0] = 0x9DE3BFA8U; /* save */
7961+ flush_dcache_page(vmf->page);
7962+ kunmap(vmf->page);
7963+ return VM_FAULT_MAJOR;
7964+}
7965+
7966+static const struct vm_operations_struct pax_vm_ops = {
7967+ .close = pax_emuplt_close,
7968+ .fault = pax_emuplt_fault
7969+};
7970+
7971+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7972+{
7973+ int ret;
7974+
7975+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7976+ vma->vm_mm = current->mm;
7977+ vma->vm_start = addr;
7978+ vma->vm_end = addr + PAGE_SIZE;
7979+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7980+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7981+ vma->vm_ops = &pax_vm_ops;
7982+
7983+ ret = insert_vm_struct(current->mm, vma);
7984+ if (ret)
7985+ return ret;
7986+
7987+ ++current->mm->total_vm;
7988+ return 0;
7989+}
7990+#endif
7991+
7992+/*
7993+ * PaX: decide what to do with offenders (regs->tpc = fault address)
7994+ *
7995+ * returns 1 when task should be killed
7996+ * 2 when patched PLT trampoline was detected
7997+ * 3 when unpatched PLT trampoline was detected
7998+ */
7999+static int pax_handle_fetch_fault(struct pt_regs *regs)
8000+{
8001+
8002+#ifdef CONFIG_PAX_EMUPLT
8003+ int err;
8004+
8005+ do { /* PaX: patched PLT emulation #1 */
8006+ unsigned int sethi1, sethi2, jmpl;
8007+
8008+ err = get_user(sethi1, (unsigned int *)regs->tpc);
8009+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
8010+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
8011+
8012+ if (err)
8013+ break;
8014+
8015+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
8016+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
8017+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
8018+ {
8019+ unsigned long addr;
8020+
8021+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
8022+ addr = regs->u_regs[UREG_G1];
8023+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8024+
8025+ if (test_thread_flag(TIF_32BIT))
8026+ addr &= 0xFFFFFFFFUL;
8027+
8028+ regs->tpc = addr;
8029+ regs->tnpc = addr+4;
8030+ return 2;
8031+ }
8032+ } while (0);
8033+
8034+ do { /* PaX: patched PLT emulation #2 */
8035+ unsigned int ba;
8036+
8037+ err = get_user(ba, (unsigned int *)regs->tpc);
8038+
8039+ if (err)
8040+ break;
8041+
8042+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
8043+ unsigned long addr;
8044+
8045+ if ((ba & 0xFFC00000U) == 0x30800000U)
8046+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8047+ else
8048+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8049+
8050+ if (test_thread_flag(TIF_32BIT))
8051+ addr &= 0xFFFFFFFFUL;
8052+
8053+ regs->tpc = addr;
8054+ regs->tnpc = addr+4;
8055+ return 2;
8056+ }
8057+ } while (0);
8058+
8059+ do { /* PaX: patched PLT emulation #3 */
8060+ unsigned int sethi, bajmpl, nop;
8061+
8062+ err = get_user(sethi, (unsigned int *)regs->tpc);
8063+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
8064+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8065+
8066+ if (err)
8067+ break;
8068+
8069+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8070+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
8071+ nop == 0x01000000U)
8072+ {
8073+ unsigned long addr;
8074+
8075+ addr = (sethi & 0x003FFFFFU) << 10;
8076+ regs->u_regs[UREG_G1] = addr;
8077+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
8078+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8079+ else
8080+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8081+
8082+ if (test_thread_flag(TIF_32BIT))
8083+ addr &= 0xFFFFFFFFUL;
8084+
8085+ regs->tpc = addr;
8086+ regs->tnpc = addr+4;
8087+ return 2;
8088+ }
8089+ } while (0);
8090+
8091+ do { /* PaX: patched PLT emulation #4 */
8092+ unsigned int sethi, mov1, call, mov2;
8093+
8094+ err = get_user(sethi, (unsigned int *)regs->tpc);
8095+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
8096+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
8097+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
8098+
8099+ if (err)
8100+ break;
8101+
8102+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8103+ mov1 == 0x8210000FU &&
8104+ (call & 0xC0000000U) == 0x40000000U &&
8105+ mov2 == 0x9E100001U)
8106+ {
8107+ unsigned long addr;
8108+
8109+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
8110+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8111+
8112+ if (test_thread_flag(TIF_32BIT))
8113+ addr &= 0xFFFFFFFFUL;
8114+
8115+ regs->tpc = addr;
8116+ regs->tnpc = addr+4;
8117+ return 2;
8118+ }
8119+ } while (0);
8120+
8121+ do { /* PaX: patched PLT emulation #5 */
8122+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
8123+
8124+ err = get_user(sethi, (unsigned int *)regs->tpc);
8125+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8126+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8127+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8128+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8129+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8130+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8131+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8132+
8133+ if (err)
8134+ break;
8135+
8136+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8137+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8138+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8139+ (or1 & 0xFFFFE000U) == 0x82106000U &&
8140+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8141+ sllx == 0x83287020U &&
8142+ jmpl == 0x81C04005U &&
8143+ nop == 0x01000000U)
8144+ {
8145+ unsigned long addr;
8146+
8147+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8148+ regs->u_regs[UREG_G1] <<= 32;
8149+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8150+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8151+ regs->tpc = addr;
8152+ regs->tnpc = addr+4;
8153+ return 2;
8154+ }
8155+ } while (0);
8156+
8157+ do { /* PaX: patched PLT emulation #6 */
8158+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8159+
8160+ err = get_user(sethi, (unsigned int *)regs->tpc);
8161+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8162+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8163+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8164+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
8165+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8166+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8167+
8168+ if (err)
8169+ break;
8170+
8171+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8172+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8173+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8174+ sllx == 0x83287020U &&
8175+ (or & 0xFFFFE000U) == 0x8A116000U &&
8176+ jmpl == 0x81C04005U &&
8177+ nop == 0x01000000U)
8178+ {
8179+ unsigned long addr;
8180+
8181+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8182+ regs->u_regs[UREG_G1] <<= 32;
8183+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8184+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8185+ regs->tpc = addr;
8186+ regs->tnpc = addr+4;
8187+ return 2;
8188+ }
8189+ } while (0);
8190+
8191+ do { /* PaX: unpatched PLT emulation step 1 */
8192+ unsigned int sethi, ba, nop;
8193+
8194+ err = get_user(sethi, (unsigned int *)regs->tpc);
8195+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8196+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8197+
8198+ if (err)
8199+ break;
8200+
8201+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8202+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8203+ nop == 0x01000000U)
8204+ {
8205+ unsigned long addr;
8206+ unsigned int save, call;
8207+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8208+
8209+ if ((ba & 0xFFC00000U) == 0x30800000U)
8210+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8211+ else
8212+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8213+
8214+ if (test_thread_flag(TIF_32BIT))
8215+ addr &= 0xFFFFFFFFUL;
8216+
8217+ err = get_user(save, (unsigned int *)addr);
8218+ err |= get_user(call, (unsigned int *)(addr+4));
8219+ err |= get_user(nop, (unsigned int *)(addr+8));
8220+ if (err)
8221+ break;
8222+
8223+#ifdef CONFIG_PAX_DLRESOLVE
8224+ if (save == 0x9DE3BFA8U &&
8225+ (call & 0xC0000000U) == 0x40000000U &&
8226+ nop == 0x01000000U)
8227+ {
8228+ struct vm_area_struct *vma;
8229+ unsigned long call_dl_resolve;
8230+
8231+ down_read(&current->mm->mmap_sem);
8232+ call_dl_resolve = current->mm->call_dl_resolve;
8233+ up_read(&current->mm->mmap_sem);
8234+ if (likely(call_dl_resolve))
8235+ goto emulate;
8236+
8237+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8238+
8239+ down_write(&current->mm->mmap_sem);
8240+ if (current->mm->call_dl_resolve) {
8241+ call_dl_resolve = current->mm->call_dl_resolve;
8242+ up_write(&current->mm->mmap_sem);
8243+ if (vma)
8244+ kmem_cache_free(vm_area_cachep, vma);
8245+ goto emulate;
8246+ }
8247+
8248+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8249+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8250+ up_write(&current->mm->mmap_sem);
8251+ if (vma)
8252+ kmem_cache_free(vm_area_cachep, vma);
8253+ return 1;
8254+ }
8255+
8256+ if (pax_insert_vma(vma, call_dl_resolve)) {
8257+ up_write(&current->mm->mmap_sem);
8258+ kmem_cache_free(vm_area_cachep, vma);
8259+ return 1;
8260+ }
8261+
8262+ current->mm->call_dl_resolve = call_dl_resolve;
8263+ up_write(&current->mm->mmap_sem);
8264+
8265+emulate:
8266+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8267+ regs->tpc = call_dl_resolve;
8268+ regs->tnpc = addr+4;
8269+ return 3;
8270+ }
8271+#endif
8272+
8273+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8274+ if ((save & 0xFFC00000U) == 0x05000000U &&
8275+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8276+ nop == 0x01000000U)
8277+ {
8278+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8279+ regs->u_regs[UREG_G2] = addr + 4;
8280+ addr = (save & 0x003FFFFFU) << 10;
8281+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8282+
8283+ if (test_thread_flag(TIF_32BIT))
8284+ addr &= 0xFFFFFFFFUL;
8285+
8286+ regs->tpc = addr;
8287+ regs->tnpc = addr+4;
8288+ return 3;
8289+ }
8290+
8291+ /* PaX: 64-bit PLT stub */
8292+ err = get_user(sethi1, (unsigned int *)addr);
8293+ err |= get_user(sethi2, (unsigned int *)(addr+4));
8294+ err |= get_user(or1, (unsigned int *)(addr+8));
8295+ err |= get_user(or2, (unsigned int *)(addr+12));
8296+ err |= get_user(sllx, (unsigned int *)(addr+16));
8297+ err |= get_user(add, (unsigned int *)(addr+20));
8298+ err |= get_user(jmpl, (unsigned int *)(addr+24));
8299+ err |= get_user(nop, (unsigned int *)(addr+28));
8300+ if (err)
8301+ break;
8302+
8303+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8304+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8305+ (or1 & 0xFFFFE000U) == 0x88112000U &&
8306+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8307+ sllx == 0x89293020U &&
8308+ add == 0x8A010005U &&
8309+ jmpl == 0x89C14000U &&
8310+ nop == 0x01000000U)
8311+ {
8312+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8313+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8314+ regs->u_regs[UREG_G4] <<= 32;
8315+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8316+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8317+ regs->u_regs[UREG_G4] = addr + 24;
8318+ addr = regs->u_regs[UREG_G5];
8319+ regs->tpc = addr;
8320+ regs->tnpc = addr+4;
8321+ return 3;
8322+ }
8323+ }
8324+ } while (0);
8325+
8326+#ifdef CONFIG_PAX_DLRESOLVE
8327+ do { /* PaX: unpatched PLT emulation step 2 */
8328+ unsigned int save, call, nop;
8329+
8330+ err = get_user(save, (unsigned int *)(regs->tpc-4));
8331+ err |= get_user(call, (unsigned int *)regs->tpc);
8332+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8333+ if (err)
8334+ break;
8335+
8336+ if (save == 0x9DE3BFA8U &&
8337+ (call & 0xC0000000U) == 0x40000000U &&
8338+ nop == 0x01000000U)
8339+ {
8340+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8341+
8342+ if (test_thread_flag(TIF_32BIT))
8343+ dl_resolve &= 0xFFFFFFFFUL;
8344+
8345+ regs->u_regs[UREG_RETPC] = regs->tpc;
8346+ regs->tpc = dl_resolve;
8347+ regs->tnpc = dl_resolve+4;
8348+ return 3;
8349+ }
8350+ } while (0);
8351+#endif
8352+
8353+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8354+ unsigned int sethi, ba, nop;
8355+
8356+ err = get_user(sethi, (unsigned int *)regs->tpc);
8357+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8358+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8359+
8360+ if (err)
8361+ break;
8362+
8363+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8364+ (ba & 0xFFF00000U) == 0x30600000U &&
8365+ nop == 0x01000000U)
8366+ {
8367+ unsigned long addr;
8368+
8369+ addr = (sethi & 0x003FFFFFU) << 10;
8370+ regs->u_regs[UREG_G1] = addr;
8371+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8372+
8373+ if (test_thread_flag(TIF_32BIT))
8374+ addr &= 0xFFFFFFFFUL;
8375+
8376+ regs->tpc = addr;
8377+ regs->tnpc = addr+4;
8378+ return 2;
8379+ }
8380+ } while (0);
8381+
8382+#endif
8383+
8384+ return 1;
8385+}
8386+
8387+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8388+{
8389+ unsigned long i;
8390+
8391+ printk(KERN_ERR "PAX: bytes at PC: ");
8392+ for (i = 0; i < 8; i++) {
8393+ unsigned int c;
8394+ if (get_user(c, (unsigned int *)pc+i))
8395+ printk(KERN_CONT "???????? ");
8396+ else
8397+ printk(KERN_CONT "%08x ", c);
8398+ }
8399+ printk("\n");
8400+}
8401+#endif
8402+
8403 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8404 {
8405 struct mm_struct *mm = current->mm;
8406@@ -341,6 +804,29 @@ retry:
8407 if (!vma)
8408 goto bad_area;
8409
8410+#ifdef CONFIG_PAX_PAGEEXEC
8411+ /* PaX: detect ITLB misses on non-exec pages */
8412+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8413+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8414+ {
8415+ if (address != regs->tpc)
8416+ goto good_area;
8417+
8418+ up_read(&mm->mmap_sem);
8419+ switch (pax_handle_fetch_fault(regs)) {
8420+
8421+#ifdef CONFIG_PAX_EMUPLT
8422+ case 2:
8423+ case 3:
8424+ return;
8425+#endif
8426+
8427+ }
8428+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8429+ do_group_exit(SIGKILL);
8430+ }
8431+#endif
8432+
8433 /* Pure DTLB misses do not tell us whether the fault causing
8434 * load/store/atomic was a write or not, it only says that there
8435 * was no match. So in such a case we (carefully) read the
8436diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8437index f76f83d..ee0d859 100644
8438--- a/arch/sparc/mm/hugetlbpage.c
8439+++ b/arch/sparc/mm/hugetlbpage.c
8440@@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8441 struct vm_area_struct * vma;
8442 unsigned long task_size = TASK_SIZE;
8443 unsigned long start_addr;
8444+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8445
8446 if (test_thread_flag(TIF_32BIT))
8447 task_size = STACK_TOP32;
8448@@ -67,7 +68,7 @@ full_search:
8449 }
8450 return -ENOMEM;
8451 }
8452- if (likely(!vma || addr + len <= vma->vm_start)) {
8453+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8454 /*
8455 * Remember the place where we stopped the search:
8456 */
8457@@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8458 struct vm_area_struct *vma;
8459 struct mm_struct *mm = current->mm;
8460 unsigned long addr = addr0;
8461+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8462
8463 /* This should only ever run for 32-bit processes. */
8464 BUG_ON(!test_thread_flag(TIF_32BIT));
8465@@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8466 /* make sure it can fit in the remaining address space */
8467 if (likely(addr > len)) {
8468 vma = find_vma(mm, addr-len);
8469- if (!vma || addr <= vma->vm_start) {
8470+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8471 /* remember the address as a hint for next time */
8472 return (mm->free_area_cache = addr-len);
8473 }
8474@@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8475 if (unlikely(mm->mmap_base < len))
8476 goto bottomup;
8477
8478- addr = (mm->mmap_base-len) & HPAGE_MASK;
8479+ addr = mm->mmap_base - len;
8480
8481 do {
8482+ addr &= HPAGE_MASK;
8483 /*
8484 * Lookup failure means no vma is above this address,
8485 * else if new region fits below vma->vm_start,
8486 * return with success:
8487 */
8488 vma = find_vma(mm, addr);
8489- if (likely(!vma || addr+len <= vma->vm_start)) {
8490+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8491 /* remember the address as a hint for next time */
8492 return (mm->free_area_cache = addr);
8493 }
8494@@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8495 mm->cached_hole_size = vma->vm_start - addr;
8496
8497 /* try just below the current vma->vm_start */
8498- addr = (vma->vm_start-len) & HPAGE_MASK;
8499- } while (likely(len < vma->vm_start));
8500+ addr = skip_heap_stack_gap(vma, len, offset);
8501+ } while (!IS_ERR_VALUE(addr));
8502
8503 bottomup:
8504 /*
8505@@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8506 struct mm_struct *mm = current->mm;
8507 struct vm_area_struct *vma;
8508 unsigned long task_size = TASK_SIZE;
8509+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8510
8511 if (test_thread_flag(TIF_32BIT))
8512 task_size = STACK_TOP32;
8513@@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8514 if (addr) {
8515 addr = ALIGN(addr, HPAGE_SIZE);
8516 vma = find_vma(mm, addr);
8517- if (task_size - len >= addr &&
8518- (!vma || addr + len <= vma->vm_start))
8519+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8520 return addr;
8521 }
8522 if (mm->get_unmapped_area == arch_get_unmapped_area)
8523diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8524index f4500c6..889656c 100644
8525--- a/arch/tile/include/asm/atomic_64.h
8526+++ b/arch/tile/include/asm/atomic_64.h
8527@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8528
8529 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8530
8531+#define atomic64_read_unchecked(v) atomic64_read(v)
8532+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8533+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8534+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8535+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8536+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8537+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8538+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8539+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8540+
8541 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8542 #define smp_mb__before_atomic_dec() smp_mb()
8543 #define smp_mb__after_atomic_dec() smp_mb()
8544diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8545index a9a5299..0fce79e 100644
8546--- a/arch/tile/include/asm/cache.h
8547+++ b/arch/tile/include/asm/cache.h
8548@@ -15,11 +15,12 @@
8549 #ifndef _ASM_TILE_CACHE_H
8550 #define _ASM_TILE_CACHE_H
8551
8552+#include <linux/const.h>
8553 #include <arch/chip.h>
8554
8555 /* bytes per L1 data cache line */
8556 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8557-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8558+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8559
8560 /* bytes per L2 cache line */
8561 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8562diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8563index 9ab078a..d6635c2 100644
8564--- a/arch/tile/include/asm/uaccess.h
8565+++ b/arch/tile/include/asm/uaccess.h
8566@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8567 const void __user *from,
8568 unsigned long n)
8569 {
8570- int sz = __compiletime_object_size(to);
8571+ size_t sz = __compiletime_object_size(to);
8572
8573- if (likely(sz == -1 || sz >= n))
8574+ if (likely(sz == (size_t)-1 || sz >= n))
8575 n = _copy_from_user(to, from, n);
8576 else
8577 copy_from_user_overflow();
8578diff --git a/arch/um/Makefile b/arch/um/Makefile
8579index 133f7de..1d6f2f1 100644
8580--- a/arch/um/Makefile
8581+++ b/arch/um/Makefile
8582@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8583 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8584 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8585
8586+ifdef CONSTIFY_PLUGIN
8587+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8588+endif
8589+
8590 #This will adjust *FLAGS accordingly to the platform.
8591 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8592
8593diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8594index 19e1bdd..3665b77 100644
8595--- a/arch/um/include/asm/cache.h
8596+++ b/arch/um/include/asm/cache.h
8597@@ -1,6 +1,7 @@
8598 #ifndef __UM_CACHE_H
8599 #define __UM_CACHE_H
8600
8601+#include <linux/const.h>
8602
8603 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8604 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8605@@ -12,6 +13,6 @@
8606 # define L1_CACHE_SHIFT 5
8607 #endif
8608
8609-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8610+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8611
8612 #endif
8613diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8614index 2e0a6b1..a64d0f5 100644
8615--- a/arch/um/include/asm/kmap_types.h
8616+++ b/arch/um/include/asm/kmap_types.h
8617@@ -8,6 +8,6 @@
8618
8619 /* No more #include "asm/arch/kmap_types.h" ! */
8620
8621-#define KM_TYPE_NR 14
8622+#define KM_TYPE_NR 15
8623
8624 #endif
8625diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8626index 5ff53d9..5850cdf 100644
8627--- a/arch/um/include/asm/page.h
8628+++ b/arch/um/include/asm/page.h
8629@@ -14,6 +14,9 @@
8630 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8631 #define PAGE_MASK (~(PAGE_SIZE-1))
8632
8633+#define ktla_ktva(addr) (addr)
8634+#define ktva_ktla(addr) (addr)
8635+
8636 #ifndef __ASSEMBLY__
8637
8638 struct page;
8639diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8640index 0032f92..cd151e0 100644
8641--- a/arch/um/include/asm/pgtable-3level.h
8642+++ b/arch/um/include/asm/pgtable-3level.h
8643@@ -58,6 +58,7 @@
8644 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8645 #define pud_populate(mm, pud, pmd) \
8646 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8647+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8648
8649 #ifdef CONFIG_64BIT
8650 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8651diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8652index b6d699c..df7ac1d 100644
8653--- a/arch/um/kernel/process.c
8654+++ b/arch/um/kernel/process.c
8655@@ -387,22 +387,6 @@ int singlestepping(void * t)
8656 return 2;
8657 }
8658
8659-/*
8660- * Only x86 and x86_64 have an arch_align_stack().
8661- * All other arches have "#define arch_align_stack(x) (x)"
8662- * in their asm/system.h
8663- * As this is included in UML from asm-um/system-generic.h,
8664- * we can use it to behave as the subarch does.
8665- */
8666-#ifndef arch_align_stack
8667-unsigned long arch_align_stack(unsigned long sp)
8668-{
8669- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8670- sp -= get_random_int() % 8192;
8671- return sp & ~0xf;
8672-}
8673-#endif
8674-
8675 unsigned long get_wchan(struct task_struct *p)
8676 {
8677 unsigned long stack_page, sp, ip;
8678diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8679index ad8f795..2c7eec6 100644
8680--- a/arch/unicore32/include/asm/cache.h
8681+++ b/arch/unicore32/include/asm/cache.h
8682@@ -12,8 +12,10 @@
8683 #ifndef __UNICORE_CACHE_H__
8684 #define __UNICORE_CACHE_H__
8685
8686-#define L1_CACHE_SHIFT (5)
8687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8688+#include <linux/const.h>
8689+
8690+#define L1_CACHE_SHIFT 5
8691+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8692
8693 /*
8694 * Memory returned by kmalloc() may be used for DMA, so we must make
8695diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8696index 46c3bff..b82f26b 100644
8697--- a/arch/x86/Kconfig
8698+++ b/arch/x86/Kconfig
8699@@ -241,7 +241,7 @@ config X86_HT
8700
8701 config X86_32_LAZY_GS
8702 def_bool y
8703- depends on X86_32 && !CC_STACKPROTECTOR
8704+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8705
8706 config ARCH_HWEIGHT_CFLAGS
8707 string
8708@@ -1033,6 +1033,7 @@ config MICROCODE_OLD_INTERFACE
8709
8710 config X86_MSR
8711 tristate "/dev/cpu/*/msr - Model-specific register support"
8712+ depends on !GRKERNSEC_KMEM
8713 ---help---
8714 This device gives privileged processes access to the x86
8715 Model-Specific Registers (MSRs). It is a character device with
8716@@ -1056,7 +1057,7 @@ choice
8717
8718 config NOHIGHMEM
8719 bool "off"
8720- depends on !X86_NUMAQ
8721+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8722 ---help---
8723 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8724 However, the address space of 32-bit x86 processors is only 4
8725@@ -1093,7 +1094,7 @@ config NOHIGHMEM
8726
8727 config HIGHMEM4G
8728 bool "4GB"
8729- depends on !X86_NUMAQ
8730+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8731 ---help---
8732 Select this if you have a 32-bit processor and between 1 and 4
8733 gigabytes of physical RAM.
8734@@ -1147,7 +1148,7 @@ config PAGE_OFFSET
8735 hex
8736 default 0xB0000000 if VMSPLIT_3G_OPT
8737 default 0x80000000 if VMSPLIT_2G
8738- default 0x78000000 if VMSPLIT_2G_OPT
8739+ default 0x70000000 if VMSPLIT_2G_OPT
8740 default 0x40000000 if VMSPLIT_1G
8741 default 0xC0000000
8742 depends on X86_32
8743@@ -1548,6 +1549,7 @@ config SECCOMP
8744
8745 config CC_STACKPROTECTOR
8746 bool "Enable -fstack-protector buffer overflow detection"
8747+ depends on X86_64 || !PAX_MEMORY_UDEREF
8748 ---help---
8749 This option turns on the -fstack-protector GCC feature. This
8750 feature puts, at the beginning of functions, a canary value on
8751@@ -1605,6 +1607,7 @@ config KEXEC_JUMP
8752 config PHYSICAL_START
8753 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8754 default "0x1000000"
8755+ range 0x400000 0x40000000
8756 ---help---
8757 This gives the physical address where the kernel is loaded.
8758
8759@@ -1668,6 +1671,7 @@ config X86_NEED_RELOCS
8760 config PHYSICAL_ALIGN
8761 hex "Alignment value to which kernel should be aligned" if X86_32
8762 default "0x1000000"
8763+ range 0x400000 0x1000000 if PAX_KERNEXEC
8764 range 0x2000 0x1000000
8765 ---help---
8766 This value puts the alignment restrictions on physical address
8767@@ -1699,9 +1703,10 @@ config HOTPLUG_CPU
8768 Say N if you want to disable CPU hotplug.
8769
8770 config COMPAT_VDSO
8771- def_bool y
8772+ def_bool n
8773 prompt "Compat VDSO support"
8774 depends on X86_32 || IA32_EMULATION
8775+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
8776 ---help---
8777 Map the 32-bit VDSO to the predictable old-style address too.
8778
8779diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8780index f3b86d0..17fd30f 100644
8781--- a/arch/x86/Kconfig.cpu
8782+++ b/arch/x86/Kconfig.cpu
8783@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8784
8785 config X86_F00F_BUG
8786 def_bool y
8787- depends on M586MMX || M586TSC || M586 || M486 || M386
8788+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8789
8790 config X86_INVD_BUG
8791 def_bool y
8792@@ -359,7 +359,7 @@ config X86_POPAD_OK
8793
8794 config X86_ALIGNMENT_16
8795 def_bool y
8796- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8797+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8798
8799 config X86_INTEL_USERCOPY
8800 def_bool y
8801@@ -405,7 +405,7 @@ config X86_CMPXCHG64
8802 # generates cmov.
8803 config X86_CMOV
8804 def_bool y
8805- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8806+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8807
8808 config X86_MINIMUM_CPU_FAMILY
8809 int
8810diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8811index b322f12..652d0d9 100644
8812--- a/arch/x86/Kconfig.debug
8813+++ b/arch/x86/Kconfig.debug
8814@@ -84,7 +84,7 @@ config X86_PTDUMP
8815 config DEBUG_RODATA
8816 bool "Write protect kernel read-only data structures"
8817 default y
8818- depends on DEBUG_KERNEL
8819+ depends on DEBUG_KERNEL && BROKEN
8820 ---help---
8821 Mark the kernel read-only data as write-protected in the pagetables,
8822 in order to catch accidental (and incorrect) writes to such const
8823@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8824
8825 config DEBUG_SET_MODULE_RONX
8826 bool "Set loadable kernel module data as NX and text as RO"
8827- depends on MODULES
8828+ depends on MODULES && BROKEN
8829 ---help---
8830 This option helps catch unintended modifications to loadable
8831 kernel module's text and read-only data. It also prevents execution
8832@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8833
8834 config DEBUG_STRICT_USER_COPY_CHECKS
8835 bool "Strict copy size checks"
8836- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8837+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8838 ---help---
8839 Enabling this option turns a certain set of sanity checks for user
8840 copy operations into compile time failures.
8841diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8842index 05afcca..b6ecb51 100644
8843--- a/arch/x86/Makefile
8844+++ b/arch/x86/Makefile
8845@@ -50,6 +50,7 @@ else
8846 UTS_MACHINE := x86_64
8847 CHECKFLAGS += -D__x86_64__ -m64
8848
8849+ biarch := $(call cc-option,-m64)
8850 KBUILD_AFLAGS += -m64
8851 KBUILD_CFLAGS += -m64
8852
8853@@ -229,3 +230,12 @@ define archhelp
8854 echo ' FDARGS="..." arguments for the booted kernel'
8855 echo ' FDINITRD=file initrd for the booted kernel'
8856 endef
8857+
8858+define OLD_LD
8859+
8860+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8861+*** Please upgrade your binutils to 2.18 or newer
8862+endef
8863+
8864+archprepare:
8865+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8866diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8867index ccce0ed..fd9da25 100644
8868--- a/arch/x86/boot/Makefile
8869+++ b/arch/x86/boot/Makefile
8870@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8871 $(call cc-option, -fno-stack-protector) \
8872 $(call cc-option, -mpreferred-stack-boundary=2)
8873 KBUILD_CFLAGS += $(call cc-option, -m32)
8874+ifdef CONSTIFY_PLUGIN
8875+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8876+endif
8877 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8878 GCOV_PROFILE := n
8879
8880diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8881index 878e4b9..20537ab 100644
8882--- a/arch/x86/boot/bitops.h
8883+++ b/arch/x86/boot/bitops.h
8884@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8885 u8 v;
8886 const u32 *p = (const u32 *)addr;
8887
8888- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8889+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8890 return v;
8891 }
8892
8893@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8894
8895 static inline void set_bit(int nr, void *addr)
8896 {
8897- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8898+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8899 }
8900
8901 #endif /* BOOT_BITOPS_H */
8902diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8903index 18997e5..83d9c67 100644
8904--- a/arch/x86/boot/boot.h
8905+++ b/arch/x86/boot/boot.h
8906@@ -85,7 +85,7 @@ static inline void io_delay(void)
8907 static inline u16 ds(void)
8908 {
8909 u16 seg;
8910- asm("movw %%ds,%0" : "=rm" (seg));
8911+ asm volatile("movw %%ds,%0" : "=rm" (seg));
8912 return seg;
8913 }
8914
8915@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8916 static inline int memcmp(const void *s1, const void *s2, size_t len)
8917 {
8918 u8 diff;
8919- asm("repe; cmpsb; setnz %0"
8920+ asm volatile("repe; cmpsb; setnz %0"
8921 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8922 return diff;
8923 }
8924diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8925index 8a84501..b2d165f 100644
8926--- a/arch/x86/boot/compressed/Makefile
8927+++ b/arch/x86/boot/compressed/Makefile
8928@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8929 KBUILD_CFLAGS += $(cflags-y)
8930 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8931 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8932+ifdef CONSTIFY_PLUGIN
8933+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8934+endif
8935
8936 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8937 GCOV_PROFILE := n
8938diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8939index ccae7e2..8ac70be 100644
8940--- a/arch/x86/boot/compressed/eboot.c
8941+++ b/arch/x86/boot/compressed/eboot.c
8942@@ -144,7 +144,6 @@ again:
8943 *addr = max_addr;
8944 }
8945
8946-free_pool:
8947 efi_call_phys1(sys_table->boottime->free_pool, map);
8948
8949 fail:
8950@@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8951 if (i == map_size / desc_size)
8952 status = EFI_NOT_FOUND;
8953
8954-free_pool:
8955 efi_call_phys1(sys_table->boottime->free_pool, map);
8956 fail:
8957 return status;
8958diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8959index ccb2f4a..e49b20e 100644
8960--- a/arch/x86/boot/compressed/head_32.S
8961+++ b/arch/x86/boot/compressed/head_32.S
8962@@ -118,7 +118,7 @@ preferred_addr:
8963 notl %eax
8964 andl %eax, %ebx
8965 #else
8966- movl $LOAD_PHYSICAL_ADDR, %ebx
8967+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8968 #endif
8969
8970 /* Target address to relocate to for decompression */
8971@@ -204,7 +204,7 @@ relocated:
8972 * and where it was actually loaded.
8973 */
8974 movl %ebp, %ebx
8975- subl $LOAD_PHYSICAL_ADDR, %ebx
8976+ subl $____LOAD_PHYSICAL_ADDR, %ebx
8977 jz 2f /* Nothing to be done if loaded at compiled addr. */
8978 /*
8979 * Process relocations.
8980@@ -212,8 +212,7 @@ relocated:
8981
8982 1: subl $4, %edi
8983 movl (%edi), %ecx
8984- testl %ecx, %ecx
8985- jz 2f
8986+ jecxz 2f
8987 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8988 jmp 1b
8989 2:
8990diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8991index 2c4b171..e1fa5b1 100644
8992--- a/arch/x86/boot/compressed/head_64.S
8993+++ b/arch/x86/boot/compressed/head_64.S
8994@@ -91,7 +91,7 @@ ENTRY(startup_32)
8995 notl %eax
8996 andl %eax, %ebx
8997 #else
8998- movl $LOAD_PHYSICAL_ADDR, %ebx
8999+ movl $____LOAD_PHYSICAL_ADDR, %ebx
9000 #endif
9001
9002 /* Target address to relocate to for decompression */
9003@@ -273,7 +273,7 @@ preferred_addr:
9004 notq %rax
9005 andq %rax, %rbp
9006 #else
9007- movq $LOAD_PHYSICAL_ADDR, %rbp
9008+ movq $____LOAD_PHYSICAL_ADDR, %rbp
9009 #endif
9010
9011 /* Target address to relocate to for decompression */
9012diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
9013index 88f7ff6..ed695dd 100644
9014--- a/arch/x86/boot/compressed/misc.c
9015+++ b/arch/x86/boot/compressed/misc.c
9016@@ -303,7 +303,7 @@ static void parse_elf(void *output)
9017 case PT_LOAD:
9018 #ifdef CONFIG_RELOCATABLE
9019 dest = output;
9020- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
9021+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
9022 #else
9023 dest = (void *)(phdr->p_paddr);
9024 #endif
9025@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
9026 error("Destination address too large");
9027 #endif
9028 #ifndef CONFIG_RELOCATABLE
9029- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
9030+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
9031 error("Wrong destination address");
9032 #endif
9033
9034diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
9035index 4d3ff03..e4972ff 100644
9036--- a/arch/x86/boot/cpucheck.c
9037+++ b/arch/x86/boot/cpucheck.c
9038@@ -74,7 +74,7 @@ static int has_fpu(void)
9039 u16 fcw = -1, fsw = -1;
9040 u32 cr0;
9041
9042- asm("movl %%cr0,%0" : "=r" (cr0));
9043+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
9044 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
9045 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
9046 asm volatile("movl %0,%%cr0" : : "r" (cr0));
9047@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
9048 {
9049 u32 f0, f1;
9050
9051- asm("pushfl ; "
9052+ asm volatile("pushfl ; "
9053 "pushfl ; "
9054 "popl %0 ; "
9055 "movl %0,%1 ; "
9056@@ -115,7 +115,7 @@ static void get_flags(void)
9057 set_bit(X86_FEATURE_FPU, cpu.flags);
9058
9059 if (has_eflag(X86_EFLAGS_ID)) {
9060- asm("cpuid"
9061+ asm volatile("cpuid"
9062 : "=a" (max_intel_level),
9063 "=b" (cpu_vendor[0]),
9064 "=d" (cpu_vendor[1]),
9065@@ -124,7 +124,7 @@ static void get_flags(void)
9066
9067 if (max_intel_level >= 0x00000001 &&
9068 max_intel_level <= 0x0000ffff) {
9069- asm("cpuid"
9070+ asm volatile("cpuid"
9071 : "=a" (tfms),
9072 "=c" (cpu.flags[4]),
9073 "=d" (cpu.flags[0])
9074@@ -136,7 +136,7 @@ static void get_flags(void)
9075 cpu.model += ((tfms >> 16) & 0xf) << 4;
9076 }
9077
9078- asm("cpuid"
9079+ asm volatile("cpuid"
9080 : "=a" (max_amd_level)
9081 : "a" (0x80000000)
9082 : "ebx", "ecx", "edx");
9083@@ -144,7 +144,7 @@ static void get_flags(void)
9084 if (max_amd_level >= 0x80000001 &&
9085 max_amd_level <= 0x8000ffff) {
9086 u32 eax = 0x80000001;
9087- asm("cpuid"
9088+ asm volatile("cpuid"
9089 : "+a" (eax),
9090 "=c" (cpu.flags[6]),
9091 "=d" (cpu.flags[1])
9092@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9093 u32 ecx = MSR_K7_HWCR;
9094 u32 eax, edx;
9095
9096- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9097+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9098 eax &= ~(1 << 15);
9099- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9100+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9101
9102 get_flags(); /* Make sure it really did something */
9103 err = check_flags();
9104@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9105 u32 ecx = MSR_VIA_FCR;
9106 u32 eax, edx;
9107
9108- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9109+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9110 eax |= (1<<1)|(1<<7);
9111- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9112+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9113
9114 set_bit(X86_FEATURE_CX8, cpu.flags);
9115 err = check_flags();
9116@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
9117 u32 eax, edx;
9118 u32 level = 1;
9119
9120- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9121- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9122- asm("cpuid"
9123+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
9124+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
9125+ asm volatile("cpuid"
9126 : "+a" (level), "=d" (cpu.flags[0])
9127 : : "ecx", "ebx");
9128- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9129+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
9130
9131 err = check_flags();
9132 }
9133diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9134index 8c132a6..13e5c96 100644
9135--- a/arch/x86/boot/header.S
9136+++ b/arch/x86/boot/header.S
9137@@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9138 # single linked list of
9139 # struct setup_data
9140
9141-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9142+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9143
9144 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9146+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9147+#else
9148 #define VO_INIT_SIZE (VO__end - VO__text)
9149+#endif
9150 #if ZO_INIT_SIZE > VO_INIT_SIZE
9151 #define INIT_SIZE ZO_INIT_SIZE
9152 #else
9153diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9154index db75d07..8e6d0af 100644
9155--- a/arch/x86/boot/memory.c
9156+++ b/arch/x86/boot/memory.c
9157@@ -19,7 +19,7 @@
9158
9159 static int detect_memory_e820(void)
9160 {
9161- int count = 0;
9162+ unsigned int count = 0;
9163 struct biosregs ireg, oreg;
9164 struct e820entry *desc = boot_params.e820_map;
9165 static struct e820entry buf; /* static so it is zeroed */
9166diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9167index 11e8c6e..fdbb1ed 100644
9168--- a/arch/x86/boot/video-vesa.c
9169+++ b/arch/x86/boot/video-vesa.c
9170@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9171
9172 boot_params.screen_info.vesapm_seg = oreg.es;
9173 boot_params.screen_info.vesapm_off = oreg.di;
9174+ boot_params.screen_info.vesapm_size = oreg.cx;
9175 }
9176
9177 /*
9178diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9179index 43eda28..5ab5fdb 100644
9180--- a/arch/x86/boot/video.c
9181+++ b/arch/x86/boot/video.c
9182@@ -96,7 +96,7 @@ static void store_mode_params(void)
9183 static unsigned int get_entry(void)
9184 {
9185 char entry_buf[4];
9186- int i, len = 0;
9187+ unsigned int i, len = 0;
9188 int key;
9189 unsigned int v;
9190
9191diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9192index 5b577d5..3c1fed4 100644
9193--- a/arch/x86/crypto/aes-x86_64-asm_64.S
9194+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9195@@ -8,6 +8,8 @@
9196 * including this sentence is retained in full.
9197 */
9198
9199+#include <asm/alternative-asm.h>
9200+
9201 .extern crypto_ft_tab
9202 .extern crypto_it_tab
9203 .extern crypto_fl_tab
9204@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9205 je B192; \
9206 leaq 32(r9),r9;
9207
9208+#define ret pax_force_retaddr 0, 1; ret
9209+
9210 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9211 movq r1,r2; \
9212 movq r3,r4; \
9213diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9214index 3470624..201259d 100644
9215--- a/arch/x86/crypto/aesni-intel_asm.S
9216+++ b/arch/x86/crypto/aesni-intel_asm.S
9217@@ -31,6 +31,7 @@
9218
9219 #include <linux/linkage.h>
9220 #include <asm/inst.h>
9221+#include <asm/alternative-asm.h>
9222
9223 #ifdef __x86_64__
9224 .data
9225@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9226 pop %r14
9227 pop %r13
9228 pop %r12
9229+ pax_force_retaddr 0, 1
9230 ret
9231+ENDPROC(aesni_gcm_dec)
9232
9233
9234 /*****************************************************************************
9235@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9236 pop %r14
9237 pop %r13
9238 pop %r12
9239+ pax_force_retaddr 0, 1
9240 ret
9241+ENDPROC(aesni_gcm_enc)
9242
9243 #endif
9244
9245@@ -1714,6 +1719,7 @@ _key_expansion_256a:
9246 pxor %xmm1, %xmm0
9247 movaps %xmm0, (TKEYP)
9248 add $0x10, TKEYP
9249+ pax_force_retaddr_bts
9250 ret
9251
9252 .align 4
9253@@ -1738,6 +1744,7 @@ _key_expansion_192a:
9254 shufps $0b01001110, %xmm2, %xmm1
9255 movaps %xmm1, 0x10(TKEYP)
9256 add $0x20, TKEYP
9257+ pax_force_retaddr_bts
9258 ret
9259
9260 .align 4
9261@@ -1757,6 +1764,7 @@ _key_expansion_192b:
9262
9263 movaps %xmm0, (TKEYP)
9264 add $0x10, TKEYP
9265+ pax_force_retaddr_bts
9266 ret
9267
9268 .align 4
9269@@ -1769,6 +1777,7 @@ _key_expansion_256b:
9270 pxor %xmm1, %xmm2
9271 movaps %xmm2, (TKEYP)
9272 add $0x10, TKEYP
9273+ pax_force_retaddr_bts
9274 ret
9275
9276 /*
9277@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9278 #ifndef __x86_64__
9279 popl KEYP
9280 #endif
9281+ pax_force_retaddr 0, 1
9282 ret
9283+ENDPROC(aesni_set_key)
9284
9285 /*
9286 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9287@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9288 popl KLEN
9289 popl KEYP
9290 #endif
9291+ pax_force_retaddr 0, 1
9292 ret
9293+ENDPROC(aesni_enc)
9294
9295 /*
9296 * _aesni_enc1: internal ABI
9297@@ -1959,6 +1972,7 @@ _aesni_enc1:
9298 AESENC KEY STATE
9299 movaps 0x70(TKEYP), KEY
9300 AESENCLAST KEY STATE
9301+ pax_force_retaddr_bts
9302 ret
9303
9304 /*
9305@@ -2067,6 +2081,7 @@ _aesni_enc4:
9306 AESENCLAST KEY STATE2
9307 AESENCLAST KEY STATE3
9308 AESENCLAST KEY STATE4
9309+ pax_force_retaddr_bts
9310 ret
9311
9312 /*
9313@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9314 popl KLEN
9315 popl KEYP
9316 #endif
9317+ pax_force_retaddr 0, 1
9318 ret
9319+ENDPROC(aesni_dec)
9320
9321 /*
9322 * _aesni_dec1: internal ABI
9323@@ -2146,6 +2163,7 @@ _aesni_dec1:
9324 AESDEC KEY STATE
9325 movaps 0x70(TKEYP), KEY
9326 AESDECLAST KEY STATE
9327+ pax_force_retaddr_bts
9328 ret
9329
9330 /*
9331@@ -2254,6 +2272,7 @@ _aesni_dec4:
9332 AESDECLAST KEY STATE2
9333 AESDECLAST KEY STATE3
9334 AESDECLAST KEY STATE4
9335+ pax_force_retaddr_bts
9336 ret
9337
9338 /*
9339@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9340 popl KEYP
9341 popl LEN
9342 #endif
9343+ pax_force_retaddr 0, 1
9344 ret
9345+ENDPROC(aesni_ecb_enc)
9346
9347 /*
9348 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9349@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9350 popl KEYP
9351 popl LEN
9352 #endif
9353+ pax_force_retaddr 0, 1
9354 ret
9355+ENDPROC(aesni_ecb_dec)
9356
9357 /*
9358 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9359@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9360 popl LEN
9361 popl IVP
9362 #endif
9363+ pax_force_retaddr 0, 1
9364 ret
9365+ENDPROC(aesni_cbc_enc)
9366
9367 /*
9368 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9369@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9370 popl LEN
9371 popl IVP
9372 #endif
9373+ pax_force_retaddr 0, 1
9374 ret
9375+ENDPROC(aesni_cbc_dec)
9376
9377 #ifdef __x86_64__
9378 .align 16
9379@@ -2526,6 +2553,7 @@ _aesni_inc_init:
9380 mov $1, TCTR_LOW
9381 MOVQ_R64_XMM TCTR_LOW INC
9382 MOVQ_R64_XMM CTR TCTR_LOW
9383+ pax_force_retaddr_bts
9384 ret
9385
9386 /*
9387@@ -2554,6 +2582,7 @@ _aesni_inc:
9388 .Linc_low:
9389 movaps CTR, IV
9390 PSHUFB_XMM BSWAP_MASK IV
9391+ pax_force_retaddr_bts
9392 ret
9393
9394 /*
9395@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9396 .Lctr_enc_ret:
9397 movups IV, (IVP)
9398 .Lctr_enc_just_ret:
9399+ pax_force_retaddr 0, 1
9400 ret
9401+ENDPROC(aesni_ctr_enc)
9402 #endif
9403diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9404index 391d245..67f35c2 100644
9405--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9406+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9407@@ -20,6 +20,8 @@
9408 *
9409 */
9410
9411+#include <asm/alternative-asm.h>
9412+
9413 .file "blowfish-x86_64-asm.S"
9414 .text
9415
9416@@ -151,9 +153,11 @@ __blowfish_enc_blk:
9417 jnz __enc_xor;
9418
9419 write_block();
9420+ pax_force_retaddr 0, 1
9421 ret;
9422 __enc_xor:
9423 xor_block();
9424+ pax_force_retaddr 0, 1
9425 ret;
9426
9427 .align 8
9428@@ -188,6 +192,7 @@ blowfish_dec_blk:
9429
9430 movq %r11, %rbp;
9431
9432+ pax_force_retaddr 0, 1
9433 ret;
9434
9435 /**********************************************************************
9436@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9437
9438 popq %rbx;
9439 popq %rbp;
9440+ pax_force_retaddr 0, 1
9441 ret;
9442
9443 __enc_xor4:
9444@@ -349,6 +355,7 @@ __enc_xor4:
9445
9446 popq %rbx;
9447 popq %rbp;
9448+ pax_force_retaddr 0, 1
9449 ret;
9450
9451 .align 8
9452@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9453 popq %rbx;
9454 popq %rbp;
9455
9456+ pax_force_retaddr 0, 1
9457 ret;
9458
9459diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9460index 0b33743..7a56206 100644
9461--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9462+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9463@@ -20,6 +20,8 @@
9464 *
9465 */
9466
9467+#include <asm/alternative-asm.h>
9468+
9469 .file "camellia-x86_64-asm_64.S"
9470 .text
9471
9472@@ -229,12 +231,14 @@ __enc_done:
9473 enc_outunpack(mov, RT1);
9474
9475 movq RRBP, %rbp;
9476+ pax_force_retaddr 0, 1
9477 ret;
9478
9479 __enc_xor:
9480 enc_outunpack(xor, RT1);
9481
9482 movq RRBP, %rbp;
9483+ pax_force_retaddr 0, 1
9484 ret;
9485
9486 .global camellia_dec_blk;
9487@@ -275,6 +279,7 @@ __dec_rounds16:
9488 dec_outunpack();
9489
9490 movq RRBP, %rbp;
9491+ pax_force_retaddr 0, 1
9492 ret;
9493
9494 /**********************************************************************
9495@@ -468,6 +473,7 @@ __enc2_done:
9496
9497 movq RRBP, %rbp;
9498 popq %rbx;
9499+ pax_force_retaddr 0, 1
9500 ret;
9501
9502 __enc2_xor:
9503@@ -475,6 +481,7 @@ __enc2_xor:
9504
9505 movq RRBP, %rbp;
9506 popq %rbx;
9507+ pax_force_retaddr 0, 1
9508 ret;
9509
9510 .global camellia_dec_blk_2way;
9511@@ -517,4 +524,5 @@ __dec2_rounds16:
9512
9513 movq RRBP, %rbp;
9514 movq RXOR, %rbx;
9515+ pax_force_retaddr 0, 1
9516 ret;
9517diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9518index a41a3aa..bdf5753 100644
9519--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9520+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9521@@ -23,6 +23,8 @@
9522 *
9523 */
9524
9525+#include <asm/alternative-asm.h>
9526+
9527 .file "cast5-avx-x86_64-asm_64.S"
9528
9529 .extern cast5_s1
9530@@ -293,6 +295,7 @@ __skip_enc:
9531 leaq 3*(2*4*4)(%r11), %rax;
9532 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9533
9534+ pax_force_retaddr 0, 1
9535 ret;
9536
9537 __enc_xor16:
9538@@ -303,6 +306,7 @@ __enc_xor16:
9539 leaq 3*(2*4*4)(%r11), %rax;
9540 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9541
9542+ pax_force_retaddr 0, 1
9543 ret;
9544
9545 .align 16
9546@@ -369,6 +373,7 @@ __dec_tail:
9547 leaq 3*(2*4*4)(%r11), %rax;
9548 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9549
9550+ pax_force_retaddr 0, 1
9551 ret;
9552
9553 __skip_dec:
9554diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9555index 218d283..819e6da 100644
9556--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9557+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9558@@ -23,6 +23,8 @@
9559 *
9560 */
9561
9562+#include <asm/alternative-asm.h>
9563+
9564 .file "cast6-avx-x86_64-asm_64.S"
9565
9566 .extern cast6_s1
9567@@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9568 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9569 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9570
9571+ pax_force_retaddr 0, 1
9572 ret;
9573
9574 __enc_xor8:
9575 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9576 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9577
9578+ pax_force_retaddr 0, 1
9579 ret;
9580
9581 .align 16
9582@@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9583 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9584 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9585
9586+ pax_force_retaddr 0, 1
9587 ret;
9588diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9589index 6214a9b..1f4fc9a 100644
9590--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9591+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9592@@ -1,3 +1,5 @@
9593+#include <asm/alternative-asm.h>
9594+
9595 # enter ECRYPT_encrypt_bytes
9596 .text
9597 .p2align 5
9598@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9599 add %r11,%rsp
9600 mov %rdi,%rax
9601 mov %rsi,%rdx
9602+ pax_force_retaddr 0, 1
9603 ret
9604 # bytesatleast65:
9605 ._bytesatleast65:
9606@@ -891,6 +894,7 @@ ECRYPT_keysetup:
9607 add %r11,%rsp
9608 mov %rdi,%rax
9609 mov %rsi,%rdx
9610+ pax_force_retaddr
9611 ret
9612 # enter ECRYPT_ivsetup
9613 .text
9614@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9615 add %r11,%rsp
9616 mov %rdi,%rax
9617 mov %rsi,%rdx
9618+ pax_force_retaddr
9619 ret
9620diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9621index 504106b..4e50951 100644
9622--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9623+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9624@@ -24,6 +24,8 @@
9625 *
9626 */
9627
9628+#include <asm/alternative-asm.h>
9629+
9630 .file "serpent-avx-x86_64-asm_64.S"
9631 .text
9632
9633@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9634 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9635 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9636
9637+ pax_force_retaddr
9638 ret;
9639
9640 __enc_xor8:
9641 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9642 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9643
9644+ pax_force_retaddr
9645 ret;
9646
9647 .align 8
9648@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9649 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9650 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9651
9652+ pax_force_retaddr
9653 ret;
9654diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9655index 3ee1ff0..cbc568b 100644
9656--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9657+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9658@@ -24,6 +24,8 @@
9659 *
9660 */
9661
9662+#include <asm/alternative-asm.h>
9663+
9664 .file "serpent-sse2-x86_64-asm_64.S"
9665 .text
9666
9667@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9668 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9669 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9670
9671+ pax_force_retaddr
9672 ret;
9673
9674 __enc_xor8:
9675 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9676 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9677
9678+ pax_force_retaddr
9679 ret;
9680
9681 .align 8
9682@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9683 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9684 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9685
9686+ pax_force_retaddr
9687 ret;
9688diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9689index 49d6987..df66bd4 100644
9690--- a/arch/x86/crypto/sha1_ssse3_asm.S
9691+++ b/arch/x86/crypto/sha1_ssse3_asm.S
9692@@ -28,6 +28,8 @@
9693 * (at your option) any later version.
9694 */
9695
9696+#include <asm/alternative-asm.h>
9697+
9698 #define CTX %rdi // arg1
9699 #define BUF %rsi // arg2
9700 #define CNT %rdx // arg3
9701@@ -104,6 +106,7 @@
9702 pop %r12
9703 pop %rbp
9704 pop %rbx
9705+ pax_force_retaddr 0, 1
9706 ret
9707
9708 .size \name, .-\name
9709diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9710index 1585abb..1ff9d9b 100644
9711--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9712+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9713@@ -23,6 +23,8 @@
9714 *
9715 */
9716
9717+#include <asm/alternative-asm.h>
9718+
9719 .file "twofish-avx-x86_64-asm_64.S"
9720 .text
9721
9722@@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9723 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9724 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9725
9726+ pax_force_retaddr 0, 1
9727 ret;
9728
9729 __enc_xor8:
9730 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9731 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9732
9733+ pax_force_retaddr 0, 1
9734 ret;
9735
9736 .align 8
9737@@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9738 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9739 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9740
9741+ pax_force_retaddr 0, 1
9742 ret;
9743diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9744index 5b012a2..36d5364 100644
9745--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9746+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9747@@ -20,6 +20,8 @@
9748 *
9749 */
9750
9751+#include <asm/alternative-asm.h>
9752+
9753 .file "twofish-x86_64-asm-3way.S"
9754 .text
9755
9756@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9757 popq %r13;
9758 popq %r14;
9759 popq %r15;
9760+ pax_force_retaddr 0, 1
9761 ret;
9762
9763 __enc_xor3:
9764@@ -271,6 +274,7 @@ __enc_xor3:
9765 popq %r13;
9766 popq %r14;
9767 popq %r15;
9768+ pax_force_retaddr 0, 1
9769 ret;
9770
9771 .global twofish_dec_blk_3way
9772@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9773 popq %r13;
9774 popq %r14;
9775 popq %r15;
9776+ pax_force_retaddr 0, 1
9777 ret;
9778
9779diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9780index 7bcf3fc..f53832f 100644
9781--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9782+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9783@@ -21,6 +21,7 @@
9784 .text
9785
9786 #include <asm/asm-offsets.h>
9787+#include <asm/alternative-asm.h>
9788
9789 #define a_offset 0
9790 #define b_offset 4
9791@@ -268,6 +269,7 @@ twofish_enc_blk:
9792
9793 popq R1
9794 movq $1,%rax
9795+ pax_force_retaddr 0, 1
9796 ret
9797
9798 twofish_dec_blk:
9799@@ -319,4 +321,5 @@ twofish_dec_blk:
9800
9801 popq R1
9802 movq $1,%rax
9803+ pax_force_retaddr 0, 1
9804 ret
9805diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9806index 07b3a68..bd2a388 100644
9807--- a/arch/x86/ia32/ia32_aout.c
9808+++ b/arch/x86/ia32/ia32_aout.c
9809@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9810 unsigned long dump_start, dump_size;
9811 struct user32 dump;
9812
9813+ memset(&dump, 0, sizeof(dump));
9814+
9815 fs = get_fs();
9816 set_fs(KERNEL_DS);
9817 has_dumped = 1;
9818diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9819index efc6a95..95abfe2 100644
9820--- a/arch/x86/ia32/ia32_signal.c
9821+++ b/arch/x86/ia32/ia32_signal.c
9822@@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9823 }
9824 seg = get_fs();
9825 set_fs(KERNEL_DS);
9826- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9827- (stack_t __force __user *) &uoss, regs->sp);
9828+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9829+ (stack_t __force_user *) &uoss, regs->sp);
9830 set_fs(seg);
9831 if (ret >= 0 && uoss_ptr) {
9832 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9833@@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9834 sp -= frame_size;
9835 /* Align the stack pointer according to the i386 ABI,
9836 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9837- sp = ((sp + 4) & -16ul) - 4;
9838+ sp = ((sp - 12) & -16ul) - 4;
9839 return (void __user *) sp;
9840 }
9841
9842@@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9843 * These are actually not used anymore, but left because some
9844 * gdb versions depend on them as a marker.
9845 */
9846- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9847+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9848 } put_user_catch(err);
9849
9850 if (err)
9851@@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9852 0xb8,
9853 __NR_ia32_rt_sigreturn,
9854 0x80cd,
9855- 0,
9856+ 0
9857 };
9858
9859 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9860@@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9861
9862 if (ka->sa.sa_flags & SA_RESTORER)
9863 restorer = ka->sa.sa_restorer;
9864+ else if (current->mm->context.vdso)
9865+ /* Return stub is in 32bit vsyscall page */
9866+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9867 else
9868- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9869- rt_sigreturn);
9870+ restorer = &frame->retcode;
9871 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9872
9873 /*
9874 * Not actually used anymore, but left because some gdb
9875 * versions need it.
9876 */
9877- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9878+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9879 } put_user_catch(err);
9880
9881 err |= copy_siginfo_to_user32(&frame->info, info);
9882diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9883index e7fa545..9e6fe1a 100644
9884--- a/arch/x86/ia32/ia32entry.S
9885+++ b/arch/x86/ia32/ia32entry.S
9886@@ -15,8 +15,10 @@
9887 #include <asm/irqflags.h>
9888 #include <asm/asm.h>
9889 #include <asm/smap.h>
9890+#include <asm/pgtable.h>
9891 #include <linux/linkage.h>
9892 #include <linux/err.h>
9893+#include <asm/alternative-asm.h>
9894
9895 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9896 #include <linux/elf-em.h>
9897@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9898 ENDPROC(native_irq_enable_sysexit)
9899 #endif
9900
9901+ .macro pax_enter_kernel_user
9902+ pax_set_fptr_mask
9903+#ifdef CONFIG_PAX_MEMORY_UDEREF
9904+ call pax_enter_kernel_user
9905+#endif
9906+ .endm
9907+
9908+ .macro pax_exit_kernel_user
9909+#ifdef CONFIG_PAX_MEMORY_UDEREF
9910+ call pax_exit_kernel_user
9911+#endif
9912+#ifdef CONFIG_PAX_RANDKSTACK
9913+ pushq %rax
9914+ pushq %r11
9915+ call pax_randomize_kstack
9916+ popq %r11
9917+ popq %rax
9918+#endif
9919+ .endm
9920+
9921+.macro pax_erase_kstack
9922+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9923+ call pax_erase_kstack
9924+#endif
9925+.endm
9926+
9927 /*
9928 * 32bit SYSENTER instruction entry.
9929 *
9930@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9931 CFI_REGISTER rsp,rbp
9932 SWAPGS_UNSAFE_STACK
9933 movq PER_CPU_VAR(kernel_stack), %rsp
9934- addq $(KERNEL_STACK_OFFSET),%rsp
9935- /*
9936- * No need to follow this irqs on/off section: the syscall
9937- * disabled irqs, here we enable it straight after entry:
9938- */
9939- ENABLE_INTERRUPTS(CLBR_NONE)
9940 movl %ebp,%ebp /* zero extension */
9941 pushq_cfi $__USER32_DS
9942 /*CFI_REL_OFFSET ss,0*/
9943@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9944 CFI_REL_OFFSET rsp,0
9945 pushfq_cfi
9946 /*CFI_REL_OFFSET rflags,0*/
9947- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9948- CFI_REGISTER rip,r10
9949+ orl $X86_EFLAGS_IF,(%rsp)
9950+ GET_THREAD_INFO(%r11)
9951+ movl TI_sysenter_return(%r11), %r11d
9952+ CFI_REGISTER rip,r11
9953 pushq_cfi $__USER32_CS
9954 /*CFI_REL_OFFSET cs,0*/
9955 movl %eax, %eax
9956- pushq_cfi %r10
9957+ pushq_cfi %r11
9958 CFI_REL_OFFSET rip,0
9959 pushq_cfi %rax
9960 cld
9961 SAVE_ARGS 0,1,0
9962+ pax_enter_kernel_user
9963+
9964+#ifdef CONFIG_PAX_RANDKSTACK
9965+ pax_erase_kstack
9966+#endif
9967+
9968+ /*
9969+ * No need to follow this irqs on/off section: the syscall
9970+ * disabled irqs, here we enable it straight after entry:
9971+ */
9972+ ENABLE_INTERRUPTS(CLBR_NONE)
9973 /* no need to do an access_ok check here because rbp has been
9974 32bit zero extended */
9975+
9976+#ifdef CONFIG_PAX_MEMORY_UDEREF
9977+ mov $PAX_USER_SHADOW_BASE,%r11
9978+ add %r11,%rbp
9979+#endif
9980+
9981 ASM_STAC
9982 1: movl (%rbp),%ebp
9983 _ASM_EXTABLE(1b,ia32_badarg)
9984 ASM_CLAC
9985- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9986- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9987+ GET_THREAD_INFO(%r11)
9988+ orl $TS_COMPAT,TI_status(%r11)
9989+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9990 CFI_REMEMBER_STATE
9991 jnz sysenter_tracesys
9992 cmpq $(IA32_NR_syscalls-1),%rax
9993@@ -162,12 +204,15 @@ sysenter_do_call:
9994 sysenter_dispatch:
9995 call *ia32_sys_call_table(,%rax,8)
9996 movq %rax,RAX-ARGOFFSET(%rsp)
9997+ GET_THREAD_INFO(%r11)
9998 DISABLE_INTERRUPTS(CLBR_NONE)
9999 TRACE_IRQS_OFF
10000- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10001+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10002 jnz sysexit_audit
10003 sysexit_from_sys_call:
10004- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10005+ pax_exit_kernel_user
10006+ pax_erase_kstack
10007+ andl $~TS_COMPAT,TI_status(%r11)
10008 /* clear IF, that popfq doesn't enable interrupts early */
10009 andl $~0x200,EFLAGS-R11(%rsp)
10010 movl RIP-R11(%rsp),%edx /* User %eip */
10011@@ -193,6 +238,9 @@ sysexit_from_sys_call:
10012 movl %eax,%esi /* 2nd arg: syscall number */
10013 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
10014 call __audit_syscall_entry
10015+
10016+ pax_erase_kstack
10017+
10018 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
10019 cmpq $(IA32_NR_syscalls-1),%rax
10020 ja ia32_badsys
10021@@ -204,7 +252,7 @@ sysexit_from_sys_call:
10022 .endm
10023
10024 .macro auditsys_exit exit
10025- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10026+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10027 jnz ia32_ret_from_sys_call
10028 TRACE_IRQS_ON
10029 ENABLE_INTERRUPTS(CLBR_NONE)
10030@@ -215,11 +263,12 @@ sysexit_from_sys_call:
10031 1: setbe %al /* 1 if error, 0 if not */
10032 movzbl %al,%edi /* zero-extend that into %edi */
10033 call __audit_syscall_exit
10034+ GET_THREAD_INFO(%r11)
10035 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
10036 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
10037 DISABLE_INTERRUPTS(CLBR_NONE)
10038 TRACE_IRQS_OFF
10039- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10040+ testl %edi,TI_flags(%r11)
10041 jz \exit
10042 CLEAR_RREGS -ARGOFFSET
10043 jmp int_with_check
10044@@ -237,7 +286,7 @@ sysexit_audit:
10045
10046 sysenter_tracesys:
10047 #ifdef CONFIG_AUDITSYSCALL
10048- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10049+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10050 jz sysenter_auditsys
10051 #endif
10052 SAVE_REST
10053@@ -249,6 +298,9 @@ sysenter_tracesys:
10054 RESTORE_REST
10055 cmpq $(IA32_NR_syscalls-1),%rax
10056 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
10057+
10058+ pax_erase_kstack
10059+
10060 jmp sysenter_do_call
10061 CFI_ENDPROC
10062 ENDPROC(ia32_sysenter_target)
10063@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
10064 ENTRY(ia32_cstar_target)
10065 CFI_STARTPROC32 simple
10066 CFI_SIGNAL_FRAME
10067- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
10068+ CFI_DEF_CFA rsp,0
10069 CFI_REGISTER rip,rcx
10070 /*CFI_REGISTER rflags,r11*/
10071 SWAPGS_UNSAFE_STACK
10072 movl %esp,%r8d
10073 CFI_REGISTER rsp,r8
10074 movq PER_CPU_VAR(kernel_stack),%rsp
10075+ SAVE_ARGS 8*6,0,0
10076+ pax_enter_kernel_user
10077+
10078+#ifdef CONFIG_PAX_RANDKSTACK
10079+ pax_erase_kstack
10080+#endif
10081+
10082 /*
10083 * No need to follow this irqs on/off section: the syscall
10084 * disabled irqs and here we enable it straight after entry:
10085 */
10086 ENABLE_INTERRUPTS(CLBR_NONE)
10087- SAVE_ARGS 8,0,0
10088 movl %eax,%eax /* zero extension */
10089 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
10090 movq %rcx,RIP-ARGOFFSET(%rsp)
10091@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
10092 /* no need to do an access_ok check here because r8 has been
10093 32bit zero extended */
10094 /* hardware stack frame is complete now */
10095+
10096+#ifdef CONFIG_PAX_MEMORY_UDEREF
10097+ mov $PAX_USER_SHADOW_BASE,%r11
10098+ add %r11,%r8
10099+#endif
10100+
10101 ASM_STAC
10102 1: movl (%r8),%r9d
10103 _ASM_EXTABLE(1b,ia32_badarg)
10104 ASM_CLAC
10105- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10106- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10107+ GET_THREAD_INFO(%r11)
10108+ orl $TS_COMPAT,TI_status(%r11)
10109+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10110 CFI_REMEMBER_STATE
10111 jnz cstar_tracesys
10112 cmpq $IA32_NR_syscalls-1,%rax
10113@@ -319,12 +384,15 @@ cstar_do_call:
10114 cstar_dispatch:
10115 call *ia32_sys_call_table(,%rax,8)
10116 movq %rax,RAX-ARGOFFSET(%rsp)
10117+ GET_THREAD_INFO(%r11)
10118 DISABLE_INTERRUPTS(CLBR_NONE)
10119 TRACE_IRQS_OFF
10120- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10121+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
10122 jnz sysretl_audit
10123 sysretl_from_sys_call:
10124- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10125+ pax_exit_kernel_user
10126+ pax_erase_kstack
10127+ andl $~TS_COMPAT,TI_status(%r11)
10128 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
10129 movl RIP-ARGOFFSET(%rsp),%ecx
10130 CFI_REGISTER rip,rcx
10131@@ -352,7 +420,7 @@ sysretl_audit:
10132
10133 cstar_tracesys:
10134 #ifdef CONFIG_AUDITSYSCALL
10135- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10136+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10137 jz cstar_auditsys
10138 #endif
10139 xchgl %r9d,%ebp
10140@@ -366,6 +434,9 @@ cstar_tracesys:
10141 xchgl %ebp,%r9d
10142 cmpq $(IA32_NR_syscalls-1),%rax
10143 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10144+
10145+ pax_erase_kstack
10146+
10147 jmp cstar_do_call
10148 END(ia32_cstar_target)
10149
10150@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10151 CFI_REL_OFFSET rip,RIP-RIP
10152 PARAVIRT_ADJUST_EXCEPTION_FRAME
10153 SWAPGS
10154- /*
10155- * No need to follow this irqs on/off section: the syscall
10156- * disabled irqs and here we enable it straight after entry:
10157- */
10158- ENABLE_INTERRUPTS(CLBR_NONE)
10159 movl %eax,%eax
10160 pushq_cfi %rax
10161 cld
10162 /* note the registers are not zero extended to the sf.
10163 this could be a problem. */
10164 SAVE_ARGS 0,1,0
10165- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10166- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10167+ pax_enter_kernel_user
10168+
10169+#ifdef CONFIG_PAX_RANDKSTACK
10170+ pax_erase_kstack
10171+#endif
10172+
10173+ /*
10174+ * No need to follow this irqs on/off section: the syscall
10175+ * disabled irqs and here we enable it straight after entry:
10176+ */
10177+ ENABLE_INTERRUPTS(CLBR_NONE)
10178+ GET_THREAD_INFO(%r11)
10179+ orl $TS_COMPAT,TI_status(%r11)
10180+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10181 jnz ia32_tracesys
10182 cmpq $(IA32_NR_syscalls-1),%rax
10183 ja ia32_badsys
10184@@ -442,6 +520,9 @@ ia32_tracesys:
10185 RESTORE_REST
10186 cmpq $(IA32_NR_syscalls-1),%rax
10187 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10188+
10189+ pax_erase_kstack
10190+
10191 jmp ia32_do_call
10192 END(ia32_syscall)
10193
10194diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10195index 86d68d1..f9960fe 100644
10196--- a/arch/x86/ia32/sys_ia32.c
10197+++ b/arch/x86/ia32/sys_ia32.c
10198@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10199 */
10200 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10201 {
10202- typeof(ubuf->st_uid) uid = 0;
10203- typeof(ubuf->st_gid) gid = 0;
10204+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
10205+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
10206 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10207 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10208 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10209@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10210 mm_segment_t old_fs = get_fs();
10211
10212 set_fs(KERNEL_DS);
10213- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10214+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10215 set_fs(old_fs);
10216 if (put_compat_timespec(&t, interval))
10217 return -EFAULT;
10218@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10219 mm_segment_t old_fs = get_fs();
10220
10221 set_fs(KERNEL_DS);
10222- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10223+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10224 set_fs(old_fs);
10225 if (!ret) {
10226 switch (_NSIG_WORDS) {
10227@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10228 if (copy_siginfo_from_user32(&info, uinfo))
10229 return -EFAULT;
10230 set_fs(KERNEL_DS);
10231- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10232+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10233 set_fs(old_fs);
10234 return ret;
10235 }
10236@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10237 return -EFAULT;
10238
10239 set_fs(KERNEL_DS);
10240- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10241+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10242 count);
10243 set_fs(old_fs);
10244
10245diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10246index 372231c..a5aa1a1 100644
10247--- a/arch/x86/include/asm/alternative-asm.h
10248+++ b/arch/x86/include/asm/alternative-asm.h
10249@@ -18,6 +18,45 @@
10250 .endm
10251 #endif
10252
10253+#ifdef KERNEXEC_PLUGIN
10254+ .macro pax_force_retaddr_bts rip=0
10255+ btsq $63,\rip(%rsp)
10256+ .endm
10257+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10258+ .macro pax_force_retaddr rip=0, reload=0
10259+ btsq $63,\rip(%rsp)
10260+ .endm
10261+ .macro pax_force_fptr ptr
10262+ btsq $63,\ptr
10263+ .endm
10264+ .macro pax_set_fptr_mask
10265+ .endm
10266+#endif
10267+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10268+ .macro pax_force_retaddr rip=0, reload=0
10269+ .if \reload
10270+ pax_set_fptr_mask
10271+ .endif
10272+ orq %r10,\rip(%rsp)
10273+ .endm
10274+ .macro pax_force_fptr ptr
10275+ orq %r10,\ptr
10276+ .endm
10277+ .macro pax_set_fptr_mask
10278+ movabs $0x8000000000000000,%r10
10279+ .endm
10280+#endif
10281+#else
10282+ .macro pax_force_retaddr rip=0, reload=0
10283+ .endm
10284+ .macro pax_force_fptr ptr
10285+ .endm
10286+ .macro pax_force_retaddr_bts rip=0
10287+ .endm
10288+ .macro pax_set_fptr_mask
10289+ .endm
10290+#endif
10291+
10292 .macro altinstruction_entry orig alt feature orig_len alt_len
10293 .long \orig - .
10294 .long \alt - .
10295diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10296index 58ed6d9..f1cbe58 100644
10297--- a/arch/x86/include/asm/alternative.h
10298+++ b/arch/x86/include/asm/alternative.h
10299@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10300 ".pushsection .discard,\"aw\",@progbits\n" \
10301 DISCARD_ENTRY(1) \
10302 ".popsection\n" \
10303- ".pushsection .altinstr_replacement, \"ax\"\n" \
10304+ ".pushsection .altinstr_replacement, \"a\"\n" \
10305 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10306 ".popsection"
10307
10308@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10309 DISCARD_ENTRY(1) \
10310 DISCARD_ENTRY(2) \
10311 ".popsection\n" \
10312- ".pushsection .altinstr_replacement, \"ax\"\n" \
10313+ ".pushsection .altinstr_replacement, \"a\"\n" \
10314 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10315 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10316 ".popsection"
10317diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10318index 3388034..050f0b9 100644
10319--- a/arch/x86/include/asm/apic.h
10320+++ b/arch/x86/include/asm/apic.h
10321@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10322
10323 #ifdef CONFIG_X86_LOCAL_APIC
10324
10325-extern unsigned int apic_verbosity;
10326+extern int apic_verbosity;
10327 extern int local_apic_timer_c2_ok;
10328
10329 extern int disable_apic;
10330diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10331index 20370c6..a2eb9b0 100644
10332--- a/arch/x86/include/asm/apm.h
10333+++ b/arch/x86/include/asm/apm.h
10334@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10335 __asm__ __volatile__(APM_DO_ZERO_SEGS
10336 "pushl %%edi\n\t"
10337 "pushl %%ebp\n\t"
10338- "lcall *%%cs:apm_bios_entry\n\t"
10339+ "lcall *%%ss:apm_bios_entry\n\t"
10340 "setc %%al\n\t"
10341 "popl %%ebp\n\t"
10342 "popl %%edi\n\t"
10343@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10344 __asm__ __volatile__(APM_DO_ZERO_SEGS
10345 "pushl %%edi\n\t"
10346 "pushl %%ebp\n\t"
10347- "lcall *%%cs:apm_bios_entry\n\t"
10348+ "lcall *%%ss:apm_bios_entry\n\t"
10349 "setc %%bl\n\t"
10350 "popl %%ebp\n\t"
10351 "popl %%edi\n\t"
10352diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10353index b6c3b82..b4c077a 100644
10354--- a/arch/x86/include/asm/atomic.h
10355+++ b/arch/x86/include/asm/atomic.h
10356@@ -22,7 +22,18 @@
10357 */
10358 static inline int atomic_read(const atomic_t *v)
10359 {
10360- return (*(volatile int *)&(v)->counter);
10361+ return (*(volatile const int *)&(v)->counter);
10362+}
10363+
10364+/**
10365+ * atomic_read_unchecked - read atomic variable
10366+ * @v: pointer of type atomic_unchecked_t
10367+ *
10368+ * Atomically reads the value of @v.
10369+ */
10370+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10371+{
10372+ return (*(volatile const int *)&(v)->counter);
10373 }
10374
10375 /**
10376@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10377 }
10378
10379 /**
10380+ * atomic_set_unchecked - set atomic variable
10381+ * @v: pointer of type atomic_unchecked_t
10382+ * @i: required value
10383+ *
10384+ * Atomically sets the value of @v to @i.
10385+ */
10386+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10387+{
10388+ v->counter = i;
10389+}
10390+
10391+/**
10392 * atomic_add - add integer to atomic variable
10393 * @i: integer value to add
10394 * @v: pointer of type atomic_t
10395@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10396 */
10397 static inline void atomic_add(int i, atomic_t *v)
10398 {
10399- asm volatile(LOCK_PREFIX "addl %1,%0"
10400+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10401+
10402+#ifdef CONFIG_PAX_REFCOUNT
10403+ "jno 0f\n"
10404+ LOCK_PREFIX "subl %1,%0\n"
10405+ "int $4\n0:\n"
10406+ _ASM_EXTABLE(0b, 0b)
10407+#endif
10408+
10409+ : "+m" (v->counter)
10410+ : "ir" (i));
10411+}
10412+
10413+/**
10414+ * atomic_add_unchecked - add integer to atomic variable
10415+ * @i: integer value to add
10416+ * @v: pointer of type atomic_unchecked_t
10417+ *
10418+ * Atomically adds @i to @v.
10419+ */
10420+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10421+{
10422+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10423 : "+m" (v->counter)
10424 : "ir" (i));
10425 }
10426@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10427 */
10428 static inline void atomic_sub(int i, atomic_t *v)
10429 {
10430- asm volatile(LOCK_PREFIX "subl %1,%0"
10431+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10432+
10433+#ifdef CONFIG_PAX_REFCOUNT
10434+ "jno 0f\n"
10435+ LOCK_PREFIX "addl %1,%0\n"
10436+ "int $4\n0:\n"
10437+ _ASM_EXTABLE(0b, 0b)
10438+#endif
10439+
10440+ : "+m" (v->counter)
10441+ : "ir" (i));
10442+}
10443+
10444+/**
10445+ * atomic_sub_unchecked - subtract integer from atomic variable
10446+ * @i: integer value to subtract
10447+ * @v: pointer of type atomic_unchecked_t
10448+ *
10449+ * Atomically subtracts @i from @v.
10450+ */
10451+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10452+{
10453+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10454 : "+m" (v->counter)
10455 : "ir" (i));
10456 }
10457@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10458 {
10459 unsigned char c;
10460
10461- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10462+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
10463+
10464+#ifdef CONFIG_PAX_REFCOUNT
10465+ "jno 0f\n"
10466+ LOCK_PREFIX "addl %2,%0\n"
10467+ "int $4\n0:\n"
10468+ _ASM_EXTABLE(0b, 0b)
10469+#endif
10470+
10471+ "sete %1\n"
10472 : "+m" (v->counter), "=qm" (c)
10473 : "ir" (i) : "memory");
10474 return c;
10475@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10476 */
10477 static inline void atomic_inc(atomic_t *v)
10478 {
10479- asm volatile(LOCK_PREFIX "incl %0"
10480+ asm volatile(LOCK_PREFIX "incl %0\n"
10481+
10482+#ifdef CONFIG_PAX_REFCOUNT
10483+ "jno 0f\n"
10484+ LOCK_PREFIX "decl %0\n"
10485+ "int $4\n0:\n"
10486+ _ASM_EXTABLE(0b, 0b)
10487+#endif
10488+
10489+ : "+m" (v->counter));
10490+}
10491+
10492+/**
10493+ * atomic_inc_unchecked - increment atomic variable
10494+ * @v: pointer of type atomic_unchecked_t
10495+ *
10496+ * Atomically increments @v by 1.
10497+ */
10498+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10499+{
10500+ asm volatile(LOCK_PREFIX "incl %0\n"
10501 : "+m" (v->counter));
10502 }
10503
10504@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10505 */
10506 static inline void atomic_dec(atomic_t *v)
10507 {
10508- asm volatile(LOCK_PREFIX "decl %0"
10509+ asm volatile(LOCK_PREFIX "decl %0\n"
10510+
10511+#ifdef CONFIG_PAX_REFCOUNT
10512+ "jno 0f\n"
10513+ LOCK_PREFIX "incl %0\n"
10514+ "int $4\n0:\n"
10515+ _ASM_EXTABLE(0b, 0b)
10516+#endif
10517+
10518+ : "+m" (v->counter));
10519+}
10520+
10521+/**
10522+ * atomic_dec_unchecked - decrement atomic variable
10523+ * @v: pointer of type atomic_unchecked_t
10524+ *
10525+ * Atomically decrements @v by 1.
10526+ */
10527+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10528+{
10529+ asm volatile(LOCK_PREFIX "decl %0\n"
10530 : "+m" (v->counter));
10531 }
10532
10533@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10534 {
10535 unsigned char c;
10536
10537- asm volatile(LOCK_PREFIX "decl %0; sete %1"
10538+ asm volatile(LOCK_PREFIX "decl %0\n"
10539+
10540+#ifdef CONFIG_PAX_REFCOUNT
10541+ "jno 0f\n"
10542+ LOCK_PREFIX "incl %0\n"
10543+ "int $4\n0:\n"
10544+ _ASM_EXTABLE(0b, 0b)
10545+#endif
10546+
10547+ "sete %1\n"
10548 : "+m" (v->counter), "=qm" (c)
10549 : : "memory");
10550 return c != 0;
10551@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10552 {
10553 unsigned char c;
10554
10555- asm volatile(LOCK_PREFIX "incl %0; sete %1"
10556+ asm volatile(LOCK_PREFIX "incl %0\n"
10557+
10558+#ifdef CONFIG_PAX_REFCOUNT
10559+ "jno 0f\n"
10560+ LOCK_PREFIX "decl %0\n"
10561+ "int $4\n0:\n"
10562+ _ASM_EXTABLE(0b, 0b)
10563+#endif
10564+
10565+ "sete %1\n"
10566+ : "+m" (v->counter), "=qm" (c)
10567+ : : "memory");
10568+ return c != 0;
10569+}
10570+
10571+/**
10572+ * atomic_inc_and_test_unchecked - increment and test
10573+ * @v: pointer of type atomic_unchecked_t
10574+ *
10575+ * Atomically increments @v by 1
10576+ * and returns true if the result is zero, or false for all
10577+ * other cases.
10578+ */
10579+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10580+{
10581+ unsigned char c;
10582+
10583+ asm volatile(LOCK_PREFIX "incl %0\n"
10584+ "sete %1\n"
10585 : "+m" (v->counter), "=qm" (c)
10586 : : "memory");
10587 return c != 0;
10588@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10589 {
10590 unsigned char c;
10591
10592- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10593+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
10594+
10595+#ifdef CONFIG_PAX_REFCOUNT
10596+ "jno 0f\n"
10597+ LOCK_PREFIX "subl %2,%0\n"
10598+ "int $4\n0:\n"
10599+ _ASM_EXTABLE(0b, 0b)
10600+#endif
10601+
10602+ "sets %1\n"
10603 : "+m" (v->counter), "=qm" (c)
10604 : "ir" (i) : "memory");
10605 return c;
10606@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10607 goto no_xadd;
10608 #endif
10609 /* Modern 486+ processor */
10610- return i + xadd(&v->counter, i);
10611+ return i + xadd_check_overflow(&v->counter, i);
10612
10613 #ifdef CONFIG_M386
10614 no_xadd: /* Legacy 386 processor */
10615@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10616 }
10617
10618 /**
10619+ * atomic_add_return_unchecked - add integer and return
10620+ * @i: integer value to add
10621+ * @v: pointer of type atomic_unchecked_t
10622+ *
10623+ * Atomically adds @i to @v and returns @i + @v
10624+ */
10625+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10626+{
10627+#ifdef CONFIG_M386
10628+ int __i;
10629+ unsigned long flags;
10630+ if (unlikely(boot_cpu_data.x86 <= 3))
10631+ goto no_xadd;
10632+#endif
10633+ /* Modern 486+ processor */
10634+ return i + xadd(&v->counter, i);
10635+
10636+#ifdef CONFIG_M386
10637+no_xadd: /* Legacy 386 processor */
10638+ raw_local_irq_save(flags);
10639+ __i = atomic_read_unchecked(v);
10640+ atomic_set_unchecked(v, i + __i);
10641+ raw_local_irq_restore(flags);
10642+ return i + __i;
10643+#endif
10644+}
10645+
10646+/**
10647 * atomic_sub_return - subtract integer and return
10648 * @v: pointer of type atomic_t
10649 * @i: integer value to subtract
10650@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10651 }
10652
10653 #define atomic_inc_return(v) (atomic_add_return(1, v))
10654+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10655+{
10656+ return atomic_add_return_unchecked(1, v);
10657+}
10658 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10659
10660 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10661@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10662 return cmpxchg(&v->counter, old, new);
10663 }
10664
10665+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10666+{
10667+ return cmpxchg(&v->counter, old, new);
10668+}
10669+
10670 static inline int atomic_xchg(atomic_t *v, int new)
10671 {
10672 return xchg(&v->counter, new);
10673 }
10674
10675+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10676+{
10677+ return xchg(&v->counter, new);
10678+}
10679+
10680 /**
10681 * __atomic_add_unless - add unless the number is already a given value
10682 * @v: pointer of type atomic_t
10683@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10684 */
10685 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10686 {
10687- int c, old;
10688+ int c, old, new;
10689 c = atomic_read(v);
10690 for (;;) {
10691- if (unlikely(c == (u)))
10692+ if (unlikely(c == u))
10693 break;
10694- old = atomic_cmpxchg((v), c, c + (a));
10695+
10696+ asm volatile("addl %2,%0\n"
10697+
10698+#ifdef CONFIG_PAX_REFCOUNT
10699+ "jno 0f\n"
10700+ "subl %2,%0\n"
10701+ "int $4\n0:\n"
10702+ _ASM_EXTABLE(0b, 0b)
10703+#endif
10704+
10705+ : "=r" (new)
10706+ : "0" (c), "ir" (a));
10707+
10708+ old = atomic_cmpxchg(v, c, new);
10709 if (likely(old == c))
10710 break;
10711 c = old;
10712@@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10713 }
10714
10715 /**
10716+ * atomic_inc_not_zero_hint - increment if not null
10717+ * @v: pointer of type atomic_t
10718+ * @hint: probable value of the atomic before the increment
10719+ *
10720+ * This version of atomic_inc_not_zero() gives a hint of probable
10721+ * value of the atomic. This helps processor to not read the memory
10722+ * before doing the atomic read/modify/write cycle, lowering
10723+ * number of bus transactions on some arches.
10724+ *
10725+ * Returns: 0 if increment was not done, 1 otherwise.
10726+ */
10727+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10728+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10729+{
10730+ int val, c = hint, new;
10731+
10732+ /* sanity test, should be removed by compiler if hint is a constant */
10733+ if (!hint)
10734+ return __atomic_add_unless(v, 1, 0);
10735+
10736+ do {
10737+ asm volatile("incl %0\n"
10738+
10739+#ifdef CONFIG_PAX_REFCOUNT
10740+ "jno 0f\n"
10741+ "decl %0\n"
10742+ "int $4\n0:\n"
10743+ _ASM_EXTABLE(0b, 0b)
10744+#endif
10745+
10746+ : "=r" (new)
10747+ : "0" (c));
10748+
10749+ val = atomic_cmpxchg(v, c, new);
10750+ if (val == c)
10751+ return 1;
10752+ c = val;
10753+ } while (c);
10754+
10755+ return 0;
10756+}
10757+
10758+/**
10759 * atomic_inc_short - increment of a short integer
10760 * @v: pointer to type int
10761 *
10762@@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10763 #endif
10764
10765 /* These are x86-specific, used by some header files */
10766-#define atomic_clear_mask(mask, addr) \
10767- asm volatile(LOCK_PREFIX "andl %0,%1" \
10768- : : "r" (~(mask)), "m" (*(addr)) : "memory")
10769+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10770+{
10771+ asm volatile(LOCK_PREFIX "andl %1,%0"
10772+ : "+m" (v->counter)
10773+ : "r" (~(mask))
10774+ : "memory");
10775+}
10776
10777-#define atomic_set_mask(mask, addr) \
10778- asm volatile(LOCK_PREFIX "orl %0,%1" \
10779- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10780- : "memory")
10781+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10782+{
10783+ asm volatile(LOCK_PREFIX "andl %1,%0"
10784+ : "+m" (v->counter)
10785+ : "r" (~(mask))
10786+ : "memory");
10787+}
10788+
10789+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10790+{
10791+ asm volatile(LOCK_PREFIX "orl %1,%0"
10792+ : "+m" (v->counter)
10793+ : "r" (mask)
10794+ : "memory");
10795+}
10796+
10797+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10798+{
10799+ asm volatile(LOCK_PREFIX "orl %1,%0"
10800+ : "+m" (v->counter)
10801+ : "r" (mask)
10802+ : "memory");
10803+}
10804
10805 /* Atomic operations are already serializing on x86 */
10806 #define smp_mb__before_atomic_dec() barrier()
10807diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10808index b154de7..aadebd8 100644
10809--- a/arch/x86/include/asm/atomic64_32.h
10810+++ b/arch/x86/include/asm/atomic64_32.h
10811@@ -12,6 +12,14 @@ typedef struct {
10812 u64 __aligned(8) counter;
10813 } atomic64_t;
10814
10815+#ifdef CONFIG_PAX_REFCOUNT
10816+typedef struct {
10817+ u64 __aligned(8) counter;
10818+} atomic64_unchecked_t;
10819+#else
10820+typedef atomic64_t atomic64_unchecked_t;
10821+#endif
10822+
10823 #define ATOMIC64_INIT(val) { (val) }
10824
10825 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10826@@ -37,21 +45,31 @@ typedef struct {
10827 ATOMIC64_DECL_ONE(sym##_386)
10828
10829 ATOMIC64_DECL_ONE(add_386);
10830+ATOMIC64_DECL_ONE(add_unchecked_386);
10831 ATOMIC64_DECL_ONE(sub_386);
10832+ATOMIC64_DECL_ONE(sub_unchecked_386);
10833 ATOMIC64_DECL_ONE(inc_386);
10834+ATOMIC64_DECL_ONE(inc_unchecked_386);
10835 ATOMIC64_DECL_ONE(dec_386);
10836+ATOMIC64_DECL_ONE(dec_unchecked_386);
10837 #endif
10838
10839 #define alternative_atomic64(f, out, in...) \
10840 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10841
10842 ATOMIC64_DECL(read);
10843+ATOMIC64_DECL(read_unchecked);
10844 ATOMIC64_DECL(set);
10845+ATOMIC64_DECL(set_unchecked);
10846 ATOMIC64_DECL(xchg);
10847 ATOMIC64_DECL(add_return);
10848+ATOMIC64_DECL(add_return_unchecked);
10849 ATOMIC64_DECL(sub_return);
10850+ATOMIC64_DECL(sub_return_unchecked);
10851 ATOMIC64_DECL(inc_return);
10852+ATOMIC64_DECL(inc_return_unchecked);
10853 ATOMIC64_DECL(dec_return);
10854+ATOMIC64_DECL(dec_return_unchecked);
10855 ATOMIC64_DECL(dec_if_positive);
10856 ATOMIC64_DECL(inc_not_zero);
10857 ATOMIC64_DECL(add_unless);
10858@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10859 }
10860
10861 /**
10862+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10863+ * @p: pointer to type atomic64_unchecked_t
10864+ * @o: expected value
10865+ * @n: new value
10866+ *
10867+ * Atomically sets @v to @n if it was equal to @o and returns
10868+ * the old value.
10869+ */
10870+
10871+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10872+{
10873+ return cmpxchg64(&v->counter, o, n);
10874+}
10875+
10876+/**
10877 * atomic64_xchg - xchg atomic64 variable
10878 * @v: pointer to type atomic64_t
10879 * @n: value to assign
10880@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10881 }
10882
10883 /**
10884+ * atomic64_set_unchecked - set atomic64 variable
10885+ * @v: pointer to type atomic64_unchecked_t
10886+ * @n: value to assign
10887+ *
10888+ * Atomically sets the value of @v to @n.
10889+ */
10890+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10891+{
10892+ unsigned high = (unsigned)(i >> 32);
10893+ unsigned low = (unsigned)i;
10894+ alternative_atomic64(set, /* no output */,
10895+ "S" (v), "b" (low), "c" (high)
10896+ : "eax", "edx", "memory");
10897+}
10898+
10899+/**
10900 * atomic64_read - read atomic64 variable
10901 * @v: pointer to type atomic64_t
10902 *
10903@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10904 }
10905
10906 /**
10907+ * atomic64_read_unchecked - read atomic64 variable
10908+ * @v: pointer to type atomic64_unchecked_t
10909+ *
10910+ * Atomically reads the value of @v and returns it.
10911+ */
10912+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10913+{
10914+ long long r;
10915+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10916+ return r;
10917+ }
10918+
10919+/**
10920 * atomic64_add_return - add and return
10921 * @i: integer value to add
10922 * @v: pointer to type atomic64_t
10923@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10924 return i;
10925 }
10926
10927+/**
10928+ * atomic64_add_return_unchecked - add and return
10929+ * @i: integer value to add
10930+ * @v: pointer to type atomic64_unchecked_t
10931+ *
10932+ * Atomically adds @i to @v and returns @i + *@v
10933+ */
10934+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10935+{
10936+ alternative_atomic64(add_return_unchecked,
10937+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10938+ ASM_NO_INPUT_CLOBBER("memory"));
10939+ return i;
10940+}
10941+
10942 /*
10943 * Other variants with different arithmetic operators:
10944 */
10945@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10946 return a;
10947 }
10948
10949+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10950+{
10951+ long long a;
10952+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
10953+ "S" (v) : "memory", "ecx");
10954+ return a;
10955+}
10956+
10957 static inline long long atomic64_dec_return(atomic64_t *v)
10958 {
10959 long long a;
10960@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10961 }
10962
10963 /**
10964+ * atomic64_add_unchecked - add integer to atomic64 variable
10965+ * @i: integer value to add
10966+ * @v: pointer to type atomic64_unchecked_t
10967+ *
10968+ * Atomically adds @i to @v.
10969+ */
10970+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10971+{
10972+ __alternative_atomic64(add_unchecked, add_return_unchecked,
10973+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10974+ ASM_NO_INPUT_CLOBBER("memory"));
10975+ return i;
10976+}
10977+
10978+/**
10979 * atomic64_sub - subtract the atomic64 variable
10980 * @i: integer value to subtract
10981 * @v: pointer to type atomic64_t
10982diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10983index 0e1cbfc..5623683 100644
10984--- a/arch/x86/include/asm/atomic64_64.h
10985+++ b/arch/x86/include/asm/atomic64_64.h
10986@@ -18,7 +18,19 @@
10987 */
10988 static inline long atomic64_read(const atomic64_t *v)
10989 {
10990- return (*(volatile long *)&(v)->counter);
10991+ return (*(volatile const long *)&(v)->counter);
10992+}
10993+
10994+/**
10995+ * atomic64_read_unchecked - read atomic64 variable
10996+ * @v: pointer of type atomic64_unchecked_t
10997+ *
10998+ * Atomically reads the value of @v.
10999+ * Doesn't imply a read memory barrier.
11000+ */
11001+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
11002+{
11003+ return (*(volatile const long *)&(v)->counter);
11004 }
11005
11006 /**
11007@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
11008 }
11009
11010 /**
11011+ * atomic64_set_unchecked - set atomic64 variable
11012+ * @v: pointer to type atomic64_unchecked_t
11013+ * @i: required value
11014+ *
11015+ * Atomically sets the value of @v to @i.
11016+ */
11017+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
11018+{
11019+ v->counter = i;
11020+}
11021+
11022+/**
11023 * atomic64_add - add integer to atomic64 variable
11024 * @i: integer value to add
11025 * @v: pointer to type atomic64_t
11026@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
11027 */
11028 static inline void atomic64_add(long i, atomic64_t *v)
11029 {
11030+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
11031+
11032+#ifdef CONFIG_PAX_REFCOUNT
11033+ "jno 0f\n"
11034+ LOCK_PREFIX "subq %1,%0\n"
11035+ "int $4\n0:\n"
11036+ _ASM_EXTABLE(0b, 0b)
11037+#endif
11038+
11039+ : "=m" (v->counter)
11040+ : "er" (i), "m" (v->counter));
11041+}
11042+
11043+/**
11044+ * atomic64_add_unchecked - add integer to atomic64 variable
11045+ * @i: integer value to add
11046+ * @v: pointer to type atomic64_unchecked_t
11047+ *
11048+ * Atomically adds @i to @v.
11049+ */
11050+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
11051+{
11052 asm volatile(LOCK_PREFIX "addq %1,%0"
11053 : "=m" (v->counter)
11054 : "er" (i), "m" (v->counter));
11055@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
11056 */
11057 static inline void atomic64_sub(long i, atomic64_t *v)
11058 {
11059- asm volatile(LOCK_PREFIX "subq %1,%0"
11060+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
11061+
11062+#ifdef CONFIG_PAX_REFCOUNT
11063+ "jno 0f\n"
11064+ LOCK_PREFIX "addq %1,%0\n"
11065+ "int $4\n0:\n"
11066+ _ASM_EXTABLE(0b, 0b)
11067+#endif
11068+
11069+ : "=m" (v->counter)
11070+ : "er" (i), "m" (v->counter));
11071+}
11072+
11073+/**
11074+ * atomic64_sub_unchecked - subtract the atomic64 variable
11075+ * @i: integer value to subtract
11076+ * @v: pointer to type atomic64_unchecked_t
11077+ *
11078+ * Atomically subtracts @i from @v.
11079+ */
11080+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
11081+{
11082+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
11083 : "=m" (v->counter)
11084 : "er" (i), "m" (v->counter));
11085 }
11086@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11087 {
11088 unsigned char c;
11089
11090- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
11091+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
11092+
11093+#ifdef CONFIG_PAX_REFCOUNT
11094+ "jno 0f\n"
11095+ LOCK_PREFIX "addq %2,%0\n"
11096+ "int $4\n0:\n"
11097+ _ASM_EXTABLE(0b, 0b)
11098+#endif
11099+
11100+ "sete %1\n"
11101 : "=m" (v->counter), "=qm" (c)
11102 : "er" (i), "m" (v->counter) : "memory");
11103 return c;
11104@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
11105 */
11106 static inline void atomic64_inc(atomic64_t *v)
11107 {
11108+ asm volatile(LOCK_PREFIX "incq %0\n"
11109+
11110+#ifdef CONFIG_PAX_REFCOUNT
11111+ "jno 0f\n"
11112+ LOCK_PREFIX "decq %0\n"
11113+ "int $4\n0:\n"
11114+ _ASM_EXTABLE(0b, 0b)
11115+#endif
11116+
11117+ : "=m" (v->counter)
11118+ : "m" (v->counter));
11119+}
11120+
11121+/**
11122+ * atomic64_inc_unchecked - increment atomic64 variable
11123+ * @v: pointer to type atomic64_unchecked_t
11124+ *
11125+ * Atomically increments @v by 1.
11126+ */
11127+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11128+{
11129 asm volatile(LOCK_PREFIX "incq %0"
11130 : "=m" (v->counter)
11131 : "m" (v->counter));
11132@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11133 */
11134 static inline void atomic64_dec(atomic64_t *v)
11135 {
11136- asm volatile(LOCK_PREFIX "decq %0"
11137+ asm volatile(LOCK_PREFIX "decq %0\n"
11138+
11139+#ifdef CONFIG_PAX_REFCOUNT
11140+ "jno 0f\n"
11141+ LOCK_PREFIX "incq %0\n"
11142+ "int $4\n0:\n"
11143+ _ASM_EXTABLE(0b, 0b)
11144+#endif
11145+
11146+ : "=m" (v->counter)
11147+ : "m" (v->counter));
11148+}
11149+
11150+/**
11151+ * atomic64_dec_unchecked - decrement atomic64 variable
11152+ * @v: pointer to type atomic64_t
11153+ *
11154+ * Atomically decrements @v by 1.
11155+ */
11156+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11157+{
11158+ asm volatile(LOCK_PREFIX "decq %0\n"
11159 : "=m" (v->counter)
11160 : "m" (v->counter));
11161 }
11162@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11163 {
11164 unsigned char c;
11165
11166- asm volatile(LOCK_PREFIX "decq %0; sete %1"
11167+ asm volatile(LOCK_PREFIX "decq %0\n"
11168+
11169+#ifdef CONFIG_PAX_REFCOUNT
11170+ "jno 0f\n"
11171+ LOCK_PREFIX "incq %0\n"
11172+ "int $4\n0:\n"
11173+ _ASM_EXTABLE(0b, 0b)
11174+#endif
11175+
11176+ "sete %1\n"
11177 : "=m" (v->counter), "=qm" (c)
11178 : "m" (v->counter) : "memory");
11179 return c != 0;
11180@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11181 {
11182 unsigned char c;
11183
11184- asm volatile(LOCK_PREFIX "incq %0; sete %1"
11185+ asm volatile(LOCK_PREFIX "incq %0\n"
11186+
11187+#ifdef CONFIG_PAX_REFCOUNT
11188+ "jno 0f\n"
11189+ LOCK_PREFIX "decq %0\n"
11190+ "int $4\n0:\n"
11191+ _ASM_EXTABLE(0b, 0b)
11192+#endif
11193+
11194+ "sete %1\n"
11195 : "=m" (v->counter), "=qm" (c)
11196 : "m" (v->counter) : "memory");
11197 return c != 0;
11198@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11199 {
11200 unsigned char c;
11201
11202- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11203+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
11204+
11205+#ifdef CONFIG_PAX_REFCOUNT
11206+ "jno 0f\n"
11207+ LOCK_PREFIX "subq %2,%0\n"
11208+ "int $4\n0:\n"
11209+ _ASM_EXTABLE(0b, 0b)
11210+#endif
11211+
11212+ "sets %1\n"
11213 : "=m" (v->counter), "=qm" (c)
11214 : "er" (i), "m" (v->counter) : "memory");
11215 return c;
11216@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11217 */
11218 static inline long atomic64_add_return(long i, atomic64_t *v)
11219 {
11220+ return i + xadd_check_overflow(&v->counter, i);
11221+}
11222+
11223+/**
11224+ * atomic64_add_return_unchecked - add and return
11225+ * @i: integer value to add
11226+ * @v: pointer to type atomic64_unchecked_t
11227+ *
11228+ * Atomically adds @i to @v and returns @i + @v
11229+ */
11230+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11231+{
11232 return i + xadd(&v->counter, i);
11233 }
11234
11235@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11236 }
11237
11238 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11239+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11240+{
11241+ return atomic64_add_return_unchecked(1, v);
11242+}
11243 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11244
11245 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11246@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11247 return cmpxchg(&v->counter, old, new);
11248 }
11249
11250+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11251+{
11252+ return cmpxchg(&v->counter, old, new);
11253+}
11254+
11255 static inline long atomic64_xchg(atomic64_t *v, long new)
11256 {
11257 return xchg(&v->counter, new);
11258@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11259 */
11260 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11261 {
11262- long c, old;
11263+ long c, old, new;
11264 c = atomic64_read(v);
11265 for (;;) {
11266- if (unlikely(c == (u)))
11267+ if (unlikely(c == u))
11268 break;
11269- old = atomic64_cmpxchg((v), c, c + (a));
11270+
11271+ asm volatile("add %2,%0\n"
11272+
11273+#ifdef CONFIG_PAX_REFCOUNT
11274+ "jno 0f\n"
11275+ "sub %2,%0\n"
11276+ "int $4\n0:\n"
11277+ _ASM_EXTABLE(0b, 0b)
11278+#endif
11279+
11280+ : "=r" (new)
11281+ : "0" (c), "ir" (a));
11282+
11283+ old = atomic64_cmpxchg(v, c, new);
11284 if (likely(old == c))
11285 break;
11286 c = old;
11287 }
11288- return c != (u);
11289+ return c != u;
11290 }
11291
11292 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11293diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11294index 6dfd019..0c6699f 100644
11295--- a/arch/x86/include/asm/bitops.h
11296+++ b/arch/x86/include/asm/bitops.h
11297@@ -40,7 +40,7 @@
11298 * a mask operation on a byte.
11299 */
11300 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11301-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11302+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11303 #define CONST_MASK(nr) (1 << ((nr) & 7))
11304
11305 /**
11306diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11307index b13fe63..0dab13a 100644
11308--- a/arch/x86/include/asm/boot.h
11309+++ b/arch/x86/include/asm/boot.h
11310@@ -11,10 +11,15 @@
11311 #include <asm/pgtable_types.h>
11312
11313 /* Physical address where kernel should be loaded. */
11314-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11315+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11316 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11317 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11318
11319+#ifndef __ASSEMBLY__
11320+extern unsigned char __LOAD_PHYSICAL_ADDR[];
11321+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11322+#endif
11323+
11324 /* Minimum kernel alignment, as a power of two */
11325 #ifdef CONFIG_X86_64
11326 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11327diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11328index 48f99f1..d78ebf9 100644
11329--- a/arch/x86/include/asm/cache.h
11330+++ b/arch/x86/include/asm/cache.h
11331@@ -5,12 +5,13 @@
11332
11333 /* L1 cache line size */
11334 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11335-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11336+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11337
11338 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11339+#define __read_only __attribute__((__section__(".data..read_only")))
11340
11341 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11342-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11343+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11344
11345 #ifdef CONFIG_X86_VSMP
11346 #ifdef CONFIG_SMP
11347diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11348index 9863ee3..4a1f8e1 100644
11349--- a/arch/x86/include/asm/cacheflush.h
11350+++ b/arch/x86/include/asm/cacheflush.h
11351@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11352 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11353
11354 if (pg_flags == _PGMT_DEFAULT)
11355- return -1;
11356+ return ~0UL;
11357 else if (pg_flags == _PGMT_WC)
11358 return _PAGE_CACHE_WC;
11359 else if (pg_flags == _PGMT_UC_MINUS)
11360diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11361index 46fc474..b02b0f9 100644
11362--- a/arch/x86/include/asm/checksum_32.h
11363+++ b/arch/x86/include/asm/checksum_32.h
11364@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11365 int len, __wsum sum,
11366 int *src_err_ptr, int *dst_err_ptr);
11367
11368+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11369+ int len, __wsum sum,
11370+ int *src_err_ptr, int *dst_err_ptr);
11371+
11372+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11373+ int len, __wsum sum,
11374+ int *src_err_ptr, int *dst_err_ptr);
11375+
11376 /*
11377 * Note: when you get a NULL pointer exception here this means someone
11378 * passed in an incorrect kernel address to one of these functions.
11379@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11380 int *err_ptr)
11381 {
11382 might_sleep();
11383- return csum_partial_copy_generic((__force void *)src, dst,
11384+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
11385 len, sum, err_ptr, NULL);
11386 }
11387
11388@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11389 {
11390 might_sleep();
11391 if (access_ok(VERIFY_WRITE, dst, len))
11392- return csum_partial_copy_generic(src, (__force void *)dst,
11393+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11394 len, sum, NULL, err_ptr);
11395
11396 if (len)
11397diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11398index 8d871ea..c1a0dc9 100644
11399--- a/arch/x86/include/asm/cmpxchg.h
11400+++ b/arch/x86/include/asm/cmpxchg.h
11401@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11402 __compiletime_error("Bad argument size for cmpxchg");
11403 extern void __xadd_wrong_size(void)
11404 __compiletime_error("Bad argument size for xadd");
11405+extern void __xadd_check_overflow_wrong_size(void)
11406+ __compiletime_error("Bad argument size for xadd_check_overflow");
11407 extern void __add_wrong_size(void)
11408 __compiletime_error("Bad argument size for add");
11409+extern void __add_check_overflow_wrong_size(void)
11410+ __compiletime_error("Bad argument size for add_check_overflow");
11411
11412 /*
11413 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11414@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11415 __ret; \
11416 })
11417
11418+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11419+ ({ \
11420+ __typeof__ (*(ptr)) __ret = (arg); \
11421+ switch (sizeof(*(ptr))) { \
11422+ case __X86_CASE_L: \
11423+ asm volatile (lock #op "l %0, %1\n" \
11424+ "jno 0f\n" \
11425+ "mov %0,%1\n" \
11426+ "int $4\n0:\n" \
11427+ _ASM_EXTABLE(0b, 0b) \
11428+ : "+r" (__ret), "+m" (*(ptr)) \
11429+ : : "memory", "cc"); \
11430+ break; \
11431+ case __X86_CASE_Q: \
11432+ asm volatile (lock #op "q %q0, %1\n" \
11433+ "jno 0f\n" \
11434+ "mov %0,%1\n" \
11435+ "int $4\n0:\n" \
11436+ _ASM_EXTABLE(0b, 0b) \
11437+ : "+r" (__ret), "+m" (*(ptr)) \
11438+ : : "memory", "cc"); \
11439+ break; \
11440+ default: \
11441+ __ ## op ## _check_overflow_wrong_size(); \
11442+ } \
11443+ __ret; \
11444+ })
11445+
11446 /*
11447 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11448 * Since this is generally used to protect other memory information, we
11449@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11450 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11451 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11452
11453+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11454+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11455+
11456 #define __add(ptr, inc, lock) \
11457 ({ \
11458 __typeof__ (*(ptr)) __ret = (inc); \
11459diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11460index 8c297aa..7a90f03 100644
11461--- a/arch/x86/include/asm/cpufeature.h
11462+++ b/arch/x86/include/asm/cpufeature.h
11463@@ -205,7 +205,7 @@
11464 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11465 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11466 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11467-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11468+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11469 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11470 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11471 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11472@@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11473 ".section .discard,\"aw\",@progbits\n"
11474 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11475 ".previous\n"
11476- ".section .altinstr_replacement,\"ax\"\n"
11477+ ".section .altinstr_replacement,\"a\"\n"
11478 "3: movb $1,%0\n"
11479 "4:\n"
11480 ".previous\n"
11481diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11482index 8bf1c06..f723dfd 100644
11483--- a/arch/x86/include/asm/desc.h
11484+++ b/arch/x86/include/asm/desc.h
11485@@ -4,6 +4,7 @@
11486 #include <asm/desc_defs.h>
11487 #include <asm/ldt.h>
11488 #include <asm/mmu.h>
11489+#include <asm/pgtable.h>
11490
11491 #include <linux/smp.h>
11492 #include <linux/percpu.h>
11493@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11494
11495 desc->type = (info->read_exec_only ^ 1) << 1;
11496 desc->type |= info->contents << 2;
11497+ desc->type |= info->seg_not_present ^ 1;
11498
11499 desc->s = 1;
11500 desc->dpl = 0x3;
11501@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11502 }
11503
11504 extern struct desc_ptr idt_descr;
11505-extern gate_desc idt_table[];
11506 extern struct desc_ptr nmi_idt_descr;
11507-extern gate_desc nmi_idt_table[];
11508-
11509-struct gdt_page {
11510- struct desc_struct gdt[GDT_ENTRIES];
11511-} __attribute__((aligned(PAGE_SIZE)));
11512-
11513-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11514+extern gate_desc idt_table[256];
11515+extern gate_desc nmi_idt_table[256];
11516
11517+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11518 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11519 {
11520- return per_cpu(gdt_page, cpu).gdt;
11521+ return cpu_gdt_table[cpu];
11522 }
11523
11524 #ifdef CONFIG_X86_64
11525@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11526 unsigned long base, unsigned dpl, unsigned flags,
11527 unsigned short seg)
11528 {
11529- gate->a = (seg << 16) | (base & 0xffff);
11530- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11531+ gate->gate.offset_low = base;
11532+ gate->gate.seg = seg;
11533+ gate->gate.reserved = 0;
11534+ gate->gate.type = type;
11535+ gate->gate.s = 0;
11536+ gate->gate.dpl = dpl;
11537+ gate->gate.p = 1;
11538+ gate->gate.offset_high = base >> 16;
11539 }
11540
11541 #endif
11542@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11543
11544 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11545 {
11546+ pax_open_kernel();
11547 memcpy(&idt[entry], gate, sizeof(*gate));
11548+ pax_close_kernel();
11549 }
11550
11551 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11552 {
11553+ pax_open_kernel();
11554 memcpy(&ldt[entry], desc, 8);
11555+ pax_close_kernel();
11556 }
11557
11558 static inline void
11559@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11560 default: size = sizeof(*gdt); break;
11561 }
11562
11563+ pax_open_kernel();
11564 memcpy(&gdt[entry], desc, size);
11565+ pax_close_kernel();
11566 }
11567
11568 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11569@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11570
11571 static inline void native_load_tr_desc(void)
11572 {
11573+ pax_open_kernel();
11574 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11575+ pax_close_kernel();
11576 }
11577
11578 static inline void native_load_gdt(const struct desc_ptr *dtr)
11579@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11580 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11581 unsigned int i;
11582
11583+ pax_open_kernel();
11584 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11585 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11586+ pax_close_kernel();
11587 }
11588
11589 #define _LDT_empty(info) \
11590@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11591 }
11592
11593 #ifdef CONFIG_X86_64
11594-static inline void set_nmi_gate(int gate, void *addr)
11595+static inline void set_nmi_gate(int gate, const void *addr)
11596 {
11597 gate_desc s;
11598
11599@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11600 }
11601 #endif
11602
11603-static inline void _set_gate(int gate, unsigned type, void *addr,
11604+static inline void _set_gate(int gate, unsigned type, const void *addr,
11605 unsigned dpl, unsigned ist, unsigned seg)
11606 {
11607 gate_desc s;
11608@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11609 * Pentium F0 0F bugfix can have resulted in the mapped
11610 * IDT being write-protected.
11611 */
11612-static inline void set_intr_gate(unsigned int n, void *addr)
11613+static inline void set_intr_gate(unsigned int n, const void *addr)
11614 {
11615 BUG_ON((unsigned)n > 0xFF);
11616 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11617@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11618 /*
11619 * This routine sets up an interrupt gate at directory privilege level 3.
11620 */
11621-static inline void set_system_intr_gate(unsigned int n, void *addr)
11622+static inline void set_system_intr_gate(unsigned int n, const void *addr)
11623 {
11624 BUG_ON((unsigned)n > 0xFF);
11625 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11626 }
11627
11628-static inline void set_system_trap_gate(unsigned int n, void *addr)
11629+static inline void set_system_trap_gate(unsigned int n, const void *addr)
11630 {
11631 BUG_ON((unsigned)n > 0xFF);
11632 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11633 }
11634
11635-static inline void set_trap_gate(unsigned int n, void *addr)
11636+static inline void set_trap_gate(unsigned int n, const void *addr)
11637 {
11638 BUG_ON((unsigned)n > 0xFF);
11639 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11640@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11641 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11642 {
11643 BUG_ON((unsigned)n > 0xFF);
11644- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11645+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11646 }
11647
11648-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11649+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11650 {
11651 BUG_ON((unsigned)n > 0xFF);
11652 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11653 }
11654
11655-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11656+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11657 {
11658 BUG_ON((unsigned)n > 0xFF);
11659 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11660 }
11661
11662+#ifdef CONFIG_X86_32
11663+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11664+{
11665+ struct desc_struct d;
11666+
11667+ if (likely(limit))
11668+ limit = (limit - 1UL) >> PAGE_SHIFT;
11669+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
11670+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11671+}
11672+#endif
11673+
11674 #endif /* _ASM_X86_DESC_H */
11675diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11676index 278441f..b95a174 100644
11677--- a/arch/x86/include/asm/desc_defs.h
11678+++ b/arch/x86/include/asm/desc_defs.h
11679@@ -31,6 +31,12 @@ struct desc_struct {
11680 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11681 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11682 };
11683+ struct {
11684+ u16 offset_low;
11685+ u16 seg;
11686+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11687+ unsigned offset_high: 16;
11688+ } gate;
11689 };
11690 } __attribute__((packed));
11691
11692diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11693index 3778256..c5d4fce 100644
11694--- a/arch/x86/include/asm/e820.h
11695+++ b/arch/x86/include/asm/e820.h
11696@@ -69,7 +69,7 @@ struct e820map {
11697 #define ISA_START_ADDRESS 0xa0000
11698 #define ISA_END_ADDRESS 0x100000
11699
11700-#define BIOS_BEGIN 0x000a0000
11701+#define BIOS_BEGIN 0x000c0000
11702 #define BIOS_END 0x00100000
11703
11704 #define BIOS_ROM_BASE 0xffe00000
11705diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11706index 5939f44..f8845f6 100644
11707--- a/arch/x86/include/asm/elf.h
11708+++ b/arch/x86/include/asm/elf.h
11709@@ -243,7 +243,25 @@ extern int force_personality32;
11710 the loader. We need to make sure that it is out of the way of the program
11711 that it will "exec", and that there is sufficient room for the brk. */
11712
11713+#ifdef CONFIG_PAX_SEGMEXEC
11714+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11715+#else
11716 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11717+#endif
11718+
11719+#ifdef CONFIG_PAX_ASLR
11720+#ifdef CONFIG_X86_32
11721+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11722+
11723+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11724+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11725+#else
11726+#define PAX_ELF_ET_DYN_BASE 0x400000UL
11727+
11728+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11729+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11730+#endif
11731+#endif
11732
11733 /* This yields a mask that user programs can use to figure out what
11734 instruction set this CPU supports. This could be done in user space,
11735@@ -296,16 +314,12 @@ do { \
11736
11737 #define ARCH_DLINFO \
11738 do { \
11739- if (vdso_enabled) \
11740- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11741- (unsigned long)current->mm->context.vdso); \
11742+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11743 } while (0)
11744
11745 #define ARCH_DLINFO_X32 \
11746 do { \
11747- if (vdso_enabled) \
11748- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11749- (unsigned long)current->mm->context.vdso); \
11750+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11751 } while (0)
11752
11753 #define AT_SYSINFO 32
11754@@ -320,7 +334,7 @@ else \
11755
11756 #endif /* !CONFIG_X86_32 */
11757
11758-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11759+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11760
11761 #define VDSO_ENTRY \
11762 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11763@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11764 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11765 #define compat_arch_setup_additional_pages syscall32_setup_pages
11766
11767-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11768-#define arch_randomize_brk arch_randomize_brk
11769-
11770 /*
11771 * True on X86_32 or when emulating IA32 on X86_64
11772 */
11773diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11774index 75ce3f4..882e801 100644
11775--- a/arch/x86/include/asm/emergency-restart.h
11776+++ b/arch/x86/include/asm/emergency-restart.h
11777@@ -13,6 +13,6 @@ enum reboot_type {
11778
11779 extern enum reboot_type reboot_type;
11780
11781-extern void machine_emergency_restart(void);
11782+extern void machine_emergency_restart(void) __noreturn;
11783
11784 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11785diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11786index 41ab26e..a88c9e6 100644
11787--- a/arch/x86/include/asm/fpu-internal.h
11788+++ b/arch/x86/include/asm/fpu-internal.h
11789@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11790 ({ \
11791 int err; \
11792 asm volatile(ASM_STAC "\n" \
11793- "1:" #insn "\n\t" \
11794+ "1:" \
11795+ __copyuser_seg \
11796+ #insn "\n\t" \
11797 "2: " ASM_CLAC "\n" \
11798 ".section .fixup,\"ax\"\n" \
11799 "3: movl $-1,%[err]\n" \
11800@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11801 "emms\n\t" /* clear stack tags */
11802 "fildl %P[addr]", /* set F?P to defined value */
11803 X86_FEATURE_FXSAVE_LEAK,
11804- [addr] "m" (tsk->thread.fpu.has_fpu));
11805+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11806
11807 return fpu_restore_checking(&tsk->thread.fpu);
11808 }
11809diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11810index f373046..02653e2 100644
11811--- a/arch/x86/include/asm/futex.h
11812+++ b/arch/x86/include/asm/futex.h
11813@@ -12,6 +12,7 @@
11814 #include <asm/smap.h>
11815
11816 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11817+ typecheck(u32 __user *, uaddr); \
11818 asm volatile("\t" ASM_STAC "\n" \
11819 "1:\t" insn "\n" \
11820 "2:\t" ASM_CLAC "\n" \
11821@@ -20,15 +21,16 @@
11822 "\tjmp\t2b\n" \
11823 "\t.previous\n" \
11824 _ASM_EXTABLE(1b, 3b) \
11825- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11826+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11827 : "i" (-EFAULT), "0" (oparg), "1" (0))
11828
11829 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11830+ typecheck(u32 __user *, uaddr); \
11831 asm volatile("\t" ASM_STAC "\n" \
11832 "1:\tmovl %2, %0\n" \
11833 "\tmovl\t%0, %3\n" \
11834 "\t" insn "\n" \
11835- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11836+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11837 "\tjnz\t1b\n" \
11838 "3:\t" ASM_CLAC "\n" \
11839 "\t.section .fixup,\"ax\"\n" \
11840@@ -38,7 +40,7 @@
11841 _ASM_EXTABLE(1b, 4b) \
11842 _ASM_EXTABLE(2b, 4b) \
11843 : "=&a" (oldval), "=&r" (ret), \
11844- "+m" (*uaddr), "=&r" (tem) \
11845+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11846 : "r" (oparg), "i" (-EFAULT), "1" (0))
11847
11848 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11849@@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11850
11851 switch (op) {
11852 case FUTEX_OP_SET:
11853- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11854+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11855 break;
11856 case FUTEX_OP_ADD:
11857- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11858+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11859 uaddr, oparg);
11860 break;
11861 case FUTEX_OP_OR:
11862@@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11863 return -EFAULT;
11864
11865 asm volatile("\t" ASM_STAC "\n"
11866- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11867+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11868 "2:\t" ASM_CLAC "\n"
11869 "\t.section .fixup, \"ax\"\n"
11870 "3:\tmov %3, %0\n"
11871 "\tjmp 2b\n"
11872 "\t.previous\n"
11873 _ASM_EXTABLE(1b, 3b)
11874- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11875+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11876 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11877 : "memory"
11878 );
11879diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11880index eb92a6e..b98b2f4 100644
11881--- a/arch/x86/include/asm/hw_irq.h
11882+++ b/arch/x86/include/asm/hw_irq.h
11883@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11884 extern void enable_IO_APIC(void);
11885
11886 /* Statistics */
11887-extern atomic_t irq_err_count;
11888-extern atomic_t irq_mis_count;
11889+extern atomic_unchecked_t irq_err_count;
11890+extern atomic_unchecked_t irq_mis_count;
11891
11892 /* EISA */
11893 extern void eisa_set_level_irq(unsigned int irq);
11894diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11895index d8e8eef..15b1179 100644
11896--- a/arch/x86/include/asm/io.h
11897+++ b/arch/x86/include/asm/io.h
11898@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11899 return ioremap_nocache(offset, size);
11900 }
11901
11902-extern void iounmap(volatile void __iomem *addr);
11903+extern void iounmap(const volatile void __iomem *addr);
11904
11905 extern void set_iounmap_nonlazy(void);
11906
11907@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11908
11909 #include <linux/vmalloc.h>
11910
11911+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11912+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11913+{
11914+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11915+}
11916+
11917+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11918+{
11919+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11920+}
11921+
11922 /*
11923 * Convert a virtual cached pointer to an uncached pointer
11924 */
11925diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11926index bba3cf8..06bc8da 100644
11927--- a/arch/x86/include/asm/irqflags.h
11928+++ b/arch/x86/include/asm/irqflags.h
11929@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11930 sti; \
11931 sysexit
11932
11933+#define GET_CR0_INTO_RDI mov %cr0, %rdi
11934+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11935+#define GET_CR3_INTO_RDI mov %cr3, %rdi
11936+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11937+
11938 #else
11939 #define INTERRUPT_RETURN iret
11940 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11941diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11942index d3ddd17..c9fb0cc 100644
11943--- a/arch/x86/include/asm/kprobes.h
11944+++ b/arch/x86/include/asm/kprobes.h
11945@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11946 #define RELATIVEJUMP_SIZE 5
11947 #define RELATIVECALL_OPCODE 0xe8
11948 #define RELATIVE_ADDR_SIZE 4
11949-#define MAX_STACK_SIZE 64
11950-#define MIN_STACK_SIZE(ADDR) \
11951- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11952- THREAD_SIZE - (unsigned long)(ADDR))) \
11953- ? (MAX_STACK_SIZE) \
11954- : (((unsigned long)current_thread_info()) + \
11955- THREAD_SIZE - (unsigned long)(ADDR)))
11956+#define MAX_STACK_SIZE 64UL
11957+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11958
11959 #define flush_insn_slot(p) do { } while (0)
11960
11961diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11962index c8bed0d..85c03fd 100644
11963--- a/arch/x86/include/asm/local.h
11964+++ b/arch/x86/include/asm/local.h
11965@@ -10,33 +10,97 @@ typedef struct {
11966 atomic_long_t a;
11967 } local_t;
11968
11969+typedef struct {
11970+ atomic_long_unchecked_t a;
11971+} local_unchecked_t;
11972+
11973 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11974
11975 #define local_read(l) atomic_long_read(&(l)->a)
11976+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11977 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11978+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11979
11980 static inline void local_inc(local_t *l)
11981 {
11982- asm volatile(_ASM_INC "%0"
11983+ asm volatile(_ASM_INC "%0\n"
11984+
11985+#ifdef CONFIG_PAX_REFCOUNT
11986+ "jno 0f\n"
11987+ _ASM_DEC "%0\n"
11988+ "int $4\n0:\n"
11989+ _ASM_EXTABLE(0b, 0b)
11990+#endif
11991+
11992+ : "+m" (l->a.counter));
11993+}
11994+
11995+static inline void local_inc_unchecked(local_unchecked_t *l)
11996+{
11997+ asm volatile(_ASM_INC "%0\n"
11998 : "+m" (l->a.counter));
11999 }
12000
12001 static inline void local_dec(local_t *l)
12002 {
12003- asm volatile(_ASM_DEC "%0"
12004+ asm volatile(_ASM_DEC "%0\n"
12005+
12006+#ifdef CONFIG_PAX_REFCOUNT
12007+ "jno 0f\n"
12008+ _ASM_INC "%0\n"
12009+ "int $4\n0:\n"
12010+ _ASM_EXTABLE(0b, 0b)
12011+#endif
12012+
12013+ : "+m" (l->a.counter));
12014+}
12015+
12016+static inline void local_dec_unchecked(local_unchecked_t *l)
12017+{
12018+ asm volatile(_ASM_DEC "%0\n"
12019 : "+m" (l->a.counter));
12020 }
12021
12022 static inline void local_add(long i, local_t *l)
12023 {
12024- asm volatile(_ASM_ADD "%1,%0"
12025+ asm volatile(_ASM_ADD "%1,%0\n"
12026+
12027+#ifdef CONFIG_PAX_REFCOUNT
12028+ "jno 0f\n"
12029+ _ASM_SUB "%1,%0\n"
12030+ "int $4\n0:\n"
12031+ _ASM_EXTABLE(0b, 0b)
12032+#endif
12033+
12034+ : "+m" (l->a.counter)
12035+ : "ir" (i));
12036+}
12037+
12038+static inline void local_add_unchecked(long i, local_unchecked_t *l)
12039+{
12040+ asm volatile(_ASM_ADD "%1,%0\n"
12041 : "+m" (l->a.counter)
12042 : "ir" (i));
12043 }
12044
12045 static inline void local_sub(long i, local_t *l)
12046 {
12047- asm volatile(_ASM_SUB "%1,%0"
12048+ asm volatile(_ASM_SUB "%1,%0\n"
12049+
12050+#ifdef CONFIG_PAX_REFCOUNT
12051+ "jno 0f\n"
12052+ _ASM_ADD "%1,%0\n"
12053+ "int $4\n0:\n"
12054+ _ASM_EXTABLE(0b, 0b)
12055+#endif
12056+
12057+ : "+m" (l->a.counter)
12058+ : "ir" (i));
12059+}
12060+
12061+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
12062+{
12063+ asm volatile(_ASM_SUB "%1,%0\n"
12064 : "+m" (l->a.counter)
12065 : "ir" (i));
12066 }
12067@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
12068 {
12069 unsigned char c;
12070
12071- asm volatile(_ASM_SUB "%2,%0; sete %1"
12072+ asm volatile(_ASM_SUB "%2,%0\n"
12073+
12074+#ifdef CONFIG_PAX_REFCOUNT
12075+ "jno 0f\n"
12076+ _ASM_ADD "%2,%0\n"
12077+ "int $4\n0:\n"
12078+ _ASM_EXTABLE(0b, 0b)
12079+#endif
12080+
12081+ "sete %1\n"
12082 : "+m" (l->a.counter), "=qm" (c)
12083 : "ir" (i) : "memory");
12084 return c;
12085@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
12086 {
12087 unsigned char c;
12088
12089- asm volatile(_ASM_DEC "%0; sete %1"
12090+ asm volatile(_ASM_DEC "%0\n"
12091+
12092+#ifdef CONFIG_PAX_REFCOUNT
12093+ "jno 0f\n"
12094+ _ASM_INC "%0\n"
12095+ "int $4\n0:\n"
12096+ _ASM_EXTABLE(0b, 0b)
12097+#endif
12098+
12099+ "sete %1\n"
12100 : "+m" (l->a.counter), "=qm" (c)
12101 : : "memory");
12102 return c != 0;
12103@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
12104 {
12105 unsigned char c;
12106
12107- asm volatile(_ASM_INC "%0; sete %1"
12108+ asm volatile(_ASM_INC "%0\n"
12109+
12110+#ifdef CONFIG_PAX_REFCOUNT
12111+ "jno 0f\n"
12112+ _ASM_DEC "%0\n"
12113+ "int $4\n0:\n"
12114+ _ASM_EXTABLE(0b, 0b)
12115+#endif
12116+
12117+ "sete %1\n"
12118 : "+m" (l->a.counter), "=qm" (c)
12119 : : "memory");
12120 return c != 0;
12121@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12122 {
12123 unsigned char c;
12124
12125- asm volatile(_ASM_ADD "%2,%0; sets %1"
12126+ asm volatile(_ASM_ADD "%2,%0\n"
12127+
12128+#ifdef CONFIG_PAX_REFCOUNT
12129+ "jno 0f\n"
12130+ _ASM_SUB "%2,%0\n"
12131+ "int $4\n0:\n"
12132+ _ASM_EXTABLE(0b, 0b)
12133+#endif
12134+
12135+ "sets %1\n"
12136 : "+m" (l->a.counter), "=qm" (c)
12137 : "ir" (i) : "memory");
12138 return c;
12139@@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12140 #endif
12141 /* Modern 486+ processor */
12142 __i = i;
12143- asm volatile(_ASM_XADD "%0, %1;"
12144+ asm volatile(_ASM_XADD "%0, %1\n"
12145+
12146+#ifdef CONFIG_PAX_REFCOUNT
12147+ "jno 0f\n"
12148+ _ASM_MOV "%0,%1\n"
12149+ "int $4\n0:\n"
12150+ _ASM_EXTABLE(0b, 0b)
12151+#endif
12152+
12153 : "+r" (i), "+m" (l->a.counter)
12154 : : "memory");
12155 return i + __i;
12156@@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12157 #endif
12158 }
12159
12160+/**
12161+ * local_add_return_unchecked - add and return
12162+ * @i: integer value to add
12163+ * @l: pointer to type local_unchecked_t
12164+ *
12165+ * Atomically adds @i to @l and returns @i + @l
12166+ */
12167+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12168+{
12169+ long __i;
12170+#ifdef CONFIG_M386
12171+ unsigned long flags;
12172+ if (unlikely(boot_cpu_data.x86 <= 3))
12173+ goto no_xadd;
12174+#endif
12175+ /* Modern 486+ processor */
12176+ __i = i;
12177+ asm volatile(_ASM_XADD "%0, %1\n"
12178+ : "+r" (i), "+m" (l->a.counter)
12179+ : : "memory");
12180+ return i + __i;
12181+
12182+#ifdef CONFIG_M386
12183+no_xadd: /* Legacy 386 processor */
12184+ local_irq_save(flags);
12185+ __i = local_read_unchecked(l);
12186+ local_set_unchecked(l, i + __i);
12187+ local_irq_restore(flags);
12188+ return i + __i;
12189+#endif
12190+}
12191+
12192 static inline long local_sub_return(long i, local_t *l)
12193 {
12194 return local_add_return(-i, l);
12195@@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12196
12197 #define local_cmpxchg(l, o, n) \
12198 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12199+#define local_cmpxchg_unchecked(l, o, n) \
12200+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
12201 /* Always has a lock prefix */
12202 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12203
12204diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12205index 593e51d..fa69c9a 100644
12206--- a/arch/x86/include/asm/mman.h
12207+++ b/arch/x86/include/asm/mman.h
12208@@ -5,4 +5,14 @@
12209
12210 #include <asm-generic/mman.h>
12211
12212+#ifdef __KERNEL__
12213+#ifndef __ASSEMBLY__
12214+#ifdef CONFIG_X86_32
12215+#define arch_mmap_check i386_mmap_check
12216+int i386_mmap_check(unsigned long addr, unsigned long len,
12217+ unsigned long flags);
12218+#endif
12219+#endif
12220+#endif
12221+
12222 #endif /* _ASM_X86_MMAN_H */
12223diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12224index 5f55e69..e20bfb1 100644
12225--- a/arch/x86/include/asm/mmu.h
12226+++ b/arch/x86/include/asm/mmu.h
12227@@ -9,7 +9,7 @@
12228 * we put the segment information here.
12229 */
12230 typedef struct {
12231- void *ldt;
12232+ struct desc_struct *ldt;
12233 int size;
12234
12235 #ifdef CONFIG_X86_64
12236@@ -18,7 +18,19 @@ typedef struct {
12237 #endif
12238
12239 struct mutex lock;
12240- void *vdso;
12241+ unsigned long vdso;
12242+
12243+#ifdef CONFIG_X86_32
12244+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12245+ unsigned long user_cs_base;
12246+ unsigned long user_cs_limit;
12247+
12248+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12249+ cpumask_t cpu_user_cs_mask;
12250+#endif
12251+
12252+#endif
12253+#endif
12254 } mm_context_t;
12255
12256 #ifdef CONFIG_SMP
12257diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12258index cdbf367..adb37ac 100644
12259--- a/arch/x86/include/asm/mmu_context.h
12260+++ b/arch/x86/include/asm/mmu_context.h
12261@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12262
12263 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12264 {
12265+
12266+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12267+ unsigned int i;
12268+ pgd_t *pgd;
12269+
12270+ pax_open_kernel();
12271+ pgd = get_cpu_pgd(smp_processor_id());
12272+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12273+ set_pgd_batched(pgd+i, native_make_pgd(0));
12274+ pax_close_kernel();
12275+#endif
12276+
12277 #ifdef CONFIG_SMP
12278 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12279 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12280@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12281 struct task_struct *tsk)
12282 {
12283 unsigned cpu = smp_processor_id();
12284+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12285+ int tlbstate = TLBSTATE_OK;
12286+#endif
12287
12288 if (likely(prev != next)) {
12289 #ifdef CONFIG_SMP
12290+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12291+ tlbstate = this_cpu_read(cpu_tlbstate.state);
12292+#endif
12293 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12294 this_cpu_write(cpu_tlbstate.active_mm, next);
12295 #endif
12296 cpumask_set_cpu(cpu, mm_cpumask(next));
12297
12298 /* Re-load page tables */
12299+#ifdef CONFIG_PAX_PER_CPU_PGD
12300+ pax_open_kernel();
12301+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12302+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12303+ pax_close_kernel();
12304+ load_cr3(get_cpu_pgd(cpu));
12305+#else
12306 load_cr3(next->pgd);
12307+#endif
12308
12309 /* stop flush ipis for the previous mm */
12310 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12311@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12312 */
12313 if (unlikely(prev->context.ldt != next->context.ldt))
12314 load_LDT_nolock(&next->context);
12315- }
12316+
12317+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12318+ if (!(__supported_pte_mask & _PAGE_NX)) {
12319+ smp_mb__before_clear_bit();
12320+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12321+ smp_mb__after_clear_bit();
12322+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12323+ }
12324+#endif
12325+
12326+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12327+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12328+ prev->context.user_cs_limit != next->context.user_cs_limit))
12329+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12330 #ifdef CONFIG_SMP
12331+ else if (unlikely(tlbstate != TLBSTATE_OK))
12332+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12333+#endif
12334+#endif
12335+
12336+ }
12337 else {
12338+
12339+#ifdef CONFIG_PAX_PER_CPU_PGD
12340+ pax_open_kernel();
12341+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12342+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12343+ pax_close_kernel();
12344+ load_cr3(get_cpu_pgd(cpu));
12345+#endif
12346+
12347+#ifdef CONFIG_SMP
12348 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12349 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12350
12351@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12352 * tlb flush IPI delivery. We must reload CR3
12353 * to make sure to use no freed page tables.
12354 */
12355+
12356+#ifndef CONFIG_PAX_PER_CPU_PGD
12357 load_cr3(next->pgd);
12358+#endif
12359+
12360 load_LDT_nolock(&next->context);
12361+
12362+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12363+ if (!(__supported_pte_mask & _PAGE_NX))
12364+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12365+#endif
12366+
12367+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12368+#ifdef CONFIG_PAX_PAGEEXEC
12369+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12370+#endif
12371+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12372+#endif
12373+
12374 }
12375+#endif
12376 }
12377-#endif
12378 }
12379
12380 #define activate_mm(prev, next) \
12381diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12382index 9eae775..c914fea 100644
12383--- a/arch/x86/include/asm/module.h
12384+++ b/arch/x86/include/asm/module.h
12385@@ -5,6 +5,7 @@
12386
12387 #ifdef CONFIG_X86_64
12388 /* X86_64 does not define MODULE_PROC_FAMILY */
12389+#define MODULE_PROC_FAMILY ""
12390 #elif defined CONFIG_M386
12391 #define MODULE_PROC_FAMILY "386 "
12392 #elif defined CONFIG_M486
12393@@ -59,8 +60,20 @@
12394 #error unknown processor family
12395 #endif
12396
12397-#ifdef CONFIG_X86_32
12398-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12399+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12400+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12401+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12402+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12403+#else
12404+#define MODULE_PAX_KERNEXEC ""
12405 #endif
12406
12407+#ifdef CONFIG_PAX_MEMORY_UDEREF
12408+#define MODULE_PAX_UDEREF "UDEREF "
12409+#else
12410+#define MODULE_PAX_UDEREF ""
12411+#endif
12412+
12413+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12414+
12415 #endif /* _ASM_X86_MODULE_H */
12416diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12417index 320f7bb..e89f8f8 100644
12418--- a/arch/x86/include/asm/page_64_types.h
12419+++ b/arch/x86/include/asm/page_64_types.h
12420@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12421
12422 /* duplicated to the one in bootmem.h */
12423 extern unsigned long max_pfn;
12424-extern unsigned long phys_base;
12425+extern const unsigned long phys_base;
12426
12427 extern unsigned long __phys_addr(unsigned long);
12428 #define __phys_reloc_hide(x) (x)
12429diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12430index a0facf3..c017b15 100644
12431--- a/arch/x86/include/asm/paravirt.h
12432+++ b/arch/x86/include/asm/paravirt.h
12433@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12434 val);
12435 }
12436
12437+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12438+{
12439+ pgdval_t val = native_pgd_val(pgd);
12440+
12441+ if (sizeof(pgdval_t) > sizeof(long))
12442+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12443+ val, (u64)val >> 32);
12444+ else
12445+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12446+ val);
12447+}
12448+
12449 static inline void pgd_clear(pgd_t *pgdp)
12450 {
12451 set_pgd(pgdp, __pgd(0));
12452@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12453 pv_mmu_ops.set_fixmap(idx, phys, flags);
12454 }
12455
12456+#ifdef CONFIG_PAX_KERNEXEC
12457+static inline unsigned long pax_open_kernel(void)
12458+{
12459+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12460+}
12461+
12462+static inline unsigned long pax_close_kernel(void)
12463+{
12464+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12465+}
12466+#else
12467+static inline unsigned long pax_open_kernel(void) { return 0; }
12468+static inline unsigned long pax_close_kernel(void) { return 0; }
12469+#endif
12470+
12471 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12472
12473 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12474@@ -929,7 +956,7 @@ extern void default_banner(void);
12475
12476 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12477 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12478-#define PARA_INDIRECT(addr) *%cs:addr
12479+#define PARA_INDIRECT(addr) *%ss:addr
12480 #endif
12481
12482 #define INTERRUPT_RETURN \
12483@@ -1004,6 +1031,21 @@ extern void default_banner(void);
12484 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12485 CLBR_NONE, \
12486 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12487+
12488+#define GET_CR0_INTO_RDI \
12489+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12490+ mov %rax,%rdi
12491+
12492+#define SET_RDI_INTO_CR0 \
12493+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12494+
12495+#define GET_CR3_INTO_RDI \
12496+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12497+ mov %rax,%rdi
12498+
12499+#define SET_RDI_INTO_CR3 \
12500+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12501+
12502 #endif /* CONFIG_X86_32 */
12503
12504 #endif /* __ASSEMBLY__ */
12505diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12506index 142236e..5446ffbc 100644
12507--- a/arch/x86/include/asm/paravirt_types.h
12508+++ b/arch/x86/include/asm/paravirt_types.h
12509@@ -84,7 +84,7 @@ struct pv_init_ops {
12510 */
12511 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
12512 unsigned long addr, unsigned len);
12513-};
12514+} __no_const;
12515
12516
12517 struct pv_lazy_ops {
12518@@ -97,7 +97,7 @@ struct pv_time_ops {
12519 unsigned long long (*sched_clock)(void);
12520 unsigned long long (*steal_clock)(int cpu);
12521 unsigned long (*get_tsc_khz)(void);
12522-};
12523+} __no_const;
12524
12525 struct pv_cpu_ops {
12526 /* hooks for various privileged instructions */
12527@@ -191,7 +191,7 @@ struct pv_cpu_ops {
12528
12529 void (*start_context_switch)(struct task_struct *prev);
12530 void (*end_context_switch)(struct task_struct *next);
12531-};
12532+} __no_const;
12533
12534 struct pv_irq_ops {
12535 /*
12536@@ -222,7 +222,7 @@ struct pv_apic_ops {
12537 unsigned long start_eip,
12538 unsigned long start_esp);
12539 #endif
12540-};
12541+} __no_const;
12542
12543 struct pv_mmu_ops {
12544 unsigned long (*read_cr2)(void);
12545@@ -312,6 +312,7 @@ struct pv_mmu_ops {
12546 struct paravirt_callee_save make_pud;
12547
12548 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12549+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12550 #endif /* PAGETABLE_LEVELS == 4 */
12551 #endif /* PAGETABLE_LEVELS >= 3 */
12552
12553@@ -323,6 +324,12 @@ struct pv_mmu_ops {
12554 an mfn. We can tell which is which from the index. */
12555 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12556 phys_addr_t phys, pgprot_t flags);
12557+
12558+#ifdef CONFIG_PAX_KERNEXEC
12559+ unsigned long (*pax_open_kernel)(void);
12560+ unsigned long (*pax_close_kernel)(void);
12561+#endif
12562+
12563 };
12564
12565 struct arch_spinlock;
12566@@ -333,7 +340,7 @@ struct pv_lock_ops {
12567 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
12568 int (*spin_trylock)(struct arch_spinlock *lock);
12569 void (*spin_unlock)(struct arch_spinlock *lock);
12570-};
12571+} __no_const;
12572
12573 /* This contains all the paravirt structures: we get a convenient
12574 * number for each function using the offset which we use to indicate
12575diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12576index b4389a4..7024269 100644
12577--- a/arch/x86/include/asm/pgalloc.h
12578+++ b/arch/x86/include/asm/pgalloc.h
12579@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12580 pmd_t *pmd, pte_t *pte)
12581 {
12582 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12583+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12584+}
12585+
12586+static inline void pmd_populate_user(struct mm_struct *mm,
12587+ pmd_t *pmd, pte_t *pte)
12588+{
12589+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12590 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12591 }
12592
12593@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12594
12595 #ifdef CONFIG_X86_PAE
12596 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12597+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12598+{
12599+ pud_populate(mm, pudp, pmd);
12600+}
12601 #else /* !CONFIG_X86_PAE */
12602 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12603 {
12604 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12605 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12606 }
12607+
12608+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12609+{
12610+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12611+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12612+}
12613 #endif /* CONFIG_X86_PAE */
12614
12615 #if PAGETABLE_LEVELS > 3
12616@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12617 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12618 }
12619
12620+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12621+{
12622+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12623+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12624+}
12625+
12626 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12627 {
12628 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12629diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12630index f2b489c..4f7e2e5 100644
12631--- a/arch/x86/include/asm/pgtable-2level.h
12632+++ b/arch/x86/include/asm/pgtable-2level.h
12633@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12634
12635 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12636 {
12637+ pax_open_kernel();
12638 *pmdp = pmd;
12639+ pax_close_kernel();
12640 }
12641
12642 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12643diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12644index 4cc9f2b..5fd9226 100644
12645--- a/arch/x86/include/asm/pgtable-3level.h
12646+++ b/arch/x86/include/asm/pgtable-3level.h
12647@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12648
12649 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12650 {
12651+ pax_open_kernel();
12652 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12653+ pax_close_kernel();
12654 }
12655
12656 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12657 {
12658+ pax_open_kernel();
12659 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12660+ pax_close_kernel();
12661 }
12662
12663 /*
12664diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12665index a1f780d..9f6c8dd 100644
12666--- a/arch/x86/include/asm/pgtable.h
12667+++ b/arch/x86/include/asm/pgtable.h
12668@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12669
12670 #ifndef __PAGETABLE_PUD_FOLDED
12671 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12672+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12673 #define pgd_clear(pgd) native_pgd_clear(pgd)
12674 #endif
12675
12676@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12677
12678 #define arch_end_context_switch(prev) do {} while(0)
12679
12680+#define pax_open_kernel() native_pax_open_kernel()
12681+#define pax_close_kernel() native_pax_close_kernel()
12682 #endif /* CONFIG_PARAVIRT */
12683
12684+#define __HAVE_ARCH_PAX_OPEN_KERNEL
12685+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12686+
12687+#ifdef CONFIG_PAX_KERNEXEC
12688+static inline unsigned long native_pax_open_kernel(void)
12689+{
12690+ unsigned long cr0;
12691+
12692+ preempt_disable();
12693+ barrier();
12694+ cr0 = read_cr0() ^ X86_CR0_WP;
12695+ BUG_ON(cr0 & X86_CR0_WP);
12696+ write_cr0(cr0);
12697+ return cr0 ^ X86_CR0_WP;
12698+}
12699+
12700+static inline unsigned long native_pax_close_kernel(void)
12701+{
12702+ unsigned long cr0;
12703+
12704+ cr0 = read_cr0() ^ X86_CR0_WP;
12705+ BUG_ON(!(cr0 & X86_CR0_WP));
12706+ write_cr0(cr0);
12707+ barrier();
12708+ preempt_enable_no_resched();
12709+ return cr0 ^ X86_CR0_WP;
12710+}
12711+#else
12712+static inline unsigned long native_pax_open_kernel(void) { return 0; }
12713+static inline unsigned long native_pax_close_kernel(void) { return 0; }
12714+#endif
12715+
12716 /*
12717 * The following only work if pte_present() is true.
12718 * Undefined behaviour if not..
12719 */
12720+static inline int pte_user(pte_t pte)
12721+{
12722+ return pte_val(pte) & _PAGE_USER;
12723+}
12724+
12725 static inline int pte_dirty(pte_t pte)
12726 {
12727 return pte_flags(pte) & _PAGE_DIRTY;
12728@@ -142,6 +182,11 @@ static inline unsigned long pmd_pfn(pmd_t pmd)
12729 return (pmd_val(pmd) & PTE_PFN_MASK) >> PAGE_SHIFT;
12730 }
12731
12732+static inline unsigned long pud_pfn(pud_t pud)
12733+{
12734+ return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
12735+}
12736+
12737 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
12738
12739 static inline int pmd_large(pmd_t pte)
12740@@ -195,9 +240,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12741 return pte_clear_flags(pte, _PAGE_RW);
12742 }
12743
12744+static inline pte_t pte_mkread(pte_t pte)
12745+{
12746+ return __pte(pte_val(pte) | _PAGE_USER);
12747+}
12748+
12749 static inline pte_t pte_mkexec(pte_t pte)
12750 {
12751- return pte_clear_flags(pte, _PAGE_NX);
12752+#ifdef CONFIG_X86_PAE
12753+ if (__supported_pte_mask & _PAGE_NX)
12754+ return pte_clear_flags(pte, _PAGE_NX);
12755+ else
12756+#endif
12757+ return pte_set_flags(pte, _PAGE_USER);
12758+}
12759+
12760+static inline pte_t pte_exprotect(pte_t pte)
12761+{
12762+#ifdef CONFIG_X86_PAE
12763+ if (__supported_pte_mask & _PAGE_NX)
12764+ return pte_set_flags(pte, _PAGE_NX);
12765+ else
12766+#endif
12767+ return pte_clear_flags(pte, _PAGE_USER);
12768 }
12769
12770 static inline pte_t pte_mkdirty(pte_t pte)
12771@@ -389,6 +454,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12772 #endif
12773
12774 #ifndef __ASSEMBLY__
12775+
12776+#ifdef CONFIG_PAX_PER_CPU_PGD
12777+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12778+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12779+{
12780+ return cpu_pgd[cpu];
12781+}
12782+#endif
12783+
12784 #include <linux/mm_types.h>
12785
12786 static inline int pte_none(pte_t pte)
12787@@ -565,7 +639,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12788
12789 static inline int pgd_bad(pgd_t pgd)
12790 {
12791- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12792+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12793 }
12794
12795 static inline int pgd_none(pgd_t pgd)
12796@@ -588,7 +662,12 @@ static inline int pgd_none(pgd_t pgd)
12797 * pgd_offset() returns a (pgd_t *)
12798 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12799 */
12800-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12801+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12802+
12803+#ifdef CONFIG_PAX_PER_CPU_PGD
12804+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12805+#endif
12806+
12807 /*
12808 * a shortcut which implies the use of the kernel's pgd, instead
12809 * of a process's
12810@@ -599,6 +678,20 @@ static inline int pgd_none(pgd_t pgd)
12811 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12812 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12813
12814+#ifdef CONFIG_X86_32
12815+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12816+#else
12817+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12818+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12819+
12820+#ifdef CONFIG_PAX_MEMORY_UDEREF
12821+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12822+#else
12823+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12824+#endif
12825+
12826+#endif
12827+
12828 #ifndef __ASSEMBLY__
12829
12830 extern int direct_gbpages;
12831@@ -763,11 +856,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12832 * dst and src can be on the same page, but the range must not overlap,
12833 * and must not cross a page boundary.
12834 */
12835-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12836+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12837 {
12838- memcpy(dst, src, count * sizeof(pgd_t));
12839+ pax_open_kernel();
12840+ while (count--)
12841+ *dst++ = *src++;
12842+ pax_close_kernel();
12843 }
12844
12845+#ifdef CONFIG_PAX_PER_CPU_PGD
12846+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12847+#endif
12848+
12849+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12850+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12851+#else
12852+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12853+#endif
12854
12855 #include <asm-generic/pgtable.h>
12856 #endif /* __ASSEMBLY__ */
12857diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12858index 8faa215..a8a17ea 100644
12859--- a/arch/x86/include/asm/pgtable_32.h
12860+++ b/arch/x86/include/asm/pgtable_32.h
12861@@ -25,9 +25,6 @@
12862 struct mm_struct;
12863 struct vm_area_struct;
12864
12865-extern pgd_t swapper_pg_dir[1024];
12866-extern pgd_t initial_page_table[1024];
12867-
12868 static inline void pgtable_cache_init(void) { }
12869 static inline void check_pgt_cache(void) { }
12870 void paging_init(void);
12871@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12872 # include <asm/pgtable-2level.h>
12873 #endif
12874
12875+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12876+extern pgd_t initial_page_table[PTRS_PER_PGD];
12877+#ifdef CONFIG_X86_PAE
12878+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12879+#endif
12880+
12881 #if defined(CONFIG_HIGHPTE)
12882 #define pte_offset_map(dir, address) \
12883 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12884@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12885 /* Clear a kernel PTE and flush it from the TLB */
12886 #define kpte_clear_flush(ptep, vaddr) \
12887 do { \
12888+ pax_open_kernel(); \
12889 pte_clear(&init_mm, (vaddr), (ptep)); \
12890+ pax_close_kernel(); \
12891 __flush_tlb_one((vaddr)); \
12892 } while (0)
12893
12894@@ -75,6 +80,9 @@ do { \
12895
12896 #endif /* !__ASSEMBLY__ */
12897
12898+#define HAVE_ARCH_UNMAPPED_AREA
12899+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12900+
12901 /*
12902 * kern_addr_valid() is (1) for FLATMEM and (0) for
12903 * SPARSEMEM and DISCONTIGMEM
12904diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12905index ed5903b..c7fe163 100644
12906--- a/arch/x86/include/asm/pgtable_32_types.h
12907+++ b/arch/x86/include/asm/pgtable_32_types.h
12908@@ -8,7 +8,7 @@
12909 */
12910 #ifdef CONFIG_X86_PAE
12911 # include <asm/pgtable-3level_types.h>
12912-# define PMD_SIZE (1UL << PMD_SHIFT)
12913+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12914 # define PMD_MASK (~(PMD_SIZE - 1))
12915 #else
12916 # include <asm/pgtable-2level_types.h>
12917@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12918 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12919 #endif
12920
12921+#ifdef CONFIG_PAX_KERNEXEC
12922+#ifndef __ASSEMBLY__
12923+extern unsigned char MODULES_EXEC_VADDR[];
12924+extern unsigned char MODULES_EXEC_END[];
12925+#endif
12926+#include <asm/boot.h>
12927+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12928+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12929+#else
12930+#define ktla_ktva(addr) (addr)
12931+#define ktva_ktla(addr) (addr)
12932+#endif
12933+
12934 #define MODULES_VADDR VMALLOC_START
12935 #define MODULES_END VMALLOC_END
12936 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12937diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12938index 47356f9..deb94a2 100644
12939--- a/arch/x86/include/asm/pgtable_64.h
12940+++ b/arch/x86/include/asm/pgtable_64.h
12941@@ -16,10 +16,14 @@
12942
12943 extern pud_t level3_kernel_pgt[512];
12944 extern pud_t level3_ident_pgt[512];
12945+extern pud_t level3_vmalloc_start_pgt[512];
12946+extern pud_t level3_vmalloc_end_pgt[512];
12947+extern pud_t level3_vmemmap_pgt[512];
12948+extern pud_t level2_vmemmap_pgt[512];
12949 extern pmd_t level2_kernel_pgt[512];
12950 extern pmd_t level2_fixmap_pgt[512];
12951-extern pmd_t level2_ident_pgt[512];
12952-extern pgd_t init_level4_pgt[];
12953+extern pmd_t level2_ident_pgt[512*2];
12954+extern pgd_t init_level4_pgt[512];
12955
12956 #define swapper_pg_dir init_level4_pgt
12957
12958@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12959
12960 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12961 {
12962+ pax_open_kernel();
12963 *pmdp = pmd;
12964+ pax_close_kernel();
12965 }
12966
12967 static inline void native_pmd_clear(pmd_t *pmd)
12968@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12969
12970 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12971 {
12972+ pax_open_kernel();
12973 *pudp = pud;
12974+ pax_close_kernel();
12975 }
12976
12977 static inline void native_pud_clear(pud_t *pud)
12978@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12979
12980 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12981 {
12982+ pax_open_kernel();
12983+ *pgdp = pgd;
12984+ pax_close_kernel();
12985+}
12986+
12987+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12988+{
12989 *pgdp = pgd;
12990 }
12991
12992diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12993index 766ea16..5b96cb3 100644
12994--- a/arch/x86/include/asm/pgtable_64_types.h
12995+++ b/arch/x86/include/asm/pgtable_64_types.h
12996@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12997 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12998 #define MODULES_END _AC(0xffffffffff000000, UL)
12999 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
13000+#define MODULES_EXEC_VADDR MODULES_VADDR
13001+#define MODULES_EXEC_END MODULES_END
13002+
13003+#define ktla_ktva(addr) (addr)
13004+#define ktva_ktla(addr) (addr)
13005
13006 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
13007diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
13008index ec8a1fc..7ccb593 100644
13009--- a/arch/x86/include/asm/pgtable_types.h
13010+++ b/arch/x86/include/asm/pgtable_types.h
13011@@ -16,13 +16,12 @@
13012 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
13013 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
13014 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
13015-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
13016+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
13017 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
13018 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
13019 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
13020-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
13021-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
13022-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
13023+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
13024+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
13025 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
13026
13027 /* If _PAGE_BIT_PRESENT is clear, we use these: */
13028@@ -40,7 +39,6 @@
13029 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
13030 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
13031 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
13032-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
13033 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
13034 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
13035 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
13036@@ -57,8 +55,10 @@
13037
13038 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
13039 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
13040-#else
13041+#elif defined(CONFIG_KMEMCHECK)
13042 #define _PAGE_NX (_AT(pteval_t, 0))
13043+#else
13044+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
13045 #endif
13046
13047 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
13048@@ -96,6 +96,9 @@
13049 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
13050 _PAGE_ACCESSED)
13051
13052+#define PAGE_READONLY_NOEXEC PAGE_READONLY
13053+#define PAGE_SHARED_NOEXEC PAGE_SHARED
13054+
13055 #define __PAGE_KERNEL_EXEC \
13056 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
13057 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
13058@@ -106,7 +109,7 @@
13059 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
13060 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
13061 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
13062-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
13063+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
13064 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
13065 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
13066 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
13067@@ -168,8 +171,8 @@
13068 * bits are combined, this will alow user to access the high address mapped
13069 * VDSO in the presence of CONFIG_COMPAT_VDSO
13070 */
13071-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
13072-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
13073+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13074+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
13075 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
13076 #endif
13077
13078@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
13079 {
13080 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
13081 }
13082+#endif
13083
13084+#if PAGETABLE_LEVELS == 3
13085+#include <asm-generic/pgtable-nopud.h>
13086+#endif
13087+
13088+#if PAGETABLE_LEVELS == 2
13089+#include <asm-generic/pgtable-nopmd.h>
13090+#endif
13091+
13092+#ifndef __ASSEMBLY__
13093 #if PAGETABLE_LEVELS > 3
13094 typedef struct { pudval_t pud; } pud_t;
13095
13096@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
13097 return pud.pud;
13098 }
13099 #else
13100-#include <asm-generic/pgtable-nopud.h>
13101-
13102 static inline pudval_t native_pud_val(pud_t pud)
13103 {
13104 return native_pgd_val(pud.pgd);
13105@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
13106 return pmd.pmd;
13107 }
13108 #else
13109-#include <asm-generic/pgtable-nopmd.h>
13110-
13111 static inline pmdval_t native_pmd_val(pmd_t pmd)
13112 {
13113 return native_pgd_val(pmd.pud.pgd);
13114@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
13115
13116 extern pteval_t __supported_pte_mask;
13117 extern void set_nx(void);
13118-extern int nx_enabled;
13119
13120 #define pgprot_writecombine pgprot_writecombine
13121 extern pgprot_t pgprot_writecombine(pgprot_t prot);
13122diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
13123index ad1fc85..0b15fe1 100644
13124--- a/arch/x86/include/asm/processor.h
13125+++ b/arch/x86/include/asm/processor.h
13126@@ -289,7 +289,7 @@ struct tss_struct {
13127
13128 } ____cacheline_aligned;
13129
13130-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
13131+extern struct tss_struct init_tss[NR_CPUS];
13132
13133 /*
13134 * Save the original ist values for checking stack pointers during debugging
13135@@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
13136 */
13137 #define TASK_SIZE PAGE_OFFSET
13138 #define TASK_SIZE_MAX TASK_SIZE
13139+
13140+#ifdef CONFIG_PAX_SEGMEXEC
13141+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
13142+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
13143+#else
13144 #define STACK_TOP TASK_SIZE
13145-#define STACK_TOP_MAX STACK_TOP
13146+#endif
13147+
13148+#define STACK_TOP_MAX TASK_SIZE
13149
13150 #define INIT_THREAD { \
13151- .sp0 = sizeof(init_stack) + (long)&init_stack, \
13152+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13153 .vm86_info = NULL, \
13154 .sysenter_cs = __KERNEL_CS, \
13155 .io_bitmap_ptr = NULL, \
13156@@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
13157 */
13158 #define INIT_TSS { \
13159 .x86_tss = { \
13160- .sp0 = sizeof(init_stack) + (long)&init_stack, \
13161+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
13162 .ss0 = __KERNEL_DS, \
13163 .ss1 = __KERNEL_CS, \
13164 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
13165@@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
13166 extern unsigned long thread_saved_pc(struct task_struct *tsk);
13167
13168 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13169-#define KSTK_TOP(info) \
13170-({ \
13171- unsigned long *__ptr = (unsigned long *)(info); \
13172- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13173-})
13174+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13175
13176 /*
13177 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13178@@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13179 #define task_pt_regs(task) \
13180 ({ \
13181 struct pt_regs *__regs__; \
13182- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13183+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13184 __regs__ - 1; \
13185 })
13186
13187@@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13188 /*
13189 * User space process size. 47bits minus one guard page.
13190 */
13191-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13192+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13193
13194 /* This decides where the kernel will search for a free chunk of vm
13195 * space during mmap's.
13196 */
13197 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13198- 0xc0000000 : 0xFFFFe000)
13199+ 0xc0000000 : 0xFFFFf000)
13200
13201 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13202 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13203@@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13204 #define STACK_TOP_MAX TASK_SIZE_MAX
13205
13206 #define INIT_THREAD { \
13207- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13208+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13209 }
13210
13211 #define INIT_TSS { \
13212- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13213+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13214 }
13215
13216 /*
13217@@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13218 */
13219 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13220
13221+#ifdef CONFIG_PAX_SEGMEXEC
13222+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13223+#endif
13224+
13225 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13226
13227 /* Get/set a process' ability to use the timestamp counter instruction */
13228@@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13229 #define cpu_has_amd_erratum(x) (false)
13230 #endif /* CONFIG_CPU_SUP_AMD */
13231
13232-extern unsigned long arch_align_stack(unsigned long sp);
13233+#define arch_align_stack(x) ((x) & ~0xfUL)
13234 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13235
13236 void default_idle(void);
13237 bool set_pm_idle_to_default(void);
13238
13239-void stop_this_cpu(void *dummy);
13240+void stop_this_cpu(void *dummy) __noreturn;
13241
13242 #endif /* _ASM_X86_PROCESSOR_H */
13243diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13244index 19f16eb..b50624b 100644
13245--- a/arch/x86/include/asm/ptrace.h
13246+++ b/arch/x86/include/asm/ptrace.h
13247@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13248 }
13249
13250 /*
13251- * user_mode_vm(regs) determines whether a register set came from user mode.
13252+ * user_mode(regs) determines whether a register set came from user mode.
13253 * This is true if V8086 mode was enabled OR if the register set was from
13254 * protected mode with RPL-3 CS value. This tricky test checks that with
13255 * one comparison. Many places in the kernel can bypass this full check
13256- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13257+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13258+ * be used.
13259 */
13260-static inline int user_mode(struct pt_regs *regs)
13261+static inline int user_mode_novm(struct pt_regs *regs)
13262 {
13263 #ifdef CONFIG_X86_32
13264 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13265 #else
13266- return !!(regs->cs & 3);
13267+ return !!(regs->cs & SEGMENT_RPL_MASK);
13268 #endif
13269 }
13270
13271-static inline int user_mode_vm(struct pt_regs *regs)
13272+static inline int user_mode(struct pt_regs *regs)
13273 {
13274 #ifdef CONFIG_X86_32
13275 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13276 USER_RPL;
13277 #else
13278- return user_mode(regs);
13279+ return user_mode_novm(regs);
13280 #endif
13281 }
13282
13283@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13284 #ifdef CONFIG_X86_64
13285 static inline bool user_64bit_mode(struct pt_regs *regs)
13286 {
13287+ unsigned long cs = regs->cs & 0xffff;
13288 #ifndef CONFIG_PARAVIRT
13289 /*
13290 * On non-paravirt systems, this is the only long mode CPL 3
13291 * selector. We do not allow long mode selectors in the LDT.
13292 */
13293- return regs->cs == __USER_CS;
13294+ return cs == __USER_CS;
13295 #else
13296 /* Headers are too twisted for this to go in paravirt.h. */
13297- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13298+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13299 #endif
13300 }
13301 #endif
13302diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13303index fe1ec5b..dc5c3fe 100644
13304--- a/arch/x86/include/asm/realmode.h
13305+++ b/arch/x86/include/asm/realmode.h
13306@@ -22,16 +22,14 @@ struct real_mode_header {
13307 #endif
13308 /* APM/BIOS reboot */
13309 u32 machine_real_restart_asm;
13310-#ifdef CONFIG_X86_64
13311 u32 machine_real_restart_seg;
13312-#endif
13313 };
13314
13315 /* This must match data at trampoline_32/64.S */
13316 struct trampoline_header {
13317 #ifdef CONFIG_X86_32
13318 u32 start;
13319- u16 gdt_pad;
13320+ u16 boot_cs;
13321 u16 gdt_limit;
13322 u32 gdt_base;
13323 #else
13324diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13325index a82c4f1..ac45053 100644
13326--- a/arch/x86/include/asm/reboot.h
13327+++ b/arch/x86/include/asm/reboot.h
13328@@ -6,13 +6,13 @@
13329 struct pt_regs;
13330
13331 struct machine_ops {
13332- void (*restart)(char *cmd);
13333- void (*halt)(void);
13334- void (*power_off)(void);
13335+ void (* __noreturn restart)(char *cmd);
13336+ void (* __noreturn halt)(void);
13337+ void (* __noreturn power_off)(void);
13338 void (*shutdown)(void);
13339 void (*crash_shutdown)(struct pt_regs *);
13340- void (*emergency_restart)(void);
13341-};
13342+ void (* __noreturn emergency_restart)(void);
13343+} __no_const;
13344
13345 extern struct machine_ops machine_ops;
13346
13347diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13348index 2dbe4a7..ce1db00 100644
13349--- a/arch/x86/include/asm/rwsem.h
13350+++ b/arch/x86/include/asm/rwsem.h
13351@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13352 {
13353 asm volatile("# beginning down_read\n\t"
13354 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13355+
13356+#ifdef CONFIG_PAX_REFCOUNT
13357+ "jno 0f\n"
13358+ LOCK_PREFIX _ASM_DEC "(%1)\n"
13359+ "int $4\n0:\n"
13360+ _ASM_EXTABLE(0b, 0b)
13361+#endif
13362+
13363 /* adds 0x00000001 */
13364 " jns 1f\n"
13365 " call call_rwsem_down_read_failed\n"
13366@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13367 "1:\n\t"
13368 " mov %1,%2\n\t"
13369 " add %3,%2\n\t"
13370+
13371+#ifdef CONFIG_PAX_REFCOUNT
13372+ "jno 0f\n"
13373+ "sub %3,%2\n"
13374+ "int $4\n0:\n"
13375+ _ASM_EXTABLE(0b, 0b)
13376+#endif
13377+
13378 " jle 2f\n\t"
13379 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13380 " jnz 1b\n\t"
13381@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13382 long tmp;
13383 asm volatile("# beginning down_write\n\t"
13384 LOCK_PREFIX " xadd %1,(%2)\n\t"
13385+
13386+#ifdef CONFIG_PAX_REFCOUNT
13387+ "jno 0f\n"
13388+ "mov %1,(%2)\n"
13389+ "int $4\n0:\n"
13390+ _ASM_EXTABLE(0b, 0b)
13391+#endif
13392+
13393 /* adds 0xffff0001, returns the old value */
13394 " test %1,%1\n\t"
13395 /* was the count 0 before? */
13396@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13397 long tmp;
13398 asm volatile("# beginning __up_read\n\t"
13399 LOCK_PREFIX " xadd %1,(%2)\n\t"
13400+
13401+#ifdef CONFIG_PAX_REFCOUNT
13402+ "jno 0f\n"
13403+ "mov %1,(%2)\n"
13404+ "int $4\n0:\n"
13405+ _ASM_EXTABLE(0b, 0b)
13406+#endif
13407+
13408 /* subtracts 1, returns the old value */
13409 " jns 1f\n\t"
13410 " call call_rwsem_wake\n" /* expects old value in %edx */
13411@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13412 long tmp;
13413 asm volatile("# beginning __up_write\n\t"
13414 LOCK_PREFIX " xadd %1,(%2)\n\t"
13415+
13416+#ifdef CONFIG_PAX_REFCOUNT
13417+ "jno 0f\n"
13418+ "mov %1,(%2)\n"
13419+ "int $4\n0:\n"
13420+ _ASM_EXTABLE(0b, 0b)
13421+#endif
13422+
13423 /* subtracts 0xffff0001, returns the old value */
13424 " jns 1f\n\t"
13425 " call call_rwsem_wake\n" /* expects old value in %edx */
13426@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13427 {
13428 asm volatile("# beginning __downgrade_write\n\t"
13429 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13430+
13431+#ifdef CONFIG_PAX_REFCOUNT
13432+ "jno 0f\n"
13433+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13434+ "int $4\n0:\n"
13435+ _ASM_EXTABLE(0b, 0b)
13436+#endif
13437+
13438 /*
13439 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13440 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13441@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13442 */
13443 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13444 {
13445- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13446+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13447+
13448+#ifdef CONFIG_PAX_REFCOUNT
13449+ "jno 0f\n"
13450+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
13451+ "int $4\n0:\n"
13452+ _ASM_EXTABLE(0b, 0b)
13453+#endif
13454+
13455 : "+m" (sem->count)
13456 : "er" (delta));
13457 }
13458@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13459 */
13460 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13461 {
13462- return delta + xadd(&sem->count, delta);
13463+ return delta + xadd_check_overflow(&sem->count, delta);
13464 }
13465
13466 #endif /* __KERNEL__ */
13467diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13468index c48a950..c6d7468 100644
13469--- a/arch/x86/include/asm/segment.h
13470+++ b/arch/x86/include/asm/segment.h
13471@@ -64,10 +64,15 @@
13472 * 26 - ESPFIX small SS
13473 * 27 - per-cpu [ offset to per-cpu data area ]
13474 * 28 - stack_canary-20 [ for stack protector ]
13475- * 29 - unused
13476- * 30 - unused
13477+ * 29 - PCI BIOS CS
13478+ * 30 - PCI BIOS DS
13479 * 31 - TSS for double fault handler
13480 */
13481+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13482+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13483+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13484+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13485+
13486 #define GDT_ENTRY_TLS_MIN 6
13487 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13488
13489@@ -79,6 +84,8 @@
13490
13491 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13492
13493+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13494+
13495 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13496
13497 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13498@@ -104,6 +111,12 @@
13499 #define __KERNEL_STACK_CANARY 0
13500 #endif
13501
13502+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13503+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13504+
13505+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13506+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13507+
13508 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13509
13510 /*
13511@@ -141,7 +154,7 @@
13512 */
13513
13514 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13515-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13516+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13517
13518
13519 #else
13520@@ -165,6 +178,8 @@
13521 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13522 #define __USER32_DS __USER_DS
13523
13524+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13525+
13526 #define GDT_ENTRY_TSS 8 /* needs two entries */
13527 #define GDT_ENTRY_LDT 10 /* needs two entries */
13528 #define GDT_ENTRY_TLS_MIN 12
13529@@ -185,6 +200,7 @@
13530 #endif
13531
13532 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13533+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13534 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13535 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13536 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13537@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13538 {
13539 unsigned long __limit;
13540 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13541- return __limit + 1;
13542+ return __limit;
13543 }
13544
13545 #endif /* !__ASSEMBLY__ */
13546diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13547index 4f19a15..9e14f27 100644
13548--- a/arch/x86/include/asm/smp.h
13549+++ b/arch/x86/include/asm/smp.h
13550@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13551 /* cpus sharing the last level cache: */
13552 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13553 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13554-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13555+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13556
13557 static inline struct cpumask *cpu_sibling_mask(int cpu)
13558 {
13559@@ -79,7 +79,7 @@ struct smp_ops {
13560
13561 void (*send_call_func_ipi)(const struct cpumask *mask);
13562 void (*send_call_func_single_ipi)(int cpu);
13563-};
13564+} __no_const;
13565
13566 /* Globals due to paravirt */
13567 extern void set_cpu_sibling_map(int cpu);
13568@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13569 extern int safe_smp_processor_id(void);
13570
13571 #elif defined(CONFIG_X86_64_SMP)
13572-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13573-
13574-#define stack_smp_processor_id() \
13575-({ \
13576- struct thread_info *ti; \
13577- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13578- ti->cpu; \
13579-})
13580+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13581+#define stack_smp_processor_id() raw_smp_processor_id()
13582 #define safe_smp_processor_id() smp_processor_id()
13583
13584 #endif
13585diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13586index 33692ea..350a534 100644
13587--- a/arch/x86/include/asm/spinlock.h
13588+++ b/arch/x86/include/asm/spinlock.h
13589@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13590 static inline void arch_read_lock(arch_rwlock_t *rw)
13591 {
13592 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13593+
13594+#ifdef CONFIG_PAX_REFCOUNT
13595+ "jno 0f\n"
13596+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13597+ "int $4\n0:\n"
13598+ _ASM_EXTABLE(0b, 0b)
13599+#endif
13600+
13601 "jns 1f\n"
13602 "call __read_lock_failed\n\t"
13603 "1:\n"
13604@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13605 static inline void arch_write_lock(arch_rwlock_t *rw)
13606 {
13607 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13608+
13609+#ifdef CONFIG_PAX_REFCOUNT
13610+ "jno 0f\n"
13611+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13612+ "int $4\n0:\n"
13613+ _ASM_EXTABLE(0b, 0b)
13614+#endif
13615+
13616 "jz 1f\n"
13617 "call __write_lock_failed\n\t"
13618 "1:\n"
13619@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13620
13621 static inline void arch_read_unlock(arch_rwlock_t *rw)
13622 {
13623- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13624+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13625+
13626+#ifdef CONFIG_PAX_REFCOUNT
13627+ "jno 0f\n"
13628+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13629+ "int $4\n0:\n"
13630+ _ASM_EXTABLE(0b, 0b)
13631+#endif
13632+
13633 :"+m" (rw->lock) : : "memory");
13634 }
13635
13636 static inline void arch_write_unlock(arch_rwlock_t *rw)
13637 {
13638- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13639+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13640+
13641+#ifdef CONFIG_PAX_REFCOUNT
13642+ "jno 0f\n"
13643+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13644+ "int $4\n0:\n"
13645+ _ASM_EXTABLE(0b, 0b)
13646+#endif
13647+
13648 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13649 }
13650
13651diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13652index 6a99859..03cb807 100644
13653--- a/arch/x86/include/asm/stackprotector.h
13654+++ b/arch/x86/include/asm/stackprotector.h
13655@@ -47,7 +47,7 @@
13656 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13657 */
13658 #define GDT_STACK_CANARY_INIT \
13659- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13660+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13661
13662 /*
13663 * Initialize the stackprotector canary value.
13664@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13665
13666 static inline void load_stack_canary_segment(void)
13667 {
13668-#ifdef CONFIG_X86_32
13669+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13670 asm volatile ("mov %0, %%gs" : : "r" (0));
13671 #endif
13672 }
13673diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13674index 70bbe39..4ae2bd4 100644
13675--- a/arch/x86/include/asm/stacktrace.h
13676+++ b/arch/x86/include/asm/stacktrace.h
13677@@ -11,28 +11,20 @@
13678
13679 extern int kstack_depth_to_print;
13680
13681-struct thread_info;
13682+struct task_struct;
13683 struct stacktrace_ops;
13684
13685-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13686- unsigned long *stack,
13687- unsigned long bp,
13688- const struct stacktrace_ops *ops,
13689- void *data,
13690- unsigned long *end,
13691- int *graph);
13692+typedef unsigned long walk_stack_t(struct task_struct *task,
13693+ void *stack_start,
13694+ unsigned long *stack,
13695+ unsigned long bp,
13696+ const struct stacktrace_ops *ops,
13697+ void *data,
13698+ unsigned long *end,
13699+ int *graph);
13700
13701-extern unsigned long
13702-print_context_stack(struct thread_info *tinfo,
13703- unsigned long *stack, unsigned long bp,
13704- const struct stacktrace_ops *ops, void *data,
13705- unsigned long *end, int *graph);
13706-
13707-extern unsigned long
13708-print_context_stack_bp(struct thread_info *tinfo,
13709- unsigned long *stack, unsigned long bp,
13710- const struct stacktrace_ops *ops, void *data,
13711- unsigned long *end, int *graph);
13712+extern walk_stack_t print_context_stack;
13713+extern walk_stack_t print_context_stack_bp;
13714
13715 /* Generic stack tracer with callbacks */
13716
13717@@ -40,7 +32,7 @@ struct stacktrace_ops {
13718 void (*address)(void *data, unsigned long address, int reliable);
13719 /* On negative return stop dumping */
13720 int (*stack)(void *data, char *name);
13721- walk_stack_t walk_stack;
13722+ walk_stack_t *walk_stack;
13723 };
13724
13725 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13726diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13727index 4ec45b3..a4f0a8a 100644
13728--- a/arch/x86/include/asm/switch_to.h
13729+++ b/arch/x86/include/asm/switch_to.h
13730@@ -108,7 +108,7 @@ do { \
13731 "call __switch_to\n\t" \
13732 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13733 __switch_canary \
13734- "movq %P[thread_info](%%rsi),%%r8\n\t" \
13735+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13736 "movq %%rax,%%rdi\n\t" \
13737 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13738 "jnz ret_from_fork\n\t" \
13739@@ -119,7 +119,7 @@ do { \
13740 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13741 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13742 [_tif_fork] "i" (_TIF_FORK), \
13743- [thread_info] "i" (offsetof(struct task_struct, stack)), \
13744+ [thread_info] "m" (current_tinfo), \
13745 [current_task] "m" (current_task) \
13746 __switch_canary_iparam \
13747 : "memory", "cc" __EXTRA_CLOBBER)
13748diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13749index 2d946e6..e453ec4 100644
13750--- a/arch/x86/include/asm/thread_info.h
13751+++ b/arch/x86/include/asm/thread_info.h
13752@@ -10,6 +10,7 @@
13753 #include <linux/compiler.h>
13754 #include <asm/page.h>
13755 #include <asm/types.h>
13756+#include <asm/percpu.h>
13757
13758 /*
13759 * low level task data that entry.S needs immediate access to
13760@@ -24,7 +25,6 @@ struct exec_domain;
13761 #include <linux/atomic.h>
13762
13763 struct thread_info {
13764- struct task_struct *task; /* main task structure */
13765 struct exec_domain *exec_domain; /* execution domain */
13766 __u32 flags; /* low level flags */
13767 __u32 status; /* thread synchronous flags */
13768@@ -34,19 +34,13 @@ struct thread_info {
13769 mm_segment_t addr_limit;
13770 struct restart_block restart_block;
13771 void __user *sysenter_return;
13772-#ifdef CONFIG_X86_32
13773- unsigned long previous_esp; /* ESP of the previous stack in
13774- case of nested (IRQ) stacks
13775- */
13776- __u8 supervisor_stack[0];
13777-#endif
13778+ unsigned long lowest_stack;
13779 unsigned int sig_on_uaccess_error:1;
13780 unsigned int uaccess_err:1; /* uaccess failed */
13781 };
13782
13783-#define INIT_THREAD_INFO(tsk) \
13784+#define INIT_THREAD_INFO \
13785 { \
13786- .task = &tsk, \
13787 .exec_domain = &default_exec_domain, \
13788 .flags = 0, \
13789 .cpu = 0, \
13790@@ -57,7 +51,7 @@ struct thread_info {
13791 }, \
13792 }
13793
13794-#define init_thread_info (init_thread_union.thread_info)
13795+#define init_thread_info (init_thread_union.stack)
13796 #define init_stack (init_thread_union.stack)
13797
13798 #else /* !__ASSEMBLY__ */
13799@@ -98,6 +92,7 @@ struct thread_info {
13800 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13801 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13802 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13803+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13804
13805 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13806 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13807@@ -122,17 +117,18 @@ struct thread_info {
13808 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13809 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13810 #define _TIF_X32 (1 << TIF_X32)
13811+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13812
13813 /* work to do in syscall_trace_enter() */
13814 #define _TIF_WORK_SYSCALL_ENTRY \
13815 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13816 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13817- _TIF_NOHZ)
13818+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13819
13820 /* work to do in syscall_trace_leave() */
13821 #define _TIF_WORK_SYSCALL_EXIT \
13822 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13823- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13824+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13825
13826 /* work to do on interrupt/exception return */
13827 #define _TIF_WORK_MASK \
13828@@ -143,7 +139,7 @@ struct thread_info {
13829 /* work to do on any return to user space */
13830 #define _TIF_ALLWORK_MASK \
13831 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13832- _TIF_NOHZ)
13833+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13834
13835 /* Only used for 64 bit */
13836 #define _TIF_DO_NOTIFY_MASK \
13837@@ -159,45 +155,40 @@ struct thread_info {
13838
13839 #define PREEMPT_ACTIVE 0x10000000
13840
13841-#ifdef CONFIG_X86_32
13842-
13843-#define STACK_WARN (THREAD_SIZE/8)
13844-/*
13845- * macros/functions for gaining access to the thread information structure
13846- *
13847- * preempt_count needs to be 1 initially, until the scheduler is functional.
13848- */
13849-#ifndef __ASSEMBLY__
13850-
13851-
13852-/* how to get the current stack pointer from C */
13853-register unsigned long current_stack_pointer asm("esp") __used;
13854-
13855-/* how to get the thread information struct from C */
13856-static inline struct thread_info *current_thread_info(void)
13857-{
13858- return (struct thread_info *)
13859- (current_stack_pointer & ~(THREAD_SIZE - 1));
13860-}
13861-
13862-#else /* !__ASSEMBLY__ */
13863-
13864+#ifdef __ASSEMBLY__
13865 /* how to get the thread information struct from ASM */
13866 #define GET_THREAD_INFO(reg) \
13867- movl $-THREAD_SIZE, reg; \
13868- andl %esp, reg
13869+ mov PER_CPU_VAR(current_tinfo), reg
13870
13871 /* use this one if reg already contains %esp */
13872-#define GET_THREAD_INFO_WITH_ESP(reg) \
13873- andl $-THREAD_SIZE, reg
13874+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13875+#else
13876+/* how to get the thread information struct from C */
13877+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13878+
13879+static __always_inline struct thread_info *current_thread_info(void)
13880+{
13881+ return this_cpu_read_stable(current_tinfo);
13882+}
13883+#endif
13884+
13885+#ifdef CONFIG_X86_32
13886+
13887+#define STACK_WARN (THREAD_SIZE/8)
13888+/*
13889+ * macros/functions for gaining access to the thread information structure
13890+ *
13891+ * preempt_count needs to be 1 initially, until the scheduler is functional.
13892+ */
13893+#ifndef __ASSEMBLY__
13894+
13895+/* how to get the current stack pointer from C */
13896+register unsigned long current_stack_pointer asm("esp") __used;
13897
13898 #endif
13899
13900 #else /* X86_32 */
13901
13902-#include <asm/percpu.h>
13903-#define KERNEL_STACK_OFFSET (5*8)
13904-
13905 /*
13906 * macros/functions for gaining access to the thread information structure
13907 * preempt_count needs to be 1 initially, until the scheduler is functional.
13908@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13909 #ifndef __ASSEMBLY__
13910 DECLARE_PER_CPU(unsigned long, kernel_stack);
13911
13912-static inline struct thread_info *current_thread_info(void)
13913-{
13914- struct thread_info *ti;
13915- ti = (void *)(this_cpu_read_stable(kernel_stack) +
13916- KERNEL_STACK_OFFSET - THREAD_SIZE);
13917- return ti;
13918-}
13919-
13920-#else /* !__ASSEMBLY__ */
13921-
13922-/* how to get the thread information struct from ASM */
13923-#define GET_THREAD_INFO(reg) \
13924- movq PER_CPU_VAR(kernel_stack),reg ; \
13925- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13926-
13927-/*
13928- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13929- * a certain register (to be used in assembler memory operands).
13930- */
13931-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13932-
13933+/* how to get the current stack pointer from C */
13934+register unsigned long current_stack_pointer asm("rsp") __used;
13935 #endif
13936
13937 #endif /* !X86_32 */
13938@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13939 extern void arch_task_cache_init(void);
13940 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13941 extern void arch_release_task_struct(struct task_struct *tsk);
13942+
13943+#define __HAVE_THREAD_FUNCTIONS
13944+#define task_thread_info(task) (&(task)->tinfo)
13945+#define task_stack_page(task) ((task)->stack)
13946+#define setup_thread_stack(p, org) do {} while (0)
13947+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13948+
13949 #endif
13950 #endif /* _ASM_X86_THREAD_INFO_H */
13951diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13952index 7ccf8d1..9a18110 100644
13953--- a/arch/x86/include/asm/uaccess.h
13954+++ b/arch/x86/include/asm/uaccess.h
13955@@ -7,6 +7,7 @@
13956 #include <linux/compiler.h>
13957 #include <linux/thread_info.h>
13958 #include <linux/string.h>
13959+#include <linux/sched.h>
13960 #include <asm/asm.h>
13961 #include <asm/page.h>
13962 #include <asm/smap.h>
13963@@ -29,7 +30,12 @@
13964
13965 #define get_ds() (KERNEL_DS)
13966 #define get_fs() (current_thread_info()->addr_limit)
13967+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13968+void __set_fs(mm_segment_t x);
13969+void set_fs(mm_segment_t x);
13970+#else
13971 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13972+#endif
13973
13974 #define segment_eq(a, b) ((a).seg == (b).seg)
13975
13976@@ -77,8 +83,33 @@
13977 * checks that the pointer is in the user space range - after calling
13978 * this function, memory access functions may still return -EFAULT.
13979 */
13980-#define access_ok(type, addr, size) \
13981- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13982+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13983+#define access_ok(type, addr, size) \
13984+({ \
13985+ long __size = size; \
13986+ unsigned long __addr = (unsigned long)addr; \
13987+ unsigned long __addr_ao = __addr & PAGE_MASK; \
13988+ unsigned long __end_ao = __addr + __size - 1; \
13989+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13990+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13991+ while(__addr_ao <= __end_ao) { \
13992+ char __c_ao; \
13993+ __addr_ao += PAGE_SIZE; \
13994+ if (__size > PAGE_SIZE) \
13995+ cond_resched(); \
13996+ if (__get_user(__c_ao, (char __user *)__addr)) \
13997+ break; \
13998+ if (type != VERIFY_WRITE) { \
13999+ __addr = __addr_ao; \
14000+ continue; \
14001+ } \
14002+ if (__put_user(__c_ao, (char __user *)__addr)) \
14003+ break; \
14004+ __addr = __addr_ao; \
14005+ } \
14006+ } \
14007+ __ret_ao; \
14008+})
14009
14010 /*
14011 * The exception table consists of pairs of addresses relative to the
14012@@ -189,13 +220,21 @@ extern int __get_user_bad(void);
14013 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
14014 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
14015
14016-
14017+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
14018+#define __copyuser_seg "gs;"
14019+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
14020+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
14021+#else
14022+#define __copyuser_seg
14023+#define __COPYUSER_SET_ES
14024+#define __COPYUSER_RESTORE_ES
14025+#endif
14026
14027 #ifdef CONFIG_X86_32
14028 #define __put_user_asm_u64(x, addr, err, errret) \
14029 asm volatile(ASM_STAC "\n" \
14030- "1: movl %%eax,0(%2)\n" \
14031- "2: movl %%edx,4(%2)\n" \
14032+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
14033+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
14034 "3: " ASM_CLAC "\n" \
14035 ".section .fixup,\"ax\"\n" \
14036 "4: movl %3,%0\n" \
14037@@ -208,8 +247,8 @@ extern int __get_user_bad(void);
14038
14039 #define __put_user_asm_ex_u64(x, addr) \
14040 asm volatile(ASM_STAC "\n" \
14041- "1: movl %%eax,0(%1)\n" \
14042- "2: movl %%edx,4(%1)\n" \
14043+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
14044+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
14045 "3: " ASM_CLAC "\n" \
14046 _ASM_EXTABLE_EX(1b, 2b) \
14047 _ASM_EXTABLE_EX(2b, 3b) \
14048@@ -261,7 +300,7 @@ extern void __put_user_8(void);
14049 __typeof__(*(ptr)) __pu_val; \
14050 __chk_user_ptr(ptr); \
14051 might_fault(); \
14052- __pu_val = x; \
14053+ __pu_val = (x); \
14054 switch (sizeof(*(ptr))) { \
14055 case 1: \
14056 __put_user_x(1, __pu_val, ptr, __ret_pu); \
14057@@ -383,7 +422,7 @@ do { \
14058
14059 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14060 asm volatile(ASM_STAC "\n" \
14061- "1: mov"itype" %2,%"rtype"1\n" \
14062+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
14063 "2: " ASM_CLAC "\n" \
14064 ".section .fixup,\"ax\"\n" \
14065 "3: mov %3,%0\n" \
14066@@ -391,7 +430,7 @@ do { \
14067 " jmp 2b\n" \
14068 ".previous\n" \
14069 _ASM_EXTABLE(1b, 3b) \
14070- : "=r" (err), ltype(x) \
14071+ : "=r" (err), ltype (x) \
14072 : "m" (__m(addr)), "i" (errret), "0" (err))
14073
14074 #define __get_user_size_ex(x, ptr, size) \
14075@@ -416,7 +455,7 @@ do { \
14076 } while (0)
14077
14078 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
14079- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
14080+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
14081 "2:\n" \
14082 _ASM_EXTABLE_EX(1b, 2b) \
14083 : ltype(x) : "m" (__m(addr)))
14084@@ -433,13 +472,24 @@ do { \
14085 int __gu_err; \
14086 unsigned long __gu_val; \
14087 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
14088- (x) = (__force __typeof__(*(ptr)))__gu_val; \
14089+ (x) = (__typeof__(*(ptr)))__gu_val; \
14090 __gu_err; \
14091 })
14092
14093 /* FIXME: this hack is definitely wrong -AK */
14094 struct __large_struct { unsigned long buf[100]; };
14095-#define __m(x) (*(struct __large_struct __user *)(x))
14096+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14097+#define ____m(x) \
14098+({ \
14099+ unsigned long ____x = (unsigned long)(x); \
14100+ if (____x < PAX_USER_SHADOW_BASE) \
14101+ ____x += PAX_USER_SHADOW_BASE; \
14102+ (void __user *)____x; \
14103+})
14104+#else
14105+#define ____m(x) (x)
14106+#endif
14107+#define __m(x) (*(struct __large_struct __user *)____m(x))
14108
14109 /*
14110 * Tell gcc we read from memory instead of writing: this is because
14111@@ -448,7 +498,7 @@ struct __large_struct { unsigned long buf[100]; };
14112 */
14113 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
14114 asm volatile(ASM_STAC "\n" \
14115- "1: mov"itype" %"rtype"1,%2\n" \
14116+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
14117 "2: " ASM_CLAC "\n" \
14118 ".section .fixup,\"ax\"\n" \
14119 "3: mov %3,%0\n" \
14120@@ -456,10 +506,10 @@ struct __large_struct { unsigned long buf[100]; };
14121 ".previous\n" \
14122 _ASM_EXTABLE(1b, 3b) \
14123 : "=r"(err) \
14124- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
14125+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
14126
14127 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
14128- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
14129+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
14130 "2:\n" \
14131 _ASM_EXTABLE_EX(1b, 2b) \
14132 : : ltype(x), "m" (__m(addr)))
14133@@ -498,8 +548,12 @@ struct __large_struct { unsigned long buf[100]; };
14134 * On error, the variable @x is set to zero.
14135 */
14136
14137+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14138+#define __get_user(x, ptr) get_user((x), (ptr))
14139+#else
14140 #define __get_user(x, ptr) \
14141 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
14142+#endif
14143
14144 /**
14145 * __put_user: - Write a simple value into user space, with less checking.
14146@@ -521,8 +575,12 @@ struct __large_struct { unsigned long buf[100]; };
14147 * Returns zero on success, or -EFAULT on error.
14148 */
14149
14150+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14151+#define __put_user(x, ptr) put_user((x), (ptr))
14152+#else
14153 #define __put_user(x, ptr) \
14154 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
14155+#endif
14156
14157 #define __get_user_unaligned __get_user
14158 #define __put_user_unaligned __put_user
14159@@ -540,7 +598,7 @@ struct __large_struct { unsigned long buf[100]; };
14160 #define get_user_ex(x, ptr) do { \
14161 unsigned long __gue_val; \
14162 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
14163- (x) = (__force __typeof__(*(ptr)))__gue_val; \
14164+ (x) = (__typeof__(*(ptr)))__gue_val; \
14165 } while (0)
14166
14167 #ifdef CONFIG_X86_WP_WORKS_OK
14168@@ -574,8 +632,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
14169 extern __must_check long strlen_user(const char __user *str);
14170 extern __must_check long strnlen_user(const char __user *str, long n);
14171
14172-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14173-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14174+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14175+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14176
14177 /*
14178 * movsl can be slow when source and dest are not both 8-byte aligned
14179diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14180index 7f760a9..04b1c65 100644
14181--- a/arch/x86/include/asm/uaccess_32.h
14182+++ b/arch/x86/include/asm/uaccess_32.h
14183@@ -11,15 +11,15 @@
14184 #include <asm/page.h>
14185
14186 unsigned long __must_check __copy_to_user_ll
14187- (void __user *to, const void *from, unsigned long n);
14188+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14189 unsigned long __must_check __copy_from_user_ll
14190- (void *to, const void __user *from, unsigned long n);
14191+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14192 unsigned long __must_check __copy_from_user_ll_nozero
14193- (void *to, const void __user *from, unsigned long n);
14194+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14195 unsigned long __must_check __copy_from_user_ll_nocache
14196- (void *to, const void __user *from, unsigned long n);
14197+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14198 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14199- (void *to, const void __user *from, unsigned long n);
14200+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14201
14202 /**
14203 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14204@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14205 static __always_inline unsigned long __must_check
14206 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14207 {
14208+ if ((long)n < 0)
14209+ return n;
14210+
14211+ check_object_size(from, n, true);
14212+
14213 if (__builtin_constant_p(n)) {
14214 unsigned long ret;
14215
14216@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14217 __copy_to_user(void __user *to, const void *from, unsigned long n)
14218 {
14219 might_fault();
14220+
14221 return __copy_to_user_inatomic(to, from, n);
14222 }
14223
14224 static __always_inline unsigned long
14225 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14226 {
14227+ if ((long)n < 0)
14228+ return n;
14229+
14230 /* Avoid zeroing the tail if the copy fails..
14231 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14232 * but as the zeroing behaviour is only significant when n is not
14233@@ -137,6 +146,12 @@ static __always_inline unsigned long
14234 __copy_from_user(void *to, const void __user *from, unsigned long n)
14235 {
14236 might_fault();
14237+
14238+ if ((long)n < 0)
14239+ return n;
14240+
14241+ check_object_size(to, n, false);
14242+
14243 if (__builtin_constant_p(n)) {
14244 unsigned long ret;
14245
14246@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14247 const void __user *from, unsigned long n)
14248 {
14249 might_fault();
14250+
14251+ if ((long)n < 0)
14252+ return n;
14253+
14254 if (__builtin_constant_p(n)) {
14255 unsigned long ret;
14256
14257@@ -181,15 +200,19 @@ static __always_inline unsigned long
14258 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14259 unsigned long n)
14260 {
14261- return __copy_from_user_ll_nocache_nozero(to, from, n);
14262+ if ((long)n < 0)
14263+ return n;
14264+
14265+ return __copy_from_user_ll_nocache_nozero(to, from, n);
14266 }
14267
14268-unsigned long __must_check copy_to_user(void __user *to,
14269- const void *from, unsigned long n);
14270-unsigned long __must_check _copy_from_user(void *to,
14271- const void __user *from,
14272- unsigned long n);
14273-
14274+extern void copy_to_user_overflow(void)
14275+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14276+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14277+#else
14278+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14279+#endif
14280+;
14281
14282 extern void copy_from_user_overflow(void)
14283 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14284@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
14285 #endif
14286 ;
14287
14288-static inline unsigned long __must_check copy_from_user(void *to,
14289- const void __user *from,
14290- unsigned long n)
14291+/**
14292+ * copy_to_user: - Copy a block of data into user space.
14293+ * @to: Destination address, in user space.
14294+ * @from: Source address, in kernel space.
14295+ * @n: Number of bytes to copy.
14296+ *
14297+ * Context: User context only. This function may sleep.
14298+ *
14299+ * Copy data from kernel space to user space.
14300+ *
14301+ * Returns number of bytes that could not be copied.
14302+ * On success, this will be zero.
14303+ */
14304+static inline unsigned long __must_check
14305+copy_to_user(void __user *to, const void *from, unsigned long n)
14306 {
14307- int sz = __compiletime_object_size(to);
14308+ size_t sz = __compiletime_object_size(from);
14309
14310- if (likely(sz == -1 || sz >= n))
14311- n = _copy_from_user(to, from, n);
14312- else
14313+ if (unlikely(sz != (size_t)-1 && sz < n))
14314+ copy_to_user_overflow();
14315+ else if (access_ok(VERIFY_WRITE, to, n))
14316+ n = __copy_to_user(to, from, n);
14317+ return n;
14318+}
14319+
14320+/**
14321+ * copy_from_user: - Copy a block of data from user space.
14322+ * @to: Destination address, in kernel space.
14323+ * @from: Source address, in user space.
14324+ * @n: Number of bytes to copy.
14325+ *
14326+ * Context: User context only. This function may sleep.
14327+ *
14328+ * Copy data from user space to kernel space.
14329+ *
14330+ * Returns number of bytes that could not be copied.
14331+ * On success, this will be zero.
14332+ *
14333+ * If some data could not be copied, this function will pad the copied
14334+ * data to the requested size using zero bytes.
14335+ */
14336+static inline unsigned long __must_check
14337+copy_from_user(void *to, const void __user *from, unsigned long n)
14338+{
14339+ size_t sz = __compiletime_object_size(to);
14340+
14341+ check_object_size(to, n, false);
14342+
14343+ if (unlikely(sz != (size_t)-1 && sz < n))
14344 copy_from_user_overflow();
14345-
14346+ else if (access_ok(VERIFY_READ, from, n))
14347+ n = __copy_from_user(to, from, n);
14348+ else if ((long)n > 0)
14349+ memset(to, 0, n);
14350 return n;
14351 }
14352
14353diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14354index 142810c..4b68a3e 100644
14355--- a/arch/x86/include/asm/uaccess_64.h
14356+++ b/arch/x86/include/asm/uaccess_64.h
14357@@ -10,6 +10,9 @@
14358 #include <asm/alternative.h>
14359 #include <asm/cpufeature.h>
14360 #include <asm/page.h>
14361+#include <asm/pgtable.h>
14362+
14363+#define set_fs(x) (current_thread_info()->addr_limit = (x))
14364
14365 /*
14366 * Copy To/From Userspace
14367@@ -17,13 +20,13 @@
14368
14369 /* Handles exceptions in both to and from, but doesn't do access_ok */
14370 __must_check unsigned long
14371-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14372+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14373 __must_check unsigned long
14374-copy_user_generic_string(void *to, const void *from, unsigned len);
14375+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14376 __must_check unsigned long
14377-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14378+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14379
14380-static __always_inline __must_check unsigned long
14381+static __always_inline __must_check __size_overflow(3) unsigned long
14382 copy_user_generic(void *to, const void *from, unsigned len)
14383 {
14384 unsigned ret;
14385@@ -41,142 +44,203 @@ copy_user_generic(void *to, const void *from, unsigned len)
14386 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14387 "=d" (len)),
14388 "1" (to), "2" (from), "3" (len)
14389- : "memory", "rcx", "r8", "r9", "r10", "r11");
14390+ : "memory", "rcx", "r8", "r9", "r11");
14391 return ret;
14392 }
14393
14394+static __always_inline __must_check unsigned long
14395+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14396+static __always_inline __must_check unsigned long
14397+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14398 __must_check unsigned long
14399-_copy_to_user(void __user *to, const void *from, unsigned len);
14400-__must_check unsigned long
14401-_copy_from_user(void *to, const void __user *from, unsigned len);
14402-__must_check unsigned long
14403-copy_in_user(void __user *to, const void __user *from, unsigned len);
14404+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14405+
14406+extern void copy_to_user_overflow(void)
14407+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14408+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14409+#else
14410+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14411+#endif
14412+;
14413+
14414+extern void copy_from_user_overflow(void)
14415+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14416+ __compiletime_error("copy_from_user() buffer size is not provably correct")
14417+#else
14418+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
14419+#endif
14420+;
14421
14422 static inline unsigned long __must_check copy_from_user(void *to,
14423 const void __user *from,
14424 unsigned long n)
14425 {
14426- int sz = __compiletime_object_size(to);
14427-
14428 might_fault();
14429- if (likely(sz == -1 || sz >= n))
14430- n = _copy_from_user(to, from, n);
14431-#ifdef CONFIG_DEBUG_VM
14432- else
14433- WARN(1, "Buffer overflow detected!\n");
14434-#endif
14435+
14436+ check_object_size(to, n, false);
14437+ if (access_ok(VERIFY_READ, from, n))
14438+ n = __copy_from_user(to, from, n);
14439+ else if (n < INT_MAX)
14440+ memset(to, 0, n);
14441 return n;
14442 }
14443
14444 static __always_inline __must_check
14445-int copy_to_user(void __user *dst, const void *src, unsigned size)
14446+int copy_to_user(void __user *dst, const void *src, unsigned long size)
14447 {
14448 might_fault();
14449
14450- return _copy_to_user(dst, src, size);
14451+ if (access_ok(VERIFY_WRITE, dst, size))
14452+ size = __copy_to_user(dst, src, size);
14453+ return size;
14454 }
14455
14456 static __always_inline __must_check
14457-int __copy_from_user(void *dst, const void __user *src, unsigned size)
14458+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14459 {
14460- int ret = 0;
14461+ size_t sz = __compiletime_object_size(dst);
14462+ unsigned ret = 0;
14463
14464 might_fault();
14465+
14466+ if (size > INT_MAX)
14467+ return size;
14468+
14469+ check_object_size(dst, size, false);
14470+
14471+#ifdef CONFIG_PAX_MEMORY_UDEREF
14472+ if (!__access_ok(VERIFY_READ, src, size))
14473+ return size;
14474+#endif
14475+
14476+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14477+ copy_from_user_overflow();
14478+ return size;
14479+ }
14480+
14481 if (!__builtin_constant_p(size))
14482- return copy_user_generic(dst, (__force void *)src, size);
14483+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14484 switch (size) {
14485- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14486+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14487 ret, "b", "b", "=q", 1);
14488 return ret;
14489- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14490+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14491 ret, "w", "w", "=r", 2);
14492 return ret;
14493- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14494+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14495 ret, "l", "k", "=r", 4);
14496 return ret;
14497- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14498+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14499 ret, "q", "", "=r", 8);
14500 return ret;
14501 case 10:
14502- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14503+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14504 ret, "q", "", "=r", 10);
14505 if (unlikely(ret))
14506 return ret;
14507 __get_user_asm(*(u16 *)(8 + (char *)dst),
14508- (u16 __user *)(8 + (char __user *)src),
14509+ (const u16 __user *)(8 + (const char __user *)src),
14510 ret, "w", "w", "=r", 2);
14511 return ret;
14512 case 16:
14513- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14514+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14515 ret, "q", "", "=r", 16);
14516 if (unlikely(ret))
14517 return ret;
14518 __get_user_asm(*(u64 *)(8 + (char *)dst),
14519- (u64 __user *)(8 + (char __user *)src),
14520+ (const u64 __user *)(8 + (const char __user *)src),
14521 ret, "q", "", "=r", 8);
14522 return ret;
14523 default:
14524- return copy_user_generic(dst, (__force void *)src, size);
14525+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14526 }
14527 }
14528
14529 static __always_inline __must_check
14530-int __copy_to_user(void __user *dst, const void *src, unsigned size)
14531+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14532 {
14533- int ret = 0;
14534+ size_t sz = __compiletime_object_size(src);
14535+ unsigned ret = 0;
14536
14537 might_fault();
14538+
14539+ if (size > INT_MAX)
14540+ return size;
14541+
14542+ check_object_size(src, size, true);
14543+
14544+#ifdef CONFIG_PAX_MEMORY_UDEREF
14545+ if (!__access_ok(VERIFY_WRITE, dst, size))
14546+ return size;
14547+#endif
14548+
14549+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14550+ copy_to_user_overflow();
14551+ return size;
14552+ }
14553+
14554 if (!__builtin_constant_p(size))
14555- return copy_user_generic((__force void *)dst, src, size);
14556+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14557 switch (size) {
14558- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14559+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14560 ret, "b", "b", "iq", 1);
14561 return ret;
14562- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14563+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14564 ret, "w", "w", "ir", 2);
14565 return ret;
14566- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14567+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14568 ret, "l", "k", "ir", 4);
14569 return ret;
14570- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14571+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14572 ret, "q", "", "er", 8);
14573 return ret;
14574 case 10:
14575- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14576+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14577 ret, "q", "", "er", 10);
14578 if (unlikely(ret))
14579 return ret;
14580 asm("":::"memory");
14581- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14582+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14583 ret, "w", "w", "ir", 2);
14584 return ret;
14585 case 16:
14586- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14587+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14588 ret, "q", "", "er", 16);
14589 if (unlikely(ret))
14590 return ret;
14591 asm("":::"memory");
14592- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14593+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14594 ret, "q", "", "er", 8);
14595 return ret;
14596 default:
14597- return copy_user_generic((__force void *)dst, src, size);
14598+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14599 }
14600 }
14601
14602 static __always_inline __must_check
14603-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14604+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14605 {
14606- int ret = 0;
14607+ unsigned ret = 0;
14608
14609 might_fault();
14610+
14611+ if (size > INT_MAX)
14612+ return size;
14613+
14614+#ifdef CONFIG_PAX_MEMORY_UDEREF
14615+ if (!__access_ok(VERIFY_READ, src, size))
14616+ return size;
14617+ if (!__access_ok(VERIFY_WRITE, dst, size))
14618+ return size;
14619+#endif
14620+
14621 if (!__builtin_constant_p(size))
14622- return copy_user_generic((__force void *)dst,
14623- (__force void *)src, size);
14624+ return copy_user_generic((__force_kernel void *)____m(dst),
14625+ (__force_kernel const void *)____m(src), size);
14626 switch (size) {
14627 case 1: {
14628 u8 tmp;
14629- __get_user_asm(tmp, (u8 __user *)src,
14630+ __get_user_asm(tmp, (const u8 __user *)src,
14631 ret, "b", "b", "=q", 1);
14632 if (likely(!ret))
14633 __put_user_asm(tmp, (u8 __user *)dst,
14634@@ -185,7 +249,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14635 }
14636 case 2: {
14637 u16 tmp;
14638- __get_user_asm(tmp, (u16 __user *)src,
14639+ __get_user_asm(tmp, (const u16 __user *)src,
14640 ret, "w", "w", "=r", 2);
14641 if (likely(!ret))
14642 __put_user_asm(tmp, (u16 __user *)dst,
14643@@ -195,7 +259,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14644
14645 case 4: {
14646 u32 tmp;
14647- __get_user_asm(tmp, (u32 __user *)src,
14648+ __get_user_asm(tmp, (const u32 __user *)src,
14649 ret, "l", "k", "=r", 4);
14650 if (likely(!ret))
14651 __put_user_asm(tmp, (u32 __user *)dst,
14652@@ -204,7 +268,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14653 }
14654 case 8: {
14655 u64 tmp;
14656- __get_user_asm(tmp, (u64 __user *)src,
14657+ __get_user_asm(tmp, (const u64 __user *)src,
14658 ret, "q", "", "=r", 8);
14659 if (likely(!ret))
14660 __put_user_asm(tmp, (u64 __user *)dst,
14661@@ -212,41 +276,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14662 return ret;
14663 }
14664 default:
14665- return copy_user_generic((__force void *)dst,
14666- (__force void *)src, size);
14667+ return copy_user_generic((__force_kernel void *)____m(dst),
14668+ (__force_kernel const void *)____m(src), size);
14669 }
14670 }
14671
14672 static __must_check __always_inline int
14673-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14674+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14675 {
14676- return copy_user_generic(dst, (__force const void *)src, size);
14677+ if (size > INT_MAX)
14678+ return size;
14679+
14680+#ifdef CONFIG_PAX_MEMORY_UDEREF
14681+ if (!__access_ok(VERIFY_READ, src, size))
14682+ return size;
14683+#endif
14684+
14685+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14686 }
14687
14688-static __must_check __always_inline int
14689-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14690+static __must_check __always_inline unsigned long
14691+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14692 {
14693- return copy_user_generic((__force void *)dst, src, size);
14694+ if (size > INT_MAX)
14695+ return size;
14696+
14697+#ifdef CONFIG_PAX_MEMORY_UDEREF
14698+ if (!__access_ok(VERIFY_WRITE, dst, size))
14699+ return size;
14700+#endif
14701+
14702+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14703 }
14704
14705-extern long __copy_user_nocache(void *dst, const void __user *src,
14706- unsigned size, int zerorest);
14707+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14708+ unsigned long size, int zerorest) __size_overflow(3);
14709
14710-static inline int
14711-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14712+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14713 {
14714 might_sleep();
14715+
14716+ if (size > INT_MAX)
14717+ return size;
14718+
14719+#ifdef CONFIG_PAX_MEMORY_UDEREF
14720+ if (!__access_ok(VERIFY_READ, src, size))
14721+ return size;
14722+#endif
14723+
14724 return __copy_user_nocache(dst, src, size, 1);
14725 }
14726
14727-static inline int
14728-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14729- unsigned size)
14730+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14731+ unsigned long size)
14732 {
14733+ if (size > INT_MAX)
14734+ return size;
14735+
14736+#ifdef CONFIG_PAX_MEMORY_UDEREF
14737+ if (!__access_ok(VERIFY_READ, src, size))
14738+ return size;
14739+#endif
14740+
14741 return __copy_user_nocache(dst, src, size, 0);
14742 }
14743
14744-unsigned long
14745-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14746+extern unsigned long
14747+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14748
14749 #endif /* _ASM_X86_UACCESS_64_H */
14750diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14751index 5b238981..77fdd78 100644
14752--- a/arch/x86/include/asm/word-at-a-time.h
14753+++ b/arch/x86/include/asm/word-at-a-time.h
14754@@ -11,7 +11,7 @@
14755 * and shift, for example.
14756 */
14757 struct word_at_a_time {
14758- const unsigned long one_bits, high_bits;
14759+ unsigned long one_bits, high_bits;
14760 };
14761
14762 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14763diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
14764index 5769349..a3d3e2a 100644
14765--- a/arch/x86/include/asm/x86_init.h
14766+++ b/arch/x86/include/asm/x86_init.h
14767@@ -141,7 +141,7 @@ struct x86_init_ops {
14768 struct x86_init_timers timers;
14769 struct x86_init_iommu iommu;
14770 struct x86_init_pci pci;
14771-};
14772+} __no_const;
14773
14774 /**
14775 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
14776@@ -152,7 +152,7 @@ struct x86_cpuinit_ops {
14777 void (*setup_percpu_clockev)(void);
14778 void (*early_percpu_clock_init)(void);
14779 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
14780-};
14781+} __no_const;
14782
14783 /**
14784 * struct x86_platform_ops - platform specific runtime functions
14785@@ -178,7 +178,7 @@ struct x86_platform_ops {
14786 void (*save_sched_clock_state)(void);
14787 void (*restore_sched_clock_state)(void);
14788 void (*apic_post_init)(void);
14789-};
14790+} __no_const;
14791
14792 struct pci_dev;
14793
14794@@ -187,14 +187,14 @@ struct x86_msi_ops {
14795 void (*teardown_msi_irq)(unsigned int irq);
14796 void (*teardown_msi_irqs)(struct pci_dev *dev);
14797 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
14798-};
14799+} __no_const;
14800
14801 struct x86_io_apic_ops {
14802 void (*init) (void);
14803 unsigned int (*read) (unsigned int apic, unsigned int reg);
14804 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
14805 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
14806-};
14807+} __no_const;
14808
14809 extern struct x86_init_ops x86_init;
14810 extern struct x86_cpuinit_ops x86_cpuinit;
14811diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14812index 0415cda..b43d877 100644
14813--- a/arch/x86/include/asm/xsave.h
14814+++ b/arch/x86/include/asm/xsave.h
14815@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14816 return -EFAULT;
14817
14818 __asm__ __volatile__(ASM_STAC "\n"
14819- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14820+ "1:"
14821+ __copyuser_seg
14822+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14823 "2: " ASM_CLAC "\n"
14824 ".section .fixup,\"ax\"\n"
14825 "3: movl $-1,%[err]\n"
14826@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14827 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14828 {
14829 int err;
14830- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14831+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14832 u32 lmask = mask;
14833 u32 hmask = mask >> 32;
14834
14835 __asm__ __volatile__(ASM_STAC "\n"
14836- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14837+ "1:"
14838+ __copyuser_seg
14839+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14840 "2: " ASM_CLAC "\n"
14841 ".section .fixup,\"ax\"\n"
14842 "3: movl $-1,%[err]\n"
14843diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14844index 91ce48f..a48ea05 100644
14845--- a/arch/x86/kernel/Makefile
14846+++ b/arch/x86/kernel/Makefile
14847@@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14848 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14849 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14850 obj-y += probe_roms.o
14851-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14852+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14853 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14854 obj-y += syscall_$(BITS).o
14855 obj-$(CONFIG_X86_64) += vsyscall_64.o
14856diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14857index 11676cf..a8cf3ec 100644
14858--- a/arch/x86/kernel/acpi/sleep.c
14859+++ b/arch/x86/kernel/acpi/sleep.c
14860@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14861 #else /* CONFIG_64BIT */
14862 #ifdef CONFIG_SMP
14863 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14864+
14865+ pax_open_kernel();
14866 early_gdt_descr.address =
14867 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14868+ pax_close_kernel();
14869+
14870 initial_gs = per_cpu_offset(smp_processor_id());
14871 #endif
14872 initial_code = (unsigned long)wakeup_long64;
14873diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14874index 13ab720..95d5442 100644
14875--- a/arch/x86/kernel/acpi/wakeup_32.S
14876+++ b/arch/x86/kernel/acpi/wakeup_32.S
14877@@ -30,13 +30,11 @@ wakeup_pmode_return:
14878 # and restore the stack ... but you need gdt for this to work
14879 movl saved_context_esp, %esp
14880
14881- movl %cs:saved_magic, %eax
14882- cmpl $0x12345678, %eax
14883+ cmpl $0x12345678, saved_magic
14884 jne bogus_magic
14885
14886 # jump to place where we left off
14887- movl saved_eip, %eax
14888- jmp *%eax
14889+ jmp *(saved_eip)
14890
14891 bogus_magic:
14892 jmp bogus_magic
14893diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14894index ef5ccca..bd83949 100644
14895--- a/arch/x86/kernel/alternative.c
14896+++ b/arch/x86/kernel/alternative.c
14897@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14898 */
14899 for (a = start; a < end; a++) {
14900 instr = (u8 *)&a->instr_offset + a->instr_offset;
14901+
14902+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14903+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14904+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14905+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14906+#endif
14907+
14908 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14909 BUG_ON(a->replacementlen > a->instrlen);
14910 BUG_ON(a->instrlen > sizeof(insnbuf));
14911@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14912 for (poff = start; poff < end; poff++) {
14913 u8 *ptr = (u8 *)poff + *poff;
14914
14915+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14916+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14917+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14918+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14919+#endif
14920+
14921 if (!*poff || ptr < text || ptr >= text_end)
14922 continue;
14923 /* turn DS segment override prefix into lock prefix */
14924- if (*ptr == 0x3e)
14925+ if (*ktla_ktva(ptr) == 0x3e)
14926 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14927 }
14928 mutex_unlock(&text_mutex);
14929@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14930 for (poff = start; poff < end; poff++) {
14931 u8 *ptr = (u8 *)poff + *poff;
14932
14933+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14934+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14935+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14936+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14937+#endif
14938+
14939 if (!*poff || ptr < text || ptr >= text_end)
14940 continue;
14941 /* turn lock prefix into DS segment override prefix */
14942- if (*ptr == 0xf0)
14943+ if (*ktla_ktva(ptr) == 0xf0)
14944 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14945 }
14946 mutex_unlock(&text_mutex);
14947@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14948
14949 BUG_ON(p->len > MAX_PATCH_LEN);
14950 /* prep the buffer with the original instructions */
14951- memcpy(insnbuf, p->instr, p->len);
14952+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14953 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14954 (unsigned long)p->instr, p->len);
14955
14956@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14957 if (!uniproc_patched || num_possible_cpus() == 1)
14958 free_init_pages("SMP alternatives",
14959 (unsigned long)__smp_locks,
14960- (unsigned long)__smp_locks_end);
14961+ PAGE_ALIGN((unsigned long)__smp_locks_end));
14962 #endif
14963
14964 apply_paravirt(__parainstructions, __parainstructions_end);
14965@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14966 * instructions. And on the local CPU you need to be protected again NMI or MCE
14967 * handlers seeing an inconsistent instruction while you patch.
14968 */
14969-void *__init_or_module text_poke_early(void *addr, const void *opcode,
14970+void *__kprobes text_poke_early(void *addr, const void *opcode,
14971 size_t len)
14972 {
14973 unsigned long flags;
14974 local_irq_save(flags);
14975- memcpy(addr, opcode, len);
14976+
14977+ pax_open_kernel();
14978+ memcpy(ktla_ktva(addr), opcode, len);
14979 sync_core();
14980+ pax_close_kernel();
14981+
14982 local_irq_restore(flags);
14983 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14984 that causes hangs on some VIA CPUs. */
14985@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14986 */
14987 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14988 {
14989- unsigned long flags;
14990- char *vaddr;
14991+ unsigned char *vaddr = ktla_ktva(addr);
14992 struct page *pages[2];
14993- int i;
14994+ size_t i;
14995
14996 if (!core_kernel_text((unsigned long)addr)) {
14997- pages[0] = vmalloc_to_page(addr);
14998- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14999+ pages[0] = vmalloc_to_page(vaddr);
15000+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
15001 } else {
15002- pages[0] = virt_to_page(addr);
15003+ pages[0] = virt_to_page(vaddr);
15004 WARN_ON(!PageReserved(pages[0]));
15005- pages[1] = virt_to_page(addr + PAGE_SIZE);
15006+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
15007 }
15008 BUG_ON(!pages[0]);
15009- local_irq_save(flags);
15010- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
15011- if (pages[1])
15012- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
15013- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
15014- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
15015- clear_fixmap(FIX_TEXT_POKE0);
15016- if (pages[1])
15017- clear_fixmap(FIX_TEXT_POKE1);
15018- local_flush_tlb();
15019- sync_core();
15020- /* Could also do a CLFLUSH here to speed up CPU recovery; but
15021- that causes hangs on some VIA CPUs. */
15022+ text_poke_early(addr, opcode, len);
15023 for (i = 0; i < len; i++)
15024- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
15025- local_irq_restore(flags);
15026+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
15027 return addr;
15028 }
15029
15030diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
15031index b17416e..5ed0f3e 100644
15032--- a/arch/x86/kernel/apic/apic.c
15033+++ b/arch/x86/kernel/apic/apic.c
15034@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
15035 /*
15036 * Debug level, exported for io_apic.c
15037 */
15038-unsigned int apic_verbosity;
15039+int apic_verbosity;
15040
15041 int pic_mode;
15042
15043@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
15044 apic_write(APIC_ESR, 0);
15045 v1 = apic_read(APIC_ESR);
15046 ack_APIC_irq();
15047- atomic_inc(&irq_err_count);
15048+ atomic_inc_unchecked(&irq_err_count);
15049
15050 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
15051 smp_processor_id(), v0 , v1);
15052diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
15053index 00c77cf..2dc6a2d 100644
15054--- a/arch/x86/kernel/apic/apic_flat_64.c
15055+++ b/arch/x86/kernel/apic/apic_flat_64.c
15056@@ -157,7 +157,7 @@ static int flat_probe(void)
15057 return 1;
15058 }
15059
15060-static struct apic apic_flat = {
15061+static struct apic apic_flat __read_only = {
15062 .name = "flat",
15063 .probe = flat_probe,
15064 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
15065@@ -271,7 +271,7 @@ static int physflat_probe(void)
15066 return 0;
15067 }
15068
15069-static struct apic apic_physflat = {
15070+static struct apic apic_physflat __read_only = {
15071
15072 .name = "physical flat",
15073 .probe = physflat_probe,
15074diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
15075index d50e364..543bee3 100644
15076--- a/arch/x86/kernel/apic/bigsmp_32.c
15077+++ b/arch/x86/kernel/apic/bigsmp_32.c
15078@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
15079 return dmi_bigsmp;
15080 }
15081
15082-static struct apic apic_bigsmp = {
15083+static struct apic apic_bigsmp __read_only = {
15084
15085 .name = "bigsmp",
15086 .probe = probe_bigsmp,
15087diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
15088index 0874799..24a836e 100644
15089--- a/arch/x86/kernel/apic/es7000_32.c
15090+++ b/arch/x86/kernel/apic/es7000_32.c
15091@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
15092 return ret && es7000_apic_is_cluster();
15093 }
15094
15095-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
15096-static struct apic __refdata apic_es7000_cluster = {
15097+static struct apic apic_es7000_cluster __read_only = {
15098
15099 .name = "es7000",
15100 .probe = probe_es7000,
15101@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
15102 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
15103 };
15104
15105-static struct apic __refdata apic_es7000 = {
15106+static struct apic __refdata apic_es7000 __read_only = {
15107
15108 .name = "es7000",
15109 .probe = probe_es7000,
15110diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
15111index 1817fa9..7bff097 100644
15112--- a/arch/x86/kernel/apic/io_apic.c
15113+++ b/arch/x86/kernel/apic/io_apic.c
15114@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
15115 }
15116 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
15117
15118-void lock_vector_lock(void)
15119+void lock_vector_lock(void) __acquires(vector_lock)
15120 {
15121 /* Used to the online set of cpus does not change
15122 * during assign_irq_vector.
15123@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
15124 raw_spin_lock(&vector_lock);
15125 }
15126
15127-void unlock_vector_lock(void)
15128+void unlock_vector_lock(void) __releases(vector_lock)
15129 {
15130 raw_spin_unlock(&vector_lock);
15131 }
15132@@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
15133 ack_APIC_irq();
15134 }
15135
15136-atomic_t irq_mis_count;
15137+atomic_unchecked_t irq_mis_count;
15138
15139 #ifdef CONFIG_GENERIC_PENDING_IRQ
15140 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
15141@@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
15142 * at the cpu.
15143 */
15144 if (!(v & (1 << (i & 0x1f)))) {
15145- atomic_inc(&irq_mis_count);
15146+ atomic_inc_unchecked(&irq_mis_count);
15147
15148 eoi_ioapic_irq(irq, cfg);
15149 }
15150diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
15151index d661ee9..791fd33 100644
15152--- a/arch/x86/kernel/apic/numaq_32.c
15153+++ b/arch/x86/kernel/apic/numaq_32.c
15154@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
15155 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
15156 }
15157
15158-/* Use __refdata to keep false positive warning calm. */
15159-static struct apic __refdata apic_numaq = {
15160+static struct apic apic_numaq __read_only = {
15161
15162 .name = "NUMAQ",
15163 .probe = probe_numaq,
15164diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
15165index eb35ef9..f184a21 100644
15166--- a/arch/x86/kernel/apic/probe_32.c
15167+++ b/arch/x86/kernel/apic/probe_32.c
15168@@ -72,7 +72,7 @@ static int probe_default(void)
15169 return 1;
15170 }
15171
15172-static struct apic apic_default = {
15173+static struct apic apic_default __read_only = {
15174
15175 .name = "default",
15176 .probe = probe_default,
15177diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
15178index 77c95c0..434f8a4 100644
15179--- a/arch/x86/kernel/apic/summit_32.c
15180+++ b/arch/x86/kernel/apic/summit_32.c
15181@@ -486,7 +486,7 @@ void setup_summit(void)
15182 }
15183 #endif
15184
15185-static struct apic apic_summit = {
15186+static struct apic apic_summit __read_only = {
15187
15188 .name = "summit",
15189 .probe = probe_summit,
15190diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
15191index c88baa4..a89def0 100644
15192--- a/arch/x86/kernel/apic/x2apic_cluster.c
15193+++ b/arch/x86/kernel/apic/x2apic_cluster.c
15194@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
15195 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
15196 }
15197
15198-static struct apic apic_x2apic_cluster = {
15199+static struct apic apic_x2apic_cluster __read_only = {
15200
15201 .name = "cluster x2apic",
15202 .probe = x2apic_cluster_probe,
15203diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
15204index e03a1e1..0e41d28 100644
15205--- a/arch/x86/kernel/apic/x2apic_phys.c
15206+++ b/arch/x86/kernel/apic/x2apic_phys.c
15207@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
15208 return apic == &apic_x2apic_phys;
15209 }
15210
15211-static struct apic apic_x2apic_phys = {
15212+static struct apic apic_x2apic_phys __read_only = {
15213
15214 .name = "physical x2apic",
15215 .probe = x2apic_phys_probe,
15216diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
15217index 8cfade9..b9d04fc 100644
15218--- a/arch/x86/kernel/apic/x2apic_uv_x.c
15219+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
15220@@ -333,7 +333,7 @@ static int uv_probe(void)
15221 return apic == &apic_x2apic_uv_x;
15222 }
15223
15224-static struct apic __refdata apic_x2apic_uv_x = {
15225+static struct apic apic_x2apic_uv_x __read_only = {
15226
15227 .name = "UV large system",
15228 .probe = uv_probe,
15229diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
15230index d65464e..1035d31 100644
15231--- a/arch/x86/kernel/apm_32.c
15232+++ b/arch/x86/kernel/apm_32.c
15233@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15234 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15235 * even though they are called in protected mode.
15236 */
15237-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15238+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15239 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15240
15241 static const char driver_version[] = "1.16ac"; /* no spaces */
15242@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15243 BUG_ON(cpu != 0);
15244 gdt = get_cpu_gdt_table(cpu);
15245 save_desc_40 = gdt[0x40 / 8];
15246+
15247+ pax_open_kernel();
15248 gdt[0x40 / 8] = bad_bios_desc;
15249+ pax_close_kernel();
15250
15251 apm_irq_save(flags);
15252 APM_DO_SAVE_SEGS;
15253@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15254 &call->esi);
15255 APM_DO_RESTORE_SEGS;
15256 apm_irq_restore(flags);
15257+
15258+ pax_open_kernel();
15259 gdt[0x40 / 8] = save_desc_40;
15260+ pax_close_kernel();
15261+
15262 put_cpu();
15263
15264 return call->eax & 0xff;
15265@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15266 BUG_ON(cpu != 0);
15267 gdt = get_cpu_gdt_table(cpu);
15268 save_desc_40 = gdt[0x40 / 8];
15269+
15270+ pax_open_kernel();
15271 gdt[0x40 / 8] = bad_bios_desc;
15272+ pax_close_kernel();
15273
15274 apm_irq_save(flags);
15275 APM_DO_SAVE_SEGS;
15276@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15277 &call->eax);
15278 APM_DO_RESTORE_SEGS;
15279 apm_irq_restore(flags);
15280+
15281+ pax_open_kernel();
15282 gdt[0x40 / 8] = save_desc_40;
15283+ pax_close_kernel();
15284+
15285 put_cpu();
15286 return error;
15287 }
15288@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15289 * code to that CPU.
15290 */
15291 gdt = get_cpu_gdt_table(0);
15292+
15293+ pax_open_kernel();
15294 set_desc_base(&gdt[APM_CS >> 3],
15295 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15296 set_desc_base(&gdt[APM_CS_16 >> 3],
15297 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15298 set_desc_base(&gdt[APM_DS >> 3],
15299 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15300+ pax_close_kernel();
15301
15302 proc_create("apm", 0, NULL, &apm_file_ops);
15303
15304diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15305index 2861082..6d4718e 100644
15306--- a/arch/x86/kernel/asm-offsets.c
15307+++ b/arch/x86/kernel/asm-offsets.c
15308@@ -33,6 +33,8 @@ void common(void) {
15309 OFFSET(TI_status, thread_info, status);
15310 OFFSET(TI_addr_limit, thread_info, addr_limit);
15311 OFFSET(TI_preempt_count, thread_info, preempt_count);
15312+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15313+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15314
15315 BLANK();
15316 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15317@@ -53,8 +55,26 @@ void common(void) {
15318 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15319 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15320 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15321+
15322+#ifdef CONFIG_PAX_KERNEXEC
15323+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15324 #endif
15325
15326+#ifdef CONFIG_PAX_MEMORY_UDEREF
15327+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15328+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15329+#ifdef CONFIG_X86_64
15330+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15331+#endif
15332+#endif
15333+
15334+#endif
15335+
15336+ BLANK();
15337+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15338+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15339+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15340+
15341 #ifdef CONFIG_XEN
15342 BLANK();
15343 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15344diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15345index 1b4754f..fbb4227 100644
15346--- a/arch/x86/kernel/asm-offsets_64.c
15347+++ b/arch/x86/kernel/asm-offsets_64.c
15348@@ -76,6 +76,7 @@ int main(void)
15349 BLANK();
15350 #undef ENTRY
15351
15352+ DEFINE(TSS_size, sizeof(struct tss_struct));
15353 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15354 BLANK();
15355
15356diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15357index a0e067d..9c7db16 100644
15358--- a/arch/x86/kernel/cpu/Makefile
15359+++ b/arch/x86/kernel/cpu/Makefile
15360@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15361 CFLAGS_REMOVE_perf_event.o = -pg
15362 endif
15363
15364-# Make sure load_percpu_segment has no stackprotector
15365-nostackp := $(call cc-option, -fno-stack-protector)
15366-CFLAGS_common.o := $(nostackp)
15367-
15368 obj-y := intel_cacheinfo.o scattered.o topology.o
15369 obj-y += proc.o capflags.o powerflags.o common.o
15370 obj-y += vmware.o hypervisor.o mshyperv.o
15371diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15372index 1b7d165..b9e2627 100644
15373--- a/arch/x86/kernel/cpu/amd.c
15374+++ b/arch/x86/kernel/cpu/amd.c
15375@@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15376 unsigned int size)
15377 {
15378 /* AMD errata T13 (order #21922) */
15379- if ((c->x86 == 6)) {
15380+ if (c->x86 == 6) {
15381 /* Duron Rev A0 */
15382 if (c->x86_model == 3 && c->x86_mask == 0)
15383 size = 64;
15384diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15385index 7505f7b..d59dac0 100644
15386--- a/arch/x86/kernel/cpu/common.c
15387+++ b/arch/x86/kernel/cpu/common.c
15388@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15389
15390 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15391
15392-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15393-#ifdef CONFIG_X86_64
15394- /*
15395- * We need valid kernel segments for data and code in long mode too
15396- * IRET will check the segment types kkeil 2000/10/28
15397- * Also sysret mandates a special GDT layout
15398- *
15399- * TLS descriptors are currently at a different place compared to i386.
15400- * Hopefully nobody expects them at a fixed place (Wine?)
15401- */
15402- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15403- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15404- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15405- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15406- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15407- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15408-#else
15409- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15410- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15411- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15412- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15413- /*
15414- * Segments used for calling PnP BIOS have byte granularity.
15415- * They code segments and data segments have fixed 64k limits,
15416- * the transfer segment sizes are set at run time.
15417- */
15418- /* 32-bit code */
15419- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15420- /* 16-bit code */
15421- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15422- /* 16-bit data */
15423- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15424- /* 16-bit data */
15425- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15426- /* 16-bit data */
15427- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15428- /*
15429- * The APM segments have byte granularity and their bases
15430- * are set at run time. All have 64k limits.
15431- */
15432- /* 32-bit code */
15433- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15434- /* 16-bit code */
15435- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15436- /* data */
15437- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15438-
15439- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15440- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15441- GDT_STACK_CANARY_INIT
15442-#endif
15443-} };
15444-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15445-
15446 static int __init x86_xsave_setup(char *s)
15447 {
15448 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15449@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15450 {
15451 struct desc_ptr gdt_descr;
15452
15453- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15454+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15455 gdt_descr.size = GDT_SIZE - 1;
15456 load_gdt(&gdt_descr);
15457 /* Reload the per-cpu base */
15458@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15459 /* Filter out anything that depends on CPUID levels we don't have */
15460 filter_cpuid_features(c, true);
15461
15462+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15463+ setup_clear_cpu_cap(X86_FEATURE_SEP);
15464+#endif
15465+
15466 /* If the model name is still unset, do table lookup. */
15467 if (!c->x86_model_id[0]) {
15468 const char *p;
15469@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15470 }
15471 __setup("clearcpuid=", setup_disablecpuid);
15472
15473+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15474+EXPORT_PER_CPU_SYMBOL(current_tinfo);
15475+
15476 #ifdef CONFIG_X86_64
15477 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15478-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15479- (unsigned long) nmi_idt_table };
15480+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15481
15482 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15483 irq_stack_union) __aligned(PAGE_SIZE);
15484@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15485 EXPORT_PER_CPU_SYMBOL(current_task);
15486
15487 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15488- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15489+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15490 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15491
15492 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15493@@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15494 {
15495 memset(regs, 0, sizeof(struct pt_regs));
15496 regs->fs = __KERNEL_PERCPU;
15497- regs->gs = __KERNEL_STACK_CANARY;
15498+ savesegment(gs, regs->gs);
15499
15500 return regs;
15501 }
15502@@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15503 int i;
15504
15505 cpu = stack_smp_processor_id();
15506- t = &per_cpu(init_tss, cpu);
15507+ t = init_tss + cpu;
15508 oist = &per_cpu(orig_ist, cpu);
15509
15510 #ifdef CONFIG_NUMA
15511@@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15512 switch_to_new_gdt(cpu);
15513 loadsegment(fs, 0);
15514
15515- load_idt((const struct desc_ptr *)&idt_descr);
15516+ load_idt(&idt_descr);
15517
15518 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15519 syscall_init();
15520@@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15521 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15522 barrier();
15523
15524- x86_configure_nx();
15525 if (cpu != 0)
15526 enable_x2apic();
15527
15528@@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15529 {
15530 int cpu = smp_processor_id();
15531 struct task_struct *curr = current;
15532- struct tss_struct *t = &per_cpu(init_tss, cpu);
15533+ struct tss_struct *t = init_tss + cpu;
15534 struct thread_struct *thread = &curr->thread;
15535
15536 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15537diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15538index 198e019..867575e 100644
15539--- a/arch/x86/kernel/cpu/intel.c
15540+++ b/arch/x86/kernel/cpu/intel.c
15541@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15542 * Update the IDT descriptor and reload the IDT so that
15543 * it uses the read-only mapped virtual address.
15544 */
15545- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15546+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15547 load_idt(&idt_descr);
15548 }
15549 #endif
15550diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15551index 93c5451..3887433 100644
15552--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15553+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15554@@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15555 };
15556
15557 #ifdef CONFIG_AMD_NB
15558+static struct attribute *default_attrs_amd_nb[] = {
15559+ &type.attr,
15560+ &level.attr,
15561+ &coherency_line_size.attr,
15562+ &physical_line_partition.attr,
15563+ &ways_of_associativity.attr,
15564+ &number_of_sets.attr,
15565+ &size.attr,
15566+ &shared_cpu_map.attr,
15567+ &shared_cpu_list.attr,
15568+ NULL,
15569+ NULL,
15570+ NULL,
15571+ NULL
15572+};
15573+
15574 static struct attribute ** __cpuinit amd_l3_attrs(void)
15575 {
15576 static struct attribute **attrs;
15577@@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15578
15579 n = ARRAY_SIZE(default_attrs);
15580
15581- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15582- n += 2;
15583-
15584- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15585- n += 1;
15586-
15587- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15588- if (attrs == NULL)
15589- return attrs = default_attrs;
15590-
15591- for (n = 0; default_attrs[n]; n++)
15592- attrs[n] = default_attrs[n];
15593+ attrs = default_attrs_amd_nb;
15594
15595 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15596 attrs[n++] = &cache_disable_0.attr;
15597@@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15598 .default_attrs = default_attrs,
15599 };
15600
15601+#ifdef CONFIG_AMD_NB
15602+static struct kobj_type ktype_cache_amd_nb = {
15603+ .sysfs_ops = &sysfs_ops,
15604+ .default_attrs = default_attrs_amd_nb,
15605+};
15606+#endif
15607+
15608 static struct kobj_type ktype_percpu_entry = {
15609 .sysfs_ops = &sysfs_ops,
15610 };
15611@@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15612 return retval;
15613 }
15614
15615+#ifdef CONFIG_AMD_NB
15616+ amd_l3_attrs();
15617+#endif
15618+
15619 for (i = 0; i < num_cache_leaves; i++) {
15620+ struct kobj_type *ktype;
15621+
15622 this_object = INDEX_KOBJECT_PTR(cpu, i);
15623 this_object->cpu = cpu;
15624 this_object->index = i;
15625
15626 this_leaf = CPUID4_INFO_IDX(cpu, i);
15627
15628- ktype_cache.default_attrs = default_attrs;
15629+ ktype = &ktype_cache;
15630 #ifdef CONFIG_AMD_NB
15631 if (this_leaf->base.nb)
15632- ktype_cache.default_attrs = amd_l3_attrs();
15633+ ktype = &ktype_cache_amd_nb;
15634 #endif
15635 retval = kobject_init_and_add(&(this_object->kobj),
15636- &ktype_cache,
15637+ ktype,
15638 per_cpu(ici_cache_kobject, cpu),
15639 "index%1lu", i);
15640 if (unlikely(retval)) {
15641diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15642index 46cbf86..55c7292 100644
15643--- a/arch/x86/kernel/cpu/mcheck/mce.c
15644+++ b/arch/x86/kernel/cpu/mcheck/mce.c
15645@@ -45,6 +45,7 @@
15646 #include <asm/processor.h>
15647 #include <asm/mce.h>
15648 #include <asm/msr.h>
15649+#include <asm/local.h>
15650
15651 #include "mce-internal.h"
15652
15653@@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15654 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15655 m->cs, m->ip);
15656
15657- if (m->cs == __KERNEL_CS)
15658+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15659 print_symbol("{%s}", m->ip);
15660 pr_cont("\n");
15661 }
15662@@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15663
15664 #define PANIC_TIMEOUT 5 /* 5 seconds */
15665
15666-static atomic_t mce_paniced;
15667+static atomic_unchecked_t mce_paniced;
15668
15669 static int fake_panic;
15670-static atomic_t mce_fake_paniced;
15671+static atomic_unchecked_t mce_fake_paniced;
15672
15673 /* Panic in progress. Enable interrupts and wait for final IPI */
15674 static void wait_for_panic(void)
15675@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15676 /*
15677 * Make sure only one CPU runs in machine check panic
15678 */
15679- if (atomic_inc_return(&mce_paniced) > 1)
15680+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15681 wait_for_panic();
15682 barrier();
15683
15684@@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15685 console_verbose();
15686 } else {
15687 /* Don't log too much for fake panic */
15688- if (atomic_inc_return(&mce_fake_paniced) > 1)
15689+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15690 return;
15691 }
15692 /* First print corrected ones that are still unlogged */
15693@@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15694 * might have been modified by someone else.
15695 */
15696 rmb();
15697- if (atomic_read(&mce_paniced))
15698+ if (atomic_read_unchecked(&mce_paniced))
15699 wait_for_panic();
15700 if (!monarch_timeout)
15701 goto out;
15702@@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15703 }
15704
15705 /* Call the installed machine check handler for this CPU setup. */
15706-void (*machine_check_vector)(struct pt_regs *, long error_code) =
15707+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15708 unexpected_machine_check;
15709
15710 /*
15711@@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15712 return;
15713 }
15714
15715+ pax_open_kernel();
15716 machine_check_vector = do_machine_check;
15717+ pax_close_kernel();
15718
15719 __mcheck_cpu_init_generic();
15720 __mcheck_cpu_init_vendor(c);
15721@@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15722 */
15723
15724 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15725-static int mce_chrdev_open_count; /* #times opened */
15726+static local_t mce_chrdev_open_count; /* #times opened */
15727 static int mce_chrdev_open_exclu; /* already open exclusive? */
15728
15729 static int mce_chrdev_open(struct inode *inode, struct file *file)
15730@@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15731 spin_lock(&mce_chrdev_state_lock);
15732
15733 if (mce_chrdev_open_exclu ||
15734- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15735+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15736 spin_unlock(&mce_chrdev_state_lock);
15737
15738 return -EBUSY;
15739@@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15740
15741 if (file->f_flags & O_EXCL)
15742 mce_chrdev_open_exclu = 1;
15743- mce_chrdev_open_count++;
15744+ local_inc(&mce_chrdev_open_count);
15745
15746 spin_unlock(&mce_chrdev_state_lock);
15747
15748@@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15749 {
15750 spin_lock(&mce_chrdev_state_lock);
15751
15752- mce_chrdev_open_count--;
15753+ local_dec(&mce_chrdev_open_count);
15754 mce_chrdev_open_exclu = 0;
15755
15756 spin_unlock(&mce_chrdev_state_lock);
15757@@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15758 return NOTIFY_OK;
15759 }
15760
15761-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15762+static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15763 .notifier_call = mce_cpu_callback,
15764 };
15765
15766@@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15767 static void mce_reset(void)
15768 {
15769 cpu_missing = 0;
15770- atomic_set(&mce_fake_paniced, 0);
15771+ atomic_set_unchecked(&mce_fake_paniced, 0);
15772 atomic_set(&mce_executing, 0);
15773 atomic_set(&mce_callin, 0);
15774 atomic_set(&global_nwo, 0);
15775diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15776index 2d5454c..51987eb 100644
15777--- a/arch/x86/kernel/cpu/mcheck/p5.c
15778+++ b/arch/x86/kernel/cpu/mcheck/p5.c
15779@@ -11,6 +11,7 @@
15780 #include <asm/processor.h>
15781 #include <asm/mce.h>
15782 #include <asm/msr.h>
15783+#include <asm/pgtable.h>
15784
15785 /* By default disabled */
15786 int mce_p5_enabled __read_mostly;
15787@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15788 if (!cpu_has(c, X86_FEATURE_MCE))
15789 return;
15790
15791+ pax_open_kernel();
15792 machine_check_vector = pentium_machine_check;
15793+ pax_close_kernel();
15794 /* Make sure the vector pointer is visible before we enable MCEs: */
15795 wmb();
15796
15797diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15798index 2d7998f..17c9de1 100644
15799--- a/arch/x86/kernel/cpu/mcheck/winchip.c
15800+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15801@@ -10,6 +10,7 @@
15802 #include <asm/processor.h>
15803 #include <asm/mce.h>
15804 #include <asm/msr.h>
15805+#include <asm/pgtable.h>
15806
15807 /* Machine check handler for WinChip C6: */
15808 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15809@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15810 {
15811 u32 lo, hi;
15812
15813+ pax_open_kernel();
15814 machine_check_vector = winchip_machine_check;
15815+ pax_close_kernel();
15816 /* Make sure the vector pointer is visible before we enable MCEs: */
15817 wmb();
15818
15819diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15820index 6b96110..0da73eb 100644
15821--- a/arch/x86/kernel/cpu/mtrr/main.c
15822+++ b/arch/x86/kernel/cpu/mtrr/main.c
15823@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15824 u64 size_or_mask, size_and_mask;
15825 static bool mtrr_aps_delayed_init;
15826
15827-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15828+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15829
15830 const struct mtrr_ops *mtrr_if;
15831
15832diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15833index df5e41f..816c719 100644
15834--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15835+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15836@@ -25,7 +25,7 @@ struct mtrr_ops {
15837 int (*validate_add_page)(unsigned long base, unsigned long size,
15838 unsigned int type);
15839 int (*have_wrcomb)(void);
15840-};
15841+} __do_const;
15842
15843 extern int generic_get_free_region(unsigned long base, unsigned long size,
15844 int replace_reg);
15845diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15846index d18b2b8..d3b834c 100644
15847--- a/arch/x86/kernel/cpu/perf_event.c
15848+++ b/arch/x86/kernel/cpu/perf_event.c
15849@@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15850 if (idx > GDT_ENTRIES)
15851 return 0;
15852
15853- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15854+ desc = get_cpu_gdt_table(smp_processor_id());
15855 }
15856
15857 return get_desc_base(desc + idx);
15858@@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15859 break;
15860
15861 perf_callchain_store(entry, frame.return_address);
15862- fp = frame.next_frame;
15863+ fp = (const void __force_user *)frame.next_frame;
15864 }
15865 }
15866
15867diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15868index 324bb52..1a93d85 100644
15869--- a/arch/x86/kernel/cpu/perf_event_intel.c
15870+++ b/arch/x86/kernel/cpu/perf_event_intel.c
15871@@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15872 * v2 and above have a perf capabilities MSR
15873 */
15874 if (version > 1) {
15875- u64 capabilities;
15876+ u64 capabilities = x86_pmu.intel_cap.capabilities;
15877
15878- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15879- x86_pmu.intel_cap.capabilities = capabilities;
15880+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15881+ x86_pmu.intel_cap.capabilities = capabilities;
15882 }
15883
15884 intel_ds_init();
15885diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15886index 13ad899..f642b9a 100644
15887--- a/arch/x86/kernel/crash.c
15888+++ b/arch/x86/kernel/crash.c
15889@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15890 {
15891 #ifdef CONFIG_X86_32
15892 struct pt_regs fixed_regs;
15893-#endif
15894
15895-#ifdef CONFIG_X86_32
15896- if (!user_mode_vm(regs)) {
15897+ if (!user_mode(regs)) {
15898 crash_fixup_ss_esp(&fixed_regs, regs);
15899 regs = &fixed_regs;
15900 }
15901diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15902index 37250fe..bf2ec74 100644
15903--- a/arch/x86/kernel/doublefault_32.c
15904+++ b/arch/x86/kernel/doublefault_32.c
15905@@ -11,7 +11,7 @@
15906
15907 #define DOUBLEFAULT_STACKSIZE (1024)
15908 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15909-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15910+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15911
15912 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15913
15914@@ -21,7 +21,7 @@ static void doublefault_fn(void)
15915 unsigned long gdt, tss;
15916
15917 store_gdt(&gdt_desc);
15918- gdt = gdt_desc.address;
15919+ gdt = (unsigned long)gdt_desc.address;
15920
15921 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15922
15923@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15924 /* 0x2 bit is always set */
15925 .flags = X86_EFLAGS_SF | 0x2,
15926 .sp = STACK_START,
15927- .es = __USER_DS,
15928+ .es = __KERNEL_DS,
15929 .cs = __KERNEL_CS,
15930 .ss = __KERNEL_DS,
15931- .ds = __USER_DS,
15932+ .ds = __KERNEL_DS,
15933 .fs = __KERNEL_PERCPU,
15934
15935 .__cr3 = __pa_nodebug(swapper_pg_dir),
15936diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15937index ae42418b..787c16b 100644
15938--- a/arch/x86/kernel/dumpstack.c
15939+++ b/arch/x86/kernel/dumpstack.c
15940@@ -2,6 +2,9 @@
15941 * Copyright (C) 1991, 1992 Linus Torvalds
15942 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15943 */
15944+#ifdef CONFIG_GRKERNSEC_HIDESYM
15945+#define __INCLUDED_BY_HIDESYM 1
15946+#endif
15947 #include <linux/kallsyms.h>
15948 #include <linux/kprobes.h>
15949 #include <linux/uaccess.h>
15950@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15951 static void
15952 print_ftrace_graph_addr(unsigned long addr, void *data,
15953 const struct stacktrace_ops *ops,
15954- struct thread_info *tinfo, int *graph)
15955+ struct task_struct *task, int *graph)
15956 {
15957- struct task_struct *task;
15958 unsigned long ret_addr;
15959 int index;
15960
15961 if (addr != (unsigned long)return_to_handler)
15962 return;
15963
15964- task = tinfo->task;
15965 index = task->curr_ret_stack;
15966
15967 if (!task->ret_stack || index < *graph)
15968@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15969 static inline void
15970 print_ftrace_graph_addr(unsigned long addr, void *data,
15971 const struct stacktrace_ops *ops,
15972- struct thread_info *tinfo, int *graph)
15973+ struct task_struct *task, int *graph)
15974 { }
15975 #endif
15976
15977@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15978 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15979 */
15980
15981-static inline int valid_stack_ptr(struct thread_info *tinfo,
15982- void *p, unsigned int size, void *end)
15983+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15984 {
15985- void *t = tinfo;
15986 if (end) {
15987 if (p < end && p >= (end-THREAD_SIZE))
15988 return 1;
15989@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15990 }
15991
15992 unsigned long
15993-print_context_stack(struct thread_info *tinfo,
15994+print_context_stack(struct task_struct *task, void *stack_start,
15995 unsigned long *stack, unsigned long bp,
15996 const struct stacktrace_ops *ops, void *data,
15997 unsigned long *end, int *graph)
15998 {
15999 struct stack_frame *frame = (struct stack_frame *)bp;
16000
16001- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
16002+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
16003 unsigned long addr;
16004
16005 addr = *stack;
16006@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
16007 } else {
16008 ops->address(data, addr, 0);
16009 }
16010- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
16011+ print_ftrace_graph_addr(addr, data, ops, task, graph);
16012 }
16013 stack++;
16014 }
16015@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
16016 EXPORT_SYMBOL_GPL(print_context_stack);
16017
16018 unsigned long
16019-print_context_stack_bp(struct thread_info *tinfo,
16020+print_context_stack_bp(struct task_struct *task, void *stack_start,
16021 unsigned long *stack, unsigned long bp,
16022 const struct stacktrace_ops *ops, void *data,
16023 unsigned long *end, int *graph)
16024@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
16025 struct stack_frame *frame = (struct stack_frame *)bp;
16026 unsigned long *ret_addr = &frame->return_address;
16027
16028- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
16029+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
16030 unsigned long addr = *ret_addr;
16031
16032 if (!__kernel_text_address(addr))
16033@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
16034 ops->address(data, addr, 1);
16035 frame = frame->next_frame;
16036 ret_addr = &frame->return_address;
16037- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
16038+ print_ftrace_graph_addr(addr, data, ops, task, graph);
16039 }
16040
16041 return (unsigned long)frame;
16042@@ -189,7 +188,7 @@ void dump_stack(void)
16043
16044 bp = stack_frame(current, NULL);
16045 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
16046- current->pid, current->comm, print_tainted(),
16047+ task_pid_nr(current), current->comm, print_tainted(),
16048 init_utsname()->release,
16049 (int)strcspn(init_utsname()->version, " "),
16050 init_utsname()->version);
16051@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
16052 }
16053 EXPORT_SYMBOL_GPL(oops_begin);
16054
16055+extern void gr_handle_kernel_exploit(void);
16056+
16057 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
16058 {
16059 if (regs && kexec_should_crash(current))
16060@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
16061 panic("Fatal exception in interrupt");
16062 if (panic_on_oops)
16063 panic("Fatal exception");
16064- do_exit(signr);
16065+
16066+ gr_handle_kernel_exploit();
16067+
16068+ do_group_exit(signr);
16069 }
16070
16071 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
16072@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
16073 print_modules();
16074 show_regs(regs);
16075 #ifdef CONFIG_X86_32
16076- if (user_mode_vm(regs)) {
16077+ if (user_mode(regs)) {
16078 sp = regs->sp;
16079 ss = regs->ss & 0xffff;
16080 } else {
16081@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
16082 unsigned long flags = oops_begin();
16083 int sig = SIGSEGV;
16084
16085- if (!user_mode_vm(regs))
16086+ if (!user_mode(regs))
16087 report_bug(regs->ip, regs);
16088
16089 if (__die(str, regs, err))
16090diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
16091index 1038a41..db2c12b 100644
16092--- a/arch/x86/kernel/dumpstack_32.c
16093+++ b/arch/x86/kernel/dumpstack_32.c
16094@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16095 bp = stack_frame(task, regs);
16096
16097 for (;;) {
16098- struct thread_info *context;
16099+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16100
16101- context = (struct thread_info *)
16102- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
16103- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
16104+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16105
16106- stack = (unsigned long *)context->previous_esp;
16107- if (!stack)
16108+ if (stack_start == task_stack_page(task))
16109 break;
16110+ stack = *(unsigned long **)stack_start;
16111 if (ops->stack(data, "IRQ") < 0)
16112 break;
16113 touch_nmi_watchdog();
16114@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
16115 {
16116 int i;
16117
16118- __show_regs(regs, !user_mode_vm(regs));
16119+ __show_regs(regs, !user_mode(regs));
16120
16121 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
16122 TASK_COMM_LEN, current->comm, task_pid_nr(current),
16123@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
16124 * When in-kernel, we also print out the stack and code at the
16125 * time of the fault..
16126 */
16127- if (!user_mode_vm(regs)) {
16128+ if (!user_mode(regs)) {
16129 unsigned int code_prologue = code_bytes * 43 / 64;
16130 unsigned int code_len = code_bytes;
16131 unsigned char c;
16132 u8 *ip;
16133+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
16134
16135 pr_emerg("Stack:\n");
16136 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
16137
16138 pr_emerg("Code:");
16139
16140- ip = (u8 *)regs->ip - code_prologue;
16141+ ip = (u8 *)regs->ip - code_prologue + cs_base;
16142 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
16143 /* try starting at IP */
16144- ip = (u8 *)regs->ip;
16145+ ip = (u8 *)regs->ip + cs_base;
16146 code_len = code_len - code_prologue + 1;
16147 }
16148 for (i = 0; i < code_len; i++, ip++) {
16149@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
16150 pr_cont(" Bad EIP value.");
16151 break;
16152 }
16153- if (ip == (u8 *)regs->ip)
16154+ if (ip == (u8 *)regs->ip + cs_base)
16155 pr_cont(" <%02x>", c);
16156 else
16157 pr_cont(" %02x", c);
16158@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
16159 {
16160 unsigned short ud2;
16161
16162+ ip = ktla_ktva(ip);
16163 if (ip < PAGE_OFFSET)
16164 return 0;
16165 if (probe_kernel_address((unsigned short *)ip, ud2))
16166@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
16167
16168 return ud2 == 0x0b0f;
16169 }
16170+
16171+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16172+void pax_check_alloca(unsigned long size)
16173+{
16174+ unsigned long sp = (unsigned long)&sp, stack_left;
16175+
16176+ /* all kernel stacks are of the same size */
16177+ stack_left = sp & (THREAD_SIZE - 1);
16178+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16179+}
16180+EXPORT_SYMBOL(pax_check_alloca);
16181+#endif
16182diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
16183index b653675..51cc8c0 100644
16184--- a/arch/x86/kernel/dumpstack_64.c
16185+++ b/arch/x86/kernel/dumpstack_64.c
16186@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16187 unsigned long *irq_stack_end =
16188 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
16189 unsigned used = 0;
16190- struct thread_info *tinfo;
16191 int graph = 0;
16192 unsigned long dummy;
16193+ void *stack_start;
16194
16195 if (!task)
16196 task = current;
16197@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16198 * current stack address. If the stacks consist of nested
16199 * exceptions
16200 */
16201- tinfo = task_thread_info(task);
16202 for (;;) {
16203 char *id;
16204 unsigned long *estack_end;
16205+
16206 estack_end = in_exception_stack(cpu, (unsigned long)stack,
16207 &used, &id);
16208
16209@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16210 if (ops->stack(data, id) < 0)
16211 break;
16212
16213- bp = ops->walk_stack(tinfo, stack, bp, ops,
16214+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
16215 data, estack_end, &graph);
16216 ops->stack(data, "<EOE>");
16217 /*
16218@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16219 * second-to-last pointer (index -2 to end) in the
16220 * exception stack:
16221 */
16222+ if ((u16)estack_end[-1] != __KERNEL_DS)
16223+ goto out;
16224 stack = (unsigned long *) estack_end[-2];
16225 continue;
16226 }
16227@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16228 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16229 if (ops->stack(data, "IRQ") < 0)
16230 break;
16231- bp = ops->walk_stack(tinfo, stack, bp,
16232+ bp = ops->walk_stack(task, irq_stack, stack, bp,
16233 ops, data, irq_stack_end, &graph);
16234 /*
16235 * We link to the next stack (which would be
16236@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16237 /*
16238 * This handles the process stack:
16239 */
16240- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16241+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16242+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16243+out:
16244 put_cpu();
16245 }
16246 EXPORT_SYMBOL(dump_trace);
16247@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16248 {
16249 int i;
16250 unsigned long sp;
16251- const int cpu = smp_processor_id();
16252+ const int cpu = raw_smp_processor_id();
16253 struct task_struct *cur = current;
16254
16255 sp = regs->sp;
16256@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16257
16258 return ud2 == 0x0b0f;
16259 }
16260+
16261+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16262+void pax_check_alloca(unsigned long size)
16263+{
16264+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16265+ unsigned cpu, used;
16266+ char *id;
16267+
16268+ /* check the process stack first */
16269+ stack_start = (unsigned long)task_stack_page(current);
16270+ stack_end = stack_start + THREAD_SIZE;
16271+ if (likely(stack_start <= sp && sp < stack_end)) {
16272+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
16273+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16274+ return;
16275+ }
16276+
16277+ cpu = get_cpu();
16278+
16279+ /* check the irq stacks */
16280+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16281+ stack_start = stack_end - IRQ_STACK_SIZE;
16282+ if (stack_start <= sp && sp < stack_end) {
16283+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16284+ put_cpu();
16285+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16286+ return;
16287+ }
16288+
16289+ /* check the exception stacks */
16290+ used = 0;
16291+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16292+ stack_start = stack_end - EXCEPTION_STKSZ;
16293+ if (stack_end && stack_start <= sp && sp < stack_end) {
16294+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16295+ put_cpu();
16296+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16297+ return;
16298+ }
16299+
16300+ put_cpu();
16301+
16302+ /* unknown stack */
16303+ BUG();
16304+}
16305+EXPORT_SYMBOL(pax_check_alloca);
16306+#endif
16307diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16308index 9b9f18b..9fcaa04 100644
16309--- a/arch/x86/kernel/early_printk.c
16310+++ b/arch/x86/kernel/early_printk.c
16311@@ -7,6 +7,7 @@
16312 #include <linux/pci_regs.h>
16313 #include <linux/pci_ids.h>
16314 #include <linux/errno.h>
16315+#include <linux/sched.h>
16316 #include <asm/io.h>
16317 #include <asm/processor.h>
16318 #include <asm/fcntl.h>
16319diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16320index cf8639b..6c6a674 100644
16321--- a/arch/x86/kernel/entry_32.S
16322+++ b/arch/x86/kernel/entry_32.S
16323@@ -177,13 +177,153 @@
16324 /*CFI_REL_OFFSET gs, PT_GS*/
16325 .endm
16326 .macro SET_KERNEL_GS reg
16327+
16328+#ifdef CONFIG_CC_STACKPROTECTOR
16329 movl $(__KERNEL_STACK_CANARY), \reg
16330+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16331+ movl $(__USER_DS), \reg
16332+#else
16333+ xorl \reg, \reg
16334+#endif
16335+
16336 movl \reg, %gs
16337 .endm
16338
16339 #endif /* CONFIG_X86_32_LAZY_GS */
16340
16341-.macro SAVE_ALL
16342+.macro pax_enter_kernel
16343+#ifdef CONFIG_PAX_KERNEXEC
16344+ call pax_enter_kernel
16345+#endif
16346+.endm
16347+
16348+.macro pax_exit_kernel
16349+#ifdef CONFIG_PAX_KERNEXEC
16350+ call pax_exit_kernel
16351+#endif
16352+.endm
16353+
16354+#ifdef CONFIG_PAX_KERNEXEC
16355+ENTRY(pax_enter_kernel)
16356+#ifdef CONFIG_PARAVIRT
16357+ pushl %eax
16358+ pushl %ecx
16359+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16360+ mov %eax, %esi
16361+#else
16362+ mov %cr0, %esi
16363+#endif
16364+ bts $16, %esi
16365+ jnc 1f
16366+ mov %cs, %esi
16367+ cmp $__KERNEL_CS, %esi
16368+ jz 3f
16369+ ljmp $__KERNEL_CS, $3f
16370+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16371+2:
16372+#ifdef CONFIG_PARAVIRT
16373+ mov %esi, %eax
16374+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16375+#else
16376+ mov %esi, %cr0
16377+#endif
16378+3:
16379+#ifdef CONFIG_PARAVIRT
16380+ popl %ecx
16381+ popl %eax
16382+#endif
16383+ ret
16384+ENDPROC(pax_enter_kernel)
16385+
16386+ENTRY(pax_exit_kernel)
16387+#ifdef CONFIG_PARAVIRT
16388+ pushl %eax
16389+ pushl %ecx
16390+#endif
16391+ mov %cs, %esi
16392+ cmp $__KERNEXEC_KERNEL_CS, %esi
16393+ jnz 2f
16394+#ifdef CONFIG_PARAVIRT
16395+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16396+ mov %eax, %esi
16397+#else
16398+ mov %cr0, %esi
16399+#endif
16400+ btr $16, %esi
16401+ ljmp $__KERNEL_CS, $1f
16402+1:
16403+#ifdef CONFIG_PARAVIRT
16404+ mov %esi, %eax
16405+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16406+#else
16407+ mov %esi, %cr0
16408+#endif
16409+2:
16410+#ifdef CONFIG_PARAVIRT
16411+ popl %ecx
16412+ popl %eax
16413+#endif
16414+ ret
16415+ENDPROC(pax_exit_kernel)
16416+#endif
16417+
16418+.macro pax_erase_kstack
16419+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16420+ call pax_erase_kstack
16421+#endif
16422+.endm
16423+
16424+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16425+/*
16426+ * ebp: thread_info
16427+ */
16428+ENTRY(pax_erase_kstack)
16429+ pushl %edi
16430+ pushl %ecx
16431+ pushl %eax
16432+
16433+ mov TI_lowest_stack(%ebp), %edi
16434+ mov $-0xBEEF, %eax
16435+ std
16436+
16437+1: mov %edi, %ecx
16438+ and $THREAD_SIZE_asm - 1, %ecx
16439+ shr $2, %ecx
16440+ repne scasl
16441+ jecxz 2f
16442+
16443+ cmp $2*16, %ecx
16444+ jc 2f
16445+
16446+ mov $2*16, %ecx
16447+ repe scasl
16448+ jecxz 2f
16449+ jne 1b
16450+
16451+2: cld
16452+ mov %esp, %ecx
16453+ sub %edi, %ecx
16454+
16455+ cmp $THREAD_SIZE_asm, %ecx
16456+ jb 3f
16457+ ud2
16458+3:
16459+
16460+ shr $2, %ecx
16461+ rep stosl
16462+
16463+ mov TI_task_thread_sp0(%ebp), %edi
16464+ sub $128, %edi
16465+ mov %edi, TI_lowest_stack(%ebp)
16466+
16467+ popl %eax
16468+ popl %ecx
16469+ popl %edi
16470+ ret
16471+ENDPROC(pax_erase_kstack)
16472+#endif
16473+
16474+.macro __SAVE_ALL _DS
16475 cld
16476 PUSH_GS
16477 pushl_cfi %fs
16478@@ -206,7 +346,7 @@
16479 CFI_REL_OFFSET ecx, 0
16480 pushl_cfi %ebx
16481 CFI_REL_OFFSET ebx, 0
16482- movl $(__USER_DS), %edx
16483+ movl $\_DS, %edx
16484 movl %edx, %ds
16485 movl %edx, %es
16486 movl $(__KERNEL_PERCPU), %edx
16487@@ -214,6 +354,15 @@
16488 SET_KERNEL_GS %edx
16489 .endm
16490
16491+.macro SAVE_ALL
16492+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16493+ __SAVE_ALL __KERNEL_DS
16494+ pax_enter_kernel
16495+#else
16496+ __SAVE_ALL __USER_DS
16497+#endif
16498+.endm
16499+
16500 .macro RESTORE_INT_REGS
16501 popl_cfi %ebx
16502 CFI_RESTORE ebx
16503@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16504 popfl_cfi
16505 jmp syscall_exit
16506 CFI_ENDPROC
16507-END(ret_from_fork)
16508+ENDPROC(ret_from_fork)
16509
16510 ENTRY(ret_from_kernel_thread)
16511 CFI_STARTPROC
16512@@ -344,7 +493,15 @@ ret_from_intr:
16513 andl $SEGMENT_RPL_MASK, %eax
16514 #endif
16515 cmpl $USER_RPL, %eax
16516+
16517+#ifdef CONFIG_PAX_KERNEXEC
16518+ jae resume_userspace
16519+
16520+ pax_exit_kernel
16521+ jmp resume_kernel
16522+#else
16523 jb resume_kernel # not returning to v8086 or userspace
16524+#endif
16525
16526 ENTRY(resume_userspace)
16527 LOCKDEP_SYS_EXIT
16528@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16529 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16530 # int/exception return?
16531 jne work_pending
16532- jmp restore_all
16533-END(ret_from_exception)
16534+ jmp restore_all_pax
16535+ENDPROC(ret_from_exception)
16536
16537 #ifdef CONFIG_PREEMPT
16538 ENTRY(resume_kernel)
16539@@ -372,7 +529,7 @@ need_resched:
16540 jz restore_all
16541 call preempt_schedule_irq
16542 jmp need_resched
16543-END(resume_kernel)
16544+ENDPROC(resume_kernel)
16545 #endif
16546 CFI_ENDPROC
16547 /*
16548@@ -406,30 +563,45 @@ sysenter_past_esp:
16549 /*CFI_REL_OFFSET cs, 0*/
16550 /*
16551 * Push current_thread_info()->sysenter_return to the stack.
16552- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16553- * pushed above; +8 corresponds to copy_thread's esp0 setting.
16554 */
16555- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16556+ pushl_cfi $0
16557 CFI_REL_OFFSET eip, 0
16558
16559 pushl_cfi %eax
16560 SAVE_ALL
16561+ GET_THREAD_INFO(%ebp)
16562+ movl TI_sysenter_return(%ebp),%ebp
16563+ movl %ebp,PT_EIP(%esp)
16564 ENABLE_INTERRUPTS(CLBR_NONE)
16565
16566 /*
16567 * Load the potential sixth argument from user stack.
16568 * Careful about security.
16569 */
16570+ movl PT_OLDESP(%esp),%ebp
16571+
16572+#ifdef CONFIG_PAX_MEMORY_UDEREF
16573+ mov PT_OLDSS(%esp),%ds
16574+1: movl %ds:(%ebp),%ebp
16575+ push %ss
16576+ pop %ds
16577+#else
16578 cmpl $__PAGE_OFFSET-3,%ebp
16579 jae syscall_fault
16580 ASM_STAC
16581 1: movl (%ebp),%ebp
16582 ASM_CLAC
16583+#endif
16584+
16585 movl %ebp,PT_EBP(%esp)
16586 _ASM_EXTABLE(1b,syscall_fault)
16587
16588 GET_THREAD_INFO(%ebp)
16589
16590+#ifdef CONFIG_PAX_RANDKSTACK
16591+ pax_erase_kstack
16592+#endif
16593+
16594 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16595 jnz sysenter_audit
16596 sysenter_do_call:
16597@@ -444,12 +616,24 @@ sysenter_do_call:
16598 testl $_TIF_ALLWORK_MASK, %ecx
16599 jne sysexit_audit
16600 sysenter_exit:
16601+
16602+#ifdef CONFIG_PAX_RANDKSTACK
16603+ pushl_cfi %eax
16604+ movl %esp, %eax
16605+ call pax_randomize_kstack
16606+ popl_cfi %eax
16607+#endif
16608+
16609+ pax_erase_kstack
16610+
16611 /* if something modifies registers it must also disable sysexit */
16612 movl PT_EIP(%esp), %edx
16613 movl PT_OLDESP(%esp), %ecx
16614 xorl %ebp,%ebp
16615 TRACE_IRQS_ON
16616 1: mov PT_FS(%esp), %fs
16617+2: mov PT_DS(%esp), %ds
16618+3: mov PT_ES(%esp), %es
16619 PTGS_TO_GS
16620 ENABLE_INTERRUPTS_SYSEXIT
16621
16622@@ -466,6 +650,9 @@ sysenter_audit:
16623 movl %eax,%edx /* 2nd arg: syscall number */
16624 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16625 call __audit_syscall_entry
16626+
16627+ pax_erase_kstack
16628+
16629 pushl_cfi %ebx
16630 movl PT_EAX(%esp),%eax /* reload syscall number */
16631 jmp sysenter_do_call
16632@@ -491,10 +678,16 @@ sysexit_audit:
16633
16634 CFI_ENDPROC
16635 .pushsection .fixup,"ax"
16636-2: movl $0,PT_FS(%esp)
16637+4: movl $0,PT_FS(%esp)
16638+ jmp 1b
16639+5: movl $0,PT_DS(%esp)
16640+ jmp 1b
16641+6: movl $0,PT_ES(%esp)
16642 jmp 1b
16643 .popsection
16644- _ASM_EXTABLE(1b,2b)
16645+ _ASM_EXTABLE(1b,4b)
16646+ _ASM_EXTABLE(2b,5b)
16647+ _ASM_EXTABLE(3b,6b)
16648 PTGS_TO_GS_EX
16649 ENDPROC(ia32_sysenter_target)
16650
16651@@ -509,6 +702,11 @@ ENTRY(system_call)
16652 pushl_cfi %eax # save orig_eax
16653 SAVE_ALL
16654 GET_THREAD_INFO(%ebp)
16655+
16656+#ifdef CONFIG_PAX_RANDKSTACK
16657+ pax_erase_kstack
16658+#endif
16659+
16660 # system call tracing in operation / emulation
16661 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16662 jnz syscall_trace_entry
16663@@ -527,6 +725,15 @@ syscall_exit:
16664 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16665 jne syscall_exit_work
16666
16667+restore_all_pax:
16668+
16669+#ifdef CONFIG_PAX_RANDKSTACK
16670+ movl %esp, %eax
16671+ call pax_randomize_kstack
16672+#endif
16673+
16674+ pax_erase_kstack
16675+
16676 restore_all:
16677 TRACE_IRQS_IRET
16678 restore_all_notrace:
16679@@ -583,14 +790,34 @@ ldt_ss:
16680 * compensating for the offset by changing to the ESPFIX segment with
16681 * a base address that matches for the difference.
16682 */
16683-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16684+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16685 mov %esp, %edx /* load kernel esp */
16686 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16687 mov %dx, %ax /* eax: new kernel esp */
16688 sub %eax, %edx /* offset (low word is 0) */
16689+#ifdef CONFIG_SMP
16690+ movl PER_CPU_VAR(cpu_number), %ebx
16691+ shll $PAGE_SHIFT_asm, %ebx
16692+ addl $cpu_gdt_table, %ebx
16693+#else
16694+ movl $cpu_gdt_table, %ebx
16695+#endif
16696 shr $16, %edx
16697- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16698- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16699+
16700+#ifdef CONFIG_PAX_KERNEXEC
16701+ mov %cr0, %esi
16702+ btr $16, %esi
16703+ mov %esi, %cr0
16704+#endif
16705+
16706+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16707+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16708+
16709+#ifdef CONFIG_PAX_KERNEXEC
16710+ bts $16, %esi
16711+ mov %esi, %cr0
16712+#endif
16713+
16714 pushl_cfi $__ESPFIX_SS
16715 pushl_cfi %eax /* new kernel esp */
16716 /* Disable interrupts, but do not irqtrace this section: we
16717@@ -619,20 +846,18 @@ work_resched:
16718 movl TI_flags(%ebp), %ecx
16719 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16720 # than syscall tracing?
16721- jz restore_all
16722+ jz restore_all_pax
16723 testb $_TIF_NEED_RESCHED, %cl
16724 jnz work_resched
16725
16726 work_notifysig: # deal with pending signals and
16727 # notify-resume requests
16728+ movl %esp, %eax
16729 #ifdef CONFIG_VM86
16730 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16731- movl %esp, %eax
16732 jne work_notifysig_v86 # returning to kernel-space or
16733 # vm86-space
16734 1:
16735-#else
16736- movl %esp, %eax
16737 #endif
16738 TRACE_IRQS_ON
16739 ENABLE_INTERRUPTS(CLBR_NONE)
16740@@ -653,7 +878,7 @@ work_notifysig_v86:
16741 movl %eax, %esp
16742 jmp 1b
16743 #endif
16744-END(work_pending)
16745+ENDPROC(work_pending)
16746
16747 # perform syscall exit tracing
16748 ALIGN
16749@@ -661,11 +886,14 @@ syscall_trace_entry:
16750 movl $-ENOSYS,PT_EAX(%esp)
16751 movl %esp, %eax
16752 call syscall_trace_enter
16753+
16754+ pax_erase_kstack
16755+
16756 /* What it returned is what we'll actually use. */
16757 cmpl $(NR_syscalls), %eax
16758 jnae syscall_call
16759 jmp syscall_exit
16760-END(syscall_trace_entry)
16761+ENDPROC(syscall_trace_entry)
16762
16763 # perform syscall exit tracing
16764 ALIGN
16765@@ -678,21 +906,25 @@ syscall_exit_work:
16766 movl %esp, %eax
16767 call syscall_trace_leave
16768 jmp resume_userspace
16769-END(syscall_exit_work)
16770+ENDPROC(syscall_exit_work)
16771 CFI_ENDPROC
16772
16773 RING0_INT_FRAME # can't unwind into user space anyway
16774 syscall_fault:
16775+#ifdef CONFIG_PAX_MEMORY_UDEREF
16776+ push %ss
16777+ pop %ds
16778+#endif
16779 ASM_CLAC
16780 GET_THREAD_INFO(%ebp)
16781 movl $-EFAULT,PT_EAX(%esp)
16782 jmp resume_userspace
16783-END(syscall_fault)
16784+ENDPROC(syscall_fault)
16785
16786 syscall_badsys:
16787 movl $-ENOSYS,PT_EAX(%esp)
16788 jmp resume_userspace
16789-END(syscall_badsys)
16790+ENDPROC(syscall_badsys)
16791 CFI_ENDPROC
16792 /*
16793 * End of kprobes section
16794@@ -772,8 +1004,15 @@ ENDPROC(ptregs_clone)
16795 * normal stack and adjusts ESP with the matching offset.
16796 */
16797 /* fixup the stack */
16798- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16799- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16800+#ifdef CONFIG_SMP
16801+ movl PER_CPU_VAR(cpu_number), %ebx
16802+ shll $PAGE_SHIFT_asm, %ebx
16803+ addl $cpu_gdt_table, %ebx
16804+#else
16805+ movl $cpu_gdt_table, %ebx
16806+#endif
16807+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16808+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16809 shl $16, %eax
16810 addl %esp, %eax /* the adjusted stack pointer */
16811 pushl_cfi $__KERNEL_DS
16812@@ -826,7 +1065,7 @@ vector=vector+1
16813 .endr
16814 2: jmp common_interrupt
16815 .endr
16816-END(irq_entries_start)
16817+ENDPROC(irq_entries_start)
16818
16819 .previous
16820 END(interrupt)
16821@@ -877,7 +1116,7 @@ ENTRY(coprocessor_error)
16822 pushl_cfi $do_coprocessor_error
16823 jmp error_code
16824 CFI_ENDPROC
16825-END(coprocessor_error)
16826+ENDPROC(coprocessor_error)
16827
16828 ENTRY(simd_coprocessor_error)
16829 RING0_INT_FRAME
16830@@ -899,7 +1138,7 @@ ENTRY(simd_coprocessor_error)
16831 #endif
16832 jmp error_code
16833 CFI_ENDPROC
16834-END(simd_coprocessor_error)
16835+ENDPROC(simd_coprocessor_error)
16836
16837 ENTRY(device_not_available)
16838 RING0_INT_FRAME
16839@@ -908,18 +1147,18 @@ ENTRY(device_not_available)
16840 pushl_cfi $do_device_not_available
16841 jmp error_code
16842 CFI_ENDPROC
16843-END(device_not_available)
16844+ENDPROC(device_not_available)
16845
16846 #ifdef CONFIG_PARAVIRT
16847 ENTRY(native_iret)
16848 iret
16849 _ASM_EXTABLE(native_iret, iret_exc)
16850-END(native_iret)
16851+ENDPROC(native_iret)
16852
16853 ENTRY(native_irq_enable_sysexit)
16854 sti
16855 sysexit
16856-END(native_irq_enable_sysexit)
16857+ENDPROC(native_irq_enable_sysexit)
16858 #endif
16859
16860 ENTRY(overflow)
16861@@ -929,7 +1168,7 @@ ENTRY(overflow)
16862 pushl_cfi $do_overflow
16863 jmp error_code
16864 CFI_ENDPROC
16865-END(overflow)
16866+ENDPROC(overflow)
16867
16868 ENTRY(bounds)
16869 RING0_INT_FRAME
16870@@ -938,7 +1177,7 @@ ENTRY(bounds)
16871 pushl_cfi $do_bounds
16872 jmp error_code
16873 CFI_ENDPROC
16874-END(bounds)
16875+ENDPROC(bounds)
16876
16877 ENTRY(invalid_op)
16878 RING0_INT_FRAME
16879@@ -947,7 +1186,7 @@ ENTRY(invalid_op)
16880 pushl_cfi $do_invalid_op
16881 jmp error_code
16882 CFI_ENDPROC
16883-END(invalid_op)
16884+ENDPROC(invalid_op)
16885
16886 ENTRY(coprocessor_segment_overrun)
16887 RING0_INT_FRAME
16888@@ -956,7 +1195,7 @@ ENTRY(coprocessor_segment_overrun)
16889 pushl_cfi $do_coprocessor_segment_overrun
16890 jmp error_code
16891 CFI_ENDPROC
16892-END(coprocessor_segment_overrun)
16893+ENDPROC(coprocessor_segment_overrun)
16894
16895 ENTRY(invalid_TSS)
16896 RING0_EC_FRAME
16897@@ -964,7 +1203,7 @@ ENTRY(invalid_TSS)
16898 pushl_cfi $do_invalid_TSS
16899 jmp error_code
16900 CFI_ENDPROC
16901-END(invalid_TSS)
16902+ENDPROC(invalid_TSS)
16903
16904 ENTRY(segment_not_present)
16905 RING0_EC_FRAME
16906@@ -972,7 +1211,7 @@ ENTRY(segment_not_present)
16907 pushl_cfi $do_segment_not_present
16908 jmp error_code
16909 CFI_ENDPROC
16910-END(segment_not_present)
16911+ENDPROC(segment_not_present)
16912
16913 ENTRY(stack_segment)
16914 RING0_EC_FRAME
16915@@ -980,7 +1219,7 @@ ENTRY(stack_segment)
16916 pushl_cfi $do_stack_segment
16917 jmp error_code
16918 CFI_ENDPROC
16919-END(stack_segment)
16920+ENDPROC(stack_segment)
16921
16922 ENTRY(alignment_check)
16923 RING0_EC_FRAME
16924@@ -988,7 +1227,7 @@ ENTRY(alignment_check)
16925 pushl_cfi $do_alignment_check
16926 jmp error_code
16927 CFI_ENDPROC
16928-END(alignment_check)
16929+ENDPROC(alignment_check)
16930
16931 ENTRY(divide_error)
16932 RING0_INT_FRAME
16933@@ -997,7 +1236,7 @@ ENTRY(divide_error)
16934 pushl_cfi $do_divide_error
16935 jmp error_code
16936 CFI_ENDPROC
16937-END(divide_error)
16938+ENDPROC(divide_error)
16939
16940 #ifdef CONFIG_X86_MCE
16941 ENTRY(machine_check)
16942@@ -1007,7 +1246,7 @@ ENTRY(machine_check)
16943 pushl_cfi machine_check_vector
16944 jmp error_code
16945 CFI_ENDPROC
16946-END(machine_check)
16947+ENDPROC(machine_check)
16948 #endif
16949
16950 ENTRY(spurious_interrupt_bug)
16951@@ -1017,7 +1256,7 @@ ENTRY(spurious_interrupt_bug)
16952 pushl_cfi $do_spurious_interrupt_bug
16953 jmp error_code
16954 CFI_ENDPROC
16955-END(spurious_interrupt_bug)
16956+ENDPROC(spurious_interrupt_bug)
16957 /*
16958 * End of kprobes section
16959 */
16960@@ -1120,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16961
16962 ENTRY(mcount)
16963 ret
16964-END(mcount)
16965+ENDPROC(mcount)
16966
16967 ENTRY(ftrace_caller)
16968 cmpl $0, function_trace_stop
16969@@ -1153,7 +1392,7 @@ ftrace_graph_call:
16970 .globl ftrace_stub
16971 ftrace_stub:
16972 ret
16973-END(ftrace_caller)
16974+ENDPROC(ftrace_caller)
16975
16976 ENTRY(ftrace_regs_caller)
16977 pushf /* push flags before compare (in cs location) */
16978@@ -1254,7 +1493,7 @@ trace:
16979 popl %ecx
16980 popl %eax
16981 jmp ftrace_stub
16982-END(mcount)
16983+ENDPROC(mcount)
16984 #endif /* CONFIG_DYNAMIC_FTRACE */
16985 #endif /* CONFIG_FUNCTION_TRACER */
16986
16987@@ -1272,7 +1511,7 @@ ENTRY(ftrace_graph_caller)
16988 popl %ecx
16989 popl %eax
16990 ret
16991-END(ftrace_graph_caller)
16992+ENDPROC(ftrace_graph_caller)
16993
16994 .globl return_to_handler
16995 return_to_handler:
16996@@ -1328,15 +1567,18 @@ error_code:
16997 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16998 REG_TO_PTGS %ecx
16999 SET_KERNEL_GS %ecx
17000- movl $(__USER_DS), %ecx
17001+ movl $(__KERNEL_DS), %ecx
17002 movl %ecx, %ds
17003 movl %ecx, %es
17004+
17005+ pax_enter_kernel
17006+
17007 TRACE_IRQS_OFF
17008 movl %esp,%eax # pt_regs pointer
17009 call *%edi
17010 jmp ret_from_exception
17011 CFI_ENDPROC
17012-END(page_fault)
17013+ENDPROC(page_fault)
17014
17015 /*
17016 * Debug traps and NMI can happen at the one SYSENTER instruction
17017@@ -1379,7 +1621,7 @@ debug_stack_correct:
17018 call do_debug
17019 jmp ret_from_exception
17020 CFI_ENDPROC
17021-END(debug)
17022+ENDPROC(debug)
17023
17024 /*
17025 * NMI is doubly nasty. It can happen _while_ we're handling
17026@@ -1417,6 +1659,9 @@ nmi_stack_correct:
17027 xorl %edx,%edx # zero error code
17028 movl %esp,%eax # pt_regs pointer
17029 call do_nmi
17030+
17031+ pax_exit_kernel
17032+
17033 jmp restore_all_notrace
17034 CFI_ENDPROC
17035
17036@@ -1453,12 +1698,15 @@ nmi_espfix_stack:
17037 FIXUP_ESPFIX_STACK # %eax == %esp
17038 xorl %edx,%edx # zero error code
17039 call do_nmi
17040+
17041+ pax_exit_kernel
17042+
17043 RESTORE_REGS
17044 lss 12+4(%esp), %esp # back to espfix stack
17045 CFI_ADJUST_CFA_OFFSET -24
17046 jmp irq_return
17047 CFI_ENDPROC
17048-END(nmi)
17049+ENDPROC(nmi)
17050
17051 ENTRY(int3)
17052 RING0_INT_FRAME
17053@@ -1471,14 +1719,14 @@ ENTRY(int3)
17054 call do_int3
17055 jmp ret_from_exception
17056 CFI_ENDPROC
17057-END(int3)
17058+ENDPROC(int3)
17059
17060 ENTRY(general_protection)
17061 RING0_EC_FRAME
17062 pushl_cfi $do_general_protection
17063 jmp error_code
17064 CFI_ENDPROC
17065-END(general_protection)
17066+ENDPROC(general_protection)
17067
17068 #ifdef CONFIG_KVM_GUEST
17069 ENTRY(async_page_fault)
17070@@ -1487,7 +1735,7 @@ ENTRY(async_page_fault)
17071 pushl_cfi $do_async_page_fault
17072 jmp error_code
17073 CFI_ENDPROC
17074-END(async_page_fault)
17075+ENDPROC(async_page_fault)
17076 #endif
17077
17078 /*
17079diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
17080index 1328fe4..cb03298 100644
17081--- a/arch/x86/kernel/entry_64.S
17082+++ b/arch/x86/kernel/entry_64.S
17083@@ -59,6 +59,8 @@
17084 #include <asm/rcu.h>
17085 #include <asm/smap.h>
17086 #include <linux/err.h>
17087+#include <asm/pgtable.h>
17088+#include <asm/alternative-asm.h>
17089
17090 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
17091 #include <linux/elf-em.h>
17092@@ -80,8 +82,9 @@
17093 #ifdef CONFIG_DYNAMIC_FTRACE
17094
17095 ENTRY(function_hook)
17096+ pax_force_retaddr
17097 retq
17098-END(function_hook)
17099+ENDPROC(function_hook)
17100
17101 /* skip is set if stack has been adjusted */
17102 .macro ftrace_caller_setup skip=0
17103@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
17104 #endif
17105
17106 GLOBAL(ftrace_stub)
17107+ pax_force_retaddr
17108 retq
17109-END(ftrace_caller)
17110+ENDPROC(ftrace_caller)
17111
17112 ENTRY(ftrace_regs_caller)
17113 /* Save the current flags before compare (in SS location)*/
17114@@ -191,7 +195,7 @@ ftrace_restore_flags:
17115 popfq
17116 jmp ftrace_stub
17117
17118-END(ftrace_regs_caller)
17119+ENDPROC(ftrace_regs_caller)
17120
17121
17122 #else /* ! CONFIG_DYNAMIC_FTRACE */
17123@@ -212,6 +216,7 @@ ENTRY(function_hook)
17124 #endif
17125
17126 GLOBAL(ftrace_stub)
17127+ pax_force_retaddr
17128 retq
17129
17130 trace:
17131@@ -225,12 +230,13 @@ trace:
17132 #endif
17133 subq $MCOUNT_INSN_SIZE, %rdi
17134
17135+ pax_force_fptr ftrace_trace_function
17136 call *ftrace_trace_function
17137
17138 MCOUNT_RESTORE_FRAME
17139
17140 jmp ftrace_stub
17141-END(function_hook)
17142+ENDPROC(function_hook)
17143 #endif /* CONFIG_DYNAMIC_FTRACE */
17144 #endif /* CONFIG_FUNCTION_TRACER */
17145
17146@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
17147
17148 MCOUNT_RESTORE_FRAME
17149
17150+ pax_force_retaddr
17151 retq
17152-END(ftrace_graph_caller)
17153+ENDPROC(ftrace_graph_caller)
17154
17155 GLOBAL(return_to_handler)
17156 subq $24, %rsp
17157@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
17158 movq 8(%rsp), %rdx
17159 movq (%rsp), %rax
17160 addq $24, %rsp
17161+ pax_force_fptr %rdi
17162 jmp *%rdi
17163+ENDPROC(return_to_handler)
17164 #endif
17165
17166
17167@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
17168 ENDPROC(native_usergs_sysret64)
17169 #endif /* CONFIG_PARAVIRT */
17170
17171+ .macro ljmpq sel, off
17172+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
17173+ .byte 0x48; ljmp *1234f(%rip)
17174+ .pushsection .rodata
17175+ .align 16
17176+ 1234: .quad \off; .word \sel
17177+ .popsection
17178+#else
17179+ pushq $\sel
17180+ pushq $\off
17181+ lretq
17182+#endif
17183+ .endm
17184+
17185+ .macro pax_enter_kernel
17186+ pax_set_fptr_mask
17187+#ifdef CONFIG_PAX_KERNEXEC
17188+ call pax_enter_kernel
17189+#endif
17190+ .endm
17191+
17192+ .macro pax_exit_kernel
17193+#ifdef CONFIG_PAX_KERNEXEC
17194+ call pax_exit_kernel
17195+#endif
17196+ .endm
17197+
17198+#ifdef CONFIG_PAX_KERNEXEC
17199+ENTRY(pax_enter_kernel)
17200+ pushq %rdi
17201+
17202+#ifdef CONFIG_PARAVIRT
17203+ PV_SAVE_REGS(CLBR_RDI)
17204+#endif
17205+
17206+ GET_CR0_INTO_RDI
17207+ bts $16,%rdi
17208+ jnc 3f
17209+ mov %cs,%edi
17210+ cmp $__KERNEL_CS,%edi
17211+ jnz 2f
17212+1:
17213+
17214+#ifdef CONFIG_PARAVIRT
17215+ PV_RESTORE_REGS(CLBR_RDI)
17216+#endif
17217+
17218+ popq %rdi
17219+ pax_force_retaddr
17220+ retq
17221+
17222+2: ljmpq __KERNEL_CS,1f
17223+3: ljmpq __KERNEXEC_KERNEL_CS,4f
17224+4: SET_RDI_INTO_CR0
17225+ jmp 1b
17226+ENDPROC(pax_enter_kernel)
17227+
17228+ENTRY(pax_exit_kernel)
17229+ pushq %rdi
17230+
17231+#ifdef CONFIG_PARAVIRT
17232+ PV_SAVE_REGS(CLBR_RDI)
17233+#endif
17234+
17235+ mov %cs,%rdi
17236+ cmp $__KERNEXEC_KERNEL_CS,%edi
17237+ jz 2f
17238+1:
17239+
17240+#ifdef CONFIG_PARAVIRT
17241+ PV_RESTORE_REGS(CLBR_RDI);
17242+#endif
17243+
17244+ popq %rdi
17245+ pax_force_retaddr
17246+ retq
17247+
17248+2: GET_CR0_INTO_RDI
17249+ btr $16,%rdi
17250+ ljmpq __KERNEL_CS,3f
17251+3: SET_RDI_INTO_CR0
17252+ jmp 1b
17253+ENDPROC(pax_exit_kernel)
17254+#endif
17255+
17256+ .macro pax_enter_kernel_user
17257+ pax_set_fptr_mask
17258+#ifdef CONFIG_PAX_MEMORY_UDEREF
17259+ call pax_enter_kernel_user
17260+#endif
17261+ .endm
17262+
17263+ .macro pax_exit_kernel_user
17264+#ifdef CONFIG_PAX_MEMORY_UDEREF
17265+ call pax_exit_kernel_user
17266+#endif
17267+#ifdef CONFIG_PAX_RANDKSTACK
17268+ pushq %rax
17269+ call pax_randomize_kstack
17270+ popq %rax
17271+#endif
17272+ .endm
17273+
17274+#ifdef CONFIG_PAX_MEMORY_UDEREF
17275+ENTRY(pax_enter_kernel_user)
17276+ pushq %rdi
17277+ pushq %rbx
17278+
17279+#ifdef CONFIG_PARAVIRT
17280+ PV_SAVE_REGS(CLBR_RDI)
17281+#endif
17282+
17283+ GET_CR3_INTO_RDI
17284+ mov %rdi,%rbx
17285+ add $__START_KERNEL_map,%rbx
17286+ sub phys_base(%rip),%rbx
17287+
17288+#ifdef CONFIG_PARAVIRT
17289+ pushq %rdi
17290+ cmpl $0, pv_info+PARAVIRT_enabled
17291+ jz 1f
17292+ i = 0
17293+ .rept USER_PGD_PTRS
17294+ mov i*8(%rbx),%rsi
17295+ mov $0,%sil
17296+ lea i*8(%rbx),%rdi
17297+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17298+ i = i + 1
17299+ .endr
17300+ jmp 2f
17301+1:
17302+#endif
17303+
17304+ i = 0
17305+ .rept USER_PGD_PTRS
17306+ movb $0,i*8(%rbx)
17307+ i = i + 1
17308+ .endr
17309+
17310+#ifdef CONFIG_PARAVIRT
17311+2: popq %rdi
17312+#endif
17313+ SET_RDI_INTO_CR3
17314+
17315+#ifdef CONFIG_PAX_KERNEXEC
17316+ GET_CR0_INTO_RDI
17317+ bts $16,%rdi
17318+ SET_RDI_INTO_CR0
17319+#endif
17320+
17321+#ifdef CONFIG_PARAVIRT
17322+ PV_RESTORE_REGS(CLBR_RDI)
17323+#endif
17324+
17325+ popq %rbx
17326+ popq %rdi
17327+ pax_force_retaddr
17328+ retq
17329+ENDPROC(pax_enter_kernel_user)
17330+
17331+ENTRY(pax_exit_kernel_user)
17332+ push %rdi
17333+
17334+#ifdef CONFIG_PARAVIRT
17335+ pushq %rbx
17336+ PV_SAVE_REGS(CLBR_RDI)
17337+#endif
17338+
17339+#ifdef CONFIG_PAX_KERNEXEC
17340+ GET_CR0_INTO_RDI
17341+ btr $16,%rdi
17342+ SET_RDI_INTO_CR0
17343+#endif
17344+
17345+ GET_CR3_INTO_RDI
17346+ add $__START_KERNEL_map,%rdi
17347+ sub phys_base(%rip),%rdi
17348+
17349+#ifdef CONFIG_PARAVIRT
17350+ cmpl $0, pv_info+PARAVIRT_enabled
17351+ jz 1f
17352+ mov %rdi,%rbx
17353+ i = 0
17354+ .rept USER_PGD_PTRS
17355+ mov i*8(%rbx),%rsi
17356+ mov $0x67,%sil
17357+ lea i*8(%rbx),%rdi
17358+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17359+ i = i + 1
17360+ .endr
17361+ jmp 2f
17362+1:
17363+#endif
17364+
17365+ i = 0
17366+ .rept USER_PGD_PTRS
17367+ movb $0x67,i*8(%rdi)
17368+ i = i + 1
17369+ .endr
17370+
17371+#ifdef CONFIG_PARAVIRT
17372+2: PV_RESTORE_REGS(CLBR_RDI)
17373+ popq %rbx
17374+#endif
17375+
17376+ popq %rdi
17377+ pax_force_retaddr
17378+ retq
17379+ENDPROC(pax_exit_kernel_user)
17380+#endif
17381+
17382+.macro pax_erase_kstack
17383+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17384+ call pax_erase_kstack
17385+#endif
17386+.endm
17387+
17388+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17389+ENTRY(pax_erase_kstack)
17390+ pushq %rdi
17391+ pushq %rcx
17392+ pushq %rax
17393+ pushq %r11
17394+
17395+ GET_THREAD_INFO(%r11)
17396+ mov TI_lowest_stack(%r11), %rdi
17397+ mov $-0xBEEF, %rax
17398+ std
17399+
17400+1: mov %edi, %ecx
17401+ and $THREAD_SIZE_asm - 1, %ecx
17402+ shr $3, %ecx
17403+ repne scasq
17404+ jecxz 2f
17405+
17406+ cmp $2*8, %ecx
17407+ jc 2f
17408+
17409+ mov $2*8, %ecx
17410+ repe scasq
17411+ jecxz 2f
17412+ jne 1b
17413+
17414+2: cld
17415+ mov %esp, %ecx
17416+ sub %edi, %ecx
17417+
17418+ cmp $THREAD_SIZE_asm, %rcx
17419+ jb 3f
17420+ ud2
17421+3:
17422+
17423+ shr $3, %ecx
17424+ rep stosq
17425+
17426+ mov TI_task_thread_sp0(%r11), %rdi
17427+ sub $256, %rdi
17428+ mov %rdi, TI_lowest_stack(%r11)
17429+
17430+ popq %r11
17431+ popq %rax
17432+ popq %rcx
17433+ popq %rdi
17434+ pax_force_retaddr
17435+ ret
17436+ENDPROC(pax_erase_kstack)
17437+#endif
17438
17439 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17440 #ifdef CONFIG_TRACE_IRQFLAGS
17441@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17442 .endm
17443
17444 .macro UNFAKE_STACK_FRAME
17445- addq $8*6, %rsp
17446- CFI_ADJUST_CFA_OFFSET -(6*8)
17447+ addq $8*6 + ARG_SKIP, %rsp
17448+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17449 .endm
17450
17451 /*
17452@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17453 movq %rsp, %rsi
17454
17455 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17456- testl $3, CS-RBP(%rsi)
17457+ testb $3, CS-RBP(%rsi)
17458 je 1f
17459 SWAPGS
17460 /*
17461@@ -498,9 +774,10 @@ ENTRY(save_rest)
17462 movq_cfi r15, R15+16
17463 movq %r11, 8(%rsp) /* return address */
17464 FIXUP_TOP_OF_STACK %r11, 16
17465+ pax_force_retaddr
17466 ret
17467 CFI_ENDPROC
17468-END(save_rest)
17469+ENDPROC(save_rest)
17470
17471 /* save complete stack frame */
17472 .pushsection .kprobes.text, "ax"
17473@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17474 js 1f /* negative -> in kernel */
17475 SWAPGS
17476 xorl %ebx,%ebx
17477-1: ret
17478+1: pax_force_retaddr_bts
17479+ ret
17480 CFI_ENDPROC
17481-END(save_paranoid)
17482+ENDPROC(save_paranoid)
17483 .popsection
17484
17485 /*
17486@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17487
17488 RESTORE_REST
17489
17490- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17491+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17492 jz 1f
17493
17494 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17495@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17496 RESTORE_REST
17497 jmp int_ret_from_sys_call
17498 CFI_ENDPROC
17499-END(ret_from_fork)
17500+ENDPROC(ret_from_fork)
17501
17502 /*
17503 * System call entry. Up to 6 arguments in registers are supported.
17504@@ -608,7 +886,7 @@ END(ret_from_fork)
17505 ENTRY(system_call)
17506 CFI_STARTPROC simple
17507 CFI_SIGNAL_FRAME
17508- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17509+ CFI_DEF_CFA rsp,0
17510 CFI_REGISTER rip,rcx
17511 /*CFI_REGISTER rflags,r11*/
17512 SWAPGS_UNSAFE_STACK
17513@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17514
17515 movq %rsp,PER_CPU_VAR(old_rsp)
17516 movq PER_CPU_VAR(kernel_stack),%rsp
17517+ SAVE_ARGS 8*6,0
17518+ pax_enter_kernel_user
17519+
17520+#ifdef CONFIG_PAX_RANDKSTACK
17521+ pax_erase_kstack
17522+#endif
17523+
17524 /*
17525 * No need to follow this irqs off/on section - it's straight
17526 * and short:
17527 */
17528 ENABLE_INTERRUPTS(CLBR_NONE)
17529- SAVE_ARGS 8,0
17530 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17531 movq %rcx,RIP-ARGOFFSET(%rsp)
17532 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17533- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17534+ GET_THREAD_INFO(%rcx)
17535+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17536 jnz tracesys
17537 system_call_fastpath:
17538 #if __SYSCALL_MASK == ~0
17539@@ -640,7 +925,7 @@ system_call_fastpath:
17540 cmpl $__NR_syscall_max,%eax
17541 #endif
17542 ja badsys
17543- movq %r10,%rcx
17544+ movq R10-ARGOFFSET(%rsp),%rcx
17545 call *sys_call_table(,%rax,8) # XXX: rip relative
17546 movq %rax,RAX-ARGOFFSET(%rsp)
17547 /*
17548@@ -654,10 +939,13 @@ sysret_check:
17549 LOCKDEP_SYS_EXIT
17550 DISABLE_INTERRUPTS(CLBR_NONE)
17551 TRACE_IRQS_OFF
17552- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17553+ GET_THREAD_INFO(%rcx)
17554+ movl TI_flags(%rcx),%edx
17555 andl %edi,%edx
17556 jnz sysret_careful
17557 CFI_REMEMBER_STATE
17558+ pax_exit_kernel_user
17559+ pax_erase_kstack
17560 /*
17561 * sysretq will re-enable interrupts:
17562 */
17563@@ -709,14 +997,18 @@ badsys:
17564 * jump back to the normal fast path.
17565 */
17566 auditsys:
17567- movq %r10,%r9 /* 6th arg: 4th syscall arg */
17568+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17569 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17570 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17571 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17572 movq %rax,%rsi /* 2nd arg: syscall number */
17573 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17574 call __audit_syscall_entry
17575+
17576+ pax_erase_kstack
17577+
17578 LOAD_ARGS 0 /* reload call-clobbered registers */
17579+ pax_set_fptr_mask
17580 jmp system_call_fastpath
17581
17582 /*
17583@@ -737,7 +1029,7 @@ sysret_audit:
17584 /* Do syscall tracing */
17585 tracesys:
17586 #ifdef CONFIG_AUDITSYSCALL
17587- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17588+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17589 jz auditsys
17590 #endif
17591 SAVE_REST
17592@@ -745,12 +1037,16 @@ tracesys:
17593 FIXUP_TOP_OF_STACK %rdi
17594 movq %rsp,%rdi
17595 call syscall_trace_enter
17596+
17597+ pax_erase_kstack
17598+
17599 /*
17600 * Reload arg registers from stack in case ptrace changed them.
17601 * We don't reload %rax because syscall_trace_enter() returned
17602 * the value it wants us to use in the table lookup.
17603 */
17604 LOAD_ARGS ARGOFFSET, 1
17605+ pax_set_fptr_mask
17606 RESTORE_REST
17607 #if __SYSCALL_MASK == ~0
17608 cmpq $__NR_syscall_max,%rax
17609@@ -759,7 +1055,7 @@ tracesys:
17610 cmpl $__NR_syscall_max,%eax
17611 #endif
17612 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17613- movq %r10,%rcx /* fixup for C */
17614+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17615 call *sys_call_table(,%rax,8)
17616 movq %rax,RAX-ARGOFFSET(%rsp)
17617 /* Use IRET because user could have changed frame */
17618@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17619 andl %edi,%edx
17620 jnz int_careful
17621 andl $~TS_COMPAT,TI_status(%rcx)
17622- jmp retint_swapgs
17623+ pax_exit_kernel_user
17624+ pax_erase_kstack
17625+ jmp retint_swapgs_pax
17626
17627 /* Either reschedule or signal or syscall exit tracking needed. */
17628 /* First do a reschedule test. */
17629@@ -826,7 +1124,7 @@ int_restore_rest:
17630 TRACE_IRQS_OFF
17631 jmp int_with_check
17632 CFI_ENDPROC
17633-END(system_call)
17634+ENDPROC(system_call)
17635
17636 /*
17637 * Certain special system calls that need to save a complete full stack frame.
17638@@ -842,7 +1140,7 @@ ENTRY(\label)
17639 call \func
17640 jmp ptregscall_common
17641 CFI_ENDPROC
17642-END(\label)
17643+ENDPROC(\label)
17644 .endm
17645
17646 PTREGSCALL stub_clone, sys_clone, %r8
17647@@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17648 movq_cfi_restore R12+8, r12
17649 movq_cfi_restore RBP+8, rbp
17650 movq_cfi_restore RBX+8, rbx
17651+ pax_force_retaddr
17652 ret $REST_SKIP /* pop extended registers */
17653 CFI_ENDPROC
17654-END(ptregscall_common)
17655+ENDPROC(ptregscall_common)
17656
17657 ENTRY(stub_execve)
17658 CFI_STARTPROC
17659@@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17660 RESTORE_REST
17661 jmp int_ret_from_sys_call
17662 CFI_ENDPROC
17663-END(stub_execve)
17664+ENDPROC(stub_execve)
17665
17666 /*
17667 * sigreturn is special because it needs to restore all registers on return.
17668@@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17669 RESTORE_REST
17670 jmp int_ret_from_sys_call
17671 CFI_ENDPROC
17672-END(stub_rt_sigreturn)
17673+ENDPROC(stub_rt_sigreturn)
17674
17675 #ifdef CONFIG_X86_X32_ABI
17676 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17677@@ -962,7 +1261,7 @@ vector=vector+1
17678 2: jmp common_interrupt
17679 .endr
17680 CFI_ENDPROC
17681-END(irq_entries_start)
17682+ENDPROC(irq_entries_start)
17683
17684 .previous
17685 END(interrupt)
17686@@ -982,6 +1281,16 @@ END(interrupt)
17687 subq $ORIG_RAX-RBP, %rsp
17688 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17689 SAVE_ARGS_IRQ
17690+#ifdef CONFIG_PAX_MEMORY_UDEREF
17691+ testb $3, CS(%rdi)
17692+ jnz 1f
17693+ pax_enter_kernel
17694+ jmp 2f
17695+1: pax_enter_kernel_user
17696+2:
17697+#else
17698+ pax_enter_kernel
17699+#endif
17700 call \func
17701 .endm
17702
17703@@ -1014,7 +1323,7 @@ ret_from_intr:
17704
17705 exit_intr:
17706 GET_THREAD_INFO(%rcx)
17707- testl $3,CS-ARGOFFSET(%rsp)
17708+ testb $3,CS-ARGOFFSET(%rsp)
17709 je retint_kernel
17710
17711 /* Interrupt came from user space */
17712@@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17713 * The iretq could re-enable interrupts:
17714 */
17715 DISABLE_INTERRUPTS(CLBR_ANY)
17716+ pax_exit_kernel_user
17717+retint_swapgs_pax:
17718 TRACE_IRQS_IRETQ
17719 SWAPGS
17720 jmp restore_args
17721
17722 retint_restore_args: /* return to kernel space */
17723 DISABLE_INTERRUPTS(CLBR_ANY)
17724+ pax_exit_kernel
17725+ pax_force_retaddr (RIP-ARGOFFSET)
17726 /*
17727 * The iretq could re-enable interrupts:
17728 */
17729@@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17730 #endif
17731
17732 CFI_ENDPROC
17733-END(common_interrupt)
17734+ENDPROC(common_interrupt)
17735 /*
17736 * End of kprobes section
17737 */
17738@@ -1142,7 +1455,7 @@ ENTRY(\sym)
17739 interrupt \do_sym
17740 jmp ret_from_intr
17741 CFI_ENDPROC
17742-END(\sym)
17743+ENDPROC(\sym)
17744 .endm
17745
17746 #ifdef CONFIG_SMP
17747@@ -1198,12 +1511,22 @@ ENTRY(\sym)
17748 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17749 call error_entry
17750 DEFAULT_FRAME 0
17751+#ifdef CONFIG_PAX_MEMORY_UDEREF
17752+ testb $3, CS(%rsp)
17753+ jnz 1f
17754+ pax_enter_kernel
17755+ jmp 2f
17756+1: pax_enter_kernel_user
17757+2:
17758+#else
17759+ pax_enter_kernel
17760+#endif
17761 movq %rsp,%rdi /* pt_regs pointer */
17762 xorl %esi,%esi /* no error code */
17763 call \do_sym
17764 jmp error_exit /* %ebx: no swapgs flag */
17765 CFI_ENDPROC
17766-END(\sym)
17767+ENDPROC(\sym)
17768 .endm
17769
17770 .macro paranoidzeroentry sym do_sym
17771@@ -1216,15 +1539,25 @@ ENTRY(\sym)
17772 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17773 call save_paranoid
17774 TRACE_IRQS_OFF
17775+#ifdef CONFIG_PAX_MEMORY_UDEREF
17776+ testb $3, CS(%rsp)
17777+ jnz 1f
17778+ pax_enter_kernel
17779+ jmp 2f
17780+1: pax_enter_kernel_user
17781+2:
17782+#else
17783+ pax_enter_kernel
17784+#endif
17785 movq %rsp,%rdi /* pt_regs pointer */
17786 xorl %esi,%esi /* no error code */
17787 call \do_sym
17788 jmp paranoid_exit /* %ebx: no swapgs flag */
17789 CFI_ENDPROC
17790-END(\sym)
17791+ENDPROC(\sym)
17792 .endm
17793
17794-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17795+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17796 .macro paranoidzeroentry_ist sym do_sym ist
17797 ENTRY(\sym)
17798 INTR_FRAME
17799@@ -1235,14 +1568,30 @@ ENTRY(\sym)
17800 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17801 call save_paranoid
17802 TRACE_IRQS_OFF_DEBUG
17803+#ifdef CONFIG_PAX_MEMORY_UDEREF
17804+ testb $3, CS(%rsp)
17805+ jnz 1f
17806+ pax_enter_kernel
17807+ jmp 2f
17808+1: pax_enter_kernel_user
17809+2:
17810+#else
17811+ pax_enter_kernel
17812+#endif
17813 movq %rsp,%rdi /* pt_regs pointer */
17814 xorl %esi,%esi /* no error code */
17815+#ifdef CONFIG_SMP
17816+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17817+ lea init_tss(%r12), %r12
17818+#else
17819+ lea init_tss(%rip), %r12
17820+#endif
17821 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17822 call \do_sym
17823 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17824 jmp paranoid_exit /* %ebx: no swapgs flag */
17825 CFI_ENDPROC
17826-END(\sym)
17827+ENDPROC(\sym)
17828 .endm
17829
17830 .macro errorentry sym do_sym
17831@@ -1254,13 +1603,23 @@ ENTRY(\sym)
17832 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17833 call error_entry
17834 DEFAULT_FRAME 0
17835+#ifdef CONFIG_PAX_MEMORY_UDEREF
17836+ testb $3, CS(%rsp)
17837+ jnz 1f
17838+ pax_enter_kernel
17839+ jmp 2f
17840+1: pax_enter_kernel_user
17841+2:
17842+#else
17843+ pax_enter_kernel
17844+#endif
17845 movq %rsp,%rdi /* pt_regs pointer */
17846 movq ORIG_RAX(%rsp),%rsi /* get error code */
17847 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17848 call \do_sym
17849 jmp error_exit /* %ebx: no swapgs flag */
17850 CFI_ENDPROC
17851-END(\sym)
17852+ENDPROC(\sym)
17853 .endm
17854
17855 /* error code is on the stack already */
17856@@ -1274,13 +1633,23 @@ ENTRY(\sym)
17857 call save_paranoid
17858 DEFAULT_FRAME 0
17859 TRACE_IRQS_OFF
17860+#ifdef CONFIG_PAX_MEMORY_UDEREF
17861+ testb $3, CS(%rsp)
17862+ jnz 1f
17863+ pax_enter_kernel
17864+ jmp 2f
17865+1: pax_enter_kernel_user
17866+2:
17867+#else
17868+ pax_enter_kernel
17869+#endif
17870 movq %rsp,%rdi /* pt_regs pointer */
17871 movq ORIG_RAX(%rsp),%rsi /* get error code */
17872 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17873 call \do_sym
17874 jmp paranoid_exit /* %ebx: no swapgs flag */
17875 CFI_ENDPROC
17876-END(\sym)
17877+ENDPROC(\sym)
17878 .endm
17879
17880 zeroentry divide_error do_divide_error
17881@@ -1310,9 +1679,10 @@ gs_change:
17882 2: mfence /* workaround */
17883 SWAPGS
17884 popfq_cfi
17885+ pax_force_retaddr
17886 ret
17887 CFI_ENDPROC
17888-END(native_load_gs_index)
17889+ENDPROC(native_load_gs_index)
17890
17891 _ASM_EXTABLE(gs_change,bad_gs)
17892 .section .fixup,"ax"
17893@@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17894 CFI_DEF_CFA_REGISTER rsp
17895 CFI_ADJUST_CFA_OFFSET -8
17896 decl PER_CPU_VAR(irq_count)
17897+ pax_force_retaddr
17898 ret
17899 CFI_ENDPROC
17900-END(call_softirq)
17901+ENDPROC(call_softirq)
17902
17903 #ifdef CONFIG_XEN
17904 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17905@@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17906 decl PER_CPU_VAR(irq_count)
17907 jmp error_exit
17908 CFI_ENDPROC
17909-END(xen_do_hypervisor_callback)
17910+ENDPROC(xen_do_hypervisor_callback)
17911
17912 /*
17913 * Hypervisor uses this for application faults while it executes.
17914@@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17915 SAVE_ALL
17916 jmp error_exit
17917 CFI_ENDPROC
17918-END(xen_failsafe_callback)
17919+ENDPROC(xen_failsafe_callback)
17920
17921 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17922 xen_hvm_callback_vector xen_evtchn_do_upcall
17923@@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17924 TRACE_IRQS_OFF_DEBUG
17925 testl %ebx,%ebx /* swapgs needed? */
17926 jnz paranoid_restore
17927- testl $3,CS(%rsp)
17928+ testb $3,CS(%rsp)
17929 jnz paranoid_userspace
17930+#ifdef CONFIG_PAX_MEMORY_UDEREF
17931+ pax_exit_kernel
17932+ TRACE_IRQS_IRETQ 0
17933+ SWAPGS_UNSAFE_STACK
17934+ RESTORE_ALL 8
17935+ pax_force_retaddr_bts
17936+ jmp irq_return
17937+#endif
17938 paranoid_swapgs:
17939+#ifdef CONFIG_PAX_MEMORY_UDEREF
17940+ pax_exit_kernel_user
17941+#else
17942+ pax_exit_kernel
17943+#endif
17944 TRACE_IRQS_IRETQ 0
17945 SWAPGS_UNSAFE_STACK
17946 RESTORE_ALL 8
17947 jmp irq_return
17948 paranoid_restore:
17949+ pax_exit_kernel
17950 TRACE_IRQS_IRETQ_DEBUG 0
17951 RESTORE_ALL 8
17952+ pax_force_retaddr_bts
17953 jmp irq_return
17954 paranoid_userspace:
17955 GET_THREAD_INFO(%rcx)
17956@@ -1526,7 +1912,7 @@ paranoid_schedule:
17957 TRACE_IRQS_OFF
17958 jmp paranoid_userspace
17959 CFI_ENDPROC
17960-END(paranoid_exit)
17961+ENDPROC(paranoid_exit)
17962
17963 /*
17964 * Exception entry point. This expects an error code/orig_rax on the stack.
17965@@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17966 movq_cfi r14, R14+8
17967 movq_cfi r15, R15+8
17968 xorl %ebx,%ebx
17969- testl $3,CS+8(%rsp)
17970+ testb $3,CS+8(%rsp)
17971 je error_kernelspace
17972 error_swapgs:
17973 SWAPGS
17974 error_sti:
17975 TRACE_IRQS_OFF
17976+ pax_force_retaddr_bts
17977 ret
17978
17979 /*
17980@@ -1585,7 +1972,7 @@ bstep_iret:
17981 movq %rcx,RIP+8(%rsp)
17982 jmp error_swapgs
17983 CFI_ENDPROC
17984-END(error_entry)
17985+ENDPROC(error_entry)
17986
17987
17988 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17989@@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17990 jnz retint_careful
17991 jmp retint_swapgs
17992 CFI_ENDPROC
17993-END(error_exit)
17994+ENDPROC(error_exit)
17995
17996 /*
17997 * Test if a given stack is an NMI stack or not.
17998@@ -1663,9 +2050,11 @@ ENTRY(nmi)
17999 * If %cs was not the kernel segment, then the NMI triggered in user
18000 * space, which means it is definitely not nested.
18001 */
18002+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
18003+ je 1f
18004 cmpl $__KERNEL_CS, 16(%rsp)
18005 jne first_nmi
18006-
18007+1:
18008 /*
18009 * Check the special variable on the stack to see if NMIs are
18010 * executing.
18011@@ -1824,6 +2213,17 @@ end_repeat_nmi:
18012 */
18013 movq %cr2, %r12
18014
18015+#ifdef CONFIG_PAX_MEMORY_UDEREF
18016+ testb $3, CS(%rsp)
18017+ jnz 1f
18018+ pax_enter_kernel
18019+ jmp 2f
18020+1: pax_enter_kernel_user
18021+2:
18022+#else
18023+ pax_enter_kernel
18024+#endif
18025+
18026 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
18027 movq %rsp,%rdi
18028 movq $-1,%rsi
18029@@ -1839,21 +2239,32 @@ end_repeat_nmi:
18030 testl %ebx,%ebx /* swapgs needed? */
18031 jnz nmi_restore
18032 nmi_swapgs:
18033+#ifdef CONFIG_PAX_MEMORY_UDEREF
18034+ pax_exit_kernel_user
18035+#else
18036+ pax_exit_kernel
18037+#endif
18038 SWAPGS_UNSAFE_STACK
18039+ RESTORE_ALL 8
18040+ /* Clear the NMI executing stack variable */
18041+ movq $0, 10*8(%rsp)
18042+ jmp irq_return
18043 nmi_restore:
18044+ pax_exit_kernel
18045 RESTORE_ALL 8
18046+ pax_force_retaddr_bts
18047 /* Clear the NMI executing stack variable */
18048 movq $0, 10*8(%rsp)
18049 jmp irq_return
18050 CFI_ENDPROC
18051-END(nmi)
18052+ENDPROC(nmi)
18053
18054 ENTRY(ignore_sysret)
18055 CFI_STARTPROC
18056 mov $-ENOSYS,%eax
18057 sysret
18058 CFI_ENDPROC
18059-END(ignore_sysret)
18060+ENDPROC(ignore_sysret)
18061
18062 /*
18063 * End of kprobes section
18064diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
18065index 1d41402..af9a46a 100644
18066--- a/arch/x86/kernel/ftrace.c
18067+++ b/arch/x86/kernel/ftrace.c
18068@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
18069 {
18070 unsigned char replaced[MCOUNT_INSN_SIZE];
18071
18072+ ip = ktla_ktva(ip);
18073+
18074 /*
18075 * Note: Due to modules and __init, code can
18076 * disappear and change, we need to protect against faulting
18077@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
18078 unsigned char old[MCOUNT_INSN_SIZE], *new;
18079 int ret;
18080
18081- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
18082+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
18083 new = ftrace_call_replace(ip, (unsigned long)func);
18084
18085 /* See comment above by declaration of modifying_ftrace_code */
18086@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
18087 /* Also update the regs callback function */
18088 if (!ret) {
18089 ip = (unsigned long)(&ftrace_regs_call);
18090- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
18091+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
18092 new = ftrace_call_replace(ip, (unsigned long)func);
18093 ret = ftrace_modify_code(ip, old, new);
18094 }
18095@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
18096 * kernel identity mapping to modify code.
18097 */
18098 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
18099- ip = (unsigned long)__va(__pa(ip));
18100+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
18101
18102 return probe_kernel_write((void *)ip, val, size);
18103 }
18104@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
18105 unsigned char replaced[MCOUNT_INSN_SIZE];
18106 unsigned char brk = BREAKPOINT_INSTRUCTION;
18107
18108- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
18109+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
18110 return -EFAULT;
18111
18112 /* Make sure it is what we expect it to be */
18113@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
18114 return ret;
18115
18116 fail_update:
18117- probe_kernel_write((void *)ip, &old_code[0], 1);
18118+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
18119 goto out;
18120 }
18121
18122@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
18123 {
18124 unsigned char code[MCOUNT_INSN_SIZE];
18125
18126+ ip = ktla_ktva(ip);
18127+
18128 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
18129 return -EFAULT;
18130
18131diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
18132index c18f59d..9c0c9f6 100644
18133--- a/arch/x86/kernel/head32.c
18134+++ b/arch/x86/kernel/head32.c
18135@@ -18,6 +18,7 @@
18136 #include <asm/io_apic.h>
18137 #include <asm/bios_ebda.h>
18138 #include <asm/tlbflush.h>
18139+#include <asm/boot.h>
18140
18141 static void __init i386_default_early_setup(void)
18142 {
18143@@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
18144
18145 void __init i386_start_kernel(void)
18146 {
18147- memblock_reserve(__pa_symbol(&_text),
18148- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
18149+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
18150
18151 #ifdef CONFIG_BLK_DEV_INITRD
18152 /* Reserve INITRD */
18153diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
18154index 4dac2f6..bc6a335 100644
18155--- a/arch/x86/kernel/head_32.S
18156+++ b/arch/x86/kernel/head_32.S
18157@@ -26,6 +26,12 @@
18158 /* Physical address */
18159 #define pa(X) ((X) - __PAGE_OFFSET)
18160
18161+#ifdef CONFIG_PAX_KERNEXEC
18162+#define ta(X) (X)
18163+#else
18164+#define ta(X) ((X) - __PAGE_OFFSET)
18165+#endif
18166+
18167 /*
18168 * References to members of the new_cpu_data structure.
18169 */
18170@@ -55,11 +61,7 @@
18171 * and small than max_low_pfn, otherwise will waste some page table entries
18172 */
18173
18174-#if PTRS_PER_PMD > 1
18175-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18176-#else
18177-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18178-#endif
18179+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18180
18181 /* Number of possible pages in the lowmem region */
18182 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18183@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18184 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18185
18186 /*
18187+ * Real beginning of normal "text" segment
18188+ */
18189+ENTRY(stext)
18190+ENTRY(_stext)
18191+
18192+/*
18193 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18194 * %esi points to the real-mode code as a 32-bit pointer.
18195 * CS and DS must be 4 GB flat segments, but we don't depend on
18196@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18197 * can.
18198 */
18199 __HEAD
18200+
18201+#ifdef CONFIG_PAX_KERNEXEC
18202+ jmp startup_32
18203+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18204+.fill PAGE_SIZE-5,1,0xcc
18205+#endif
18206+
18207 ENTRY(startup_32)
18208 movl pa(stack_start),%ecx
18209
18210@@ -106,6 +121,59 @@ ENTRY(startup_32)
18211 2:
18212 leal -__PAGE_OFFSET(%ecx),%esp
18213
18214+#ifdef CONFIG_SMP
18215+ movl $pa(cpu_gdt_table),%edi
18216+ movl $__per_cpu_load,%eax
18217+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18218+ rorl $16,%eax
18219+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18220+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18221+ movl $__per_cpu_end - 1,%eax
18222+ subl $__per_cpu_start,%eax
18223+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18224+#endif
18225+
18226+#ifdef CONFIG_PAX_MEMORY_UDEREF
18227+ movl $NR_CPUS,%ecx
18228+ movl $pa(cpu_gdt_table),%edi
18229+1:
18230+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18231+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18232+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18233+ addl $PAGE_SIZE_asm,%edi
18234+ loop 1b
18235+#endif
18236+
18237+#ifdef CONFIG_PAX_KERNEXEC
18238+ movl $pa(boot_gdt),%edi
18239+ movl $__LOAD_PHYSICAL_ADDR,%eax
18240+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18241+ rorl $16,%eax
18242+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18243+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18244+ rorl $16,%eax
18245+
18246+ ljmp $(__BOOT_CS),$1f
18247+1:
18248+
18249+ movl $NR_CPUS,%ecx
18250+ movl $pa(cpu_gdt_table),%edi
18251+ addl $__PAGE_OFFSET,%eax
18252+1:
18253+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18254+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18255+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18256+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18257+ rorl $16,%eax
18258+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18259+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18260+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18261+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18262+ rorl $16,%eax
18263+ addl $PAGE_SIZE_asm,%edi
18264+ loop 1b
18265+#endif
18266+
18267 /*
18268 * Clear BSS first so that there are no surprises...
18269 */
18270@@ -196,8 +264,11 @@ ENTRY(startup_32)
18271 movl %eax, pa(max_pfn_mapped)
18272
18273 /* Do early initialization of the fixmap area */
18274- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18275- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18276+#ifdef CONFIG_COMPAT_VDSO
18277+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18278+#else
18279+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18280+#endif
18281 #else /* Not PAE */
18282
18283 page_pde_offset = (__PAGE_OFFSET >> 20);
18284@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18285 movl %eax, pa(max_pfn_mapped)
18286
18287 /* Do early initialization of the fixmap area */
18288- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18289- movl %eax,pa(initial_page_table+0xffc)
18290+#ifdef CONFIG_COMPAT_VDSO
18291+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18292+#else
18293+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18294+#endif
18295 #endif
18296
18297 #ifdef CONFIG_PARAVIRT
18298@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18299 cmpl $num_subarch_entries, %eax
18300 jae bad_subarch
18301
18302- movl pa(subarch_entries)(,%eax,4), %eax
18303- subl $__PAGE_OFFSET, %eax
18304- jmp *%eax
18305+ jmp *pa(subarch_entries)(,%eax,4)
18306
18307 bad_subarch:
18308 WEAK(lguest_entry)
18309@@ -256,10 +328,10 @@ WEAK(xen_entry)
18310 __INITDATA
18311
18312 subarch_entries:
18313- .long default_entry /* normal x86/PC */
18314- .long lguest_entry /* lguest hypervisor */
18315- .long xen_entry /* Xen hypervisor */
18316- .long default_entry /* Moorestown MID */
18317+ .long ta(default_entry) /* normal x86/PC */
18318+ .long ta(lguest_entry) /* lguest hypervisor */
18319+ .long ta(xen_entry) /* Xen hypervisor */
18320+ .long ta(default_entry) /* Moorestown MID */
18321 num_subarch_entries = (. - subarch_entries) / 4
18322 .previous
18323 #else
18324@@ -316,6 +388,7 @@ default_entry:
18325 movl pa(mmu_cr4_features),%eax
18326 movl %eax,%cr4
18327
18328+#ifdef CONFIG_X86_PAE
18329 testb $X86_CR4_PAE, %al # check if PAE is enabled
18330 jz 6f
18331
18332@@ -344,6 +417,9 @@ default_entry:
18333 /* Make changes effective */
18334 wrmsr
18335
18336+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18337+#endif
18338+
18339 6:
18340
18341 /*
18342@@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18343 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18344 movl %eax,%ss # after changing gdt.
18345
18346- movl $(__USER_DS),%eax # DS/ES contains default USER segment
18347+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18348 movl %eax,%ds
18349 movl %eax,%es
18350
18351 movl $(__KERNEL_PERCPU), %eax
18352 movl %eax,%fs # set this cpu's percpu
18353
18354+#ifdef CONFIG_CC_STACKPROTECTOR
18355 movl $(__KERNEL_STACK_CANARY),%eax
18356+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18357+ movl $(__USER_DS),%eax
18358+#else
18359+ xorl %eax,%eax
18360+#endif
18361 movl %eax,%gs
18362
18363 xorl %eax,%eax # Clear LDT
18364@@ -526,8 +608,11 @@ setup_once:
18365 * relocation. Manually set base address in stack canary
18366 * segment descriptor.
18367 */
18368- movl $gdt_page,%eax
18369+ movl $cpu_gdt_table,%eax
18370 movl $stack_canary,%ecx
18371+#ifdef CONFIG_SMP
18372+ addl $__per_cpu_load,%ecx
18373+#endif
18374 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18375 shrl $16, %ecx
18376 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18377@@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18378 /* This is global to keep gas from relaxing the jumps */
18379 ENTRY(early_idt_handler)
18380 cld
18381- cmpl $2,%ss:early_recursion_flag
18382+ cmpl $1,%ss:early_recursion_flag
18383 je hlt_loop
18384 incl %ss:early_recursion_flag
18385
18386@@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18387 pushl (20+6*4)(%esp) /* trapno */
18388 pushl $fault_msg
18389 call printk
18390-#endif
18391 call dump_stack
18392+#endif
18393 hlt_loop:
18394 hlt
18395 jmp hlt_loop
18396@@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18397 /* This is the default interrupt "handler" :-) */
18398 ALIGN
18399 ignore_int:
18400- cld
18401 #ifdef CONFIG_PRINTK
18402+ cmpl $2,%ss:early_recursion_flag
18403+ je hlt_loop
18404+ incl %ss:early_recursion_flag
18405+ cld
18406 pushl %eax
18407 pushl %ecx
18408 pushl %edx
18409@@ -626,9 +714,6 @@ ignore_int:
18410 movl $(__KERNEL_DS),%eax
18411 movl %eax,%ds
18412 movl %eax,%es
18413- cmpl $2,early_recursion_flag
18414- je hlt_loop
18415- incl early_recursion_flag
18416 pushl 16(%esp)
18417 pushl 24(%esp)
18418 pushl 32(%esp)
18419@@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18420 /*
18421 * BSS section
18422 */
18423-__PAGE_ALIGNED_BSS
18424- .align PAGE_SIZE
18425 #ifdef CONFIG_X86_PAE
18426+.section .initial_pg_pmd,"a",@progbits
18427 initial_pg_pmd:
18428 .fill 1024*KPMDS,4,0
18429 #else
18430+.section .initial_page_table,"a",@progbits
18431 ENTRY(initial_page_table)
18432 .fill 1024,4,0
18433 #endif
18434+.section .initial_pg_fixmap,"a",@progbits
18435 initial_pg_fixmap:
18436 .fill 1024,4,0
18437+.section .empty_zero_page,"a",@progbits
18438 ENTRY(empty_zero_page)
18439 .fill 4096,1,0
18440+.section .swapper_pg_dir,"a",@progbits
18441 ENTRY(swapper_pg_dir)
18442+#ifdef CONFIG_X86_PAE
18443+ .fill 4,8,0
18444+#else
18445 .fill 1024,4,0
18446+#endif
18447+
18448+/*
18449+ * The IDT has to be page-aligned to simplify the Pentium
18450+ * F0 0F bug workaround.. We have a special link segment
18451+ * for this.
18452+ */
18453+.section .idt,"a",@progbits
18454+ENTRY(idt_table)
18455+ .fill 256,8,0
18456
18457 /*
18458 * This starts the data section.
18459 */
18460 #ifdef CONFIG_X86_PAE
18461-__PAGE_ALIGNED_DATA
18462- /* Page-aligned for the benefit of paravirt? */
18463- .align PAGE_SIZE
18464+.section .initial_page_table,"a",@progbits
18465 ENTRY(initial_page_table)
18466 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18467 # if KPMDS == 3
18468@@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18469 # error "Kernel PMDs should be 1, 2 or 3"
18470 # endif
18471 .align PAGE_SIZE /* needs to be page-sized too */
18472+
18473+#ifdef CONFIG_PAX_PER_CPU_PGD
18474+ENTRY(cpu_pgd)
18475+ .rept NR_CPUS
18476+ .fill 4,8,0
18477+ .endr
18478+#endif
18479+
18480 #endif
18481
18482 .data
18483 .balign 4
18484 ENTRY(stack_start)
18485- .long init_thread_union+THREAD_SIZE
18486+ .long init_thread_union+THREAD_SIZE-8
18487
18488 __INITRODATA
18489 int_msg:
18490@@ -736,7 +843,7 @@ fault_msg:
18491 * segment size, and 32-bit linear address value:
18492 */
18493
18494- .data
18495+.section .rodata,"a",@progbits
18496 .globl boot_gdt_descr
18497 .globl idt_descr
18498
18499@@ -745,7 +852,7 @@ fault_msg:
18500 .word 0 # 32 bit align gdt_desc.address
18501 boot_gdt_descr:
18502 .word __BOOT_DS+7
18503- .long boot_gdt - __PAGE_OFFSET
18504+ .long pa(boot_gdt)
18505
18506 .word 0 # 32-bit align idt_desc.address
18507 idt_descr:
18508@@ -756,7 +863,7 @@ idt_descr:
18509 .word 0 # 32 bit align gdt_desc.address
18510 ENTRY(early_gdt_descr)
18511 .word GDT_ENTRIES*8-1
18512- .long gdt_page /* Overwritten for secondary CPUs */
18513+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
18514
18515 /*
18516 * The boot_gdt must mirror the equivalent in setup.S and is
18517@@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18518 .align L1_CACHE_BYTES
18519 ENTRY(boot_gdt)
18520 .fill GDT_ENTRY_BOOT_CS,8,0
18521- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18522- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18523+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18524+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18525+
18526+ .align PAGE_SIZE_asm
18527+ENTRY(cpu_gdt_table)
18528+ .rept NR_CPUS
18529+ .quad 0x0000000000000000 /* NULL descriptor */
18530+ .quad 0x0000000000000000 /* 0x0b reserved */
18531+ .quad 0x0000000000000000 /* 0x13 reserved */
18532+ .quad 0x0000000000000000 /* 0x1b reserved */
18533+
18534+#ifdef CONFIG_PAX_KERNEXEC
18535+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18536+#else
18537+ .quad 0x0000000000000000 /* 0x20 unused */
18538+#endif
18539+
18540+ .quad 0x0000000000000000 /* 0x28 unused */
18541+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18542+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18543+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18544+ .quad 0x0000000000000000 /* 0x4b reserved */
18545+ .quad 0x0000000000000000 /* 0x53 reserved */
18546+ .quad 0x0000000000000000 /* 0x5b reserved */
18547+
18548+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18549+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18550+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18551+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18552+
18553+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18554+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18555+
18556+ /*
18557+ * Segments used for calling PnP BIOS have byte granularity.
18558+ * The code segments and data segments have fixed 64k limits,
18559+ * the transfer segment sizes are set at run time.
18560+ */
18561+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
18562+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
18563+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
18564+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
18565+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
18566+
18567+ /*
18568+ * The APM segments have byte granularity and their bases
18569+ * are set at run time. All have 64k limits.
18570+ */
18571+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18572+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18573+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
18574+
18575+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18576+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18577+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18578+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18579+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18580+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18581+
18582+ /* Be sure this is zeroed to avoid false validations in Xen */
18583+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18584+ .endr
18585diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18586index 94bf9cc..400455a 100644
18587--- a/arch/x86/kernel/head_64.S
18588+++ b/arch/x86/kernel/head_64.S
18589@@ -20,6 +20,8 @@
18590 #include <asm/processor-flags.h>
18591 #include <asm/percpu.h>
18592 #include <asm/nops.h>
18593+#include <asm/cpufeature.h>
18594+#include <asm/alternative-asm.h>
18595
18596 #ifdef CONFIG_PARAVIRT
18597 #include <asm/asm-offsets.h>
18598@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18599 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18600 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18601 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18602+L4_VMALLOC_START = pgd_index(VMALLOC_START)
18603+L3_VMALLOC_START = pud_index(VMALLOC_START)
18604+L4_VMALLOC_END = pgd_index(VMALLOC_END)
18605+L3_VMALLOC_END = pud_index(VMALLOC_END)
18606+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18607+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18608
18609 .text
18610 __HEAD
18611@@ -88,35 +96,23 @@ startup_64:
18612 */
18613 addq %rbp, init_level4_pgt + 0(%rip)
18614 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18615+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18616+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18617+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18618 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18619
18620 addq %rbp, level3_ident_pgt + 0(%rip)
18621+#ifndef CONFIG_XEN
18622+ addq %rbp, level3_ident_pgt + 8(%rip)
18623+#endif
18624
18625- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18626- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18627+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18628+
18629+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18630+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18631
18632 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18633-
18634- /* Add an Identity mapping if I am above 1G */
18635- leaq _text(%rip), %rdi
18636- andq $PMD_PAGE_MASK, %rdi
18637-
18638- movq %rdi, %rax
18639- shrq $PUD_SHIFT, %rax
18640- andq $(PTRS_PER_PUD - 1), %rax
18641- jz ident_complete
18642-
18643- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18644- leaq level3_ident_pgt(%rip), %rbx
18645- movq %rdx, 0(%rbx, %rax, 8)
18646-
18647- movq %rdi, %rax
18648- shrq $PMD_SHIFT, %rax
18649- andq $(PTRS_PER_PMD - 1), %rax
18650- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18651- leaq level2_spare_pgt(%rip), %rbx
18652- movq %rdx, 0(%rbx, %rax, 8)
18653-ident_complete:
18654+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18655
18656 /*
18657 * Fixup the kernel text+data virtual addresses. Note that
18658@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18659 * after the boot processor executes this code.
18660 */
18661
18662- /* Enable PAE mode and PGE */
18663- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18664+ /* Enable PAE mode and PSE/PGE */
18665+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18666 movq %rax, %cr4
18667
18668 /* Setup early boot stage 4 level pagetables. */
18669@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18670 movl $MSR_EFER, %ecx
18671 rdmsr
18672 btsl $_EFER_SCE, %eax /* Enable System Call */
18673- btl $20,%edi /* No Execute supported? */
18674+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18675 jnc 1f
18676 btsl $_EFER_NX, %eax
18677+ leaq init_level4_pgt(%rip), %rdi
18678+#ifndef CONFIG_EFI
18679+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18680+#endif
18681+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18682+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18683+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18684+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18685 1: wrmsr /* Make changes effective */
18686
18687 /* Setup cr0 */
18688@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18689 * jump. In addition we need to ensure %cs is set so we make this
18690 * a far return.
18691 */
18692+ pax_set_fptr_mask
18693 movq initial_code(%rip),%rax
18694 pushq $0 # fake return address to stop unwinder
18695 pushq $__KERNEL_CS # set correct cs
18696@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18697 bad_address:
18698 jmp bad_address
18699
18700- .section ".init.text","ax"
18701+ __INIT
18702 .globl early_idt_handlers
18703 early_idt_handlers:
18704 # 104(%rsp) %rflags
18705@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18706 addq $16,%rsp # drop vector number and error code
18707 decl early_recursion_flag(%rip)
18708 INTERRUPT_RETURN
18709+ .previous
18710
18711+ __INITDATA
18712 .balign 4
18713 early_recursion_flag:
18714 .long 0
18715+ .previous
18716
18717+ .section .rodata,"a",@progbits
18718 #ifdef CONFIG_EARLY_PRINTK
18719 early_idt_msg:
18720 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18721@@ -360,6 +369,7 @@ early_idt_ripmsg:
18722 #endif /* CONFIG_EARLY_PRINTK */
18723 .previous
18724
18725+ .section .rodata,"a",@progbits
18726 #define NEXT_PAGE(name) \
18727 .balign PAGE_SIZE; \
18728 ENTRY(name)
18729@@ -372,7 +382,6 @@ ENTRY(name)
18730 i = i + 1 ; \
18731 .endr
18732
18733- .data
18734 /*
18735 * This default setting generates an ident mapping at address 0x100000
18736 * and a mapping for the kernel that precisely maps virtual address
18737@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18738 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18739 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18740 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18741+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
18742+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18743+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
18744+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18745+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18746+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18747 .org init_level4_pgt + L4_START_KERNEL*8, 0
18748 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18749 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18750
18751+#ifdef CONFIG_PAX_PER_CPU_PGD
18752+NEXT_PAGE(cpu_pgd)
18753+ .rept NR_CPUS
18754+ .fill 512,8,0
18755+ .endr
18756+#endif
18757+
18758 NEXT_PAGE(level3_ident_pgt)
18759 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18760+#ifdef CONFIG_XEN
18761 .fill 511,8,0
18762+#else
18763+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18764+ .fill 510,8,0
18765+#endif
18766+
18767+NEXT_PAGE(level3_vmalloc_start_pgt)
18768+ .fill 512,8,0
18769+
18770+NEXT_PAGE(level3_vmalloc_end_pgt)
18771+ .fill 512,8,0
18772+
18773+NEXT_PAGE(level3_vmemmap_pgt)
18774+ .fill L3_VMEMMAP_START,8,0
18775+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18776
18777 NEXT_PAGE(level3_kernel_pgt)
18778 .fill L3_START_KERNEL,8,0
18779@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18780 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18781 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18782
18783+NEXT_PAGE(level2_vmemmap_pgt)
18784+ .fill 512,8,0
18785+
18786 NEXT_PAGE(level2_fixmap_pgt)
18787- .fill 506,8,0
18788- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18789- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18790- .fill 5,8,0
18791+ .fill 507,8,0
18792+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18793+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18794+ .fill 4,8,0
18795
18796-NEXT_PAGE(level1_fixmap_pgt)
18797+NEXT_PAGE(level1_vsyscall_pgt)
18798 .fill 512,8,0
18799
18800-NEXT_PAGE(level2_ident_pgt)
18801- /* Since I easily can, map the first 1G.
18802+ /* Since I easily can, map the first 2G.
18803 * Don't set NX because code runs from these pages.
18804 */
18805- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18806+NEXT_PAGE(level2_ident_pgt)
18807+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18808
18809 NEXT_PAGE(level2_kernel_pgt)
18810 /*
18811@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18812 * If you want to increase this then increase MODULES_VADDR
18813 * too.)
18814 */
18815- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18816- KERNEL_IMAGE_SIZE/PMD_SIZE)
18817-
18818-NEXT_PAGE(level2_spare_pgt)
18819- .fill 512, 8, 0
18820+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18821
18822 #undef PMDS
18823 #undef NEXT_PAGE
18824
18825- .data
18826+ .align PAGE_SIZE
18827+ENTRY(cpu_gdt_table)
18828+ .rept NR_CPUS
18829+ .quad 0x0000000000000000 /* NULL descriptor */
18830+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18831+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
18832+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
18833+ .quad 0x00cffb000000ffff /* __USER32_CS */
18834+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18835+ .quad 0x00affb000000ffff /* __USER_CS */
18836+
18837+#ifdef CONFIG_PAX_KERNEXEC
18838+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18839+#else
18840+ .quad 0x0 /* unused */
18841+#endif
18842+
18843+ .quad 0,0 /* TSS */
18844+ .quad 0,0 /* LDT */
18845+ .quad 0,0,0 /* three TLS descriptors */
18846+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
18847+ /* asm/segment.h:GDT_ENTRIES must match this */
18848+
18849+ /* zero the remaining page */
18850+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18851+ .endr
18852+
18853 .align 16
18854 .globl early_gdt_descr
18855 early_gdt_descr:
18856 .word GDT_ENTRIES*8-1
18857 early_gdt_descr_base:
18858- .quad INIT_PER_CPU_VAR(gdt_page)
18859+ .quad cpu_gdt_table
18860
18861 ENTRY(phys_base)
18862 /* This must match the first entry in level2_kernel_pgt */
18863 .quad 0x0000000000000000
18864
18865 #include "../../x86/xen/xen-head.S"
18866-
18867- .section .bss, "aw", @nobits
18868+
18869+ .section .rodata,"a",@progbits
18870 .align L1_CACHE_BYTES
18871 ENTRY(idt_table)
18872- .skip IDT_ENTRIES * 16
18873+ .fill 512,8,0
18874
18875 .align L1_CACHE_BYTES
18876 ENTRY(nmi_idt_table)
18877- .skip IDT_ENTRIES * 16
18878+ .fill 512,8,0
18879
18880 __PAGE_ALIGNED_BSS
18881 .align PAGE_SIZE
18882diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18883index 9c3bd4a..e1d9b35 100644
18884--- a/arch/x86/kernel/i386_ksyms_32.c
18885+++ b/arch/x86/kernel/i386_ksyms_32.c
18886@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18887 EXPORT_SYMBOL(cmpxchg8b_emu);
18888 #endif
18889
18890+EXPORT_SYMBOL_GPL(cpu_gdt_table);
18891+
18892 /* Networking helper routines. */
18893 EXPORT_SYMBOL(csum_partial_copy_generic);
18894+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18895+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18896
18897 EXPORT_SYMBOL(__get_user_1);
18898 EXPORT_SYMBOL(__get_user_2);
18899@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18900
18901 EXPORT_SYMBOL(csum_partial);
18902 EXPORT_SYMBOL(empty_zero_page);
18903+
18904+#ifdef CONFIG_PAX_KERNEXEC
18905+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18906+#endif
18907diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18908index 675a050..95febfd 100644
18909--- a/arch/x86/kernel/i387.c
18910+++ b/arch/x86/kernel/i387.c
18911@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18912 static inline bool interrupted_user_mode(void)
18913 {
18914 struct pt_regs *regs = get_irq_regs();
18915- return regs && user_mode_vm(regs);
18916+ return regs && user_mode(regs);
18917 }
18918
18919 /*
18920diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18921index 9a5c460..dc4374d 100644
18922--- a/arch/x86/kernel/i8259.c
18923+++ b/arch/x86/kernel/i8259.c
18924@@ -209,7 +209,7 @@ spurious_8259A_irq:
18925 "spurious 8259A interrupt: IRQ%d.\n", irq);
18926 spurious_irq_mask |= irqmask;
18927 }
18928- atomic_inc(&irq_err_count);
18929+ atomic_inc_unchecked(&irq_err_count);
18930 /*
18931 * Theoretically we do not have to handle this IRQ,
18932 * but in Linux this does not cause problems and is
18933diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18934index 8c96897..be66bfa 100644
18935--- a/arch/x86/kernel/ioport.c
18936+++ b/arch/x86/kernel/ioport.c
18937@@ -6,6 +6,7 @@
18938 #include <linux/sched.h>
18939 #include <linux/kernel.h>
18940 #include <linux/capability.h>
18941+#include <linux/security.h>
18942 #include <linux/errno.h>
18943 #include <linux/types.h>
18944 #include <linux/ioport.h>
18945@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18946
18947 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18948 return -EINVAL;
18949+#ifdef CONFIG_GRKERNSEC_IO
18950+ if (turn_on && grsec_disable_privio) {
18951+ gr_handle_ioperm();
18952+ return -EPERM;
18953+ }
18954+#endif
18955 if (turn_on && !capable(CAP_SYS_RAWIO))
18956 return -EPERM;
18957
18958@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18959 * because the ->io_bitmap_max value must match the bitmap
18960 * contents:
18961 */
18962- tss = &per_cpu(init_tss, get_cpu());
18963+ tss = init_tss + get_cpu();
18964
18965 if (turn_on)
18966 bitmap_clear(t->io_bitmap_ptr, from, num);
18967@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18968 return -EINVAL;
18969 /* Trying to gain more privileges? */
18970 if (level > old) {
18971+#ifdef CONFIG_GRKERNSEC_IO
18972+ if (grsec_disable_privio) {
18973+ gr_handle_iopl();
18974+ return -EPERM;
18975+ }
18976+#endif
18977 if (!capable(CAP_SYS_RAWIO))
18978 return -EPERM;
18979 }
18980diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18981index e4595f1..ee3bfb8 100644
18982--- a/arch/x86/kernel/irq.c
18983+++ b/arch/x86/kernel/irq.c
18984@@ -18,7 +18,7 @@
18985 #include <asm/mce.h>
18986 #include <asm/hw_irq.h>
18987
18988-atomic_t irq_err_count;
18989+atomic_unchecked_t irq_err_count;
18990
18991 /* Function pointer for generic interrupt vector handling */
18992 void (*x86_platform_ipi_callback)(void) = NULL;
18993@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18994 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18995 seq_printf(p, " Machine check polls\n");
18996 #endif
18997- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18998+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18999 #if defined(CONFIG_X86_IO_APIC)
19000- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
19001+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
19002 #endif
19003 return 0;
19004 }
19005@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
19006
19007 u64 arch_irq_stat(void)
19008 {
19009- u64 sum = atomic_read(&irq_err_count);
19010+ u64 sum = atomic_read_unchecked(&irq_err_count);
19011
19012 #ifdef CONFIG_X86_IO_APIC
19013- sum += atomic_read(&irq_mis_count);
19014+ sum += atomic_read_unchecked(&irq_mis_count);
19015 #endif
19016 return sum;
19017 }
19018diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
19019index 344faf8..355f60d 100644
19020--- a/arch/x86/kernel/irq_32.c
19021+++ b/arch/x86/kernel/irq_32.c
19022@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
19023 __asm__ __volatile__("andl %%esp,%0" :
19024 "=r" (sp) : "0" (THREAD_SIZE - 1));
19025
19026- return sp < (sizeof(struct thread_info) + STACK_WARN);
19027+ return sp < STACK_WARN;
19028 }
19029
19030 static void print_stack_overflow(void)
19031@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
19032 * per-CPU IRQ handling contexts (thread information and stack)
19033 */
19034 union irq_ctx {
19035- struct thread_info tinfo;
19036- u32 stack[THREAD_SIZE/sizeof(u32)];
19037+ unsigned long previous_esp;
19038+ u32 stack[THREAD_SIZE/sizeof(u32)];
19039 } __attribute__((aligned(THREAD_SIZE)));
19040
19041 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
19042@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
19043 static inline int
19044 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19045 {
19046- union irq_ctx *curctx, *irqctx;
19047+ union irq_ctx *irqctx;
19048 u32 *isp, arg1, arg2;
19049
19050- curctx = (union irq_ctx *) current_thread_info();
19051 irqctx = __this_cpu_read(hardirq_ctx);
19052
19053 /*
19054@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19055 * handler) we can't do that and just have to keep using the
19056 * current stack (which is the irq stack already after all)
19057 */
19058- if (unlikely(curctx == irqctx))
19059+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
19060 return 0;
19061
19062 /* build the stack frame on the IRQ stack */
19063- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19064- irqctx->tinfo.task = curctx->tinfo.task;
19065- irqctx->tinfo.previous_esp = current_stack_pointer;
19066+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19067+ irqctx->previous_esp = current_stack_pointer;
19068
19069- /* Copy the preempt_count so that the [soft]irq checks work. */
19070- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
19071+#ifdef CONFIG_PAX_MEMORY_UDEREF
19072+ __set_fs(MAKE_MM_SEG(0));
19073+#endif
19074
19075 if (unlikely(overflow))
19076 call_on_stack(print_stack_overflow, isp);
19077@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19078 : "0" (irq), "1" (desc), "2" (isp),
19079 "D" (desc->handle_irq)
19080 : "memory", "cc", "ecx");
19081+
19082+#ifdef CONFIG_PAX_MEMORY_UDEREF
19083+ __set_fs(current_thread_info()->addr_limit);
19084+#endif
19085+
19086 return 1;
19087 }
19088
19089@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
19090 */
19091 void __cpuinit irq_ctx_init(int cpu)
19092 {
19093- union irq_ctx *irqctx;
19094-
19095 if (per_cpu(hardirq_ctx, cpu))
19096 return;
19097
19098- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19099- THREADINFO_GFP,
19100- THREAD_SIZE_ORDER));
19101- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19102- irqctx->tinfo.cpu = cpu;
19103- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
19104- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19105-
19106- per_cpu(hardirq_ctx, cpu) = irqctx;
19107-
19108- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
19109- THREADINFO_GFP,
19110- THREAD_SIZE_ORDER));
19111- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
19112- irqctx->tinfo.cpu = cpu;
19113- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
19114-
19115- per_cpu(softirq_ctx, cpu) = irqctx;
19116+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19117+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
19118+
19119+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19120+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19121
19122 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
19123 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
19124@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
19125 asmlinkage void do_softirq(void)
19126 {
19127 unsigned long flags;
19128- struct thread_info *curctx;
19129 union irq_ctx *irqctx;
19130 u32 *isp;
19131
19132@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
19133 local_irq_save(flags);
19134
19135 if (local_softirq_pending()) {
19136- curctx = current_thread_info();
19137 irqctx = __this_cpu_read(softirq_ctx);
19138- irqctx->tinfo.task = curctx->task;
19139- irqctx->tinfo.previous_esp = current_stack_pointer;
19140+ irqctx->previous_esp = current_stack_pointer;
19141
19142 /* build the stack frame on the softirq stack */
19143- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
19144+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
19145+
19146+#ifdef CONFIG_PAX_MEMORY_UDEREF
19147+ __set_fs(MAKE_MM_SEG(0));
19148+#endif
19149
19150 call_on_stack(__do_softirq, isp);
19151+
19152+#ifdef CONFIG_PAX_MEMORY_UDEREF
19153+ __set_fs(current_thread_info()->addr_limit);
19154+#endif
19155+
19156 /*
19157 * Shouldn't happen, we returned above if in_interrupt():
19158 */
19159@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
19160 if (unlikely(!desc))
19161 return false;
19162
19163- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19164+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
19165 if (unlikely(overflow))
19166 print_stack_overflow();
19167 desc->handle_irq(irq, desc);
19168diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
19169index d04d3ec..ea4b374 100644
19170--- a/arch/x86/kernel/irq_64.c
19171+++ b/arch/x86/kernel/irq_64.c
19172@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
19173 u64 estack_top, estack_bottom;
19174 u64 curbase = (u64)task_stack_page(current);
19175
19176- if (user_mode_vm(regs))
19177+ if (user_mode(regs))
19178 return;
19179
19180 if (regs->sp >= curbase + sizeof(struct thread_info) +
19181diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19182index dc1404b..bbc43e7 100644
19183--- a/arch/x86/kernel/kdebugfs.c
19184+++ b/arch/x86/kernel/kdebugfs.c
19185@@ -27,7 +27,7 @@ struct setup_data_node {
19186 u32 len;
19187 };
19188
19189-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19190+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19191 size_t count, loff_t *ppos)
19192 {
19193 struct setup_data_node *node = file->private_data;
19194diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19195index 836f832..a8bda67 100644
19196--- a/arch/x86/kernel/kgdb.c
19197+++ b/arch/x86/kernel/kgdb.c
19198@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19199 #ifdef CONFIG_X86_32
19200 switch (regno) {
19201 case GDB_SS:
19202- if (!user_mode_vm(regs))
19203+ if (!user_mode(regs))
19204 *(unsigned long *)mem = __KERNEL_DS;
19205 break;
19206 case GDB_SP:
19207- if (!user_mode_vm(regs))
19208+ if (!user_mode(regs))
19209 *(unsigned long *)mem = kernel_stack_pointer(regs);
19210 break;
19211 case GDB_GS:
19212@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19213 bp->attr.bp_addr = breakinfo[breakno].addr;
19214 bp->attr.bp_len = breakinfo[breakno].len;
19215 bp->attr.bp_type = breakinfo[breakno].type;
19216- info->address = breakinfo[breakno].addr;
19217+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19218+ info->address = ktla_ktva(breakinfo[breakno].addr);
19219+ else
19220+ info->address = breakinfo[breakno].addr;
19221 info->len = breakinfo[breakno].len;
19222 info->type = breakinfo[breakno].type;
19223 val = arch_install_hw_breakpoint(bp);
19224@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19225 case 'k':
19226 /* clear the trace bit */
19227 linux_regs->flags &= ~X86_EFLAGS_TF;
19228- atomic_set(&kgdb_cpu_doing_single_step, -1);
19229+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19230
19231 /* set the trace bit if we're stepping */
19232 if (remcomInBuffer[0] == 's') {
19233 linux_regs->flags |= X86_EFLAGS_TF;
19234- atomic_set(&kgdb_cpu_doing_single_step,
19235+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19236 raw_smp_processor_id());
19237 }
19238
19239@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19240
19241 switch (cmd) {
19242 case DIE_DEBUG:
19243- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19244+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19245 if (user_mode(regs))
19246 return single_step_cont(regs, args);
19247 break;
19248@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19249 #endif /* CONFIG_DEBUG_RODATA */
19250
19251 bpt->type = BP_BREAKPOINT;
19252- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19253+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19254 BREAK_INSTR_SIZE);
19255 if (err)
19256 return err;
19257- err = probe_kernel_write((char *)bpt->bpt_addr,
19258+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19259 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19260 #ifdef CONFIG_DEBUG_RODATA
19261 if (!err)
19262@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19263 return -EBUSY;
19264 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19265 BREAK_INSTR_SIZE);
19266- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19267+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19268 if (err)
19269 return err;
19270 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19271@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19272 if (mutex_is_locked(&text_mutex))
19273 goto knl_write;
19274 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19275- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19276+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19277 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19278 goto knl_write;
19279 return err;
19280 knl_write:
19281 #endif /* CONFIG_DEBUG_RODATA */
19282- return probe_kernel_write((char *)bpt->bpt_addr,
19283+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19284 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19285 }
19286
19287diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19288index c5e410e..ed5a7f0 100644
19289--- a/arch/x86/kernel/kprobes-opt.c
19290+++ b/arch/x86/kernel/kprobes-opt.c
19291@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19292 * Verify if the address gap is in 2GB range, because this uses
19293 * a relative jump.
19294 */
19295- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19296+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19297 if (abs(rel) > 0x7fffffff)
19298 return -ERANGE;
19299
19300@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19301 op->optinsn.size = ret;
19302
19303 /* Copy arch-dep-instance from template */
19304- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19305+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19306
19307 /* Set probe information */
19308 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19309
19310 /* Set probe function call */
19311- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19312+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19313
19314 /* Set returning jmp instruction at the tail of out-of-line buffer */
19315- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19316+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19317 (u8 *)op->kp.addr + op->optinsn.size);
19318
19319 flush_icache_range((unsigned long) buf,
19320@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19321 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19322
19323 /* Backup instructions which will be replaced by jump address */
19324- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19325+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19326 RELATIVE_ADDR_SIZE);
19327
19328 insn_buf[0] = RELATIVEJUMP_OPCODE;
19329@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19330 /* This kprobe is really able to run optimized path. */
19331 op = container_of(p, struct optimized_kprobe, kp);
19332 /* Detour through copied instructions */
19333- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19334+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19335 if (!reenter)
19336 reset_current_kprobe();
19337 preempt_enable_no_resched();
19338diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19339index 57916c0..9e0b9d0 100644
19340--- a/arch/x86/kernel/kprobes.c
19341+++ b/arch/x86/kernel/kprobes.c
19342@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19343 s32 raddr;
19344 } __attribute__((packed)) *insn;
19345
19346- insn = (struct __arch_relative_insn *)from;
19347+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
19348+
19349+ pax_open_kernel();
19350 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19351 insn->op = op;
19352+ pax_close_kernel();
19353 }
19354
19355 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19356@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19357 kprobe_opcode_t opcode;
19358 kprobe_opcode_t *orig_opcodes = opcodes;
19359
19360- if (search_exception_tables((unsigned long)opcodes))
19361+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19362 return 0; /* Page fault may occur on this address. */
19363
19364 retry:
19365@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19366 * for the first byte, we can recover the original instruction
19367 * from it and kp->opcode.
19368 */
19369- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19370+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19371 buf[0] = kp->opcode;
19372- return (unsigned long)buf;
19373+ return ktva_ktla((unsigned long)buf);
19374 }
19375
19376 /*
19377@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19378 /* Another subsystem puts a breakpoint, failed to recover */
19379 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19380 return 0;
19381+ pax_open_kernel();
19382 memcpy(dest, insn.kaddr, insn.length);
19383+ pax_close_kernel();
19384
19385 #ifdef CONFIG_X86_64
19386 if (insn_rip_relative(&insn)) {
19387@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19388 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19389 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19390 disp = (u8 *) dest + insn_offset_displacement(&insn);
19391+ pax_open_kernel();
19392 *(s32 *) disp = (s32) newdisp;
19393+ pax_close_kernel();
19394 }
19395 #endif
19396 return insn.length;
19397@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19398 * nor set current_kprobe, because it doesn't use single
19399 * stepping.
19400 */
19401- regs->ip = (unsigned long)p->ainsn.insn;
19402+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19403 preempt_enable_no_resched();
19404 return;
19405 }
19406@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19407 regs->flags &= ~X86_EFLAGS_IF;
19408 /* single step inline if the instruction is an int3 */
19409 if (p->opcode == BREAKPOINT_INSTRUCTION)
19410- regs->ip = (unsigned long)p->addr;
19411+ regs->ip = ktla_ktva((unsigned long)p->addr);
19412 else
19413- regs->ip = (unsigned long)p->ainsn.insn;
19414+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19415 }
19416
19417 /*
19418@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19419 setup_singlestep(p, regs, kcb, 0);
19420 return 1;
19421 }
19422- } else if (*addr != BREAKPOINT_INSTRUCTION) {
19423+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19424 /*
19425 * The breakpoint instruction was removed right
19426 * after we hit it. Another cpu has removed
19427@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19428 " movq %rax, 152(%rsp)\n"
19429 RESTORE_REGS_STRING
19430 " popfq\n"
19431+#ifdef KERNEXEC_PLUGIN
19432+ " btsq $63,(%rsp)\n"
19433+#endif
19434 #else
19435 " pushf\n"
19436 SAVE_REGS_STRING
19437@@ -788,7 +798,7 @@ static void __kprobes
19438 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19439 {
19440 unsigned long *tos = stack_addr(regs);
19441- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19442+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19443 unsigned long orig_ip = (unsigned long)p->addr;
19444 kprobe_opcode_t *insn = p->ainsn.insn;
19445
19446@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19447 struct die_args *args = data;
19448 int ret = NOTIFY_DONE;
19449
19450- if (args->regs && user_mode_vm(args->regs))
19451+ if (args->regs && user_mode(args->regs))
19452 return ret;
19453
19454 switch (val) {
19455diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19456index ebc9873..1b9724b 100644
19457--- a/arch/x86/kernel/ldt.c
19458+++ b/arch/x86/kernel/ldt.c
19459@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19460 if (reload) {
19461 #ifdef CONFIG_SMP
19462 preempt_disable();
19463- load_LDT(pc);
19464+ load_LDT_nolock(pc);
19465 if (!cpumask_equal(mm_cpumask(current->mm),
19466 cpumask_of(smp_processor_id())))
19467 smp_call_function(flush_ldt, current->mm, 1);
19468 preempt_enable();
19469 #else
19470- load_LDT(pc);
19471+ load_LDT_nolock(pc);
19472 #endif
19473 }
19474 if (oldsize) {
19475@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19476 return err;
19477
19478 for (i = 0; i < old->size; i++)
19479- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19480+ write_ldt_entry(new->ldt, i, old->ldt + i);
19481 return 0;
19482 }
19483
19484@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19485 retval = copy_ldt(&mm->context, &old_mm->context);
19486 mutex_unlock(&old_mm->context.lock);
19487 }
19488+
19489+ if (tsk == current) {
19490+ mm->context.vdso = 0;
19491+
19492+#ifdef CONFIG_X86_32
19493+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19494+ mm->context.user_cs_base = 0UL;
19495+ mm->context.user_cs_limit = ~0UL;
19496+
19497+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19498+ cpus_clear(mm->context.cpu_user_cs_mask);
19499+#endif
19500+
19501+#endif
19502+#endif
19503+
19504+ }
19505+
19506 return retval;
19507 }
19508
19509@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19510 }
19511 }
19512
19513+#ifdef CONFIG_PAX_SEGMEXEC
19514+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19515+ error = -EINVAL;
19516+ goto out_unlock;
19517+ }
19518+#endif
19519+
19520 fill_ldt(&ldt, &ldt_info);
19521 if (oldmode)
19522 ldt.avl = 0;
19523diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19524index 5b19e4d..6476a76 100644
19525--- a/arch/x86/kernel/machine_kexec_32.c
19526+++ b/arch/x86/kernel/machine_kexec_32.c
19527@@ -26,7 +26,7 @@
19528 #include <asm/cacheflush.h>
19529 #include <asm/debugreg.h>
19530
19531-static void set_idt(void *newidt, __u16 limit)
19532+static void set_idt(struct desc_struct *newidt, __u16 limit)
19533 {
19534 struct desc_ptr curidt;
19535
19536@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19537 }
19538
19539
19540-static void set_gdt(void *newgdt, __u16 limit)
19541+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19542 {
19543 struct desc_ptr curgdt;
19544
19545@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19546 }
19547
19548 control_page = page_address(image->control_code_page);
19549- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19550+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19551
19552 relocate_kernel_ptr = control_page;
19553 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19554diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19555index 3544aed..01ddc1c 100644
19556--- a/arch/x86/kernel/microcode_intel.c
19557+++ b/arch/x86/kernel/microcode_intel.c
19558@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19559
19560 static int get_ucode_user(void *to, const void *from, size_t n)
19561 {
19562- return copy_from_user(to, from, n);
19563+ return copy_from_user(to, (const void __force_user *)from, n);
19564 }
19565
19566 static enum ucode_state
19567 request_microcode_user(int cpu, const void __user *buf, size_t size)
19568 {
19569- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19570+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19571 }
19572
19573 static void microcode_fini_cpu(int cpu)
19574diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19575index 216a4d7..228255a 100644
19576--- a/arch/x86/kernel/module.c
19577+++ b/arch/x86/kernel/module.c
19578@@ -43,15 +43,60 @@ do { \
19579 } while (0)
19580 #endif
19581
19582-void *module_alloc(unsigned long size)
19583+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19584 {
19585- if (PAGE_ALIGN(size) > MODULES_LEN)
19586+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
19587 return NULL;
19588 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19589- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19590+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19591 -1, __builtin_return_address(0));
19592 }
19593
19594+void *module_alloc(unsigned long size)
19595+{
19596+
19597+#ifdef CONFIG_PAX_KERNEXEC
19598+ return __module_alloc(size, PAGE_KERNEL);
19599+#else
19600+ return __module_alloc(size, PAGE_KERNEL_EXEC);
19601+#endif
19602+
19603+}
19604+
19605+#ifdef CONFIG_PAX_KERNEXEC
19606+#ifdef CONFIG_X86_32
19607+void *module_alloc_exec(unsigned long size)
19608+{
19609+ struct vm_struct *area;
19610+
19611+ if (size == 0)
19612+ return NULL;
19613+
19614+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19615+ return area ? area->addr : NULL;
19616+}
19617+EXPORT_SYMBOL(module_alloc_exec);
19618+
19619+void module_free_exec(struct module *mod, void *module_region)
19620+{
19621+ vunmap(module_region);
19622+}
19623+EXPORT_SYMBOL(module_free_exec);
19624+#else
19625+void module_free_exec(struct module *mod, void *module_region)
19626+{
19627+ module_free(mod, module_region);
19628+}
19629+EXPORT_SYMBOL(module_free_exec);
19630+
19631+void *module_alloc_exec(unsigned long size)
19632+{
19633+ return __module_alloc(size, PAGE_KERNEL_RX);
19634+}
19635+EXPORT_SYMBOL(module_alloc_exec);
19636+#endif
19637+#endif
19638+
19639 #ifdef CONFIG_X86_32
19640 int apply_relocate(Elf32_Shdr *sechdrs,
19641 const char *strtab,
19642@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19643 unsigned int i;
19644 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19645 Elf32_Sym *sym;
19646- uint32_t *location;
19647+ uint32_t *plocation, location;
19648
19649 DEBUGP("Applying relocate section %u to %u\n",
19650 relsec, sechdrs[relsec].sh_info);
19651 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19652 /* This is where to make the change */
19653- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19654- + rel[i].r_offset;
19655+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19656+ location = (uint32_t)plocation;
19657+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19658+ plocation = ktla_ktva((void *)plocation);
19659 /* This is the symbol it is referring to. Note that all
19660 undefined symbols have been resolved. */
19661 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19662@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19663 switch (ELF32_R_TYPE(rel[i].r_info)) {
19664 case R_386_32:
19665 /* We add the value into the location given */
19666- *location += sym->st_value;
19667+ pax_open_kernel();
19668+ *plocation += sym->st_value;
19669+ pax_close_kernel();
19670 break;
19671 case R_386_PC32:
19672 /* Add the value, subtract its position */
19673- *location += sym->st_value - (uint32_t)location;
19674+ pax_open_kernel();
19675+ *plocation += sym->st_value - location;
19676+ pax_close_kernel();
19677 break;
19678 default:
19679 pr_err("%s: Unknown relocation: %u\n",
19680@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19681 case R_X86_64_NONE:
19682 break;
19683 case R_X86_64_64:
19684+ pax_open_kernel();
19685 *(u64 *)loc = val;
19686+ pax_close_kernel();
19687 break;
19688 case R_X86_64_32:
19689+ pax_open_kernel();
19690 *(u32 *)loc = val;
19691+ pax_close_kernel();
19692 if (val != *(u32 *)loc)
19693 goto overflow;
19694 break;
19695 case R_X86_64_32S:
19696+ pax_open_kernel();
19697 *(s32 *)loc = val;
19698+ pax_close_kernel();
19699 if ((s64)val != *(s32 *)loc)
19700 goto overflow;
19701 break;
19702 case R_X86_64_PC32:
19703 val -= (u64)loc;
19704+ pax_open_kernel();
19705 *(u32 *)loc = val;
19706+ pax_close_kernel();
19707+
19708 #if 0
19709 if ((s64)val != *(s32 *)loc)
19710 goto overflow;
19711diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19712index f84f5c5..e27e54b 100644
19713--- a/arch/x86/kernel/nmi.c
19714+++ b/arch/x86/kernel/nmi.c
19715@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19716 dotraplinkage notrace __kprobes void
19717 do_nmi(struct pt_regs *regs, long error_code)
19718 {
19719+
19720+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19721+ if (!user_mode(regs)) {
19722+ unsigned long cs = regs->cs & 0xFFFF;
19723+ unsigned long ip = ktva_ktla(regs->ip);
19724+
19725+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19726+ regs->ip = ip;
19727+ }
19728+#endif
19729+
19730 nmi_nesting_preprocess(regs);
19731
19732 nmi_enter();
19733diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19734index 676b8c7..870ba04 100644
19735--- a/arch/x86/kernel/paravirt-spinlocks.c
19736+++ b/arch/x86/kernel/paravirt-spinlocks.c
19737@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19738 arch_spin_lock(lock);
19739 }
19740
19741-struct pv_lock_ops pv_lock_ops = {
19742+struct pv_lock_ops pv_lock_ops __read_only = {
19743 #ifdef CONFIG_SMP
19744 .spin_is_locked = __ticket_spin_is_locked,
19745 .spin_is_contended = __ticket_spin_is_contended,
19746diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19747index 17fff18..5cfa0f4 100644
19748--- a/arch/x86/kernel/paravirt.c
19749+++ b/arch/x86/kernel/paravirt.c
19750@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19751 {
19752 return x;
19753 }
19754+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19755+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19756+#endif
19757
19758 void __init default_banner(void)
19759 {
19760@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19761 if (opfunc == NULL)
19762 /* If there's no function, patch it with a ud2a (BUG) */
19763 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19764- else if (opfunc == _paravirt_nop)
19765+ else if (opfunc == (void *)_paravirt_nop)
19766 /* If the operation is a nop, then nop the callsite */
19767 ret = paravirt_patch_nop();
19768
19769 /* identity functions just return their single argument */
19770- else if (opfunc == _paravirt_ident_32)
19771+ else if (opfunc == (void *)_paravirt_ident_32)
19772 ret = paravirt_patch_ident_32(insnbuf, len);
19773- else if (opfunc == _paravirt_ident_64)
19774+ else if (opfunc == (void *)_paravirt_ident_64)
19775 ret = paravirt_patch_ident_64(insnbuf, len);
19776+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19777+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19778+ ret = paravirt_patch_ident_64(insnbuf, len);
19779+#endif
19780
19781 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19782 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19783@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19784 if (insn_len > len || start == NULL)
19785 insn_len = len;
19786 else
19787- memcpy(insnbuf, start, insn_len);
19788+ memcpy(insnbuf, ktla_ktva(start), insn_len);
19789
19790 return insn_len;
19791 }
19792@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19793 preempt_enable();
19794 }
19795
19796-struct pv_info pv_info = {
19797+struct pv_info pv_info __read_only = {
19798 .name = "bare hardware",
19799 .paravirt_enabled = 0,
19800 .kernel_rpl = 0,
19801@@ -315,16 +322,16 @@ struct pv_info pv_info = {
19802 #endif
19803 };
19804
19805-struct pv_init_ops pv_init_ops = {
19806+struct pv_init_ops pv_init_ops __read_only = {
19807 .patch = native_patch,
19808 };
19809
19810-struct pv_time_ops pv_time_ops = {
19811+struct pv_time_ops pv_time_ops __read_only = {
19812 .sched_clock = native_sched_clock,
19813 .steal_clock = native_steal_clock,
19814 };
19815
19816-struct pv_irq_ops pv_irq_ops = {
19817+struct pv_irq_ops pv_irq_ops __read_only = {
19818 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19819 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19820 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19821@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
19822 #endif
19823 };
19824
19825-struct pv_cpu_ops pv_cpu_ops = {
19826+struct pv_cpu_ops pv_cpu_ops __read_only = {
19827 .cpuid = native_cpuid,
19828 .get_debugreg = native_get_debugreg,
19829 .set_debugreg = native_set_debugreg,
19830@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
19831 .end_context_switch = paravirt_nop,
19832 };
19833
19834-struct pv_apic_ops pv_apic_ops = {
19835+struct pv_apic_ops pv_apic_ops __read_only= {
19836 #ifdef CONFIG_X86_LOCAL_APIC
19837 .startup_ipi_hook = paravirt_nop,
19838 #endif
19839 };
19840
19841-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19842+#ifdef CONFIG_X86_32
19843+#ifdef CONFIG_X86_PAE
19844+/* 64-bit pagetable entries */
19845+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19846+#else
19847 /* 32-bit pagetable entries */
19848 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19849+#endif
19850 #else
19851 /* 64-bit pagetable entries */
19852 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19853 #endif
19854
19855-struct pv_mmu_ops pv_mmu_ops = {
19856+struct pv_mmu_ops pv_mmu_ops __read_only = {
19857
19858 .read_cr2 = native_read_cr2,
19859 .write_cr2 = native_write_cr2,
19860@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19861 .make_pud = PTE_IDENT,
19862
19863 .set_pgd = native_set_pgd,
19864+ .set_pgd_batched = native_set_pgd_batched,
19865 #endif
19866 #endif /* PAGETABLE_LEVELS >= 3 */
19867
19868@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19869 },
19870
19871 .set_fixmap = native_set_fixmap,
19872+
19873+#ifdef CONFIG_PAX_KERNEXEC
19874+ .pax_open_kernel = native_pax_open_kernel,
19875+ .pax_close_kernel = native_pax_close_kernel,
19876+#endif
19877+
19878 };
19879
19880 EXPORT_SYMBOL_GPL(pv_time_ops);
19881diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19882index 35ccf75..7a15747 100644
19883--- a/arch/x86/kernel/pci-iommu_table.c
19884+++ b/arch/x86/kernel/pci-iommu_table.c
19885@@ -2,7 +2,7 @@
19886 #include <asm/iommu_table.h>
19887 #include <linux/string.h>
19888 #include <linux/kallsyms.h>
19889-
19890+#include <linux/sched.h>
19891
19892 #define DEBUG 1
19893
19894diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19895index b644e1c..4a6d379 100644
19896--- a/arch/x86/kernel/process.c
19897+++ b/arch/x86/kernel/process.c
19898@@ -36,7 +36,8 @@
19899 * section. Since TSS's are completely CPU-local, we want them
19900 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19901 */
19902-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19903+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19904+EXPORT_SYMBOL(init_tss);
19905
19906 #ifdef CONFIG_X86_64
19907 static DEFINE_PER_CPU(unsigned char, is_idle);
19908@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19909 task_xstate_cachep =
19910 kmem_cache_create("task_xstate", xstate_size,
19911 __alignof__(union thread_xstate),
19912- SLAB_PANIC | SLAB_NOTRACK, NULL);
19913+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19914 }
19915
19916 /*
19917@@ -105,7 +106,7 @@ void exit_thread(void)
19918 unsigned long *bp = t->io_bitmap_ptr;
19919
19920 if (bp) {
19921- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19922+ struct tss_struct *tss = init_tss + get_cpu();
19923
19924 t->io_bitmap_ptr = NULL;
19925 clear_thread_flag(TIF_IO_BITMAP);
19926@@ -136,7 +137,7 @@ void show_regs_common(void)
19927 board = dmi_get_system_info(DMI_BOARD_NAME);
19928
19929 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19930- current->pid, current->comm, print_tainted(),
19931+ task_pid_nr(current), current->comm, print_tainted(),
19932 init_utsname()->release,
19933 (int)strcspn(init_utsname()->version, " "),
19934 init_utsname()->version,
19935@@ -149,6 +150,9 @@ void flush_thread(void)
19936 {
19937 struct task_struct *tsk = current;
19938
19939+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19940+ loadsegment(gs, 0);
19941+#endif
19942 flush_ptrace_hw_breakpoint(tsk);
19943 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19944 drop_init_fpu(tsk);
19945@@ -336,7 +340,7 @@ static void __exit_idle(void)
19946 void exit_idle(void)
19947 {
19948 /* idle loop has pid 0 */
19949- if (current->pid)
19950+ if (task_pid_nr(current))
19951 return;
19952 __exit_idle();
19953 }
19954@@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19955
19956 return ret;
19957 }
19958-void stop_this_cpu(void *dummy)
19959+__noreturn void stop_this_cpu(void *dummy)
19960 {
19961 local_irq_disable();
19962 /*
19963@@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19964 }
19965 early_param("idle", idle_setup);
19966
19967-unsigned long arch_align_stack(unsigned long sp)
19968+#ifdef CONFIG_PAX_RANDKSTACK
19969+void pax_randomize_kstack(struct pt_regs *regs)
19970 {
19971- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19972- sp -= get_random_int() % 8192;
19973- return sp & ~0xf;
19974-}
19975+ struct thread_struct *thread = &current->thread;
19976+ unsigned long time;
19977
19978-unsigned long arch_randomize_brk(struct mm_struct *mm)
19979-{
19980- unsigned long range_end = mm->brk + 0x02000000;
19981- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19982-}
19983+ if (!randomize_va_space)
19984+ return;
19985+
19986+ if (v8086_mode(regs))
19987+ return;
19988
19989+ rdtscl(time);
19990+
19991+ /* P4 seems to return a 0 LSB, ignore it */
19992+#ifdef CONFIG_MPENTIUM4
19993+ time &= 0x3EUL;
19994+ time <<= 2;
19995+#elif defined(CONFIG_X86_64)
19996+ time &= 0xFUL;
19997+ time <<= 4;
19998+#else
19999+ time &= 0x1FUL;
20000+ time <<= 3;
20001+#endif
20002+
20003+ thread->sp0 ^= time;
20004+ load_sp0(init_tss + smp_processor_id(), thread);
20005+
20006+#ifdef CONFIG_X86_64
20007+ this_cpu_write(kernel_stack, thread->sp0);
20008+#endif
20009+}
20010+#endif
20011diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
20012index 44e0bff..5ceb99c 100644
20013--- a/arch/x86/kernel/process_32.c
20014+++ b/arch/x86/kernel/process_32.c
20015@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
20016 unsigned long thread_saved_pc(struct task_struct *tsk)
20017 {
20018 return ((unsigned long *)tsk->thread.sp)[3];
20019+//XXX return tsk->thread.eip;
20020 }
20021
20022 void __show_regs(struct pt_regs *regs, int all)
20023@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
20024 unsigned long sp;
20025 unsigned short ss, gs;
20026
20027- if (user_mode_vm(regs)) {
20028+ if (user_mode(regs)) {
20029 sp = regs->sp;
20030 ss = regs->ss & 0xffff;
20031- gs = get_user_gs(regs);
20032 } else {
20033 sp = kernel_stack_pointer(regs);
20034 savesegment(ss, ss);
20035- savesegment(gs, gs);
20036 }
20037+ gs = get_user_gs(regs);
20038
20039 show_regs_common();
20040
20041 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
20042 (u16)regs->cs, regs->ip, regs->flags,
20043- smp_processor_id());
20044+ raw_smp_processor_id());
20045 print_symbol("EIP is at %s\n", regs->ip);
20046
20047 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
20048@@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20049 unsigned long arg,
20050 struct task_struct *p, struct pt_regs *regs)
20051 {
20052- struct pt_regs *childregs = task_pt_regs(p);
20053+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
20054 struct task_struct *tsk;
20055 int err;
20056
20057 p->thread.sp = (unsigned long) childregs;
20058 p->thread.sp0 = (unsigned long) (childregs+1);
20059+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20060
20061 if (unlikely(!regs)) {
20062 /* kernel thread */
20063 memset(childregs, 0, sizeof(struct pt_regs));
20064 p->thread.ip = (unsigned long) ret_from_kernel_thread;
20065- task_user_gs(p) = __KERNEL_STACK_CANARY;
20066- childregs->ds = __USER_DS;
20067- childregs->es = __USER_DS;
20068+ savesegment(gs, childregs->gs);
20069+ childregs->ds = __KERNEL_DS;
20070+ childregs->es = __KERNEL_DS;
20071 childregs->fs = __KERNEL_PERCPU;
20072 childregs->bx = sp; /* function */
20073 childregs->bp = arg;
20074@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20075 struct thread_struct *prev = &prev_p->thread,
20076 *next = &next_p->thread;
20077 int cpu = smp_processor_id();
20078- struct tss_struct *tss = &per_cpu(init_tss, cpu);
20079+ struct tss_struct *tss = init_tss + cpu;
20080 fpu_switch_t fpu;
20081
20082 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
20083@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20084 */
20085 lazy_save_gs(prev->gs);
20086
20087+#ifdef CONFIG_PAX_MEMORY_UDEREF
20088+ __set_fs(task_thread_info(next_p)->addr_limit);
20089+#endif
20090+
20091 /*
20092 * Load the per-thread Thread-Local Storage descriptor.
20093 */
20094@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20095 */
20096 arch_end_context_switch(next_p);
20097
20098+ this_cpu_write(current_task, next_p);
20099+ this_cpu_write(current_tinfo, &next_p->tinfo);
20100+
20101 /*
20102 * Restore %gs if needed (which is common)
20103 */
20104@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20105
20106 switch_fpu_finish(next_p, fpu);
20107
20108- this_cpu_write(current_task, next_p);
20109-
20110 return prev_p;
20111 }
20112
20113@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
20114 } while (count++ < 16);
20115 return 0;
20116 }
20117-
20118diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
20119index 16c6365..5d32218 100644
20120--- a/arch/x86/kernel/process_64.c
20121+++ b/arch/x86/kernel/process_64.c
20122@@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20123 struct pt_regs *childregs;
20124 struct task_struct *me = current;
20125
20126- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20127+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20128 childregs = task_pt_regs(p);
20129 p->thread.sp = (unsigned long) childregs;
20130 p->thread.usersp = me->thread.usersp;
20131+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20132 set_tsk_thread_flag(p, TIF_FORK);
20133 p->fpu_counter = 0;
20134 p->thread.io_bitmap_ptr = NULL;
20135@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20136 struct thread_struct *prev = &prev_p->thread;
20137 struct thread_struct *next = &next_p->thread;
20138 int cpu = smp_processor_id();
20139- struct tss_struct *tss = &per_cpu(init_tss, cpu);
20140+ struct tss_struct *tss = init_tss + cpu;
20141 unsigned fsindex, gsindex;
20142 fpu_switch_t fpu;
20143
20144@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20145 prev->usersp = this_cpu_read(old_rsp);
20146 this_cpu_write(old_rsp, next->usersp);
20147 this_cpu_write(current_task, next_p);
20148+ this_cpu_write(current_tinfo, &next_p->tinfo);
20149
20150- this_cpu_write(kernel_stack,
20151- (unsigned long)task_stack_page(next_p) +
20152- THREAD_SIZE - KERNEL_STACK_OFFSET);
20153+ this_cpu_write(kernel_stack, next->sp0);
20154
20155 /*
20156 * Now maybe reload the debug registers and handle I/O bitmaps
20157@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20158 if (!p || p == current || p->state == TASK_RUNNING)
20159 return 0;
20160 stack = (unsigned long)task_stack_page(p);
20161- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20162+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20163 return 0;
20164 fp = *(u64 *)(p->thread.sp);
20165 do {
20166- if (fp < (unsigned long)stack ||
20167- fp >= (unsigned long)stack+THREAD_SIZE)
20168+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20169 return 0;
20170 ip = *(u64 *)(fp+8);
20171 if (!in_sched_functions(ip))
20172diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20173index 974b67e..53bdb6c 100644
20174--- a/arch/x86/kernel/ptrace.c
20175+++ b/arch/x86/kernel/ptrace.c
20176@@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20177 {
20178 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20179 unsigned long sp = (unsigned long)&regs->sp;
20180- struct thread_info *tinfo;
20181
20182- if (context == (sp & ~(THREAD_SIZE - 1)))
20183+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20184 return sp;
20185
20186- tinfo = (struct thread_info *)context;
20187- if (tinfo->previous_esp)
20188- return tinfo->previous_esp;
20189+ sp = *(unsigned long *)context;
20190+ if (sp)
20191+ return sp;
20192
20193 return (unsigned long)regs;
20194 }
20195@@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20196 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20197 {
20198 int i;
20199- int dr7 = 0;
20200+ unsigned long dr7 = 0;
20201 struct arch_hw_breakpoint *info;
20202
20203 for (i = 0; i < HBP_NUM; i++) {
20204@@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20205 unsigned long addr, unsigned long data)
20206 {
20207 int ret;
20208- unsigned long __user *datap = (unsigned long __user *)data;
20209+ unsigned long __user *datap = (__force unsigned long __user *)data;
20210
20211 switch (request) {
20212 /* read the word at location addr in the USER area. */
20213@@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20214 if ((int) addr < 0)
20215 return -EIO;
20216 ret = do_get_thread_area(child, addr,
20217- (struct user_desc __user *)data);
20218+ (__force struct user_desc __user *) data);
20219 break;
20220
20221 case PTRACE_SET_THREAD_AREA:
20222 if ((int) addr < 0)
20223 return -EIO;
20224 ret = do_set_thread_area(child, addr,
20225- (struct user_desc __user *)data, 0);
20226+ (__force struct user_desc __user *) data, 0);
20227 break;
20228 #endif
20229
20230@@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20231
20232 #ifdef CONFIG_X86_64
20233
20234-static struct user_regset x86_64_regsets[] __read_mostly = {
20235+static user_regset_no_const x86_64_regsets[] __read_only = {
20236 [REGSET_GENERAL] = {
20237 .core_note_type = NT_PRSTATUS,
20238 .n = sizeof(struct user_regs_struct) / sizeof(long),
20239@@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20240 #endif /* CONFIG_X86_64 */
20241
20242 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20243-static struct user_regset x86_32_regsets[] __read_mostly = {
20244+static user_regset_no_const x86_32_regsets[] __read_only = {
20245 [REGSET_GENERAL] = {
20246 .core_note_type = NT_PRSTATUS,
20247 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20248@@ -1419,7 +1418,7 @@ static const struct user_regset_view user_x86_32_view = {
20249 */
20250 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20251
20252-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20253+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20254 {
20255 #ifdef CONFIG_X86_64
20256 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20257@@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20258 memset(info, 0, sizeof(*info));
20259 info->si_signo = SIGTRAP;
20260 info->si_code = si_code;
20261- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20262+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20263 }
20264
20265 void user_single_step_siginfo(struct task_struct *tsk,
20266@@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20267 # define IS_IA32 0
20268 #endif
20269
20270+#ifdef CONFIG_GRKERNSEC_SETXID
20271+extern void gr_delayed_cred_worker(void);
20272+#endif
20273+
20274 /*
20275 * We must return the syscall number to actually look up in the table.
20276 * This can be -1L to skip running any syscall at all.
20277@@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20278
20279 rcu_user_exit();
20280
20281+#ifdef CONFIG_GRKERNSEC_SETXID
20282+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20283+ gr_delayed_cred_worker();
20284+#endif
20285+
20286 /*
20287 * If we stepped into a sysenter/syscall insn, it trapped in
20288 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20289@@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20290 */
20291 rcu_user_exit();
20292
20293+#ifdef CONFIG_GRKERNSEC_SETXID
20294+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20295+ gr_delayed_cred_worker();
20296+#endif
20297+
20298 audit_syscall_exit(regs);
20299
20300 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20301diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20302index 42eb330..139955c 100644
20303--- a/arch/x86/kernel/pvclock.c
20304+++ b/arch/x86/kernel/pvclock.c
20305@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20306 return pv_tsc_khz;
20307 }
20308
20309-static atomic64_t last_value = ATOMIC64_INIT(0);
20310+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20311
20312 void pvclock_resume(void)
20313 {
20314- atomic64_set(&last_value, 0);
20315+ atomic64_set_unchecked(&last_value, 0);
20316 }
20317
20318 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20319@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20320 * updating at the same time, and one of them could be slightly behind,
20321 * making the assumption that last_value always go forward fail to hold.
20322 */
20323- last = atomic64_read(&last_value);
20324+ last = atomic64_read_unchecked(&last_value);
20325 do {
20326 if (ret < last)
20327 return last;
20328- last = atomic64_cmpxchg(&last_value, last, ret);
20329+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20330 } while (unlikely(last != ret));
20331
20332 return ret;
20333diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20334index 76fa1e9..abf09ea 100644
20335--- a/arch/x86/kernel/reboot.c
20336+++ b/arch/x86/kernel/reboot.c
20337@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20338 EXPORT_SYMBOL(pm_power_off);
20339
20340 static const struct desc_ptr no_idt = {};
20341-static int reboot_mode;
20342+static unsigned short reboot_mode;
20343 enum reboot_type reboot_type = BOOT_ACPI;
20344 int reboot_force;
20345
20346@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20347
20348 void __noreturn machine_real_restart(unsigned int type)
20349 {
20350+
20351+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20352+ struct desc_struct *gdt;
20353+#endif
20354+
20355 local_irq_disable();
20356
20357 /*
20358@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20359
20360 /* Jump to the identity-mapped low memory code */
20361 #ifdef CONFIG_X86_32
20362- asm volatile("jmpl *%0" : :
20363+
20364+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20365+ gdt = get_cpu_gdt_table(smp_processor_id());
20366+ pax_open_kernel();
20367+#ifdef CONFIG_PAX_MEMORY_UDEREF
20368+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20369+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20370+ loadsegment(ds, __KERNEL_DS);
20371+ loadsegment(es, __KERNEL_DS);
20372+ loadsegment(ss, __KERNEL_DS);
20373+#endif
20374+#ifdef CONFIG_PAX_KERNEXEC
20375+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20376+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20377+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20378+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20379+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20380+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20381+#endif
20382+ pax_close_kernel();
20383+#endif
20384+
20385+ asm volatile("ljmpl *%0" : :
20386 "rm" (real_mode_header->machine_real_restart_asm),
20387 "a" (type));
20388 #else
20389@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20390 * try to force a triple fault and then cycle between hitting the keyboard
20391 * controller and doing that
20392 */
20393-static void native_machine_emergency_restart(void)
20394+static void __noreturn native_machine_emergency_restart(void)
20395 {
20396 int i;
20397 int attempt = 0;
20398@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20399 #endif
20400 }
20401
20402-static void __machine_emergency_restart(int emergency)
20403+static void __noreturn __machine_emergency_restart(int emergency)
20404 {
20405 reboot_emergency = emergency;
20406 machine_ops.emergency_restart();
20407 }
20408
20409-static void native_machine_restart(char *__unused)
20410+static void __noreturn native_machine_restart(char *__unused)
20411 {
20412 pr_notice("machine restart\n");
20413
20414@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20415 __machine_emergency_restart(0);
20416 }
20417
20418-static void native_machine_halt(void)
20419+static void __noreturn native_machine_halt(void)
20420 {
20421 /* Stop other cpus and apics */
20422 machine_shutdown();
20423@@ -679,7 +706,7 @@ static void native_machine_halt(void)
20424 stop_this_cpu(NULL);
20425 }
20426
20427-static void native_machine_power_off(void)
20428+static void __noreturn native_machine_power_off(void)
20429 {
20430 if (pm_power_off) {
20431 if (!reboot_force)
20432@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
20433 }
20434 /* A fallback in case there is no PM info available */
20435 tboot_shutdown(TB_SHUTDOWN_HALT);
20436+ unreachable();
20437 }
20438
20439-struct machine_ops machine_ops = {
20440+struct machine_ops machine_ops __read_only = {
20441 .power_off = native_machine_power_off,
20442 .shutdown = native_machine_shutdown,
20443 .emergency_restart = native_machine_emergency_restart,
20444diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20445index 7a6f3b3..bed145d7 100644
20446--- a/arch/x86/kernel/relocate_kernel_64.S
20447+++ b/arch/x86/kernel/relocate_kernel_64.S
20448@@ -11,6 +11,7 @@
20449 #include <asm/kexec.h>
20450 #include <asm/processor-flags.h>
20451 #include <asm/pgtable_types.h>
20452+#include <asm/alternative-asm.h>
20453
20454 /*
20455 * Must be relocatable PIC code callable as a C function
20456@@ -160,13 +161,14 @@ identity_mapped:
20457 xorq %rbp, %rbp
20458 xorq %r8, %r8
20459 xorq %r9, %r9
20460- xorq %r10, %r9
20461+ xorq %r10, %r10
20462 xorq %r11, %r11
20463 xorq %r12, %r12
20464 xorq %r13, %r13
20465 xorq %r14, %r14
20466 xorq %r15, %r15
20467
20468+ pax_force_retaddr 0, 1
20469 ret
20470
20471 1:
20472diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20473index aeacb0e..f9d4c02 100644
20474--- a/arch/x86/kernel/setup.c
20475+++ b/arch/x86/kernel/setup.c
20476@@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20477
20478 switch (data->type) {
20479 case SETUP_E820_EXT:
20480- parse_e820_ext(data);
20481+ parse_e820_ext((struct setup_data __force_kernel *)data);
20482 break;
20483 case SETUP_DTB:
20484 add_dtb(pa_data);
20485@@ -710,7 +710,7 @@ static void __init trim_bios_range(void)
20486 * area (640->1Mb) as ram even though it is not.
20487 * take them out.
20488 */
20489- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20490+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20491
20492 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20493 }
20494@@ -834,14 +834,14 @@ void __init setup_arch(char **cmdline_p)
20495
20496 if (!boot_params.hdr.root_flags)
20497 root_mountflags &= ~MS_RDONLY;
20498- init_mm.start_code = (unsigned long) _text;
20499- init_mm.end_code = (unsigned long) _etext;
20500+ init_mm.start_code = ktla_ktva((unsigned long) _text);
20501+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
20502 init_mm.end_data = (unsigned long) _edata;
20503 init_mm.brk = _brk_end;
20504
20505- code_resource.start = virt_to_phys(_text);
20506- code_resource.end = virt_to_phys(_etext)-1;
20507- data_resource.start = virt_to_phys(_etext);
20508+ code_resource.start = virt_to_phys(ktla_ktva(_text));
20509+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20510+ data_resource.start = virt_to_phys(_sdata);
20511 data_resource.end = virt_to_phys(_edata)-1;
20512 bss_resource.start = virt_to_phys(&__bss_start);
20513 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20514diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20515index 5cdff03..5810740 100644
20516--- a/arch/x86/kernel/setup_percpu.c
20517+++ b/arch/x86/kernel/setup_percpu.c
20518@@ -21,19 +21,17 @@
20519 #include <asm/cpu.h>
20520 #include <asm/stackprotector.h>
20521
20522-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20523+#ifdef CONFIG_SMP
20524+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20525 EXPORT_PER_CPU_SYMBOL(cpu_number);
20526+#endif
20527
20528-#ifdef CONFIG_X86_64
20529 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20530-#else
20531-#define BOOT_PERCPU_OFFSET 0
20532-#endif
20533
20534 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20535 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20536
20537-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20538+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20539 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20540 };
20541 EXPORT_SYMBOL(__per_cpu_offset);
20542@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20543 {
20544 #ifdef CONFIG_X86_32
20545 struct desc_struct gdt;
20546+ unsigned long base = per_cpu_offset(cpu);
20547
20548- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20549- 0x2 | DESCTYPE_S, 0x8);
20550- gdt.s = 1;
20551+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20552+ 0x83 | DESCTYPE_S, 0xC);
20553 write_gdt_entry(get_cpu_gdt_table(cpu),
20554 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20555 #endif
20556@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20557 /* alrighty, percpu areas up and running */
20558 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20559 for_each_possible_cpu(cpu) {
20560+#ifdef CONFIG_CC_STACKPROTECTOR
20561+#ifdef CONFIG_X86_32
20562+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
20563+#endif
20564+#endif
20565 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20566 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20567 per_cpu(cpu_number, cpu) = cpu;
20568@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20569 */
20570 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20571 #endif
20572+#ifdef CONFIG_CC_STACKPROTECTOR
20573+#ifdef CONFIG_X86_32
20574+ if (!cpu)
20575+ per_cpu(stack_canary.canary, cpu) = canary;
20576+#endif
20577+#endif
20578 /*
20579 * Up to this point, the boot CPU has been using .init.data
20580 * area. Reload any changed state for the boot CPU.
20581diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20582index 70b27ee..fcf827f 100644
20583--- a/arch/x86/kernel/signal.c
20584+++ b/arch/x86/kernel/signal.c
20585@@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20586 * Align the stack pointer according to the i386 ABI,
20587 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20588 */
20589- sp = ((sp + 4) & -16ul) - 4;
20590+ sp = ((sp - 12) & -16ul) - 4;
20591 #else /* !CONFIG_X86_32 */
20592 sp = round_down(sp, 16) - 8;
20593 #endif
20594@@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20595 }
20596
20597 if (current->mm->context.vdso)
20598- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20599+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20600 else
20601- restorer = &frame->retcode;
20602+ restorer = (void __user *)&frame->retcode;
20603 if (ka->sa.sa_flags & SA_RESTORER)
20604 restorer = ka->sa.sa_restorer;
20605
20606@@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20607 * reasons and because gdb uses it as a signature to notice
20608 * signal handler stack frames.
20609 */
20610- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20611+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20612
20613 if (err)
20614 return -EFAULT;
20615@@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20616 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20617
20618 /* Set up to return from userspace. */
20619- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20620+ if (current->mm->context.vdso)
20621+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20622+ else
20623+ restorer = (void __user *)&frame->retcode;
20624 if (ka->sa.sa_flags & SA_RESTORER)
20625 restorer = ka->sa.sa_restorer;
20626 put_user_ex(restorer, &frame->pretcode);
20627@@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20628 * reasons and because gdb uses it as a signature to notice
20629 * signal handler stack frames.
20630 */
20631- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20632+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20633 } put_user_catch(err);
20634
20635 err |= copy_siginfo_to_user(&frame->info, info);
20636diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
20637index 48d2b7d..90d328a 100644
20638--- a/arch/x86/kernel/smp.c
20639+++ b/arch/x86/kernel/smp.c
20640@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
20641
20642 __setup("nonmi_ipi", nonmi_ipi_setup);
20643
20644-struct smp_ops smp_ops = {
20645+struct smp_ops smp_ops __read_only = {
20646 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
20647 .smp_prepare_cpus = native_smp_prepare_cpus,
20648 .smp_cpus_done = native_smp_cpus_done,
20649diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20650index f3e2ec8..ad5287a 100644
20651--- a/arch/x86/kernel/smpboot.c
20652+++ b/arch/x86/kernel/smpboot.c
20653@@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20654 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20655 (THREAD_SIZE + task_stack_page(idle))) - 1);
20656 per_cpu(current_task, cpu) = idle;
20657+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
20658
20659 #ifdef CONFIG_X86_32
20660 /* Stack for startup_32 can be just as for start_secondary onwards */
20661@@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20662 #else
20663 clear_tsk_thread_flag(idle, TIF_FORK);
20664 initial_gs = per_cpu_offset(cpu);
20665- per_cpu(kernel_stack, cpu) =
20666- (unsigned long)task_stack_page(idle) -
20667- KERNEL_STACK_OFFSET + THREAD_SIZE;
20668+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20669 #endif
20670+
20671+ pax_open_kernel();
20672 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20673+ pax_close_kernel();
20674+
20675 initial_code = (unsigned long)start_secondary;
20676 stack_start = idle->thread.sp;
20677
20678@@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20679 /* the FPU context is blank, nobody can own it */
20680 __cpu_disable_lazy_restore(cpu);
20681
20682+#ifdef CONFIG_PAX_PER_CPU_PGD
20683+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20684+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20685+ KERNEL_PGD_PTRS);
20686+#endif
20687+
20688+ /* the FPU context is blank, nobody can own it */
20689+ __cpu_disable_lazy_restore(cpu);
20690+
20691 err = do_boot_cpu(apicid, cpu, tidle);
20692 if (err) {
20693 pr_debug("do_boot_cpu failed %d\n", err);
20694diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20695index 9b4d51d..5d28b58 100644
20696--- a/arch/x86/kernel/step.c
20697+++ b/arch/x86/kernel/step.c
20698@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20699 struct desc_struct *desc;
20700 unsigned long base;
20701
20702- seg &= ~7UL;
20703+ seg >>= 3;
20704
20705 mutex_lock(&child->mm->context.lock);
20706- if (unlikely((seg >> 3) >= child->mm->context.size))
20707+ if (unlikely(seg >= child->mm->context.size))
20708 addr = -1L; /* bogus selector, access would fault */
20709 else {
20710 desc = child->mm->context.ldt + seg;
20711@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20712 addr += base;
20713 }
20714 mutex_unlock(&child->mm->context.lock);
20715- }
20716+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20717+ addr = ktla_ktva(addr);
20718
20719 return addr;
20720 }
20721@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20722 unsigned char opcode[15];
20723 unsigned long addr = convert_ip_to_linear(child, regs);
20724
20725+ if (addr == -EINVAL)
20726+ return 0;
20727+
20728 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20729 for (i = 0; i < copied; i++) {
20730 switch (opcode[i]) {
20731diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20732new file mode 100644
20733index 0000000..26bb1af
20734--- /dev/null
20735+++ b/arch/x86/kernel/sys_i386_32.c
20736@@ -0,0 +1,249 @@
20737+/*
20738+ * This file contains various random system calls that
20739+ * have a non-standard calling sequence on the Linux/i386
20740+ * platform.
20741+ */
20742+
20743+#include <linux/errno.h>
20744+#include <linux/sched.h>
20745+#include <linux/mm.h>
20746+#include <linux/fs.h>
20747+#include <linux/smp.h>
20748+#include <linux/sem.h>
20749+#include <linux/msg.h>
20750+#include <linux/shm.h>
20751+#include <linux/stat.h>
20752+#include <linux/syscalls.h>
20753+#include <linux/mman.h>
20754+#include <linux/file.h>
20755+#include <linux/utsname.h>
20756+#include <linux/ipc.h>
20757+
20758+#include <linux/uaccess.h>
20759+#include <linux/unistd.h>
20760+
20761+#include <asm/syscalls.h>
20762+
20763+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20764+{
20765+ unsigned long pax_task_size = TASK_SIZE;
20766+
20767+#ifdef CONFIG_PAX_SEGMEXEC
20768+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20769+ pax_task_size = SEGMEXEC_TASK_SIZE;
20770+#endif
20771+
20772+ if (len > pax_task_size || addr > pax_task_size - len)
20773+ return -EINVAL;
20774+
20775+ return 0;
20776+}
20777+
20778+unsigned long
20779+arch_get_unmapped_area(struct file *filp, unsigned long addr,
20780+ unsigned long len, unsigned long pgoff, unsigned long flags)
20781+{
20782+ struct mm_struct *mm = current->mm;
20783+ struct vm_area_struct *vma;
20784+ unsigned long start_addr, pax_task_size = TASK_SIZE;
20785+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20786+
20787+#ifdef CONFIG_PAX_SEGMEXEC
20788+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20789+ pax_task_size = SEGMEXEC_TASK_SIZE;
20790+#endif
20791+
20792+ pax_task_size -= PAGE_SIZE;
20793+
20794+ if (len > pax_task_size)
20795+ return -ENOMEM;
20796+
20797+ if (flags & MAP_FIXED)
20798+ return addr;
20799+
20800+#ifdef CONFIG_PAX_RANDMMAP
20801+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20802+#endif
20803+
20804+ if (addr) {
20805+ addr = PAGE_ALIGN(addr);
20806+ if (pax_task_size - len >= addr) {
20807+ vma = find_vma(mm, addr);
20808+ if (check_heap_stack_gap(vma, addr, len, offset))
20809+ return addr;
20810+ }
20811+ }
20812+ if (len > mm->cached_hole_size) {
20813+ start_addr = addr = mm->free_area_cache;
20814+ } else {
20815+ start_addr = addr = mm->mmap_base;
20816+ mm->cached_hole_size = 0;
20817+ }
20818+
20819+#ifdef CONFIG_PAX_PAGEEXEC
20820+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20821+ start_addr = 0x00110000UL;
20822+
20823+#ifdef CONFIG_PAX_RANDMMAP
20824+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20825+ start_addr += mm->delta_mmap & 0x03FFF000UL;
20826+#endif
20827+
20828+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20829+ start_addr = addr = mm->mmap_base;
20830+ else
20831+ addr = start_addr;
20832+ }
20833+#endif
20834+
20835+full_search:
20836+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20837+ /* At this point: (!vma || addr < vma->vm_end). */
20838+ if (pax_task_size - len < addr) {
20839+ /*
20840+ * Start a new search - just in case we missed
20841+ * some holes.
20842+ */
20843+ if (start_addr != mm->mmap_base) {
20844+ start_addr = addr = mm->mmap_base;
20845+ mm->cached_hole_size = 0;
20846+ goto full_search;
20847+ }
20848+ return -ENOMEM;
20849+ }
20850+ if (check_heap_stack_gap(vma, addr, len, offset))
20851+ break;
20852+ if (addr + mm->cached_hole_size < vma->vm_start)
20853+ mm->cached_hole_size = vma->vm_start - addr;
20854+ addr = vma->vm_end;
20855+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
20856+ start_addr = addr = mm->mmap_base;
20857+ mm->cached_hole_size = 0;
20858+ goto full_search;
20859+ }
20860+ }
20861+
20862+ /*
20863+ * Remember the place where we stopped the search:
20864+ */
20865+ mm->free_area_cache = addr + len;
20866+ return addr;
20867+}
20868+
20869+unsigned long
20870+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20871+ const unsigned long len, const unsigned long pgoff,
20872+ const unsigned long flags)
20873+{
20874+ struct vm_area_struct *vma;
20875+ struct mm_struct *mm = current->mm;
20876+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20877+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20878+
20879+#ifdef CONFIG_PAX_SEGMEXEC
20880+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20881+ pax_task_size = SEGMEXEC_TASK_SIZE;
20882+#endif
20883+
20884+ pax_task_size -= PAGE_SIZE;
20885+
20886+ /* requested length too big for entire address space */
20887+ if (len > pax_task_size)
20888+ return -ENOMEM;
20889+
20890+ if (flags & MAP_FIXED)
20891+ return addr;
20892+
20893+#ifdef CONFIG_PAX_PAGEEXEC
20894+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20895+ goto bottomup;
20896+#endif
20897+
20898+#ifdef CONFIG_PAX_RANDMMAP
20899+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20900+#endif
20901+
20902+ /* requesting a specific address */
20903+ if (addr) {
20904+ addr = PAGE_ALIGN(addr);
20905+ if (pax_task_size - len >= addr) {
20906+ vma = find_vma(mm, addr);
20907+ if (check_heap_stack_gap(vma, addr, len, offset))
20908+ return addr;
20909+ }
20910+ }
20911+
20912+ /* check if free_area_cache is useful for us */
20913+ if (len <= mm->cached_hole_size) {
20914+ mm->cached_hole_size = 0;
20915+ mm->free_area_cache = mm->mmap_base;
20916+ }
20917+
20918+ /* either no address requested or can't fit in requested address hole */
20919+ addr = mm->free_area_cache;
20920+
20921+ /* make sure it can fit in the remaining address space */
20922+ if (addr > len) {
20923+ vma = find_vma(mm, addr-len);
20924+ if (check_heap_stack_gap(vma, addr - len, len, offset))
20925+ /* remember the address as a hint for next time */
20926+ return (mm->free_area_cache = addr-len);
20927+ }
20928+
20929+ if (mm->mmap_base < len)
20930+ goto bottomup;
20931+
20932+ addr = mm->mmap_base-len;
20933+
20934+ do {
20935+ /*
20936+ * Lookup failure means no vma is above this address,
20937+ * else if new region fits below vma->vm_start,
20938+ * return with success:
20939+ */
20940+ vma = find_vma(mm, addr);
20941+ if (check_heap_stack_gap(vma, addr, len, offset))
20942+ /* remember the address as a hint for next time */
20943+ return (mm->free_area_cache = addr);
20944+
20945+ /* remember the largest hole we saw so far */
20946+ if (addr + mm->cached_hole_size < vma->vm_start)
20947+ mm->cached_hole_size = vma->vm_start - addr;
20948+
20949+ /* try just below the current vma->vm_start */
20950+ addr = skip_heap_stack_gap(vma, len, offset);
20951+ } while (!IS_ERR_VALUE(addr));
20952+
20953+bottomup:
20954+ /*
20955+ * A failed mmap() very likely causes application failure,
20956+ * so fall back to the bottom-up function here. This scenario
20957+ * can happen with large stack limits and large mmap()
20958+ * allocations.
20959+ */
20960+
20961+#ifdef CONFIG_PAX_SEGMEXEC
20962+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20963+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20964+ else
20965+#endif
20966+
20967+ mm->mmap_base = TASK_UNMAPPED_BASE;
20968+
20969+#ifdef CONFIG_PAX_RANDMMAP
20970+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20971+ mm->mmap_base += mm->delta_mmap;
20972+#endif
20973+
20974+ mm->free_area_cache = mm->mmap_base;
20975+ mm->cached_hole_size = ~0UL;
20976+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20977+ /*
20978+ * Restore the topdown base:
20979+ */
20980+ mm->mmap_base = base;
20981+ mm->free_area_cache = base;
20982+ mm->cached_hole_size = ~0UL;
20983+
20984+ return addr;
20985+}
20986diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20987index b4d3c39..d699d77 100644
20988--- a/arch/x86/kernel/sys_x86_64.c
20989+++ b/arch/x86/kernel/sys_x86_64.c
20990@@ -95,8 +95,8 @@ out:
20991 return error;
20992 }
20993
20994-static void find_start_end(unsigned long flags, unsigned long *begin,
20995- unsigned long *end)
20996+static void find_start_end(struct mm_struct *mm, unsigned long flags,
20997+ unsigned long *begin, unsigned long *end)
20998 {
20999 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
21000 unsigned long new_begin;
21001@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
21002 *begin = new_begin;
21003 }
21004 } else {
21005- *begin = TASK_UNMAPPED_BASE;
21006+ *begin = mm->mmap_base;
21007 *end = TASK_SIZE;
21008 }
21009 }
21010@@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
21011 struct vm_area_struct *vma;
21012 unsigned long start_addr;
21013 unsigned long begin, end;
21014+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
21015
21016 if (flags & MAP_FIXED)
21017 return addr;
21018
21019- find_start_end(flags, &begin, &end);
21020+ find_start_end(mm, flags, &begin, &end);
21021
21022 if (len > end)
21023 return -ENOMEM;
21024
21025+#ifdef CONFIG_PAX_RANDMMAP
21026+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21027+#endif
21028+
21029 if (addr) {
21030 addr = PAGE_ALIGN(addr);
21031 vma = find_vma(mm, addr);
21032- if (end - len >= addr &&
21033- (!vma || addr + len <= vma->vm_start))
21034+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
21035 return addr;
21036 }
21037 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
21038@@ -172,7 +176,7 @@ full_search:
21039 }
21040 return -ENOMEM;
21041 }
21042- if (!vma || addr + len <= vma->vm_start) {
21043+ if (check_heap_stack_gap(vma, addr, len, offset)) {
21044 /*
21045 * Remember the place where we stopped the search:
21046 */
21047@@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
21048 {
21049 struct vm_area_struct *vma;
21050 struct mm_struct *mm = current->mm;
21051- unsigned long addr = addr0, start_addr;
21052+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
21053+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
21054
21055 /* requested length too big for entire address space */
21056 if (len > TASK_SIZE)
21057@@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
21058 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
21059 goto bottomup;
21060
21061+#ifdef CONFIG_PAX_RANDMMAP
21062+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
21063+#endif
21064+
21065 /* requesting a specific address */
21066 if (addr) {
21067 addr = PAGE_ALIGN(addr);
21068- vma = find_vma(mm, addr);
21069- if (TASK_SIZE - len >= addr &&
21070- (!vma || addr + len <= vma->vm_start))
21071- return addr;
21072+ if (TASK_SIZE - len >= addr) {
21073+ vma = find_vma(mm, addr);
21074+ if (check_heap_stack_gap(vma, addr, len, offset))
21075+ return addr;
21076+ }
21077 }
21078
21079 /* check if free_area_cache is useful for us */
21080@@ -240,7 +250,7 @@ try_again:
21081 * return with success:
21082 */
21083 vma = find_vma(mm, addr);
21084- if (!vma || addr+len <= vma->vm_start)
21085+ if (check_heap_stack_gap(vma, addr, len, offset))
21086 /* remember the address as a hint for next time */
21087 return mm->free_area_cache = addr;
21088
21089@@ -249,8 +259,8 @@ try_again:
21090 mm->cached_hole_size = vma->vm_start - addr;
21091
21092 /* try just below the current vma->vm_start */
21093- addr = vma->vm_start-len;
21094- } while (len < vma->vm_start);
21095+ addr = skip_heap_stack_gap(vma, len, offset);
21096+ } while (!IS_ERR_VALUE(addr));
21097
21098 fail:
21099 /*
21100@@ -270,13 +280,21 @@ bottomup:
21101 * can happen with large stack limits and large mmap()
21102 * allocations.
21103 */
21104+ mm->mmap_base = TASK_UNMAPPED_BASE;
21105+
21106+#ifdef CONFIG_PAX_RANDMMAP
21107+ if (mm->pax_flags & MF_PAX_RANDMMAP)
21108+ mm->mmap_base += mm->delta_mmap;
21109+#endif
21110+
21111+ mm->free_area_cache = mm->mmap_base;
21112 mm->cached_hole_size = ~0UL;
21113- mm->free_area_cache = TASK_UNMAPPED_BASE;
21114 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
21115 /*
21116 * Restore the topdown base:
21117 */
21118- mm->free_area_cache = mm->mmap_base;
21119+ mm->mmap_base = base;
21120+ mm->free_area_cache = base;
21121 mm->cached_hole_size = ~0UL;
21122
21123 return addr;
21124diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
21125index f84fe00..93fe08f 100644
21126--- a/arch/x86/kernel/tboot.c
21127+++ b/arch/x86/kernel/tboot.c
21128@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21129
21130 void tboot_shutdown(u32 shutdown_type)
21131 {
21132- void (*shutdown)(void);
21133+ void (* __noreturn shutdown)(void);
21134
21135 if (!tboot_enabled())
21136 return;
21137@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21138
21139 switch_to_tboot_pt();
21140
21141- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21142+ shutdown = (void *)tboot->shutdown_entry;
21143 shutdown();
21144
21145 /* should not reach here */
21146@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21147 return 0;
21148 }
21149
21150-static atomic_t ap_wfs_count;
21151+static atomic_unchecked_t ap_wfs_count;
21152
21153 static int tboot_wait_for_aps(int num_aps)
21154 {
21155@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21156 {
21157 switch (action) {
21158 case CPU_DYING:
21159- atomic_inc(&ap_wfs_count);
21160+ atomic_inc_unchecked(&ap_wfs_count);
21161 if (num_online_cpus() == 1)
21162- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21163+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21164 return NOTIFY_BAD;
21165 break;
21166 }
21167@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21168
21169 tboot_create_trampoline();
21170
21171- atomic_set(&ap_wfs_count, 0);
21172+ atomic_set_unchecked(&ap_wfs_count, 0);
21173 register_hotcpu_notifier(&tboot_cpu_notifier);
21174
21175 acpi_os_set_prepare_sleep(&tboot_sleep);
21176diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21177index 24d3c91..d06b473 100644
21178--- a/arch/x86/kernel/time.c
21179+++ b/arch/x86/kernel/time.c
21180@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21181 {
21182 unsigned long pc = instruction_pointer(regs);
21183
21184- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21185+ if (!user_mode(regs) && in_lock_functions(pc)) {
21186 #ifdef CONFIG_FRAME_POINTER
21187- return *(unsigned long *)(regs->bp + sizeof(long));
21188+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21189 #else
21190 unsigned long *sp =
21191 (unsigned long *)kernel_stack_pointer(regs);
21192@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21193 * or above a saved flags. Eflags has bits 22-31 zero,
21194 * kernel addresses don't.
21195 */
21196+
21197+#ifdef CONFIG_PAX_KERNEXEC
21198+ return ktla_ktva(sp[0]);
21199+#else
21200 if (sp[0] >> 22)
21201 return sp[0];
21202 if (sp[1] >> 22)
21203 return sp[1];
21204 #endif
21205+
21206+#endif
21207 }
21208 return pc;
21209 }
21210diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21211index 9d9d2f9..cad418a 100644
21212--- a/arch/x86/kernel/tls.c
21213+++ b/arch/x86/kernel/tls.c
21214@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21215 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21216 return -EINVAL;
21217
21218+#ifdef CONFIG_PAX_SEGMEXEC
21219+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21220+ return -EINVAL;
21221+#endif
21222+
21223 set_tls_desc(p, idx, &info, 1);
21224
21225 return 0;
21226@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21227
21228 if (kbuf)
21229 info = kbuf;
21230- else if (__copy_from_user(infobuf, ubuf, count))
21231+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21232 return -EFAULT;
21233 else
21234 info = infobuf;
21235diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21236index 8276dc6..4ca48a2 100644
21237--- a/arch/x86/kernel/traps.c
21238+++ b/arch/x86/kernel/traps.c
21239@@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21240
21241 /* Do we ignore FPU interrupts ? */
21242 char ignore_fpu_irq;
21243-
21244-/*
21245- * The IDT has to be page-aligned to simplify the Pentium
21246- * F0 0F bug workaround.
21247- */
21248-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21249 #endif
21250
21251 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21252@@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21253 }
21254
21255 static int __kprobes
21256-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21257+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21258 struct pt_regs *regs, long error_code)
21259 {
21260 #ifdef CONFIG_X86_32
21261- if (regs->flags & X86_VM_MASK) {
21262+ if (v8086_mode(regs)) {
21263 /*
21264 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21265 * On nmi (interrupt 2), do_trap should not be called.
21266@@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21267 return -1;
21268 }
21269 #endif
21270- if (!user_mode(regs)) {
21271+ if (!user_mode_novm(regs)) {
21272 if (!fixup_exception(regs)) {
21273 tsk->thread.error_code = error_code;
21274 tsk->thread.trap_nr = trapnr;
21275+
21276+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21277+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21278+ str = "PAX: suspicious stack segment fault";
21279+#endif
21280+
21281 die(str, regs, error_code);
21282 }
21283+
21284+#ifdef CONFIG_PAX_REFCOUNT
21285+ if (trapnr == 4)
21286+ pax_report_refcount_overflow(regs);
21287+#endif
21288+
21289 return 0;
21290 }
21291
21292@@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21293 }
21294
21295 static void __kprobes
21296-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21297+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21298 long error_code, siginfo_t *info)
21299 {
21300 struct task_struct *tsk = current;
21301@@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21302 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21303 printk_ratelimit()) {
21304 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21305- tsk->comm, tsk->pid, str,
21306+ tsk->comm, task_pid_nr(tsk), str,
21307 regs->ip, regs->sp, error_code);
21308 print_vma_addr(" in ", regs->ip);
21309 pr_cont("\n");
21310@@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21311 conditional_sti(regs);
21312
21313 #ifdef CONFIG_X86_32
21314- if (regs->flags & X86_VM_MASK) {
21315+ if (v8086_mode(regs)) {
21316 local_irq_enable();
21317 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21318 goto exit;
21319@@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21320 #endif
21321
21322 tsk = current;
21323- if (!user_mode(regs)) {
21324+ if (!user_mode_novm(regs)) {
21325 if (fixup_exception(regs))
21326 goto exit;
21327
21328 tsk->thread.error_code = error_code;
21329 tsk->thread.trap_nr = X86_TRAP_GP;
21330 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21331- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21332+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21333+
21334+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21335+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21336+ die("PAX: suspicious general protection fault", regs, error_code);
21337+ else
21338+#endif
21339+
21340 die("general protection fault", regs, error_code);
21341+ }
21342 goto exit;
21343 }
21344
21345+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21346+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21347+ struct mm_struct *mm = tsk->mm;
21348+ unsigned long limit;
21349+
21350+ down_write(&mm->mmap_sem);
21351+ limit = mm->context.user_cs_limit;
21352+ if (limit < TASK_SIZE) {
21353+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21354+ up_write(&mm->mmap_sem);
21355+ return;
21356+ }
21357+ up_write(&mm->mmap_sem);
21358+ }
21359+#endif
21360+
21361 tsk->thread.error_code = error_code;
21362 tsk->thread.trap_nr = X86_TRAP_GP;
21363
21364@@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21365 /* It's safe to allow irq's after DR6 has been saved */
21366 preempt_conditional_sti(regs);
21367
21368- if (regs->flags & X86_VM_MASK) {
21369+ if (v8086_mode(regs)) {
21370 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21371 X86_TRAP_DB);
21372 preempt_conditional_cli(regs);
21373@@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21374 * We already checked v86 mode above, so we can check for kernel mode
21375 * by just checking the CPL of CS.
21376 */
21377- if ((dr6 & DR_STEP) && !user_mode(regs)) {
21378+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21379 tsk->thread.debugreg6 &= ~DR_STEP;
21380 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21381 regs->flags &= ~X86_EFLAGS_TF;
21382@@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21383 return;
21384 conditional_sti(regs);
21385
21386- if (!user_mode_vm(regs))
21387+ if (!user_mode(regs))
21388 {
21389 if (!fixup_exception(regs)) {
21390 task->thread.error_code = error_code;
21391diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21392index aafa555..a04691a 100644
21393--- a/arch/x86/kernel/uprobes.c
21394+++ b/arch/x86/kernel/uprobes.c
21395@@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21396 int ret = NOTIFY_DONE;
21397
21398 /* We are only interested in userspace traps */
21399- if (regs && !user_mode_vm(regs))
21400+ if (regs && !user_mode(regs))
21401 return NOTIFY_DONE;
21402
21403 switch (val) {
21404diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21405index b9242ba..50c5edd 100644
21406--- a/arch/x86/kernel/verify_cpu.S
21407+++ b/arch/x86/kernel/verify_cpu.S
21408@@ -20,6 +20,7 @@
21409 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21410 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21411 * arch/x86/kernel/head_32.S: processor startup
21412+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21413 *
21414 * verify_cpu, returns the status of longmode and SSE in register %eax.
21415 * 0: Success 1: Failure
21416diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21417index 5c9687b..5f857d3 100644
21418--- a/arch/x86/kernel/vm86_32.c
21419+++ b/arch/x86/kernel/vm86_32.c
21420@@ -43,6 +43,7 @@
21421 #include <linux/ptrace.h>
21422 #include <linux/audit.h>
21423 #include <linux/stddef.h>
21424+#include <linux/grsecurity.h>
21425
21426 #include <asm/uaccess.h>
21427 #include <asm/io.h>
21428@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21429 do_exit(SIGSEGV);
21430 }
21431
21432- tss = &per_cpu(init_tss, get_cpu());
21433+ tss = init_tss + get_cpu();
21434 current->thread.sp0 = current->thread.saved_sp0;
21435 current->thread.sysenter_cs = __KERNEL_CS;
21436 load_sp0(tss, &current->thread);
21437@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21438 struct task_struct *tsk;
21439 int tmp, ret = -EPERM;
21440
21441+#ifdef CONFIG_GRKERNSEC_VM86
21442+ if (!capable(CAP_SYS_RAWIO)) {
21443+ gr_handle_vm86();
21444+ goto out;
21445+ }
21446+#endif
21447+
21448 tsk = current;
21449 if (tsk->thread.saved_sp0)
21450 goto out;
21451@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21452 int tmp, ret;
21453 struct vm86plus_struct __user *v86;
21454
21455+#ifdef CONFIG_GRKERNSEC_VM86
21456+ if (!capable(CAP_SYS_RAWIO)) {
21457+ gr_handle_vm86();
21458+ ret = -EPERM;
21459+ goto out;
21460+ }
21461+#endif
21462+
21463 tsk = current;
21464 switch (cmd) {
21465 case VM86_REQUEST_IRQ:
21466@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21467 tsk->thread.saved_fs = info->regs32->fs;
21468 tsk->thread.saved_gs = get_user_gs(info->regs32);
21469
21470- tss = &per_cpu(init_tss, get_cpu());
21471+ tss = init_tss + get_cpu();
21472 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21473 if (cpu_has_sep)
21474 tsk->thread.sysenter_cs = 0;
21475@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21476 goto cannot_handle;
21477 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21478 goto cannot_handle;
21479- intr_ptr = (unsigned long __user *) (i << 2);
21480+ intr_ptr = (__force unsigned long __user *) (i << 2);
21481 if (get_user(segoffs, intr_ptr))
21482 goto cannot_handle;
21483 if ((segoffs >> 16) == BIOSSEG)
21484diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21485index 22a1530..8fbaaad 100644
21486--- a/arch/x86/kernel/vmlinux.lds.S
21487+++ b/arch/x86/kernel/vmlinux.lds.S
21488@@ -26,6 +26,13 @@
21489 #include <asm/page_types.h>
21490 #include <asm/cache.h>
21491 #include <asm/boot.h>
21492+#include <asm/segment.h>
21493+
21494+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21495+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21496+#else
21497+#define __KERNEL_TEXT_OFFSET 0
21498+#endif
21499
21500 #undef i386 /* in case the preprocessor is a 32bit one */
21501
21502@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21503
21504 PHDRS {
21505 text PT_LOAD FLAGS(5); /* R_E */
21506+#ifdef CONFIG_X86_32
21507+ module PT_LOAD FLAGS(5); /* R_E */
21508+#endif
21509+#ifdef CONFIG_XEN
21510+ rodata PT_LOAD FLAGS(5); /* R_E */
21511+#else
21512+ rodata PT_LOAD FLAGS(4); /* R__ */
21513+#endif
21514 data PT_LOAD FLAGS(6); /* RW_ */
21515-#ifdef CONFIG_X86_64
21516+ init.begin PT_LOAD FLAGS(6); /* RW_ */
21517 #ifdef CONFIG_SMP
21518 percpu PT_LOAD FLAGS(6); /* RW_ */
21519 #endif
21520+ text.init PT_LOAD FLAGS(5); /* R_E */
21521+ text.exit PT_LOAD FLAGS(5); /* R_E */
21522 init PT_LOAD FLAGS(7); /* RWE */
21523-#endif
21524 note PT_NOTE FLAGS(0); /* ___ */
21525 }
21526
21527 SECTIONS
21528 {
21529 #ifdef CONFIG_X86_32
21530- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21531- phys_startup_32 = startup_32 - LOAD_OFFSET;
21532+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21533 #else
21534- . = __START_KERNEL;
21535- phys_startup_64 = startup_64 - LOAD_OFFSET;
21536+ . = __START_KERNEL;
21537 #endif
21538
21539 /* Text and read-only data */
21540- .text : AT(ADDR(.text) - LOAD_OFFSET) {
21541- _text = .;
21542+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21543 /* bootstrapping code */
21544+#ifdef CONFIG_X86_32
21545+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21546+#else
21547+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21548+#endif
21549+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21550+ _text = .;
21551 HEAD_TEXT
21552 #ifdef CONFIG_X86_32
21553 . = ALIGN(PAGE_SIZE);
21554@@ -108,13 +128,48 @@ SECTIONS
21555 IRQENTRY_TEXT
21556 *(.fixup)
21557 *(.gnu.warning)
21558- /* End of text section */
21559- _etext = .;
21560 } :text = 0x9090
21561
21562- NOTES :text :note
21563+ . += __KERNEL_TEXT_OFFSET;
21564
21565- EXCEPTION_TABLE(16) :text = 0x9090
21566+#ifdef CONFIG_X86_32
21567+ . = ALIGN(PAGE_SIZE);
21568+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21569+
21570+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21571+ MODULES_EXEC_VADDR = .;
21572+ BYTE(0)
21573+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21574+ . = ALIGN(HPAGE_SIZE) - 1;
21575+ MODULES_EXEC_END = .;
21576+#endif
21577+
21578+ } :module
21579+#endif
21580+
21581+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21582+ /* End of text section */
21583+ BYTE(0)
21584+ _etext = . - __KERNEL_TEXT_OFFSET;
21585+ }
21586+
21587+#ifdef CONFIG_X86_32
21588+ . = ALIGN(PAGE_SIZE);
21589+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21590+ *(.idt)
21591+ . = ALIGN(PAGE_SIZE);
21592+ *(.empty_zero_page)
21593+ *(.initial_pg_fixmap)
21594+ *(.initial_pg_pmd)
21595+ *(.initial_page_table)
21596+ *(.swapper_pg_dir)
21597+ } :rodata
21598+#endif
21599+
21600+ . = ALIGN(PAGE_SIZE);
21601+ NOTES :rodata :note
21602+
21603+ EXCEPTION_TABLE(16) :rodata
21604
21605 #if defined(CONFIG_DEBUG_RODATA)
21606 /* .text should occupy whole number of pages */
21607@@ -126,16 +181,20 @@ SECTIONS
21608
21609 /* Data */
21610 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21611+
21612+#ifdef CONFIG_PAX_KERNEXEC
21613+ . = ALIGN(HPAGE_SIZE);
21614+#else
21615+ . = ALIGN(PAGE_SIZE);
21616+#endif
21617+
21618 /* Start of data section */
21619 _sdata = .;
21620
21621 /* init_task */
21622 INIT_TASK_DATA(THREAD_SIZE)
21623
21624-#ifdef CONFIG_X86_32
21625- /* 32 bit has nosave before _edata */
21626 NOSAVE_DATA
21627-#endif
21628
21629 PAGE_ALIGNED_DATA(PAGE_SIZE)
21630
21631@@ -176,12 +235,19 @@ SECTIONS
21632 #endif /* CONFIG_X86_64 */
21633
21634 /* Init code and data - will be freed after init */
21635- . = ALIGN(PAGE_SIZE);
21636 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21637+ BYTE(0)
21638+
21639+#ifdef CONFIG_PAX_KERNEXEC
21640+ . = ALIGN(HPAGE_SIZE);
21641+#else
21642+ . = ALIGN(PAGE_SIZE);
21643+#endif
21644+
21645 __init_begin = .; /* paired with __init_end */
21646- }
21647+ } :init.begin
21648
21649-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21650+#ifdef CONFIG_SMP
21651 /*
21652 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21653 * output PHDR, so the next output section - .init.text - should
21654@@ -190,12 +256,27 @@ SECTIONS
21655 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21656 #endif
21657
21658- INIT_TEXT_SECTION(PAGE_SIZE)
21659-#ifdef CONFIG_X86_64
21660- :init
21661-#endif
21662+ . = ALIGN(PAGE_SIZE);
21663+ init_begin = .;
21664+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21665+ VMLINUX_SYMBOL(_sinittext) = .;
21666+ INIT_TEXT
21667+ VMLINUX_SYMBOL(_einittext) = .;
21668+ . = ALIGN(PAGE_SIZE);
21669+ } :text.init
21670
21671- INIT_DATA_SECTION(16)
21672+ /*
21673+ * .exit.text is discard at runtime, not link time, to deal with
21674+ * references from .altinstructions and .eh_frame
21675+ */
21676+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21677+ EXIT_TEXT
21678+ . = ALIGN(16);
21679+ } :text.exit
21680+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21681+
21682+ . = ALIGN(PAGE_SIZE);
21683+ INIT_DATA_SECTION(16) :init
21684
21685 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21686 __x86_cpu_dev_start = .;
21687@@ -257,19 +338,12 @@ SECTIONS
21688 }
21689
21690 . = ALIGN(8);
21691- /*
21692- * .exit.text is discard at runtime, not link time, to deal with
21693- * references from .altinstructions and .eh_frame
21694- */
21695- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21696- EXIT_TEXT
21697- }
21698
21699 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21700 EXIT_DATA
21701 }
21702
21703-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21704+#ifndef CONFIG_SMP
21705 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21706 #endif
21707
21708@@ -288,16 +362,10 @@ SECTIONS
21709 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21710 __smp_locks = .;
21711 *(.smp_locks)
21712- . = ALIGN(PAGE_SIZE);
21713 __smp_locks_end = .;
21714+ . = ALIGN(PAGE_SIZE);
21715 }
21716
21717-#ifdef CONFIG_X86_64
21718- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21719- NOSAVE_DATA
21720- }
21721-#endif
21722-
21723 /* BSS */
21724 . = ALIGN(PAGE_SIZE);
21725 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21726@@ -313,6 +381,7 @@ SECTIONS
21727 __brk_base = .;
21728 . += 64 * 1024; /* 64k alignment slop space */
21729 *(.brk_reservation) /* areas brk users have reserved */
21730+ . = ALIGN(HPAGE_SIZE);
21731 __brk_limit = .;
21732 }
21733
21734@@ -339,13 +408,12 @@ SECTIONS
21735 * for the boot processor.
21736 */
21737 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21738-INIT_PER_CPU(gdt_page);
21739 INIT_PER_CPU(irq_stack_union);
21740
21741 /*
21742 * Build-time check on the image size:
21743 */
21744-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21745+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21746 "kernel image bigger than KERNEL_IMAGE_SIZE");
21747
21748 #ifdef CONFIG_SMP
21749diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21750index 3a3e8c9..1af9465 100644
21751--- a/arch/x86/kernel/vsyscall_64.c
21752+++ b/arch/x86/kernel/vsyscall_64.c
21753@@ -56,15 +56,13 @@
21754 DEFINE_VVAR(int, vgetcpu_mode);
21755 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21756
21757-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21758+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21759
21760 static int __init vsyscall_setup(char *str)
21761 {
21762 if (str) {
21763 if (!strcmp("emulate", str))
21764 vsyscall_mode = EMULATE;
21765- else if (!strcmp("native", str))
21766- vsyscall_mode = NATIVE;
21767 else if (!strcmp("none", str))
21768 vsyscall_mode = NONE;
21769 else
21770@@ -315,8 +313,7 @@ done:
21771 return true;
21772
21773 sigsegv:
21774- force_sig(SIGSEGV, current);
21775- return true;
21776+ do_group_exit(SIGKILL);
21777 }
21778
21779 /*
21780@@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21781 extern char __vvar_page;
21782 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21783
21784- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21785- vsyscall_mode == NATIVE
21786- ? PAGE_KERNEL_VSYSCALL
21787- : PAGE_KERNEL_VVAR);
21788+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21789 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21790 (unsigned long)VSYSCALL_START);
21791
21792diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21793index 1330dd1..d220b99 100644
21794--- a/arch/x86/kernel/x8664_ksyms_64.c
21795+++ b/arch/x86/kernel/x8664_ksyms_64.c
21796@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21797 EXPORT_SYMBOL(copy_user_generic_unrolled);
21798 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21799 EXPORT_SYMBOL(__copy_user_nocache);
21800-EXPORT_SYMBOL(_copy_from_user);
21801-EXPORT_SYMBOL(_copy_to_user);
21802
21803 EXPORT_SYMBOL(copy_page);
21804 EXPORT_SYMBOL(clear_page);
21805diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
21806index 7a3d075..6cb373d 100644
21807--- a/arch/x86/kernel/x86_init.c
21808+++ b/arch/x86/kernel/x86_init.c
21809@@ -88,7 +88,7 @@ struct x86_init_ops x86_init __initdata = {
21810 },
21811 };
21812
21813-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
21814+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
21815 .early_percpu_clock_init = x86_init_noop,
21816 .setup_percpu_clockev = setup_secondary_APIC_clock,
21817 };
21818@@ -96,7 +96,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
21819 static void default_nmi_init(void) { };
21820 static int default_i8042_detect(void) { return 1; };
21821
21822-struct x86_platform_ops x86_platform = {
21823+struct x86_platform_ops x86_platform __read_only = {
21824 .calibrate_tsc = native_calibrate_tsc,
21825 .get_wallclock = mach_get_cmos_time,
21826 .set_wallclock = mach_set_rtc_mmss,
21827@@ -110,14 +110,14 @@ struct x86_platform_ops x86_platform = {
21828 };
21829
21830 EXPORT_SYMBOL_GPL(x86_platform);
21831-struct x86_msi_ops x86_msi = {
21832+struct x86_msi_ops x86_msi __read_only = {
21833 .setup_msi_irqs = native_setup_msi_irqs,
21834 .teardown_msi_irq = native_teardown_msi_irq,
21835 .teardown_msi_irqs = default_teardown_msi_irqs,
21836 .restore_msi_irqs = default_restore_msi_irqs,
21837 };
21838
21839-struct x86_io_apic_ops x86_io_apic_ops = {
21840+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
21841 .init = native_io_apic_init_mappings,
21842 .read = native_io_apic_read,
21843 .write = native_io_apic_write,
21844diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21845index ada87a3..afea76d 100644
21846--- a/arch/x86/kernel/xsave.c
21847+++ b/arch/x86/kernel/xsave.c
21848@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21849 {
21850 int err;
21851
21852+ buf = (struct xsave_struct __user *)____m(buf);
21853 if (use_xsave())
21854 err = xsave_user(buf);
21855 else if (use_fxsr())
21856@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21857 */
21858 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21859 {
21860+ buf = (void __user *)____m(buf);
21861 if (use_xsave()) {
21862 if ((unsigned long)buf % 64 || fx_only) {
21863 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21864diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21865index ec79e77..420f5cc 100644
21866--- a/arch/x86/kvm/cpuid.c
21867+++ b/arch/x86/kvm/cpuid.c
21868@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21869 struct kvm_cpuid2 *cpuid,
21870 struct kvm_cpuid_entry2 __user *entries)
21871 {
21872- int r;
21873+ int r, i;
21874
21875 r = -E2BIG;
21876 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21877 goto out;
21878 r = -EFAULT;
21879- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21880- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21881+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21882 goto out;
21883+ for (i = 0; i < cpuid->nent; ++i) {
21884+ struct kvm_cpuid_entry2 cpuid_entry;
21885+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21886+ goto out;
21887+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21888+ }
21889 vcpu->arch.cpuid_nent = cpuid->nent;
21890 kvm_apic_set_version(vcpu);
21891 kvm_x86_ops->cpuid_update(vcpu);
21892@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21893 struct kvm_cpuid2 *cpuid,
21894 struct kvm_cpuid_entry2 __user *entries)
21895 {
21896- int r;
21897+ int r, i;
21898
21899 r = -E2BIG;
21900 if (cpuid->nent < vcpu->arch.cpuid_nent)
21901 goto out;
21902 r = -EFAULT;
21903- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21904- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21905+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21906 goto out;
21907+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21908+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21909+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21910+ goto out;
21911+ }
21912 return 0;
21913
21914 out:
21915diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21916index bba39bf..296540a 100644
21917--- a/arch/x86/kvm/emulate.c
21918+++ b/arch/x86/kvm/emulate.c
21919@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21920
21921 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21922 do { \
21923+ unsigned long _tmp; \
21924 __asm__ __volatile__ ( \
21925 _PRE_EFLAGS("0", "4", "2") \
21926 _op _suffix " %"_x"3,%1; " \
21927@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21928 /* Raw emulation: instruction has two explicit operands. */
21929 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21930 do { \
21931- unsigned long _tmp; \
21932- \
21933 switch ((ctxt)->dst.bytes) { \
21934 case 2: \
21935 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21936@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21937
21938 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21939 do { \
21940- unsigned long _tmp; \
21941 switch ((ctxt)->dst.bytes) { \
21942 case 1: \
21943 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21944diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21945index 43e9fad..3b7c059 100644
21946--- a/arch/x86/kvm/lapic.c
21947+++ b/arch/x86/kvm/lapic.c
21948@@ -55,7 +55,7 @@
21949 #define APIC_BUS_CYCLE_NS 1
21950
21951 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21952-#define apic_debug(fmt, arg...)
21953+#define apic_debug(fmt, arg...) do {} while (0)
21954
21955 #define APIC_LVT_NUM 6
21956 /* 14 is the version for Xeon and Pentium 8.4.8*/
21957diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21958index 714e2c0..3f7a086 100644
21959--- a/arch/x86/kvm/paging_tmpl.h
21960+++ b/arch/x86/kvm/paging_tmpl.h
21961@@ -208,7 +208,7 @@ retry_walk:
21962 if (unlikely(kvm_is_error_hva(host_addr)))
21963 goto error;
21964
21965- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21966+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21967 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21968 goto error;
21969 walker->ptep_user[walker->level - 1] = ptep_user;
21970diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21971index d017df3..61ae42e 100644
21972--- a/arch/x86/kvm/svm.c
21973+++ b/arch/x86/kvm/svm.c
21974@@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21975 int cpu = raw_smp_processor_id();
21976
21977 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21978+
21979+ pax_open_kernel();
21980 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21981+ pax_close_kernel();
21982+
21983 load_TR_desc();
21984 }
21985
21986@@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21987 #endif
21988 #endif
21989
21990+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21991+ __set_fs(current_thread_info()->addr_limit);
21992+#endif
21993+
21994 reload_tss(vcpu);
21995
21996 local_irq_disable();
21997diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21998index f858159..4ab7dba 100644
21999--- a/arch/x86/kvm/vmx.c
22000+++ b/arch/x86/kvm/vmx.c
22001@@ -1332,7 +1332,11 @@ static void reload_tss(void)
22002 struct desc_struct *descs;
22003
22004 descs = (void *)gdt->address;
22005+
22006+ pax_open_kernel();
22007 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
22008+ pax_close_kernel();
22009+
22010 load_TR_desc();
22011 }
22012
22013@@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
22014 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
22015 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
22016
22017+#ifdef CONFIG_PAX_PER_CPU_PGD
22018+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
22019+#endif
22020+
22021 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
22022 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
22023 vmx->loaded_vmcs->cpu = cpu;
22024@@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
22025 if (!cpu_has_vmx_flexpriority())
22026 flexpriority_enabled = 0;
22027
22028- if (!cpu_has_vmx_tpr_shadow())
22029- kvm_x86_ops->update_cr8_intercept = NULL;
22030+ if (!cpu_has_vmx_tpr_shadow()) {
22031+ pax_open_kernel();
22032+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
22033+ pax_close_kernel();
22034+ }
22035
22036 if (enable_ept && !cpu_has_vmx_ept_2m_page())
22037 kvm_disable_largepages();
22038@@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
22039
22040 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
22041 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
22042+
22043+#ifndef CONFIG_PAX_PER_CPU_PGD
22044 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
22045+#endif
22046
22047 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
22048 #ifdef CONFIG_X86_64
22049@@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
22050 native_store_idt(&dt);
22051 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
22052
22053- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
22054+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
22055
22056 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
22057 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
22058@@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22059 "jmp 2f \n\t"
22060 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
22061 "2: "
22062+
22063+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22064+ "ljmp %[cs],$3f\n\t"
22065+ "3: "
22066+#endif
22067+
22068 /* Save guest registers, load host registers, keep flags */
22069 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
22070 "pop %0 \n\t"
22071@@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22072 #endif
22073 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
22074 [wordsize]"i"(sizeof(ulong))
22075+
22076+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
22077+ ,[cs]"i"(__KERNEL_CS)
22078+#endif
22079+
22080 : "cc", "memory"
22081 #ifdef CONFIG_X86_64
22082 , "rax", "rbx", "rdi", "rsi"
22083@@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22084 if (debugctlmsr)
22085 update_debugctlmsr(debugctlmsr);
22086
22087-#ifndef CONFIG_X86_64
22088+#ifdef CONFIG_X86_32
22089 /*
22090 * The sysexit path does not restore ds/es, so we must set them to
22091 * a reasonable value ourselves.
22092@@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
22093 * may be executed in interrupt context, which saves and restore segments
22094 * around it, nullifying its effect.
22095 */
22096- loadsegment(ds, __USER_DS);
22097- loadsegment(es, __USER_DS);
22098+ loadsegment(ds, __KERNEL_DS);
22099+ loadsegment(es, __KERNEL_DS);
22100+ loadsegment(ss, __KERNEL_DS);
22101+
22102+#ifdef CONFIG_PAX_KERNEXEC
22103+ loadsegment(fs, __KERNEL_PERCPU);
22104+#endif
22105+
22106+#ifdef CONFIG_PAX_MEMORY_UDEREF
22107+ __set_fs(current_thread_info()->addr_limit);
22108+#endif
22109+
22110 #endif
22111
22112 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
22113diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
22114index 4f76417..93429b5 100644
22115--- a/arch/x86/kvm/x86.c
22116+++ b/arch/x86/kvm/x86.c
22117@@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
22118 {
22119 struct kvm *kvm = vcpu->kvm;
22120 int lm = is_long_mode(vcpu);
22121- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22122- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22123+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
22124+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
22125 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
22126 : kvm->arch.xen_hvm_config.blob_size_32;
22127 u32 page_num = data & ~PAGE_MASK;
22128@@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
22129 if (n < msr_list.nmsrs)
22130 goto out;
22131 r = -EFAULT;
22132+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
22133+ goto out;
22134 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22135 num_msrs_to_save * sizeof(u32)))
22136 goto out;
22137@@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22138 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22139 struct kvm_interrupt *irq)
22140 {
22141- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22142+ if (irq->irq >= KVM_NR_INTERRUPTS)
22143 return -EINVAL;
22144 if (irqchip_in_kernel(vcpu->kvm))
22145 return -ENXIO;
22146@@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22147 kvm_mmu_set_mmio_spte_mask(mask);
22148 }
22149
22150-int kvm_arch_init(void *opaque)
22151+int kvm_arch_init(const void *opaque)
22152 {
22153 int r;
22154 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22155diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22156index 642d880..44e0f3f 100644
22157--- a/arch/x86/lguest/boot.c
22158+++ b/arch/x86/lguest/boot.c
22159@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22160 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22161 * Launcher to reboot us.
22162 */
22163-static void lguest_restart(char *reason)
22164+static __noreturn void lguest_restart(char *reason)
22165 {
22166 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22167+ BUG();
22168 }
22169
22170 /*G:050
22171diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22172index 00933d5..3a64af9 100644
22173--- a/arch/x86/lib/atomic64_386_32.S
22174+++ b/arch/x86/lib/atomic64_386_32.S
22175@@ -48,6 +48,10 @@ BEGIN(read)
22176 movl (v), %eax
22177 movl 4(v), %edx
22178 RET_ENDP
22179+BEGIN(read_unchecked)
22180+ movl (v), %eax
22181+ movl 4(v), %edx
22182+RET_ENDP
22183 #undef v
22184
22185 #define v %esi
22186@@ -55,6 +59,10 @@ BEGIN(set)
22187 movl %ebx, (v)
22188 movl %ecx, 4(v)
22189 RET_ENDP
22190+BEGIN(set_unchecked)
22191+ movl %ebx, (v)
22192+ movl %ecx, 4(v)
22193+RET_ENDP
22194 #undef v
22195
22196 #define v %esi
22197@@ -70,6 +78,20 @@ RET_ENDP
22198 BEGIN(add)
22199 addl %eax, (v)
22200 adcl %edx, 4(v)
22201+
22202+#ifdef CONFIG_PAX_REFCOUNT
22203+ jno 0f
22204+ subl %eax, (v)
22205+ sbbl %edx, 4(v)
22206+ int $4
22207+0:
22208+ _ASM_EXTABLE(0b, 0b)
22209+#endif
22210+
22211+RET_ENDP
22212+BEGIN(add_unchecked)
22213+ addl %eax, (v)
22214+ adcl %edx, 4(v)
22215 RET_ENDP
22216 #undef v
22217
22218@@ -77,6 +99,24 @@ RET_ENDP
22219 BEGIN(add_return)
22220 addl (v), %eax
22221 adcl 4(v), %edx
22222+
22223+#ifdef CONFIG_PAX_REFCOUNT
22224+ into
22225+1234:
22226+ _ASM_EXTABLE(1234b, 2f)
22227+#endif
22228+
22229+ movl %eax, (v)
22230+ movl %edx, 4(v)
22231+
22232+#ifdef CONFIG_PAX_REFCOUNT
22233+2:
22234+#endif
22235+
22236+RET_ENDP
22237+BEGIN(add_return_unchecked)
22238+ addl (v), %eax
22239+ adcl 4(v), %edx
22240 movl %eax, (v)
22241 movl %edx, 4(v)
22242 RET_ENDP
22243@@ -86,6 +126,20 @@ RET_ENDP
22244 BEGIN(sub)
22245 subl %eax, (v)
22246 sbbl %edx, 4(v)
22247+
22248+#ifdef CONFIG_PAX_REFCOUNT
22249+ jno 0f
22250+ addl %eax, (v)
22251+ adcl %edx, 4(v)
22252+ int $4
22253+0:
22254+ _ASM_EXTABLE(0b, 0b)
22255+#endif
22256+
22257+RET_ENDP
22258+BEGIN(sub_unchecked)
22259+ subl %eax, (v)
22260+ sbbl %edx, 4(v)
22261 RET_ENDP
22262 #undef v
22263
22264@@ -96,6 +150,27 @@ BEGIN(sub_return)
22265 sbbl $0, %edx
22266 addl (v), %eax
22267 adcl 4(v), %edx
22268+
22269+#ifdef CONFIG_PAX_REFCOUNT
22270+ into
22271+1234:
22272+ _ASM_EXTABLE(1234b, 2f)
22273+#endif
22274+
22275+ movl %eax, (v)
22276+ movl %edx, 4(v)
22277+
22278+#ifdef CONFIG_PAX_REFCOUNT
22279+2:
22280+#endif
22281+
22282+RET_ENDP
22283+BEGIN(sub_return_unchecked)
22284+ negl %edx
22285+ negl %eax
22286+ sbbl $0, %edx
22287+ addl (v), %eax
22288+ adcl 4(v), %edx
22289 movl %eax, (v)
22290 movl %edx, 4(v)
22291 RET_ENDP
22292@@ -105,6 +180,20 @@ RET_ENDP
22293 BEGIN(inc)
22294 addl $1, (v)
22295 adcl $0, 4(v)
22296+
22297+#ifdef CONFIG_PAX_REFCOUNT
22298+ jno 0f
22299+ subl $1, (v)
22300+ sbbl $0, 4(v)
22301+ int $4
22302+0:
22303+ _ASM_EXTABLE(0b, 0b)
22304+#endif
22305+
22306+RET_ENDP
22307+BEGIN(inc_unchecked)
22308+ addl $1, (v)
22309+ adcl $0, 4(v)
22310 RET_ENDP
22311 #undef v
22312
22313@@ -114,6 +203,26 @@ BEGIN(inc_return)
22314 movl 4(v), %edx
22315 addl $1, %eax
22316 adcl $0, %edx
22317+
22318+#ifdef CONFIG_PAX_REFCOUNT
22319+ into
22320+1234:
22321+ _ASM_EXTABLE(1234b, 2f)
22322+#endif
22323+
22324+ movl %eax, (v)
22325+ movl %edx, 4(v)
22326+
22327+#ifdef CONFIG_PAX_REFCOUNT
22328+2:
22329+#endif
22330+
22331+RET_ENDP
22332+BEGIN(inc_return_unchecked)
22333+ movl (v), %eax
22334+ movl 4(v), %edx
22335+ addl $1, %eax
22336+ adcl $0, %edx
22337 movl %eax, (v)
22338 movl %edx, 4(v)
22339 RET_ENDP
22340@@ -123,6 +232,20 @@ RET_ENDP
22341 BEGIN(dec)
22342 subl $1, (v)
22343 sbbl $0, 4(v)
22344+
22345+#ifdef CONFIG_PAX_REFCOUNT
22346+ jno 0f
22347+ addl $1, (v)
22348+ adcl $0, 4(v)
22349+ int $4
22350+0:
22351+ _ASM_EXTABLE(0b, 0b)
22352+#endif
22353+
22354+RET_ENDP
22355+BEGIN(dec_unchecked)
22356+ subl $1, (v)
22357+ sbbl $0, 4(v)
22358 RET_ENDP
22359 #undef v
22360
22361@@ -132,6 +255,26 @@ BEGIN(dec_return)
22362 movl 4(v), %edx
22363 subl $1, %eax
22364 sbbl $0, %edx
22365+
22366+#ifdef CONFIG_PAX_REFCOUNT
22367+ into
22368+1234:
22369+ _ASM_EXTABLE(1234b, 2f)
22370+#endif
22371+
22372+ movl %eax, (v)
22373+ movl %edx, 4(v)
22374+
22375+#ifdef CONFIG_PAX_REFCOUNT
22376+2:
22377+#endif
22378+
22379+RET_ENDP
22380+BEGIN(dec_return_unchecked)
22381+ movl (v), %eax
22382+ movl 4(v), %edx
22383+ subl $1, %eax
22384+ sbbl $0, %edx
22385 movl %eax, (v)
22386 movl %edx, 4(v)
22387 RET_ENDP
22388@@ -143,6 +286,13 @@ BEGIN(add_unless)
22389 adcl %edx, %edi
22390 addl (v), %eax
22391 adcl 4(v), %edx
22392+
22393+#ifdef CONFIG_PAX_REFCOUNT
22394+ into
22395+1234:
22396+ _ASM_EXTABLE(1234b, 2f)
22397+#endif
22398+
22399 cmpl %eax, %ecx
22400 je 3f
22401 1:
22402@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22403 1:
22404 addl $1, %eax
22405 adcl $0, %edx
22406+
22407+#ifdef CONFIG_PAX_REFCOUNT
22408+ into
22409+1234:
22410+ _ASM_EXTABLE(1234b, 2f)
22411+#endif
22412+
22413 movl %eax, (v)
22414 movl %edx, 4(v)
22415 movl $1, %eax
22416@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22417 movl 4(v), %edx
22418 subl $1, %eax
22419 sbbl $0, %edx
22420+
22421+#ifdef CONFIG_PAX_REFCOUNT
22422+ into
22423+1234:
22424+ _ASM_EXTABLE(1234b, 1f)
22425+#endif
22426+
22427 js 1f
22428 movl %eax, (v)
22429 movl %edx, 4(v)
22430diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22431index f5cc9eb..51fa319 100644
22432--- a/arch/x86/lib/atomic64_cx8_32.S
22433+++ b/arch/x86/lib/atomic64_cx8_32.S
22434@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22435 CFI_STARTPROC
22436
22437 read64 %ecx
22438+ pax_force_retaddr
22439 ret
22440 CFI_ENDPROC
22441 ENDPROC(atomic64_read_cx8)
22442
22443+ENTRY(atomic64_read_unchecked_cx8)
22444+ CFI_STARTPROC
22445+
22446+ read64 %ecx
22447+ pax_force_retaddr
22448+ ret
22449+ CFI_ENDPROC
22450+ENDPROC(atomic64_read_unchecked_cx8)
22451+
22452 ENTRY(atomic64_set_cx8)
22453 CFI_STARTPROC
22454
22455@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22456 cmpxchg8b (%esi)
22457 jne 1b
22458
22459+ pax_force_retaddr
22460 ret
22461 CFI_ENDPROC
22462 ENDPROC(atomic64_set_cx8)
22463
22464+ENTRY(atomic64_set_unchecked_cx8)
22465+ CFI_STARTPROC
22466+
22467+1:
22468+/* we don't need LOCK_PREFIX since aligned 64-bit writes
22469+ * are atomic on 586 and newer */
22470+ cmpxchg8b (%esi)
22471+ jne 1b
22472+
22473+ pax_force_retaddr
22474+ ret
22475+ CFI_ENDPROC
22476+ENDPROC(atomic64_set_unchecked_cx8)
22477+
22478 ENTRY(atomic64_xchg_cx8)
22479 CFI_STARTPROC
22480
22481@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22482 cmpxchg8b (%esi)
22483 jne 1b
22484
22485+ pax_force_retaddr
22486 ret
22487 CFI_ENDPROC
22488 ENDPROC(atomic64_xchg_cx8)
22489
22490-.macro addsub_return func ins insc
22491-ENTRY(atomic64_\func\()_return_cx8)
22492+.macro addsub_return func ins insc unchecked=""
22493+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22494 CFI_STARTPROC
22495 SAVE ebp
22496 SAVE ebx
22497@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22498 movl %edx, %ecx
22499 \ins\()l %esi, %ebx
22500 \insc\()l %edi, %ecx
22501+
22502+.ifb \unchecked
22503+#ifdef CONFIG_PAX_REFCOUNT
22504+ into
22505+2:
22506+ _ASM_EXTABLE(2b, 3f)
22507+#endif
22508+.endif
22509+
22510 LOCK_PREFIX
22511 cmpxchg8b (%ebp)
22512 jne 1b
22513-
22514-10:
22515 movl %ebx, %eax
22516 movl %ecx, %edx
22517+
22518+.ifb \unchecked
22519+#ifdef CONFIG_PAX_REFCOUNT
22520+3:
22521+#endif
22522+.endif
22523+
22524 RESTORE edi
22525 RESTORE esi
22526 RESTORE ebx
22527 RESTORE ebp
22528+ pax_force_retaddr
22529 ret
22530 CFI_ENDPROC
22531-ENDPROC(atomic64_\func\()_return_cx8)
22532+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22533 .endm
22534
22535 addsub_return add add adc
22536 addsub_return sub sub sbb
22537+addsub_return add add adc _unchecked
22538+addsub_return sub sub sbb _unchecked
22539
22540-.macro incdec_return func ins insc
22541-ENTRY(atomic64_\func\()_return_cx8)
22542+.macro incdec_return func ins insc unchecked=""
22543+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22544 CFI_STARTPROC
22545 SAVE ebx
22546
22547@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22548 movl %edx, %ecx
22549 \ins\()l $1, %ebx
22550 \insc\()l $0, %ecx
22551+
22552+.ifb \unchecked
22553+#ifdef CONFIG_PAX_REFCOUNT
22554+ into
22555+2:
22556+ _ASM_EXTABLE(2b, 3f)
22557+#endif
22558+.endif
22559+
22560 LOCK_PREFIX
22561 cmpxchg8b (%esi)
22562 jne 1b
22563
22564-10:
22565 movl %ebx, %eax
22566 movl %ecx, %edx
22567+
22568+.ifb \unchecked
22569+#ifdef CONFIG_PAX_REFCOUNT
22570+3:
22571+#endif
22572+.endif
22573+
22574 RESTORE ebx
22575+ pax_force_retaddr
22576 ret
22577 CFI_ENDPROC
22578-ENDPROC(atomic64_\func\()_return_cx8)
22579+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22580 .endm
22581
22582 incdec_return inc add adc
22583 incdec_return dec sub sbb
22584+incdec_return inc add adc _unchecked
22585+incdec_return dec sub sbb _unchecked
22586
22587 ENTRY(atomic64_dec_if_positive_cx8)
22588 CFI_STARTPROC
22589@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22590 movl %edx, %ecx
22591 subl $1, %ebx
22592 sbb $0, %ecx
22593+
22594+#ifdef CONFIG_PAX_REFCOUNT
22595+ into
22596+1234:
22597+ _ASM_EXTABLE(1234b, 2f)
22598+#endif
22599+
22600 js 2f
22601 LOCK_PREFIX
22602 cmpxchg8b (%esi)
22603@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22604 movl %ebx, %eax
22605 movl %ecx, %edx
22606 RESTORE ebx
22607+ pax_force_retaddr
22608 ret
22609 CFI_ENDPROC
22610 ENDPROC(atomic64_dec_if_positive_cx8)
22611@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22612 movl %edx, %ecx
22613 addl %ebp, %ebx
22614 adcl %edi, %ecx
22615+
22616+#ifdef CONFIG_PAX_REFCOUNT
22617+ into
22618+1234:
22619+ _ASM_EXTABLE(1234b, 3f)
22620+#endif
22621+
22622 LOCK_PREFIX
22623 cmpxchg8b (%esi)
22624 jne 1b
22625@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22626 CFI_ADJUST_CFA_OFFSET -8
22627 RESTORE ebx
22628 RESTORE ebp
22629+ pax_force_retaddr
22630 ret
22631 4:
22632 cmpl %edx, 4(%esp)
22633@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22634 xorl %ecx, %ecx
22635 addl $1, %ebx
22636 adcl %edx, %ecx
22637+
22638+#ifdef CONFIG_PAX_REFCOUNT
22639+ into
22640+1234:
22641+ _ASM_EXTABLE(1234b, 3f)
22642+#endif
22643+
22644 LOCK_PREFIX
22645 cmpxchg8b (%esi)
22646 jne 1b
22647@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22648 movl $1, %eax
22649 3:
22650 RESTORE ebx
22651+ pax_force_retaddr
22652 ret
22653 CFI_ENDPROC
22654 ENDPROC(atomic64_inc_not_zero_cx8)
22655diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22656index 2af5df3..62b1a5a 100644
22657--- a/arch/x86/lib/checksum_32.S
22658+++ b/arch/x86/lib/checksum_32.S
22659@@ -29,7 +29,8 @@
22660 #include <asm/dwarf2.h>
22661 #include <asm/errno.h>
22662 #include <asm/asm.h>
22663-
22664+#include <asm/segment.h>
22665+
22666 /*
22667 * computes a partial checksum, e.g. for TCP/UDP fragments
22668 */
22669@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22670
22671 #define ARGBASE 16
22672 #define FP 12
22673-
22674-ENTRY(csum_partial_copy_generic)
22675+
22676+ENTRY(csum_partial_copy_generic_to_user)
22677 CFI_STARTPROC
22678+
22679+#ifdef CONFIG_PAX_MEMORY_UDEREF
22680+ pushl_cfi %gs
22681+ popl_cfi %es
22682+ jmp csum_partial_copy_generic
22683+#endif
22684+
22685+ENTRY(csum_partial_copy_generic_from_user)
22686+
22687+#ifdef CONFIG_PAX_MEMORY_UDEREF
22688+ pushl_cfi %gs
22689+ popl_cfi %ds
22690+#endif
22691+
22692+ENTRY(csum_partial_copy_generic)
22693 subl $4,%esp
22694 CFI_ADJUST_CFA_OFFSET 4
22695 pushl_cfi %edi
22696@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22697 jmp 4f
22698 SRC(1: movw (%esi), %bx )
22699 addl $2, %esi
22700-DST( movw %bx, (%edi) )
22701+DST( movw %bx, %es:(%edi) )
22702 addl $2, %edi
22703 addw %bx, %ax
22704 adcl $0, %eax
22705@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22706 SRC(1: movl (%esi), %ebx )
22707 SRC( movl 4(%esi), %edx )
22708 adcl %ebx, %eax
22709-DST( movl %ebx, (%edi) )
22710+DST( movl %ebx, %es:(%edi) )
22711 adcl %edx, %eax
22712-DST( movl %edx, 4(%edi) )
22713+DST( movl %edx, %es:4(%edi) )
22714
22715 SRC( movl 8(%esi), %ebx )
22716 SRC( movl 12(%esi), %edx )
22717 adcl %ebx, %eax
22718-DST( movl %ebx, 8(%edi) )
22719+DST( movl %ebx, %es:8(%edi) )
22720 adcl %edx, %eax
22721-DST( movl %edx, 12(%edi) )
22722+DST( movl %edx, %es:12(%edi) )
22723
22724 SRC( movl 16(%esi), %ebx )
22725 SRC( movl 20(%esi), %edx )
22726 adcl %ebx, %eax
22727-DST( movl %ebx, 16(%edi) )
22728+DST( movl %ebx, %es:16(%edi) )
22729 adcl %edx, %eax
22730-DST( movl %edx, 20(%edi) )
22731+DST( movl %edx, %es:20(%edi) )
22732
22733 SRC( movl 24(%esi), %ebx )
22734 SRC( movl 28(%esi), %edx )
22735 adcl %ebx, %eax
22736-DST( movl %ebx, 24(%edi) )
22737+DST( movl %ebx, %es:24(%edi) )
22738 adcl %edx, %eax
22739-DST( movl %edx, 28(%edi) )
22740+DST( movl %edx, %es:28(%edi) )
22741
22742 lea 32(%esi), %esi
22743 lea 32(%edi), %edi
22744@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22745 shrl $2, %edx # This clears CF
22746 SRC(3: movl (%esi), %ebx )
22747 adcl %ebx, %eax
22748-DST( movl %ebx, (%edi) )
22749+DST( movl %ebx, %es:(%edi) )
22750 lea 4(%esi), %esi
22751 lea 4(%edi), %edi
22752 dec %edx
22753@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22754 jb 5f
22755 SRC( movw (%esi), %cx )
22756 leal 2(%esi), %esi
22757-DST( movw %cx, (%edi) )
22758+DST( movw %cx, %es:(%edi) )
22759 leal 2(%edi), %edi
22760 je 6f
22761 shll $16,%ecx
22762 SRC(5: movb (%esi), %cl )
22763-DST( movb %cl, (%edi) )
22764+DST( movb %cl, %es:(%edi) )
22765 6: addl %ecx, %eax
22766 adcl $0, %eax
22767 7:
22768@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22769
22770 6001:
22771 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22772- movl $-EFAULT, (%ebx)
22773+ movl $-EFAULT, %ss:(%ebx)
22774
22775 # zero the complete destination - computing the rest
22776 # is too much work
22777@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22778
22779 6002:
22780 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22781- movl $-EFAULT,(%ebx)
22782+ movl $-EFAULT,%ss:(%ebx)
22783 jmp 5000b
22784
22785 .previous
22786
22787+ pushl_cfi %ss
22788+ popl_cfi %ds
22789+ pushl_cfi %ss
22790+ popl_cfi %es
22791 popl_cfi %ebx
22792 CFI_RESTORE ebx
22793 popl_cfi %esi
22794@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22795 popl_cfi %ecx # equivalent to addl $4,%esp
22796 ret
22797 CFI_ENDPROC
22798-ENDPROC(csum_partial_copy_generic)
22799+ENDPROC(csum_partial_copy_generic_to_user)
22800
22801 #else
22802
22803 /* Version for PentiumII/PPro */
22804
22805 #define ROUND1(x) \
22806+ nop; nop; nop; \
22807 SRC(movl x(%esi), %ebx ) ; \
22808 addl %ebx, %eax ; \
22809- DST(movl %ebx, x(%edi) ) ;
22810+ DST(movl %ebx, %es:x(%edi)) ;
22811
22812 #define ROUND(x) \
22813+ nop; nop; nop; \
22814 SRC(movl x(%esi), %ebx ) ; \
22815 adcl %ebx, %eax ; \
22816- DST(movl %ebx, x(%edi) ) ;
22817+ DST(movl %ebx, %es:x(%edi)) ;
22818
22819 #define ARGBASE 12
22820-
22821-ENTRY(csum_partial_copy_generic)
22822+
22823+ENTRY(csum_partial_copy_generic_to_user)
22824 CFI_STARTPROC
22825+
22826+#ifdef CONFIG_PAX_MEMORY_UDEREF
22827+ pushl_cfi %gs
22828+ popl_cfi %es
22829+ jmp csum_partial_copy_generic
22830+#endif
22831+
22832+ENTRY(csum_partial_copy_generic_from_user)
22833+
22834+#ifdef CONFIG_PAX_MEMORY_UDEREF
22835+ pushl_cfi %gs
22836+ popl_cfi %ds
22837+#endif
22838+
22839+ENTRY(csum_partial_copy_generic)
22840 pushl_cfi %ebx
22841 CFI_REL_OFFSET ebx, 0
22842 pushl_cfi %edi
22843@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22844 subl %ebx, %edi
22845 lea -1(%esi),%edx
22846 andl $-32,%edx
22847- lea 3f(%ebx,%ebx), %ebx
22848+ lea 3f(%ebx,%ebx,2), %ebx
22849 testl %esi, %esi
22850 jmp *%ebx
22851 1: addl $64,%esi
22852@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22853 jb 5f
22854 SRC( movw (%esi), %dx )
22855 leal 2(%esi), %esi
22856-DST( movw %dx, (%edi) )
22857+DST( movw %dx, %es:(%edi) )
22858 leal 2(%edi), %edi
22859 je 6f
22860 shll $16,%edx
22861 5:
22862 SRC( movb (%esi), %dl )
22863-DST( movb %dl, (%edi) )
22864+DST( movb %dl, %es:(%edi) )
22865 6: addl %edx, %eax
22866 adcl $0, %eax
22867 7:
22868 .section .fixup, "ax"
22869 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22870- movl $-EFAULT, (%ebx)
22871+ movl $-EFAULT, %ss:(%ebx)
22872 # zero the complete destination (computing the rest is too much work)
22873 movl ARGBASE+8(%esp),%edi # dst
22874 movl ARGBASE+12(%esp),%ecx # len
22875@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22876 rep; stosb
22877 jmp 7b
22878 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22879- movl $-EFAULT, (%ebx)
22880+ movl $-EFAULT, %ss:(%ebx)
22881 jmp 7b
22882 .previous
22883
22884+#ifdef CONFIG_PAX_MEMORY_UDEREF
22885+ pushl_cfi %ss
22886+ popl_cfi %ds
22887+ pushl_cfi %ss
22888+ popl_cfi %es
22889+#endif
22890+
22891 popl_cfi %esi
22892 CFI_RESTORE esi
22893 popl_cfi %edi
22894@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22895 CFI_RESTORE ebx
22896 ret
22897 CFI_ENDPROC
22898-ENDPROC(csum_partial_copy_generic)
22899+ENDPROC(csum_partial_copy_generic_to_user)
22900
22901 #undef ROUND
22902 #undef ROUND1
22903diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22904index f2145cf..cea889d 100644
22905--- a/arch/x86/lib/clear_page_64.S
22906+++ b/arch/x86/lib/clear_page_64.S
22907@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22908 movl $4096/8,%ecx
22909 xorl %eax,%eax
22910 rep stosq
22911+ pax_force_retaddr
22912 ret
22913 CFI_ENDPROC
22914 ENDPROC(clear_page_c)
22915@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22916 movl $4096,%ecx
22917 xorl %eax,%eax
22918 rep stosb
22919+ pax_force_retaddr
22920 ret
22921 CFI_ENDPROC
22922 ENDPROC(clear_page_c_e)
22923@@ -43,6 +45,7 @@ ENTRY(clear_page)
22924 leaq 64(%rdi),%rdi
22925 jnz .Lloop
22926 nop
22927+ pax_force_retaddr
22928 ret
22929 CFI_ENDPROC
22930 .Lclear_page_end:
22931@@ -58,7 +61,7 @@ ENDPROC(clear_page)
22932
22933 #include <asm/cpufeature.h>
22934
22935- .section .altinstr_replacement,"ax"
22936+ .section .altinstr_replacement,"a"
22937 1: .byte 0xeb /* jmp <disp8> */
22938 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22939 2: .byte 0xeb /* jmp <disp8> */
22940diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22941index 1e572c5..2a162cd 100644
22942--- a/arch/x86/lib/cmpxchg16b_emu.S
22943+++ b/arch/x86/lib/cmpxchg16b_emu.S
22944@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22945
22946 popf
22947 mov $1, %al
22948+ pax_force_retaddr
22949 ret
22950
22951 not_same:
22952 popf
22953 xor %al,%al
22954+ pax_force_retaddr
22955 ret
22956
22957 CFI_ENDPROC
22958diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22959index 6b34d04..dccb07f 100644
22960--- a/arch/x86/lib/copy_page_64.S
22961+++ b/arch/x86/lib/copy_page_64.S
22962@@ -9,6 +9,7 @@ copy_page_c:
22963 CFI_STARTPROC
22964 movl $4096/8,%ecx
22965 rep movsq
22966+ pax_force_retaddr
22967 ret
22968 CFI_ENDPROC
22969 ENDPROC(copy_page_c)
22970@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22971
22972 ENTRY(copy_page)
22973 CFI_STARTPROC
22974- subq $2*8,%rsp
22975- CFI_ADJUST_CFA_OFFSET 2*8
22976+ subq $3*8,%rsp
22977+ CFI_ADJUST_CFA_OFFSET 3*8
22978 movq %rbx,(%rsp)
22979 CFI_REL_OFFSET rbx, 0
22980 movq %r12,1*8(%rsp)
22981 CFI_REL_OFFSET r12, 1*8
22982+ movq %r13,2*8(%rsp)
22983+ CFI_REL_OFFSET r13, 2*8
22984
22985 movl $(4096/64)-5,%ecx
22986 .p2align 4
22987@@ -37,7 +40,7 @@ ENTRY(copy_page)
22988 movq 16 (%rsi), %rdx
22989 movq 24 (%rsi), %r8
22990 movq 32 (%rsi), %r9
22991- movq 40 (%rsi), %r10
22992+ movq 40 (%rsi), %r13
22993 movq 48 (%rsi), %r11
22994 movq 56 (%rsi), %r12
22995
22996@@ -48,7 +51,7 @@ ENTRY(copy_page)
22997 movq %rdx, 16 (%rdi)
22998 movq %r8, 24 (%rdi)
22999 movq %r9, 32 (%rdi)
23000- movq %r10, 40 (%rdi)
23001+ movq %r13, 40 (%rdi)
23002 movq %r11, 48 (%rdi)
23003 movq %r12, 56 (%rdi)
23004
23005@@ -67,7 +70,7 @@ ENTRY(copy_page)
23006 movq 16 (%rsi), %rdx
23007 movq 24 (%rsi), %r8
23008 movq 32 (%rsi), %r9
23009- movq 40 (%rsi), %r10
23010+ movq 40 (%rsi), %r13
23011 movq 48 (%rsi), %r11
23012 movq 56 (%rsi), %r12
23013
23014@@ -76,7 +79,7 @@ ENTRY(copy_page)
23015 movq %rdx, 16 (%rdi)
23016 movq %r8, 24 (%rdi)
23017 movq %r9, 32 (%rdi)
23018- movq %r10, 40 (%rdi)
23019+ movq %r13, 40 (%rdi)
23020 movq %r11, 48 (%rdi)
23021 movq %r12, 56 (%rdi)
23022
23023@@ -89,8 +92,11 @@ ENTRY(copy_page)
23024 CFI_RESTORE rbx
23025 movq 1*8(%rsp),%r12
23026 CFI_RESTORE r12
23027- addq $2*8,%rsp
23028- CFI_ADJUST_CFA_OFFSET -2*8
23029+ movq 2*8(%rsp),%r13
23030+ CFI_RESTORE r13
23031+ addq $3*8,%rsp
23032+ CFI_ADJUST_CFA_OFFSET -3*8
23033+ pax_force_retaddr
23034 ret
23035 .Lcopy_page_end:
23036 CFI_ENDPROC
23037@@ -101,7 +107,7 @@ ENDPROC(copy_page)
23038
23039 #include <asm/cpufeature.h>
23040
23041- .section .altinstr_replacement,"ax"
23042+ .section .altinstr_replacement,"a"
23043 1: .byte 0xeb /* jmp <disp8> */
23044 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23045 2:
23046diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23047index a30ca15..d25fab6 100644
23048--- a/arch/x86/lib/copy_user_64.S
23049+++ b/arch/x86/lib/copy_user_64.S
23050@@ -18,6 +18,7 @@
23051 #include <asm/alternative-asm.h>
23052 #include <asm/asm.h>
23053 #include <asm/smap.h>
23054+#include <asm/pgtable.h>
23055
23056 /*
23057 * By placing feature2 after feature1 in altinstructions section, we logically
23058@@ -31,7 +32,7 @@
23059 .byte 0xe9 /* 32bit jump */
23060 .long \orig-1f /* by default jump to orig */
23061 1:
23062- .section .altinstr_replacement,"ax"
23063+ .section .altinstr_replacement,"a"
23064 2: .byte 0xe9 /* near jump with 32bit immediate */
23065 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23066 3: .byte 0xe9 /* near jump with 32bit immediate */
23067@@ -70,47 +71,20 @@
23068 #endif
23069 .endm
23070
23071-/* Standard copy_to_user with segment limit checking */
23072-ENTRY(_copy_to_user)
23073- CFI_STARTPROC
23074- GET_THREAD_INFO(%rax)
23075- movq %rdi,%rcx
23076- addq %rdx,%rcx
23077- jc bad_to_user
23078- cmpq TI_addr_limit(%rax),%rcx
23079- ja bad_to_user
23080- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23081- copy_user_generic_unrolled,copy_user_generic_string, \
23082- copy_user_enhanced_fast_string
23083- CFI_ENDPROC
23084-ENDPROC(_copy_to_user)
23085-
23086-/* Standard copy_from_user with segment limit checking */
23087-ENTRY(_copy_from_user)
23088- CFI_STARTPROC
23089- GET_THREAD_INFO(%rax)
23090- movq %rsi,%rcx
23091- addq %rdx,%rcx
23092- jc bad_from_user
23093- cmpq TI_addr_limit(%rax),%rcx
23094- ja bad_from_user
23095- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23096- copy_user_generic_unrolled,copy_user_generic_string, \
23097- copy_user_enhanced_fast_string
23098- CFI_ENDPROC
23099-ENDPROC(_copy_from_user)
23100-
23101 .section .fixup,"ax"
23102 /* must zero dest */
23103 ENTRY(bad_from_user)
23104 bad_from_user:
23105 CFI_STARTPROC
23106+ testl %edx,%edx
23107+ js bad_to_user
23108 movl %edx,%ecx
23109 xorl %eax,%eax
23110 rep
23111 stosb
23112 bad_to_user:
23113 movl %edx,%eax
23114+ pax_force_retaddr
23115 ret
23116 CFI_ENDPROC
23117 ENDPROC(bad_from_user)
23118@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23119 jz 17f
23120 1: movq (%rsi),%r8
23121 2: movq 1*8(%rsi),%r9
23122-3: movq 2*8(%rsi),%r10
23123+3: movq 2*8(%rsi),%rax
23124 4: movq 3*8(%rsi),%r11
23125 5: movq %r8,(%rdi)
23126 6: movq %r9,1*8(%rdi)
23127-7: movq %r10,2*8(%rdi)
23128+7: movq %rax,2*8(%rdi)
23129 8: movq %r11,3*8(%rdi)
23130 9: movq 4*8(%rsi),%r8
23131 10: movq 5*8(%rsi),%r9
23132-11: movq 6*8(%rsi),%r10
23133+11: movq 6*8(%rsi),%rax
23134 12: movq 7*8(%rsi),%r11
23135 13: movq %r8,4*8(%rdi)
23136 14: movq %r9,5*8(%rdi)
23137-15: movq %r10,6*8(%rdi)
23138+15: movq %rax,6*8(%rdi)
23139 16: movq %r11,7*8(%rdi)
23140 leaq 64(%rsi),%rsi
23141 leaq 64(%rdi),%rdi
23142@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23143 jnz 21b
23144 23: xor %eax,%eax
23145 ASM_CLAC
23146+ pax_force_retaddr
23147 ret
23148
23149 .section .fixup,"ax"
23150@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23151 movsb
23152 4: xorl %eax,%eax
23153 ASM_CLAC
23154+ pax_force_retaddr
23155 ret
23156
23157 .section .fixup,"ax"
23158@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23159 movsb
23160 2: xorl %eax,%eax
23161 ASM_CLAC
23162+ pax_force_retaddr
23163 ret
23164
23165 .section .fixup,"ax"
23166diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23167index 6a4f43c..f5f9e26 100644
23168--- a/arch/x86/lib/copy_user_nocache_64.S
23169+++ b/arch/x86/lib/copy_user_nocache_64.S
23170@@ -8,6 +8,7 @@
23171
23172 #include <linux/linkage.h>
23173 #include <asm/dwarf2.h>
23174+#include <asm/alternative-asm.h>
23175
23176 #define FIX_ALIGNMENT 1
23177
23178@@ -16,6 +17,7 @@
23179 #include <asm/thread_info.h>
23180 #include <asm/asm.h>
23181 #include <asm/smap.h>
23182+#include <asm/pgtable.h>
23183
23184 .macro ALIGN_DESTINATION
23185 #ifdef FIX_ALIGNMENT
23186@@ -49,6 +51,15 @@
23187 */
23188 ENTRY(__copy_user_nocache)
23189 CFI_STARTPROC
23190+
23191+#ifdef CONFIG_PAX_MEMORY_UDEREF
23192+ mov $PAX_USER_SHADOW_BASE,%rcx
23193+ cmp %rcx,%rsi
23194+ jae 1f
23195+ add %rcx,%rsi
23196+1:
23197+#endif
23198+
23199 ASM_STAC
23200 cmpl $8,%edx
23201 jb 20f /* less then 8 bytes, go to byte copy loop */
23202@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23203 jz 17f
23204 1: movq (%rsi),%r8
23205 2: movq 1*8(%rsi),%r9
23206-3: movq 2*8(%rsi),%r10
23207+3: movq 2*8(%rsi),%rax
23208 4: movq 3*8(%rsi),%r11
23209 5: movnti %r8,(%rdi)
23210 6: movnti %r9,1*8(%rdi)
23211-7: movnti %r10,2*8(%rdi)
23212+7: movnti %rax,2*8(%rdi)
23213 8: movnti %r11,3*8(%rdi)
23214 9: movq 4*8(%rsi),%r8
23215 10: movq 5*8(%rsi),%r9
23216-11: movq 6*8(%rsi),%r10
23217+11: movq 6*8(%rsi),%rax
23218 12: movq 7*8(%rsi),%r11
23219 13: movnti %r8,4*8(%rdi)
23220 14: movnti %r9,5*8(%rdi)
23221-15: movnti %r10,6*8(%rdi)
23222+15: movnti %rax,6*8(%rdi)
23223 16: movnti %r11,7*8(%rdi)
23224 leaq 64(%rsi),%rsi
23225 leaq 64(%rdi),%rdi
23226@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23227 23: xorl %eax,%eax
23228 ASM_CLAC
23229 sfence
23230+ pax_force_retaddr
23231 ret
23232
23233 .section .fixup,"ax"
23234diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23235index 2419d5f..953ee51 100644
23236--- a/arch/x86/lib/csum-copy_64.S
23237+++ b/arch/x86/lib/csum-copy_64.S
23238@@ -9,6 +9,7 @@
23239 #include <asm/dwarf2.h>
23240 #include <asm/errno.h>
23241 #include <asm/asm.h>
23242+#include <asm/alternative-asm.h>
23243
23244 /*
23245 * Checksum copy with exception handling.
23246@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23247 CFI_RESTORE rbp
23248 addq $7*8, %rsp
23249 CFI_ADJUST_CFA_OFFSET -7*8
23250+ pax_force_retaddr 0, 1
23251 ret
23252 CFI_RESTORE_STATE
23253
23254diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23255index 25b7ae8..169fafc 100644
23256--- a/arch/x86/lib/csum-wrappers_64.c
23257+++ b/arch/x86/lib/csum-wrappers_64.c
23258@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23259 len -= 2;
23260 }
23261 }
23262- isum = csum_partial_copy_generic((__force const void *)src,
23263+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23264 dst, len, isum, errp, NULL);
23265 if (unlikely(*errp))
23266 goto out_err;
23267@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23268 }
23269
23270 *errp = 0;
23271- return csum_partial_copy_generic(src, (void __force *)dst,
23272+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23273 len, isum, NULL, errp);
23274 }
23275 EXPORT_SYMBOL(csum_partial_copy_to_user);
23276diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23277index 156b9c8..b144132 100644
23278--- a/arch/x86/lib/getuser.S
23279+++ b/arch/x86/lib/getuser.S
23280@@ -34,17 +34,40 @@
23281 #include <asm/thread_info.h>
23282 #include <asm/asm.h>
23283 #include <asm/smap.h>
23284+#include <asm/segment.h>
23285+#include <asm/pgtable.h>
23286+#include <asm/alternative-asm.h>
23287+
23288+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23289+#define __copyuser_seg gs;
23290+#else
23291+#define __copyuser_seg
23292+#endif
23293
23294 .text
23295 ENTRY(__get_user_1)
23296 CFI_STARTPROC
23297+
23298+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23299 GET_THREAD_INFO(%_ASM_DX)
23300 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23301 jae bad_get_user
23302 ASM_STAC
23303-1: movzb (%_ASM_AX),%edx
23304+
23305+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23306+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23307+ cmp %_ASM_DX,%_ASM_AX
23308+ jae 1234f
23309+ add %_ASM_DX,%_ASM_AX
23310+1234:
23311+#endif
23312+
23313+#endif
23314+
23315+1: __copyuser_seg movzb (%_ASM_AX),%edx
23316 xor %eax,%eax
23317 ASM_CLAC
23318+ pax_force_retaddr
23319 ret
23320 CFI_ENDPROC
23321 ENDPROC(__get_user_1)
23322@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23323 ENTRY(__get_user_2)
23324 CFI_STARTPROC
23325 add $1,%_ASM_AX
23326+
23327+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23328 jc bad_get_user
23329 GET_THREAD_INFO(%_ASM_DX)
23330 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23331 jae bad_get_user
23332 ASM_STAC
23333-2: movzwl -1(%_ASM_AX),%edx
23334+
23335+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23336+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23337+ cmp %_ASM_DX,%_ASM_AX
23338+ jae 1234f
23339+ add %_ASM_DX,%_ASM_AX
23340+1234:
23341+#endif
23342+
23343+#endif
23344+
23345+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23346 xor %eax,%eax
23347 ASM_CLAC
23348+ pax_force_retaddr
23349 ret
23350 CFI_ENDPROC
23351 ENDPROC(__get_user_2)
23352@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23353 ENTRY(__get_user_4)
23354 CFI_STARTPROC
23355 add $3,%_ASM_AX
23356+
23357+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23358 jc bad_get_user
23359 GET_THREAD_INFO(%_ASM_DX)
23360 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23361 jae bad_get_user
23362 ASM_STAC
23363-3: mov -3(%_ASM_AX),%edx
23364+
23365+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23366+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23367+ cmp %_ASM_DX,%_ASM_AX
23368+ jae 1234f
23369+ add %_ASM_DX,%_ASM_AX
23370+1234:
23371+#endif
23372+
23373+#endif
23374+
23375+3: __copyuser_seg mov -3(%_ASM_AX),%edx
23376 xor %eax,%eax
23377 ASM_CLAC
23378+ pax_force_retaddr
23379 ret
23380 CFI_ENDPROC
23381 ENDPROC(__get_user_4)
23382@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23383 GET_THREAD_INFO(%_ASM_DX)
23384 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23385 jae bad_get_user
23386+
23387+#ifdef CONFIG_PAX_MEMORY_UDEREF
23388+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23389+ cmp %_ASM_DX,%_ASM_AX
23390+ jae 1234f
23391+ add %_ASM_DX,%_ASM_AX
23392+1234:
23393+#endif
23394+
23395 ASM_STAC
23396 4: movq -7(%_ASM_AX),%_ASM_DX
23397 xor %eax,%eax
23398 ASM_CLAC
23399+ pax_force_retaddr
23400 ret
23401 CFI_ENDPROC
23402 ENDPROC(__get_user_8)
23403@@ -101,6 +162,7 @@ bad_get_user:
23404 xor %edx,%edx
23405 mov $(-EFAULT),%_ASM_AX
23406 ASM_CLAC
23407+ pax_force_retaddr
23408 ret
23409 CFI_ENDPROC
23410 END(bad_get_user)
23411diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23412index 54fcffe..7be149e 100644
23413--- a/arch/x86/lib/insn.c
23414+++ b/arch/x86/lib/insn.c
23415@@ -20,8 +20,10 @@
23416
23417 #ifdef __KERNEL__
23418 #include <linux/string.h>
23419+#include <asm/pgtable_types.h>
23420 #else
23421 #include <string.h>
23422+#define ktla_ktva(addr) addr
23423 #endif
23424 #include <asm/inat.h>
23425 #include <asm/insn.h>
23426@@ -53,8 +55,8 @@
23427 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23428 {
23429 memset(insn, 0, sizeof(*insn));
23430- insn->kaddr = kaddr;
23431- insn->next_byte = kaddr;
23432+ insn->kaddr = ktla_ktva(kaddr);
23433+ insn->next_byte = ktla_ktva(kaddr);
23434 insn->x86_64 = x86_64 ? 1 : 0;
23435 insn->opnd_bytes = 4;
23436 if (x86_64)
23437diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23438index 05a95e7..326f2fa 100644
23439--- a/arch/x86/lib/iomap_copy_64.S
23440+++ b/arch/x86/lib/iomap_copy_64.S
23441@@ -17,6 +17,7 @@
23442
23443 #include <linux/linkage.h>
23444 #include <asm/dwarf2.h>
23445+#include <asm/alternative-asm.h>
23446
23447 /*
23448 * override generic version in lib/iomap_copy.c
23449@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23450 CFI_STARTPROC
23451 movl %edx,%ecx
23452 rep movsd
23453+ pax_force_retaddr
23454 ret
23455 CFI_ENDPROC
23456 ENDPROC(__iowrite32_copy)
23457diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23458index 1c273be..da9cc0e 100644
23459--- a/arch/x86/lib/memcpy_64.S
23460+++ b/arch/x86/lib/memcpy_64.S
23461@@ -33,6 +33,7 @@
23462 rep movsq
23463 movl %edx, %ecx
23464 rep movsb
23465+ pax_force_retaddr
23466 ret
23467 .Lmemcpy_e:
23468 .previous
23469@@ -49,6 +50,7 @@
23470 movq %rdi, %rax
23471 movq %rdx, %rcx
23472 rep movsb
23473+ pax_force_retaddr
23474 ret
23475 .Lmemcpy_e_e:
23476 .previous
23477@@ -76,13 +78,13 @@ ENTRY(memcpy)
23478 */
23479 movq 0*8(%rsi), %r8
23480 movq 1*8(%rsi), %r9
23481- movq 2*8(%rsi), %r10
23482+ movq 2*8(%rsi), %rcx
23483 movq 3*8(%rsi), %r11
23484 leaq 4*8(%rsi), %rsi
23485
23486 movq %r8, 0*8(%rdi)
23487 movq %r9, 1*8(%rdi)
23488- movq %r10, 2*8(%rdi)
23489+ movq %rcx, 2*8(%rdi)
23490 movq %r11, 3*8(%rdi)
23491 leaq 4*8(%rdi), %rdi
23492 jae .Lcopy_forward_loop
23493@@ -105,12 +107,12 @@ ENTRY(memcpy)
23494 subq $0x20, %rdx
23495 movq -1*8(%rsi), %r8
23496 movq -2*8(%rsi), %r9
23497- movq -3*8(%rsi), %r10
23498+ movq -3*8(%rsi), %rcx
23499 movq -4*8(%rsi), %r11
23500 leaq -4*8(%rsi), %rsi
23501 movq %r8, -1*8(%rdi)
23502 movq %r9, -2*8(%rdi)
23503- movq %r10, -3*8(%rdi)
23504+ movq %rcx, -3*8(%rdi)
23505 movq %r11, -4*8(%rdi)
23506 leaq -4*8(%rdi), %rdi
23507 jae .Lcopy_backward_loop
23508@@ -130,12 +132,13 @@ ENTRY(memcpy)
23509 */
23510 movq 0*8(%rsi), %r8
23511 movq 1*8(%rsi), %r9
23512- movq -2*8(%rsi, %rdx), %r10
23513+ movq -2*8(%rsi, %rdx), %rcx
23514 movq -1*8(%rsi, %rdx), %r11
23515 movq %r8, 0*8(%rdi)
23516 movq %r9, 1*8(%rdi)
23517- movq %r10, -2*8(%rdi, %rdx)
23518+ movq %rcx, -2*8(%rdi, %rdx)
23519 movq %r11, -1*8(%rdi, %rdx)
23520+ pax_force_retaddr
23521 retq
23522 .p2align 4
23523 .Lless_16bytes:
23524@@ -148,6 +151,7 @@ ENTRY(memcpy)
23525 movq -1*8(%rsi, %rdx), %r9
23526 movq %r8, 0*8(%rdi)
23527 movq %r9, -1*8(%rdi, %rdx)
23528+ pax_force_retaddr
23529 retq
23530 .p2align 4
23531 .Lless_8bytes:
23532@@ -161,6 +165,7 @@ ENTRY(memcpy)
23533 movl -4(%rsi, %rdx), %r8d
23534 movl %ecx, (%rdi)
23535 movl %r8d, -4(%rdi, %rdx)
23536+ pax_force_retaddr
23537 retq
23538 .p2align 4
23539 .Lless_3bytes:
23540@@ -179,6 +184,7 @@ ENTRY(memcpy)
23541 movb %cl, (%rdi)
23542
23543 .Lend:
23544+ pax_force_retaddr
23545 retq
23546 CFI_ENDPROC
23547 ENDPROC(memcpy)
23548diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23549index ee16461..c39c199 100644
23550--- a/arch/x86/lib/memmove_64.S
23551+++ b/arch/x86/lib/memmove_64.S
23552@@ -61,13 +61,13 @@ ENTRY(memmove)
23553 5:
23554 sub $0x20, %rdx
23555 movq 0*8(%rsi), %r11
23556- movq 1*8(%rsi), %r10
23557+ movq 1*8(%rsi), %rcx
23558 movq 2*8(%rsi), %r9
23559 movq 3*8(%rsi), %r8
23560 leaq 4*8(%rsi), %rsi
23561
23562 movq %r11, 0*8(%rdi)
23563- movq %r10, 1*8(%rdi)
23564+ movq %rcx, 1*8(%rdi)
23565 movq %r9, 2*8(%rdi)
23566 movq %r8, 3*8(%rdi)
23567 leaq 4*8(%rdi), %rdi
23568@@ -81,10 +81,10 @@ ENTRY(memmove)
23569 4:
23570 movq %rdx, %rcx
23571 movq -8(%rsi, %rdx), %r11
23572- lea -8(%rdi, %rdx), %r10
23573+ lea -8(%rdi, %rdx), %r9
23574 shrq $3, %rcx
23575 rep movsq
23576- movq %r11, (%r10)
23577+ movq %r11, (%r9)
23578 jmp 13f
23579 .Lmemmove_end_forward:
23580
23581@@ -95,14 +95,14 @@ ENTRY(memmove)
23582 7:
23583 movq %rdx, %rcx
23584 movq (%rsi), %r11
23585- movq %rdi, %r10
23586+ movq %rdi, %r9
23587 leaq -8(%rsi, %rdx), %rsi
23588 leaq -8(%rdi, %rdx), %rdi
23589 shrq $3, %rcx
23590 std
23591 rep movsq
23592 cld
23593- movq %r11, (%r10)
23594+ movq %r11, (%r9)
23595 jmp 13f
23596
23597 /*
23598@@ -127,13 +127,13 @@ ENTRY(memmove)
23599 8:
23600 subq $0x20, %rdx
23601 movq -1*8(%rsi), %r11
23602- movq -2*8(%rsi), %r10
23603+ movq -2*8(%rsi), %rcx
23604 movq -3*8(%rsi), %r9
23605 movq -4*8(%rsi), %r8
23606 leaq -4*8(%rsi), %rsi
23607
23608 movq %r11, -1*8(%rdi)
23609- movq %r10, -2*8(%rdi)
23610+ movq %rcx, -2*8(%rdi)
23611 movq %r9, -3*8(%rdi)
23612 movq %r8, -4*8(%rdi)
23613 leaq -4*8(%rdi), %rdi
23614@@ -151,11 +151,11 @@ ENTRY(memmove)
23615 * Move data from 16 bytes to 31 bytes.
23616 */
23617 movq 0*8(%rsi), %r11
23618- movq 1*8(%rsi), %r10
23619+ movq 1*8(%rsi), %rcx
23620 movq -2*8(%rsi, %rdx), %r9
23621 movq -1*8(%rsi, %rdx), %r8
23622 movq %r11, 0*8(%rdi)
23623- movq %r10, 1*8(%rdi)
23624+ movq %rcx, 1*8(%rdi)
23625 movq %r9, -2*8(%rdi, %rdx)
23626 movq %r8, -1*8(%rdi, %rdx)
23627 jmp 13f
23628@@ -167,9 +167,9 @@ ENTRY(memmove)
23629 * Move data from 8 bytes to 15 bytes.
23630 */
23631 movq 0*8(%rsi), %r11
23632- movq -1*8(%rsi, %rdx), %r10
23633+ movq -1*8(%rsi, %rdx), %r9
23634 movq %r11, 0*8(%rdi)
23635- movq %r10, -1*8(%rdi, %rdx)
23636+ movq %r9, -1*8(%rdi, %rdx)
23637 jmp 13f
23638 10:
23639 cmpq $4, %rdx
23640@@ -178,9 +178,9 @@ ENTRY(memmove)
23641 * Move data from 4 bytes to 7 bytes.
23642 */
23643 movl (%rsi), %r11d
23644- movl -4(%rsi, %rdx), %r10d
23645+ movl -4(%rsi, %rdx), %r9d
23646 movl %r11d, (%rdi)
23647- movl %r10d, -4(%rdi, %rdx)
23648+ movl %r9d, -4(%rdi, %rdx)
23649 jmp 13f
23650 11:
23651 cmp $2, %rdx
23652@@ -189,9 +189,9 @@ ENTRY(memmove)
23653 * Move data from 2 bytes to 3 bytes.
23654 */
23655 movw (%rsi), %r11w
23656- movw -2(%rsi, %rdx), %r10w
23657+ movw -2(%rsi, %rdx), %r9w
23658 movw %r11w, (%rdi)
23659- movw %r10w, -2(%rdi, %rdx)
23660+ movw %r9w, -2(%rdi, %rdx)
23661 jmp 13f
23662 12:
23663 cmp $1, %rdx
23664@@ -202,6 +202,7 @@ ENTRY(memmove)
23665 movb (%rsi), %r11b
23666 movb %r11b, (%rdi)
23667 13:
23668+ pax_force_retaddr
23669 retq
23670 CFI_ENDPROC
23671
23672@@ -210,6 +211,7 @@ ENTRY(memmove)
23673 /* Forward moving data. */
23674 movq %rdx, %rcx
23675 rep movsb
23676+ pax_force_retaddr
23677 retq
23678 .Lmemmove_end_forward_efs:
23679 .previous
23680diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23681index 2dcb380..963660a 100644
23682--- a/arch/x86/lib/memset_64.S
23683+++ b/arch/x86/lib/memset_64.S
23684@@ -30,6 +30,7 @@
23685 movl %edx,%ecx
23686 rep stosb
23687 movq %r9,%rax
23688+ pax_force_retaddr
23689 ret
23690 .Lmemset_e:
23691 .previous
23692@@ -52,6 +53,7 @@
23693 movq %rdx,%rcx
23694 rep stosb
23695 movq %r9,%rax
23696+ pax_force_retaddr
23697 ret
23698 .Lmemset_e_e:
23699 .previous
23700@@ -59,7 +61,7 @@
23701 ENTRY(memset)
23702 ENTRY(__memset)
23703 CFI_STARTPROC
23704- movq %rdi,%r10
23705+ movq %rdi,%r11
23706
23707 /* expand byte value */
23708 movzbl %sil,%ecx
23709@@ -117,7 +119,8 @@ ENTRY(__memset)
23710 jnz .Lloop_1
23711
23712 .Lende:
23713- movq %r10,%rax
23714+ movq %r11,%rax
23715+ pax_force_retaddr
23716 ret
23717
23718 CFI_RESTORE_STATE
23719diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23720index c9f2d9b..e7fd2c0 100644
23721--- a/arch/x86/lib/mmx_32.c
23722+++ b/arch/x86/lib/mmx_32.c
23723@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23724 {
23725 void *p;
23726 int i;
23727+ unsigned long cr0;
23728
23729 if (unlikely(in_interrupt()))
23730 return __memcpy(to, from, len);
23731@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23732 kernel_fpu_begin();
23733
23734 __asm__ __volatile__ (
23735- "1: prefetch (%0)\n" /* This set is 28 bytes */
23736- " prefetch 64(%0)\n"
23737- " prefetch 128(%0)\n"
23738- " prefetch 192(%0)\n"
23739- " prefetch 256(%0)\n"
23740+ "1: prefetch (%1)\n" /* This set is 28 bytes */
23741+ " prefetch 64(%1)\n"
23742+ " prefetch 128(%1)\n"
23743+ " prefetch 192(%1)\n"
23744+ " prefetch 256(%1)\n"
23745 "2: \n"
23746 ".section .fixup, \"ax\"\n"
23747- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23748+ "3: \n"
23749+
23750+#ifdef CONFIG_PAX_KERNEXEC
23751+ " movl %%cr0, %0\n"
23752+ " movl %0, %%eax\n"
23753+ " andl $0xFFFEFFFF, %%eax\n"
23754+ " movl %%eax, %%cr0\n"
23755+#endif
23756+
23757+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23758+
23759+#ifdef CONFIG_PAX_KERNEXEC
23760+ " movl %0, %%cr0\n"
23761+#endif
23762+
23763 " jmp 2b\n"
23764 ".previous\n"
23765 _ASM_EXTABLE(1b, 3b)
23766- : : "r" (from));
23767+ : "=&r" (cr0) : "r" (from) : "ax");
23768
23769 for ( ; i > 5; i--) {
23770 __asm__ __volatile__ (
23771- "1: prefetch 320(%0)\n"
23772- "2: movq (%0), %%mm0\n"
23773- " movq 8(%0), %%mm1\n"
23774- " movq 16(%0), %%mm2\n"
23775- " movq 24(%0), %%mm3\n"
23776- " movq %%mm0, (%1)\n"
23777- " movq %%mm1, 8(%1)\n"
23778- " movq %%mm2, 16(%1)\n"
23779- " movq %%mm3, 24(%1)\n"
23780- " movq 32(%0), %%mm0\n"
23781- " movq 40(%0), %%mm1\n"
23782- " movq 48(%0), %%mm2\n"
23783- " movq 56(%0), %%mm3\n"
23784- " movq %%mm0, 32(%1)\n"
23785- " movq %%mm1, 40(%1)\n"
23786- " movq %%mm2, 48(%1)\n"
23787- " movq %%mm3, 56(%1)\n"
23788+ "1: prefetch 320(%1)\n"
23789+ "2: movq (%1), %%mm0\n"
23790+ " movq 8(%1), %%mm1\n"
23791+ " movq 16(%1), %%mm2\n"
23792+ " movq 24(%1), %%mm3\n"
23793+ " movq %%mm0, (%2)\n"
23794+ " movq %%mm1, 8(%2)\n"
23795+ " movq %%mm2, 16(%2)\n"
23796+ " movq %%mm3, 24(%2)\n"
23797+ " movq 32(%1), %%mm0\n"
23798+ " movq 40(%1), %%mm1\n"
23799+ " movq 48(%1), %%mm2\n"
23800+ " movq 56(%1), %%mm3\n"
23801+ " movq %%mm0, 32(%2)\n"
23802+ " movq %%mm1, 40(%2)\n"
23803+ " movq %%mm2, 48(%2)\n"
23804+ " movq %%mm3, 56(%2)\n"
23805 ".section .fixup, \"ax\"\n"
23806- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23807+ "3:\n"
23808+
23809+#ifdef CONFIG_PAX_KERNEXEC
23810+ " movl %%cr0, %0\n"
23811+ " movl %0, %%eax\n"
23812+ " andl $0xFFFEFFFF, %%eax\n"
23813+ " movl %%eax, %%cr0\n"
23814+#endif
23815+
23816+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23817+
23818+#ifdef CONFIG_PAX_KERNEXEC
23819+ " movl %0, %%cr0\n"
23820+#endif
23821+
23822 " jmp 2b\n"
23823 ".previous\n"
23824 _ASM_EXTABLE(1b, 3b)
23825- : : "r" (from), "r" (to) : "memory");
23826+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23827
23828 from += 64;
23829 to += 64;
23830@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23831 static void fast_copy_page(void *to, void *from)
23832 {
23833 int i;
23834+ unsigned long cr0;
23835
23836 kernel_fpu_begin();
23837
23838@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23839 * but that is for later. -AV
23840 */
23841 __asm__ __volatile__(
23842- "1: prefetch (%0)\n"
23843- " prefetch 64(%0)\n"
23844- " prefetch 128(%0)\n"
23845- " prefetch 192(%0)\n"
23846- " prefetch 256(%0)\n"
23847+ "1: prefetch (%1)\n"
23848+ " prefetch 64(%1)\n"
23849+ " prefetch 128(%1)\n"
23850+ " prefetch 192(%1)\n"
23851+ " prefetch 256(%1)\n"
23852 "2: \n"
23853 ".section .fixup, \"ax\"\n"
23854- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23855+ "3: \n"
23856+
23857+#ifdef CONFIG_PAX_KERNEXEC
23858+ " movl %%cr0, %0\n"
23859+ " movl %0, %%eax\n"
23860+ " andl $0xFFFEFFFF, %%eax\n"
23861+ " movl %%eax, %%cr0\n"
23862+#endif
23863+
23864+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23865+
23866+#ifdef CONFIG_PAX_KERNEXEC
23867+ " movl %0, %%cr0\n"
23868+#endif
23869+
23870 " jmp 2b\n"
23871 ".previous\n"
23872- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23873+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23874
23875 for (i = 0; i < (4096-320)/64; i++) {
23876 __asm__ __volatile__ (
23877- "1: prefetch 320(%0)\n"
23878- "2: movq (%0), %%mm0\n"
23879- " movntq %%mm0, (%1)\n"
23880- " movq 8(%0), %%mm1\n"
23881- " movntq %%mm1, 8(%1)\n"
23882- " movq 16(%0), %%mm2\n"
23883- " movntq %%mm2, 16(%1)\n"
23884- " movq 24(%0), %%mm3\n"
23885- " movntq %%mm3, 24(%1)\n"
23886- " movq 32(%0), %%mm4\n"
23887- " movntq %%mm4, 32(%1)\n"
23888- " movq 40(%0), %%mm5\n"
23889- " movntq %%mm5, 40(%1)\n"
23890- " movq 48(%0), %%mm6\n"
23891- " movntq %%mm6, 48(%1)\n"
23892- " movq 56(%0), %%mm7\n"
23893- " movntq %%mm7, 56(%1)\n"
23894+ "1: prefetch 320(%1)\n"
23895+ "2: movq (%1), %%mm0\n"
23896+ " movntq %%mm0, (%2)\n"
23897+ " movq 8(%1), %%mm1\n"
23898+ " movntq %%mm1, 8(%2)\n"
23899+ " movq 16(%1), %%mm2\n"
23900+ " movntq %%mm2, 16(%2)\n"
23901+ " movq 24(%1), %%mm3\n"
23902+ " movntq %%mm3, 24(%2)\n"
23903+ " movq 32(%1), %%mm4\n"
23904+ " movntq %%mm4, 32(%2)\n"
23905+ " movq 40(%1), %%mm5\n"
23906+ " movntq %%mm5, 40(%2)\n"
23907+ " movq 48(%1), %%mm6\n"
23908+ " movntq %%mm6, 48(%2)\n"
23909+ " movq 56(%1), %%mm7\n"
23910+ " movntq %%mm7, 56(%2)\n"
23911 ".section .fixup, \"ax\"\n"
23912- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23913+ "3:\n"
23914+
23915+#ifdef CONFIG_PAX_KERNEXEC
23916+ " movl %%cr0, %0\n"
23917+ " movl %0, %%eax\n"
23918+ " andl $0xFFFEFFFF, %%eax\n"
23919+ " movl %%eax, %%cr0\n"
23920+#endif
23921+
23922+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23923+
23924+#ifdef CONFIG_PAX_KERNEXEC
23925+ " movl %0, %%cr0\n"
23926+#endif
23927+
23928 " jmp 2b\n"
23929 ".previous\n"
23930- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23931+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23932
23933 from += 64;
23934 to += 64;
23935@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23936 static void fast_copy_page(void *to, void *from)
23937 {
23938 int i;
23939+ unsigned long cr0;
23940
23941 kernel_fpu_begin();
23942
23943 __asm__ __volatile__ (
23944- "1: prefetch (%0)\n"
23945- " prefetch 64(%0)\n"
23946- " prefetch 128(%0)\n"
23947- " prefetch 192(%0)\n"
23948- " prefetch 256(%0)\n"
23949+ "1: prefetch (%1)\n"
23950+ " prefetch 64(%1)\n"
23951+ " prefetch 128(%1)\n"
23952+ " prefetch 192(%1)\n"
23953+ " prefetch 256(%1)\n"
23954 "2: \n"
23955 ".section .fixup, \"ax\"\n"
23956- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23957+ "3: \n"
23958+
23959+#ifdef CONFIG_PAX_KERNEXEC
23960+ " movl %%cr0, %0\n"
23961+ " movl %0, %%eax\n"
23962+ " andl $0xFFFEFFFF, %%eax\n"
23963+ " movl %%eax, %%cr0\n"
23964+#endif
23965+
23966+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23967+
23968+#ifdef CONFIG_PAX_KERNEXEC
23969+ " movl %0, %%cr0\n"
23970+#endif
23971+
23972 " jmp 2b\n"
23973 ".previous\n"
23974- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23975+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23976
23977 for (i = 0; i < 4096/64; i++) {
23978 __asm__ __volatile__ (
23979- "1: prefetch 320(%0)\n"
23980- "2: movq (%0), %%mm0\n"
23981- " movq 8(%0), %%mm1\n"
23982- " movq 16(%0), %%mm2\n"
23983- " movq 24(%0), %%mm3\n"
23984- " movq %%mm0, (%1)\n"
23985- " movq %%mm1, 8(%1)\n"
23986- " movq %%mm2, 16(%1)\n"
23987- " movq %%mm3, 24(%1)\n"
23988- " movq 32(%0), %%mm0\n"
23989- " movq 40(%0), %%mm1\n"
23990- " movq 48(%0), %%mm2\n"
23991- " movq 56(%0), %%mm3\n"
23992- " movq %%mm0, 32(%1)\n"
23993- " movq %%mm1, 40(%1)\n"
23994- " movq %%mm2, 48(%1)\n"
23995- " movq %%mm3, 56(%1)\n"
23996+ "1: prefetch 320(%1)\n"
23997+ "2: movq (%1), %%mm0\n"
23998+ " movq 8(%1), %%mm1\n"
23999+ " movq 16(%1), %%mm2\n"
24000+ " movq 24(%1), %%mm3\n"
24001+ " movq %%mm0, (%2)\n"
24002+ " movq %%mm1, 8(%2)\n"
24003+ " movq %%mm2, 16(%2)\n"
24004+ " movq %%mm3, 24(%2)\n"
24005+ " movq 32(%1), %%mm0\n"
24006+ " movq 40(%1), %%mm1\n"
24007+ " movq 48(%1), %%mm2\n"
24008+ " movq 56(%1), %%mm3\n"
24009+ " movq %%mm0, 32(%2)\n"
24010+ " movq %%mm1, 40(%2)\n"
24011+ " movq %%mm2, 48(%2)\n"
24012+ " movq %%mm3, 56(%2)\n"
24013 ".section .fixup, \"ax\"\n"
24014- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24015+ "3:\n"
24016+
24017+#ifdef CONFIG_PAX_KERNEXEC
24018+ " movl %%cr0, %0\n"
24019+ " movl %0, %%eax\n"
24020+ " andl $0xFFFEFFFF, %%eax\n"
24021+ " movl %%eax, %%cr0\n"
24022+#endif
24023+
24024+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
24025+
24026+#ifdef CONFIG_PAX_KERNEXEC
24027+ " movl %0, %%cr0\n"
24028+#endif
24029+
24030 " jmp 2b\n"
24031 ".previous\n"
24032 _ASM_EXTABLE(1b, 3b)
24033- : : "r" (from), "r" (to) : "memory");
24034+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
24035
24036 from += 64;
24037 to += 64;
24038diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
24039index f6d13ee..aca5f0b 100644
24040--- a/arch/x86/lib/msr-reg.S
24041+++ b/arch/x86/lib/msr-reg.S
24042@@ -3,6 +3,7 @@
24043 #include <asm/dwarf2.h>
24044 #include <asm/asm.h>
24045 #include <asm/msr.h>
24046+#include <asm/alternative-asm.h>
24047
24048 #ifdef CONFIG_X86_64
24049 /*
24050@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24051 CFI_STARTPROC
24052 pushq_cfi %rbx
24053 pushq_cfi %rbp
24054- movq %rdi, %r10 /* Save pointer */
24055+ movq %rdi, %r9 /* Save pointer */
24056 xorl %r11d, %r11d /* Return value */
24057 movl (%rdi), %eax
24058 movl 4(%rdi), %ecx
24059@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24060 movl 28(%rdi), %edi
24061 CFI_REMEMBER_STATE
24062 1: \op
24063-2: movl %eax, (%r10)
24064+2: movl %eax, (%r9)
24065 movl %r11d, %eax /* Return value */
24066- movl %ecx, 4(%r10)
24067- movl %edx, 8(%r10)
24068- movl %ebx, 12(%r10)
24069- movl %ebp, 20(%r10)
24070- movl %esi, 24(%r10)
24071- movl %edi, 28(%r10)
24072+ movl %ecx, 4(%r9)
24073+ movl %edx, 8(%r9)
24074+ movl %ebx, 12(%r9)
24075+ movl %ebp, 20(%r9)
24076+ movl %esi, 24(%r9)
24077+ movl %edi, 28(%r9)
24078 popq_cfi %rbp
24079 popq_cfi %rbx
24080+ pax_force_retaddr
24081 ret
24082 3:
24083 CFI_RESTORE_STATE
24084diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24085index fc6ba17..04471c5 100644
24086--- a/arch/x86/lib/putuser.S
24087+++ b/arch/x86/lib/putuser.S
24088@@ -16,7 +16,9 @@
24089 #include <asm/errno.h>
24090 #include <asm/asm.h>
24091 #include <asm/smap.h>
24092-
24093+#include <asm/segment.h>
24094+#include <asm/pgtable.h>
24095+#include <asm/alternative-asm.h>
24096
24097 /*
24098 * __put_user_X
24099@@ -30,57 +32,125 @@
24100 * as they get called from within inline assembly.
24101 */
24102
24103-#define ENTER CFI_STARTPROC ; \
24104- GET_THREAD_INFO(%_ASM_BX)
24105-#define EXIT ASM_CLAC ; \
24106- ret ; \
24107+#define ENTER CFI_STARTPROC
24108+#define EXIT ASM_CLAC ; \
24109+ pax_force_retaddr ; \
24110+ ret ; \
24111 CFI_ENDPROC
24112
24113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24114+#define _DEST %_ASM_CX,%_ASM_BX
24115+#else
24116+#define _DEST %_ASM_CX
24117+#endif
24118+
24119+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24120+#define __copyuser_seg gs;
24121+#else
24122+#define __copyuser_seg
24123+#endif
24124+
24125 .text
24126 ENTRY(__put_user_1)
24127 ENTER
24128+
24129+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24130+ GET_THREAD_INFO(%_ASM_BX)
24131 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24132 jae bad_put_user
24133 ASM_STAC
24134-1: movb %al,(%_ASM_CX)
24135+
24136+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24137+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24138+ cmp %_ASM_BX,%_ASM_CX
24139+ jb 1234f
24140+ xor %ebx,%ebx
24141+1234:
24142+#endif
24143+
24144+#endif
24145+
24146+1: __copyuser_seg movb %al,(_DEST)
24147 xor %eax,%eax
24148 EXIT
24149 ENDPROC(__put_user_1)
24150
24151 ENTRY(__put_user_2)
24152 ENTER
24153+
24154+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24155+ GET_THREAD_INFO(%_ASM_BX)
24156 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24157 sub $1,%_ASM_BX
24158 cmp %_ASM_BX,%_ASM_CX
24159 jae bad_put_user
24160 ASM_STAC
24161-2: movw %ax,(%_ASM_CX)
24162+
24163+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24164+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24165+ cmp %_ASM_BX,%_ASM_CX
24166+ jb 1234f
24167+ xor %ebx,%ebx
24168+1234:
24169+#endif
24170+
24171+#endif
24172+
24173+2: __copyuser_seg movw %ax,(_DEST)
24174 xor %eax,%eax
24175 EXIT
24176 ENDPROC(__put_user_2)
24177
24178 ENTRY(__put_user_4)
24179 ENTER
24180+
24181+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24182+ GET_THREAD_INFO(%_ASM_BX)
24183 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24184 sub $3,%_ASM_BX
24185 cmp %_ASM_BX,%_ASM_CX
24186 jae bad_put_user
24187 ASM_STAC
24188-3: movl %eax,(%_ASM_CX)
24189+
24190+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24191+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24192+ cmp %_ASM_BX,%_ASM_CX
24193+ jb 1234f
24194+ xor %ebx,%ebx
24195+1234:
24196+#endif
24197+
24198+#endif
24199+
24200+3: __copyuser_seg movl %eax,(_DEST)
24201 xor %eax,%eax
24202 EXIT
24203 ENDPROC(__put_user_4)
24204
24205 ENTRY(__put_user_8)
24206 ENTER
24207+
24208+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24209+ GET_THREAD_INFO(%_ASM_BX)
24210 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24211 sub $7,%_ASM_BX
24212 cmp %_ASM_BX,%_ASM_CX
24213 jae bad_put_user
24214 ASM_STAC
24215-4: mov %_ASM_AX,(%_ASM_CX)
24216+
24217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24218+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24219+ cmp %_ASM_BX,%_ASM_CX
24220+ jb 1234f
24221+ xor %ebx,%ebx
24222+1234:
24223+#endif
24224+
24225+#endif
24226+
24227+4: __copyuser_seg mov %_ASM_AX,(_DEST)
24228 #ifdef CONFIG_X86_32
24229-5: movl %edx,4(%_ASM_CX)
24230+5: __copyuser_seg movl %edx,4(_DEST)
24231 #endif
24232 xor %eax,%eax
24233 EXIT
24234diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24235index 1cad221..de671ee 100644
24236--- a/arch/x86/lib/rwlock.S
24237+++ b/arch/x86/lib/rwlock.S
24238@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24239 FRAME
24240 0: LOCK_PREFIX
24241 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24242+
24243+#ifdef CONFIG_PAX_REFCOUNT
24244+ jno 1234f
24245+ LOCK_PREFIX
24246+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24247+ int $4
24248+1234:
24249+ _ASM_EXTABLE(1234b, 1234b)
24250+#endif
24251+
24252 1: rep; nop
24253 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24254 jne 1b
24255 LOCK_PREFIX
24256 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24257+
24258+#ifdef CONFIG_PAX_REFCOUNT
24259+ jno 1234f
24260+ LOCK_PREFIX
24261+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24262+ int $4
24263+1234:
24264+ _ASM_EXTABLE(1234b, 1234b)
24265+#endif
24266+
24267 jnz 0b
24268 ENDFRAME
24269+ pax_force_retaddr
24270 ret
24271 CFI_ENDPROC
24272 END(__write_lock_failed)
24273@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24274 FRAME
24275 0: LOCK_PREFIX
24276 READ_LOCK_SIZE(inc) (%__lock_ptr)
24277+
24278+#ifdef CONFIG_PAX_REFCOUNT
24279+ jno 1234f
24280+ LOCK_PREFIX
24281+ READ_LOCK_SIZE(dec) (%__lock_ptr)
24282+ int $4
24283+1234:
24284+ _ASM_EXTABLE(1234b, 1234b)
24285+#endif
24286+
24287 1: rep; nop
24288 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24289 js 1b
24290 LOCK_PREFIX
24291 READ_LOCK_SIZE(dec) (%__lock_ptr)
24292+
24293+#ifdef CONFIG_PAX_REFCOUNT
24294+ jno 1234f
24295+ LOCK_PREFIX
24296+ READ_LOCK_SIZE(inc) (%__lock_ptr)
24297+ int $4
24298+1234:
24299+ _ASM_EXTABLE(1234b, 1234b)
24300+#endif
24301+
24302 js 0b
24303 ENDFRAME
24304+ pax_force_retaddr
24305 ret
24306 CFI_ENDPROC
24307 END(__read_lock_failed)
24308diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24309index 5dff5f0..cadebf4 100644
24310--- a/arch/x86/lib/rwsem.S
24311+++ b/arch/x86/lib/rwsem.S
24312@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24313 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24314 CFI_RESTORE __ASM_REG(dx)
24315 restore_common_regs
24316+ pax_force_retaddr
24317 ret
24318 CFI_ENDPROC
24319 ENDPROC(call_rwsem_down_read_failed)
24320@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24321 movq %rax,%rdi
24322 call rwsem_down_write_failed
24323 restore_common_regs
24324+ pax_force_retaddr
24325 ret
24326 CFI_ENDPROC
24327 ENDPROC(call_rwsem_down_write_failed)
24328@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24329 movq %rax,%rdi
24330 call rwsem_wake
24331 restore_common_regs
24332-1: ret
24333+1: pax_force_retaddr
24334+ ret
24335 CFI_ENDPROC
24336 ENDPROC(call_rwsem_wake)
24337
24338@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24339 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24340 CFI_RESTORE __ASM_REG(dx)
24341 restore_common_regs
24342+ pax_force_retaddr
24343 ret
24344 CFI_ENDPROC
24345 ENDPROC(call_rwsem_downgrade_wake)
24346diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24347index a63efd6..ccecad8 100644
24348--- a/arch/x86/lib/thunk_64.S
24349+++ b/arch/x86/lib/thunk_64.S
24350@@ -8,6 +8,7 @@
24351 #include <linux/linkage.h>
24352 #include <asm/dwarf2.h>
24353 #include <asm/calling.h>
24354+#include <asm/alternative-asm.h>
24355
24356 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24357 .macro THUNK name, func, put_ret_addr_in_rdi=0
24358@@ -41,5 +42,6 @@
24359 SAVE_ARGS
24360 restore:
24361 RESTORE_ARGS
24362+ pax_force_retaddr
24363 ret
24364 CFI_ENDPROC
24365diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24366index 98f6d6b6..d27f045 100644
24367--- a/arch/x86/lib/usercopy_32.c
24368+++ b/arch/x86/lib/usercopy_32.c
24369@@ -42,11 +42,13 @@ do { \
24370 int __d0; \
24371 might_fault(); \
24372 __asm__ __volatile__( \
24373+ __COPYUSER_SET_ES \
24374 ASM_STAC "\n" \
24375 "0: rep; stosl\n" \
24376 " movl %2,%0\n" \
24377 "1: rep; stosb\n" \
24378 "2: " ASM_CLAC "\n" \
24379+ __COPYUSER_RESTORE_ES \
24380 ".section .fixup,\"ax\"\n" \
24381 "3: lea 0(%2,%0,4),%0\n" \
24382 " jmp 2b\n" \
24383@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24384
24385 #ifdef CONFIG_X86_INTEL_USERCOPY
24386 static unsigned long
24387-__copy_user_intel(void __user *to, const void *from, unsigned long size)
24388+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24389 {
24390 int d0, d1;
24391 __asm__ __volatile__(
24392@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24393 " .align 2,0x90\n"
24394 "3: movl 0(%4), %%eax\n"
24395 "4: movl 4(%4), %%edx\n"
24396- "5: movl %%eax, 0(%3)\n"
24397- "6: movl %%edx, 4(%3)\n"
24398+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24399+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24400 "7: movl 8(%4), %%eax\n"
24401 "8: movl 12(%4),%%edx\n"
24402- "9: movl %%eax, 8(%3)\n"
24403- "10: movl %%edx, 12(%3)\n"
24404+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24405+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24406 "11: movl 16(%4), %%eax\n"
24407 "12: movl 20(%4), %%edx\n"
24408- "13: movl %%eax, 16(%3)\n"
24409- "14: movl %%edx, 20(%3)\n"
24410+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24411+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24412 "15: movl 24(%4), %%eax\n"
24413 "16: movl 28(%4), %%edx\n"
24414- "17: movl %%eax, 24(%3)\n"
24415- "18: movl %%edx, 28(%3)\n"
24416+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24417+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24418 "19: movl 32(%4), %%eax\n"
24419 "20: movl 36(%4), %%edx\n"
24420- "21: movl %%eax, 32(%3)\n"
24421- "22: movl %%edx, 36(%3)\n"
24422+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24423+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24424 "23: movl 40(%4), %%eax\n"
24425 "24: movl 44(%4), %%edx\n"
24426- "25: movl %%eax, 40(%3)\n"
24427- "26: movl %%edx, 44(%3)\n"
24428+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24429+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24430 "27: movl 48(%4), %%eax\n"
24431 "28: movl 52(%4), %%edx\n"
24432- "29: movl %%eax, 48(%3)\n"
24433- "30: movl %%edx, 52(%3)\n"
24434+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24435+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24436 "31: movl 56(%4), %%eax\n"
24437 "32: movl 60(%4), %%edx\n"
24438- "33: movl %%eax, 56(%3)\n"
24439- "34: movl %%edx, 60(%3)\n"
24440+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24441+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24442 " addl $-64, %0\n"
24443 " addl $64, %4\n"
24444 " addl $64, %3\n"
24445@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24446 " shrl $2, %0\n"
24447 " andl $3, %%eax\n"
24448 " cld\n"
24449+ __COPYUSER_SET_ES
24450 "99: rep; movsl\n"
24451 "36: movl %%eax, %0\n"
24452 "37: rep; movsb\n"
24453 "100:\n"
24454+ __COPYUSER_RESTORE_ES
24455 ".section .fixup,\"ax\"\n"
24456 "101: lea 0(%%eax,%0,4),%0\n"
24457 " jmp 100b\n"
24458@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24459 }
24460
24461 static unsigned long
24462+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24463+{
24464+ int d0, d1;
24465+ __asm__ __volatile__(
24466+ " .align 2,0x90\n"
24467+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24468+ " cmpl $67, %0\n"
24469+ " jbe 3f\n"
24470+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24471+ " .align 2,0x90\n"
24472+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24473+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24474+ "5: movl %%eax, 0(%3)\n"
24475+ "6: movl %%edx, 4(%3)\n"
24476+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24477+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24478+ "9: movl %%eax, 8(%3)\n"
24479+ "10: movl %%edx, 12(%3)\n"
24480+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24481+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24482+ "13: movl %%eax, 16(%3)\n"
24483+ "14: movl %%edx, 20(%3)\n"
24484+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24485+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24486+ "17: movl %%eax, 24(%3)\n"
24487+ "18: movl %%edx, 28(%3)\n"
24488+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24489+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24490+ "21: movl %%eax, 32(%3)\n"
24491+ "22: movl %%edx, 36(%3)\n"
24492+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24493+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24494+ "25: movl %%eax, 40(%3)\n"
24495+ "26: movl %%edx, 44(%3)\n"
24496+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24497+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24498+ "29: movl %%eax, 48(%3)\n"
24499+ "30: movl %%edx, 52(%3)\n"
24500+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24501+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24502+ "33: movl %%eax, 56(%3)\n"
24503+ "34: movl %%edx, 60(%3)\n"
24504+ " addl $-64, %0\n"
24505+ " addl $64, %4\n"
24506+ " addl $64, %3\n"
24507+ " cmpl $63, %0\n"
24508+ " ja 1b\n"
24509+ "35: movl %0, %%eax\n"
24510+ " shrl $2, %0\n"
24511+ " andl $3, %%eax\n"
24512+ " cld\n"
24513+ "99: rep; "__copyuser_seg" movsl\n"
24514+ "36: movl %%eax, %0\n"
24515+ "37: rep; "__copyuser_seg" movsb\n"
24516+ "100:\n"
24517+ ".section .fixup,\"ax\"\n"
24518+ "101: lea 0(%%eax,%0,4),%0\n"
24519+ " jmp 100b\n"
24520+ ".previous\n"
24521+ _ASM_EXTABLE(1b,100b)
24522+ _ASM_EXTABLE(2b,100b)
24523+ _ASM_EXTABLE(3b,100b)
24524+ _ASM_EXTABLE(4b,100b)
24525+ _ASM_EXTABLE(5b,100b)
24526+ _ASM_EXTABLE(6b,100b)
24527+ _ASM_EXTABLE(7b,100b)
24528+ _ASM_EXTABLE(8b,100b)
24529+ _ASM_EXTABLE(9b,100b)
24530+ _ASM_EXTABLE(10b,100b)
24531+ _ASM_EXTABLE(11b,100b)
24532+ _ASM_EXTABLE(12b,100b)
24533+ _ASM_EXTABLE(13b,100b)
24534+ _ASM_EXTABLE(14b,100b)
24535+ _ASM_EXTABLE(15b,100b)
24536+ _ASM_EXTABLE(16b,100b)
24537+ _ASM_EXTABLE(17b,100b)
24538+ _ASM_EXTABLE(18b,100b)
24539+ _ASM_EXTABLE(19b,100b)
24540+ _ASM_EXTABLE(20b,100b)
24541+ _ASM_EXTABLE(21b,100b)
24542+ _ASM_EXTABLE(22b,100b)
24543+ _ASM_EXTABLE(23b,100b)
24544+ _ASM_EXTABLE(24b,100b)
24545+ _ASM_EXTABLE(25b,100b)
24546+ _ASM_EXTABLE(26b,100b)
24547+ _ASM_EXTABLE(27b,100b)
24548+ _ASM_EXTABLE(28b,100b)
24549+ _ASM_EXTABLE(29b,100b)
24550+ _ASM_EXTABLE(30b,100b)
24551+ _ASM_EXTABLE(31b,100b)
24552+ _ASM_EXTABLE(32b,100b)
24553+ _ASM_EXTABLE(33b,100b)
24554+ _ASM_EXTABLE(34b,100b)
24555+ _ASM_EXTABLE(35b,100b)
24556+ _ASM_EXTABLE(36b,100b)
24557+ _ASM_EXTABLE(37b,100b)
24558+ _ASM_EXTABLE(99b,101b)
24559+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
24560+ : "1"(to), "2"(from), "0"(size)
24561+ : "eax", "edx", "memory");
24562+ return size;
24563+}
24564+
24565+static unsigned long __size_overflow(3)
24566 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24567 {
24568 int d0, d1;
24569 __asm__ __volatile__(
24570 " .align 2,0x90\n"
24571- "0: movl 32(%4), %%eax\n"
24572+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24573 " cmpl $67, %0\n"
24574 " jbe 2f\n"
24575- "1: movl 64(%4), %%eax\n"
24576+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24577 " .align 2,0x90\n"
24578- "2: movl 0(%4), %%eax\n"
24579- "21: movl 4(%4), %%edx\n"
24580+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24581+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24582 " movl %%eax, 0(%3)\n"
24583 " movl %%edx, 4(%3)\n"
24584- "3: movl 8(%4), %%eax\n"
24585- "31: movl 12(%4),%%edx\n"
24586+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24587+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24588 " movl %%eax, 8(%3)\n"
24589 " movl %%edx, 12(%3)\n"
24590- "4: movl 16(%4), %%eax\n"
24591- "41: movl 20(%4), %%edx\n"
24592+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24593+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24594 " movl %%eax, 16(%3)\n"
24595 " movl %%edx, 20(%3)\n"
24596- "10: movl 24(%4), %%eax\n"
24597- "51: movl 28(%4), %%edx\n"
24598+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24599+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24600 " movl %%eax, 24(%3)\n"
24601 " movl %%edx, 28(%3)\n"
24602- "11: movl 32(%4), %%eax\n"
24603- "61: movl 36(%4), %%edx\n"
24604+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24605+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24606 " movl %%eax, 32(%3)\n"
24607 " movl %%edx, 36(%3)\n"
24608- "12: movl 40(%4), %%eax\n"
24609- "71: movl 44(%4), %%edx\n"
24610+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24611+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24612 " movl %%eax, 40(%3)\n"
24613 " movl %%edx, 44(%3)\n"
24614- "13: movl 48(%4), %%eax\n"
24615- "81: movl 52(%4), %%edx\n"
24616+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24617+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24618 " movl %%eax, 48(%3)\n"
24619 " movl %%edx, 52(%3)\n"
24620- "14: movl 56(%4), %%eax\n"
24621- "91: movl 60(%4), %%edx\n"
24622+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24623+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24624 " movl %%eax, 56(%3)\n"
24625 " movl %%edx, 60(%3)\n"
24626 " addl $-64, %0\n"
24627@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24628 " shrl $2, %0\n"
24629 " andl $3, %%eax\n"
24630 " cld\n"
24631- "6: rep; movsl\n"
24632+ "6: rep; "__copyuser_seg" movsl\n"
24633 " movl %%eax,%0\n"
24634- "7: rep; movsb\n"
24635+ "7: rep; "__copyuser_seg" movsb\n"
24636 "8:\n"
24637 ".section .fixup,\"ax\"\n"
24638 "9: lea 0(%%eax,%0,4),%0\n"
24639@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24640 * hyoshiok@miraclelinux.com
24641 */
24642
24643-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24644+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24645 const void __user *from, unsigned long size)
24646 {
24647 int d0, d1;
24648
24649 __asm__ __volatile__(
24650 " .align 2,0x90\n"
24651- "0: movl 32(%4), %%eax\n"
24652+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24653 " cmpl $67, %0\n"
24654 " jbe 2f\n"
24655- "1: movl 64(%4), %%eax\n"
24656+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24657 " .align 2,0x90\n"
24658- "2: movl 0(%4), %%eax\n"
24659- "21: movl 4(%4), %%edx\n"
24660+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24661+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24662 " movnti %%eax, 0(%3)\n"
24663 " movnti %%edx, 4(%3)\n"
24664- "3: movl 8(%4), %%eax\n"
24665- "31: movl 12(%4),%%edx\n"
24666+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24667+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24668 " movnti %%eax, 8(%3)\n"
24669 " movnti %%edx, 12(%3)\n"
24670- "4: movl 16(%4), %%eax\n"
24671- "41: movl 20(%4), %%edx\n"
24672+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24673+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24674 " movnti %%eax, 16(%3)\n"
24675 " movnti %%edx, 20(%3)\n"
24676- "10: movl 24(%4), %%eax\n"
24677- "51: movl 28(%4), %%edx\n"
24678+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24679+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24680 " movnti %%eax, 24(%3)\n"
24681 " movnti %%edx, 28(%3)\n"
24682- "11: movl 32(%4), %%eax\n"
24683- "61: movl 36(%4), %%edx\n"
24684+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24685+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24686 " movnti %%eax, 32(%3)\n"
24687 " movnti %%edx, 36(%3)\n"
24688- "12: movl 40(%4), %%eax\n"
24689- "71: movl 44(%4), %%edx\n"
24690+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24691+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24692 " movnti %%eax, 40(%3)\n"
24693 " movnti %%edx, 44(%3)\n"
24694- "13: movl 48(%4), %%eax\n"
24695- "81: movl 52(%4), %%edx\n"
24696+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24697+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24698 " movnti %%eax, 48(%3)\n"
24699 " movnti %%edx, 52(%3)\n"
24700- "14: movl 56(%4), %%eax\n"
24701- "91: movl 60(%4), %%edx\n"
24702+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24703+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24704 " movnti %%eax, 56(%3)\n"
24705 " movnti %%edx, 60(%3)\n"
24706 " addl $-64, %0\n"
24707@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24708 " shrl $2, %0\n"
24709 " andl $3, %%eax\n"
24710 " cld\n"
24711- "6: rep; movsl\n"
24712+ "6: rep; "__copyuser_seg" movsl\n"
24713 " movl %%eax,%0\n"
24714- "7: rep; movsb\n"
24715+ "7: rep; "__copyuser_seg" movsb\n"
24716 "8:\n"
24717 ".section .fixup,\"ax\"\n"
24718 "9: lea 0(%%eax,%0,4),%0\n"
24719@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24720 return size;
24721 }
24722
24723-static unsigned long __copy_user_intel_nocache(void *to,
24724+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24725 const void __user *from, unsigned long size)
24726 {
24727 int d0, d1;
24728
24729 __asm__ __volatile__(
24730 " .align 2,0x90\n"
24731- "0: movl 32(%4), %%eax\n"
24732+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24733 " cmpl $67, %0\n"
24734 " jbe 2f\n"
24735- "1: movl 64(%4), %%eax\n"
24736+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24737 " .align 2,0x90\n"
24738- "2: movl 0(%4), %%eax\n"
24739- "21: movl 4(%4), %%edx\n"
24740+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24741+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24742 " movnti %%eax, 0(%3)\n"
24743 " movnti %%edx, 4(%3)\n"
24744- "3: movl 8(%4), %%eax\n"
24745- "31: movl 12(%4),%%edx\n"
24746+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24747+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24748 " movnti %%eax, 8(%3)\n"
24749 " movnti %%edx, 12(%3)\n"
24750- "4: movl 16(%4), %%eax\n"
24751- "41: movl 20(%4), %%edx\n"
24752+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24753+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24754 " movnti %%eax, 16(%3)\n"
24755 " movnti %%edx, 20(%3)\n"
24756- "10: movl 24(%4), %%eax\n"
24757- "51: movl 28(%4), %%edx\n"
24758+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24759+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24760 " movnti %%eax, 24(%3)\n"
24761 " movnti %%edx, 28(%3)\n"
24762- "11: movl 32(%4), %%eax\n"
24763- "61: movl 36(%4), %%edx\n"
24764+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24765+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24766 " movnti %%eax, 32(%3)\n"
24767 " movnti %%edx, 36(%3)\n"
24768- "12: movl 40(%4), %%eax\n"
24769- "71: movl 44(%4), %%edx\n"
24770+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24771+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24772 " movnti %%eax, 40(%3)\n"
24773 " movnti %%edx, 44(%3)\n"
24774- "13: movl 48(%4), %%eax\n"
24775- "81: movl 52(%4), %%edx\n"
24776+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24777+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24778 " movnti %%eax, 48(%3)\n"
24779 " movnti %%edx, 52(%3)\n"
24780- "14: movl 56(%4), %%eax\n"
24781- "91: movl 60(%4), %%edx\n"
24782+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24783+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24784 " movnti %%eax, 56(%3)\n"
24785 " movnti %%edx, 60(%3)\n"
24786 " addl $-64, %0\n"
24787@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24788 " shrl $2, %0\n"
24789 " andl $3, %%eax\n"
24790 " cld\n"
24791- "6: rep; movsl\n"
24792+ "6: rep; "__copyuser_seg" movsl\n"
24793 " movl %%eax,%0\n"
24794- "7: rep; movsb\n"
24795+ "7: rep; "__copyuser_seg" movsb\n"
24796 "8:\n"
24797 ".section .fixup,\"ax\"\n"
24798 "9: lea 0(%%eax,%0,4),%0\n"
24799@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24800 */
24801 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24802 unsigned long size);
24803-unsigned long __copy_user_intel(void __user *to, const void *from,
24804+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24805+ unsigned long size);
24806+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24807 unsigned long size);
24808 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24809 const void __user *from, unsigned long size);
24810 #endif /* CONFIG_X86_INTEL_USERCOPY */
24811
24812 /* Generic arbitrary sized copy. */
24813-#define __copy_user(to, from, size) \
24814+#define __copy_user(to, from, size, prefix, set, restore) \
24815 do { \
24816 int __d0, __d1, __d2; \
24817 __asm__ __volatile__( \
24818+ set \
24819 " cmp $7,%0\n" \
24820 " jbe 1f\n" \
24821 " movl %1,%0\n" \
24822 " negl %0\n" \
24823 " andl $7,%0\n" \
24824 " subl %0,%3\n" \
24825- "4: rep; movsb\n" \
24826+ "4: rep; "prefix"movsb\n" \
24827 " movl %3,%0\n" \
24828 " shrl $2,%0\n" \
24829 " andl $3,%3\n" \
24830 " .align 2,0x90\n" \
24831- "0: rep; movsl\n" \
24832+ "0: rep; "prefix"movsl\n" \
24833 " movl %3,%0\n" \
24834- "1: rep; movsb\n" \
24835+ "1: rep; "prefix"movsb\n" \
24836 "2:\n" \
24837+ restore \
24838 ".section .fixup,\"ax\"\n" \
24839 "5: addl %3,%0\n" \
24840 " jmp 2b\n" \
24841@@ -538,14 +650,14 @@ do { \
24842 " negl %0\n" \
24843 " andl $7,%0\n" \
24844 " subl %0,%3\n" \
24845- "4: rep; movsb\n" \
24846+ "4: rep; "__copyuser_seg"movsb\n" \
24847 " movl %3,%0\n" \
24848 " shrl $2,%0\n" \
24849 " andl $3,%3\n" \
24850 " .align 2,0x90\n" \
24851- "0: rep; movsl\n" \
24852+ "0: rep; "__copyuser_seg"movsl\n" \
24853 " movl %3,%0\n" \
24854- "1: rep; movsb\n" \
24855+ "1: rep; "__copyuser_seg"movsb\n" \
24856 "2:\n" \
24857 ".section .fixup,\"ax\"\n" \
24858 "5: addl %3,%0\n" \
24859@@ -629,9 +741,9 @@ survive:
24860 #endif
24861 stac();
24862 if (movsl_is_ok(to, from, n))
24863- __copy_user(to, from, n);
24864+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24865 else
24866- n = __copy_user_intel(to, from, n);
24867+ n = __generic_copy_to_user_intel(to, from, n);
24868 clac();
24869 return n;
24870 }
24871@@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24872 {
24873 stac();
24874 if (movsl_is_ok(to, from, n))
24875- __copy_user(to, from, n);
24876+ __copy_user(to, from, n, __copyuser_seg, "", "");
24877 else
24878- n = __copy_user_intel((void __user *)to,
24879- (const void *)from, n);
24880+ n = __generic_copy_from_user_intel(to, from, n);
24881 clac();
24882 return n;
24883 }
24884@@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24885 if (n > 64 && cpu_has_xmm2)
24886 n = __copy_user_intel_nocache(to, from, n);
24887 else
24888- __copy_user(to, from, n);
24889+ __copy_user(to, from, n, __copyuser_seg, "", "");
24890 #else
24891- __copy_user(to, from, n);
24892+ __copy_user(to, from, n, __copyuser_seg, "", "");
24893 #endif
24894 clac();
24895 return n;
24896 }
24897 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24898
24899-/**
24900- * copy_to_user: - Copy a block of data into user space.
24901- * @to: Destination address, in user space.
24902- * @from: Source address, in kernel space.
24903- * @n: Number of bytes to copy.
24904- *
24905- * Context: User context only. This function may sleep.
24906- *
24907- * Copy data from kernel space to user space.
24908- *
24909- * Returns number of bytes that could not be copied.
24910- * On success, this will be zero.
24911- */
24912-unsigned long
24913-copy_to_user(void __user *to, const void *from, unsigned long n)
24914-{
24915- if (access_ok(VERIFY_WRITE, to, n))
24916- n = __copy_to_user(to, from, n);
24917- return n;
24918-}
24919-EXPORT_SYMBOL(copy_to_user);
24920-
24921-/**
24922- * copy_from_user: - Copy a block of data from user space.
24923- * @to: Destination address, in kernel space.
24924- * @from: Source address, in user space.
24925- * @n: Number of bytes to copy.
24926- *
24927- * Context: User context only. This function may sleep.
24928- *
24929- * Copy data from user space to kernel space.
24930- *
24931- * Returns number of bytes that could not be copied.
24932- * On success, this will be zero.
24933- *
24934- * If some data could not be copied, this function will pad the copied
24935- * data to the requested size using zero bytes.
24936- */
24937-unsigned long
24938-_copy_from_user(void *to, const void __user *from, unsigned long n)
24939-{
24940- if (access_ok(VERIFY_READ, from, n))
24941- n = __copy_from_user(to, from, n);
24942- else
24943- memset(to, 0, n);
24944- return n;
24945-}
24946-EXPORT_SYMBOL(_copy_from_user);
24947-
24948 void copy_from_user_overflow(void)
24949 {
24950 WARN(1, "Buffer overflow detected!\n");
24951 }
24952 EXPORT_SYMBOL(copy_from_user_overflow);
24953+
24954+void copy_to_user_overflow(void)
24955+{
24956+ WARN(1, "Buffer overflow detected!\n");
24957+}
24958+EXPORT_SYMBOL(copy_to_user_overflow);
24959+
24960+#ifdef CONFIG_PAX_MEMORY_UDEREF
24961+void __set_fs(mm_segment_t x)
24962+{
24963+ switch (x.seg) {
24964+ case 0:
24965+ loadsegment(gs, 0);
24966+ break;
24967+ case TASK_SIZE_MAX:
24968+ loadsegment(gs, __USER_DS);
24969+ break;
24970+ case -1UL:
24971+ loadsegment(gs, __KERNEL_DS);
24972+ break;
24973+ default:
24974+ BUG();
24975+ }
24976+ return;
24977+}
24978+EXPORT_SYMBOL(__set_fs);
24979+
24980+void set_fs(mm_segment_t x)
24981+{
24982+ current_thread_info()->addr_limit = x;
24983+ __set_fs(x);
24984+}
24985+EXPORT_SYMBOL(set_fs);
24986+#endif
24987diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24988index 05928aa..b33dea1 100644
24989--- a/arch/x86/lib/usercopy_64.c
24990+++ b/arch/x86/lib/usercopy_64.c
24991@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24992 _ASM_EXTABLE(0b,3b)
24993 _ASM_EXTABLE(1b,2b)
24994 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24995- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24996+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24997 [zero] "r" (0UL), [eight] "r" (8UL));
24998 clac();
24999 return size;
25000@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
25001 }
25002 EXPORT_SYMBOL(clear_user);
25003
25004-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
25005+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
25006 {
25007- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
25008- return copy_user_generic((__force void *)to, (__force void *)from, len);
25009- }
25010- return len;
25011+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
25012+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
25013+ return len;
25014 }
25015 EXPORT_SYMBOL(copy_in_user);
25016
25017@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
25018 * it is not necessary to optimize tail handling.
25019 */
25020 unsigned long
25021-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25022+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
25023 {
25024 char c;
25025 unsigned zero_len;
25026@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
25027 clac();
25028 return len;
25029 }
25030+
25031+void copy_from_user_overflow(void)
25032+{
25033+ WARN(1, "Buffer overflow detected!\n");
25034+}
25035+EXPORT_SYMBOL(copy_from_user_overflow);
25036+
25037+void copy_to_user_overflow(void)
25038+{
25039+ WARN(1, "Buffer overflow detected!\n");
25040+}
25041+EXPORT_SYMBOL(copy_to_user_overflow);
25042diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25043index 903ec1e..c4166b2 100644
25044--- a/arch/x86/mm/extable.c
25045+++ b/arch/x86/mm/extable.c
25046@@ -6,12 +6,24 @@
25047 static inline unsigned long
25048 ex_insn_addr(const struct exception_table_entry *x)
25049 {
25050- return (unsigned long)&x->insn + x->insn;
25051+ unsigned long reloc = 0;
25052+
25053+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25054+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25055+#endif
25056+
25057+ return (unsigned long)&x->insn + x->insn + reloc;
25058 }
25059 static inline unsigned long
25060 ex_fixup_addr(const struct exception_table_entry *x)
25061 {
25062- return (unsigned long)&x->fixup + x->fixup;
25063+ unsigned long reloc = 0;
25064+
25065+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25066+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25067+#endif
25068+
25069+ return (unsigned long)&x->fixup + x->fixup + reloc;
25070 }
25071
25072 int fixup_exception(struct pt_regs *regs)
25073@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25074 unsigned long new_ip;
25075
25076 #ifdef CONFIG_PNPBIOS
25077- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25078+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25079 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25080 extern u32 pnp_bios_is_utter_crap;
25081 pnp_bios_is_utter_crap = 1;
25082@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25083 i += 4;
25084 p->fixup -= i;
25085 i += 4;
25086+
25087+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25088+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25089+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25090+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25091+#endif
25092+
25093 }
25094 }
25095
25096diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25097index 8e13ecb..60bf506 100644
25098--- a/arch/x86/mm/fault.c
25099+++ b/arch/x86/mm/fault.c
25100@@ -13,12 +13,19 @@
25101 #include <linux/perf_event.h> /* perf_sw_event */
25102 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25103 #include <linux/prefetch.h> /* prefetchw */
25104+#include <linux/unistd.h>
25105+#include <linux/compiler.h>
25106
25107 #include <asm/traps.h> /* dotraplinkage, ... */
25108 #include <asm/pgalloc.h> /* pgd_*(), ... */
25109 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25110 #include <asm/fixmap.h> /* VSYSCALL_START */
25111 #include <asm/rcu.h> /* exception_enter(), ... */
25112+#include <asm/tlbflush.h>
25113+
25114+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25115+#include <asm/stacktrace.h>
25116+#endif
25117
25118 /*
25119 * Page fault error code bits:
25120@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25121 int ret = 0;
25122
25123 /* kprobe_running() needs smp_processor_id() */
25124- if (kprobes_built_in() && !user_mode_vm(regs)) {
25125+ if (kprobes_built_in() && !user_mode(regs)) {
25126 preempt_disable();
25127 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25128 ret = 1;
25129@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25130 return !instr_lo || (instr_lo>>1) == 1;
25131 case 0x00:
25132 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25133- if (probe_kernel_address(instr, opcode))
25134+ if (user_mode(regs)) {
25135+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25136+ return 0;
25137+ } else if (probe_kernel_address(instr, opcode))
25138 return 0;
25139
25140 *prefetch = (instr_lo == 0xF) &&
25141@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25142 while (instr < max_instr) {
25143 unsigned char opcode;
25144
25145- if (probe_kernel_address(instr, opcode))
25146+ if (user_mode(regs)) {
25147+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25148+ break;
25149+ } else if (probe_kernel_address(instr, opcode))
25150 break;
25151
25152 instr++;
25153@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25154 force_sig_info(si_signo, &info, tsk);
25155 }
25156
25157+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25158+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25159+#endif
25160+
25161+#ifdef CONFIG_PAX_EMUTRAMP
25162+static int pax_handle_fetch_fault(struct pt_regs *regs);
25163+#endif
25164+
25165+#ifdef CONFIG_PAX_PAGEEXEC
25166+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25167+{
25168+ pgd_t *pgd;
25169+ pud_t *pud;
25170+ pmd_t *pmd;
25171+
25172+ pgd = pgd_offset(mm, address);
25173+ if (!pgd_present(*pgd))
25174+ return NULL;
25175+ pud = pud_offset(pgd, address);
25176+ if (!pud_present(*pud))
25177+ return NULL;
25178+ pmd = pmd_offset(pud, address);
25179+ if (!pmd_present(*pmd))
25180+ return NULL;
25181+ return pmd;
25182+}
25183+#endif
25184+
25185 DEFINE_SPINLOCK(pgd_lock);
25186 LIST_HEAD(pgd_list);
25187
25188@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25189 for (address = VMALLOC_START & PMD_MASK;
25190 address >= TASK_SIZE && address < FIXADDR_TOP;
25191 address += PMD_SIZE) {
25192+
25193+#ifdef CONFIG_PAX_PER_CPU_PGD
25194+ unsigned long cpu;
25195+#else
25196 struct page *page;
25197+#endif
25198
25199 spin_lock(&pgd_lock);
25200+
25201+#ifdef CONFIG_PAX_PER_CPU_PGD
25202+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25203+ pgd_t *pgd = get_cpu_pgd(cpu);
25204+ pmd_t *ret;
25205+#else
25206 list_for_each_entry(page, &pgd_list, lru) {
25207+ pgd_t *pgd = page_address(page);
25208 spinlock_t *pgt_lock;
25209 pmd_t *ret;
25210
25211@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25212 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25213
25214 spin_lock(pgt_lock);
25215- ret = vmalloc_sync_one(page_address(page), address);
25216+#endif
25217+
25218+ ret = vmalloc_sync_one(pgd, address);
25219+
25220+#ifndef CONFIG_PAX_PER_CPU_PGD
25221 spin_unlock(pgt_lock);
25222+#endif
25223
25224 if (!ret)
25225 break;
25226@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25227 * an interrupt in the middle of a task switch..
25228 */
25229 pgd_paddr = read_cr3();
25230+
25231+#ifdef CONFIG_PAX_PER_CPU_PGD
25232+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25233+#endif
25234+
25235 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25236 if (!pmd_k)
25237 return -1;
25238@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25239 * happen within a race in page table update. In the later
25240 * case just flush:
25241 */
25242+
25243+#ifdef CONFIG_PAX_PER_CPU_PGD
25244+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25245+ pgd = pgd_offset_cpu(smp_processor_id(), address);
25246+#else
25247 pgd = pgd_offset(current->active_mm, address);
25248+#endif
25249+
25250 pgd_ref = pgd_offset_k(address);
25251 if (pgd_none(*pgd_ref))
25252 return -1;
25253@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25254 static int is_errata100(struct pt_regs *regs, unsigned long address)
25255 {
25256 #ifdef CONFIG_X86_64
25257- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25258+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25259 return 1;
25260 #endif
25261 return 0;
25262@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25263 }
25264
25265 static const char nx_warning[] = KERN_CRIT
25266-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25267+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25268
25269 static void
25270 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25271@@ -577,15 +647,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25272 if (!oops_may_print())
25273 return;
25274
25275- if (error_code & PF_INSTR) {
25276+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25277 unsigned int level;
25278
25279 pte_t *pte = lookup_address(address, &level);
25280
25281 if (pte && pte_present(*pte) && !pte_exec(*pte))
25282- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25283+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25284 }
25285
25286+#ifdef CONFIG_PAX_KERNEXEC
25287+ if (init_mm.start_code <= address && address < init_mm.end_code) {
25288+ if (current->signal->curr_ip)
25289+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25290+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
25291+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25292+ else
25293+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
25294+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
25295+ }
25296+#endif
25297+
25298 printk(KERN_ALERT "BUG: unable to handle kernel ");
25299 if (address < PAGE_SIZE)
25300 printk(KERN_CONT "NULL pointer dereference");
25301@@ -749,12 +831,30 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25302 }
25303 #endif
25304
25305- if (unlikely(show_unhandled_signals))
25306- show_signal_msg(regs, error_code, address, tsk);
25307+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25308+ if (pax_is_fetch_fault(regs, error_code, address)) {
25309+
25310+#ifdef CONFIG_PAX_EMUTRAMP
25311+ switch (pax_handle_fetch_fault(regs)) {
25312+ case 2:
25313+ return;
25314+ }
25315+#endif
25316+
25317+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25318+ do_group_exit(SIGKILL);
25319+ }
25320+#endif
25321
25322 /* Kernel addresses are always protection faults: */
25323+ if (address >= TASK_SIZE)
25324+ error_code |= PF_PROT;
25325+
25326+ if (show_unhandled_signals)
25327+ show_signal_msg(regs, error_code, address, tsk);
25328+
25329 tsk->thread.cr2 = address;
25330- tsk->thread.error_code = error_code | (address >= TASK_SIZE);
25331+ tsk->thread.error_code = error_code;
25332 tsk->thread.trap_nr = X86_TRAP_PF;
25333
25334 force_sig_info_fault(SIGSEGV, si_code, address, tsk, 0);
25335@@ -845,7 +945,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25336 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25337 printk(KERN_ERR
25338 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25339- tsk->comm, tsk->pid, address);
25340+ tsk->comm, task_pid_nr(tsk), address);
25341 code = BUS_MCEERR_AR;
25342 }
25343 #endif
25344@@ -901,6 +1001,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25345 return 1;
25346 }
25347
25348+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25349+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25350+{
25351+ pte_t *pte;
25352+ pmd_t *pmd;
25353+ spinlock_t *ptl;
25354+ unsigned char pte_mask;
25355+
25356+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25357+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
25358+ return 0;
25359+
25360+ /* PaX: it's our fault, let's handle it if we can */
25361+
25362+ /* PaX: take a look at read faults before acquiring any locks */
25363+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25364+ /* instruction fetch attempt from a protected page in user mode */
25365+ up_read(&mm->mmap_sem);
25366+
25367+#ifdef CONFIG_PAX_EMUTRAMP
25368+ switch (pax_handle_fetch_fault(regs)) {
25369+ case 2:
25370+ return 1;
25371+ }
25372+#endif
25373+
25374+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25375+ do_group_exit(SIGKILL);
25376+ }
25377+
25378+ pmd = pax_get_pmd(mm, address);
25379+ if (unlikely(!pmd))
25380+ return 0;
25381+
25382+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25383+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25384+ pte_unmap_unlock(pte, ptl);
25385+ return 0;
25386+ }
25387+
25388+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25389+ /* write attempt to a protected page in user mode */
25390+ pte_unmap_unlock(pte, ptl);
25391+ return 0;
25392+ }
25393+
25394+#ifdef CONFIG_SMP
25395+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25396+#else
25397+ if (likely(address > get_limit(regs->cs)))
25398+#endif
25399+ {
25400+ set_pte(pte, pte_mkread(*pte));
25401+ __flush_tlb_one(address);
25402+ pte_unmap_unlock(pte, ptl);
25403+ up_read(&mm->mmap_sem);
25404+ return 1;
25405+ }
25406+
25407+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25408+
25409+ /*
25410+ * PaX: fill DTLB with user rights and retry
25411+ */
25412+ __asm__ __volatile__ (
25413+ "orb %2,(%1)\n"
25414+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25415+/*
25416+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25417+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25418+ * page fault when examined during a TLB load attempt. this is true not only
25419+ * for PTEs holding a non-present entry but also present entries that will
25420+ * raise a page fault (such as those set up by PaX, or the copy-on-write
25421+ * mechanism). in effect it means that we do *not* need to flush the TLBs
25422+ * for our target pages since their PTEs are simply not in the TLBs at all.
25423+
25424+ * the best thing in omitting it is that we gain around 15-20% speed in the
25425+ * fast path of the page fault handler and can get rid of tracing since we
25426+ * can no longer flush unintended entries.
25427+ */
25428+ "invlpg (%0)\n"
25429+#endif
25430+ __copyuser_seg"testb $0,(%0)\n"
25431+ "xorb %3,(%1)\n"
25432+ :
25433+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25434+ : "memory", "cc");
25435+ pte_unmap_unlock(pte, ptl);
25436+ up_read(&mm->mmap_sem);
25437+ return 1;
25438+}
25439+#endif
25440+
25441 /*
25442 * Handle a spurious fault caused by a stale TLB entry.
25443 *
25444@@ -973,6 +1166,9 @@ int show_unhandled_signals = 1;
25445 static inline int
25446 access_error(unsigned long error_code, struct vm_area_struct *vma)
25447 {
25448+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25449+ return 1;
25450+
25451 if (error_code & PF_WRITE) {
25452 /* write, present and write, not present: */
25453 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25454@@ -1001,7 +1197,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25455 if (error_code & PF_USER)
25456 return false;
25457
25458- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25459+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25460 return false;
25461
25462 return true;
25463@@ -1017,18 +1213,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25464 {
25465 struct vm_area_struct *vma;
25466 struct task_struct *tsk;
25467- unsigned long address;
25468 struct mm_struct *mm;
25469 int fault;
25470 int write = error_code & PF_WRITE;
25471 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25472 (write ? FAULT_FLAG_WRITE : 0);
25473
25474- tsk = current;
25475- mm = tsk->mm;
25476-
25477 /* Get the faulting address: */
25478- address = read_cr2();
25479+ unsigned long address = read_cr2();
25480+
25481+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25482+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25483+ if (!search_exception_tables(regs->ip)) {
25484+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25485+ bad_area_nosemaphore(regs, error_code, address);
25486+ return;
25487+ }
25488+ if (address < PAX_USER_SHADOW_BASE) {
25489+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25490+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25491+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25492+ } else
25493+ address -= PAX_USER_SHADOW_BASE;
25494+ }
25495+#endif
25496+
25497+ tsk = current;
25498+ mm = tsk->mm;
25499
25500 /*
25501 * Detect and handle instructions that would cause a page fault for
25502@@ -1089,7 +1300,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25503 * User-mode registers count as a user access even for any
25504 * potential system fault or CPU buglet:
25505 */
25506- if (user_mode_vm(regs)) {
25507+ if (user_mode(regs)) {
25508 local_irq_enable();
25509 error_code |= PF_USER;
25510 } else {
25511@@ -1151,6 +1362,11 @@ retry:
25512 might_sleep();
25513 }
25514
25515+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25516+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25517+ return;
25518+#endif
25519+
25520 vma = find_vma(mm, address);
25521 if (unlikely(!vma)) {
25522 bad_area(regs, error_code, address);
25523@@ -1162,18 +1378,24 @@ retry:
25524 bad_area(regs, error_code, address);
25525 return;
25526 }
25527- if (error_code & PF_USER) {
25528- /*
25529- * Accessing the stack below %sp is always a bug.
25530- * The large cushion allows instructions like enter
25531- * and pusha to work. ("enter $65535, $31" pushes
25532- * 32 pointers and then decrements %sp by 65535.)
25533- */
25534- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25535- bad_area(regs, error_code, address);
25536- return;
25537- }
25538+ /*
25539+ * Accessing the stack below %sp is always a bug.
25540+ * The large cushion allows instructions like enter
25541+ * and pusha to work. ("enter $65535, $31" pushes
25542+ * 32 pointers and then decrements %sp by 65535.)
25543+ */
25544+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25545+ bad_area(regs, error_code, address);
25546+ return;
25547 }
25548+
25549+#ifdef CONFIG_PAX_SEGMEXEC
25550+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25551+ bad_area(regs, error_code, address);
25552+ return;
25553+ }
25554+#endif
25555+
25556 if (unlikely(expand_stack(vma, address))) {
25557 bad_area(regs, error_code, address);
25558 return;
25559@@ -1237,3 +1459,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25560 __do_page_fault(regs, error_code);
25561 exception_exit(regs);
25562 }
25563+
25564+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25565+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25566+{
25567+ struct mm_struct *mm = current->mm;
25568+ unsigned long ip = regs->ip;
25569+
25570+ if (v8086_mode(regs))
25571+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25572+
25573+#ifdef CONFIG_PAX_PAGEEXEC
25574+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25575+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25576+ return true;
25577+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25578+ return true;
25579+ return false;
25580+ }
25581+#endif
25582+
25583+#ifdef CONFIG_PAX_SEGMEXEC
25584+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25585+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25586+ return true;
25587+ return false;
25588+ }
25589+#endif
25590+
25591+ return false;
25592+}
25593+#endif
25594+
25595+#ifdef CONFIG_PAX_EMUTRAMP
25596+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25597+{
25598+ int err;
25599+
25600+ do { /* PaX: libffi trampoline emulation */
25601+ unsigned char mov, jmp;
25602+ unsigned int addr1, addr2;
25603+
25604+#ifdef CONFIG_X86_64
25605+ if ((regs->ip + 9) >> 32)
25606+ break;
25607+#endif
25608+
25609+ err = get_user(mov, (unsigned char __user *)regs->ip);
25610+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25611+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25612+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25613+
25614+ if (err)
25615+ break;
25616+
25617+ if (mov == 0xB8 && jmp == 0xE9) {
25618+ regs->ax = addr1;
25619+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25620+ return 2;
25621+ }
25622+ } while (0);
25623+
25624+ do { /* PaX: gcc trampoline emulation #1 */
25625+ unsigned char mov1, mov2;
25626+ unsigned short jmp;
25627+ unsigned int addr1, addr2;
25628+
25629+#ifdef CONFIG_X86_64
25630+ if ((regs->ip + 11) >> 32)
25631+ break;
25632+#endif
25633+
25634+ err = get_user(mov1, (unsigned char __user *)regs->ip);
25635+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25636+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25637+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25638+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25639+
25640+ if (err)
25641+ break;
25642+
25643+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25644+ regs->cx = addr1;
25645+ regs->ax = addr2;
25646+ regs->ip = addr2;
25647+ return 2;
25648+ }
25649+ } while (0);
25650+
25651+ do { /* PaX: gcc trampoline emulation #2 */
25652+ unsigned char mov, jmp;
25653+ unsigned int addr1, addr2;
25654+
25655+#ifdef CONFIG_X86_64
25656+ if ((regs->ip + 9) >> 32)
25657+ break;
25658+#endif
25659+
25660+ err = get_user(mov, (unsigned char __user *)regs->ip);
25661+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25662+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25663+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25664+
25665+ if (err)
25666+ break;
25667+
25668+ if (mov == 0xB9 && jmp == 0xE9) {
25669+ regs->cx = addr1;
25670+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25671+ return 2;
25672+ }
25673+ } while (0);
25674+
25675+ return 1; /* PaX in action */
25676+}
25677+
25678+#ifdef CONFIG_X86_64
25679+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25680+{
25681+ int err;
25682+
25683+ do { /* PaX: libffi trampoline emulation */
25684+ unsigned short mov1, mov2, jmp1;
25685+ unsigned char stcclc, jmp2;
25686+ unsigned long addr1, addr2;
25687+
25688+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25689+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25690+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25691+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25692+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25693+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25694+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25695+
25696+ if (err)
25697+ break;
25698+
25699+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25700+ regs->r11 = addr1;
25701+ regs->r10 = addr2;
25702+ if (stcclc == 0xF8)
25703+ regs->flags &= ~X86_EFLAGS_CF;
25704+ else
25705+ regs->flags |= X86_EFLAGS_CF;
25706+ regs->ip = addr1;
25707+ return 2;
25708+ }
25709+ } while (0);
25710+
25711+ do { /* PaX: gcc trampoline emulation #1 */
25712+ unsigned short mov1, mov2, jmp1;
25713+ unsigned char jmp2;
25714+ unsigned int addr1;
25715+ unsigned long addr2;
25716+
25717+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25718+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25719+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25720+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25721+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25722+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25723+
25724+ if (err)
25725+ break;
25726+
25727+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25728+ regs->r11 = addr1;
25729+ regs->r10 = addr2;
25730+ regs->ip = addr1;
25731+ return 2;
25732+ }
25733+ } while (0);
25734+
25735+ do { /* PaX: gcc trampoline emulation #2 */
25736+ unsigned short mov1, mov2, jmp1;
25737+ unsigned char jmp2;
25738+ unsigned long addr1, addr2;
25739+
25740+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25741+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25742+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25743+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25744+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25745+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25746+
25747+ if (err)
25748+ break;
25749+
25750+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25751+ regs->r11 = addr1;
25752+ regs->r10 = addr2;
25753+ regs->ip = addr1;
25754+ return 2;
25755+ }
25756+ } while (0);
25757+
25758+ return 1; /* PaX in action */
25759+}
25760+#endif
25761+
25762+/*
25763+ * PaX: decide what to do with offenders (regs->ip = fault address)
25764+ *
25765+ * returns 1 when task should be killed
25766+ * 2 when gcc trampoline was detected
25767+ */
25768+static int pax_handle_fetch_fault(struct pt_regs *regs)
25769+{
25770+ if (v8086_mode(regs))
25771+ return 1;
25772+
25773+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25774+ return 1;
25775+
25776+#ifdef CONFIG_X86_32
25777+ return pax_handle_fetch_fault_32(regs);
25778+#else
25779+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25780+ return pax_handle_fetch_fault_32(regs);
25781+ else
25782+ return pax_handle_fetch_fault_64(regs);
25783+#endif
25784+}
25785+#endif
25786+
25787+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25788+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25789+{
25790+ long i;
25791+
25792+ printk(KERN_ERR "PAX: bytes at PC: ");
25793+ for (i = 0; i < 20; i++) {
25794+ unsigned char c;
25795+ if (get_user(c, (unsigned char __force_user *)pc+i))
25796+ printk(KERN_CONT "?? ");
25797+ else
25798+ printk(KERN_CONT "%02x ", c);
25799+ }
25800+ printk("\n");
25801+
25802+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25803+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
25804+ unsigned long c;
25805+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
25806+#ifdef CONFIG_X86_32
25807+ printk(KERN_CONT "???????? ");
25808+#else
25809+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25810+ printk(KERN_CONT "???????? ???????? ");
25811+ else
25812+ printk(KERN_CONT "???????????????? ");
25813+#endif
25814+ } else {
25815+#ifdef CONFIG_X86_64
25816+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25817+ printk(KERN_CONT "%08x ", (unsigned int)c);
25818+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25819+ } else
25820+#endif
25821+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25822+ }
25823+ }
25824+ printk("\n");
25825+}
25826+#endif
25827+
25828+/**
25829+ * probe_kernel_write(): safely attempt to write to a location
25830+ * @dst: address to write to
25831+ * @src: pointer to the data that shall be written
25832+ * @size: size of the data chunk
25833+ *
25834+ * Safely write to address @dst from the buffer at @src. If a kernel fault
25835+ * happens, handle that and return -EFAULT.
25836+ */
25837+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25838+{
25839+ long ret;
25840+ mm_segment_t old_fs = get_fs();
25841+
25842+ set_fs(KERNEL_DS);
25843+ pagefault_disable();
25844+ pax_open_kernel();
25845+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25846+ pax_close_kernel();
25847+ pagefault_enable();
25848+ set_fs(old_fs);
25849+
25850+ return ret ? -EFAULT : 0;
25851+}
25852diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25853index dd74e46..7d26398 100644
25854--- a/arch/x86/mm/gup.c
25855+++ b/arch/x86/mm/gup.c
25856@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25857 addr = start;
25858 len = (unsigned long) nr_pages << PAGE_SHIFT;
25859 end = start + len;
25860- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25861+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25862 (void __user *)start, len)))
25863 return 0;
25864
25865diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25866index 6f31ee5..8ee4164 100644
25867--- a/arch/x86/mm/highmem_32.c
25868+++ b/arch/x86/mm/highmem_32.c
25869@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25870 idx = type + KM_TYPE_NR*smp_processor_id();
25871 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25872 BUG_ON(!pte_none(*(kmap_pte-idx)));
25873+
25874+ pax_open_kernel();
25875 set_pte(kmap_pte-idx, mk_pte(page, prot));
25876+ pax_close_kernel();
25877+
25878 arch_flush_lazy_mmu_mode();
25879
25880 return (void *)vaddr;
25881diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25882index 937bff5..dce75ff 100644
25883--- a/arch/x86/mm/hugetlbpage.c
25884+++ b/arch/x86/mm/hugetlbpage.c
25885@@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25886 struct hstate *h = hstate_file(file);
25887 struct mm_struct *mm = current->mm;
25888 struct vm_area_struct *vma;
25889- unsigned long start_addr;
25890+ unsigned long start_addr, pax_task_size = TASK_SIZE;
25891+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25892+
25893+#ifdef CONFIG_PAX_SEGMEXEC
25894+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25895+ pax_task_size = SEGMEXEC_TASK_SIZE;
25896+#endif
25897+
25898+ pax_task_size -= PAGE_SIZE;
25899
25900 if (len > mm->cached_hole_size) {
25901- start_addr = mm->free_area_cache;
25902+ start_addr = mm->free_area_cache;
25903 } else {
25904- start_addr = TASK_UNMAPPED_BASE;
25905- mm->cached_hole_size = 0;
25906+ start_addr = mm->mmap_base;
25907+ mm->cached_hole_size = 0;
25908 }
25909
25910 full_search:
25911@@ -290,26 +298,27 @@ full_search:
25912
25913 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25914 /* At this point: (!vma || addr < vma->vm_end). */
25915- if (TASK_SIZE - len < addr) {
25916+ if (pax_task_size - len < addr) {
25917 /*
25918 * Start a new search - just in case we missed
25919 * some holes.
25920 */
25921- if (start_addr != TASK_UNMAPPED_BASE) {
25922- start_addr = TASK_UNMAPPED_BASE;
25923+ if (start_addr != mm->mmap_base) {
25924+ start_addr = mm->mmap_base;
25925 mm->cached_hole_size = 0;
25926 goto full_search;
25927 }
25928 return -ENOMEM;
25929 }
25930- if (!vma || addr + len <= vma->vm_start) {
25931- mm->free_area_cache = addr + len;
25932- return addr;
25933- }
25934+ if (check_heap_stack_gap(vma, addr, len, offset))
25935+ break;
25936 if (addr + mm->cached_hole_size < vma->vm_start)
25937 mm->cached_hole_size = vma->vm_start - addr;
25938 addr = ALIGN(vma->vm_end, huge_page_size(h));
25939 }
25940+
25941+ mm->free_area_cache = addr + len;
25942+ return addr;
25943 }
25944
25945 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25946@@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25947 struct mm_struct *mm = current->mm;
25948 struct vm_area_struct *vma;
25949 unsigned long base = mm->mmap_base;
25950- unsigned long addr = addr0;
25951+ unsigned long addr;
25952 unsigned long largest_hole = mm->cached_hole_size;
25953- unsigned long start_addr;
25954+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25955
25956 /* don't allow allocations above current base */
25957 if (mm->free_area_cache > base)
25958@@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25959 largest_hole = 0;
25960 mm->free_area_cache = base;
25961 }
25962-try_again:
25963- start_addr = mm->free_area_cache;
25964
25965 /* make sure it can fit in the remaining address space */
25966 if (mm->free_area_cache < len)
25967 goto fail;
25968
25969 /* either no address requested or can't fit in requested address hole */
25970- addr = (mm->free_area_cache - len) & huge_page_mask(h);
25971+ addr = mm->free_area_cache - len;
25972 do {
25973+ addr &= huge_page_mask(h);
25974 /*
25975 * Lookup failure means no vma is above this address,
25976 * i.e. return with success:
25977@@ -350,10 +358,10 @@ try_again:
25978 if (!vma)
25979 return addr;
25980
25981- if (addr + len <= vma->vm_start) {
25982+ if (check_heap_stack_gap(vma, addr, len, offset)) {
25983 /* remember the address as a hint for next time */
25984- mm->cached_hole_size = largest_hole;
25985- return (mm->free_area_cache = addr);
25986+ mm->cached_hole_size = largest_hole;
25987+ return (mm->free_area_cache = addr);
25988 } else if (mm->free_area_cache == vma->vm_end) {
25989 /* pull free_area_cache down to the first hole */
25990 mm->free_area_cache = vma->vm_start;
25991@@ -362,29 +370,34 @@ try_again:
25992
25993 /* remember the largest hole we saw so far */
25994 if (addr + largest_hole < vma->vm_start)
25995- largest_hole = vma->vm_start - addr;
25996+ largest_hole = vma->vm_start - addr;
25997
25998 /* try just below the current vma->vm_start */
25999- addr = (vma->vm_start - len) & huge_page_mask(h);
26000- } while (len <= vma->vm_start);
26001+ addr = skip_heap_stack_gap(vma, len, offset);
26002+ } while (!IS_ERR_VALUE(addr));
26003
26004 fail:
26005 /*
26006- * if hint left us with no space for the requested
26007- * mapping then try again:
26008- */
26009- if (start_addr != base) {
26010- mm->free_area_cache = base;
26011- largest_hole = 0;
26012- goto try_again;
26013- }
26014- /*
26015 * A failed mmap() very likely causes application failure,
26016 * so fall back to the bottom-up function here. This scenario
26017 * can happen with large stack limits and large mmap()
26018 * allocations.
26019 */
26020- mm->free_area_cache = TASK_UNMAPPED_BASE;
26021+
26022+#ifdef CONFIG_PAX_SEGMEXEC
26023+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26024+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
26025+ else
26026+#endif
26027+
26028+ mm->mmap_base = TASK_UNMAPPED_BASE;
26029+
26030+#ifdef CONFIG_PAX_RANDMMAP
26031+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26032+ mm->mmap_base += mm->delta_mmap;
26033+#endif
26034+
26035+ mm->free_area_cache = mm->mmap_base;
26036 mm->cached_hole_size = ~0UL;
26037 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
26038 len, pgoff, flags);
26039@@ -392,6 +405,7 @@ fail:
26040 /*
26041 * Restore the topdown base:
26042 */
26043+ mm->mmap_base = base;
26044 mm->free_area_cache = base;
26045 mm->cached_hole_size = ~0UL;
26046
26047@@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26048 struct hstate *h = hstate_file(file);
26049 struct mm_struct *mm = current->mm;
26050 struct vm_area_struct *vma;
26051+ unsigned long pax_task_size = TASK_SIZE;
26052+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
26053
26054 if (len & ~huge_page_mask(h))
26055 return -EINVAL;
26056- if (len > TASK_SIZE)
26057+
26058+#ifdef CONFIG_PAX_SEGMEXEC
26059+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26060+ pax_task_size = SEGMEXEC_TASK_SIZE;
26061+#endif
26062+
26063+ pax_task_size -= PAGE_SIZE;
26064+
26065+ if (len > pax_task_size)
26066 return -ENOMEM;
26067
26068 if (flags & MAP_FIXED) {
26069@@ -417,11 +441,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26070 return addr;
26071 }
26072
26073+#ifdef CONFIG_PAX_RANDMMAP
26074+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26075+#endif
26076+
26077 if (addr) {
26078 addr = ALIGN(addr, huge_page_size(h));
26079 vma = find_vma(mm, addr);
26080- if (TASK_SIZE - len >= addr &&
26081- (!vma || addr + len <= vma->vm_start))
26082+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26083 return addr;
26084 }
26085 if (mm->get_unmapped_area == arch_get_unmapped_area)
26086diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26087index d7aea41..0fc945b 100644
26088--- a/arch/x86/mm/init.c
26089+++ b/arch/x86/mm/init.c
26090@@ -4,6 +4,7 @@
26091 #include <linux/swap.h>
26092 #include <linux/memblock.h>
26093 #include <linux/bootmem.h> /* for max_low_pfn */
26094+#include <linux/tboot.h>
26095
26096 #include <asm/cacheflush.h>
26097 #include <asm/e820.h>
26098@@ -16,6 +17,8 @@
26099 #include <asm/tlb.h>
26100 #include <asm/proto.h>
26101 #include <asm/dma.h> /* for MAX_DMA_PFN */
26102+#include <asm/desc.h>
26103+#include <asm/bios_ebda.h>
26104
26105 unsigned long __initdata pgt_buf_start;
26106 unsigned long __meminitdata pgt_buf_end;
26107@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26108 {
26109 int i;
26110 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26111- unsigned long start = 0, good_end;
26112+ unsigned long start = 0x100000, good_end;
26113 phys_addr_t base;
26114
26115 for (i = 0; i < nr_range; i++) {
26116@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26117 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26118 * mmio resources as well as potential bios/acpi data regions.
26119 */
26120+
26121+#ifdef CONFIG_GRKERNSEC_KMEM
26122+static unsigned int ebda_start __read_only;
26123+static unsigned int ebda_end __read_only;
26124+#endif
26125+
26126 int devmem_is_allowed(unsigned long pagenr)
26127 {
26128- if (pagenr < 256)
26129+#ifdef CONFIG_GRKERNSEC_KMEM
26130+ /* allow BDA */
26131+ if (!pagenr)
26132 return 1;
26133+ /* allow EBDA */
26134+ if (pagenr >= ebda_start && pagenr < ebda_end)
26135+ return 1;
26136+ /* if tboot is in use, allow access to its hardcoded serial log range */
26137+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26138+ return 1;
26139+#else
26140+ if (!pagenr)
26141+ return 1;
26142+#ifdef CONFIG_VM86
26143+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26144+ return 1;
26145+#endif
26146+#endif
26147+
26148+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26149+ return 1;
26150+#ifdef CONFIG_GRKERNSEC_KMEM
26151+ /* throw out everything else below 1MB */
26152+ if (pagenr <= 256)
26153+ return 0;
26154+#endif
26155 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26156 return 0;
26157 if (!page_is_ram(pagenr))
26158@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26159 #endif
26160 }
26161
26162+#ifdef CONFIG_GRKERNSEC_KMEM
26163+static inline void gr_init_ebda(void)
26164+{
26165+ unsigned int ebda_addr;
26166+ unsigned int ebda_size = 0;
26167+
26168+ ebda_addr = get_bios_ebda();
26169+ if (ebda_addr) {
26170+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26171+ ebda_size <<= 10;
26172+ }
26173+ if (ebda_addr && ebda_size) {
26174+ ebda_start = ebda_addr >> PAGE_SHIFT;
26175+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26176+ } else {
26177+ ebda_start = 0x9f000 >> PAGE_SHIFT;
26178+ ebda_end = 0xa0000 >> PAGE_SHIFT;
26179+ }
26180+}
26181+#else
26182+static inline void gr_init_ebda(void) { }
26183+#endif
26184+
26185 void free_initmem(void)
26186 {
26187+#ifdef CONFIG_PAX_KERNEXEC
26188+#ifdef CONFIG_X86_32
26189+ /* PaX: limit KERNEL_CS to actual size */
26190+ unsigned long addr, limit;
26191+ struct desc_struct d;
26192+ int cpu;
26193+#else
26194+ pgd_t *pgd;
26195+ pud_t *pud;
26196+ pmd_t *pmd;
26197+ unsigned long addr, end;
26198+#endif
26199+#endif
26200+
26201+ gr_init_ebda();
26202+
26203+#ifdef CONFIG_PAX_KERNEXEC
26204+#ifdef CONFIG_X86_32
26205+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26206+ limit = (limit - 1UL) >> PAGE_SHIFT;
26207+
26208+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26209+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26210+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26211+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26212+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26213+ }
26214+
26215+ /* PaX: make KERNEL_CS read-only */
26216+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26217+ if (!paravirt_enabled())
26218+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26219+/*
26220+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26221+ pgd = pgd_offset_k(addr);
26222+ pud = pud_offset(pgd, addr);
26223+ pmd = pmd_offset(pud, addr);
26224+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26225+ }
26226+*/
26227+#ifdef CONFIG_X86_PAE
26228+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26229+/*
26230+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26231+ pgd = pgd_offset_k(addr);
26232+ pud = pud_offset(pgd, addr);
26233+ pmd = pmd_offset(pud, addr);
26234+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26235+ }
26236+*/
26237+#endif
26238+
26239+#ifdef CONFIG_MODULES
26240+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26241+#endif
26242+
26243+#else
26244+ /* PaX: make kernel code/rodata read-only, rest non-executable */
26245+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26246+ pgd = pgd_offset_k(addr);
26247+ pud = pud_offset(pgd, addr);
26248+ pmd = pmd_offset(pud, addr);
26249+ if (!pmd_present(*pmd))
26250+ continue;
26251+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26252+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26253+ else
26254+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26255+ }
26256+
26257+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26258+ end = addr + KERNEL_IMAGE_SIZE;
26259+ for (; addr < end; addr += PMD_SIZE) {
26260+ pgd = pgd_offset_k(addr);
26261+ pud = pud_offset(pgd, addr);
26262+ pmd = pmd_offset(pud, addr);
26263+ if (!pmd_present(*pmd))
26264+ continue;
26265+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26266+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26267+ }
26268+#endif
26269+
26270+ flush_tlb_all();
26271+#endif
26272+
26273 free_init_pages("unused kernel memory",
26274 (unsigned long)(&__init_begin),
26275 (unsigned long)(&__init_end));
26276diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26277index 11a5800..4bd9977 100644
26278--- a/arch/x86/mm/init_32.c
26279+++ b/arch/x86/mm/init_32.c
26280@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26281 }
26282
26283 /*
26284- * Creates a middle page table and puts a pointer to it in the
26285- * given global directory entry. This only returns the gd entry
26286- * in non-PAE compilation mode, since the middle layer is folded.
26287- */
26288-static pmd_t * __init one_md_table_init(pgd_t *pgd)
26289-{
26290- pud_t *pud;
26291- pmd_t *pmd_table;
26292-
26293-#ifdef CONFIG_X86_PAE
26294- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26295- if (after_bootmem)
26296- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26297- else
26298- pmd_table = (pmd_t *)alloc_low_page();
26299- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26300- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26301- pud = pud_offset(pgd, 0);
26302- BUG_ON(pmd_table != pmd_offset(pud, 0));
26303-
26304- return pmd_table;
26305- }
26306-#endif
26307- pud = pud_offset(pgd, 0);
26308- pmd_table = pmd_offset(pud, 0);
26309-
26310- return pmd_table;
26311-}
26312-
26313-/*
26314 * Create a page table and place a pointer to it in a middle page
26315 * directory entry:
26316 */
26317@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26318 page_table = (pte_t *)alloc_low_page();
26319
26320 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26321+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26322+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26323+#else
26324 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26325+#endif
26326 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26327 }
26328
26329 return pte_offset_kernel(pmd, 0);
26330 }
26331
26332+static pmd_t * __init one_md_table_init(pgd_t *pgd)
26333+{
26334+ pud_t *pud;
26335+ pmd_t *pmd_table;
26336+
26337+ pud = pud_offset(pgd, 0);
26338+ pmd_table = pmd_offset(pud, 0);
26339+
26340+ return pmd_table;
26341+}
26342+
26343 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26344 {
26345 int pgd_idx = pgd_index(vaddr);
26346@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26347 int pgd_idx, pmd_idx;
26348 unsigned long vaddr;
26349 pgd_t *pgd;
26350+ pud_t *pud;
26351 pmd_t *pmd;
26352 pte_t *pte = NULL;
26353
26354@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26355 pgd = pgd_base + pgd_idx;
26356
26357 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26358- pmd = one_md_table_init(pgd);
26359- pmd = pmd + pmd_index(vaddr);
26360+ pud = pud_offset(pgd, vaddr);
26361+ pmd = pmd_offset(pud, vaddr);
26362+
26363+#ifdef CONFIG_X86_PAE
26364+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26365+#endif
26366+
26367 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26368 pmd++, pmd_idx++) {
26369 pte = page_table_kmap_check(one_page_table_init(pmd),
26370@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26371 }
26372 }
26373
26374-static inline int is_kernel_text(unsigned long addr)
26375+static inline int is_kernel_text(unsigned long start, unsigned long end)
26376 {
26377- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26378- return 1;
26379- return 0;
26380+ if ((start > ktla_ktva((unsigned long)_etext) ||
26381+ end <= ktla_ktva((unsigned long)_stext)) &&
26382+ (start > ktla_ktva((unsigned long)_einittext) ||
26383+ end <= ktla_ktva((unsigned long)_sinittext)) &&
26384+
26385+#ifdef CONFIG_ACPI_SLEEP
26386+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26387+#endif
26388+
26389+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26390+ return 0;
26391+ return 1;
26392 }
26393
26394 /*
26395@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26396 unsigned long last_map_addr = end;
26397 unsigned long start_pfn, end_pfn;
26398 pgd_t *pgd_base = swapper_pg_dir;
26399- int pgd_idx, pmd_idx, pte_ofs;
26400+ unsigned int pgd_idx, pmd_idx, pte_ofs;
26401 unsigned long pfn;
26402 pgd_t *pgd;
26403+ pud_t *pud;
26404 pmd_t *pmd;
26405 pte_t *pte;
26406 unsigned pages_2m, pages_4k;
26407@@ -280,8 +281,13 @@ repeat:
26408 pfn = start_pfn;
26409 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26410 pgd = pgd_base + pgd_idx;
26411- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26412- pmd = one_md_table_init(pgd);
26413+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26414+ pud = pud_offset(pgd, 0);
26415+ pmd = pmd_offset(pud, 0);
26416+
26417+#ifdef CONFIG_X86_PAE
26418+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26419+#endif
26420
26421 if (pfn >= end_pfn)
26422 continue;
26423@@ -293,14 +299,13 @@ repeat:
26424 #endif
26425 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26426 pmd++, pmd_idx++) {
26427- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26428+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26429
26430 /*
26431 * Map with big pages if possible, otherwise
26432 * create normal page tables:
26433 */
26434 if (use_pse) {
26435- unsigned int addr2;
26436 pgprot_t prot = PAGE_KERNEL_LARGE;
26437 /*
26438 * first pass will use the same initial
26439@@ -310,11 +315,7 @@ repeat:
26440 __pgprot(PTE_IDENT_ATTR |
26441 _PAGE_PSE);
26442
26443- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26444- PAGE_OFFSET + PAGE_SIZE-1;
26445-
26446- if (is_kernel_text(addr) ||
26447- is_kernel_text(addr2))
26448+ if (is_kernel_text(address, address + PMD_SIZE))
26449 prot = PAGE_KERNEL_LARGE_EXEC;
26450
26451 pages_2m++;
26452@@ -331,7 +332,7 @@ repeat:
26453 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26454 pte += pte_ofs;
26455 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26456- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26457+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26458 pgprot_t prot = PAGE_KERNEL;
26459 /*
26460 * first pass will use the same initial
26461@@ -339,7 +340,7 @@ repeat:
26462 */
26463 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26464
26465- if (is_kernel_text(addr))
26466+ if (is_kernel_text(address, address + PAGE_SIZE))
26467 prot = PAGE_KERNEL_EXEC;
26468
26469 pages_4k++;
26470@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26471
26472 pud = pud_offset(pgd, va);
26473 pmd = pmd_offset(pud, va);
26474- if (!pmd_present(*pmd))
26475+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
26476 break;
26477
26478 pte = pte_offset_kernel(pmd, va);
26479@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26480
26481 static void __init pagetable_init(void)
26482 {
26483- pgd_t *pgd_base = swapper_pg_dir;
26484-
26485- permanent_kmaps_init(pgd_base);
26486+ permanent_kmaps_init(swapper_pg_dir);
26487 }
26488
26489-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26490+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26491 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26492
26493 /* user-defined highmem size */
26494@@ -731,6 +730,12 @@ void __init mem_init(void)
26495
26496 pci_iommu_alloc();
26497
26498+#ifdef CONFIG_PAX_PER_CPU_PGD
26499+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26500+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26501+ KERNEL_PGD_PTRS);
26502+#endif
26503+
26504 #ifdef CONFIG_FLATMEM
26505 BUG_ON(!mem_map);
26506 #endif
26507@@ -757,7 +762,7 @@ void __init mem_init(void)
26508 reservedpages++;
26509
26510 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26511- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26512+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26513 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26514
26515 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26516@@ -798,10 +803,10 @@ void __init mem_init(void)
26517 ((unsigned long)&__init_end -
26518 (unsigned long)&__init_begin) >> 10,
26519
26520- (unsigned long)&_etext, (unsigned long)&_edata,
26521- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26522+ (unsigned long)&_sdata, (unsigned long)&_edata,
26523+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26524
26525- (unsigned long)&_text, (unsigned long)&_etext,
26526+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26527 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26528
26529 /*
26530@@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26531 if (!kernel_set_to_readonly)
26532 return;
26533
26534+ start = ktla_ktva(start);
26535 pr_debug("Set kernel text: %lx - %lx for read write\n",
26536 start, start+size);
26537
26538@@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26539 if (!kernel_set_to_readonly)
26540 return;
26541
26542+ start = ktla_ktva(start);
26543 pr_debug("Set kernel text: %lx - %lx for read only\n",
26544 start, start+size);
26545
26546@@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26547 unsigned long start = PFN_ALIGN(_text);
26548 unsigned long size = PFN_ALIGN(_etext) - start;
26549
26550+ start = ktla_ktva(start);
26551 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26552 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26553 size >> 10);
26554diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26555index 3baff25..678a54e 100644
26556--- a/arch/x86/mm/init_64.c
26557+++ b/arch/x86/mm/init_64.c
26558@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26559 * around without checking the pgd every time.
26560 */
26561
26562-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26563+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26564 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26565
26566 int force_personality32;
26567@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26568
26569 for (address = start; address <= end; address += PGDIR_SIZE) {
26570 const pgd_t *pgd_ref = pgd_offset_k(address);
26571+
26572+#ifdef CONFIG_PAX_PER_CPU_PGD
26573+ unsigned long cpu;
26574+#else
26575 struct page *page;
26576+#endif
26577
26578 if (pgd_none(*pgd_ref))
26579 continue;
26580
26581 spin_lock(&pgd_lock);
26582+
26583+#ifdef CONFIG_PAX_PER_CPU_PGD
26584+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26585+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
26586+#else
26587 list_for_each_entry(page, &pgd_list, lru) {
26588 pgd_t *pgd;
26589 spinlock_t *pgt_lock;
26590@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26591 /* the pgt_lock only for Xen */
26592 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26593 spin_lock(pgt_lock);
26594+#endif
26595
26596 if (pgd_none(*pgd))
26597 set_pgd(pgd, *pgd_ref);
26598@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26599 BUG_ON(pgd_page_vaddr(*pgd)
26600 != pgd_page_vaddr(*pgd_ref));
26601
26602+#ifndef CONFIG_PAX_PER_CPU_PGD
26603 spin_unlock(pgt_lock);
26604+#endif
26605+
26606 }
26607 spin_unlock(&pgd_lock);
26608 }
26609@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26610 {
26611 if (pgd_none(*pgd)) {
26612 pud_t *pud = (pud_t *)spp_getpage();
26613- pgd_populate(&init_mm, pgd, pud);
26614+ pgd_populate_kernel(&init_mm, pgd, pud);
26615 if (pud != pud_offset(pgd, 0))
26616 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26617 pud, pud_offset(pgd, 0));
26618@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26619 {
26620 if (pud_none(*pud)) {
26621 pmd_t *pmd = (pmd_t *) spp_getpage();
26622- pud_populate(&init_mm, pud, pmd);
26623+ pud_populate_kernel(&init_mm, pud, pmd);
26624 if (pmd != pmd_offset(pud, 0))
26625 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26626 pmd, pmd_offset(pud, 0));
26627@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26628 pmd = fill_pmd(pud, vaddr);
26629 pte = fill_pte(pmd, vaddr);
26630
26631+ pax_open_kernel();
26632 set_pte(pte, new_pte);
26633+ pax_close_kernel();
26634
26635 /*
26636 * It's enough to flush this one mapping.
26637@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26638 pgd = pgd_offset_k((unsigned long)__va(phys));
26639 if (pgd_none(*pgd)) {
26640 pud = (pud_t *) spp_getpage();
26641- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26642- _PAGE_USER));
26643+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26644 }
26645 pud = pud_offset(pgd, (unsigned long)__va(phys));
26646 if (pud_none(*pud)) {
26647 pmd = (pmd_t *) spp_getpage();
26648- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26649- _PAGE_USER));
26650+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26651 }
26652 pmd = pmd_offset(pud, phys);
26653 BUG_ON(!pmd_none(*pmd));
26654@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26655 if (pfn >= pgt_buf_top)
26656 panic("alloc_low_page: ran out of memory");
26657
26658- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26659+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26660 clear_page(adr);
26661 *phys = pfn * PAGE_SIZE;
26662 return adr;
26663@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26664
26665 phys = __pa(virt);
26666 left = phys & (PAGE_SIZE - 1);
26667- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26668+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26669 adr = (void *)(((unsigned long)adr) | left);
26670
26671 return adr;
26672@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26673 unmap_low_page(pmd);
26674
26675 spin_lock(&init_mm.page_table_lock);
26676- pud_populate(&init_mm, pud, __va(pmd_phys));
26677+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26678 spin_unlock(&init_mm.page_table_lock);
26679 }
26680 __flush_tlb_all();
26681@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26682 unmap_low_page(pud);
26683
26684 spin_lock(&init_mm.page_table_lock);
26685- pgd_populate(&init_mm, pgd, __va(pud_phys));
26686+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26687 spin_unlock(&init_mm.page_table_lock);
26688 pgd_changed = true;
26689 }
26690@@ -691,6 +705,12 @@ void __init mem_init(void)
26691
26692 pci_iommu_alloc();
26693
26694+#ifdef CONFIG_PAX_PER_CPU_PGD
26695+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26696+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26697+ KERNEL_PGD_PTRS);
26698+#endif
26699+
26700 /* clear_bss() already clear the empty_zero_page */
26701
26702 reservedpages = 0;
26703@@ -829,6 +849,9 @@ int kern_addr_valid(unsigned long addr)
26704 if (pud_none(*pud))
26705 return 0;
26706
26707+ if (pud_large(*pud))
26708+ return pfn_valid(pud_pfn(*pud));
26709+
26710 pmd = pmd_offset(pud, addr);
26711 if (pmd_none(*pmd))
26712 return 0;
26713@@ -851,8 +874,8 @@ int kern_addr_valid(unsigned long addr)
26714 static struct vm_area_struct gate_vma = {
26715 .vm_start = VSYSCALL_START,
26716 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26717- .vm_page_prot = PAGE_READONLY_EXEC,
26718- .vm_flags = VM_READ | VM_EXEC
26719+ .vm_page_prot = PAGE_READONLY,
26720+ .vm_flags = VM_READ
26721 };
26722
26723 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26724@@ -886,7 +909,7 @@ int in_gate_area_no_mm(unsigned long addr)
26725
26726 const char *arch_vma_name(struct vm_area_struct *vma)
26727 {
26728- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26729+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26730 return "[vdso]";
26731 if (vma == &gate_vma)
26732 return "[vsyscall]";
26733diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26734index 7b179b4..6bd1777 100644
26735--- a/arch/x86/mm/iomap_32.c
26736+++ b/arch/x86/mm/iomap_32.c
26737@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26738 type = kmap_atomic_idx_push();
26739 idx = type + KM_TYPE_NR * smp_processor_id();
26740 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26741+
26742+ pax_open_kernel();
26743 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26744+ pax_close_kernel();
26745+
26746 arch_flush_lazy_mmu_mode();
26747
26748 return (void *)vaddr;
26749diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26750index 78fe3f1..2f9433c 100644
26751--- a/arch/x86/mm/ioremap.c
26752+++ b/arch/x86/mm/ioremap.c
26753@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26754 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26755 int is_ram = page_is_ram(pfn);
26756
26757- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26758+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26759 return NULL;
26760 WARN_ON_ONCE(is_ram);
26761 }
26762@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26763 *
26764 * Caller must ensure there is only one unmapping for the same pointer.
26765 */
26766-void iounmap(volatile void __iomem *addr)
26767+void iounmap(const volatile void __iomem *addr)
26768 {
26769 struct vm_struct *p, *o;
26770
26771@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26772
26773 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26774 if (page_is_ram(start >> PAGE_SHIFT))
26775+#ifdef CONFIG_HIGHMEM
26776+ if ((start >> PAGE_SHIFT) < max_low_pfn)
26777+#endif
26778 return __va(phys);
26779
26780 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26781@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26782 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26783
26784 static __initdata int after_paging_init;
26785-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26786+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26787
26788 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26789 {
26790@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26791 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26792
26793 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26794- memset(bm_pte, 0, sizeof(bm_pte));
26795- pmd_populate_kernel(&init_mm, pmd, bm_pte);
26796+ pmd_populate_user(&init_mm, pmd, bm_pte);
26797
26798 /*
26799 * The boot-ioremap range spans multiple pmds, for which
26800diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26801index d87dd6d..bf3fa66 100644
26802--- a/arch/x86/mm/kmemcheck/kmemcheck.c
26803+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26804@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26805 * memory (e.g. tracked pages)? For now, we need this to avoid
26806 * invoking kmemcheck for PnP BIOS calls.
26807 */
26808- if (regs->flags & X86_VM_MASK)
26809+ if (v8086_mode(regs))
26810 return false;
26811- if (regs->cs != __KERNEL_CS)
26812+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26813 return false;
26814
26815 pte = kmemcheck_pte_lookup(address);
26816diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26817index 845df68..1d8d29f 100644
26818--- a/arch/x86/mm/mmap.c
26819+++ b/arch/x86/mm/mmap.c
26820@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26821 * Leave an at least ~128 MB hole with possible stack randomization.
26822 */
26823 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26824-#define MAX_GAP (TASK_SIZE/6*5)
26825+#define MAX_GAP (pax_task_size/6*5)
26826
26827 static int mmap_is_legacy(void)
26828 {
26829@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26830 return rnd << PAGE_SHIFT;
26831 }
26832
26833-static unsigned long mmap_base(void)
26834+static unsigned long mmap_base(struct mm_struct *mm)
26835 {
26836 unsigned long gap = rlimit(RLIMIT_STACK);
26837+ unsigned long pax_task_size = TASK_SIZE;
26838+
26839+#ifdef CONFIG_PAX_SEGMEXEC
26840+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26841+ pax_task_size = SEGMEXEC_TASK_SIZE;
26842+#endif
26843
26844 if (gap < MIN_GAP)
26845 gap = MIN_GAP;
26846 else if (gap > MAX_GAP)
26847 gap = MAX_GAP;
26848
26849- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26850+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26851 }
26852
26853 /*
26854 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26855 * does, but not when emulating X86_32
26856 */
26857-static unsigned long mmap_legacy_base(void)
26858+static unsigned long mmap_legacy_base(struct mm_struct *mm)
26859 {
26860- if (mmap_is_ia32())
26861+ if (mmap_is_ia32()) {
26862+
26863+#ifdef CONFIG_PAX_SEGMEXEC
26864+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26865+ return SEGMEXEC_TASK_UNMAPPED_BASE;
26866+ else
26867+#endif
26868+
26869 return TASK_UNMAPPED_BASE;
26870- else
26871+ } else
26872 return TASK_UNMAPPED_BASE + mmap_rnd();
26873 }
26874
26875@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26876 void arch_pick_mmap_layout(struct mm_struct *mm)
26877 {
26878 if (mmap_is_legacy()) {
26879- mm->mmap_base = mmap_legacy_base();
26880+ mm->mmap_base = mmap_legacy_base(mm);
26881+
26882+#ifdef CONFIG_PAX_RANDMMAP
26883+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26884+ mm->mmap_base += mm->delta_mmap;
26885+#endif
26886+
26887 mm->get_unmapped_area = arch_get_unmapped_area;
26888 mm->unmap_area = arch_unmap_area;
26889 } else {
26890- mm->mmap_base = mmap_base();
26891+ mm->mmap_base = mmap_base(mm);
26892+
26893+#ifdef CONFIG_PAX_RANDMMAP
26894+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26895+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26896+#endif
26897+
26898 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26899 mm->unmap_area = arch_unmap_area_topdown;
26900 }
26901diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26902index dc0b727..f612039 100644
26903--- a/arch/x86/mm/mmio-mod.c
26904+++ b/arch/x86/mm/mmio-mod.c
26905@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26906 break;
26907 default:
26908 {
26909- unsigned char *ip = (unsigned char *)instptr;
26910+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26911 my_trace->opcode = MMIO_UNKNOWN_OP;
26912 my_trace->width = 0;
26913 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26914@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26915 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26916 void __iomem *addr)
26917 {
26918- static atomic_t next_id;
26919+ static atomic_unchecked_t next_id;
26920 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26921 /* These are page-unaligned. */
26922 struct mmiotrace_map map = {
26923@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26924 .private = trace
26925 },
26926 .phys = offset,
26927- .id = atomic_inc_return(&next_id)
26928+ .id = atomic_inc_return_unchecked(&next_id)
26929 };
26930 map.map_id = trace->id;
26931
26932@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26933 ioremap_trace_core(offset, size, addr);
26934 }
26935
26936-static void iounmap_trace_core(volatile void __iomem *addr)
26937+static void iounmap_trace_core(const volatile void __iomem *addr)
26938 {
26939 struct mmiotrace_map map = {
26940 .phys = 0,
26941@@ -328,7 +328,7 @@ not_enabled:
26942 }
26943 }
26944
26945-void mmiotrace_iounmap(volatile void __iomem *addr)
26946+void mmiotrace_iounmap(const volatile void __iomem *addr)
26947 {
26948 might_sleep();
26949 if (is_enabled()) /* recheck and proper locking in *_core() */
26950diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26951index b008656..773eac2 100644
26952--- a/arch/x86/mm/pageattr-test.c
26953+++ b/arch/x86/mm/pageattr-test.c
26954@@ -36,7 +36,7 @@ enum {
26955
26956 static int pte_testbit(pte_t pte)
26957 {
26958- return pte_flags(pte) & _PAGE_UNUSED1;
26959+ return pte_flags(pte) & _PAGE_CPA_TEST;
26960 }
26961
26962 struct split_state {
26963diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26964index a718e0d..77419bc 100644
26965--- a/arch/x86/mm/pageattr.c
26966+++ b/arch/x86/mm/pageattr.c
26967@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26968 */
26969 #ifdef CONFIG_PCI_BIOS
26970 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26971- pgprot_val(forbidden) |= _PAGE_NX;
26972+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26973 #endif
26974
26975 /*
26976@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26977 * Does not cover __inittext since that is gone later on. On
26978 * 64bit we do not enforce !NX on the low mapping
26979 */
26980- if (within(address, (unsigned long)_text, (unsigned long)_etext))
26981- pgprot_val(forbidden) |= _PAGE_NX;
26982+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26983+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26984
26985+#ifdef CONFIG_DEBUG_RODATA
26986 /*
26987 * The .rodata section needs to be read-only. Using the pfn
26988 * catches all aliases.
26989@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26990 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26991 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26992 pgprot_val(forbidden) |= _PAGE_RW;
26993+#endif
26994
26995 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26996 /*
26997@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26998 }
26999 #endif
27000
27001+#ifdef CONFIG_PAX_KERNEXEC
27002+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
27003+ pgprot_val(forbidden) |= _PAGE_RW;
27004+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
27005+ }
27006+#endif
27007+
27008 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
27009
27010 return prot;
27011@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
27012 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
27013 {
27014 /* change init_mm */
27015+ pax_open_kernel();
27016 set_pte_atomic(kpte, pte);
27017+
27018 #ifdef CONFIG_X86_32
27019 if (!SHARED_KERNEL_PMD) {
27020+
27021+#ifdef CONFIG_PAX_PER_CPU_PGD
27022+ unsigned long cpu;
27023+#else
27024 struct page *page;
27025+#endif
27026
27027+#ifdef CONFIG_PAX_PER_CPU_PGD
27028+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27029+ pgd_t *pgd = get_cpu_pgd(cpu);
27030+#else
27031 list_for_each_entry(page, &pgd_list, lru) {
27032- pgd_t *pgd;
27033+ pgd_t *pgd = (pgd_t *)page_address(page);
27034+#endif
27035+
27036 pud_t *pud;
27037 pmd_t *pmd;
27038
27039- pgd = (pgd_t *)page_address(page) + pgd_index(address);
27040+ pgd += pgd_index(address);
27041 pud = pud_offset(pgd, address);
27042 pmd = pmd_offset(pud, address);
27043 set_pte_atomic((pte_t *)pmd, pte);
27044 }
27045 }
27046 #endif
27047+ pax_close_kernel();
27048 }
27049
27050 static int
27051diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
27052index 0eb572e..92f5c1e 100644
27053--- a/arch/x86/mm/pat.c
27054+++ b/arch/x86/mm/pat.c
27055@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
27056
27057 if (!entry) {
27058 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
27059- current->comm, current->pid, start, end - 1);
27060+ current->comm, task_pid_nr(current), start, end - 1);
27061 return -EINVAL;
27062 }
27063
27064@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
27065
27066 while (cursor < to) {
27067 if (!devmem_is_allowed(pfn)) {
27068- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
27069- current->comm, from, to - 1);
27070+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27071+ current->comm, from, to - 1, cursor);
27072 return 0;
27073 }
27074 cursor += PAGE_SIZE;
27075@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27076 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27077 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27078 "for [mem %#010Lx-%#010Lx]\n",
27079- current->comm, current->pid,
27080+ current->comm, task_pid_nr(current),
27081 cattr_name(flags),
27082 base, (unsigned long long)(base + size-1));
27083 return -EINVAL;
27084@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27085 flags = lookup_memtype(paddr);
27086 if (want_flags != flags) {
27087 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27088- current->comm, current->pid,
27089+ current->comm, task_pid_nr(current),
27090 cattr_name(want_flags),
27091 (unsigned long long)paddr,
27092 (unsigned long long)(paddr + size - 1),
27093@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27094 free_memtype(paddr, paddr + size);
27095 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27096 " for [mem %#010Lx-%#010Lx], got %s\n",
27097- current->comm, current->pid,
27098+ current->comm, task_pid_nr(current),
27099 cattr_name(want_flags),
27100 (unsigned long long)paddr,
27101 (unsigned long long)(paddr + size - 1),
27102diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27103index 9f0614d..92ae64a 100644
27104--- a/arch/x86/mm/pf_in.c
27105+++ b/arch/x86/mm/pf_in.c
27106@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27107 int i;
27108 enum reason_type rv = OTHERS;
27109
27110- p = (unsigned char *)ins_addr;
27111+ p = (unsigned char *)ktla_ktva(ins_addr);
27112 p += skip_prefix(p, &prf);
27113 p += get_opcode(p, &opcode);
27114
27115@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27116 struct prefix_bits prf;
27117 int i;
27118
27119- p = (unsigned char *)ins_addr;
27120+ p = (unsigned char *)ktla_ktva(ins_addr);
27121 p += skip_prefix(p, &prf);
27122 p += get_opcode(p, &opcode);
27123
27124@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27125 struct prefix_bits prf;
27126 int i;
27127
27128- p = (unsigned char *)ins_addr;
27129+ p = (unsigned char *)ktla_ktva(ins_addr);
27130 p += skip_prefix(p, &prf);
27131 p += get_opcode(p, &opcode);
27132
27133@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27134 struct prefix_bits prf;
27135 int i;
27136
27137- p = (unsigned char *)ins_addr;
27138+ p = (unsigned char *)ktla_ktva(ins_addr);
27139 p += skip_prefix(p, &prf);
27140 p += get_opcode(p, &opcode);
27141 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27142@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27143 struct prefix_bits prf;
27144 int i;
27145
27146- p = (unsigned char *)ins_addr;
27147+ p = (unsigned char *)ktla_ktva(ins_addr);
27148 p += skip_prefix(p, &prf);
27149 p += get_opcode(p, &opcode);
27150 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27151diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27152index 8573b83..4f3ed7e 100644
27153--- a/arch/x86/mm/pgtable.c
27154+++ b/arch/x86/mm/pgtable.c
27155@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27156 list_del(&page->lru);
27157 }
27158
27159-#define UNSHARED_PTRS_PER_PGD \
27160- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27161+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27162+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27163
27164+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27165+{
27166+ unsigned int count = USER_PGD_PTRS;
27167
27168+ while (count--)
27169+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27170+}
27171+#endif
27172+
27173+#ifdef CONFIG_PAX_PER_CPU_PGD
27174+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27175+{
27176+ unsigned int count = USER_PGD_PTRS;
27177+
27178+ while (count--) {
27179+ pgd_t pgd;
27180+
27181+#ifdef CONFIG_X86_64
27182+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27183+#else
27184+ pgd = *src++;
27185+#endif
27186+
27187+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27188+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27189+#endif
27190+
27191+ *dst++ = pgd;
27192+ }
27193+
27194+}
27195+#endif
27196+
27197+#ifdef CONFIG_X86_64
27198+#define pxd_t pud_t
27199+#define pyd_t pgd_t
27200+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27201+#define pxd_free(mm, pud) pud_free((mm), (pud))
27202+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27203+#define pyd_offset(mm, address) pgd_offset((mm), (address))
27204+#define PYD_SIZE PGDIR_SIZE
27205+#else
27206+#define pxd_t pmd_t
27207+#define pyd_t pud_t
27208+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27209+#define pxd_free(mm, pud) pmd_free((mm), (pud))
27210+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27211+#define pyd_offset(mm, address) pud_offset((mm), (address))
27212+#define PYD_SIZE PUD_SIZE
27213+#endif
27214+
27215+#ifdef CONFIG_PAX_PER_CPU_PGD
27216+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27217+static inline void pgd_dtor(pgd_t *pgd) {}
27218+#else
27219 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27220 {
27221 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27222@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27223 pgd_list_del(pgd);
27224 spin_unlock(&pgd_lock);
27225 }
27226+#endif
27227
27228 /*
27229 * List of all pgd's needed for non-PAE so it can invalidate entries
27230@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27231 * -- wli
27232 */
27233
27234-#ifdef CONFIG_X86_PAE
27235+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27236 /*
27237 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27238 * updating the top-level pagetable entries to guarantee the
27239@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27240 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27241 * and initialize the kernel pmds here.
27242 */
27243-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27244+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27245
27246 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27247 {
27248@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27249 */
27250 flush_tlb_mm(mm);
27251 }
27252+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27253+#define PREALLOCATED_PXDS USER_PGD_PTRS
27254 #else /* !CONFIG_X86_PAE */
27255
27256 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27257-#define PREALLOCATED_PMDS 0
27258+#define PREALLOCATED_PXDS 0
27259
27260 #endif /* CONFIG_X86_PAE */
27261
27262-static void free_pmds(pmd_t *pmds[])
27263+static void free_pxds(pxd_t *pxds[])
27264 {
27265 int i;
27266
27267- for(i = 0; i < PREALLOCATED_PMDS; i++)
27268- if (pmds[i])
27269- free_page((unsigned long)pmds[i]);
27270+ for(i = 0; i < PREALLOCATED_PXDS; i++)
27271+ if (pxds[i])
27272+ free_page((unsigned long)pxds[i]);
27273 }
27274
27275-static int preallocate_pmds(pmd_t *pmds[])
27276+static int preallocate_pxds(pxd_t *pxds[])
27277 {
27278 int i;
27279 bool failed = false;
27280
27281- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27282- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27283- if (pmd == NULL)
27284+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27285+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27286+ if (pxd == NULL)
27287 failed = true;
27288- pmds[i] = pmd;
27289+ pxds[i] = pxd;
27290 }
27291
27292 if (failed) {
27293- free_pmds(pmds);
27294+ free_pxds(pxds);
27295 return -ENOMEM;
27296 }
27297
27298@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27299 * preallocate which never got a corresponding vma will need to be
27300 * freed manually.
27301 */
27302-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27303+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27304 {
27305 int i;
27306
27307- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27308+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27309 pgd_t pgd = pgdp[i];
27310
27311 if (pgd_val(pgd) != 0) {
27312- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27313+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27314
27315- pgdp[i] = native_make_pgd(0);
27316+ set_pgd(pgdp + i, native_make_pgd(0));
27317
27318- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27319- pmd_free(mm, pmd);
27320+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27321+ pxd_free(mm, pxd);
27322 }
27323 }
27324 }
27325
27326-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27327+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27328 {
27329- pud_t *pud;
27330+ pyd_t *pyd;
27331 unsigned long addr;
27332 int i;
27333
27334- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27335+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27336 return;
27337
27338- pud = pud_offset(pgd, 0);
27339+#ifdef CONFIG_X86_64
27340+ pyd = pyd_offset(mm, 0L);
27341+#else
27342+ pyd = pyd_offset(pgd, 0L);
27343+#endif
27344
27345- for (addr = i = 0; i < PREALLOCATED_PMDS;
27346- i++, pud++, addr += PUD_SIZE) {
27347- pmd_t *pmd = pmds[i];
27348+ for (addr = i = 0; i < PREALLOCATED_PXDS;
27349+ i++, pyd++, addr += PYD_SIZE) {
27350+ pxd_t *pxd = pxds[i];
27351
27352 if (i >= KERNEL_PGD_BOUNDARY)
27353- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27354- sizeof(pmd_t) * PTRS_PER_PMD);
27355+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27356+ sizeof(pxd_t) * PTRS_PER_PMD);
27357
27358- pud_populate(mm, pud, pmd);
27359+ pyd_populate(mm, pyd, pxd);
27360 }
27361 }
27362
27363 pgd_t *pgd_alloc(struct mm_struct *mm)
27364 {
27365 pgd_t *pgd;
27366- pmd_t *pmds[PREALLOCATED_PMDS];
27367+ pxd_t *pxds[PREALLOCATED_PXDS];
27368
27369 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27370
27371@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27372
27373 mm->pgd = pgd;
27374
27375- if (preallocate_pmds(pmds) != 0)
27376+ if (preallocate_pxds(pxds) != 0)
27377 goto out_free_pgd;
27378
27379 if (paravirt_pgd_alloc(mm) != 0)
27380- goto out_free_pmds;
27381+ goto out_free_pxds;
27382
27383 /*
27384 * Make sure that pre-populating the pmds is atomic with
27385@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27386 spin_lock(&pgd_lock);
27387
27388 pgd_ctor(mm, pgd);
27389- pgd_prepopulate_pmd(mm, pgd, pmds);
27390+ pgd_prepopulate_pxd(mm, pgd, pxds);
27391
27392 spin_unlock(&pgd_lock);
27393
27394 return pgd;
27395
27396-out_free_pmds:
27397- free_pmds(pmds);
27398+out_free_pxds:
27399+ free_pxds(pxds);
27400 out_free_pgd:
27401 free_page((unsigned long)pgd);
27402 out:
27403@@ -295,7 +356,7 @@ out:
27404
27405 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27406 {
27407- pgd_mop_up_pmds(mm, pgd);
27408+ pgd_mop_up_pxds(mm, pgd);
27409 pgd_dtor(pgd);
27410 paravirt_pgd_free(mm, pgd);
27411 free_page((unsigned long)pgd);
27412diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27413index a69bcb8..19068ab 100644
27414--- a/arch/x86/mm/pgtable_32.c
27415+++ b/arch/x86/mm/pgtable_32.c
27416@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27417 return;
27418 }
27419 pte = pte_offset_kernel(pmd, vaddr);
27420+
27421+ pax_open_kernel();
27422 if (pte_val(pteval))
27423 set_pte_at(&init_mm, vaddr, pte, pteval);
27424 else
27425 pte_clear(&init_mm, vaddr, pte);
27426+ pax_close_kernel();
27427
27428 /*
27429 * It's enough to flush this one mapping.
27430diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27431index 410531d..0f16030 100644
27432--- a/arch/x86/mm/setup_nx.c
27433+++ b/arch/x86/mm/setup_nx.c
27434@@ -5,8 +5,10 @@
27435 #include <asm/pgtable.h>
27436 #include <asm/proto.h>
27437
27438+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27439 static int disable_nx __cpuinitdata;
27440
27441+#ifndef CONFIG_PAX_PAGEEXEC
27442 /*
27443 * noexec = on|off
27444 *
27445@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27446 return 0;
27447 }
27448 early_param("noexec", noexec_setup);
27449+#endif
27450+
27451+#endif
27452
27453 void __cpuinit x86_configure_nx(void)
27454 {
27455+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27456 if (cpu_has_nx && !disable_nx)
27457 __supported_pte_mask |= _PAGE_NX;
27458 else
27459+#endif
27460 __supported_pte_mask &= ~_PAGE_NX;
27461 }
27462
27463diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27464index 60f926c..a710970 100644
27465--- a/arch/x86/mm/tlb.c
27466+++ b/arch/x86/mm/tlb.c
27467@@ -48,7 +48,11 @@ void leave_mm(int cpu)
27468 BUG();
27469 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27470 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27471+
27472+#ifndef CONFIG_PAX_PER_CPU_PGD
27473 load_cr3(swapper_pg_dir);
27474+#endif
27475+
27476 }
27477 }
27478 EXPORT_SYMBOL_GPL(leave_mm);
27479diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27480index 877b9a1..a8ecf42 100644
27481--- a/arch/x86/net/bpf_jit.S
27482+++ b/arch/x86/net/bpf_jit.S
27483@@ -9,6 +9,7 @@
27484 */
27485 #include <linux/linkage.h>
27486 #include <asm/dwarf2.h>
27487+#include <asm/alternative-asm.h>
27488
27489 /*
27490 * Calling convention :
27491@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27492 jle bpf_slow_path_word
27493 mov (SKBDATA,%rsi),%eax
27494 bswap %eax /* ntohl() */
27495+ pax_force_retaddr
27496 ret
27497
27498 sk_load_half:
27499@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27500 jle bpf_slow_path_half
27501 movzwl (SKBDATA,%rsi),%eax
27502 rol $8,%ax # ntohs()
27503+ pax_force_retaddr
27504 ret
27505
27506 sk_load_byte:
27507@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27508 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27509 jle bpf_slow_path_byte
27510 movzbl (SKBDATA,%rsi),%eax
27511+ pax_force_retaddr
27512 ret
27513
27514 /**
27515@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27516 movzbl (SKBDATA,%rsi),%ebx
27517 and $15,%bl
27518 shl $2,%bl
27519+ pax_force_retaddr
27520 ret
27521
27522 /* rsi contains offset and can be scratched */
27523@@ -109,6 +114,7 @@ bpf_slow_path_word:
27524 js bpf_error
27525 mov -12(%rbp),%eax
27526 bswap %eax
27527+ pax_force_retaddr
27528 ret
27529
27530 bpf_slow_path_half:
27531@@ -117,12 +123,14 @@ bpf_slow_path_half:
27532 mov -12(%rbp),%ax
27533 rol $8,%ax
27534 movzwl %ax,%eax
27535+ pax_force_retaddr
27536 ret
27537
27538 bpf_slow_path_byte:
27539 bpf_slow_path_common(1)
27540 js bpf_error
27541 movzbl -12(%rbp),%eax
27542+ pax_force_retaddr
27543 ret
27544
27545 bpf_slow_path_byte_msh:
27546@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27547 and $15,%al
27548 shl $2,%al
27549 xchg %eax,%ebx
27550+ pax_force_retaddr
27551 ret
27552
27553 #define sk_negative_common(SIZE) \
27554@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27555 sk_negative_common(4)
27556 mov (%rax), %eax
27557 bswap %eax
27558+ pax_force_retaddr
27559 ret
27560
27561 bpf_slow_path_half_neg:
27562@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27563 mov (%rax),%ax
27564 rol $8,%ax
27565 movzwl %ax,%eax
27566+ pax_force_retaddr
27567 ret
27568
27569 bpf_slow_path_byte_neg:
27570@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27571 .globl sk_load_byte_negative_offset
27572 sk_negative_common(1)
27573 movzbl (%rax), %eax
27574+ pax_force_retaddr
27575 ret
27576
27577 bpf_slow_path_byte_msh_neg:
27578@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27579 and $15,%al
27580 shl $2,%al
27581 xchg %eax,%ebx
27582+ pax_force_retaddr
27583 ret
27584
27585 bpf_error:
27586@@ -197,4 +210,5 @@ bpf_error:
27587 xor %eax,%eax
27588 mov -8(%rbp),%rbx
27589 leaveq
27590+ pax_force_retaddr
27591 ret
27592diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27593index 520d2bd..b895ef4 100644
27594--- a/arch/x86/net/bpf_jit_comp.c
27595+++ b/arch/x86/net/bpf_jit_comp.c
27596@@ -11,6 +11,7 @@
27597 #include <asm/cacheflush.h>
27598 #include <linux/netdevice.h>
27599 #include <linux/filter.h>
27600+#include <linux/random.h>
27601
27602 /*
27603 * Conventions :
27604@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27605 return ptr + len;
27606 }
27607
27608+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27609+#define MAX_INSTR_CODE_SIZE 96
27610+#else
27611+#define MAX_INSTR_CODE_SIZE 64
27612+#endif
27613+
27614 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27615
27616 #define EMIT1(b1) EMIT(b1, 1)
27617 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27618 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27619 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27620+
27621+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27622+/* original constant will appear in ecx */
27623+#define DILUTE_CONST_SEQUENCE(_off, _key) \
27624+do { \
27625+ /* mov ecx, randkey */ \
27626+ EMIT1(0xb9); \
27627+ EMIT(_key, 4); \
27628+ /* xor ecx, randkey ^ off */ \
27629+ EMIT2(0x81, 0xf1); \
27630+ EMIT((_key) ^ (_off), 4); \
27631+} while (0)
27632+
27633+#define EMIT1_off32(b1, _off) \
27634+do { \
27635+ switch (b1) { \
27636+ case 0x05: /* add eax, imm32 */ \
27637+ case 0x2d: /* sub eax, imm32 */ \
27638+ case 0x25: /* and eax, imm32 */ \
27639+ case 0x0d: /* or eax, imm32 */ \
27640+ case 0xb8: /* mov eax, imm32 */ \
27641+ case 0x3d: /* cmp eax, imm32 */ \
27642+ case 0xa9: /* test eax, imm32 */ \
27643+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27644+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27645+ break; \
27646+ case 0xbb: /* mov ebx, imm32 */ \
27647+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27648+ /* mov ebx, ecx */ \
27649+ EMIT2(0x89, 0xcb); \
27650+ break; \
27651+ case 0xbe: /* mov esi, imm32 */ \
27652+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27653+ /* mov esi, ecx */ \
27654+ EMIT2(0x89, 0xce); \
27655+ break; \
27656+ case 0xe9: /* jmp rel imm32 */ \
27657+ EMIT1(b1); \
27658+ EMIT(_off, 4); \
27659+ /* prevent fall-through, we're not called if off = 0 */ \
27660+ EMIT(0xcccccccc, 4); \
27661+ EMIT(0xcccccccc, 4); \
27662+ break; \
27663+ default: \
27664+ EMIT1(b1); \
27665+ EMIT(_off, 4); \
27666+ } \
27667+} while (0)
27668+
27669+#define EMIT2_off32(b1, b2, _off) \
27670+do { \
27671+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27672+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27673+ EMIT(randkey, 4); \
27674+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27675+ EMIT((_off) - randkey, 4); \
27676+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27677+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27678+ /* imul eax, ecx */ \
27679+ EMIT3(0x0f, 0xaf, 0xc1); \
27680+ } else { \
27681+ EMIT2(b1, b2); \
27682+ EMIT(_off, 4); \
27683+ } \
27684+} while (0)
27685+#else
27686 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27687+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27688+#endif
27689
27690 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27691 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27692@@ -89,6 +164,24 @@ do { \
27693 #define X86_JBE 0x76
27694 #define X86_JA 0x77
27695
27696+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27697+#define APPEND_FLOW_VERIFY() \
27698+do { \
27699+ /* mov ecx, randkey */ \
27700+ EMIT1(0xb9); \
27701+ EMIT(randkey, 4); \
27702+ /* cmp ecx, randkey */ \
27703+ EMIT2(0x81, 0xf9); \
27704+ EMIT(randkey, 4); \
27705+ /* jz after 8 int 3s */ \
27706+ EMIT2(0x74, 0x08); \
27707+ EMIT(0xcccccccc, 4); \
27708+ EMIT(0xcccccccc, 4); \
27709+} while (0)
27710+#else
27711+#define APPEND_FLOW_VERIFY() do { } while (0)
27712+#endif
27713+
27714 #define EMIT_COND_JMP(op, offset) \
27715 do { \
27716 if (is_near(offset)) \
27717@@ -96,6 +189,7 @@ do { \
27718 else { \
27719 EMIT2(0x0f, op + 0x10); \
27720 EMIT(offset, 4); /* jxx .+off32 */ \
27721+ APPEND_FLOW_VERIFY(); \
27722 } \
27723 } while (0)
27724
27725@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27726 set_fs(old_fs);
27727 }
27728
27729+struct bpf_jit_work {
27730+ struct work_struct work;
27731+ void *image;
27732+};
27733+
27734 #define CHOOSE_LOAD_FUNC(K, func) \
27735 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27736
27737 void bpf_jit_compile(struct sk_filter *fp)
27738 {
27739- u8 temp[64];
27740+ u8 temp[MAX_INSTR_CODE_SIZE];
27741 u8 *prog;
27742 unsigned int proglen, oldproglen = 0;
27743 int ilen, i;
27744@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27745 unsigned int *addrs;
27746 const struct sock_filter *filter = fp->insns;
27747 int flen = fp->len;
27748+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27749+ unsigned int randkey;
27750+#endif
27751
27752 if (!bpf_jit_enable)
27753 return;
27754@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27755 if (addrs == NULL)
27756 return;
27757
27758+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27759+ if (!fp->work)
27760+ goto out;
27761+
27762+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27763+ randkey = get_random_int();
27764+#endif
27765+
27766 /* Before first pass, make a rough estimation of addrs[]
27767- * each bpf instruction is translated to less than 64 bytes
27768+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27769 */
27770 for (proglen = 0, i = 0; i < flen; i++) {
27771- proglen += 64;
27772+ proglen += MAX_INSTR_CODE_SIZE;
27773 addrs[i] = proglen;
27774 }
27775 cleanup_addr = proglen; /* epilogue address */
27776@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27777 case BPF_S_ALU_MUL_K: /* A *= K */
27778 if (is_imm8(K))
27779 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27780- else {
27781- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27782- EMIT(K, 4);
27783- }
27784+ else
27785+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27786 break;
27787 case BPF_S_ALU_DIV_X: /* A /= X; */
27788 seen |= SEEN_XREG;
27789@@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27790 break;
27791 case BPF_S_ALU_MOD_K: /* A %= K; */
27792 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27793+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27794+ DILUTE_CONST_SEQUENCE(K, randkey);
27795+#else
27796 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27797+#endif
27798 EMIT2(0xf7, 0xf1); /* div %ecx */
27799 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27800 break;
27801 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27802+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27803+ DILUTE_CONST_SEQUENCE(K, randkey);
27804+ // imul rax, rcx
27805+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27806+#else
27807 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27808 EMIT(K, 4);
27809+#endif
27810 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27811 break;
27812 case BPF_S_ALU_AND_X:
27813@@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27814 if (is_imm8(K)) {
27815 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27816 } else {
27817- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27818- EMIT(K, 4);
27819+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27820 }
27821 } else {
27822 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27823@@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27824 break;
27825 default:
27826 /* hmm, too complex filter, give up with jit compiler */
27827- goto out;
27828+ goto error;
27829 }
27830 ilen = prog - temp;
27831 if (image) {
27832 if (unlikely(proglen + ilen > oldproglen)) {
27833 pr_err("bpb_jit_compile fatal error\n");
27834- kfree(addrs);
27835- module_free(NULL, image);
27836- return;
27837+ module_free_exec(NULL, image);
27838+ goto error;
27839 }
27840+ pax_open_kernel();
27841 memcpy(image + proglen, temp, ilen);
27842+ pax_close_kernel();
27843 }
27844 proglen += ilen;
27845 addrs[i] = proglen;
27846@@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27847 break;
27848 }
27849 if (proglen == oldproglen) {
27850- image = module_alloc(max_t(unsigned int,
27851- proglen,
27852- sizeof(struct work_struct)));
27853+ image = module_alloc_exec(proglen);
27854 if (!image)
27855- goto out;
27856+ goto error;
27857 }
27858 oldproglen = proglen;
27859 }
27860@@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27861 bpf_flush_icache(image, image + proglen);
27862
27863 fp->bpf_func = (void *)image;
27864- }
27865+ } else
27866+error:
27867+ kfree(fp->work);
27868+
27869 out:
27870 kfree(addrs);
27871 return;
27872@@ -686,18 +805,20 @@ out:
27873
27874 static void jit_free_defer(struct work_struct *arg)
27875 {
27876- module_free(NULL, arg);
27877+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27878+ kfree(arg);
27879 }
27880
27881 /* run from softirq, we must use a work_struct to call
27882- * module_free() from process context
27883+ * module_free_exec() from process context
27884 */
27885 void bpf_jit_free(struct sk_filter *fp)
27886 {
27887 if (fp->bpf_func != sk_run_filter) {
27888- struct work_struct *work = (struct work_struct *)fp->bpf_func;
27889+ struct work_struct *work = &fp->work->work;
27890
27891 INIT_WORK(work, jit_free_defer);
27892+ fp->work->image = fp->bpf_func;
27893 schedule_work(work);
27894 }
27895 }
27896diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27897index d6aa6e8..266395a 100644
27898--- a/arch/x86/oprofile/backtrace.c
27899+++ b/arch/x86/oprofile/backtrace.c
27900@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27901 struct stack_frame_ia32 *fp;
27902 unsigned long bytes;
27903
27904- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27905+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27906 if (bytes != sizeof(bufhead))
27907 return NULL;
27908
27909- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27910+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27911
27912 oprofile_add_trace(bufhead[0].return_address);
27913
27914@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27915 struct stack_frame bufhead[2];
27916 unsigned long bytes;
27917
27918- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27919+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27920 if (bytes != sizeof(bufhead))
27921 return NULL;
27922
27923@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27924 {
27925 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27926
27927- if (!user_mode_vm(regs)) {
27928+ if (!user_mode(regs)) {
27929 unsigned long stack = kernel_stack_pointer(regs);
27930 if (depth)
27931 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27932diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27933index e14a2ff..3fd6b58 100644
27934--- a/arch/x86/pci/mrst.c
27935+++ b/arch/x86/pci/mrst.c
27936@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27937 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27938 pci_mmcfg_late_init();
27939 pcibios_enable_irq = mrst_pci_irq_enable;
27940- pci_root_ops = pci_mrst_ops;
27941+ pax_open_kernel();
27942+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27943+ pax_close_kernel();
27944 pci_soc_mode = 1;
27945 /* Continue with standard init */
27946 return 1;
27947diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27948index da8fe05..7ee6704 100644
27949--- a/arch/x86/pci/pcbios.c
27950+++ b/arch/x86/pci/pcbios.c
27951@@ -79,50 +79,93 @@ union bios32 {
27952 static struct {
27953 unsigned long address;
27954 unsigned short segment;
27955-} bios32_indirect = { 0, __KERNEL_CS };
27956+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27957
27958 /*
27959 * Returns the entry point for the given service, NULL on error
27960 */
27961
27962-static unsigned long bios32_service(unsigned long service)
27963+static unsigned long __devinit bios32_service(unsigned long service)
27964 {
27965 unsigned char return_code; /* %al */
27966 unsigned long address; /* %ebx */
27967 unsigned long length; /* %ecx */
27968 unsigned long entry; /* %edx */
27969 unsigned long flags;
27970+ struct desc_struct d, *gdt;
27971
27972 local_irq_save(flags);
27973- __asm__("lcall *(%%edi); cld"
27974+
27975+ gdt = get_cpu_gdt_table(smp_processor_id());
27976+
27977+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27978+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27979+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27980+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27981+
27982+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27983 : "=a" (return_code),
27984 "=b" (address),
27985 "=c" (length),
27986 "=d" (entry)
27987 : "0" (service),
27988 "1" (0),
27989- "D" (&bios32_indirect));
27990+ "D" (&bios32_indirect),
27991+ "r"(__PCIBIOS_DS)
27992+ : "memory");
27993+
27994+ pax_open_kernel();
27995+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27996+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27997+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27998+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27999+ pax_close_kernel();
28000+
28001 local_irq_restore(flags);
28002
28003 switch (return_code) {
28004- case 0:
28005- return address + entry;
28006- case 0x80: /* Not present */
28007- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28008- return 0;
28009- default: /* Shouldn't happen */
28010- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28011- service, return_code);
28012+ case 0: {
28013+ int cpu;
28014+ unsigned char flags;
28015+
28016+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
28017+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
28018+ printk(KERN_WARNING "bios32_service: not valid\n");
28019 return 0;
28020+ }
28021+ address = address + PAGE_OFFSET;
28022+ length += 16UL; /* some BIOSs underreport this... */
28023+ flags = 4;
28024+ if (length >= 64*1024*1024) {
28025+ length >>= PAGE_SHIFT;
28026+ flags |= 8;
28027+ }
28028+
28029+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28030+ gdt = get_cpu_gdt_table(cpu);
28031+ pack_descriptor(&d, address, length, 0x9b, flags);
28032+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
28033+ pack_descriptor(&d, address, length, 0x93, flags);
28034+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
28035+ }
28036+ return entry;
28037+ }
28038+ case 0x80: /* Not present */
28039+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
28040+ return 0;
28041+ default: /* Shouldn't happen */
28042+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
28043+ service, return_code);
28044+ return 0;
28045 }
28046 }
28047
28048 static struct {
28049 unsigned long address;
28050 unsigned short segment;
28051-} pci_indirect = { 0, __KERNEL_CS };
28052+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
28053
28054-static int pci_bios_present;
28055+static int pci_bios_present __read_only;
28056
28057 static int __devinit check_pcibios(void)
28058 {
28059@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28060 unsigned long flags, pcibios_entry;
28061
28062 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28063- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28064+ pci_indirect.address = pcibios_entry;
28065
28066 local_irq_save(flags);
28067- __asm__(
28068- "lcall *(%%edi); cld\n\t"
28069+ __asm__("movw %w6, %%ds\n\t"
28070+ "lcall *%%ss:(%%edi); cld\n\t"
28071+ "push %%ss\n\t"
28072+ "pop %%ds\n\t"
28073 "jc 1f\n\t"
28074 "xor %%ah, %%ah\n"
28075 "1:"
28076@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28077 "=b" (ebx),
28078 "=c" (ecx)
28079 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28080- "D" (&pci_indirect)
28081+ "D" (&pci_indirect),
28082+ "r" (__PCIBIOS_DS)
28083 : "memory");
28084 local_irq_restore(flags);
28085
28086@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28087
28088 switch (len) {
28089 case 1:
28090- __asm__("lcall *(%%esi); cld\n\t"
28091+ __asm__("movw %w6, %%ds\n\t"
28092+ "lcall *%%ss:(%%esi); cld\n\t"
28093+ "push %%ss\n\t"
28094+ "pop %%ds\n\t"
28095 "jc 1f\n\t"
28096 "xor %%ah, %%ah\n"
28097 "1:"
28098@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28099 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28100 "b" (bx),
28101 "D" ((long)reg),
28102- "S" (&pci_indirect));
28103+ "S" (&pci_indirect),
28104+ "r" (__PCIBIOS_DS));
28105 /*
28106 * Zero-extend the result beyond 8 bits, do not trust the
28107 * BIOS having done it:
28108@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28109 *value &= 0xff;
28110 break;
28111 case 2:
28112- __asm__("lcall *(%%esi); cld\n\t"
28113+ __asm__("movw %w6, %%ds\n\t"
28114+ "lcall *%%ss:(%%esi); cld\n\t"
28115+ "push %%ss\n\t"
28116+ "pop %%ds\n\t"
28117 "jc 1f\n\t"
28118 "xor %%ah, %%ah\n"
28119 "1:"
28120@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28121 : "1" (PCIBIOS_READ_CONFIG_WORD),
28122 "b" (bx),
28123 "D" ((long)reg),
28124- "S" (&pci_indirect));
28125+ "S" (&pci_indirect),
28126+ "r" (__PCIBIOS_DS));
28127 /*
28128 * Zero-extend the result beyond 16 bits, do not trust the
28129 * BIOS having done it:
28130@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28131 *value &= 0xffff;
28132 break;
28133 case 4:
28134- __asm__("lcall *(%%esi); cld\n\t"
28135+ __asm__("movw %w6, %%ds\n\t"
28136+ "lcall *%%ss:(%%esi); cld\n\t"
28137+ "push %%ss\n\t"
28138+ "pop %%ds\n\t"
28139 "jc 1f\n\t"
28140 "xor %%ah, %%ah\n"
28141 "1:"
28142@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28143 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28144 "b" (bx),
28145 "D" ((long)reg),
28146- "S" (&pci_indirect));
28147+ "S" (&pci_indirect),
28148+ "r" (__PCIBIOS_DS));
28149 break;
28150 }
28151
28152@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28153
28154 switch (len) {
28155 case 1:
28156- __asm__("lcall *(%%esi); cld\n\t"
28157+ __asm__("movw %w6, %%ds\n\t"
28158+ "lcall *%%ss:(%%esi); cld\n\t"
28159+ "push %%ss\n\t"
28160+ "pop %%ds\n\t"
28161 "jc 1f\n\t"
28162 "xor %%ah, %%ah\n"
28163 "1:"
28164@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28165 "c" (value),
28166 "b" (bx),
28167 "D" ((long)reg),
28168- "S" (&pci_indirect));
28169+ "S" (&pci_indirect),
28170+ "r" (__PCIBIOS_DS));
28171 break;
28172 case 2:
28173- __asm__("lcall *(%%esi); cld\n\t"
28174+ __asm__("movw %w6, %%ds\n\t"
28175+ "lcall *%%ss:(%%esi); cld\n\t"
28176+ "push %%ss\n\t"
28177+ "pop %%ds\n\t"
28178 "jc 1f\n\t"
28179 "xor %%ah, %%ah\n"
28180 "1:"
28181@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28182 "c" (value),
28183 "b" (bx),
28184 "D" ((long)reg),
28185- "S" (&pci_indirect));
28186+ "S" (&pci_indirect),
28187+ "r" (__PCIBIOS_DS));
28188 break;
28189 case 4:
28190- __asm__("lcall *(%%esi); cld\n\t"
28191+ __asm__("movw %w6, %%ds\n\t"
28192+ "lcall *%%ss:(%%esi); cld\n\t"
28193+ "push %%ss\n\t"
28194+ "pop %%ds\n\t"
28195 "jc 1f\n\t"
28196 "xor %%ah, %%ah\n"
28197 "1:"
28198@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28199 "c" (value),
28200 "b" (bx),
28201 "D" ((long)reg),
28202- "S" (&pci_indirect));
28203+ "S" (&pci_indirect),
28204+ "r" (__PCIBIOS_DS));
28205 break;
28206 }
28207
28208@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28209
28210 DBG("PCI: Fetching IRQ routing table... ");
28211 __asm__("push %%es\n\t"
28212+ "movw %w8, %%ds\n\t"
28213 "push %%ds\n\t"
28214 "pop %%es\n\t"
28215- "lcall *(%%esi); cld\n\t"
28216+ "lcall *%%ss:(%%esi); cld\n\t"
28217 "pop %%es\n\t"
28218+ "push %%ss\n\t"
28219+ "pop %%ds\n"
28220 "jc 1f\n\t"
28221 "xor %%ah, %%ah\n"
28222 "1:"
28223@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28224 "1" (0),
28225 "D" ((long) &opt),
28226 "S" (&pci_indirect),
28227- "m" (opt)
28228+ "m" (opt),
28229+ "r" (__PCIBIOS_DS)
28230 : "memory");
28231 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28232 if (ret & 0xff00)
28233@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28234 {
28235 int ret;
28236
28237- __asm__("lcall *(%%esi); cld\n\t"
28238+ __asm__("movw %w5, %%ds\n\t"
28239+ "lcall *%%ss:(%%esi); cld\n\t"
28240+ "push %%ss\n\t"
28241+ "pop %%ds\n"
28242 "jc 1f\n\t"
28243 "xor %%ah, %%ah\n"
28244 "1:"
28245@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28246 : "0" (PCIBIOS_SET_PCI_HW_INT),
28247 "b" ((dev->bus->number << 8) | dev->devfn),
28248 "c" ((irq << 8) | (pin + 10)),
28249- "S" (&pci_indirect));
28250+ "S" (&pci_indirect),
28251+ "r" (__PCIBIOS_DS));
28252 return !(ret & 0xff00);
28253 }
28254 EXPORT_SYMBOL(pcibios_set_irq_routing);
28255diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28256index 40e4469..1ab536e 100644
28257--- a/arch/x86/platform/efi/efi_32.c
28258+++ b/arch/x86/platform/efi/efi_32.c
28259@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28260 {
28261 struct desc_ptr gdt_descr;
28262
28263+#ifdef CONFIG_PAX_KERNEXEC
28264+ struct desc_struct d;
28265+#endif
28266+
28267 local_irq_save(efi_rt_eflags);
28268
28269 load_cr3(initial_page_table);
28270 __flush_tlb_all();
28271
28272+#ifdef CONFIG_PAX_KERNEXEC
28273+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28274+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28275+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28276+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28277+#endif
28278+
28279 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28280 gdt_descr.size = GDT_SIZE - 1;
28281 load_gdt(&gdt_descr);
28282@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28283 {
28284 struct desc_ptr gdt_descr;
28285
28286+#ifdef CONFIG_PAX_KERNEXEC
28287+ struct desc_struct d;
28288+
28289+ memset(&d, 0, sizeof d);
28290+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28291+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28292+#endif
28293+
28294 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28295 gdt_descr.size = GDT_SIZE - 1;
28296 load_gdt(&gdt_descr);
28297diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28298index fbe66e6..eae5e38 100644
28299--- a/arch/x86/platform/efi/efi_stub_32.S
28300+++ b/arch/x86/platform/efi/efi_stub_32.S
28301@@ -6,7 +6,9 @@
28302 */
28303
28304 #include <linux/linkage.h>
28305+#include <linux/init.h>
28306 #include <asm/page_types.h>
28307+#include <asm/segment.h>
28308
28309 /*
28310 * efi_call_phys(void *, ...) is a function with variable parameters.
28311@@ -20,7 +22,7 @@
28312 * service functions will comply with gcc calling convention, too.
28313 */
28314
28315-.text
28316+__INIT
28317 ENTRY(efi_call_phys)
28318 /*
28319 * 0. The function can only be called in Linux kernel. So CS has been
28320@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28321 * The mapping of lower virtual memory has been created in prelog and
28322 * epilog.
28323 */
28324- movl $1f, %edx
28325- subl $__PAGE_OFFSET, %edx
28326- jmp *%edx
28327+#ifdef CONFIG_PAX_KERNEXEC
28328+ movl $(__KERNEXEC_EFI_DS), %edx
28329+ mov %edx, %ds
28330+ mov %edx, %es
28331+ mov %edx, %ss
28332+ addl $2f,(1f)
28333+ ljmp *(1f)
28334+
28335+__INITDATA
28336+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28337+.previous
28338+
28339+2:
28340+ subl $2b,(1b)
28341+#else
28342+ jmp 1f-__PAGE_OFFSET
28343 1:
28344+#endif
28345
28346 /*
28347 * 2. Now on the top of stack is the return
28348@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28349 * parameter 2, ..., param n. To make things easy, we save the return
28350 * address of efi_call_phys in a global variable.
28351 */
28352- popl %edx
28353- movl %edx, saved_return_addr
28354- /* get the function pointer into ECX*/
28355- popl %ecx
28356- movl %ecx, efi_rt_function_ptr
28357- movl $2f, %edx
28358- subl $__PAGE_OFFSET, %edx
28359- pushl %edx
28360+ popl (saved_return_addr)
28361+ popl (efi_rt_function_ptr)
28362
28363 /*
28364 * 3. Clear PG bit in %CR0.
28365@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28366 /*
28367 * 5. Call the physical function.
28368 */
28369- jmp *%ecx
28370+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
28371
28372-2:
28373 /*
28374 * 6. After EFI runtime service returns, control will return to
28375 * following instruction. We'd better readjust stack pointer first.
28376@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28377 movl %cr0, %edx
28378 orl $0x80000000, %edx
28379 movl %edx, %cr0
28380- jmp 1f
28381-1:
28382+
28383 /*
28384 * 8. Now restore the virtual mode from flat mode by
28385 * adding EIP with PAGE_OFFSET.
28386 */
28387- movl $1f, %edx
28388- jmp *%edx
28389+#ifdef CONFIG_PAX_KERNEXEC
28390+ movl $(__KERNEL_DS), %edx
28391+ mov %edx, %ds
28392+ mov %edx, %es
28393+ mov %edx, %ss
28394+ ljmp $(__KERNEL_CS),$1f
28395+#else
28396+ jmp 1f+__PAGE_OFFSET
28397+#endif
28398 1:
28399
28400 /*
28401 * 9. Balance the stack. And because EAX contain the return value,
28402 * we'd better not clobber it.
28403 */
28404- leal efi_rt_function_ptr, %edx
28405- movl (%edx), %ecx
28406- pushl %ecx
28407+ pushl (efi_rt_function_ptr)
28408
28409 /*
28410- * 10. Push the saved return address onto the stack and return.
28411+ * 10. Return to the saved return address.
28412 */
28413- leal saved_return_addr, %edx
28414- movl (%edx), %ecx
28415- pushl %ecx
28416- ret
28417+ jmpl *(saved_return_addr)
28418 ENDPROC(efi_call_phys)
28419 .previous
28420
28421-.data
28422+__INITDATA
28423 saved_return_addr:
28424 .long 0
28425 efi_rt_function_ptr:
28426diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28427index 4c07cca..2c8427d 100644
28428--- a/arch/x86/platform/efi/efi_stub_64.S
28429+++ b/arch/x86/platform/efi/efi_stub_64.S
28430@@ -7,6 +7,7 @@
28431 */
28432
28433 #include <linux/linkage.h>
28434+#include <asm/alternative-asm.h>
28435
28436 #define SAVE_XMM \
28437 mov %rsp, %rax; \
28438@@ -40,6 +41,7 @@ ENTRY(efi_call0)
28439 call *%rdi
28440 addq $32, %rsp
28441 RESTORE_XMM
28442+ pax_force_retaddr 0, 1
28443 ret
28444 ENDPROC(efi_call0)
28445
28446@@ -50,6 +52,7 @@ ENTRY(efi_call1)
28447 call *%rdi
28448 addq $32, %rsp
28449 RESTORE_XMM
28450+ pax_force_retaddr 0, 1
28451 ret
28452 ENDPROC(efi_call1)
28453
28454@@ -60,6 +63,7 @@ ENTRY(efi_call2)
28455 call *%rdi
28456 addq $32, %rsp
28457 RESTORE_XMM
28458+ pax_force_retaddr 0, 1
28459 ret
28460 ENDPROC(efi_call2)
28461
28462@@ -71,6 +75,7 @@ ENTRY(efi_call3)
28463 call *%rdi
28464 addq $32, %rsp
28465 RESTORE_XMM
28466+ pax_force_retaddr 0, 1
28467 ret
28468 ENDPROC(efi_call3)
28469
28470@@ -83,6 +88,7 @@ ENTRY(efi_call4)
28471 call *%rdi
28472 addq $32, %rsp
28473 RESTORE_XMM
28474+ pax_force_retaddr 0, 1
28475 ret
28476 ENDPROC(efi_call4)
28477
28478@@ -96,6 +102,7 @@ ENTRY(efi_call5)
28479 call *%rdi
28480 addq $48, %rsp
28481 RESTORE_XMM
28482+ pax_force_retaddr 0, 1
28483 ret
28484 ENDPROC(efi_call5)
28485
28486@@ -112,5 +119,6 @@ ENTRY(efi_call6)
28487 call *%rdi
28488 addq $48, %rsp
28489 RESTORE_XMM
28490+ pax_force_retaddr 0, 1
28491 ret
28492 ENDPROC(efi_call6)
28493diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28494index fd41a92..9c33628 100644
28495--- a/arch/x86/platform/mrst/mrst.c
28496+++ b/arch/x86/platform/mrst/mrst.c
28497@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28498 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28499 int sfi_mrtc_num;
28500
28501-static void mrst_power_off(void)
28502+static __noreturn void mrst_power_off(void)
28503 {
28504+ BUG();
28505 }
28506
28507-static void mrst_reboot(void)
28508+static __noreturn void mrst_reboot(void)
28509 {
28510 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28511+ BUG();
28512 }
28513
28514 /* parse all the mtimer info to a static mtimer array */
28515diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28516index d6ee929..3637cb5 100644
28517--- a/arch/x86/platform/olpc/olpc_dt.c
28518+++ b/arch/x86/platform/olpc/olpc_dt.c
28519@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28520 return res;
28521 }
28522
28523-static struct of_pdt_ops prom_olpc_ops __initdata = {
28524+static struct of_pdt_ops prom_olpc_ops __initconst = {
28525 .nextprop = olpc_dt_nextprop,
28526 .getproplen = olpc_dt_getproplen,
28527 .getproperty = olpc_dt_getproperty,
28528diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28529index 218cdb1..c1178eb 100644
28530--- a/arch/x86/power/cpu.c
28531+++ b/arch/x86/power/cpu.c
28532@@ -132,7 +132,7 @@ static void do_fpu_end(void)
28533 static void fix_processor_context(void)
28534 {
28535 int cpu = smp_processor_id();
28536- struct tss_struct *t = &per_cpu(init_tss, cpu);
28537+ struct tss_struct *t = init_tss + cpu;
28538
28539 set_tss_desc(cpu, t); /*
28540 * This just modifies memory; should not be
28541@@ -142,8 +142,6 @@ static void fix_processor_context(void)
28542 */
28543
28544 #ifdef CONFIG_X86_64
28545- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28546-
28547 syscall_init(); /* This sets MSR_*STAR and related */
28548 #endif
28549 load_TR_desc(); /* This does ltr */
28550diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28551index cbca565..bae7133 100644
28552--- a/arch/x86/realmode/init.c
28553+++ b/arch/x86/realmode/init.c
28554@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28555 __va(real_mode_header->trampoline_header);
28556
28557 #ifdef CONFIG_X86_32
28558- trampoline_header->start = __pa(startup_32_smp);
28559+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28560+
28561+#ifdef CONFIG_PAX_KERNEXEC
28562+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28563+#endif
28564+
28565+ trampoline_header->boot_cs = __BOOT_CS;
28566 trampoline_header->gdt_limit = __BOOT_DS + 7;
28567 trampoline_header->gdt_base = __pa(boot_gdt);
28568 #else
28569diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28570index 8869287..d577672 100644
28571--- a/arch/x86/realmode/rm/Makefile
28572+++ b/arch/x86/realmode/rm/Makefile
28573@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28574 $(call cc-option, -fno-unit-at-a-time)) \
28575 $(call cc-option, -fno-stack-protector) \
28576 $(call cc-option, -mpreferred-stack-boundary=2)
28577+ifdef CONSTIFY_PLUGIN
28578+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28579+endif
28580 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28581 GCOV_PROFILE := n
28582diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28583index a28221d..93c40f1 100644
28584--- a/arch/x86/realmode/rm/header.S
28585+++ b/arch/x86/realmode/rm/header.S
28586@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28587 #endif
28588 /* APM/BIOS reboot */
28589 .long pa_machine_real_restart_asm
28590-#ifdef CONFIG_X86_64
28591+#ifdef CONFIG_X86_32
28592+ .long __KERNEL_CS
28593+#else
28594 .long __KERNEL32_CS
28595 #endif
28596 END(real_mode_header)
28597diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28598index c1b2791..f9e31c7 100644
28599--- a/arch/x86/realmode/rm/trampoline_32.S
28600+++ b/arch/x86/realmode/rm/trampoline_32.S
28601@@ -25,6 +25,12 @@
28602 #include <asm/page_types.h>
28603 #include "realmode.h"
28604
28605+#ifdef CONFIG_PAX_KERNEXEC
28606+#define ta(X) (X)
28607+#else
28608+#define ta(X) (pa_ ## X)
28609+#endif
28610+
28611 .text
28612 .code16
28613
28614@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28615
28616 cli # We should be safe anyway
28617
28618- movl tr_start, %eax # where we need to go
28619-
28620 movl $0xA5A5A5A5, trampoline_status
28621 # write marker for master knows we're running
28622
28623@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28624 movw $1, %dx # protected mode (PE) bit
28625 lmsw %dx # into protected mode
28626
28627- ljmpl $__BOOT_CS, $pa_startup_32
28628+ ljmpl *(trampoline_header)
28629
28630 .section ".text32","ax"
28631 .code32
28632@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28633 .balign 8
28634 GLOBAL(trampoline_header)
28635 tr_start: .space 4
28636- tr_gdt_pad: .space 2
28637+ tr_boot_cs: .space 2
28638 tr_gdt: .space 6
28639 END(trampoline_header)
28640
28641diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28642index bb360dc..3e5945f 100644
28643--- a/arch/x86/realmode/rm/trampoline_64.S
28644+++ b/arch/x86/realmode/rm/trampoline_64.S
28645@@ -107,7 +107,7 @@ ENTRY(startup_32)
28646 wrmsr
28647
28648 # Enable paging and in turn activate Long Mode
28649- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28650+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
28651 movl %eax, %cr0
28652
28653 /*
28654diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28655index 5a1847d..deccb30 100644
28656--- a/arch/x86/tools/relocs.c
28657+++ b/arch/x86/tools/relocs.c
28658@@ -12,10 +12,13 @@
28659 #include <regex.h>
28660 #include <tools/le_byteshift.h>
28661
28662+#include "../../../include/generated/autoconf.h"
28663+
28664 static void die(char *fmt, ...);
28665
28666 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28667 static Elf32_Ehdr ehdr;
28668+static Elf32_Phdr *phdr;
28669 static unsigned long reloc_count, reloc_idx;
28670 static unsigned long *relocs;
28671 static unsigned long reloc16_count, reloc16_idx;
28672@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28673 }
28674 }
28675
28676+static void read_phdrs(FILE *fp)
28677+{
28678+ unsigned int i;
28679+
28680+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28681+ if (!phdr) {
28682+ die("Unable to allocate %d program headers\n",
28683+ ehdr.e_phnum);
28684+ }
28685+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28686+ die("Seek to %d failed: %s\n",
28687+ ehdr.e_phoff, strerror(errno));
28688+ }
28689+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28690+ die("Cannot read ELF program headers: %s\n",
28691+ strerror(errno));
28692+ }
28693+ for(i = 0; i < ehdr.e_phnum; i++) {
28694+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28695+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28696+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28697+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28698+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28699+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28700+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28701+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28702+ }
28703+
28704+}
28705+
28706 static void read_shdrs(FILE *fp)
28707 {
28708- int i;
28709+ unsigned int i;
28710 Elf32_Shdr shdr;
28711
28712 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28713@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28714
28715 static void read_strtabs(FILE *fp)
28716 {
28717- int i;
28718+ unsigned int i;
28719 for (i = 0; i < ehdr.e_shnum; i++) {
28720 struct section *sec = &secs[i];
28721 if (sec->shdr.sh_type != SHT_STRTAB) {
28722@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28723
28724 static void read_symtabs(FILE *fp)
28725 {
28726- int i,j;
28727+ unsigned int i,j;
28728 for (i = 0; i < ehdr.e_shnum; i++) {
28729 struct section *sec = &secs[i];
28730 if (sec->shdr.sh_type != SHT_SYMTAB) {
28731@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28732 }
28733
28734
28735-static void read_relocs(FILE *fp)
28736+static void read_relocs(FILE *fp, int use_real_mode)
28737 {
28738- int i,j;
28739+ unsigned int i,j;
28740+ uint32_t base;
28741+
28742 for (i = 0; i < ehdr.e_shnum; i++) {
28743 struct section *sec = &secs[i];
28744 if (sec->shdr.sh_type != SHT_REL) {
28745@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28746 die("Cannot read symbol table: %s\n",
28747 strerror(errno));
28748 }
28749+ base = 0;
28750+
28751+#ifdef CONFIG_X86_32
28752+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28753+ if (phdr[j].p_type != PT_LOAD )
28754+ continue;
28755+ 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)
28756+ continue;
28757+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28758+ break;
28759+ }
28760+#endif
28761+
28762 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28763 Elf32_Rel *rel = &sec->reltab[j];
28764- rel->r_offset = elf32_to_cpu(rel->r_offset);
28765+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28766 rel->r_info = elf32_to_cpu(rel->r_info);
28767 }
28768 }
28769@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28770
28771 static void print_absolute_symbols(void)
28772 {
28773- int i;
28774+ unsigned int i;
28775 printf("Absolute symbols\n");
28776 printf(" Num: Value Size Type Bind Visibility Name\n");
28777 for (i = 0; i < ehdr.e_shnum; i++) {
28778 struct section *sec = &secs[i];
28779 char *sym_strtab;
28780- int j;
28781+ unsigned int j;
28782
28783 if (sec->shdr.sh_type != SHT_SYMTAB) {
28784 continue;
28785@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28786
28787 static void print_absolute_relocs(void)
28788 {
28789- int i, printed = 0;
28790+ unsigned int i, printed = 0;
28791
28792 for (i = 0; i < ehdr.e_shnum; i++) {
28793 struct section *sec = &secs[i];
28794 struct section *sec_applies, *sec_symtab;
28795 char *sym_strtab;
28796 Elf32_Sym *sh_symtab;
28797- int j;
28798+ unsigned int j;
28799 if (sec->shdr.sh_type != SHT_REL) {
28800 continue;
28801 }
28802@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28803 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28804 int use_real_mode)
28805 {
28806- int i;
28807+ unsigned int i;
28808 /* Walk through the relocations */
28809 for (i = 0; i < ehdr.e_shnum; i++) {
28810 char *sym_strtab;
28811 Elf32_Sym *sh_symtab;
28812 struct section *sec_applies, *sec_symtab;
28813- int j;
28814+ unsigned int j;
28815 struct section *sec = &secs[i];
28816
28817 if (sec->shdr.sh_type != SHT_REL) {
28818@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28819 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28820 r_type = ELF32_R_TYPE(rel->r_info);
28821
28822+ if (!use_real_mode) {
28823+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28824+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28825+ continue;
28826+
28827+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28828+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28829+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28830+ continue;
28831+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28832+ continue;
28833+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28834+ continue;
28835+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28836+ continue;
28837+#endif
28838+ }
28839+
28840 shn_abs = sym->st_shndx == SHN_ABS;
28841
28842 switch (r_type) {
28843@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28844
28845 static void emit_relocs(int as_text, int use_real_mode)
28846 {
28847- int i;
28848+ unsigned int i;
28849 /* Count how many relocations I have and allocate space for them. */
28850 reloc_count = 0;
28851 walk_relocs(count_reloc, use_real_mode);
28852@@ -808,10 +874,11 @@ int main(int argc, char **argv)
28853 fname, strerror(errno));
28854 }
28855 read_ehdr(fp);
28856+ read_phdrs(fp);
28857 read_shdrs(fp);
28858 read_strtabs(fp);
28859 read_symtabs(fp);
28860- read_relocs(fp);
28861+ read_relocs(fp, use_real_mode);
28862 if (show_absolute_syms) {
28863 print_absolute_symbols();
28864 return 0;
28865diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28866index fd14be1..e3c79c0 100644
28867--- a/arch/x86/vdso/Makefile
28868+++ b/arch/x86/vdso/Makefile
28869@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28870 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28871 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28872
28873-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28874+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28875 GCOV_PROFILE := n
28876
28877 #
28878diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28879index 0faad64..39ef157 100644
28880--- a/arch/x86/vdso/vdso32-setup.c
28881+++ b/arch/x86/vdso/vdso32-setup.c
28882@@ -25,6 +25,7 @@
28883 #include <asm/tlbflush.h>
28884 #include <asm/vdso.h>
28885 #include <asm/proto.h>
28886+#include <asm/mman.h>
28887
28888 enum {
28889 VDSO_DISABLED = 0,
28890@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
28891 void enable_sep_cpu(void)
28892 {
28893 int cpu = get_cpu();
28894- struct tss_struct *tss = &per_cpu(init_tss, cpu);
28895+ struct tss_struct *tss = init_tss + cpu;
28896
28897 if (!boot_cpu_has(X86_FEATURE_SEP)) {
28898 put_cpu();
28899@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
28900 gate_vma.vm_start = FIXADDR_USER_START;
28901 gate_vma.vm_end = FIXADDR_USER_END;
28902 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
28903- gate_vma.vm_page_prot = __P101;
28904+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
28905
28906 return 0;
28907 }
28908@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28909 if (compat)
28910 addr = VDSO_HIGH_BASE;
28911 else {
28912- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
28913+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
28914 if (IS_ERR_VALUE(addr)) {
28915 ret = addr;
28916 goto up_fail;
28917 }
28918 }
28919
28920- current->mm->context.vdso = (void *)addr;
28921+ current->mm->context.vdso = addr;
28922
28923 if (compat_uses_vma || !compat) {
28924 /*
28925@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
28926 }
28927
28928 current_thread_info()->sysenter_return =
28929- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28930+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
28931
28932 up_fail:
28933 if (ret)
28934- current->mm->context.vdso = NULL;
28935+ current->mm->context.vdso = 0;
28936
28937 up_write(&mm->mmap_sem);
28938
28939@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
28940
28941 const char *arch_vma_name(struct vm_area_struct *vma)
28942 {
28943- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28944+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28945 return "[vdso]";
28946+
28947+#ifdef CONFIG_PAX_SEGMEXEC
28948+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
28949+ return "[vdso]";
28950+#endif
28951+
28952 return NULL;
28953 }
28954
28955@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28956 * Check to see if the corresponding task was created in compat vdso
28957 * mode.
28958 */
28959- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
28960+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
28961 return &gate_vma;
28962 return NULL;
28963 }
28964diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
28965index 00aaf04..4a26505 100644
28966--- a/arch/x86/vdso/vma.c
28967+++ b/arch/x86/vdso/vma.c
28968@@ -16,8 +16,6 @@
28969 #include <asm/vdso.h>
28970 #include <asm/page.h>
28971
28972-unsigned int __read_mostly vdso_enabled = 1;
28973-
28974 extern char vdso_start[], vdso_end[];
28975 extern unsigned short vdso_sync_cpuid;
28976
28977@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
28978 * unaligned here as a result of stack start randomization.
28979 */
28980 addr = PAGE_ALIGN(addr);
28981- addr = align_addr(addr, NULL, ALIGN_VDSO);
28982
28983 return addr;
28984 }
28985@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
28986 unsigned size)
28987 {
28988 struct mm_struct *mm = current->mm;
28989- unsigned long addr;
28990+ unsigned long addr = 0;
28991 int ret;
28992
28993- if (!vdso_enabled)
28994- return 0;
28995-
28996 down_write(&mm->mmap_sem);
28997+
28998+#ifdef CONFIG_PAX_RANDMMAP
28999+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29000+#endif
29001+
29002 addr = vdso_addr(mm->start_stack, size);
29003+ addr = align_addr(addr, NULL, ALIGN_VDSO);
29004 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29005 if (IS_ERR_VALUE(addr)) {
29006 ret = addr;
29007 goto up_fail;
29008 }
29009
29010- current->mm->context.vdso = (void *)addr;
29011+ mm->context.vdso = addr;
29012
29013 ret = install_special_mapping(mm, addr, size,
29014 VM_READ|VM_EXEC|
29015 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29016 pages);
29017- if (ret) {
29018- current->mm->context.vdso = NULL;
29019- goto up_fail;
29020- }
29021+ if (ret)
29022+ mm->context.vdso = 0;
29023
29024 up_fail:
29025 up_write(&mm->mmap_sem);
29026@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29027 vdsox32_size);
29028 }
29029 #endif
29030-
29031-static __init int vdso_setup(char *s)
29032-{
29033- vdso_enabled = simple_strtoul(s, NULL, 0);
29034- return 0;
29035-}
29036-__setup("vdso=", vdso_setup);
29037diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29038index 586d838..e883209 100644
29039--- a/arch/x86/xen/enlighten.c
29040+++ b/arch/x86/xen/enlighten.c
29041@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29042
29043 struct shared_info xen_dummy_shared_info;
29044
29045-void *xen_initial_gdt;
29046-
29047 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29048 __read_mostly int xen_have_vector_callback;
29049 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29050@@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29051 {
29052 unsigned long va = dtr->address;
29053 unsigned int size = dtr->size + 1;
29054- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29055- unsigned long frames[pages];
29056+ unsigned long frames[65536 / PAGE_SIZE];
29057 int f;
29058
29059 /*
29060@@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29061 {
29062 unsigned long va = dtr->address;
29063 unsigned int size = dtr->size + 1;
29064- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29065- unsigned long frames[pages];
29066+ unsigned long frames[65536 / PAGE_SIZE];
29067 int f;
29068
29069 /*
29070@@ -916,7 +912,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29071 return 0;
29072 }
29073
29074-static void set_xen_basic_apic_ops(void)
29075+static void __init set_xen_basic_apic_ops(void)
29076 {
29077 apic->read = xen_apic_read;
29078 apic->write = xen_apic_write;
29079@@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29080 #endif
29081 };
29082
29083-static void xen_reboot(int reason)
29084+static __noreturn void xen_reboot(int reason)
29085 {
29086 struct sched_shutdown r = { .reason = reason };
29087
29088- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29089- BUG();
29090+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29091+ BUG();
29092 }
29093
29094-static void xen_restart(char *msg)
29095+static __noreturn void xen_restart(char *msg)
29096 {
29097 xen_reboot(SHUTDOWN_reboot);
29098 }
29099
29100-static void xen_emergency_restart(void)
29101+static __noreturn void xen_emergency_restart(void)
29102 {
29103 xen_reboot(SHUTDOWN_reboot);
29104 }
29105
29106-static void xen_machine_halt(void)
29107+static __noreturn void xen_machine_halt(void)
29108 {
29109 xen_reboot(SHUTDOWN_poweroff);
29110 }
29111
29112-static void xen_machine_power_off(void)
29113+static __noreturn void xen_machine_power_off(void)
29114 {
29115 if (pm_power_off)
29116 pm_power_off();
29117@@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29118 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29119
29120 /* Work out if we support NX */
29121- x86_configure_nx();
29122+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29123+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29124+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29125+ unsigned l, h;
29126+
29127+ __supported_pte_mask |= _PAGE_NX;
29128+ rdmsr(MSR_EFER, l, h);
29129+ l |= EFER_NX;
29130+ wrmsr(MSR_EFER, l, h);
29131+ }
29132+#endif
29133
29134 xen_setup_features();
29135
29136@@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29137 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29138 }
29139
29140- machine_ops = xen_machine_ops;
29141-
29142- /*
29143- * The only reliable way to retain the initial address of the
29144- * percpu gdt_page is to remember it here, so we can go and
29145- * mark it RW later, when the initial percpu area is freed.
29146- */
29147- xen_initial_gdt = &per_cpu(gdt_page, 0);
29148+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29149
29150 xen_smp_init();
29151
29152diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29153index dcf5f2d..d804c25 100644
29154--- a/arch/x86/xen/mmu.c
29155+++ b/arch/x86/xen/mmu.c
29156@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29157 /* L3_k[510] -> level2_kernel_pgt
29158 * L3_i[511] -> level2_fixmap_pgt */
29159 convert_pfn_mfn(level3_kernel_pgt);
29160+ convert_pfn_mfn(level3_vmalloc_start_pgt);
29161+ convert_pfn_mfn(level3_vmalloc_end_pgt);
29162+ convert_pfn_mfn(level3_vmemmap_pgt);
29163
29164 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29165 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29166@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29167 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29168 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29169 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29170+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29171+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29172+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29173 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29174 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29175+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29176 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29177 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29178
29179@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29180 pv_mmu_ops.set_pud = xen_set_pud;
29181 #if PAGETABLE_LEVELS == 4
29182 pv_mmu_ops.set_pgd = xen_set_pgd;
29183+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29184 #endif
29185
29186 /* This will work as long as patching hasn't happened yet
29187@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29188 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29189 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29190 .set_pgd = xen_set_pgd_hyper,
29191+ .set_pgd_batched = xen_set_pgd_hyper,
29192
29193 .alloc_pud = xen_alloc_pmd_init,
29194 .release_pud = xen_release_pmd_init,
29195diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29196index 353c50f..8f3c179 100644
29197--- a/arch/x86/xen/smp.c
29198+++ b/arch/x86/xen/smp.c
29199@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29200 {
29201 BUG_ON(smp_processor_id() != 0);
29202 native_smp_prepare_boot_cpu();
29203-
29204- /* We've switched to the "real" per-cpu gdt, so make sure the
29205- old memory can be recycled */
29206- make_lowmem_page_readwrite(xen_initial_gdt);
29207-
29208 xen_filter_cpu_maps();
29209 xen_setup_vcpu_info_placement();
29210 }
29211@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29212 gdt = get_cpu_gdt_table(cpu);
29213
29214 ctxt->flags = VGCF_IN_KERNEL;
29215- ctxt->user_regs.ds = __USER_DS;
29216- ctxt->user_regs.es = __USER_DS;
29217+ ctxt->user_regs.ds = __KERNEL_DS;
29218+ ctxt->user_regs.es = __KERNEL_DS;
29219 ctxt->user_regs.ss = __KERNEL_DS;
29220 #ifdef CONFIG_X86_32
29221 ctxt->user_regs.fs = __KERNEL_PERCPU;
29222- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29223+ savesegment(gs, ctxt->user_regs.gs);
29224 #else
29225 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29226 #endif
29227@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29228 int rc;
29229
29230 per_cpu(current_task, cpu) = idle;
29231+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
29232 #ifdef CONFIG_X86_32
29233 irq_ctx_init(cpu);
29234 #else
29235 clear_tsk_thread_flag(idle, TIF_FORK);
29236- per_cpu(kernel_stack, cpu) =
29237- (unsigned long)task_stack_page(idle) -
29238- KERNEL_STACK_OFFSET + THREAD_SIZE;
29239+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29240 #endif
29241 xen_setup_runstate_info(cpu);
29242 xen_setup_timer(cpu);
29243@@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29244
29245 void __init xen_smp_init(void)
29246 {
29247- smp_ops = xen_smp_ops;
29248+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29249 xen_fill_possible_map();
29250 xen_init_spinlocks();
29251 }
29252diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29253index f9643fc..602e8af 100644
29254--- a/arch/x86/xen/xen-asm_32.S
29255+++ b/arch/x86/xen/xen-asm_32.S
29256@@ -84,14 +84,14 @@ ENTRY(xen_iret)
29257 ESP_OFFSET=4 # bytes pushed onto stack
29258
29259 /*
29260- * Store vcpu_info pointer for easy access. Do it this way to
29261- * avoid having to reload %fs
29262+ * Store vcpu_info pointer for easy access.
29263 */
29264 #ifdef CONFIG_SMP
29265- GET_THREAD_INFO(%eax)
29266- movl TI_cpu(%eax), %eax
29267- movl __per_cpu_offset(,%eax,4), %eax
29268- mov xen_vcpu(%eax), %eax
29269+ push %fs
29270+ mov $(__KERNEL_PERCPU), %eax
29271+ mov %eax, %fs
29272+ mov PER_CPU_VAR(xen_vcpu), %eax
29273+ pop %fs
29274 #else
29275 movl xen_vcpu, %eax
29276 #endif
29277diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29278index 7faed58..ba4427c 100644
29279--- a/arch/x86/xen/xen-head.S
29280+++ b/arch/x86/xen/xen-head.S
29281@@ -19,6 +19,17 @@ ENTRY(startup_xen)
29282 #ifdef CONFIG_X86_32
29283 mov %esi,xen_start_info
29284 mov $init_thread_union+THREAD_SIZE,%esp
29285+#ifdef CONFIG_SMP
29286+ movl $cpu_gdt_table,%edi
29287+ movl $__per_cpu_load,%eax
29288+ movw %ax,__KERNEL_PERCPU + 2(%edi)
29289+ rorl $16,%eax
29290+ movb %al,__KERNEL_PERCPU + 4(%edi)
29291+ movb %ah,__KERNEL_PERCPU + 7(%edi)
29292+ movl $__per_cpu_end - 1,%eax
29293+ subl $__per_cpu_start,%eax
29294+ movw %ax,__KERNEL_PERCPU + 0(%edi)
29295+#endif
29296 #else
29297 mov %rsi,xen_start_info
29298 mov $init_thread_union+THREAD_SIZE,%rsp
29299diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29300index a95b417..b6dbd0b 100644
29301--- a/arch/x86/xen/xen-ops.h
29302+++ b/arch/x86/xen/xen-ops.h
29303@@ -10,8 +10,6 @@
29304 extern const char xen_hypervisor_callback[];
29305 extern const char xen_failsafe_callback[];
29306
29307-extern void *xen_initial_gdt;
29308-
29309 struct trap_info;
29310 void xen_copy_trap_info(struct trap_info *traps);
29311
29312diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29313index 525bd3d..ef888b1 100644
29314--- a/arch/xtensa/variants/dc232b/include/variant/core.h
29315+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29316@@ -119,9 +119,9 @@
29317 ----------------------------------------------------------------------*/
29318
29319 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29320-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29321 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29322 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29323+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29324
29325 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29326 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29327diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29328index 2f33760..835e50a 100644
29329--- a/arch/xtensa/variants/fsf/include/variant/core.h
29330+++ b/arch/xtensa/variants/fsf/include/variant/core.h
29331@@ -11,6 +11,7 @@
29332 #ifndef _XTENSA_CORE_H
29333 #define _XTENSA_CORE_H
29334
29335+#include <linux/const.h>
29336
29337 /****************************************************************************
29338 Parameters Useful for Any Code, USER or PRIVILEGED
29339@@ -112,9 +113,9 @@
29340 ----------------------------------------------------------------------*/
29341
29342 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29343-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29344 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29345 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29346+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29347
29348 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29349 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29350diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29351index af00795..2bb8105 100644
29352--- a/arch/xtensa/variants/s6000/include/variant/core.h
29353+++ b/arch/xtensa/variants/s6000/include/variant/core.h
29354@@ -11,6 +11,7 @@
29355 #ifndef _XTENSA_CORE_CONFIGURATION_H
29356 #define _XTENSA_CORE_CONFIGURATION_H
29357
29358+#include <linux/const.h>
29359
29360 /****************************************************************************
29361 Parameters Useful for Any Code, USER or PRIVILEGED
29362@@ -118,9 +119,9 @@
29363 ----------------------------------------------------------------------*/
29364
29365 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29366-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29367 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29368 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29369+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29370
29371 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29372 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29373diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29374index 58916af..9cb880b 100644
29375--- a/block/blk-iopoll.c
29376+++ b/block/blk-iopoll.c
29377@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29378 }
29379 EXPORT_SYMBOL(blk_iopoll_complete);
29380
29381-static void blk_iopoll_softirq(struct softirq_action *h)
29382+static void blk_iopoll_softirq(void)
29383 {
29384 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29385 int rearm = 0, budget = blk_iopoll_budget;
29386diff --git a/block/blk-map.c b/block/blk-map.c
29387index 623e1cd..ca1e109 100644
29388--- a/block/blk-map.c
29389+++ b/block/blk-map.c
29390@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29391 if (!len || !kbuf)
29392 return -EINVAL;
29393
29394- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29395+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29396 if (do_copy)
29397 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29398 else
29399diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29400index 467c8de..4bddc6d 100644
29401--- a/block/blk-softirq.c
29402+++ b/block/blk-softirq.c
29403@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29404 * Softirq action handler - move entries to local list and loop over them
29405 * while passing them to the queue registered handler.
29406 */
29407-static void blk_done_softirq(struct softirq_action *h)
29408+static void blk_done_softirq(void)
29409 {
29410 struct list_head *cpu_list, local_list;
29411
29412diff --git a/block/bsg.c b/block/bsg.c
29413index ff64ae3..593560c 100644
29414--- a/block/bsg.c
29415+++ b/block/bsg.c
29416@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29417 struct sg_io_v4 *hdr, struct bsg_device *bd,
29418 fmode_t has_write_perm)
29419 {
29420+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29421+ unsigned char *cmdptr;
29422+
29423 if (hdr->request_len > BLK_MAX_CDB) {
29424 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29425 if (!rq->cmd)
29426 return -ENOMEM;
29427- }
29428+ cmdptr = rq->cmd;
29429+ } else
29430+ cmdptr = tmpcmd;
29431
29432- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29433+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29434 hdr->request_len))
29435 return -EFAULT;
29436
29437+ if (cmdptr != rq->cmd)
29438+ memcpy(rq->cmd, cmdptr, hdr->request_len);
29439+
29440 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29441 if (blk_verify_command(rq->cmd, has_write_perm))
29442 return -EPERM;
29443diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29444index 7c668c8..db3521c 100644
29445--- a/block/compat_ioctl.c
29446+++ b/block/compat_ioctl.c
29447@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29448 err |= __get_user(f->spec1, &uf->spec1);
29449 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29450 err |= __get_user(name, &uf->name);
29451- f->name = compat_ptr(name);
29452+ f->name = (void __force_kernel *)compat_ptr(name);
29453 if (err) {
29454 err = -EFAULT;
29455 goto out;
29456diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29457index 6296b40..417c00f 100644
29458--- a/block/partitions/efi.c
29459+++ b/block/partitions/efi.c
29460@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29461 if (!gpt)
29462 return NULL;
29463
29464+ if (!le32_to_cpu(gpt->num_partition_entries))
29465+ return NULL;
29466+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29467+ if (!pte)
29468+ return NULL;
29469+
29470 count = le32_to_cpu(gpt->num_partition_entries) *
29471 le32_to_cpu(gpt->sizeof_partition_entry);
29472- if (!count)
29473- return NULL;
29474- pte = kzalloc(count, GFP_KERNEL);
29475- if (!pte)
29476- return NULL;
29477-
29478 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29479 (u8 *) pte,
29480 count) < count) {
29481diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29482index 9a87daa..fb17486 100644
29483--- a/block/scsi_ioctl.c
29484+++ b/block/scsi_ioctl.c
29485@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29486 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29487 struct sg_io_hdr *hdr, fmode_t mode)
29488 {
29489- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29490+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29491+ unsigned char *cmdptr;
29492+
29493+ if (rq->cmd != rq->__cmd)
29494+ cmdptr = rq->cmd;
29495+ else
29496+ cmdptr = tmpcmd;
29497+
29498+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29499 return -EFAULT;
29500+
29501+ if (cmdptr != rq->cmd)
29502+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29503+
29504 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29505 return -EPERM;
29506
29507@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29508 int err;
29509 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29510 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29511+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29512+ unsigned char *cmdptr;
29513
29514 if (!sic)
29515 return -EINVAL;
29516@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29517 */
29518 err = -EFAULT;
29519 rq->cmd_len = cmdlen;
29520- if (copy_from_user(rq->cmd, sic->data, cmdlen))
29521+
29522+ if (rq->cmd != rq->__cmd)
29523+ cmdptr = rq->cmd;
29524+ else
29525+ cmdptr = tmpcmd;
29526+
29527+ if (copy_from_user(cmdptr, sic->data, cmdlen))
29528 goto error;
29529
29530+ if (rq->cmd != cmdptr)
29531+ memcpy(rq->cmd, cmdptr, cmdlen);
29532+
29533 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29534 goto error;
29535
29536diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29537index 7bdd61b..afec999 100644
29538--- a/crypto/cryptd.c
29539+++ b/crypto/cryptd.c
29540@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29541
29542 struct cryptd_blkcipher_request_ctx {
29543 crypto_completion_t complete;
29544-};
29545+} __no_const;
29546
29547 struct cryptd_hash_ctx {
29548 struct crypto_shash *child;
29549@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29550
29551 struct cryptd_aead_request_ctx {
29552 crypto_completion_t complete;
29553-};
29554+} __no_const;
29555
29556 static void cryptd_queue_worker(struct work_struct *work);
29557
29558diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29559index e6defd8..c26a225 100644
29560--- a/drivers/acpi/apei/cper.c
29561+++ b/drivers/acpi/apei/cper.c
29562@@ -38,12 +38,12 @@
29563 */
29564 u64 cper_next_record_id(void)
29565 {
29566- static atomic64_t seq;
29567+ static atomic64_unchecked_t seq;
29568
29569- if (!atomic64_read(&seq))
29570- atomic64_set(&seq, ((u64)get_seconds()) << 32);
29571+ if (!atomic64_read_unchecked(&seq))
29572+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29573
29574- return atomic64_inc_return(&seq);
29575+ return atomic64_inc_return_unchecked(&seq);
29576 }
29577 EXPORT_SYMBOL_GPL(cper_next_record_id);
29578
29579diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29580index 7586544..636a2f0 100644
29581--- a/drivers/acpi/ec_sys.c
29582+++ b/drivers/acpi/ec_sys.c
29583@@ -12,6 +12,7 @@
29584 #include <linux/acpi.h>
29585 #include <linux/debugfs.h>
29586 #include <linux/module.h>
29587+#include <linux/uaccess.h>
29588 #include "internal.h"
29589
29590 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29591@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29592 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29593 */
29594 unsigned int size = EC_SPACE_SIZE;
29595- u8 *data = (u8 *) buf;
29596+ u8 data;
29597 loff_t init_off = *off;
29598 int err = 0;
29599
29600@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29601 size = count;
29602
29603 while (size) {
29604- err = ec_read(*off, &data[*off - init_off]);
29605+ err = ec_read(*off, &data);
29606 if (err)
29607 return err;
29608+ if (put_user(data, &buf[*off - init_off]))
29609+ return -EFAULT;
29610 *off += 1;
29611 size--;
29612 }
29613@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29614
29615 unsigned int size = count;
29616 loff_t init_off = *off;
29617- u8 *data = (u8 *) buf;
29618 int err = 0;
29619
29620 if (*off >= EC_SPACE_SIZE)
29621@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29622 }
29623
29624 while (size) {
29625- u8 byte_write = data[*off - init_off];
29626+ u8 byte_write;
29627+ if (get_user(byte_write, &buf[*off - init_off]))
29628+ return -EFAULT;
29629 err = ec_write(*off, byte_write);
29630 if (err)
29631 return err;
29632diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29633index 27adb09..ef98796b 100644
29634--- a/drivers/acpi/proc.c
29635+++ b/drivers/acpi/proc.c
29636@@ -362,16 +362,13 @@ acpi_system_write_wakeup_device(struct file *file,
29637 struct list_head *node, *next;
29638 char strbuf[5];
29639 char str[5] = "";
29640- unsigned int len = count;
29641
29642- if (len > 4)
29643- len = 4;
29644- if (len < 0)
29645- return -EFAULT;
29646+ if (count > 4)
29647+ count = 4;
29648
29649- if (copy_from_user(strbuf, buffer, len))
29650+ if (copy_from_user(strbuf, buffer, count))
29651 return -EFAULT;
29652- strbuf[len] = '\0';
29653+ strbuf[count] = '\0';
29654 sscanf(strbuf, "%s", str);
29655
29656 mutex_lock(&acpi_device_lock);
29657diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
29658index bd4e5dc..0497b66 100644
29659--- a/drivers/acpi/processor_driver.c
29660+++ b/drivers/acpi/processor_driver.c
29661@@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
29662 return 0;
29663 #endif
29664
29665- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
29666+ BUG_ON(pr->id >= nr_cpu_ids);
29667
29668 /*
29669 * Buggy BIOS check
29670diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
29671index c8ac4fe..631818e 100644
29672--- a/drivers/ata/libata-core.c
29673+++ b/drivers/ata/libata-core.c
29674@@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
29675 struct ata_port *ap;
29676 unsigned int tag;
29677
29678- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29679+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29680 ap = qc->ap;
29681
29682 qc->flags = 0;
29683@@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
29684 struct ata_port *ap;
29685 struct ata_link *link;
29686
29687- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29688+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
29689 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
29690 ap = qc->ap;
29691 link = qc->dev->link;
29692@@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29693 return;
29694
29695 spin_lock(&lock);
29696+ pax_open_kernel();
29697
29698 for (cur = ops->inherits; cur; cur = cur->inherits) {
29699 void **inherit = (void **)cur;
29700@@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
29701 if (IS_ERR(*pp))
29702 *pp = NULL;
29703
29704- ops->inherits = NULL;
29705+ *(struct ata_port_operations **)&ops->inherits = NULL;
29706
29707+ pax_close_kernel();
29708 spin_unlock(&lock);
29709 }
29710
29711diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
29712index 371fd2c..0836c78 100644
29713--- a/drivers/ata/pata_arasan_cf.c
29714+++ b/drivers/ata/pata_arasan_cf.c
29715@@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
29716 /* Handle platform specific quirks */
29717 if (pdata->quirk) {
29718 if (pdata->quirk & CF_BROKEN_PIO) {
29719- ap->ops->set_piomode = NULL;
29720+ pax_open_kernel();
29721+ *(void **)&ap->ops->set_piomode = NULL;
29722+ pax_close_kernel();
29723 ap->pio_mask = 0;
29724 }
29725 if (pdata->quirk & CF_BROKEN_MWDMA)
29726diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
29727index f9b983a..887b9d8 100644
29728--- a/drivers/atm/adummy.c
29729+++ b/drivers/atm/adummy.c
29730@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
29731 vcc->pop(vcc, skb);
29732 else
29733 dev_kfree_skb_any(skb);
29734- atomic_inc(&vcc->stats->tx);
29735+ atomic_inc_unchecked(&vcc->stats->tx);
29736
29737 return 0;
29738 }
29739diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
29740index ff7bb8a..568fc0b 100644
29741--- a/drivers/atm/ambassador.c
29742+++ b/drivers/atm/ambassador.c
29743@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
29744 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
29745
29746 // VC layer stats
29747- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29748+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29749
29750 // free the descriptor
29751 kfree (tx_descr);
29752@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29753 dump_skb ("<<<", vc, skb);
29754
29755 // VC layer stats
29756- atomic_inc(&atm_vcc->stats->rx);
29757+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29758 __net_timestamp(skb);
29759 // end of our responsibility
29760 atm_vcc->push (atm_vcc, skb);
29761@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
29762 } else {
29763 PRINTK (KERN_INFO, "dropped over-size frame");
29764 // should we count this?
29765- atomic_inc(&atm_vcc->stats->rx_drop);
29766+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29767 }
29768
29769 } else {
29770@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
29771 }
29772
29773 if (check_area (skb->data, skb->len)) {
29774- atomic_inc(&atm_vcc->stats->tx_err);
29775+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
29776 return -ENOMEM; // ?
29777 }
29778
29779diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
29780index b22d71c..d6e1049 100644
29781--- a/drivers/atm/atmtcp.c
29782+++ b/drivers/atm/atmtcp.c
29783@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29784 if (vcc->pop) vcc->pop(vcc,skb);
29785 else dev_kfree_skb(skb);
29786 if (dev_data) return 0;
29787- atomic_inc(&vcc->stats->tx_err);
29788+ atomic_inc_unchecked(&vcc->stats->tx_err);
29789 return -ENOLINK;
29790 }
29791 size = skb->len+sizeof(struct atmtcp_hdr);
29792@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29793 if (!new_skb) {
29794 if (vcc->pop) vcc->pop(vcc,skb);
29795 else dev_kfree_skb(skb);
29796- atomic_inc(&vcc->stats->tx_err);
29797+ atomic_inc_unchecked(&vcc->stats->tx_err);
29798 return -ENOBUFS;
29799 }
29800 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
29801@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
29802 if (vcc->pop) vcc->pop(vcc,skb);
29803 else dev_kfree_skb(skb);
29804 out_vcc->push(out_vcc,new_skb);
29805- atomic_inc(&vcc->stats->tx);
29806- atomic_inc(&out_vcc->stats->rx);
29807+ atomic_inc_unchecked(&vcc->stats->tx);
29808+ atomic_inc_unchecked(&out_vcc->stats->rx);
29809 return 0;
29810 }
29811
29812@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29813 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
29814 read_unlock(&vcc_sklist_lock);
29815 if (!out_vcc) {
29816- atomic_inc(&vcc->stats->tx_err);
29817+ atomic_inc_unchecked(&vcc->stats->tx_err);
29818 goto done;
29819 }
29820 skb_pull(skb,sizeof(struct atmtcp_hdr));
29821@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
29822 __net_timestamp(new_skb);
29823 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
29824 out_vcc->push(out_vcc,new_skb);
29825- atomic_inc(&vcc->stats->tx);
29826- atomic_inc(&out_vcc->stats->rx);
29827+ atomic_inc_unchecked(&vcc->stats->tx);
29828+ atomic_inc_unchecked(&out_vcc->stats->rx);
29829 done:
29830 if (vcc->pop) vcc->pop(vcc,skb);
29831 else dev_kfree_skb(skb);
29832diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
29833index 81e44f7..498ea36 100644
29834--- a/drivers/atm/eni.c
29835+++ b/drivers/atm/eni.c
29836@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
29837 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
29838 vcc->dev->number);
29839 length = 0;
29840- atomic_inc(&vcc->stats->rx_err);
29841+ atomic_inc_unchecked(&vcc->stats->rx_err);
29842 }
29843 else {
29844 length = ATM_CELL_SIZE-1; /* no HEC */
29845@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29846 size);
29847 }
29848 eff = length = 0;
29849- atomic_inc(&vcc->stats->rx_err);
29850+ atomic_inc_unchecked(&vcc->stats->rx_err);
29851 }
29852 else {
29853 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
29854@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
29855 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
29856 vcc->dev->number,vcc->vci,length,size << 2,descr);
29857 length = eff = 0;
29858- atomic_inc(&vcc->stats->rx_err);
29859+ atomic_inc_unchecked(&vcc->stats->rx_err);
29860 }
29861 }
29862 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
29863@@ -767,7 +767,7 @@ rx_dequeued++;
29864 vcc->push(vcc,skb);
29865 pushed++;
29866 }
29867- atomic_inc(&vcc->stats->rx);
29868+ atomic_inc_unchecked(&vcc->stats->rx);
29869 }
29870 wake_up(&eni_dev->rx_wait);
29871 }
29872@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
29873 PCI_DMA_TODEVICE);
29874 if (vcc->pop) vcc->pop(vcc,skb);
29875 else dev_kfree_skb_irq(skb);
29876- atomic_inc(&vcc->stats->tx);
29877+ atomic_inc_unchecked(&vcc->stats->tx);
29878 wake_up(&eni_dev->tx_wait);
29879 dma_complete++;
29880 }
29881diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
29882index 86fed1b..6dc4721 100644
29883--- a/drivers/atm/firestream.c
29884+++ b/drivers/atm/firestream.c
29885@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
29886 }
29887 }
29888
29889- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
29890+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
29891
29892 fs_dprintk (FS_DEBUG_TXMEM, "i");
29893 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
29894@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29895 #endif
29896 skb_put (skb, qe->p1 & 0xffff);
29897 ATM_SKB(skb)->vcc = atm_vcc;
29898- atomic_inc(&atm_vcc->stats->rx);
29899+ atomic_inc_unchecked(&atm_vcc->stats->rx);
29900 __net_timestamp(skb);
29901 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
29902 atm_vcc->push (atm_vcc, skb);
29903@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
29904 kfree (pe);
29905 }
29906 if (atm_vcc)
29907- atomic_inc(&atm_vcc->stats->rx_drop);
29908+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29909 break;
29910 case 0x1f: /* Reassembly abort: no buffers. */
29911 /* Silently increment error counter. */
29912 if (atm_vcc)
29913- atomic_inc(&atm_vcc->stats->rx_drop);
29914+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
29915 break;
29916 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
29917 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
29918diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
29919index 361f5ae..7fc552d 100644
29920--- a/drivers/atm/fore200e.c
29921+++ b/drivers/atm/fore200e.c
29922@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
29923 #endif
29924 /* check error condition */
29925 if (*entry->status & STATUS_ERROR)
29926- atomic_inc(&vcc->stats->tx_err);
29927+ atomic_inc_unchecked(&vcc->stats->tx_err);
29928 else
29929- atomic_inc(&vcc->stats->tx);
29930+ atomic_inc_unchecked(&vcc->stats->tx);
29931 }
29932 }
29933
29934@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29935 if (skb == NULL) {
29936 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
29937
29938- atomic_inc(&vcc->stats->rx_drop);
29939+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29940 return -ENOMEM;
29941 }
29942
29943@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
29944
29945 dev_kfree_skb_any(skb);
29946
29947- atomic_inc(&vcc->stats->rx_drop);
29948+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29949 return -ENOMEM;
29950 }
29951
29952 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29953
29954 vcc->push(vcc, skb);
29955- atomic_inc(&vcc->stats->rx);
29956+ atomic_inc_unchecked(&vcc->stats->rx);
29957
29958 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
29959
29960@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
29961 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
29962 fore200e->atm_dev->number,
29963 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
29964- atomic_inc(&vcc->stats->rx_err);
29965+ atomic_inc_unchecked(&vcc->stats->rx_err);
29966 }
29967 }
29968
29969@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
29970 goto retry_here;
29971 }
29972
29973- atomic_inc(&vcc->stats->tx_err);
29974+ atomic_inc_unchecked(&vcc->stats->tx_err);
29975
29976 fore200e->tx_sat++;
29977 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
29978diff --git a/drivers/atm/he.c b/drivers/atm/he.c
29979index b182c2f..1c6fa8a 100644
29980--- a/drivers/atm/he.c
29981+++ b/drivers/atm/he.c
29982@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29983
29984 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
29985 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
29986- atomic_inc(&vcc->stats->rx_drop);
29987+ atomic_inc_unchecked(&vcc->stats->rx_drop);
29988 goto return_host_buffers;
29989 }
29990
29991@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
29992 RBRQ_LEN_ERR(he_dev->rbrq_head)
29993 ? "LEN_ERR" : "",
29994 vcc->vpi, vcc->vci);
29995- atomic_inc(&vcc->stats->rx_err);
29996+ atomic_inc_unchecked(&vcc->stats->rx_err);
29997 goto return_host_buffers;
29998 }
29999
30000@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30001 vcc->push(vcc, skb);
30002 spin_lock(&he_dev->global_lock);
30003
30004- atomic_inc(&vcc->stats->rx);
30005+ atomic_inc_unchecked(&vcc->stats->rx);
30006
30007 return_host_buffers:
30008 ++pdus_assembled;
30009@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30010 tpd->vcc->pop(tpd->vcc, tpd->skb);
30011 else
30012 dev_kfree_skb_any(tpd->skb);
30013- atomic_inc(&tpd->vcc->stats->tx_err);
30014+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30015 }
30016 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30017 return;
30018@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30019 vcc->pop(vcc, skb);
30020 else
30021 dev_kfree_skb_any(skb);
30022- atomic_inc(&vcc->stats->tx_err);
30023+ atomic_inc_unchecked(&vcc->stats->tx_err);
30024 return -EINVAL;
30025 }
30026
30027@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30028 vcc->pop(vcc, skb);
30029 else
30030 dev_kfree_skb_any(skb);
30031- atomic_inc(&vcc->stats->tx_err);
30032+ atomic_inc_unchecked(&vcc->stats->tx_err);
30033 return -EINVAL;
30034 }
30035 #endif
30036@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30037 vcc->pop(vcc, skb);
30038 else
30039 dev_kfree_skb_any(skb);
30040- atomic_inc(&vcc->stats->tx_err);
30041+ atomic_inc_unchecked(&vcc->stats->tx_err);
30042 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30043 return -ENOMEM;
30044 }
30045@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30046 vcc->pop(vcc, skb);
30047 else
30048 dev_kfree_skb_any(skb);
30049- atomic_inc(&vcc->stats->tx_err);
30050+ atomic_inc_unchecked(&vcc->stats->tx_err);
30051 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30052 return -ENOMEM;
30053 }
30054@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30055 __enqueue_tpd(he_dev, tpd, cid);
30056 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30057
30058- atomic_inc(&vcc->stats->tx);
30059+ atomic_inc_unchecked(&vcc->stats->tx);
30060
30061 return 0;
30062 }
30063diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30064index 7d01c2a..4e3ac01 100644
30065--- a/drivers/atm/horizon.c
30066+++ b/drivers/atm/horizon.c
30067@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30068 {
30069 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30070 // VC layer stats
30071- atomic_inc(&vcc->stats->rx);
30072+ atomic_inc_unchecked(&vcc->stats->rx);
30073 __net_timestamp(skb);
30074 // end of our responsibility
30075 vcc->push (vcc, skb);
30076@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30077 dev->tx_iovec = NULL;
30078
30079 // VC layer stats
30080- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30081+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30082
30083 // free the skb
30084 hrz_kfree_skb (skb);
30085diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30086index 8974bd2..b856f85 100644
30087--- a/drivers/atm/idt77252.c
30088+++ b/drivers/atm/idt77252.c
30089@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30090 else
30091 dev_kfree_skb(skb);
30092
30093- atomic_inc(&vcc->stats->tx);
30094+ atomic_inc_unchecked(&vcc->stats->tx);
30095 }
30096
30097 atomic_dec(&scq->used);
30098@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30099 if ((sb = dev_alloc_skb(64)) == NULL) {
30100 printk("%s: Can't allocate buffers for aal0.\n",
30101 card->name);
30102- atomic_add(i, &vcc->stats->rx_drop);
30103+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30104 break;
30105 }
30106 if (!atm_charge(vcc, sb->truesize)) {
30107 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30108 card->name);
30109- atomic_add(i - 1, &vcc->stats->rx_drop);
30110+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30111 dev_kfree_skb(sb);
30112 break;
30113 }
30114@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30115 ATM_SKB(sb)->vcc = vcc;
30116 __net_timestamp(sb);
30117 vcc->push(vcc, sb);
30118- atomic_inc(&vcc->stats->rx);
30119+ atomic_inc_unchecked(&vcc->stats->rx);
30120
30121 cell += ATM_CELL_PAYLOAD;
30122 }
30123@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30124 "(CDC: %08x)\n",
30125 card->name, len, rpp->len, readl(SAR_REG_CDC));
30126 recycle_rx_pool_skb(card, rpp);
30127- atomic_inc(&vcc->stats->rx_err);
30128+ atomic_inc_unchecked(&vcc->stats->rx_err);
30129 return;
30130 }
30131 if (stat & SAR_RSQE_CRC) {
30132 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30133 recycle_rx_pool_skb(card, rpp);
30134- atomic_inc(&vcc->stats->rx_err);
30135+ atomic_inc_unchecked(&vcc->stats->rx_err);
30136 return;
30137 }
30138 if (skb_queue_len(&rpp->queue) > 1) {
30139@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30140 RXPRINTK("%s: Can't alloc RX skb.\n",
30141 card->name);
30142 recycle_rx_pool_skb(card, rpp);
30143- atomic_inc(&vcc->stats->rx_err);
30144+ atomic_inc_unchecked(&vcc->stats->rx_err);
30145 return;
30146 }
30147 if (!atm_charge(vcc, skb->truesize)) {
30148@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30149 __net_timestamp(skb);
30150
30151 vcc->push(vcc, skb);
30152- atomic_inc(&vcc->stats->rx);
30153+ atomic_inc_unchecked(&vcc->stats->rx);
30154
30155 return;
30156 }
30157@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30158 __net_timestamp(skb);
30159
30160 vcc->push(vcc, skb);
30161- atomic_inc(&vcc->stats->rx);
30162+ atomic_inc_unchecked(&vcc->stats->rx);
30163
30164 if (skb->truesize > SAR_FB_SIZE_3)
30165 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30166@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30167 if (vcc->qos.aal != ATM_AAL0) {
30168 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30169 card->name, vpi, vci);
30170- atomic_inc(&vcc->stats->rx_drop);
30171+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30172 goto drop;
30173 }
30174
30175 if ((sb = dev_alloc_skb(64)) == NULL) {
30176 printk("%s: Can't allocate buffers for AAL0.\n",
30177 card->name);
30178- atomic_inc(&vcc->stats->rx_err);
30179+ atomic_inc_unchecked(&vcc->stats->rx_err);
30180 goto drop;
30181 }
30182
30183@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30184 ATM_SKB(sb)->vcc = vcc;
30185 __net_timestamp(sb);
30186 vcc->push(vcc, sb);
30187- atomic_inc(&vcc->stats->rx);
30188+ atomic_inc_unchecked(&vcc->stats->rx);
30189
30190 drop:
30191 skb_pull(queue, 64);
30192@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30193
30194 if (vc == NULL) {
30195 printk("%s: NULL connection in send().\n", card->name);
30196- atomic_inc(&vcc->stats->tx_err);
30197+ atomic_inc_unchecked(&vcc->stats->tx_err);
30198 dev_kfree_skb(skb);
30199 return -EINVAL;
30200 }
30201 if (!test_bit(VCF_TX, &vc->flags)) {
30202 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30203- atomic_inc(&vcc->stats->tx_err);
30204+ atomic_inc_unchecked(&vcc->stats->tx_err);
30205 dev_kfree_skb(skb);
30206 return -EINVAL;
30207 }
30208@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30209 break;
30210 default:
30211 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30212- atomic_inc(&vcc->stats->tx_err);
30213+ atomic_inc_unchecked(&vcc->stats->tx_err);
30214 dev_kfree_skb(skb);
30215 return -EINVAL;
30216 }
30217
30218 if (skb_shinfo(skb)->nr_frags != 0) {
30219 printk("%s: No scatter-gather yet.\n", card->name);
30220- atomic_inc(&vcc->stats->tx_err);
30221+ atomic_inc_unchecked(&vcc->stats->tx_err);
30222 dev_kfree_skb(skb);
30223 return -EINVAL;
30224 }
30225@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30226
30227 err = queue_skb(card, vc, skb, oam);
30228 if (err) {
30229- atomic_inc(&vcc->stats->tx_err);
30230+ atomic_inc_unchecked(&vcc->stats->tx_err);
30231 dev_kfree_skb(skb);
30232 return err;
30233 }
30234@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30235 skb = dev_alloc_skb(64);
30236 if (!skb) {
30237 printk("%s: Out of memory in send_oam().\n", card->name);
30238- atomic_inc(&vcc->stats->tx_err);
30239+ atomic_inc_unchecked(&vcc->stats->tx_err);
30240 return -ENOMEM;
30241 }
30242 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30243diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30244index 96cce6d..62c3ec5 100644
30245--- a/drivers/atm/iphase.c
30246+++ b/drivers/atm/iphase.c
30247@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30248 status = (u_short) (buf_desc_ptr->desc_mode);
30249 if (status & (RX_CER | RX_PTE | RX_OFL))
30250 {
30251- atomic_inc(&vcc->stats->rx_err);
30252+ atomic_inc_unchecked(&vcc->stats->rx_err);
30253 IF_ERR(printk("IA: bad packet, dropping it");)
30254 if (status & RX_CER) {
30255 IF_ERR(printk(" cause: packet CRC error\n");)
30256@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30257 len = dma_addr - buf_addr;
30258 if (len > iadev->rx_buf_sz) {
30259 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30260- atomic_inc(&vcc->stats->rx_err);
30261+ atomic_inc_unchecked(&vcc->stats->rx_err);
30262 goto out_free_desc;
30263 }
30264
30265@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30266 ia_vcc = INPH_IA_VCC(vcc);
30267 if (ia_vcc == NULL)
30268 {
30269- atomic_inc(&vcc->stats->rx_err);
30270+ atomic_inc_unchecked(&vcc->stats->rx_err);
30271 atm_return(vcc, skb->truesize);
30272 dev_kfree_skb_any(skb);
30273 goto INCR_DLE;
30274@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30275 if ((length > iadev->rx_buf_sz) || (length >
30276 (skb->len - sizeof(struct cpcs_trailer))))
30277 {
30278- atomic_inc(&vcc->stats->rx_err);
30279+ atomic_inc_unchecked(&vcc->stats->rx_err);
30280 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30281 length, skb->len);)
30282 atm_return(vcc, skb->truesize);
30283@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30284
30285 IF_RX(printk("rx_dle_intr: skb push");)
30286 vcc->push(vcc,skb);
30287- atomic_inc(&vcc->stats->rx);
30288+ atomic_inc_unchecked(&vcc->stats->rx);
30289 iadev->rx_pkt_cnt++;
30290 }
30291 INCR_DLE:
30292@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30293 {
30294 struct k_sonet_stats *stats;
30295 stats = &PRIV(_ia_dev[board])->sonet_stats;
30296- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30297- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30298- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30299- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30300- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30301- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30302- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30303- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30304- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30305+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30306+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30307+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30308+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30309+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30310+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30311+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30312+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30313+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30314 }
30315 ia_cmds.status = 0;
30316 break;
30317@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30318 if ((desc == 0) || (desc > iadev->num_tx_desc))
30319 {
30320 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30321- atomic_inc(&vcc->stats->tx);
30322+ atomic_inc_unchecked(&vcc->stats->tx);
30323 if (vcc->pop)
30324 vcc->pop(vcc, skb);
30325 else
30326@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30327 ATM_DESC(skb) = vcc->vci;
30328 skb_queue_tail(&iadev->tx_dma_q, skb);
30329
30330- atomic_inc(&vcc->stats->tx);
30331+ atomic_inc_unchecked(&vcc->stats->tx);
30332 iadev->tx_pkt_cnt++;
30333 /* Increment transaction counter */
30334 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30335
30336 #if 0
30337 /* add flow control logic */
30338- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30339+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30340 if (iavcc->vc_desc_cnt > 10) {
30341 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30342 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30343diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30344index 68c7588..7036683 100644
30345--- a/drivers/atm/lanai.c
30346+++ b/drivers/atm/lanai.c
30347@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30348 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30349 lanai_endtx(lanai, lvcc);
30350 lanai_free_skb(lvcc->tx.atmvcc, skb);
30351- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30352+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30353 }
30354
30355 /* Try to fill the buffer - don't call unless there is backlog */
30356@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30357 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30358 __net_timestamp(skb);
30359 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30360- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30361+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30362 out:
30363 lvcc->rx.buf.ptr = end;
30364 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30365@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30366 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30367 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30368 lanai->stats.service_rxnotaal5++;
30369- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30370+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30371 return 0;
30372 }
30373 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30374@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30375 int bytes;
30376 read_unlock(&vcc_sklist_lock);
30377 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30378- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30379+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30380 lvcc->stats.x.aal5.service_trash++;
30381 bytes = (SERVICE_GET_END(s) * 16) -
30382 (((unsigned long) lvcc->rx.buf.ptr) -
30383@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30384 }
30385 if (s & SERVICE_STREAM) {
30386 read_unlock(&vcc_sklist_lock);
30387- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30388+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30389 lvcc->stats.x.aal5.service_stream++;
30390 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30391 "PDU on VCI %d!\n", lanai->number, vci);
30392@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30393 return 0;
30394 }
30395 DPRINTK("got rx crc error on vci %d\n", vci);
30396- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30397+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30398 lvcc->stats.x.aal5.service_rxcrc++;
30399 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30400 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30401diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30402index 1c70c45..300718d 100644
30403--- a/drivers/atm/nicstar.c
30404+++ b/drivers/atm/nicstar.c
30405@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30406 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30407 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30408 card->index);
30409- atomic_inc(&vcc->stats->tx_err);
30410+ atomic_inc_unchecked(&vcc->stats->tx_err);
30411 dev_kfree_skb_any(skb);
30412 return -EINVAL;
30413 }
30414@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30415 if (!vc->tx) {
30416 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30417 card->index);
30418- atomic_inc(&vcc->stats->tx_err);
30419+ atomic_inc_unchecked(&vcc->stats->tx_err);
30420 dev_kfree_skb_any(skb);
30421 return -EINVAL;
30422 }
30423@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30424 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30425 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30426 card->index);
30427- atomic_inc(&vcc->stats->tx_err);
30428+ atomic_inc_unchecked(&vcc->stats->tx_err);
30429 dev_kfree_skb_any(skb);
30430 return -EINVAL;
30431 }
30432
30433 if (skb_shinfo(skb)->nr_frags != 0) {
30434 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30435- atomic_inc(&vcc->stats->tx_err);
30436+ atomic_inc_unchecked(&vcc->stats->tx_err);
30437 dev_kfree_skb_any(skb);
30438 return -EINVAL;
30439 }
30440@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30441 }
30442
30443 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30444- atomic_inc(&vcc->stats->tx_err);
30445+ atomic_inc_unchecked(&vcc->stats->tx_err);
30446 dev_kfree_skb_any(skb);
30447 return -EIO;
30448 }
30449- atomic_inc(&vcc->stats->tx);
30450+ atomic_inc_unchecked(&vcc->stats->tx);
30451
30452 return 0;
30453 }
30454@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30455 printk
30456 ("nicstar%d: Can't allocate buffers for aal0.\n",
30457 card->index);
30458- atomic_add(i, &vcc->stats->rx_drop);
30459+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30460 break;
30461 }
30462 if (!atm_charge(vcc, sb->truesize)) {
30463 RXPRINTK
30464 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30465 card->index);
30466- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30467+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30468 dev_kfree_skb_any(sb);
30469 break;
30470 }
30471@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30472 ATM_SKB(sb)->vcc = vcc;
30473 __net_timestamp(sb);
30474 vcc->push(vcc, sb);
30475- atomic_inc(&vcc->stats->rx);
30476+ atomic_inc_unchecked(&vcc->stats->rx);
30477 cell += ATM_CELL_PAYLOAD;
30478 }
30479
30480@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30481 if (iovb == NULL) {
30482 printk("nicstar%d: Out of iovec buffers.\n",
30483 card->index);
30484- atomic_inc(&vcc->stats->rx_drop);
30485+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30486 recycle_rx_buf(card, skb);
30487 return;
30488 }
30489@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30490 small or large buffer itself. */
30491 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30492 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30493- atomic_inc(&vcc->stats->rx_err);
30494+ atomic_inc_unchecked(&vcc->stats->rx_err);
30495 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30496 NS_MAX_IOVECS);
30497 NS_PRV_IOVCNT(iovb) = 0;
30498@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30499 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30500 card->index);
30501 which_list(card, skb);
30502- atomic_inc(&vcc->stats->rx_err);
30503+ atomic_inc_unchecked(&vcc->stats->rx_err);
30504 recycle_rx_buf(card, skb);
30505 vc->rx_iov = NULL;
30506 recycle_iov_buf(card, iovb);
30507@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30508 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30509 card->index);
30510 which_list(card, skb);
30511- atomic_inc(&vcc->stats->rx_err);
30512+ atomic_inc_unchecked(&vcc->stats->rx_err);
30513 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30514 NS_PRV_IOVCNT(iovb));
30515 vc->rx_iov = NULL;
30516@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30517 printk(" - PDU size mismatch.\n");
30518 else
30519 printk(".\n");
30520- atomic_inc(&vcc->stats->rx_err);
30521+ atomic_inc_unchecked(&vcc->stats->rx_err);
30522 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30523 NS_PRV_IOVCNT(iovb));
30524 vc->rx_iov = NULL;
30525@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30526 /* skb points to a small buffer */
30527 if (!atm_charge(vcc, skb->truesize)) {
30528 push_rxbufs(card, skb);
30529- atomic_inc(&vcc->stats->rx_drop);
30530+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30531 } else {
30532 skb_put(skb, len);
30533 dequeue_sm_buf(card, skb);
30534@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30535 ATM_SKB(skb)->vcc = vcc;
30536 __net_timestamp(skb);
30537 vcc->push(vcc, skb);
30538- atomic_inc(&vcc->stats->rx);
30539+ atomic_inc_unchecked(&vcc->stats->rx);
30540 }
30541 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30542 struct sk_buff *sb;
30543@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30544 if (len <= NS_SMBUFSIZE) {
30545 if (!atm_charge(vcc, sb->truesize)) {
30546 push_rxbufs(card, sb);
30547- atomic_inc(&vcc->stats->rx_drop);
30548+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30549 } else {
30550 skb_put(sb, len);
30551 dequeue_sm_buf(card, sb);
30552@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30553 ATM_SKB(sb)->vcc = vcc;
30554 __net_timestamp(sb);
30555 vcc->push(vcc, sb);
30556- atomic_inc(&vcc->stats->rx);
30557+ atomic_inc_unchecked(&vcc->stats->rx);
30558 }
30559
30560 push_rxbufs(card, skb);
30561@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30562
30563 if (!atm_charge(vcc, skb->truesize)) {
30564 push_rxbufs(card, skb);
30565- atomic_inc(&vcc->stats->rx_drop);
30566+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30567 } else {
30568 dequeue_lg_buf(card, skb);
30569 #ifdef NS_USE_DESTRUCTORS
30570@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30571 ATM_SKB(skb)->vcc = vcc;
30572 __net_timestamp(skb);
30573 vcc->push(vcc, skb);
30574- atomic_inc(&vcc->stats->rx);
30575+ atomic_inc_unchecked(&vcc->stats->rx);
30576 }
30577
30578 push_rxbufs(card, sb);
30579@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30580 printk
30581 ("nicstar%d: Out of huge buffers.\n",
30582 card->index);
30583- atomic_inc(&vcc->stats->rx_drop);
30584+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30585 recycle_iovec_rx_bufs(card,
30586 (struct iovec *)
30587 iovb->data,
30588@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30589 card->hbpool.count++;
30590 } else
30591 dev_kfree_skb_any(hb);
30592- atomic_inc(&vcc->stats->rx_drop);
30593+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30594 } else {
30595 /* Copy the small buffer to the huge buffer */
30596 sb = (struct sk_buff *)iov->iov_base;
30597@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30598 #endif /* NS_USE_DESTRUCTORS */
30599 __net_timestamp(hb);
30600 vcc->push(vcc, hb);
30601- atomic_inc(&vcc->stats->rx);
30602+ atomic_inc_unchecked(&vcc->stats->rx);
30603 }
30604 }
30605
30606diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30607index 1853a45..cf2426d 100644
30608--- a/drivers/atm/solos-pci.c
30609+++ b/drivers/atm/solos-pci.c
30610@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30611 }
30612 atm_charge(vcc, skb->truesize);
30613 vcc->push(vcc, skb);
30614- atomic_inc(&vcc->stats->rx);
30615+ atomic_inc_unchecked(&vcc->stats->rx);
30616 break;
30617
30618 case PKT_STATUS:
30619@@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30620 vcc = SKB_CB(oldskb)->vcc;
30621
30622 if (vcc) {
30623- atomic_inc(&vcc->stats->tx);
30624+ atomic_inc_unchecked(&vcc->stats->tx);
30625 solos_pop(vcc, oldskb);
30626 } else
30627 dev_kfree_skb_irq(oldskb);
30628diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30629index 0215934..ce9f5b1 100644
30630--- a/drivers/atm/suni.c
30631+++ b/drivers/atm/suni.c
30632@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30633
30634
30635 #define ADD_LIMITED(s,v) \
30636- atomic_add((v),&stats->s); \
30637- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30638+ atomic_add_unchecked((v),&stats->s); \
30639+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30640
30641
30642 static void suni_hz(unsigned long from_timer)
30643diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30644index 5120a96..e2572bd 100644
30645--- a/drivers/atm/uPD98402.c
30646+++ b/drivers/atm/uPD98402.c
30647@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30648 struct sonet_stats tmp;
30649 int error = 0;
30650
30651- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30652+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30653 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30654 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30655 if (zero && !error) {
30656@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30657
30658
30659 #define ADD_LIMITED(s,v) \
30660- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30661- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30662- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30663+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30664+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30665+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30666
30667
30668 static void stat_event(struct atm_dev *dev)
30669@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
30670 if (reason & uPD98402_INT_PFM) stat_event(dev);
30671 if (reason & uPD98402_INT_PCO) {
30672 (void) GET(PCOCR); /* clear interrupt cause */
30673- atomic_add(GET(HECCT),
30674+ atomic_add_unchecked(GET(HECCT),
30675 &PRIV(dev)->sonet_stats.uncorr_hcs);
30676 }
30677 if ((reason & uPD98402_INT_RFO) &&
30678@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
30679 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
30680 uPD98402_INT_LOS),PIMR); /* enable them */
30681 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
30682- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30683- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
30684- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
30685+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
30686+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
30687+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
30688 return 0;
30689 }
30690
30691diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
30692index abe4e20..83c4727 100644
30693--- a/drivers/atm/zatm.c
30694+++ b/drivers/atm/zatm.c
30695@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30696 }
30697 if (!size) {
30698 dev_kfree_skb_irq(skb);
30699- if (vcc) atomic_inc(&vcc->stats->rx_err);
30700+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
30701 continue;
30702 }
30703 if (!atm_charge(vcc,skb->truesize)) {
30704@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
30705 skb->len = size;
30706 ATM_SKB(skb)->vcc = vcc;
30707 vcc->push(vcc,skb);
30708- atomic_inc(&vcc->stats->rx);
30709+ atomic_inc_unchecked(&vcc->stats->rx);
30710 }
30711 zout(pos & 0xffff,MTA(mbx));
30712 #if 0 /* probably a stupid idea */
30713@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
30714 skb_queue_head(&zatm_vcc->backlog,skb);
30715 break;
30716 }
30717- atomic_inc(&vcc->stats->tx);
30718+ atomic_inc_unchecked(&vcc->stats->tx);
30719 wake_up(&zatm_vcc->tx_wait);
30720 }
30721
30722diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
30723index 147d1a4..d0fd4b0 100644
30724--- a/drivers/base/devtmpfs.c
30725+++ b/drivers/base/devtmpfs.c
30726@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
30727 if (!thread)
30728 return 0;
30729
30730- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
30731+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
30732 if (err)
30733 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
30734 else
30735diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
30736index e6ee5e8..98ad7fc 100644
30737--- a/drivers/base/power/wakeup.c
30738+++ b/drivers/base/power/wakeup.c
30739@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
30740 * They need to be modified together atomically, so it's better to use one
30741 * atomic variable to hold them both.
30742 */
30743-static atomic_t combined_event_count = ATOMIC_INIT(0);
30744+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
30745
30746 #define IN_PROGRESS_BITS (sizeof(int) * 4)
30747 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
30748
30749 static void split_counters(unsigned int *cnt, unsigned int *inpr)
30750 {
30751- unsigned int comb = atomic_read(&combined_event_count);
30752+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
30753
30754 *cnt = (comb >> IN_PROGRESS_BITS);
30755 *inpr = comb & MAX_IN_PROGRESS;
30756@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
30757 ws->start_prevent_time = ws->last_time;
30758
30759 /* Increment the counter of events in progress. */
30760- cec = atomic_inc_return(&combined_event_count);
30761+ cec = atomic_inc_return_unchecked(&combined_event_count);
30762
30763 trace_wakeup_source_activate(ws->name, cec);
30764 }
30765@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
30766 * Increment the counter of registered wakeup events and decrement the
30767 * couter of wakeup events in progress simultaneously.
30768 */
30769- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
30770+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
30771 trace_wakeup_source_deactivate(ws->name, cec);
30772
30773 split_counters(&cnt, &inpr);
30774diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
30775index ca83f96..69d4ea9 100644
30776--- a/drivers/block/cciss.c
30777+++ b/drivers/block/cciss.c
30778@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
30779 int err;
30780 u32 cp;
30781
30782+ memset(&arg64, 0, sizeof(arg64));
30783+
30784 err = 0;
30785 err |=
30786 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
30787@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
30788 while (!list_empty(&h->reqQ)) {
30789 c = list_entry(h->reqQ.next, CommandList_struct, list);
30790 /* can't do anything if fifo is full */
30791- if ((h->access.fifo_full(h))) {
30792+ if ((h->access->fifo_full(h))) {
30793 dev_warn(&h->pdev->dev, "fifo full\n");
30794 break;
30795 }
30796@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
30797 h->Qdepth--;
30798
30799 /* Tell the controller execute command */
30800- h->access.submit_command(h, c);
30801+ h->access->submit_command(h, c);
30802
30803 /* Put job onto the completed Q */
30804 addQ(&h->cmpQ, c);
30805@@ -3443,17 +3445,17 @@ startio:
30806
30807 static inline unsigned long get_next_completion(ctlr_info_t *h)
30808 {
30809- return h->access.command_completed(h);
30810+ return h->access->command_completed(h);
30811 }
30812
30813 static inline int interrupt_pending(ctlr_info_t *h)
30814 {
30815- return h->access.intr_pending(h);
30816+ return h->access->intr_pending(h);
30817 }
30818
30819 static inline long interrupt_not_for_us(ctlr_info_t *h)
30820 {
30821- return ((h->access.intr_pending(h) == 0) ||
30822+ return ((h->access->intr_pending(h) == 0) ||
30823 (h->interrupts_enabled == 0));
30824 }
30825
30826@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
30827 u32 a;
30828
30829 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
30830- return h->access.command_completed(h);
30831+ return h->access->command_completed(h);
30832
30833 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
30834 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
30835@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
30836 trans_support & CFGTBL_Trans_use_short_tags);
30837
30838 /* Change the access methods to the performant access methods */
30839- h->access = SA5_performant_access;
30840+ h->access = &SA5_performant_access;
30841 h->transMethod = CFGTBL_Trans_Performant;
30842
30843 return;
30844@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
30845 if (prod_index < 0)
30846 return -ENODEV;
30847 h->product_name = products[prod_index].product_name;
30848- h->access = *(products[prod_index].access);
30849+ h->access = products[prod_index].access;
30850
30851 if (cciss_board_disabled(h)) {
30852 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
30853@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
30854 }
30855
30856 /* make sure the board interrupts are off */
30857- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30858+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30859 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
30860 if (rc)
30861 goto clean2;
30862@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
30863 * fake ones to scoop up any residual completions.
30864 */
30865 spin_lock_irqsave(&h->lock, flags);
30866- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30867+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30868 spin_unlock_irqrestore(&h->lock, flags);
30869 free_irq(h->intr[h->intr_mode], h);
30870 rc = cciss_request_irq(h, cciss_msix_discard_completions,
30871@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
30872 dev_info(&h->pdev->dev, "Board READY.\n");
30873 dev_info(&h->pdev->dev,
30874 "Waiting for stale completions to drain.\n");
30875- h->access.set_intr_mask(h, CCISS_INTR_ON);
30876+ h->access->set_intr_mask(h, CCISS_INTR_ON);
30877 msleep(10000);
30878- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30879+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30880
30881 rc = controller_reset_failed(h->cfgtable);
30882 if (rc)
30883@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
30884 cciss_scsi_setup(h);
30885
30886 /* Turn the interrupts on so we can service requests */
30887- h->access.set_intr_mask(h, CCISS_INTR_ON);
30888+ h->access->set_intr_mask(h, CCISS_INTR_ON);
30889
30890 /* Get the firmware version */
30891 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
30892@@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
30893 kfree(flush_buf);
30894 if (return_code != IO_OK)
30895 dev_warn(&h->pdev->dev, "Error flushing cache\n");
30896- h->access.set_intr_mask(h, CCISS_INTR_OFF);
30897+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
30898 free_irq(h->intr[h->intr_mode], h);
30899 }
30900
30901diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
30902index 7fda30e..eb5dfe0 100644
30903--- a/drivers/block/cciss.h
30904+++ b/drivers/block/cciss.h
30905@@ -101,7 +101,7 @@ struct ctlr_info
30906 /* information about each logical volume */
30907 drive_info_struct *drv[CISS_MAX_LUN];
30908
30909- struct access_method access;
30910+ struct access_method *access;
30911
30912 /* queue and queue Info */
30913 struct list_head reqQ;
30914diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
30915index 9125bbe..eede5c8 100644
30916--- a/drivers/block/cpqarray.c
30917+++ b/drivers/block/cpqarray.c
30918@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30919 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
30920 goto Enomem4;
30921 }
30922- hba[i]->access.set_intr_mask(hba[i], 0);
30923+ hba[i]->access->set_intr_mask(hba[i], 0);
30924 if (request_irq(hba[i]->intr, do_ida_intr,
30925 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
30926 {
30927@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
30928 add_timer(&hba[i]->timer);
30929
30930 /* Enable IRQ now that spinlock and rate limit timer are set up */
30931- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30932+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
30933
30934 for(j=0; j<NWD; j++) {
30935 struct gendisk *disk = ida_gendisk[i][j];
30936@@ -694,7 +694,7 @@ DBGINFO(
30937 for(i=0; i<NR_PRODUCTS; i++) {
30938 if (board_id == products[i].board_id) {
30939 c->product_name = products[i].product_name;
30940- c->access = *(products[i].access);
30941+ c->access = products[i].access;
30942 break;
30943 }
30944 }
30945@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
30946 hba[ctlr]->intr = intr;
30947 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
30948 hba[ctlr]->product_name = products[j].product_name;
30949- hba[ctlr]->access = *(products[j].access);
30950+ hba[ctlr]->access = products[j].access;
30951 hba[ctlr]->ctlr = ctlr;
30952 hba[ctlr]->board_id = board_id;
30953 hba[ctlr]->pci_dev = NULL; /* not PCI */
30954@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
30955
30956 while((c = h->reqQ) != NULL) {
30957 /* Can't do anything if we're busy */
30958- if (h->access.fifo_full(h) == 0)
30959+ if (h->access->fifo_full(h) == 0)
30960 return;
30961
30962 /* Get the first entry from the request Q */
30963@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
30964 h->Qdepth--;
30965
30966 /* Tell the controller to do our bidding */
30967- h->access.submit_command(h, c);
30968+ h->access->submit_command(h, c);
30969
30970 /* Get onto the completion Q */
30971 addQ(&h->cmpQ, c);
30972@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30973 unsigned long flags;
30974 __u32 a,a1;
30975
30976- istat = h->access.intr_pending(h);
30977+ istat = h->access->intr_pending(h);
30978 /* Is this interrupt for us? */
30979 if (istat == 0)
30980 return IRQ_NONE;
30981@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
30982 */
30983 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
30984 if (istat & FIFO_NOT_EMPTY) {
30985- while((a = h->access.command_completed(h))) {
30986+ while((a = h->access->command_completed(h))) {
30987 a1 = a; a &= ~3;
30988 if ((c = h->cmpQ) == NULL)
30989 {
30990@@ -1449,11 +1449,11 @@ static int sendcmd(
30991 /*
30992 * Disable interrupt
30993 */
30994- info_p->access.set_intr_mask(info_p, 0);
30995+ info_p->access->set_intr_mask(info_p, 0);
30996 /* Make sure there is room in the command FIFO */
30997 /* Actually it should be completely empty at this time. */
30998 for (i = 200000; i > 0; i--) {
30999- temp = info_p->access.fifo_full(info_p);
31000+ temp = info_p->access->fifo_full(info_p);
31001 if (temp != 0) {
31002 break;
31003 }
31004@@ -1466,7 +1466,7 @@ DBG(
31005 /*
31006 * Send the cmd
31007 */
31008- info_p->access.submit_command(info_p, c);
31009+ info_p->access->submit_command(info_p, c);
31010 complete = pollcomplete(ctlr);
31011
31012 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31013@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31014 * we check the new geometry. Then turn interrupts back on when
31015 * we're done.
31016 */
31017- host->access.set_intr_mask(host, 0);
31018+ host->access->set_intr_mask(host, 0);
31019 getgeometry(ctlr);
31020- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31021+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31022
31023 for(i=0; i<NWD; i++) {
31024 struct gendisk *disk = ida_gendisk[ctlr][i];
31025@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31026 /* Wait (up to 2 seconds) for a command to complete */
31027
31028 for (i = 200000; i > 0; i--) {
31029- done = hba[ctlr]->access.command_completed(hba[ctlr]);
31030+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
31031 if (done == 0) {
31032 udelay(10); /* a short fixed delay */
31033 } else
31034diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31035index be73e9d..7fbf140 100644
31036--- a/drivers/block/cpqarray.h
31037+++ b/drivers/block/cpqarray.h
31038@@ -99,7 +99,7 @@ struct ctlr_info {
31039 drv_info_t drv[NWD];
31040 struct proc_dir_entry *proc;
31041
31042- struct access_method access;
31043+ struct access_method *access;
31044
31045 cmdlist_t *reqQ;
31046 cmdlist_t *cmpQ;
31047diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31048index b953cc7..e3dc580 100644
31049--- a/drivers/block/drbd/drbd_int.h
31050+++ b/drivers/block/drbd/drbd_int.h
31051@@ -735,7 +735,7 @@ struct drbd_request;
31052 struct drbd_epoch {
31053 struct list_head list;
31054 unsigned int barrier_nr;
31055- atomic_t epoch_size; /* increased on every request added. */
31056+ atomic_unchecked_t epoch_size; /* increased on every request added. */
31057 atomic_t active; /* increased on every req. added, and dec on every finished. */
31058 unsigned long flags;
31059 };
31060@@ -1116,7 +1116,7 @@ struct drbd_conf {
31061 void *int_dig_in;
31062 void *int_dig_vv;
31063 wait_queue_head_t seq_wait;
31064- atomic_t packet_seq;
31065+ atomic_unchecked_t packet_seq;
31066 unsigned int peer_seq;
31067 spinlock_t peer_seq_lock;
31068 unsigned int minor;
31069@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31070
31071 static inline void drbd_tcp_cork(struct socket *sock)
31072 {
31073- int __user val = 1;
31074+ int val = 1;
31075 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31076- (char __user *)&val, sizeof(val));
31077+ (char __force_user *)&val, sizeof(val));
31078 }
31079
31080 static inline void drbd_tcp_uncork(struct socket *sock)
31081 {
31082- int __user val = 0;
31083+ int val = 0;
31084 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31085- (char __user *)&val, sizeof(val));
31086+ (char __force_user *)&val, sizeof(val));
31087 }
31088
31089 static inline void drbd_tcp_nodelay(struct socket *sock)
31090 {
31091- int __user val = 1;
31092+ int val = 1;
31093 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31094- (char __user *)&val, sizeof(val));
31095+ (char __force_user *)&val, sizeof(val));
31096 }
31097
31098 static inline void drbd_tcp_quickack(struct socket *sock)
31099 {
31100- int __user val = 2;
31101+ int val = 2;
31102 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31103- (char __user *)&val, sizeof(val));
31104+ (char __force_user *)&val, sizeof(val));
31105 }
31106
31107 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31108diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31109index f55683a..2101b96 100644
31110--- a/drivers/block/drbd/drbd_main.c
31111+++ b/drivers/block/drbd/drbd_main.c
31112@@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31113 p.sector = sector;
31114 p.block_id = block_id;
31115 p.blksize = blksize;
31116- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31117+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31118
31119 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31120 return false;
31121@@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31122
31123 p.sector = cpu_to_be64(req->sector);
31124 p.block_id = (unsigned long)req;
31125- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31126+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31127
31128 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31129
31130@@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31131 atomic_set(&mdev->unacked_cnt, 0);
31132 atomic_set(&mdev->local_cnt, 0);
31133 atomic_set(&mdev->net_cnt, 0);
31134- atomic_set(&mdev->packet_seq, 0);
31135+ atomic_set_unchecked(&mdev->packet_seq, 0);
31136 atomic_set(&mdev->pp_in_use, 0);
31137 atomic_set(&mdev->pp_in_use_by_net, 0);
31138 atomic_set(&mdev->rs_sect_in, 0);
31139@@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31140 mdev->receiver.t_state);
31141
31142 /* no need to lock it, I'm the only thread alive */
31143- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31144- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31145+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31146+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31147 mdev->al_writ_cnt =
31148 mdev->bm_writ_cnt =
31149 mdev->read_cnt =
31150diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31151index edb490a..ecd69da 100644
31152--- a/drivers/block/drbd/drbd_nl.c
31153+++ b/drivers/block/drbd/drbd_nl.c
31154@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31155 module_put(THIS_MODULE);
31156 }
31157
31158-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31159+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31160
31161 static unsigned short *
31162 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31163@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31164 cn_reply->id.idx = CN_IDX_DRBD;
31165 cn_reply->id.val = CN_VAL_DRBD;
31166
31167- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31168+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31169 cn_reply->ack = 0; /* not used here. */
31170 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31171 (int)((char *)tl - (char *)reply->tag_list);
31172@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31173 cn_reply->id.idx = CN_IDX_DRBD;
31174 cn_reply->id.val = CN_VAL_DRBD;
31175
31176- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31177+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31178 cn_reply->ack = 0; /* not used here. */
31179 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31180 (int)((char *)tl - (char *)reply->tag_list);
31181@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31182 cn_reply->id.idx = CN_IDX_DRBD;
31183 cn_reply->id.val = CN_VAL_DRBD;
31184
31185- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31186+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31187 cn_reply->ack = 0; // not used here.
31188 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31189 (int)((char*)tl - (char*)reply->tag_list);
31190@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31191 cn_reply->id.idx = CN_IDX_DRBD;
31192 cn_reply->id.val = CN_VAL_DRBD;
31193
31194- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31195+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31196 cn_reply->ack = 0; /* not used here. */
31197 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31198 (int)((char *)tl - (char *)reply->tag_list);
31199diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31200index c74ca2d..860c819 100644
31201--- a/drivers/block/drbd/drbd_receiver.c
31202+++ b/drivers/block/drbd/drbd_receiver.c
31203@@ -898,7 +898,7 @@ retry:
31204 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31205 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31206
31207- atomic_set(&mdev->packet_seq, 0);
31208+ atomic_set_unchecked(&mdev->packet_seq, 0);
31209 mdev->peer_seq = 0;
31210
31211 if (drbd_send_protocol(mdev) == -1)
31212@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31213 do {
31214 next_epoch = NULL;
31215
31216- epoch_size = atomic_read(&epoch->epoch_size);
31217+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31218
31219 switch (ev & ~EV_CLEANUP) {
31220 case EV_PUT:
31221@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31222 rv = FE_DESTROYED;
31223 } else {
31224 epoch->flags = 0;
31225- atomic_set(&epoch->epoch_size, 0);
31226+ atomic_set_unchecked(&epoch->epoch_size, 0);
31227 /* atomic_set(&epoch->active, 0); is already zero */
31228 if (rv == FE_STILL_LIVE)
31229 rv = FE_RECYCLED;
31230@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31231 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31232 drbd_flush(mdev);
31233
31234- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31235+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31236 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31237 if (epoch)
31238 break;
31239 }
31240
31241 epoch = mdev->current_epoch;
31242- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31243+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31244
31245 D_ASSERT(atomic_read(&epoch->active) == 0);
31246 D_ASSERT(epoch->flags == 0);
31247@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31248 }
31249
31250 epoch->flags = 0;
31251- atomic_set(&epoch->epoch_size, 0);
31252+ atomic_set_unchecked(&epoch->epoch_size, 0);
31253 atomic_set(&epoch->active, 0);
31254
31255 spin_lock(&mdev->epoch_lock);
31256- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31257+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31258 list_add(&epoch->list, &mdev->current_epoch->list);
31259 mdev->current_epoch = epoch;
31260 mdev->epochs++;
31261@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31262 spin_unlock(&mdev->peer_seq_lock);
31263
31264 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31265- atomic_inc(&mdev->current_epoch->epoch_size);
31266+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31267 return drbd_drain_block(mdev, data_size);
31268 }
31269
31270@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31271
31272 spin_lock(&mdev->epoch_lock);
31273 e->epoch = mdev->current_epoch;
31274- atomic_inc(&e->epoch->epoch_size);
31275+ atomic_inc_unchecked(&e->epoch->epoch_size);
31276 atomic_inc(&e->epoch->active);
31277 spin_unlock(&mdev->epoch_lock);
31278
31279@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31280 D_ASSERT(list_empty(&mdev->done_ee));
31281
31282 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31283- atomic_set(&mdev->current_epoch->epoch_size, 0);
31284+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31285 D_ASSERT(list_empty(&mdev->current_epoch->list));
31286 }
31287
31288diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31289index 54046e5..7759c55 100644
31290--- a/drivers/block/loop.c
31291+++ b/drivers/block/loop.c
31292@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31293 mm_segment_t old_fs = get_fs();
31294
31295 set_fs(get_ds());
31296- bw = file->f_op->write(file, buf, len, &pos);
31297+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31298 set_fs(old_fs);
31299 if (likely(bw == len))
31300 return 0;
31301diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31302index d620b44..587561e 100644
31303--- a/drivers/cdrom/cdrom.c
31304+++ b/drivers/cdrom/cdrom.c
31305@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31306 ENSURE(reset, CDC_RESET);
31307 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31308 cdi->mc_flags = 0;
31309- cdo->n_minors = 0;
31310 cdi->options = CDO_USE_FFLAGS;
31311
31312 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31313@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31314 else
31315 cdi->cdda_method = CDDA_OLD;
31316
31317- if (!cdo->generic_packet)
31318- cdo->generic_packet = cdrom_dummy_generic_packet;
31319+ if (!cdo->generic_packet) {
31320+ pax_open_kernel();
31321+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31322+ pax_close_kernel();
31323+ }
31324
31325 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31326 mutex_lock(&cdrom_mutex);
31327@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31328 if (cdi->exit)
31329 cdi->exit(cdi);
31330
31331- cdi->ops->n_minors--;
31332 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31333 }
31334
31335diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31336index 75d485a..2809958 100644
31337--- a/drivers/cdrom/gdrom.c
31338+++ b/drivers/cdrom/gdrom.c
31339@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31340 .audio_ioctl = gdrom_audio_ioctl,
31341 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31342 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31343- .n_minors = 1,
31344 };
31345
31346 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31347diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31348index 72bedad..8181ce1 100644
31349--- a/drivers/char/Kconfig
31350+++ b/drivers/char/Kconfig
31351@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31352
31353 config DEVKMEM
31354 bool "/dev/kmem virtual device support"
31355- default y
31356+ default n
31357+ depends on !GRKERNSEC_KMEM
31358 help
31359 Say Y here if you want to support the /dev/kmem device. The
31360 /dev/kmem device is rarely used, but can be used for certain
31361@@ -581,6 +582,7 @@ config DEVPORT
31362 bool
31363 depends on !M68K
31364 depends on ISA || PCI
31365+ depends on !GRKERNSEC_KMEM
31366 default y
31367
31368 source "drivers/s390/char/Kconfig"
31369diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31370index 2e04433..22afc64 100644
31371--- a/drivers/char/agp/frontend.c
31372+++ b/drivers/char/agp/frontend.c
31373@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31374 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31375 return -EFAULT;
31376
31377- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31378+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31379 return -EFAULT;
31380
31381 client = agp_find_client_by_pid(reserve.pid);
31382diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31383index 21cb980..f15107c 100644
31384--- a/drivers/char/genrtc.c
31385+++ b/drivers/char/genrtc.c
31386@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31387 switch (cmd) {
31388
31389 case RTC_PLL_GET:
31390+ memset(&pll, 0, sizeof(pll));
31391 if (get_rtc_pll(&pll))
31392 return -EINVAL;
31393 else
31394diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31395index dfd7876..c0b0885 100644
31396--- a/drivers/char/hpet.c
31397+++ b/drivers/char/hpet.c
31398@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31399 }
31400
31401 static int
31402-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31403+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31404 struct hpet_info *info)
31405 {
31406 struct hpet_timer __iomem *timer;
31407diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31408index a0c84bb..9edcf60 100644
31409--- a/drivers/char/ipmi/ipmi_msghandler.c
31410+++ b/drivers/char/ipmi/ipmi_msghandler.c
31411@@ -420,7 +420,7 @@ struct ipmi_smi {
31412 struct proc_dir_entry *proc_dir;
31413 char proc_dir_name[10];
31414
31415- atomic_t stats[IPMI_NUM_STATS];
31416+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31417
31418 /*
31419 * run_to_completion duplicate of smb_info, smi_info
31420@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31421
31422
31423 #define ipmi_inc_stat(intf, stat) \
31424- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31425+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31426 #define ipmi_get_stat(intf, stat) \
31427- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31428+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31429
31430 static int is_lan_addr(struct ipmi_addr *addr)
31431 {
31432@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31433 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31434 init_waitqueue_head(&intf->waitq);
31435 for (i = 0; i < IPMI_NUM_STATS; i++)
31436- atomic_set(&intf->stats[i], 0);
31437+ atomic_set_unchecked(&intf->stats[i], 0);
31438
31439 intf->proc_dir = NULL;
31440
31441diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31442index 32a6c7e..f6966a9 100644
31443--- a/drivers/char/ipmi/ipmi_si_intf.c
31444+++ b/drivers/char/ipmi/ipmi_si_intf.c
31445@@ -275,7 +275,7 @@ struct smi_info {
31446 unsigned char slave_addr;
31447
31448 /* Counters and things for the proc filesystem. */
31449- atomic_t stats[SI_NUM_STATS];
31450+ atomic_unchecked_t stats[SI_NUM_STATS];
31451
31452 struct task_struct *thread;
31453
31454@@ -284,9 +284,9 @@ struct smi_info {
31455 };
31456
31457 #define smi_inc_stat(smi, stat) \
31458- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31459+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31460 #define smi_get_stat(smi, stat) \
31461- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31462+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31463
31464 #define SI_MAX_PARMS 4
31465
31466@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31467 atomic_set(&new_smi->req_events, 0);
31468 new_smi->run_to_completion = 0;
31469 for (i = 0; i < SI_NUM_STATS; i++)
31470- atomic_set(&new_smi->stats[i], 0);
31471+ atomic_set_unchecked(&new_smi->stats[i], 0);
31472
31473 new_smi->interrupt_disabled = 1;
31474 atomic_set(&new_smi->stop_operation, 0);
31475diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31476index 0537903..121c699 100644
31477--- a/drivers/char/mem.c
31478+++ b/drivers/char/mem.c
31479@@ -18,6 +18,7 @@
31480 #include <linux/raw.h>
31481 #include <linux/tty.h>
31482 #include <linux/capability.h>
31483+#include <linux/security.h>
31484 #include <linux/ptrace.h>
31485 #include <linux/device.h>
31486 #include <linux/highmem.h>
31487@@ -37,6 +38,10 @@
31488
31489 #define DEVPORT_MINOR 4
31490
31491+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31492+extern const struct file_operations grsec_fops;
31493+#endif
31494+
31495 static inline unsigned long size_inside_page(unsigned long start,
31496 unsigned long size)
31497 {
31498@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31499
31500 while (cursor < to) {
31501 if (!devmem_is_allowed(pfn)) {
31502+#ifdef CONFIG_GRKERNSEC_KMEM
31503+ gr_handle_mem_readwrite(from, to);
31504+#else
31505 printk(KERN_INFO
31506 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31507 current->comm, from, to);
31508+#endif
31509 return 0;
31510 }
31511 cursor += PAGE_SIZE;
31512@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31513 }
31514 return 1;
31515 }
31516+#elif defined(CONFIG_GRKERNSEC_KMEM)
31517+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31518+{
31519+ return 0;
31520+}
31521 #else
31522 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31523 {
31524@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31525
31526 while (count > 0) {
31527 unsigned long remaining;
31528+ char *temp;
31529
31530 sz = size_inside_page(p, count);
31531
31532@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31533 if (!ptr)
31534 return -EFAULT;
31535
31536- remaining = copy_to_user(buf, ptr, sz);
31537+#ifdef CONFIG_PAX_USERCOPY
31538+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31539+ if (!temp) {
31540+ unxlate_dev_mem_ptr(p, ptr);
31541+ return -ENOMEM;
31542+ }
31543+ memcpy(temp, ptr, sz);
31544+#else
31545+ temp = ptr;
31546+#endif
31547+
31548+ remaining = copy_to_user(buf, temp, sz);
31549+
31550+#ifdef CONFIG_PAX_USERCOPY
31551+ kfree(temp);
31552+#endif
31553+
31554 unxlate_dev_mem_ptr(p, ptr);
31555 if (remaining)
31556 return -EFAULT;
31557@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31558 size_t count, loff_t *ppos)
31559 {
31560 unsigned long p = *ppos;
31561- ssize_t low_count, read, sz;
31562+ ssize_t low_count, read, sz, err = 0;
31563 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31564- int err = 0;
31565
31566 read = 0;
31567 if (p < (unsigned long) high_memory) {
31568@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31569 }
31570 #endif
31571 while (low_count > 0) {
31572+ char *temp;
31573+
31574 sz = size_inside_page(p, low_count);
31575
31576 /*
31577@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31578 */
31579 kbuf = xlate_dev_kmem_ptr((char *)p);
31580
31581- if (copy_to_user(buf, kbuf, sz))
31582+#ifdef CONFIG_PAX_USERCOPY
31583+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31584+ if (!temp)
31585+ return -ENOMEM;
31586+ memcpy(temp, kbuf, sz);
31587+#else
31588+ temp = kbuf;
31589+#endif
31590+
31591+ err = copy_to_user(buf, temp, sz);
31592+
31593+#ifdef CONFIG_PAX_USERCOPY
31594+ kfree(temp);
31595+#endif
31596+
31597+ if (err)
31598 return -EFAULT;
31599 buf += sz;
31600 p += sz;
31601@@ -833,6 +880,9 @@ static const struct memdev {
31602 #ifdef CONFIG_CRASH_DUMP
31603 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31604 #endif
31605+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31606+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31607+#endif
31608 };
31609
31610 static int memory_open(struct inode *inode, struct file *filp)
31611diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31612index 9df78e2..01ba9ae 100644
31613--- a/drivers/char/nvram.c
31614+++ b/drivers/char/nvram.c
31615@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31616
31617 spin_unlock_irq(&rtc_lock);
31618
31619- if (copy_to_user(buf, contents, tmp - contents))
31620+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31621 return -EFAULT;
31622
31623 *ppos = i;
31624diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31625index 21721d2..4e98777 100644
31626--- a/drivers/char/pcmcia/synclink_cs.c
31627+++ b/drivers/char/pcmcia/synclink_cs.c
31628@@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31629
31630 if (debug_level >= DEBUG_LEVEL_INFO)
31631 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31632- __FILE__,__LINE__, info->device_name, port->count);
31633+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31634
31635- WARN_ON(!port->count);
31636+ WARN_ON(!atomic_read(&port->count));
31637
31638 if (tty_port_close_start(port, tty, filp) == 0)
31639 goto cleanup;
31640@@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31641 cleanup:
31642 if (debug_level >= DEBUG_LEVEL_INFO)
31643 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31644- tty->driver->name, port->count);
31645+ tty->driver->name, atomic_read(&port->count));
31646 }
31647
31648 /* Wait until the transmitter is empty.
31649@@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31650
31651 if (debug_level >= DEBUG_LEVEL_INFO)
31652 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31653- __FILE__,__LINE__,tty->driver->name, port->count);
31654+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
31655
31656 /* If port is closing, signal caller to try again */
31657 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
31658@@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31659 goto cleanup;
31660 }
31661 spin_lock(&port->lock);
31662- port->count++;
31663+ atomic_inc(&port->count);
31664 spin_unlock(&port->lock);
31665 spin_unlock_irqrestore(&info->netlock, flags);
31666
31667- if (port->count == 1) {
31668+ if (atomic_read(&port->count) == 1) {
31669 /* 1st open on this device, init hardware */
31670 retval = startup(info, tty);
31671 if (retval < 0)
31672@@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
31673 unsigned short new_crctype;
31674
31675 /* return error if TTY interface open */
31676- if (info->port.count)
31677+ if (atomic_read(&info->port.count))
31678 return -EBUSY;
31679
31680 switch (encoding)
31681@@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
31682
31683 /* arbitrate between network and tty opens */
31684 spin_lock_irqsave(&info->netlock, flags);
31685- if (info->port.count != 0 || info->netcount != 0) {
31686+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
31687 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
31688 spin_unlock_irqrestore(&info->netlock, flags);
31689 return -EBUSY;
31690@@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
31691 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
31692
31693 /* return error if TTY interface open */
31694- if (info->port.count)
31695+ if (atomic_read(&info->port.count))
31696 return -EBUSY;
31697
31698 if (cmd != SIOCWANDEV)
31699diff --git a/drivers/char/random.c b/drivers/char/random.c
31700index b86eae9..b9c2ed7 100644
31701--- a/drivers/char/random.c
31702+++ b/drivers/char/random.c
31703@@ -272,8 +272,13 @@
31704 /*
31705 * Configuration information
31706 */
31707+#ifdef CONFIG_GRKERNSEC_RANDNET
31708+#define INPUT_POOL_WORDS 512
31709+#define OUTPUT_POOL_WORDS 128
31710+#else
31711 #define INPUT_POOL_WORDS 128
31712 #define OUTPUT_POOL_WORDS 32
31713+#endif
31714 #define SEC_XFER_SIZE 512
31715 #define EXTRACT_SIZE 10
31716
31717@@ -313,10 +318,17 @@ static struct poolinfo {
31718 int poolwords;
31719 int tap1, tap2, tap3, tap4, tap5;
31720 } poolinfo_table[] = {
31721+#ifdef CONFIG_GRKERNSEC_RANDNET
31722+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
31723+ { 512, 411, 308, 208, 104, 1 },
31724+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
31725+ { 128, 103, 76, 51, 25, 1 },
31726+#else
31727 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
31728 { 128, 103, 76, 51, 25, 1 },
31729 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
31730 { 32, 26, 20, 14, 7, 1 },
31731+#endif
31732 #if 0
31733 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
31734 { 2048, 1638, 1231, 819, 411, 1 },
31735@@ -437,6 +449,7 @@ struct entropy_store {
31736 int entropy_count;
31737 int entropy_total;
31738 unsigned int initialized:1;
31739+ bool last_data_init;
31740 __u8 last_data[EXTRACT_SIZE];
31741 };
31742
31743@@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
31744 input_rotate += i ? 7 : 14;
31745 }
31746
31747- ACCESS_ONCE(r->input_rotate) = input_rotate;
31748- ACCESS_ONCE(r->add_ptr) = i;
31749+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
31750+ ACCESS_ONCE_RW(r->add_ptr) = i;
31751 smp_wmb();
31752
31753 if (out)
31754@@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31755 ssize_t ret = 0, i;
31756 __u8 tmp[EXTRACT_SIZE];
31757
31758+ /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
31759+ if (fips_enabled && !r->last_data_init)
31760+ nbytes += EXTRACT_SIZE;
31761+
31762 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
31763 xfer_secondary_pool(r, nbytes);
31764 nbytes = account(r, nbytes, min, reserved);
31765@@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
31766 if (fips_enabled) {
31767 unsigned long flags;
31768
31769+
31770+ /* prime last_data value if need be, per fips 140-2 */
31771+ if (!r->last_data_init) {
31772+ spin_lock_irqsave(&r->lock, flags);
31773+ memcpy(r->last_data, tmp, EXTRACT_SIZE);
31774+ r->last_data_init = true;
31775+ nbytes -= EXTRACT_SIZE;
31776+ spin_unlock_irqrestore(&r->lock, flags);
31777+ extract_buf(r, tmp);
31778+ }
31779+
31780 spin_lock_irqsave(&r->lock, flags);
31781 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
31782 panic("Hardware RNG duplicated output!\n");
31783@@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
31784
31785 extract_buf(r, tmp);
31786 i = min_t(int, nbytes, EXTRACT_SIZE);
31787- if (copy_to_user(buf, tmp, i)) {
31788+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
31789 ret = -EFAULT;
31790 break;
31791 }
31792@@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
31793
31794 r->entropy_count = 0;
31795 r->entropy_total = 0;
31796+ r->last_data_init = false;
31797 mix_pool_bytes(r, &now, sizeof(now), NULL);
31798 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
31799 if (!arch_get_random_long(&rv))
31800@@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
31801 #include <linux/sysctl.h>
31802
31803 static int min_read_thresh = 8, min_write_thresh;
31804-static int max_read_thresh = INPUT_POOL_WORDS * 32;
31805+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
31806 static int max_write_thresh = INPUT_POOL_WORDS * 32;
31807 static char sysctl_bootid[16];
31808
31809diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
31810index 9b4f011..b7e0a1a 100644
31811--- a/drivers/char/sonypi.c
31812+++ b/drivers/char/sonypi.c
31813@@ -54,6 +54,7 @@
31814
31815 #include <asm/uaccess.h>
31816 #include <asm/io.h>
31817+#include <asm/local.h>
31818
31819 #include <linux/sonypi.h>
31820
31821@@ -490,7 +491,7 @@ static struct sonypi_device {
31822 spinlock_t fifo_lock;
31823 wait_queue_head_t fifo_proc_list;
31824 struct fasync_struct *fifo_async;
31825- int open_count;
31826+ local_t open_count;
31827 int model;
31828 struct input_dev *input_jog_dev;
31829 struct input_dev *input_key_dev;
31830@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
31831 static int sonypi_misc_release(struct inode *inode, struct file *file)
31832 {
31833 mutex_lock(&sonypi_device.lock);
31834- sonypi_device.open_count--;
31835+ local_dec(&sonypi_device.open_count);
31836 mutex_unlock(&sonypi_device.lock);
31837 return 0;
31838 }
31839@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
31840 {
31841 mutex_lock(&sonypi_device.lock);
31842 /* Flush input queue on first open */
31843- if (!sonypi_device.open_count)
31844+ if (!local_read(&sonypi_device.open_count))
31845 kfifo_reset(&sonypi_device.fifo);
31846- sonypi_device.open_count++;
31847+ local_inc(&sonypi_device.open_count);
31848 mutex_unlock(&sonypi_device.lock);
31849
31850 return 0;
31851diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
31852index 93211df..c7805f7 100644
31853--- a/drivers/char/tpm/tpm.c
31854+++ b/drivers/char/tpm/tpm.c
31855@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
31856 chip->vendor.req_complete_val)
31857 goto out_recv;
31858
31859- if ((status == chip->vendor.req_canceled)) {
31860+ if (status == chip->vendor.req_canceled) {
31861 dev_err(chip->dev, "Operation Canceled\n");
31862 rc = -ECANCELED;
31863 goto out;
31864diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
31865index 56051d0..11cf3b7 100644
31866--- a/drivers/char/tpm/tpm_acpi.c
31867+++ b/drivers/char/tpm/tpm_acpi.c
31868@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
31869 virt = acpi_os_map_memory(start, len);
31870 if (!virt) {
31871 kfree(log->bios_event_log);
31872+ log->bios_event_log = NULL;
31873 printk("%s: ERROR - Unable to map memory\n", __func__);
31874 return -EIO;
31875 }
31876
31877- memcpy_fromio(log->bios_event_log, virt, len);
31878+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
31879
31880 acpi_os_unmap_memory(virt, len);
31881 return 0;
31882diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
31883index 84ddc55..1d32f1e 100644
31884--- a/drivers/char/tpm/tpm_eventlog.c
31885+++ b/drivers/char/tpm/tpm_eventlog.c
31886@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
31887 event = addr;
31888
31889 if ((event->event_type == 0 && event->event_size == 0) ||
31890- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
31891+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
31892 return NULL;
31893
31894 return addr;
31895@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
31896 return NULL;
31897
31898 if ((event->event_type == 0 && event->event_size == 0) ||
31899- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
31900+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
31901 return NULL;
31902
31903 (*pos)++;
31904@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
31905 int i;
31906
31907 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
31908- seq_putc(m, data[i]);
31909+ if (!seq_putc(m, data[i]))
31910+ return -EFAULT;
31911
31912 return 0;
31913 }
31914diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
31915index 088c8fd..774c5a5 100644
31916--- a/drivers/char/virtio_console.c
31917+++ b/drivers/char/virtio_console.c
31918@@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
31919 if (to_user) {
31920 ssize_t ret;
31921
31922- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
31923+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
31924 if (ret)
31925 return -EFAULT;
31926 } else {
31927@@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
31928 if (!port_has_data(port) && !port->host_connected)
31929 return 0;
31930
31931- return fill_readbuf(port, ubuf, count, true);
31932+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
31933 }
31934
31935 static int wait_port_writable(struct port *port, bool nonblock)
31936diff --git a/drivers/edac/edac_mc.c b/drivers/edac/edac_mc.c
31937index 75c0a1a..96ba8f6 100644
31938--- a/drivers/edac/edac_mc.c
31939+++ b/drivers/edac/edac_mc.c
31940@@ -340,7 +340,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
31941 /*
31942 * Alocate and fill the csrow/channels structs
31943 */
31944- mci->csrows = kcalloc(sizeof(*mci->csrows), tot_csrows, GFP_KERNEL);
31945+ mci->csrows = kcalloc(tot_csrows, sizeof(*mci->csrows), GFP_KERNEL);
31946 if (!mci->csrows)
31947 goto error;
31948 for (row = 0; row < tot_csrows; row++) {
31949@@ -351,7 +351,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
31950 csr->csrow_idx = row;
31951 csr->mci = mci;
31952 csr->nr_channels = tot_channels;
31953- csr->channels = kcalloc(sizeof(*csr->channels), tot_channels,
31954+ csr->channels = kcalloc(tot_channels, sizeof(*csr->channels),
31955 GFP_KERNEL);
31956 if (!csr->channels)
31957 goto error;
31958@@ -369,7 +369,7 @@ struct mem_ctl_info *edac_mc_alloc(unsigned mc_num,
31959 /*
31960 * Allocate and fill the dimm structs
31961 */
31962- mci->dimms = kcalloc(sizeof(*mci->dimms), tot_dimms, GFP_KERNEL);
31963+ mci->dimms = kcalloc(tot_dimms, sizeof(*mci->dimms), GFP_KERNEL);
31964 if (!mci->dimms)
31965 goto error;
31966
31967diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
31968index 1bfb207..0d059c2 100644
31969--- a/drivers/edac/edac_pci_sysfs.c
31970+++ b/drivers/edac/edac_pci_sysfs.c
31971@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
31972 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
31973 static int edac_pci_poll_msec = 1000; /* one second workq period */
31974
31975-static atomic_t pci_parity_count = ATOMIC_INIT(0);
31976-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
31977+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
31978+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
31979
31980 static struct kobject *edac_pci_top_main_kobj;
31981 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
31982@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31983 edac_printk(KERN_CRIT, EDAC_PCI,
31984 "Signaled System Error on %s\n",
31985 pci_name(dev));
31986- atomic_inc(&pci_nonparity_count);
31987+ atomic_inc_unchecked(&pci_nonparity_count);
31988 }
31989
31990 if (status & (PCI_STATUS_PARITY)) {
31991@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
31992 "Master Data Parity Error on %s\n",
31993 pci_name(dev));
31994
31995- atomic_inc(&pci_parity_count);
31996+ atomic_inc_unchecked(&pci_parity_count);
31997 }
31998
31999 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32000@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32001 "Detected Parity Error on %s\n",
32002 pci_name(dev));
32003
32004- atomic_inc(&pci_parity_count);
32005+ atomic_inc_unchecked(&pci_parity_count);
32006 }
32007 }
32008
32009@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32010 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32011 "Signaled System Error on %s\n",
32012 pci_name(dev));
32013- atomic_inc(&pci_nonparity_count);
32014+ atomic_inc_unchecked(&pci_nonparity_count);
32015 }
32016
32017 if (status & (PCI_STATUS_PARITY)) {
32018@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32019 "Master Data Parity Error on "
32020 "%s\n", pci_name(dev));
32021
32022- atomic_inc(&pci_parity_count);
32023+ atomic_inc_unchecked(&pci_parity_count);
32024 }
32025
32026 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32027@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32028 "Detected Parity Error on %s\n",
32029 pci_name(dev));
32030
32031- atomic_inc(&pci_parity_count);
32032+ atomic_inc_unchecked(&pci_parity_count);
32033 }
32034 }
32035 }
32036@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32037 if (!check_pci_errors)
32038 return;
32039
32040- before_count = atomic_read(&pci_parity_count);
32041+ before_count = atomic_read_unchecked(&pci_parity_count);
32042
32043 /* scan all PCI devices looking for a Parity Error on devices and
32044 * bridges.
32045@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32046 /* Only if operator has selected panic on PCI Error */
32047 if (edac_pci_get_panic_on_pe()) {
32048 /* If the count is different 'after' from 'before' */
32049- if (before_count != atomic_read(&pci_parity_count))
32050+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32051 panic("EDAC: PCI Parity Error");
32052 }
32053 }
32054diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32055index 8c87a5e..a19cbd7 100644
32056--- a/drivers/edac/mce_amd.h
32057+++ b/drivers/edac/mce_amd.h
32058@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32059 struct amd_decoder_ops {
32060 bool (*dc_mce)(u16, u8);
32061 bool (*ic_mce)(u16, u8);
32062-};
32063+} __no_const;
32064
32065 void amd_report_gart_errors(bool);
32066 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32067diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32068index 57ea7f4..789e3c3 100644
32069--- a/drivers/firewire/core-card.c
32070+++ b/drivers/firewire/core-card.c
32071@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32072
32073 void fw_core_remove_card(struct fw_card *card)
32074 {
32075- struct fw_card_driver dummy_driver = dummy_driver_template;
32076+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32077
32078 card->driver->update_phy_reg(card, 4,
32079 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32080diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32081index f8d2287..5aaf4db 100644
32082--- a/drivers/firewire/core-cdev.c
32083+++ b/drivers/firewire/core-cdev.c
32084@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32085 int ret;
32086
32087 if ((request->channels == 0 && request->bandwidth == 0) ||
32088- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32089- request->bandwidth < 0)
32090+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32091 return -EINVAL;
32092
32093 r = kmalloc(sizeof(*r), GFP_KERNEL);
32094diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32095index 28a94c7..58da63a 100644
32096--- a/drivers/firewire/core-transaction.c
32097+++ b/drivers/firewire/core-transaction.c
32098@@ -38,6 +38,7 @@
32099 #include <linux/timer.h>
32100 #include <linux/types.h>
32101 #include <linux/workqueue.h>
32102+#include <linux/sched.h>
32103
32104 #include <asm/byteorder.h>
32105
32106diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32107index 515a42c..5ecf3ba 100644
32108--- a/drivers/firewire/core.h
32109+++ b/drivers/firewire/core.h
32110@@ -111,6 +111,7 @@ struct fw_card_driver {
32111
32112 int (*stop_iso)(struct fw_iso_context *ctx);
32113 };
32114+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32115
32116 void fw_card_initialize(struct fw_card *card,
32117 const struct fw_card_driver *driver, struct device *device);
32118diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32119index 982f1f5..d21e5da 100644
32120--- a/drivers/firmware/dmi_scan.c
32121+++ b/drivers/firmware/dmi_scan.c
32122@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32123 }
32124 }
32125 else {
32126- /*
32127- * no iounmap() for that ioremap(); it would be a no-op, but
32128- * it's so early in setup that sucker gets confused into doing
32129- * what it shouldn't if we actually call it.
32130- */
32131 p = dmi_ioremap(0xF0000, 0x10000);
32132 if (p == NULL)
32133 goto error;
32134@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32135 if (buf == NULL)
32136 return -1;
32137
32138- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32139+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32140
32141 iounmap(buf);
32142 return 0;
32143diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32144index bfd8f43..b1fe1f8 100644
32145--- a/drivers/firmware/efivars.c
32146+++ b/drivers/firmware/efivars.c
32147@@ -1206,7 +1206,7 @@ out:
32148 EXPORT_SYMBOL_GPL(register_efivars);
32149
32150 static struct efivars __efivars;
32151-static struct efivar_operations ops;
32152+static efivar_operations_no_const ops __read_only;
32153
32154 /*
32155 * For now we register the efi subsystem with the firmware subsystem
32156diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32157index 82d5c20..44a7177 100644
32158--- a/drivers/gpio/gpio-vr41xx.c
32159+++ b/drivers/gpio/gpio-vr41xx.c
32160@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32161 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32162 maskl, pendl, maskh, pendh);
32163
32164- atomic_inc(&irq_err_count);
32165+ atomic_inc_unchecked(&irq_err_count);
32166
32167 return -EINVAL;
32168 }
32169diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32170index 1227adf..f2301c2 100644
32171--- a/drivers/gpu/drm/drm_crtc_helper.c
32172+++ b/drivers/gpu/drm/drm_crtc_helper.c
32173@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32174 struct drm_crtc *tmp;
32175 int crtc_mask = 1;
32176
32177- WARN(!crtc, "checking null crtc?\n");
32178+ BUG_ON(!crtc);
32179
32180 dev = crtc->dev;
32181
32182diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32183index be174ca..0bcbb71 100644
32184--- a/drivers/gpu/drm/drm_drv.c
32185+++ b/drivers/gpu/drm/drm_drv.c
32186@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32187 /**
32188 * Copy and IOCTL return string to user space
32189 */
32190-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32191+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32192 {
32193 int len;
32194
32195@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32196 return -ENODEV;
32197
32198 atomic_inc(&dev->ioctl_count);
32199- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32200+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32201 ++file_priv->ioctl_count;
32202
32203 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32204diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32205index 133b413..fd68225 100644
32206--- a/drivers/gpu/drm/drm_fops.c
32207+++ b/drivers/gpu/drm/drm_fops.c
32208@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32209 }
32210
32211 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32212- atomic_set(&dev->counts[i], 0);
32213+ atomic_set_unchecked(&dev->counts[i], 0);
32214
32215 dev->sigdata.lock = NULL;
32216
32217@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32218 if (drm_device_is_unplugged(dev))
32219 return -ENODEV;
32220
32221- if (!dev->open_count++)
32222+ if (local_inc_return(&dev->open_count) == 1)
32223 need_setup = 1;
32224 mutex_lock(&dev->struct_mutex);
32225 old_mapping = dev->dev_mapping;
32226@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32227 retcode = drm_open_helper(inode, filp, dev);
32228 if (retcode)
32229 goto err_undo;
32230- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32231+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32232 if (need_setup) {
32233 retcode = drm_setup(dev);
32234 if (retcode)
32235@@ -164,7 +164,7 @@ err_undo:
32236 iput(container_of(dev->dev_mapping, struct inode, i_data));
32237 dev->dev_mapping = old_mapping;
32238 mutex_unlock(&dev->struct_mutex);
32239- dev->open_count--;
32240+ local_dec(&dev->open_count);
32241 return retcode;
32242 }
32243 EXPORT_SYMBOL(drm_open);
32244@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32245
32246 mutex_lock(&drm_global_mutex);
32247
32248- DRM_DEBUG("open_count = %d\n", dev->open_count);
32249+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32250
32251 if (dev->driver->preclose)
32252 dev->driver->preclose(dev, file_priv);
32253@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32254 * Begin inline drm_release
32255 */
32256
32257- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32258+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32259 task_pid_nr(current),
32260 (long)old_encode_dev(file_priv->minor->device),
32261- dev->open_count);
32262+ local_read(&dev->open_count));
32263
32264 /* Release any auth tokens that might point to this file_priv,
32265 (do that under the drm_global_mutex) */
32266@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32267 * End inline drm_release
32268 */
32269
32270- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32271- if (!--dev->open_count) {
32272+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32273+ if (local_dec_and_test(&dev->open_count)) {
32274 if (atomic_read(&dev->ioctl_count)) {
32275 DRM_ERROR("Device busy: %d\n",
32276 atomic_read(&dev->ioctl_count));
32277diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32278index f731116..629842c 100644
32279--- a/drivers/gpu/drm/drm_global.c
32280+++ b/drivers/gpu/drm/drm_global.c
32281@@ -36,7 +36,7 @@
32282 struct drm_global_item {
32283 struct mutex mutex;
32284 void *object;
32285- int refcount;
32286+ atomic_t refcount;
32287 };
32288
32289 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32290@@ -49,7 +49,7 @@ void drm_global_init(void)
32291 struct drm_global_item *item = &glob[i];
32292 mutex_init(&item->mutex);
32293 item->object = NULL;
32294- item->refcount = 0;
32295+ atomic_set(&item->refcount, 0);
32296 }
32297 }
32298
32299@@ -59,7 +59,7 @@ void drm_global_release(void)
32300 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32301 struct drm_global_item *item = &glob[i];
32302 BUG_ON(item->object != NULL);
32303- BUG_ON(item->refcount != 0);
32304+ BUG_ON(atomic_read(&item->refcount) != 0);
32305 }
32306 }
32307
32308@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32309 void *object;
32310
32311 mutex_lock(&item->mutex);
32312- if (item->refcount == 0) {
32313+ if (atomic_read(&item->refcount) == 0) {
32314 item->object = kzalloc(ref->size, GFP_KERNEL);
32315 if (unlikely(item->object == NULL)) {
32316 ret = -ENOMEM;
32317@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32318 goto out_err;
32319
32320 }
32321- ++item->refcount;
32322+ atomic_inc(&item->refcount);
32323 ref->object = item->object;
32324 object = item->object;
32325 mutex_unlock(&item->mutex);
32326@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32327 struct drm_global_item *item = &glob[ref->global_type];
32328
32329 mutex_lock(&item->mutex);
32330- BUG_ON(item->refcount == 0);
32331+ BUG_ON(atomic_read(&item->refcount) == 0);
32332 BUG_ON(ref->object != item->object);
32333- if (--item->refcount == 0) {
32334+ if (atomic_dec_and_test(&item->refcount)) {
32335 ref->release(ref);
32336 item->object = NULL;
32337 }
32338diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32339index d4b20ce..77a8d41 100644
32340--- a/drivers/gpu/drm/drm_info.c
32341+++ b/drivers/gpu/drm/drm_info.c
32342@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32343 struct drm_local_map *map;
32344 struct drm_map_list *r_list;
32345
32346- /* Hardcoded from _DRM_FRAME_BUFFER,
32347- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32348- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32349- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32350+ static const char * const types[] = {
32351+ [_DRM_FRAME_BUFFER] = "FB",
32352+ [_DRM_REGISTERS] = "REG",
32353+ [_DRM_SHM] = "SHM",
32354+ [_DRM_AGP] = "AGP",
32355+ [_DRM_SCATTER_GATHER] = "SG",
32356+ [_DRM_CONSISTENT] = "PCI",
32357+ [_DRM_GEM] = "GEM" };
32358 const char *type;
32359 int i;
32360
32361@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32362 map = r_list->map;
32363 if (!map)
32364 continue;
32365- if (map->type < 0 || map->type > 5)
32366+ if (map->type >= ARRAY_SIZE(types))
32367 type = "??";
32368 else
32369 type = types[map->type];
32370@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32371 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32372 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32373 vma->vm_flags & VM_IO ? 'i' : '-',
32374+#ifdef CONFIG_GRKERNSEC_HIDESYM
32375+ 0);
32376+#else
32377 vma->vm_pgoff);
32378+#endif
32379
32380 #if defined(__i386__)
32381 pgprot = pgprot_val(vma->vm_page_prot);
32382diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32383index 2f4c434..764794b 100644
32384--- a/drivers/gpu/drm/drm_ioc32.c
32385+++ b/drivers/gpu/drm/drm_ioc32.c
32386@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32387 request = compat_alloc_user_space(nbytes);
32388 if (!access_ok(VERIFY_WRITE, request, nbytes))
32389 return -EFAULT;
32390- list = (struct drm_buf_desc *) (request + 1);
32391+ list = (struct drm_buf_desc __user *) (request + 1);
32392
32393 if (__put_user(count, &request->count)
32394 || __put_user(list, &request->list))
32395@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32396 request = compat_alloc_user_space(nbytes);
32397 if (!access_ok(VERIFY_WRITE, request, nbytes))
32398 return -EFAULT;
32399- list = (struct drm_buf_pub *) (request + 1);
32400+ list = (struct drm_buf_pub __user *) (request + 1);
32401
32402 if (__put_user(count, &request->count)
32403 || __put_user(list, &request->list))
32404diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32405index 23dd975..63e9801 100644
32406--- a/drivers/gpu/drm/drm_ioctl.c
32407+++ b/drivers/gpu/drm/drm_ioctl.c
32408@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32409 stats->data[i].value =
32410 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32411 else
32412- stats->data[i].value = atomic_read(&dev->counts[i]);
32413+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32414 stats->data[i].type = dev->types[i];
32415 }
32416
32417diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32418index d752c96..fe08455 100644
32419--- a/drivers/gpu/drm/drm_lock.c
32420+++ b/drivers/gpu/drm/drm_lock.c
32421@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32422 if (drm_lock_take(&master->lock, lock->context)) {
32423 master->lock.file_priv = file_priv;
32424 master->lock.lock_time = jiffies;
32425- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32426+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32427 break; /* Got lock */
32428 }
32429
32430@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32431 return -EINVAL;
32432 }
32433
32434- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32435+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32436
32437 if (drm_lock_free(&master->lock, lock->context)) {
32438 /* FIXME: Should really bail out here. */
32439diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32440index c236fd2..6b5f2e7 100644
32441--- a/drivers/gpu/drm/drm_stub.c
32442+++ b/drivers/gpu/drm/drm_stub.c
32443@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32444
32445 drm_device_set_unplugged(dev);
32446
32447- if (dev->open_count == 0) {
32448+ if (local_read(&dev->open_count) == 0) {
32449 drm_put_dev(dev);
32450 }
32451 mutex_unlock(&drm_global_mutex);
32452diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32453index 004ecdf..db1f6e0 100644
32454--- a/drivers/gpu/drm/i810/i810_dma.c
32455+++ b/drivers/gpu/drm/i810/i810_dma.c
32456@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32457 dma->buflist[vertex->idx],
32458 vertex->discard, vertex->used);
32459
32460- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32461- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32462+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32463+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32464 sarea_priv->last_enqueue = dev_priv->counter - 1;
32465 sarea_priv->last_dispatch = (int)hw_status[5];
32466
32467@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32468 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32469 mc->last_render);
32470
32471- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32472- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32473+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32474+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32475 sarea_priv->last_enqueue = dev_priv->counter - 1;
32476 sarea_priv->last_dispatch = (int)hw_status[5];
32477
32478diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32479index 6e0acad..93c8289 100644
32480--- a/drivers/gpu/drm/i810/i810_drv.h
32481+++ b/drivers/gpu/drm/i810/i810_drv.h
32482@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32483 int page_flipping;
32484
32485 wait_queue_head_t irq_queue;
32486- atomic_t irq_received;
32487- atomic_t irq_emitted;
32488+ atomic_unchecked_t irq_received;
32489+ atomic_unchecked_t irq_emitted;
32490
32491 int front_offset;
32492 } drm_i810_private_t;
32493diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32494index 3a1a495..995c093 100644
32495--- a/drivers/gpu/drm/i915/i915_debugfs.c
32496+++ b/drivers/gpu/drm/i915/i915_debugfs.c
32497@@ -496,7 +496,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32498 I915_READ(GTIMR));
32499 }
32500 seq_printf(m, "Interrupts received: %d\n",
32501- atomic_read(&dev_priv->irq_received));
32502+ atomic_read_unchecked(&dev_priv->irq_received));
32503 for_each_ring(ring, dev_priv, i) {
32504 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32505 seq_printf(m,
32506diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32507index 61ae104..f8a4bc1 100644
32508--- a/drivers/gpu/drm/i915/i915_dma.c
32509+++ b/drivers/gpu/drm/i915/i915_dma.c
32510@@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32511 bool can_switch;
32512
32513 spin_lock(&dev->count_lock);
32514- can_switch = (dev->open_count == 0);
32515+ can_switch = (local_read(&dev->open_count) == 0);
32516 spin_unlock(&dev->count_lock);
32517 return can_switch;
32518 }
32519diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32520index 92f1750..3beba74 100644
32521--- a/drivers/gpu/drm/i915/i915_drv.h
32522+++ b/drivers/gpu/drm/i915/i915_drv.h
32523@@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32524
32525 struct resource mch_res;
32526
32527- atomic_t irq_received;
32528+ atomic_unchecked_t irq_received;
32529
32530 /* protects the irq masks */
32531 spinlock_t irq_lock;
32532@@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32533 * will be page flipped away on the next vblank. When it
32534 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32535 */
32536- atomic_t pending_flip;
32537+ atomic_unchecked_t pending_flip;
32538 };
32539
32540 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32541@@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32542 struct drm_i915_private *dev_priv, unsigned port);
32543 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32544 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32545-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32546+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32547 {
32548 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32549 }
32550diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32551index 67036e9..b9f1357 100644
32552--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32553+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32554@@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32555 i915_gem_clflush_object(obj);
32556
32557 if (obj->base.pending_write_domain)
32558- flips |= atomic_read(&obj->pending_flip);
32559+ flips |= atomic_read_unchecked(&obj->pending_flip);
32560
32561 flush_domains |= obj->base.write_domain;
32562 }
32563@@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32564
32565 static int
32566 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32567- int count)
32568+ unsigned int count)
32569 {
32570- int i;
32571+ unsigned int i;
32572
32573 for (i = 0; i < count; i++) {
32574 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32575diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32576index dc29ace..137d83a 100644
32577--- a/drivers/gpu/drm/i915/i915_irq.c
32578+++ b/drivers/gpu/drm/i915/i915_irq.c
32579@@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32580 u32 pipe_stats[I915_MAX_PIPES];
32581 bool blc_event;
32582
32583- atomic_inc(&dev_priv->irq_received);
32584+ atomic_inc_unchecked(&dev_priv->irq_received);
32585
32586 while (true) {
32587 iir = I915_READ(VLV_IIR);
32588@@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32589 irqreturn_t ret = IRQ_NONE;
32590 int i;
32591
32592- atomic_inc(&dev_priv->irq_received);
32593+ atomic_inc_unchecked(&dev_priv->irq_received);
32594
32595 /* disable master interrupt before clearing iir */
32596 de_ier = I915_READ(DEIER);
32597@@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32598 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32599 u32 hotplug_mask;
32600
32601- atomic_inc(&dev_priv->irq_received);
32602+ atomic_inc_unchecked(&dev_priv->irq_received);
32603
32604 /* disable master interrupt before clearing iir */
32605 de_ier = I915_READ(DEIER);
32606@@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32607 {
32608 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32609
32610- atomic_set(&dev_priv->irq_received, 0);
32611+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32612
32613 I915_WRITE(HWSTAM, 0xeffe);
32614
32615@@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32616 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32617 int pipe;
32618
32619- atomic_set(&dev_priv->irq_received, 0);
32620+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32621
32622 /* VLV magic */
32623 I915_WRITE(VLV_IMR, 0);
32624@@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32625 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32626 int pipe;
32627
32628- atomic_set(&dev_priv->irq_received, 0);
32629+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32630
32631 for_each_pipe(pipe)
32632 I915_WRITE(PIPESTAT(pipe), 0);
32633@@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32634 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32635 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32636
32637- atomic_inc(&dev_priv->irq_received);
32638+ atomic_inc_unchecked(&dev_priv->irq_received);
32639
32640 iir = I915_READ16(IIR);
32641 if (iir == 0)
32642@@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32643 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32644 int pipe;
32645
32646- atomic_set(&dev_priv->irq_received, 0);
32647+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32648
32649 if (I915_HAS_HOTPLUG(dev)) {
32650 I915_WRITE(PORT_HOTPLUG_EN, 0);
32651@@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32652 };
32653 int pipe, ret = IRQ_NONE;
32654
32655- atomic_inc(&dev_priv->irq_received);
32656+ atomic_inc_unchecked(&dev_priv->irq_received);
32657
32658 iir = I915_READ(IIR);
32659 do {
32660@@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32661 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32662 int pipe;
32663
32664- atomic_set(&dev_priv->irq_received, 0);
32665+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32666
32667 I915_WRITE(PORT_HOTPLUG_EN, 0);
32668 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32669@@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32670 int irq_received;
32671 int ret = IRQ_NONE, pipe;
32672
32673- atomic_inc(&dev_priv->irq_received);
32674+ atomic_inc_unchecked(&dev_priv->irq_received);
32675
32676 iir = I915_READ(IIR);
32677
32678diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32679index 4d3c7c6..eaac87b 100644
32680--- a/drivers/gpu/drm/i915/intel_display.c
32681+++ b/drivers/gpu/drm/i915/intel_display.c
32682@@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
32683
32684 wait_event(dev_priv->pending_flip_queue,
32685 atomic_read(&dev_priv->mm.wedged) ||
32686- atomic_read(&obj->pending_flip) == 0);
32687+ atomic_read_unchecked(&obj->pending_flip) == 0);
32688
32689 /* Big Hammer, we also need to ensure that any pending
32690 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
32691@@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
32692
32693 obj = work->old_fb_obj;
32694
32695- atomic_clear_mask(1 << intel_crtc->plane,
32696- &obj->pending_flip.counter);
32697+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
32698 wake_up(&dev_priv->pending_flip_queue);
32699
32700 queue_work(dev_priv->wq, &work->work);
32701@@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32702 /* Block clients from rendering to the new back buffer until
32703 * the flip occurs and the object is no longer visible.
32704 */
32705- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32706+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32707 atomic_inc(&intel_crtc->unpin_work_count);
32708
32709 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
32710@@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32711
32712 cleanup_pending:
32713 atomic_dec(&intel_crtc->unpin_work_count);
32714- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32715+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
32716 drm_gem_object_unreference(&work->old_fb_obj->base);
32717 drm_gem_object_unreference(&obj->base);
32718 mutex_unlock(&dev->struct_mutex);
32719diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
32720index 54558a0..2d97005 100644
32721--- a/drivers/gpu/drm/mga/mga_drv.h
32722+++ b/drivers/gpu/drm/mga/mga_drv.h
32723@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
32724 u32 clear_cmd;
32725 u32 maccess;
32726
32727- atomic_t vbl_received; /**< Number of vblanks received. */
32728+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
32729 wait_queue_head_t fence_queue;
32730- atomic_t last_fence_retired;
32731+ atomic_unchecked_t last_fence_retired;
32732 u32 next_fence_to_post;
32733
32734 unsigned int fb_cpp;
32735diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
32736index 598c281..60d590e 100644
32737--- a/drivers/gpu/drm/mga/mga_irq.c
32738+++ b/drivers/gpu/drm/mga/mga_irq.c
32739@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
32740 if (crtc != 0)
32741 return 0;
32742
32743- return atomic_read(&dev_priv->vbl_received);
32744+ return atomic_read_unchecked(&dev_priv->vbl_received);
32745 }
32746
32747
32748@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32749 /* VBLANK interrupt */
32750 if (status & MGA_VLINEPEN) {
32751 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
32752- atomic_inc(&dev_priv->vbl_received);
32753+ atomic_inc_unchecked(&dev_priv->vbl_received);
32754 drm_handle_vblank(dev, 0);
32755 handled = 1;
32756 }
32757@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
32758 if ((prim_start & ~0x03) != (prim_end & ~0x03))
32759 MGA_WRITE(MGA_PRIMEND, prim_end);
32760
32761- atomic_inc(&dev_priv->last_fence_retired);
32762+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
32763 DRM_WAKEUP(&dev_priv->fence_queue);
32764 handled = 1;
32765 }
32766@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
32767 * using fences.
32768 */
32769 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
32770- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
32771+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
32772 - *sequence) <= (1 << 23)));
32773
32774 *sequence = cur_fence;
32775diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
32776index 09fdef2..57f5c3b 100644
32777--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
32778+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
32779@@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
32780 struct bit_table {
32781 const char id;
32782 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
32783-};
32784+} __no_const;
32785
32786 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
32787
32788diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
32789index a101699..a163f0a 100644
32790--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
32791+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
32792@@ -80,7 +80,7 @@ struct nouveau_drm {
32793 struct drm_global_reference mem_global_ref;
32794 struct ttm_bo_global_ref bo_global_ref;
32795 struct ttm_bo_device bdev;
32796- atomic_t validate_sequence;
32797+ atomic_unchecked_t validate_sequence;
32798 int (*move)(struct nouveau_channel *,
32799 struct ttm_buffer_object *,
32800 struct ttm_mem_reg *, struct ttm_mem_reg *);
32801diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
32802index cdb83ac..27f0a16 100644
32803--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
32804+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
32805@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
32806 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
32807 struct nouveau_channel *);
32808 u32 (*read)(struct nouveau_channel *);
32809-};
32810+} __no_const;
32811
32812 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
32813
32814diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
32815index 5e2f521..0d21436 100644
32816--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
32817+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
32818@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
32819 int trycnt = 0;
32820 int ret, i;
32821
32822- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
32823+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
32824 retry:
32825 if (++trycnt > 100000) {
32826 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
32827diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
32828index 6f0ac64..9c2dfb4 100644
32829--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
32830+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
32831@@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
32832 bool can_switch;
32833
32834 spin_lock(&dev->count_lock);
32835- can_switch = (dev->open_count == 0);
32836+ can_switch = (local_read(&dev->open_count) == 0);
32837 spin_unlock(&dev->count_lock);
32838 return can_switch;
32839 }
32840diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
32841index 9f6f55c..30e3a29 100644
32842--- a/drivers/gpu/drm/nouveau/nv50_evo.c
32843+++ b/drivers/gpu/drm/nouveau/nv50_evo.c
32844@@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
32845 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
32846 evo->object->oclass->ofuncs =
32847 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
32848- evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32849- evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32850- evo->object->oclass->ofuncs->rd08 =
32851+ *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
32852+ *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
32853+ *(void**)&evo->object->oclass->ofuncs->rd08 =
32854 ioremap(pci_resource_start(dev->pdev, 0) +
32855 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
32856 return 0;
32857diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
32858index b562b59..9d725a8 100644
32859--- a/drivers/gpu/drm/nouveau/nv50_sor.c
32860+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
32861@@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
32862 }
32863
32864 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32865- struct dp_train_func func = {
32866+ static struct dp_train_func func = {
32867 .link_set = nv50_sor_dp_link_set,
32868 .train_set = nv50_sor_dp_train_set,
32869 .train_adj = nv50_sor_dp_train_adj
32870diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
32871index c402fca..f1d694b 100644
32872--- a/drivers/gpu/drm/nouveau/nvd0_display.c
32873+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
32874@@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
32875 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
32876
32877 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
32878- struct dp_train_func func = {
32879+ static struct dp_train_func func = {
32880 .link_set = nvd0_sor_dp_link_set,
32881 .train_set = nvd0_sor_dp_train_set,
32882 .train_adj = nvd0_sor_dp_train_adj
32883diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
32884index d4660cf..70dbe65 100644
32885--- a/drivers/gpu/drm/r128/r128_cce.c
32886+++ b/drivers/gpu/drm/r128/r128_cce.c
32887@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
32888
32889 /* GH: Simple idle check.
32890 */
32891- atomic_set(&dev_priv->idle_count, 0);
32892+ atomic_set_unchecked(&dev_priv->idle_count, 0);
32893
32894 /* We don't support anything other than bus-mastering ring mode,
32895 * but the ring can be in either AGP or PCI space for the ring
32896diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
32897index 930c71b..499aded 100644
32898--- a/drivers/gpu/drm/r128/r128_drv.h
32899+++ b/drivers/gpu/drm/r128/r128_drv.h
32900@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
32901 int is_pci;
32902 unsigned long cce_buffers_offset;
32903
32904- atomic_t idle_count;
32905+ atomic_unchecked_t idle_count;
32906
32907 int page_flipping;
32908 int current_page;
32909 u32 crtc_offset;
32910 u32 crtc_offset_cntl;
32911
32912- atomic_t vbl_received;
32913+ atomic_unchecked_t vbl_received;
32914
32915 u32 color_fmt;
32916 unsigned int front_offset;
32917diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
32918index 2ea4f09..d391371 100644
32919--- a/drivers/gpu/drm/r128/r128_irq.c
32920+++ b/drivers/gpu/drm/r128/r128_irq.c
32921@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
32922 if (crtc != 0)
32923 return 0;
32924
32925- return atomic_read(&dev_priv->vbl_received);
32926+ return atomic_read_unchecked(&dev_priv->vbl_received);
32927 }
32928
32929 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32930@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
32931 /* VBLANK interrupt */
32932 if (status & R128_CRTC_VBLANK_INT) {
32933 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
32934- atomic_inc(&dev_priv->vbl_received);
32935+ atomic_inc_unchecked(&dev_priv->vbl_received);
32936 drm_handle_vblank(dev, 0);
32937 return IRQ_HANDLED;
32938 }
32939diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
32940index 19bb7e6..de7e2a2 100644
32941--- a/drivers/gpu/drm/r128/r128_state.c
32942+++ b/drivers/gpu/drm/r128/r128_state.c
32943@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
32944
32945 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
32946 {
32947- if (atomic_read(&dev_priv->idle_count) == 0)
32948+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
32949 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
32950 else
32951- atomic_set(&dev_priv->idle_count, 0);
32952+ atomic_set_unchecked(&dev_priv->idle_count, 0);
32953 }
32954
32955 #endif
32956diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
32957index 5a82b6b..9e69c73 100644
32958--- a/drivers/gpu/drm/radeon/mkregtable.c
32959+++ b/drivers/gpu/drm/radeon/mkregtable.c
32960@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
32961 regex_t mask_rex;
32962 regmatch_t match[4];
32963 char buf[1024];
32964- size_t end;
32965+ long end;
32966 int len;
32967 int done = 0;
32968 int r;
32969 unsigned o;
32970 struct offset *offset;
32971 char last_reg_s[10];
32972- int last_reg;
32973+ unsigned long last_reg;
32974
32975 if (regcomp
32976 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
32977diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
32978index 008d645..de03849 100644
32979--- a/drivers/gpu/drm/radeon/radeon_device.c
32980+++ b/drivers/gpu/drm/radeon/radeon_device.c
32981@@ -941,7 +941,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
32982 bool can_switch;
32983
32984 spin_lock(&dev->count_lock);
32985- can_switch = (dev->open_count == 0);
32986+ can_switch = (local_read(&dev->open_count) == 0);
32987 spin_unlock(&dev->count_lock);
32988 return can_switch;
32989 }
32990diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
32991index a1b59ca..86f2d44 100644
32992--- a/drivers/gpu/drm/radeon/radeon_drv.h
32993+++ b/drivers/gpu/drm/radeon/radeon_drv.h
32994@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
32995
32996 /* SW interrupt */
32997 wait_queue_head_t swi_queue;
32998- atomic_t swi_emitted;
32999+ atomic_unchecked_t swi_emitted;
33000 int vblank_crtc;
33001 uint32_t irq_enable_reg;
33002 uint32_t r500_disp_irq_reg;
33003diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33004index c180df8..cd80dd2d 100644
33005--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33006+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33007@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33008 request = compat_alloc_user_space(sizeof(*request));
33009 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33010 || __put_user(req32.param, &request->param)
33011- || __put_user((void __user *)(unsigned long)req32.value,
33012+ || __put_user((unsigned long)req32.value,
33013 &request->value))
33014 return -EFAULT;
33015
33016diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33017index e771033..a0bc6b3 100644
33018--- a/drivers/gpu/drm/radeon/radeon_irq.c
33019+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33020@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33021 unsigned int ret;
33022 RING_LOCALS;
33023
33024- atomic_inc(&dev_priv->swi_emitted);
33025- ret = atomic_read(&dev_priv->swi_emitted);
33026+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33027+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33028
33029 BEGIN_RING(4);
33030 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33031@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33032 drm_radeon_private_t *dev_priv =
33033 (drm_radeon_private_t *) dev->dev_private;
33034
33035- atomic_set(&dev_priv->swi_emitted, 0);
33036+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33037 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33038
33039 dev->max_vblank_count = 0x001fffff;
33040diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33041index 8e9057b..af6dacb 100644
33042--- a/drivers/gpu/drm/radeon/radeon_state.c
33043+++ b/drivers/gpu/drm/radeon/radeon_state.c
33044@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33045 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33046 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33047
33048- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33049+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33050 sarea_priv->nbox * sizeof(depth_boxes[0])))
33051 return -EFAULT;
33052
33053@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33054 {
33055 drm_radeon_private_t *dev_priv = dev->dev_private;
33056 drm_radeon_getparam_t *param = data;
33057- int value;
33058+ int value = 0;
33059
33060 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33061
33062diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33063index 5ebe1b3..44209ea 100644
33064--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33065+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33066@@ -781,7 +781,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
33067 man->size = size >> PAGE_SHIFT;
33068 }
33069
33070-static struct vm_operations_struct radeon_ttm_vm_ops;
33071+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
33072 static const struct vm_operations_struct *ttm_vm_ops = NULL;
33073
33074 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
33075diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33076index 5706d2a..17aedaa 100644
33077--- a/drivers/gpu/drm/radeon/rs690.c
33078+++ b/drivers/gpu/drm/radeon/rs690.c
33079@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33080 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33081 rdev->pm.sideport_bandwidth.full)
33082 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33083- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33084+ read_delay_latency.full = dfixed_const(800 * 1000);
33085 read_delay_latency.full = dfixed_div(read_delay_latency,
33086 rdev->pm.igp_sideport_mclk);
33087+ a.full = dfixed_const(370);
33088+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33089 } else {
33090 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33091 rdev->pm.k8_bandwidth.full)
33092diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33093index bd2a3b4..122d9ad 100644
33094--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33095+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33096@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33097 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33098 struct shrink_control *sc)
33099 {
33100- static atomic_t start_pool = ATOMIC_INIT(0);
33101+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33102 unsigned i;
33103- unsigned pool_offset = atomic_add_return(1, &start_pool);
33104+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33105 struct ttm_page_pool *pool;
33106 int shrink_pages = sc->nr_to_scan;
33107
33108diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33109index 893a650..6190d3b 100644
33110--- a/drivers/gpu/drm/via/via_drv.h
33111+++ b/drivers/gpu/drm/via/via_drv.h
33112@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33113 typedef uint32_t maskarray_t[5];
33114
33115 typedef struct drm_via_irq {
33116- atomic_t irq_received;
33117+ atomic_unchecked_t irq_received;
33118 uint32_t pending_mask;
33119 uint32_t enable_mask;
33120 wait_queue_head_t irq_queue;
33121@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33122 struct timeval last_vblank;
33123 int last_vblank_valid;
33124 unsigned usec_per_vblank;
33125- atomic_t vbl_received;
33126+ atomic_unchecked_t vbl_received;
33127 drm_via_state_t hc_state;
33128 char pci_buf[VIA_PCI_BUF_SIZE];
33129 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33130diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33131index ac98964..5dbf512 100644
33132--- a/drivers/gpu/drm/via/via_irq.c
33133+++ b/drivers/gpu/drm/via/via_irq.c
33134@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33135 if (crtc != 0)
33136 return 0;
33137
33138- return atomic_read(&dev_priv->vbl_received);
33139+ return atomic_read_unchecked(&dev_priv->vbl_received);
33140 }
33141
33142 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33143@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33144
33145 status = VIA_READ(VIA_REG_INTERRUPT);
33146 if (status & VIA_IRQ_VBLANK_PENDING) {
33147- atomic_inc(&dev_priv->vbl_received);
33148- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33149+ atomic_inc_unchecked(&dev_priv->vbl_received);
33150+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33151 do_gettimeofday(&cur_vblank);
33152 if (dev_priv->last_vblank_valid) {
33153 dev_priv->usec_per_vblank =
33154@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33155 dev_priv->last_vblank = cur_vblank;
33156 dev_priv->last_vblank_valid = 1;
33157 }
33158- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33159+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33160 DRM_DEBUG("US per vblank is: %u\n",
33161 dev_priv->usec_per_vblank);
33162 }
33163@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33164
33165 for (i = 0; i < dev_priv->num_irqs; ++i) {
33166 if (status & cur_irq->pending_mask) {
33167- atomic_inc(&cur_irq->irq_received);
33168+ atomic_inc_unchecked(&cur_irq->irq_received);
33169 DRM_WAKEUP(&cur_irq->irq_queue);
33170 handled = 1;
33171 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33172@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33173 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33174 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33175 masks[irq][4]));
33176- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33177+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33178 } else {
33179 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33180 (((cur_irq_sequence =
33181- atomic_read(&cur_irq->irq_received)) -
33182+ atomic_read_unchecked(&cur_irq->irq_received)) -
33183 *sequence) <= (1 << 23)));
33184 }
33185 *sequence = cur_irq_sequence;
33186@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33187 }
33188
33189 for (i = 0; i < dev_priv->num_irqs; ++i) {
33190- atomic_set(&cur_irq->irq_received, 0);
33191+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33192 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33193 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33194 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33195@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33196 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33197 case VIA_IRQ_RELATIVE:
33198 irqwait->request.sequence +=
33199- atomic_read(&cur_irq->irq_received);
33200+ atomic_read_unchecked(&cur_irq->irq_received);
33201 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33202 case VIA_IRQ_ABSOLUTE:
33203 break;
33204diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33205index 88a179e..57fe50481c 100644
33206--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33207+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33208@@ -263,7 +263,7 @@ struct vmw_private {
33209 * Fencing and IRQs.
33210 */
33211
33212- atomic_t marker_seq;
33213+ atomic_unchecked_t marker_seq;
33214 wait_queue_head_t fence_queue;
33215 wait_queue_head_t fifo_queue;
33216 int fence_queue_waiters; /* Protected by hw_mutex */
33217diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33218index 3eb1486..0a47ee9 100644
33219--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33220+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33221@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33222 (unsigned int) min,
33223 (unsigned int) fifo->capabilities);
33224
33225- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33226+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33227 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33228 vmw_marker_queue_init(&fifo->marker_queue);
33229 return vmw_fifo_send_fence(dev_priv, &dummy);
33230@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33231 if (reserveable)
33232 iowrite32(bytes, fifo_mem +
33233 SVGA_FIFO_RESERVED);
33234- return fifo_mem + (next_cmd >> 2);
33235+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33236 } else {
33237 need_bounce = true;
33238 }
33239@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33240
33241 fm = vmw_fifo_reserve(dev_priv, bytes);
33242 if (unlikely(fm == NULL)) {
33243- *seqno = atomic_read(&dev_priv->marker_seq);
33244+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33245 ret = -ENOMEM;
33246 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33247 false, 3*HZ);
33248@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33249 }
33250
33251 do {
33252- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33253+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33254 } while (*seqno == 0);
33255
33256 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33257diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33258index 4640adb..e1384ed 100644
33259--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33260+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33261@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33262 * emitted. Then the fence is stale and signaled.
33263 */
33264
33265- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33266+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33267 > VMW_FENCE_WRAP);
33268
33269 return ret;
33270@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33271
33272 if (fifo_idle)
33273 down_read(&fifo_state->rwsem);
33274- signal_seq = atomic_read(&dev_priv->marker_seq);
33275+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33276 ret = 0;
33277
33278 for (;;) {
33279diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33280index 8a8725c..afed796 100644
33281--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33282+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33283@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33284 while (!vmw_lag_lt(queue, us)) {
33285 spin_lock(&queue->lock);
33286 if (list_empty(&queue->head))
33287- seqno = atomic_read(&dev_priv->marker_seq);
33288+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33289 else {
33290 marker = list_first_entry(&queue->head,
33291 struct vmw_marker, head);
33292diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33293index 52146db..ae33762 100644
33294--- a/drivers/hid/hid-core.c
33295+++ b/drivers/hid/hid-core.c
33296@@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33297
33298 int hid_add_device(struct hid_device *hdev)
33299 {
33300- static atomic_t id = ATOMIC_INIT(0);
33301+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33302 int ret;
33303
33304 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33305@@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33306 /* XXX hack, any other cleaner solution after the driver core
33307 * is converted to allow more than 20 bytes as the device name? */
33308 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33309- hdev->vendor, hdev->product, atomic_inc_return(&id));
33310+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33311
33312 hid_debug_register(hdev, dev_name(&hdev->dev));
33313 ret = device_add(&hdev->dev);
33314diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33315index eec3291..8ed706b 100644
33316--- a/drivers/hid/hid-wiimote-debug.c
33317+++ b/drivers/hid/hid-wiimote-debug.c
33318@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33319 else if (size == 0)
33320 return -EIO;
33321
33322- if (copy_to_user(u, buf, size))
33323+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
33324 return -EFAULT;
33325
33326 *off += size;
33327diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33328index 14599e2..711c965 100644
33329--- a/drivers/hid/usbhid/hiddev.c
33330+++ b/drivers/hid/usbhid/hiddev.c
33331@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33332 break;
33333
33334 case HIDIOCAPPLICATION:
33335- if (arg < 0 || arg >= hid->maxapplication)
33336+ if (arg >= hid->maxapplication)
33337 break;
33338
33339 for (i = 0; i < hid->maxcollection; i++)
33340diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33341index f4c3d28..82f45a9 100644
33342--- a/drivers/hv/channel.c
33343+++ b/drivers/hv/channel.c
33344@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33345 int ret = 0;
33346 int t;
33347
33348- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33349- atomic_inc(&vmbus_connection.next_gpadl_handle);
33350+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33351+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33352
33353 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33354 if (ret)
33355diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33356index 3648f8f..30ef30d 100644
33357--- a/drivers/hv/hv.c
33358+++ b/drivers/hv/hv.c
33359@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33360 u64 output_address = (output) ? virt_to_phys(output) : 0;
33361 u32 output_address_hi = output_address >> 32;
33362 u32 output_address_lo = output_address & 0xFFFFFFFF;
33363- void *hypercall_page = hv_context.hypercall_page;
33364+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33365
33366 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33367 "=a"(hv_status_lo) : "d" (control_hi),
33368diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33369index d8d1fad..b91caf7 100644
33370--- a/drivers/hv/hyperv_vmbus.h
33371+++ b/drivers/hv/hyperv_vmbus.h
33372@@ -594,7 +594,7 @@ enum vmbus_connect_state {
33373 struct vmbus_connection {
33374 enum vmbus_connect_state conn_state;
33375
33376- atomic_t next_gpadl_handle;
33377+ atomic_unchecked_t next_gpadl_handle;
33378
33379 /*
33380 * Represents channel interrupts. Each bit position represents a
33381diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33382index 8e1a9ec..4687821 100644
33383--- a/drivers/hv/vmbus_drv.c
33384+++ b/drivers/hv/vmbus_drv.c
33385@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33386 {
33387 int ret = 0;
33388
33389- static atomic_t device_num = ATOMIC_INIT(0);
33390+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33391
33392 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33393- atomic_inc_return(&device_num));
33394+ atomic_inc_return_unchecked(&device_num));
33395
33396 child_device_obj->device.bus = &hv_bus;
33397 child_device_obj->device.parent = &hv_acpi_dev->dev;
33398diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33399index 07a0c1a..0cac334 100644
33400--- a/drivers/hwmon/sht15.c
33401+++ b/drivers/hwmon/sht15.c
33402@@ -169,7 +169,7 @@ struct sht15_data {
33403 int supply_uV;
33404 bool supply_uV_valid;
33405 struct work_struct update_supply_work;
33406- atomic_t interrupt_handled;
33407+ atomic_unchecked_t interrupt_handled;
33408 };
33409
33410 /**
33411@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33412 return ret;
33413
33414 gpio_direction_input(data->pdata->gpio_data);
33415- atomic_set(&data->interrupt_handled, 0);
33416+ atomic_set_unchecked(&data->interrupt_handled, 0);
33417
33418 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33419 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33420 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33421 /* Only relevant if the interrupt hasn't occurred. */
33422- if (!atomic_read(&data->interrupt_handled))
33423+ if (!atomic_read_unchecked(&data->interrupt_handled))
33424 schedule_work(&data->read_work);
33425 }
33426 ret = wait_event_timeout(data->wait_queue,
33427@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33428
33429 /* First disable the interrupt */
33430 disable_irq_nosync(irq);
33431- atomic_inc(&data->interrupt_handled);
33432+ atomic_inc_unchecked(&data->interrupt_handled);
33433 /* Then schedule a reading work struct */
33434 if (data->state != SHT15_READING_NOTHING)
33435 schedule_work(&data->read_work);
33436@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33437 * If not, then start the interrupt again - care here as could
33438 * have gone low in meantime so verify it hasn't!
33439 */
33440- atomic_set(&data->interrupt_handled, 0);
33441+ atomic_set_unchecked(&data->interrupt_handled, 0);
33442 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33443 /* If still not occurred or another handler was scheduled */
33444 if (gpio_get_value(data->pdata->gpio_data)
33445- || atomic_read(&data->interrupt_handled))
33446+ || atomic_read_unchecked(&data->interrupt_handled))
33447 return;
33448 }
33449
33450diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33451index 378fcb5..5e91fa8 100644
33452--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33453+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33454@@ -43,7 +43,7 @@
33455 extern struct i2c_adapter amd756_smbus;
33456
33457 static struct i2c_adapter *s4882_adapter;
33458-static struct i2c_algorithm *s4882_algo;
33459+static i2c_algorithm_no_const *s4882_algo;
33460
33461 /* Wrapper access functions for multiplexed SMBus */
33462 static DEFINE_MUTEX(amd756_lock);
33463diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33464index 29015eb..af2d8e9 100644
33465--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33466+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33467@@ -41,7 +41,7 @@
33468 extern struct i2c_adapter *nforce2_smbus;
33469
33470 static struct i2c_adapter *s4985_adapter;
33471-static struct i2c_algorithm *s4985_algo;
33472+static i2c_algorithm_no_const *s4985_algo;
33473
33474 /* Wrapper access functions for multiplexed SMBus */
33475 static DEFINE_MUTEX(nforce2_lock);
33476diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33477index 8126824..55a2798 100644
33478--- a/drivers/ide/ide-cd.c
33479+++ b/drivers/ide/ide-cd.c
33480@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33481 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33482 if ((unsigned long)buf & alignment
33483 || blk_rq_bytes(rq) & q->dma_pad_mask
33484- || object_is_on_stack(buf))
33485+ || object_starts_on_stack(buf))
33486 drive->dma = 0;
33487 }
33488 }
33489diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33490index 394fea2..c833880 100644
33491--- a/drivers/infiniband/core/cm.c
33492+++ b/drivers/infiniband/core/cm.c
33493@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33494
33495 struct cm_counter_group {
33496 struct kobject obj;
33497- atomic_long_t counter[CM_ATTR_COUNT];
33498+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33499 };
33500
33501 struct cm_counter_attribute {
33502@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33503 struct ib_mad_send_buf *msg = NULL;
33504 int ret;
33505
33506- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33507+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33508 counter[CM_REQ_COUNTER]);
33509
33510 /* Quick state check to discard duplicate REQs. */
33511@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33512 if (!cm_id_priv)
33513 return;
33514
33515- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33516+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33517 counter[CM_REP_COUNTER]);
33518 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33519 if (ret)
33520@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33521 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33522 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33523 spin_unlock_irq(&cm_id_priv->lock);
33524- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33525+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33526 counter[CM_RTU_COUNTER]);
33527 goto out;
33528 }
33529@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33530 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33531 dreq_msg->local_comm_id);
33532 if (!cm_id_priv) {
33533- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33534+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33535 counter[CM_DREQ_COUNTER]);
33536 cm_issue_drep(work->port, work->mad_recv_wc);
33537 return -EINVAL;
33538@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33539 case IB_CM_MRA_REP_RCVD:
33540 break;
33541 case IB_CM_TIMEWAIT:
33542- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33543+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33544 counter[CM_DREQ_COUNTER]);
33545 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33546 goto unlock;
33547@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33548 cm_free_msg(msg);
33549 goto deref;
33550 case IB_CM_DREQ_RCVD:
33551- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33552+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33553 counter[CM_DREQ_COUNTER]);
33554 goto unlock;
33555 default:
33556@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33557 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33558 cm_id_priv->msg, timeout)) {
33559 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33560- atomic_long_inc(&work->port->
33561+ atomic_long_inc_unchecked(&work->port->
33562 counter_group[CM_RECV_DUPLICATES].
33563 counter[CM_MRA_COUNTER]);
33564 goto out;
33565@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33566 break;
33567 case IB_CM_MRA_REQ_RCVD:
33568 case IB_CM_MRA_REP_RCVD:
33569- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33570+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33571 counter[CM_MRA_COUNTER]);
33572 /* fall through */
33573 default:
33574@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33575 case IB_CM_LAP_IDLE:
33576 break;
33577 case IB_CM_MRA_LAP_SENT:
33578- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33579+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33580 counter[CM_LAP_COUNTER]);
33581 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33582 goto unlock;
33583@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33584 cm_free_msg(msg);
33585 goto deref;
33586 case IB_CM_LAP_RCVD:
33587- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33588+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33589 counter[CM_LAP_COUNTER]);
33590 goto unlock;
33591 default:
33592@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33593 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33594 if (cur_cm_id_priv) {
33595 spin_unlock_irq(&cm.lock);
33596- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33597+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33598 counter[CM_SIDR_REQ_COUNTER]);
33599 goto out; /* Duplicate message. */
33600 }
33601@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33602 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33603 msg->retries = 1;
33604
33605- atomic_long_add(1 + msg->retries,
33606+ atomic_long_add_unchecked(1 + msg->retries,
33607 &port->counter_group[CM_XMIT].counter[attr_index]);
33608 if (msg->retries)
33609- atomic_long_add(msg->retries,
33610+ atomic_long_add_unchecked(msg->retries,
33611 &port->counter_group[CM_XMIT_RETRIES].
33612 counter[attr_index]);
33613
33614@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33615 }
33616
33617 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33618- atomic_long_inc(&port->counter_group[CM_RECV].
33619+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33620 counter[attr_id - CM_ATTR_ID_OFFSET]);
33621
33622 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33623@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33624 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33625
33626 return sprintf(buf, "%ld\n",
33627- atomic_long_read(&group->counter[cm_attr->index]));
33628+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33629 }
33630
33631 static const struct sysfs_ops cm_counter_ops = {
33632diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33633index 176c8f9..2627b62 100644
33634--- a/drivers/infiniband/core/fmr_pool.c
33635+++ b/drivers/infiniband/core/fmr_pool.c
33636@@ -98,8 +98,8 @@ struct ib_fmr_pool {
33637
33638 struct task_struct *thread;
33639
33640- atomic_t req_ser;
33641- atomic_t flush_ser;
33642+ atomic_unchecked_t req_ser;
33643+ atomic_unchecked_t flush_ser;
33644
33645 wait_queue_head_t force_wait;
33646 };
33647@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33648 struct ib_fmr_pool *pool = pool_ptr;
33649
33650 do {
33651- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33652+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33653 ib_fmr_batch_release(pool);
33654
33655- atomic_inc(&pool->flush_ser);
33656+ atomic_inc_unchecked(&pool->flush_ser);
33657 wake_up_interruptible(&pool->force_wait);
33658
33659 if (pool->flush_function)
33660@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33661 }
33662
33663 set_current_state(TASK_INTERRUPTIBLE);
33664- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33665+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33666 !kthread_should_stop())
33667 schedule();
33668 __set_current_state(TASK_RUNNING);
33669@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33670 pool->dirty_watermark = params->dirty_watermark;
33671 pool->dirty_len = 0;
33672 spin_lock_init(&pool->pool_lock);
33673- atomic_set(&pool->req_ser, 0);
33674- atomic_set(&pool->flush_ser, 0);
33675+ atomic_set_unchecked(&pool->req_ser, 0);
33676+ atomic_set_unchecked(&pool->flush_ser, 0);
33677 init_waitqueue_head(&pool->force_wait);
33678
33679 pool->thread = kthread_run(ib_fmr_cleanup_thread,
33680@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
33681 }
33682 spin_unlock_irq(&pool->pool_lock);
33683
33684- serial = atomic_inc_return(&pool->req_ser);
33685+ serial = atomic_inc_return_unchecked(&pool->req_ser);
33686 wake_up_process(pool->thread);
33687
33688 if (wait_event_interruptible(pool->force_wait,
33689- atomic_read(&pool->flush_ser) - serial >= 0))
33690+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
33691 return -EINTR;
33692
33693 return 0;
33694@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
33695 } else {
33696 list_add_tail(&fmr->list, &pool->dirty_list);
33697 if (++pool->dirty_len >= pool->dirty_watermark) {
33698- atomic_inc(&pool->req_ser);
33699+ atomic_inc_unchecked(&pool->req_ser);
33700 wake_up_process(pool->thread);
33701 }
33702 }
33703diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
33704index afd8179..598063f 100644
33705--- a/drivers/infiniband/hw/cxgb4/mem.c
33706+++ b/drivers/infiniband/hw/cxgb4/mem.c
33707@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33708 int err;
33709 struct fw_ri_tpte tpt;
33710 u32 stag_idx;
33711- static atomic_t key;
33712+ static atomic_unchecked_t key;
33713
33714 if (c4iw_fatal_error(rdev))
33715 return -EIO;
33716@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
33717 if (rdev->stats.stag.cur > rdev->stats.stag.max)
33718 rdev->stats.stag.max = rdev->stats.stag.cur;
33719 mutex_unlock(&rdev->stats.lock);
33720- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
33721+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
33722 }
33723 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
33724 __func__, stag_state, type, pdid, stag_idx);
33725diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
33726index 79b3dbc..96e5fcc 100644
33727--- a/drivers/infiniband/hw/ipath/ipath_rc.c
33728+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
33729@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33730 struct ib_atomic_eth *ateth;
33731 struct ipath_ack_entry *e;
33732 u64 vaddr;
33733- atomic64_t *maddr;
33734+ atomic64_unchecked_t *maddr;
33735 u64 sdata;
33736 u32 rkey;
33737 u8 next;
33738@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
33739 IB_ACCESS_REMOTE_ATOMIC)))
33740 goto nack_acc_unlck;
33741 /* Perform atomic OP and save result. */
33742- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33743+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33744 sdata = be64_to_cpu(ateth->swap_data);
33745 e = &qp->s_ack_queue[qp->r_head_ack_queue];
33746 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
33747- (u64) atomic64_add_return(sdata, maddr) - sdata :
33748+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33749 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33750 be64_to_cpu(ateth->compare_data),
33751 sdata);
33752diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
33753index 1f95bba..9530f87 100644
33754--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
33755+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
33756@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
33757 unsigned long flags;
33758 struct ib_wc wc;
33759 u64 sdata;
33760- atomic64_t *maddr;
33761+ atomic64_unchecked_t *maddr;
33762 enum ib_wc_status send_status;
33763
33764 /*
33765@@ -382,11 +382,11 @@ again:
33766 IB_ACCESS_REMOTE_ATOMIC)))
33767 goto acc_err;
33768 /* Perform atomic OP and save result. */
33769- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
33770+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
33771 sdata = wqe->wr.wr.atomic.compare_add;
33772 *(u64 *) sqp->s_sge.sge.vaddr =
33773 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
33774- (u64) atomic64_add_return(sdata, maddr) - sdata :
33775+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
33776 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
33777 sdata, wqe->wr.wr.atomic.swap);
33778 goto send_comp;
33779diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
33780index 748db2d..5f75cc3 100644
33781--- a/drivers/infiniband/hw/nes/nes.c
33782+++ b/drivers/infiniband/hw/nes/nes.c
33783@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
33784 LIST_HEAD(nes_adapter_list);
33785 static LIST_HEAD(nes_dev_list);
33786
33787-atomic_t qps_destroyed;
33788+atomic_unchecked_t qps_destroyed;
33789
33790 static unsigned int ee_flsh_adapter;
33791 static unsigned int sysfs_nonidx_addr;
33792@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
33793 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
33794 struct nes_adapter *nesadapter = nesdev->nesadapter;
33795
33796- atomic_inc(&qps_destroyed);
33797+ atomic_inc_unchecked(&qps_destroyed);
33798
33799 /* Free the control structures */
33800
33801diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
33802index 33cc589..3bd6538 100644
33803--- a/drivers/infiniband/hw/nes/nes.h
33804+++ b/drivers/infiniband/hw/nes/nes.h
33805@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
33806 extern unsigned int wqm_quanta;
33807 extern struct list_head nes_adapter_list;
33808
33809-extern atomic_t cm_connects;
33810-extern atomic_t cm_accepts;
33811-extern atomic_t cm_disconnects;
33812-extern atomic_t cm_closes;
33813-extern atomic_t cm_connecteds;
33814-extern atomic_t cm_connect_reqs;
33815-extern atomic_t cm_rejects;
33816-extern atomic_t mod_qp_timouts;
33817-extern atomic_t qps_created;
33818-extern atomic_t qps_destroyed;
33819-extern atomic_t sw_qps_destroyed;
33820+extern atomic_unchecked_t cm_connects;
33821+extern atomic_unchecked_t cm_accepts;
33822+extern atomic_unchecked_t cm_disconnects;
33823+extern atomic_unchecked_t cm_closes;
33824+extern atomic_unchecked_t cm_connecteds;
33825+extern atomic_unchecked_t cm_connect_reqs;
33826+extern atomic_unchecked_t cm_rejects;
33827+extern atomic_unchecked_t mod_qp_timouts;
33828+extern atomic_unchecked_t qps_created;
33829+extern atomic_unchecked_t qps_destroyed;
33830+extern atomic_unchecked_t sw_qps_destroyed;
33831 extern u32 mh_detected;
33832 extern u32 mh_pauses_sent;
33833 extern u32 cm_packets_sent;
33834@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
33835 extern u32 cm_packets_received;
33836 extern u32 cm_packets_dropped;
33837 extern u32 cm_packets_retrans;
33838-extern atomic_t cm_listens_created;
33839-extern atomic_t cm_listens_destroyed;
33840+extern atomic_unchecked_t cm_listens_created;
33841+extern atomic_unchecked_t cm_listens_destroyed;
33842 extern u32 cm_backlog_drops;
33843-extern atomic_t cm_loopbacks;
33844-extern atomic_t cm_nodes_created;
33845-extern atomic_t cm_nodes_destroyed;
33846-extern atomic_t cm_accel_dropped_pkts;
33847-extern atomic_t cm_resets_recvd;
33848-extern atomic_t pau_qps_created;
33849-extern atomic_t pau_qps_destroyed;
33850+extern atomic_unchecked_t cm_loopbacks;
33851+extern atomic_unchecked_t cm_nodes_created;
33852+extern atomic_unchecked_t cm_nodes_destroyed;
33853+extern atomic_unchecked_t cm_accel_dropped_pkts;
33854+extern atomic_unchecked_t cm_resets_recvd;
33855+extern atomic_unchecked_t pau_qps_created;
33856+extern atomic_unchecked_t pau_qps_destroyed;
33857
33858 extern u32 int_mod_timer_init;
33859 extern u32 int_mod_cq_depth_256;
33860diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
33861index cfaacaf..fa0722e 100644
33862--- a/drivers/infiniband/hw/nes/nes_cm.c
33863+++ b/drivers/infiniband/hw/nes/nes_cm.c
33864@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
33865 u32 cm_packets_retrans;
33866 u32 cm_packets_created;
33867 u32 cm_packets_received;
33868-atomic_t cm_listens_created;
33869-atomic_t cm_listens_destroyed;
33870+atomic_unchecked_t cm_listens_created;
33871+atomic_unchecked_t cm_listens_destroyed;
33872 u32 cm_backlog_drops;
33873-atomic_t cm_loopbacks;
33874-atomic_t cm_nodes_created;
33875-atomic_t cm_nodes_destroyed;
33876-atomic_t cm_accel_dropped_pkts;
33877-atomic_t cm_resets_recvd;
33878+atomic_unchecked_t cm_loopbacks;
33879+atomic_unchecked_t cm_nodes_created;
33880+atomic_unchecked_t cm_nodes_destroyed;
33881+atomic_unchecked_t cm_accel_dropped_pkts;
33882+atomic_unchecked_t cm_resets_recvd;
33883
33884 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
33885 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
33886@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
33887
33888 static struct nes_cm_core *g_cm_core;
33889
33890-atomic_t cm_connects;
33891-atomic_t cm_accepts;
33892-atomic_t cm_disconnects;
33893-atomic_t cm_closes;
33894-atomic_t cm_connecteds;
33895-atomic_t cm_connect_reqs;
33896-atomic_t cm_rejects;
33897+atomic_unchecked_t cm_connects;
33898+atomic_unchecked_t cm_accepts;
33899+atomic_unchecked_t cm_disconnects;
33900+atomic_unchecked_t cm_closes;
33901+atomic_unchecked_t cm_connecteds;
33902+atomic_unchecked_t cm_connect_reqs;
33903+atomic_unchecked_t cm_rejects;
33904
33905 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
33906 {
33907@@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
33908 kfree(listener);
33909 listener = NULL;
33910 ret = 0;
33911- atomic_inc(&cm_listens_destroyed);
33912+ atomic_inc_unchecked(&cm_listens_destroyed);
33913 } else {
33914 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
33915 }
33916@@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
33917 cm_node->rem_mac);
33918
33919 add_hte_node(cm_core, cm_node);
33920- atomic_inc(&cm_nodes_created);
33921+ atomic_inc_unchecked(&cm_nodes_created);
33922
33923 return cm_node;
33924 }
33925@@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
33926 }
33927
33928 atomic_dec(&cm_core->node_cnt);
33929- atomic_inc(&cm_nodes_destroyed);
33930+ atomic_inc_unchecked(&cm_nodes_destroyed);
33931 nesqp = cm_node->nesqp;
33932 if (nesqp) {
33933 nesqp->cm_node = NULL;
33934@@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
33935
33936 static void drop_packet(struct sk_buff *skb)
33937 {
33938- atomic_inc(&cm_accel_dropped_pkts);
33939+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
33940 dev_kfree_skb_any(skb);
33941 }
33942
33943@@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
33944 {
33945
33946 int reset = 0; /* whether to send reset in case of err.. */
33947- atomic_inc(&cm_resets_recvd);
33948+ atomic_inc_unchecked(&cm_resets_recvd);
33949 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
33950 " refcnt=%d\n", cm_node, cm_node->state,
33951 atomic_read(&cm_node->ref_count));
33952@@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
33953 rem_ref_cm_node(cm_node->cm_core, cm_node);
33954 return NULL;
33955 }
33956- atomic_inc(&cm_loopbacks);
33957+ atomic_inc_unchecked(&cm_loopbacks);
33958 loopbackremotenode->loopbackpartner = cm_node;
33959 loopbackremotenode->tcp_cntxt.rcv_wscale =
33960 NES_CM_DEFAULT_RCV_WND_SCALE;
33961@@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
33962 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
33963 else {
33964 rem_ref_cm_node(cm_core, cm_node);
33965- atomic_inc(&cm_accel_dropped_pkts);
33966+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
33967 dev_kfree_skb_any(skb);
33968 }
33969 break;
33970@@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33971
33972 if ((cm_id) && (cm_id->event_handler)) {
33973 if (issue_disconn) {
33974- atomic_inc(&cm_disconnects);
33975+ atomic_inc_unchecked(&cm_disconnects);
33976 cm_event.event = IW_CM_EVENT_DISCONNECT;
33977 cm_event.status = disconn_status;
33978 cm_event.local_addr = cm_id->local_addr;
33979@@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
33980 }
33981
33982 if (issue_close) {
33983- atomic_inc(&cm_closes);
33984+ atomic_inc_unchecked(&cm_closes);
33985 nes_disconnect(nesqp, 1);
33986
33987 cm_id->provider_data = nesqp;
33988@@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
33989
33990 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
33991 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
33992- atomic_inc(&cm_accepts);
33993+ atomic_inc_unchecked(&cm_accepts);
33994
33995 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
33996 netdev_refcnt_read(nesvnic->netdev));
33997@@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
33998 struct nes_cm_core *cm_core;
33999 u8 *start_buff;
34000
34001- atomic_inc(&cm_rejects);
34002+ atomic_inc_unchecked(&cm_rejects);
34003 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34004 loopback = cm_node->loopbackpartner;
34005 cm_core = cm_node->cm_core;
34006@@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34007 ntohl(cm_id->local_addr.sin_addr.s_addr),
34008 ntohs(cm_id->local_addr.sin_port));
34009
34010- atomic_inc(&cm_connects);
34011+ atomic_inc_unchecked(&cm_connects);
34012 nesqp->active_conn = 1;
34013
34014 /* cache the cm_id in the qp */
34015@@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34016 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34017 return err;
34018 }
34019- atomic_inc(&cm_listens_created);
34020+ atomic_inc_unchecked(&cm_listens_created);
34021 }
34022
34023 cm_id->add_ref(cm_id);
34024@@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34025
34026 if (nesqp->destroyed)
34027 return;
34028- atomic_inc(&cm_connecteds);
34029+ atomic_inc_unchecked(&cm_connecteds);
34030 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34031 " local port 0x%04X. jiffies = %lu.\n",
34032 nesqp->hwqp.qp_id,
34033@@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34034
34035 cm_id->add_ref(cm_id);
34036 ret = cm_id->event_handler(cm_id, &cm_event);
34037- atomic_inc(&cm_closes);
34038+ atomic_inc_unchecked(&cm_closes);
34039 cm_event.event = IW_CM_EVENT_CLOSE;
34040 cm_event.status = 0;
34041 cm_event.provider_data = cm_id->provider_data;
34042@@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34043 return;
34044 cm_id = cm_node->cm_id;
34045
34046- atomic_inc(&cm_connect_reqs);
34047+ atomic_inc_unchecked(&cm_connect_reqs);
34048 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34049 cm_node, cm_id, jiffies);
34050
34051@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34052 return;
34053 cm_id = cm_node->cm_id;
34054
34055- atomic_inc(&cm_connect_reqs);
34056+ atomic_inc_unchecked(&cm_connect_reqs);
34057 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34058 cm_node, cm_id, jiffies);
34059
34060diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34061index 3ba7be3..c81f6ff 100644
34062--- a/drivers/infiniband/hw/nes/nes_mgt.c
34063+++ b/drivers/infiniband/hw/nes/nes_mgt.c
34064@@ -40,8 +40,8 @@
34065 #include "nes.h"
34066 #include "nes_mgt.h"
34067
34068-atomic_t pau_qps_created;
34069-atomic_t pau_qps_destroyed;
34070+atomic_unchecked_t pau_qps_created;
34071+atomic_unchecked_t pau_qps_destroyed;
34072
34073 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34074 {
34075@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34076 {
34077 struct sk_buff *skb;
34078 unsigned long flags;
34079- atomic_inc(&pau_qps_destroyed);
34080+ atomic_inc_unchecked(&pau_qps_destroyed);
34081
34082 /* Free packets that have not yet been forwarded */
34083 /* Lock is acquired by skb_dequeue when removing the skb */
34084@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34085 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34086 skb_queue_head_init(&nesqp->pau_list);
34087 spin_lock_init(&nesqp->pau_lock);
34088- atomic_inc(&pau_qps_created);
34089+ atomic_inc_unchecked(&pau_qps_created);
34090 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34091 }
34092
34093diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34094index 0564be7..f68b0f1 100644
34095--- a/drivers/infiniband/hw/nes/nes_nic.c
34096+++ b/drivers/infiniband/hw/nes/nes_nic.c
34097@@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34098 target_stat_values[++index] = mh_detected;
34099 target_stat_values[++index] = mh_pauses_sent;
34100 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34101- target_stat_values[++index] = atomic_read(&cm_connects);
34102- target_stat_values[++index] = atomic_read(&cm_accepts);
34103- target_stat_values[++index] = atomic_read(&cm_disconnects);
34104- target_stat_values[++index] = atomic_read(&cm_connecteds);
34105- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34106- target_stat_values[++index] = atomic_read(&cm_rejects);
34107- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34108- target_stat_values[++index] = atomic_read(&qps_created);
34109- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34110- target_stat_values[++index] = atomic_read(&qps_destroyed);
34111- target_stat_values[++index] = atomic_read(&cm_closes);
34112+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34113+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34114+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34115+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34116+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34117+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34118+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34119+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34120+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34121+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34122+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34123 target_stat_values[++index] = cm_packets_sent;
34124 target_stat_values[++index] = cm_packets_bounced;
34125 target_stat_values[++index] = cm_packets_created;
34126 target_stat_values[++index] = cm_packets_received;
34127 target_stat_values[++index] = cm_packets_dropped;
34128 target_stat_values[++index] = cm_packets_retrans;
34129- target_stat_values[++index] = atomic_read(&cm_listens_created);
34130- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34131+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34132+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34133 target_stat_values[++index] = cm_backlog_drops;
34134- target_stat_values[++index] = atomic_read(&cm_loopbacks);
34135- target_stat_values[++index] = atomic_read(&cm_nodes_created);
34136- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34137- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34138- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34139+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34140+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34141+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34142+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34143+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34144 target_stat_values[++index] = nesadapter->free_4kpbl;
34145 target_stat_values[++index] = nesadapter->free_256pbl;
34146 target_stat_values[++index] = int_mod_timer_init;
34147 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34148 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34149 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34150- target_stat_values[++index] = atomic_read(&pau_qps_created);
34151- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34152+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34153+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34154 }
34155
34156 /**
34157diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34158index 07e4fba..685f041 100644
34159--- a/drivers/infiniband/hw/nes/nes_verbs.c
34160+++ b/drivers/infiniband/hw/nes/nes_verbs.c
34161@@ -46,9 +46,9 @@
34162
34163 #include <rdma/ib_umem.h>
34164
34165-atomic_t mod_qp_timouts;
34166-atomic_t qps_created;
34167-atomic_t sw_qps_destroyed;
34168+atomic_unchecked_t mod_qp_timouts;
34169+atomic_unchecked_t qps_created;
34170+atomic_unchecked_t sw_qps_destroyed;
34171
34172 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34173
34174@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34175 if (init_attr->create_flags)
34176 return ERR_PTR(-EINVAL);
34177
34178- atomic_inc(&qps_created);
34179+ atomic_inc_unchecked(&qps_created);
34180 switch (init_attr->qp_type) {
34181 case IB_QPT_RC:
34182 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34183@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34184 struct iw_cm_event cm_event;
34185 int ret = 0;
34186
34187- atomic_inc(&sw_qps_destroyed);
34188+ atomic_inc_unchecked(&sw_qps_destroyed);
34189 nesqp->destroyed = 1;
34190
34191 /* Blow away the connection if it exists. */
34192diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34193index 4d11575..3e890e5 100644
34194--- a/drivers/infiniband/hw/qib/qib.h
34195+++ b/drivers/infiniband/hw/qib/qib.h
34196@@ -51,6 +51,7 @@
34197 #include <linux/completion.h>
34198 #include <linux/kref.h>
34199 #include <linux/sched.h>
34200+#include <linux/slab.h>
34201
34202 #include "qib_common.h"
34203 #include "qib_verbs.h"
34204diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34205index da739d9..da1c7f4 100644
34206--- a/drivers/input/gameport/gameport.c
34207+++ b/drivers/input/gameport/gameport.c
34208@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34209 */
34210 static void gameport_init_port(struct gameport *gameport)
34211 {
34212- static atomic_t gameport_no = ATOMIC_INIT(0);
34213+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34214
34215 __module_get(THIS_MODULE);
34216
34217 mutex_init(&gameport->drv_mutex);
34218 device_initialize(&gameport->dev);
34219 dev_set_name(&gameport->dev, "gameport%lu",
34220- (unsigned long)atomic_inc_return(&gameport_no) - 1);
34221+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34222 gameport->dev.bus = &gameport_bus;
34223 gameport->dev.release = gameport_release_port;
34224 if (gameport->parent)
34225diff --git a/drivers/input/input.c b/drivers/input/input.c
34226index 53a0dde..abffda7 100644
34227--- a/drivers/input/input.c
34228+++ b/drivers/input/input.c
34229@@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34230 */
34231 int input_register_device(struct input_dev *dev)
34232 {
34233- static atomic_t input_no = ATOMIC_INIT(0);
34234+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34235 struct input_handler *handler;
34236 unsigned int packet_size;
34237 const char *path;
34238@@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34239 dev->setkeycode = input_default_setkeycode;
34240
34241 dev_set_name(&dev->dev, "input%ld",
34242- (unsigned long) atomic_inc_return(&input_no) - 1);
34243+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34244
34245 error = device_add(&dev->dev);
34246 if (error)
34247diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34248index 04c69af..5f92d00 100644
34249--- a/drivers/input/joystick/sidewinder.c
34250+++ b/drivers/input/joystick/sidewinder.c
34251@@ -30,6 +30,7 @@
34252 #include <linux/kernel.h>
34253 #include <linux/module.h>
34254 #include <linux/slab.h>
34255+#include <linux/sched.h>
34256 #include <linux/init.h>
34257 #include <linux/input.h>
34258 #include <linux/gameport.h>
34259diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34260index 83811e4..0822b90 100644
34261--- a/drivers/input/joystick/xpad.c
34262+++ b/drivers/input/joystick/xpad.c
34263@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34264
34265 static int xpad_led_probe(struct usb_xpad *xpad)
34266 {
34267- static atomic_t led_seq = ATOMIC_INIT(0);
34268+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34269 long led_no;
34270 struct xpad_led *led;
34271 struct led_classdev *led_cdev;
34272@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34273 if (!led)
34274 return -ENOMEM;
34275
34276- led_no = (long)atomic_inc_return(&led_seq) - 1;
34277+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34278
34279 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34280 led->xpad = xpad;
34281diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34282index 4c842c3..590b0bf 100644
34283--- a/drivers/input/mousedev.c
34284+++ b/drivers/input/mousedev.c
34285@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34286
34287 spin_unlock_irq(&client->packet_lock);
34288
34289- if (copy_to_user(buffer, data, count))
34290+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
34291 return -EFAULT;
34292
34293 return count;
34294diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34295index d0f7533..fb8215b 100644
34296--- a/drivers/input/serio/serio.c
34297+++ b/drivers/input/serio/serio.c
34298@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34299 */
34300 static void serio_init_port(struct serio *serio)
34301 {
34302- static atomic_t serio_no = ATOMIC_INIT(0);
34303+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34304
34305 __module_get(THIS_MODULE);
34306
34307@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34308 mutex_init(&serio->drv_mutex);
34309 device_initialize(&serio->dev);
34310 dev_set_name(&serio->dev, "serio%ld",
34311- (long)atomic_inc_return(&serio_no) - 1);
34312+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
34313 serio->dev.bus = &serio_bus;
34314 serio->dev.release = serio_release_port;
34315 serio->dev.groups = serio_device_attr_groups;
34316diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34317index c679867..6e2e34d 100644
34318--- a/drivers/isdn/capi/capi.c
34319+++ b/drivers/isdn/capi/capi.c
34320@@ -83,8 +83,8 @@ struct capiminor {
34321
34322 struct capi20_appl *ap;
34323 u32 ncci;
34324- atomic_t datahandle;
34325- atomic_t msgid;
34326+ atomic_unchecked_t datahandle;
34327+ atomic_unchecked_t msgid;
34328
34329 struct tty_port port;
34330 int ttyinstop;
34331@@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34332 capimsg_setu16(s, 2, mp->ap->applid);
34333 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34334 capimsg_setu8 (s, 5, CAPI_RESP);
34335- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34336+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34337 capimsg_setu32(s, 8, mp->ncci);
34338 capimsg_setu16(s, 12, datahandle);
34339 }
34340@@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34341 mp->outbytes -= len;
34342 spin_unlock_bh(&mp->outlock);
34343
34344- datahandle = atomic_inc_return(&mp->datahandle);
34345+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34346 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34347 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34348 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34349 capimsg_setu16(skb->data, 2, mp->ap->applid);
34350 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34351 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34352- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34353+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34354 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34355 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34356 capimsg_setu16(skb->data, 16, len); /* Data length */
34357diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34358index 67abf3f..076b3a6 100644
34359--- a/drivers/isdn/gigaset/interface.c
34360+++ b/drivers/isdn/gigaset/interface.c
34361@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34362 }
34363 tty->driver_data = cs;
34364
34365- ++cs->port.count;
34366+ atomic_inc(&cs->port.count);
34367
34368- if (cs->port.count == 1) {
34369+ if (atomic_read(&cs->port.count) == 1) {
34370 tty_port_tty_set(&cs->port, tty);
34371 tty->low_latency = 1;
34372 }
34373@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34374
34375 if (!cs->connected)
34376 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34377- else if (!cs->port.count)
34378+ else if (!atomic_read(&cs->port.count))
34379 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34380- else if (!--cs->port.count)
34381+ else if (!atomic_dec_return(&cs->port.count))
34382 tty_port_tty_set(&cs->port, NULL);
34383
34384 mutex_unlock(&cs->mutex);
34385diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34386index 821f7ac..28d4030 100644
34387--- a/drivers/isdn/hardware/avm/b1.c
34388+++ b/drivers/isdn/hardware/avm/b1.c
34389@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34390 }
34391 if (left) {
34392 if (t4file->user) {
34393- if (copy_from_user(buf, dp, left))
34394+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34395 return -EFAULT;
34396 } else {
34397 memcpy(buf, dp, left);
34398@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34399 }
34400 if (left) {
34401 if (config->user) {
34402- if (copy_from_user(buf, dp, left))
34403+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34404 return -EFAULT;
34405 } else {
34406 memcpy(buf, dp, left);
34407diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34408index b817809..409caff 100644
34409--- a/drivers/isdn/i4l/isdn_tty.c
34410+++ b/drivers/isdn/i4l/isdn_tty.c
34411@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34412
34413 #ifdef ISDN_DEBUG_MODEM_OPEN
34414 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34415- port->count);
34416+ atomic_read(&port->count));
34417 #endif
34418- port->count++;
34419+ atomic_inc(&port->count);
34420 port->tty = tty;
34421 /*
34422 * Start up serial port
34423@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34424 #endif
34425 return;
34426 }
34427- if ((tty->count == 1) && (port->count != 1)) {
34428+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34429 /*
34430 * Uh, oh. tty->count is 1, which means that the tty
34431 * structure will be freed. Info->count should always
34432@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34433 * serial port won't be shutdown.
34434 */
34435 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34436- "info->count is %d\n", port->count);
34437- port->count = 1;
34438+ "info->count is %d\n", atomic_read(&port->count));
34439+ atomic_set(&port->count, 1);
34440 }
34441- if (--port->count < 0) {
34442+ if (atomic_dec_return(&port->count) < 0) {
34443 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34444- info->line, port->count);
34445- port->count = 0;
34446+ info->line, atomic_read(&port->count));
34447+ atomic_set(&port->count, 0);
34448 }
34449- if (port->count) {
34450+ if (atomic_read(&port->count)) {
34451 #ifdef ISDN_DEBUG_MODEM_OPEN
34452 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34453 #endif
34454@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34455 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34456 return;
34457 isdn_tty_shutdown(info);
34458- port->count = 0;
34459+ atomic_set(&port->count, 0);
34460 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34461 port->tty = NULL;
34462 wake_up_interruptible(&port->open_wait);
34463@@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34464 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34465 modem_info *info = &dev->mdm.info[i];
34466
34467- if (info->port.count == 0)
34468+ if (atomic_read(&info->port.count) == 0)
34469 continue;
34470 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34471 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34472diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34473index e74df7c..03a03ba 100644
34474--- a/drivers/isdn/icn/icn.c
34475+++ b/drivers/isdn/icn/icn.c
34476@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34477 if (count > len)
34478 count = len;
34479 if (user) {
34480- if (copy_from_user(msg, buf, count))
34481+ if (count > sizeof msg || copy_from_user(msg, buf, count))
34482 return -EFAULT;
34483 } else
34484 memcpy(msg, buf, count);
34485diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34486index b5fdcb7..5b6c59f 100644
34487--- a/drivers/lguest/core.c
34488+++ b/drivers/lguest/core.c
34489@@ -92,9 +92,17 @@ static __init int map_switcher(void)
34490 * it's worked so far. The end address needs +1 because __get_vm_area
34491 * allocates an extra guard page, so we need space for that.
34492 */
34493+
34494+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34495+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34496+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34497+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34498+#else
34499 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34500 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34501 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34502+#endif
34503+
34504 if (!switcher_vma) {
34505 err = -ENOMEM;
34506 printk("lguest: could not map switcher pages high\n");
34507@@ -119,7 +127,7 @@ static __init int map_switcher(void)
34508 * Now the Switcher is mapped at the right address, we can't fail!
34509 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34510 */
34511- memcpy(switcher_vma->addr, start_switcher_text,
34512+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34513 end_switcher_text - start_switcher_text);
34514
34515 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34516diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34517index 4af12e1..0e89afe 100644
34518--- a/drivers/lguest/x86/core.c
34519+++ b/drivers/lguest/x86/core.c
34520@@ -59,7 +59,7 @@ static struct {
34521 /* Offset from where switcher.S was compiled to where we've copied it */
34522 static unsigned long switcher_offset(void)
34523 {
34524- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34525+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34526 }
34527
34528 /* This cpu's struct lguest_pages. */
34529@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34530 * These copies are pretty cheap, so we do them unconditionally: */
34531 /* Save the current Host top-level page directory.
34532 */
34533+
34534+#ifdef CONFIG_PAX_PER_CPU_PGD
34535+ pages->state.host_cr3 = read_cr3();
34536+#else
34537 pages->state.host_cr3 = __pa(current->mm->pgd);
34538+#endif
34539+
34540 /*
34541 * Set up the Guest's page tables to see this CPU's pages (and no
34542 * other CPU's pages).
34543@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34544 * compiled-in switcher code and the high-mapped copy we just made.
34545 */
34546 for (i = 0; i < IDT_ENTRIES; i++)
34547- default_idt_entries[i] += switcher_offset();
34548+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34549
34550 /*
34551 * Set up the Switcher's per-cpu areas.
34552@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34553 * it will be undisturbed when we switch. To change %cs and jump we
34554 * need this structure to feed to Intel's "lcall" instruction.
34555 */
34556- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34557+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34558 lguest_entry.segment = LGUEST_CS;
34559
34560 /*
34561diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34562index 40634b0..4f5855e 100644
34563--- a/drivers/lguest/x86/switcher_32.S
34564+++ b/drivers/lguest/x86/switcher_32.S
34565@@ -87,6 +87,7 @@
34566 #include <asm/page.h>
34567 #include <asm/segment.h>
34568 #include <asm/lguest.h>
34569+#include <asm/processor-flags.h>
34570
34571 // We mark the start of the code to copy
34572 // It's placed in .text tho it's never run here
34573@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34574 // Changes type when we load it: damn Intel!
34575 // For after we switch over our page tables
34576 // That entry will be read-only: we'd crash.
34577+
34578+#ifdef CONFIG_PAX_KERNEXEC
34579+ mov %cr0, %edx
34580+ xor $X86_CR0_WP, %edx
34581+ mov %edx, %cr0
34582+#endif
34583+
34584 movl $(GDT_ENTRY_TSS*8), %edx
34585 ltr %dx
34586
34587@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34588 // Let's clear it again for our return.
34589 // The GDT descriptor of the Host
34590 // Points to the table after two "size" bytes
34591- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34592+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34593 // Clear "used" from type field (byte 5, bit 2)
34594- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34595+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34596+
34597+#ifdef CONFIG_PAX_KERNEXEC
34598+ mov %cr0, %eax
34599+ xor $X86_CR0_WP, %eax
34600+ mov %eax, %cr0
34601+#endif
34602
34603 // Once our page table's switched, the Guest is live!
34604 // The Host fades as we run this final step.
34605@@ -295,13 +309,12 @@ deliver_to_host:
34606 // I consulted gcc, and it gave
34607 // These instructions, which I gladly credit:
34608 leal (%edx,%ebx,8), %eax
34609- movzwl (%eax),%edx
34610- movl 4(%eax), %eax
34611- xorw %ax, %ax
34612- orl %eax, %edx
34613+ movl 4(%eax), %edx
34614+ movw (%eax), %dx
34615 // Now the address of the handler's in %edx
34616 // We call it now: its "iret" drops us home.
34617- jmp *%edx
34618+ ljmp $__KERNEL_CS, $1f
34619+1: jmp *%edx
34620
34621 // Every interrupt can come to us here
34622 // But we must truly tell each apart.
34623diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34624index 7155945..4bcc562 100644
34625--- a/drivers/md/bitmap.c
34626+++ b/drivers/md/bitmap.c
34627@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34628 chunk_kb ? "KB" : "B");
34629 if (bitmap->storage.file) {
34630 seq_printf(seq, ", file: ");
34631- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34632+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34633 }
34634
34635 seq_printf(seq, "\n");
34636diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34637index a651d52..82f8a95 100644
34638--- a/drivers/md/dm-ioctl.c
34639+++ b/drivers/md/dm-ioctl.c
34640@@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34641 cmd == DM_LIST_VERSIONS_CMD)
34642 return 0;
34643
34644- if ((cmd == DM_DEV_CREATE_CMD)) {
34645+ if (cmd == DM_DEV_CREATE_CMD) {
34646 if (!*param->name) {
34647 DMWARN("name not supplied when creating device");
34648 return -EINVAL;
34649diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
34650index fd61f98..8050783 100644
34651--- a/drivers/md/dm-raid1.c
34652+++ b/drivers/md/dm-raid1.c
34653@@ -40,7 +40,7 @@ enum dm_raid1_error {
34654
34655 struct mirror {
34656 struct mirror_set *ms;
34657- atomic_t error_count;
34658+ atomic_unchecked_t error_count;
34659 unsigned long error_type;
34660 struct dm_dev *dev;
34661 sector_t offset;
34662@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
34663 struct mirror *m;
34664
34665 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
34666- if (!atomic_read(&m->error_count))
34667+ if (!atomic_read_unchecked(&m->error_count))
34668 return m;
34669
34670 return NULL;
34671@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
34672 * simple way to tell if a device has encountered
34673 * errors.
34674 */
34675- atomic_inc(&m->error_count);
34676+ atomic_inc_unchecked(&m->error_count);
34677
34678 if (test_and_set_bit(error_type, &m->error_type))
34679 return;
34680@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
34681 struct mirror *m = get_default_mirror(ms);
34682
34683 do {
34684- if (likely(!atomic_read(&m->error_count)))
34685+ if (likely(!atomic_read_unchecked(&m->error_count)))
34686 return m;
34687
34688 if (m-- == ms->mirror)
34689@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
34690 {
34691 struct mirror *default_mirror = get_default_mirror(m->ms);
34692
34693- return !atomic_read(&default_mirror->error_count);
34694+ return !atomic_read_unchecked(&default_mirror->error_count);
34695 }
34696
34697 static int mirror_available(struct mirror_set *ms, struct bio *bio)
34698@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
34699 */
34700 if (likely(region_in_sync(ms, region, 1)))
34701 m = choose_mirror(ms, bio->bi_sector);
34702- else if (m && atomic_read(&m->error_count))
34703+ else if (m && atomic_read_unchecked(&m->error_count))
34704 m = NULL;
34705
34706 if (likely(m))
34707@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
34708 }
34709
34710 ms->mirror[mirror].ms = ms;
34711- atomic_set(&(ms->mirror[mirror].error_count), 0);
34712+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
34713 ms->mirror[mirror].error_type = 0;
34714 ms->mirror[mirror].offset = offset;
34715
34716@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
34717 */
34718 static char device_status_char(struct mirror *m)
34719 {
34720- if (!atomic_read(&(m->error_count)))
34721+ if (!atomic_read_unchecked(&(m->error_count)))
34722 return 'A';
34723
34724 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
34725diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
34726index e2f87653..f279abe 100644
34727--- a/drivers/md/dm-stripe.c
34728+++ b/drivers/md/dm-stripe.c
34729@@ -20,7 +20,7 @@ struct stripe {
34730 struct dm_dev *dev;
34731 sector_t physical_start;
34732
34733- atomic_t error_count;
34734+ atomic_unchecked_t error_count;
34735 };
34736
34737 struct stripe_c {
34738@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
34739 kfree(sc);
34740 return r;
34741 }
34742- atomic_set(&(sc->stripe[i].error_count), 0);
34743+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
34744 }
34745
34746 ti->private = sc;
34747@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
34748 DMEMIT("%d ", sc->stripes);
34749 for (i = 0; i < sc->stripes; i++) {
34750 DMEMIT("%s ", sc->stripe[i].dev->name);
34751- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
34752+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
34753 'D' : 'A';
34754 }
34755 buffer[i] = '\0';
34756@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
34757 */
34758 for (i = 0; i < sc->stripes; i++)
34759 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
34760- atomic_inc(&(sc->stripe[i].error_count));
34761- if (atomic_read(&(sc->stripe[i].error_count)) <
34762+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
34763+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
34764 DM_IO_ERROR_THRESHOLD)
34765 schedule_work(&sc->trigger_event);
34766 }
34767diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
34768index fa29557..d24a5b7 100644
34769--- a/drivers/md/dm-table.c
34770+++ b/drivers/md/dm-table.c
34771@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
34772 if (!dev_size)
34773 return 0;
34774
34775- if ((start >= dev_size) || (start + len > dev_size)) {
34776+ if ((start >= dev_size) || (len > dev_size - start)) {
34777 DMWARN("%s: %s too small for target: "
34778 "start=%llu, len=%llu, dev_size=%llu",
34779 dm_device_name(ti->table->md), bdevname(bdev, b),
34780diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
34781index 693e149..b7e0fde 100644
34782--- a/drivers/md/dm-thin-metadata.c
34783+++ b/drivers/md/dm-thin-metadata.c
34784@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34785 {
34786 pmd->info.tm = pmd->tm;
34787 pmd->info.levels = 2;
34788- pmd->info.value_type.context = pmd->data_sm;
34789+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34790 pmd->info.value_type.size = sizeof(__le64);
34791 pmd->info.value_type.inc = data_block_inc;
34792 pmd->info.value_type.dec = data_block_dec;
34793@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
34794
34795 pmd->bl_info.tm = pmd->tm;
34796 pmd->bl_info.levels = 1;
34797- pmd->bl_info.value_type.context = pmd->data_sm;
34798+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
34799 pmd->bl_info.value_type.size = sizeof(__le64);
34800 pmd->bl_info.value_type.inc = data_block_inc;
34801 pmd->bl_info.value_type.dec = data_block_dec;
34802diff --git a/drivers/md/dm.c b/drivers/md/dm.c
34803index 77e6eff..913d695 100644
34804--- a/drivers/md/dm.c
34805+++ b/drivers/md/dm.c
34806@@ -182,9 +182,9 @@ struct mapped_device {
34807 /*
34808 * Event handling.
34809 */
34810- atomic_t event_nr;
34811+ atomic_unchecked_t event_nr;
34812 wait_queue_head_t eventq;
34813- atomic_t uevent_seq;
34814+ atomic_unchecked_t uevent_seq;
34815 struct list_head uevent_list;
34816 spinlock_t uevent_lock; /* Protect access to uevent_list */
34817
34818@@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
34819 rwlock_init(&md->map_lock);
34820 atomic_set(&md->holders, 1);
34821 atomic_set(&md->open_count, 0);
34822- atomic_set(&md->event_nr, 0);
34823- atomic_set(&md->uevent_seq, 0);
34824+ atomic_set_unchecked(&md->event_nr, 0);
34825+ atomic_set_unchecked(&md->uevent_seq, 0);
34826 INIT_LIST_HEAD(&md->uevent_list);
34827 spin_lock_init(&md->uevent_lock);
34828
34829@@ -1982,7 +1982,7 @@ static void event_callback(void *context)
34830
34831 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
34832
34833- atomic_inc(&md->event_nr);
34834+ atomic_inc_unchecked(&md->event_nr);
34835 wake_up(&md->eventq);
34836 }
34837
34838@@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
34839
34840 uint32_t dm_next_uevent_seq(struct mapped_device *md)
34841 {
34842- return atomic_add_return(1, &md->uevent_seq);
34843+ return atomic_add_return_unchecked(1, &md->uevent_seq);
34844 }
34845
34846 uint32_t dm_get_event_nr(struct mapped_device *md)
34847 {
34848- return atomic_read(&md->event_nr);
34849+ return atomic_read_unchecked(&md->event_nr);
34850 }
34851
34852 int dm_wait_event(struct mapped_device *md, int event_nr)
34853 {
34854 return wait_event_interruptible(md->eventq,
34855- (event_nr != atomic_read(&md->event_nr)));
34856+ (event_nr != atomic_read_unchecked(&md->event_nr)));
34857 }
34858
34859 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
34860diff --git a/drivers/md/md.c b/drivers/md/md.c
34861index 6120071..31d9be2 100644
34862--- a/drivers/md/md.c
34863+++ b/drivers/md/md.c
34864@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
34865 * start build, activate spare
34866 */
34867 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
34868-static atomic_t md_event_count;
34869+static atomic_unchecked_t md_event_count;
34870 void md_new_event(struct mddev *mddev)
34871 {
34872- atomic_inc(&md_event_count);
34873+ atomic_inc_unchecked(&md_event_count);
34874 wake_up(&md_event_waiters);
34875 }
34876 EXPORT_SYMBOL_GPL(md_new_event);
34877@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
34878 */
34879 static void md_new_event_inintr(struct mddev *mddev)
34880 {
34881- atomic_inc(&md_event_count);
34882+ atomic_inc_unchecked(&md_event_count);
34883 wake_up(&md_event_waiters);
34884 }
34885
34886@@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
34887 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
34888 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
34889 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
34890- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34891+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
34892
34893 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
34894 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
34895@@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
34896 else
34897 sb->resync_offset = cpu_to_le64(0);
34898
34899- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
34900+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
34901
34902 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
34903 sb->size = cpu_to_le64(mddev->dev_sectors);
34904@@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
34905 static ssize_t
34906 errors_show(struct md_rdev *rdev, char *page)
34907 {
34908- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
34909+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
34910 }
34911
34912 static ssize_t
34913@@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
34914 char *e;
34915 unsigned long n = simple_strtoul(buf, &e, 10);
34916 if (*buf && (*e == 0 || *e == '\n')) {
34917- atomic_set(&rdev->corrected_errors, n);
34918+ atomic_set_unchecked(&rdev->corrected_errors, n);
34919 return len;
34920 }
34921 return -EINVAL;
34922@@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
34923 rdev->sb_loaded = 0;
34924 rdev->bb_page = NULL;
34925 atomic_set(&rdev->nr_pending, 0);
34926- atomic_set(&rdev->read_errors, 0);
34927- atomic_set(&rdev->corrected_errors, 0);
34928+ atomic_set_unchecked(&rdev->read_errors, 0);
34929+ atomic_set_unchecked(&rdev->corrected_errors, 0);
34930
34931 INIT_LIST_HEAD(&rdev->same_set);
34932 init_waitqueue_head(&rdev->blocked_wait);
34933@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
34934
34935 spin_unlock(&pers_lock);
34936 seq_printf(seq, "\n");
34937- seq->poll_event = atomic_read(&md_event_count);
34938+ seq->poll_event = atomic_read_unchecked(&md_event_count);
34939 return 0;
34940 }
34941 if (v == (void*)2) {
34942@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
34943 return error;
34944
34945 seq = file->private_data;
34946- seq->poll_event = atomic_read(&md_event_count);
34947+ seq->poll_event = atomic_read_unchecked(&md_event_count);
34948 return error;
34949 }
34950
34951@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
34952 /* always allow read */
34953 mask = POLLIN | POLLRDNORM;
34954
34955- if (seq->poll_event != atomic_read(&md_event_count))
34956+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
34957 mask |= POLLERR | POLLPRI;
34958 return mask;
34959 }
34960@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
34961 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
34962 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
34963 (int)part_stat_read(&disk->part0, sectors[1]) -
34964- atomic_read(&disk->sync_io);
34965+ atomic_read_unchecked(&disk->sync_io);
34966 /* sync IO will cause sync_io to increase before the disk_stats
34967 * as sync_io is counted when a request starts, and
34968 * disk_stats is counted when it completes.
34969diff --git a/drivers/md/md.h b/drivers/md/md.h
34970index af443ab..0f93be3 100644
34971--- a/drivers/md/md.h
34972+++ b/drivers/md/md.h
34973@@ -94,13 +94,13 @@ struct md_rdev {
34974 * only maintained for arrays that
34975 * support hot removal
34976 */
34977- atomic_t read_errors; /* number of consecutive read errors that
34978+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
34979 * we have tried to ignore.
34980 */
34981 struct timespec last_read_error; /* monotonic time since our
34982 * last read error
34983 */
34984- atomic_t corrected_errors; /* number of corrected read errors,
34985+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
34986 * for reporting to userspace and storing
34987 * in superblock.
34988 */
34989@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
34990
34991 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
34992 {
34993- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34994+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
34995 }
34996
34997 struct md_personality
34998diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
34999index 1cbfc6b..56e1dbb 100644
35000--- a/drivers/md/persistent-data/dm-space-map.h
35001+++ b/drivers/md/persistent-data/dm-space-map.h
35002@@ -60,6 +60,7 @@ struct dm_space_map {
35003 int (*root_size)(struct dm_space_map *sm, size_t *result);
35004 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35005 };
35006+typedef struct dm_space_map __no_const dm_space_map_no_const;
35007
35008 /*----------------------------------------------------------------*/
35009
35010diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35011index a0f7309..5599dbc 100644
35012--- a/drivers/md/raid1.c
35013+++ b/drivers/md/raid1.c
35014@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35015 if (r1_sync_page_io(rdev, sect, s,
35016 bio->bi_io_vec[idx].bv_page,
35017 READ) != 0)
35018- atomic_add(s, &rdev->corrected_errors);
35019+ atomic_add_unchecked(s, &rdev->corrected_errors);
35020 }
35021 sectors -= s;
35022 sect += s;
35023@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35024 test_bit(In_sync, &rdev->flags)) {
35025 if (r1_sync_page_io(rdev, sect, s,
35026 conf->tmppage, READ)) {
35027- atomic_add(s, &rdev->corrected_errors);
35028+ atomic_add_unchecked(s, &rdev->corrected_errors);
35029 printk(KERN_INFO
35030 "md/raid1:%s: read error corrected "
35031 "(%d sectors at %llu on %s)\n",
35032diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35033index c9acbd7..386cd3e 100644
35034--- a/drivers/md/raid10.c
35035+++ b/drivers/md/raid10.c
35036@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35037 /* The write handler will notice the lack of
35038 * R10BIO_Uptodate and record any errors etc
35039 */
35040- atomic_add(r10_bio->sectors,
35041+ atomic_add_unchecked(r10_bio->sectors,
35042 &conf->mirrors[d].rdev->corrected_errors);
35043
35044 /* for reconstruct, we always reschedule after a read.
35045@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35046 {
35047 struct timespec cur_time_mon;
35048 unsigned long hours_since_last;
35049- unsigned int read_errors = atomic_read(&rdev->read_errors);
35050+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35051
35052 ktime_get_ts(&cur_time_mon);
35053
35054@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35055 * overflowing the shift of read_errors by hours_since_last.
35056 */
35057 if (hours_since_last >= 8 * sizeof(read_errors))
35058- atomic_set(&rdev->read_errors, 0);
35059+ atomic_set_unchecked(&rdev->read_errors, 0);
35060 else
35061- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35062+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35063 }
35064
35065 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35066@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35067 return;
35068
35069 check_decay_read_errors(mddev, rdev);
35070- atomic_inc(&rdev->read_errors);
35071- if (atomic_read(&rdev->read_errors) > max_read_errors) {
35072+ atomic_inc_unchecked(&rdev->read_errors);
35073+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35074 char b[BDEVNAME_SIZE];
35075 bdevname(rdev->bdev, b);
35076
35077@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35078 "md/raid10:%s: %s: Raid device exceeded "
35079 "read_error threshold [cur %d:max %d]\n",
35080 mdname(mddev), b,
35081- atomic_read(&rdev->read_errors), max_read_errors);
35082+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35083 printk(KERN_NOTICE
35084 "md/raid10:%s: %s: Failing raid device\n",
35085 mdname(mddev), b);
35086@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35087 sect +
35088 choose_data_offset(r10_bio, rdev)),
35089 bdevname(rdev->bdev, b));
35090- atomic_add(s, &rdev->corrected_errors);
35091+ atomic_add_unchecked(s, &rdev->corrected_errors);
35092 }
35093
35094 rdev_dec_pending(rdev, mddev);
35095diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35096index a450268..c4168a9 100644
35097--- a/drivers/md/raid5.c
35098+++ b/drivers/md/raid5.c
35099@@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35100 mdname(conf->mddev), STRIPE_SECTORS,
35101 (unsigned long long)s,
35102 bdevname(rdev->bdev, b));
35103- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35104+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35105 clear_bit(R5_ReadError, &sh->dev[i].flags);
35106 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35107 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35108 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35109
35110- if (atomic_read(&rdev->read_errors))
35111- atomic_set(&rdev->read_errors, 0);
35112+ if (atomic_read_unchecked(&rdev->read_errors))
35113+ atomic_set_unchecked(&rdev->read_errors, 0);
35114 } else {
35115 const char *bdn = bdevname(rdev->bdev, b);
35116 int retry = 0;
35117 int set_bad = 0;
35118
35119 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35120- atomic_inc(&rdev->read_errors);
35121+ atomic_inc_unchecked(&rdev->read_errors);
35122 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35123 printk_ratelimited(
35124 KERN_WARNING
35125@@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35126 mdname(conf->mddev),
35127 (unsigned long long)s,
35128 bdn);
35129- } else if (atomic_read(&rdev->read_errors)
35130+ } else if (atomic_read_unchecked(&rdev->read_errors)
35131 > conf->max_nr_stripes)
35132 printk(KERN_WARNING
35133 "md/raid:%s: Too many read errors, failing device %s.\n",
35134diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35135index d33101a..6b13069 100644
35136--- a/drivers/media/dvb-core/dvbdev.c
35137+++ b/drivers/media/dvb-core/dvbdev.c
35138@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35139 const struct dvb_device *template, void *priv, int type)
35140 {
35141 struct dvb_device *dvbdev;
35142- struct file_operations *dvbdevfops;
35143+ file_operations_no_const *dvbdevfops;
35144 struct device *clsdev;
35145 int minor;
35146 int id;
35147diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35148index 404f63a..4796533 100644
35149--- a/drivers/media/dvb-frontends/dib3000.h
35150+++ b/drivers/media/dvb-frontends/dib3000.h
35151@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35152 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35153 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35154 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35155-};
35156+} __no_const;
35157
35158 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35159 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35160diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35161index 3aa6856..435ad25 100644
35162--- a/drivers/media/pci/cx88/cx88-alsa.c
35163+++ b/drivers/media/pci/cx88/cx88-alsa.c
35164@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35165 * Only boards with eeprom and byte 1 at eeprom=1 have it
35166 */
35167
35168-static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35169+static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35170 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35171 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35172 {0, }
35173diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35174index feff57e..66a2c67 100644
35175--- a/drivers/media/pci/ddbridge/ddbridge-core.c
35176+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35177@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35178 .subvendor = _subvend, .subdevice = _subdev, \
35179 .driver_data = (unsigned long)&_driverdata }
35180
35181-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35182+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35183 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35184 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35185 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35186diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35187index 96a13ed..6df45b4 100644
35188--- a/drivers/media/pci/ngene/ngene-cards.c
35189+++ b/drivers/media/pci/ngene/ngene-cards.c
35190@@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35191
35192 /****************************************************************************/
35193
35194-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35195+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35196 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35197 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35198 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35199diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35200index a3b1a34..71ce0e3 100644
35201--- a/drivers/media/platform/omap/omap_vout.c
35202+++ b/drivers/media/platform/omap/omap_vout.c
35203@@ -65,7 +65,6 @@ enum omap_vout_channels {
35204 OMAP_VIDEO2,
35205 };
35206
35207-static struct videobuf_queue_ops video_vbq_ops;
35208 /* Variables configurable through module params*/
35209 static u32 video1_numbuffers = 3;
35210 static u32 video2_numbuffers = 3;
35211@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35212 {
35213 struct videobuf_queue *q;
35214 struct omap_vout_device *vout = NULL;
35215+ static struct videobuf_queue_ops video_vbq_ops = {
35216+ .buf_setup = omap_vout_buffer_setup,
35217+ .buf_prepare = omap_vout_buffer_prepare,
35218+ .buf_release = omap_vout_buffer_release,
35219+ .buf_queue = omap_vout_buffer_queue,
35220+ };
35221
35222 vout = video_drvdata(file);
35223 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35224@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35225 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35226
35227 q = &vout->vbq;
35228- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35229- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35230- video_vbq_ops.buf_release = omap_vout_buffer_release;
35231- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35232 spin_lock_init(&vout->vbq_lock);
35233
35234 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35235diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
35236index ddb422e..8cf008e 100644
35237--- a/drivers/media/platform/s5p-tv/mixer.h
35238+++ b/drivers/media/platform/s5p-tv/mixer.h
35239@@ -155,7 +155,7 @@ struct mxr_layer {
35240 /** layer index (unique identifier) */
35241 int idx;
35242 /** callbacks for layer methods */
35243- struct mxr_layer_ops ops;
35244+ struct mxr_layer_ops *ops;
35245 /** format array */
35246 const struct mxr_format **fmt_array;
35247 /** size of format array */
35248diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35249index b93a21f..2535195 100644
35250--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35251+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
35252@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
35253 {
35254 struct mxr_layer *layer;
35255 int ret;
35256- struct mxr_layer_ops ops = {
35257+ static struct mxr_layer_ops ops = {
35258 .release = mxr_graph_layer_release,
35259 .buffer_set = mxr_graph_buffer_set,
35260 .stream_set = mxr_graph_stream_set,
35261diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
35262index 3b1670a..595c939 100644
35263--- a/drivers/media/platform/s5p-tv/mixer_reg.c
35264+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
35265@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
35266 layer->update_buf = next;
35267 }
35268
35269- layer->ops.buffer_set(layer, layer->update_buf);
35270+ layer->ops->buffer_set(layer, layer->update_buf);
35271
35272 if (done && done != layer->shadow_buf)
35273 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
35274diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
35275index 0c1cd89..6574647 100644
35276--- a/drivers/media/platform/s5p-tv/mixer_video.c
35277+++ b/drivers/media/platform/s5p-tv/mixer_video.c
35278@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
35279 layer->geo.src.height = layer->geo.src.full_height;
35280
35281 mxr_geometry_dump(mdev, &layer->geo);
35282- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35283+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35284 mxr_geometry_dump(mdev, &layer->geo);
35285 }
35286
35287@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
35288 layer->geo.dst.full_width = mbus_fmt.width;
35289 layer->geo.dst.full_height = mbus_fmt.height;
35290 layer->geo.dst.field = mbus_fmt.field;
35291- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35292+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
35293
35294 mxr_geometry_dump(mdev, &layer->geo);
35295 }
35296@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
35297 /* set source size to highest accepted value */
35298 geo->src.full_width = max(geo->dst.full_width, pix->width);
35299 geo->src.full_height = max(geo->dst.full_height, pix->height);
35300- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35301+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35302 mxr_geometry_dump(mdev, &layer->geo);
35303 /* set cropping to total visible screen */
35304 geo->src.width = pix->width;
35305@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
35306 geo->src.x_offset = 0;
35307 geo->src.y_offset = 0;
35308 /* assure consistency of geometry */
35309- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35310+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
35311 mxr_geometry_dump(mdev, &layer->geo);
35312 /* set full size to lowest possible value */
35313 geo->src.full_width = 0;
35314 geo->src.full_height = 0;
35315- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35316+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
35317 mxr_geometry_dump(mdev, &layer->geo);
35318
35319 /* returning results */
35320@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
35321 target->width = s->r.width;
35322 target->height = s->r.height;
35323
35324- layer->ops.fix_geometry(layer, stage, s->flags);
35325+ layer->ops->fix_geometry(layer, stage, s->flags);
35326
35327 /* retrieve update selection rectangle */
35328 res.left = target->x_offset;
35329@@ -928,13 +928,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
35330 mxr_output_get(mdev);
35331
35332 mxr_layer_update_output(layer);
35333- layer->ops.format_set(layer);
35334+ layer->ops->format_set(layer);
35335 /* enabling layer in hardware */
35336 spin_lock_irqsave(&layer->enq_slock, flags);
35337 layer->state = MXR_LAYER_STREAMING;
35338 spin_unlock_irqrestore(&layer->enq_slock, flags);
35339
35340- layer->ops.stream_set(layer, MXR_ENABLE);
35341+ layer->ops->stream_set(layer, MXR_ENABLE);
35342 mxr_streamer_get(mdev);
35343
35344 return 0;
35345@@ -1004,7 +1004,7 @@ static int stop_streaming(struct vb2_queue *vq)
35346 spin_unlock_irqrestore(&layer->enq_slock, flags);
35347
35348 /* disabling layer in hardware */
35349- layer->ops.stream_set(layer, MXR_DISABLE);
35350+ layer->ops->stream_set(layer, MXR_DISABLE);
35351 /* remove one streamer */
35352 mxr_streamer_put(mdev);
35353 /* allow changes in output configuration */
35354@@ -1043,8 +1043,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
35355
35356 void mxr_layer_release(struct mxr_layer *layer)
35357 {
35358- if (layer->ops.release)
35359- layer->ops.release(layer);
35360+ if (layer->ops->release)
35361+ layer->ops->release(layer);
35362 }
35363
35364 void mxr_base_layer_release(struct mxr_layer *layer)
35365@@ -1070,7 +1070,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
35366
35367 layer->mdev = mdev;
35368 layer->idx = idx;
35369- layer->ops = *ops;
35370+ layer->ops = ops;
35371
35372 spin_lock_init(&layer->enq_slock);
35373 INIT_LIST_HEAD(&layer->enq_list);
35374diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35375index 3d13a63..da31bf1 100644
35376--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35377+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
35378@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
35379 {
35380 struct mxr_layer *layer;
35381 int ret;
35382- struct mxr_layer_ops ops = {
35383+ static struct mxr_layer_ops ops = {
35384 .release = mxr_vp_layer_release,
35385 .buffer_set = mxr_vp_buffer_set,
35386 .stream_set = mxr_vp_stream_set,
35387diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35388index 02194c0..36d69c1 100644
35389--- a/drivers/media/platform/timblogiw.c
35390+++ b/drivers/media/platform/timblogiw.c
35391@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35392
35393 /* Platform device functions */
35394
35395-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35396+static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35397 .vidioc_querycap = timblogiw_querycap,
35398 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35399 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35400@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35401 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35402 };
35403
35404-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35405+static struct v4l2_file_operations timblogiw_fops = {
35406 .owner = THIS_MODULE,
35407 .open = timblogiw_open,
35408 .release = timblogiw_close,
35409diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35410index 697a421..16c5a5f 100644
35411--- a/drivers/media/radio/radio-cadet.c
35412+++ b/drivers/media/radio/radio-cadet.c
35413@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35414 unsigned char readbuf[RDS_BUFFER];
35415 int i = 0;
35416
35417+ if (count > RDS_BUFFER)
35418+ return -EFAULT;
35419 mutex_lock(&dev->lock);
35420 if (dev->rdsstat == 0)
35421 cadet_start_rds(dev);
35422@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35423 while (i < count && dev->rdsin != dev->rdsout)
35424 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35425
35426- if (i && copy_to_user(data, readbuf, i))
35427+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35428 i = -EFAULT;
35429 unlock:
35430 mutex_unlock(&dev->lock);
35431diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35432index 3940bb0..fb3952a 100644
35433--- a/drivers/media/usb/dvb-usb/cxusb.c
35434+++ b/drivers/media/usb/dvb-usb/cxusb.c
35435@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35436
35437 struct dib0700_adapter_state {
35438 int (*set_param_save) (struct dvb_frontend *);
35439-};
35440+} __no_const;
35441
35442 static int dib7070_set_param_override(struct dvb_frontend *fe)
35443 {
35444diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35445index 9382895..ac8093c 100644
35446--- a/drivers/media/usb/dvb-usb/dw2102.c
35447+++ b/drivers/media/usb/dvb-usb/dw2102.c
35448@@ -95,7 +95,7 @@ struct su3000_state {
35449
35450 struct s6x0_state {
35451 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35452-};
35453+} __no_const;
35454
35455 /* debug */
35456 static int dvb_usb_dw2102_debug;
35457diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35458index fb69baa..cf7ad22 100644
35459--- a/drivers/message/fusion/mptbase.c
35460+++ b/drivers/message/fusion/mptbase.c
35461@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35462 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35463 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35464
35465+#ifdef CONFIG_GRKERNSEC_HIDESYM
35466+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35467+#else
35468 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35469 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35470+#endif
35471+
35472 /*
35473 * Rounding UP to nearest 4-kB boundary here...
35474 */
35475diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35476index 551262e..7551198 100644
35477--- a/drivers/message/fusion/mptsas.c
35478+++ b/drivers/message/fusion/mptsas.c
35479@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35480 return 0;
35481 }
35482
35483+static inline void
35484+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35485+{
35486+ if (phy_info->port_details) {
35487+ phy_info->port_details->rphy = rphy;
35488+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35489+ ioc->name, rphy));
35490+ }
35491+
35492+ if (rphy) {
35493+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35494+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35495+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35496+ ioc->name, rphy, rphy->dev.release));
35497+ }
35498+}
35499+
35500 /* no mutex */
35501 static void
35502 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35503@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35504 return NULL;
35505 }
35506
35507-static inline void
35508-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35509-{
35510- if (phy_info->port_details) {
35511- phy_info->port_details->rphy = rphy;
35512- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35513- ioc->name, rphy));
35514- }
35515-
35516- if (rphy) {
35517- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35518- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35519- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35520- ioc->name, rphy, rphy->dev.release));
35521- }
35522-}
35523-
35524 static inline struct sas_port *
35525 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35526 {
35527diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35528index 0c3ced7..1fe34ec 100644
35529--- a/drivers/message/fusion/mptscsih.c
35530+++ b/drivers/message/fusion/mptscsih.c
35531@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35532
35533 h = shost_priv(SChost);
35534
35535- if (h) {
35536- if (h->info_kbuf == NULL)
35537- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35538- return h->info_kbuf;
35539- h->info_kbuf[0] = '\0';
35540+ if (!h)
35541+ return NULL;
35542
35543- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35544- h->info_kbuf[size-1] = '\0';
35545- }
35546+ if (h->info_kbuf == NULL)
35547+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35548+ return h->info_kbuf;
35549+ h->info_kbuf[0] = '\0';
35550+
35551+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35552+ h->info_kbuf[size-1] = '\0';
35553
35554 return h->info_kbuf;
35555 }
35556diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35557index 8001aa6..b137580 100644
35558--- a/drivers/message/i2o/i2o_proc.c
35559+++ b/drivers/message/i2o/i2o_proc.c
35560@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35561 "Array Controller Device"
35562 };
35563
35564-static char *chtostr(char *tmp, u8 *chars, int n)
35565-{
35566- tmp[0] = 0;
35567- return strncat(tmp, (char *)chars, n);
35568-}
35569-
35570 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35571 char *group)
35572 {
35573@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35574 } *result;
35575
35576 i2o_exec_execute_ddm_table ddm_table;
35577- char tmp[28 + 1];
35578
35579 result = kmalloc(sizeof(*result), GFP_KERNEL);
35580 if (!result)
35581@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35582
35583 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35584 seq_printf(seq, "%-#8x", ddm_table.module_id);
35585- seq_printf(seq, "%-29s",
35586- chtostr(tmp, ddm_table.module_name_version, 28));
35587+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35588 seq_printf(seq, "%9d ", ddm_table.data_size);
35589 seq_printf(seq, "%8d", ddm_table.code_size);
35590
35591@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35592
35593 i2o_driver_result_table *result;
35594 i2o_driver_store_table *dst;
35595- char tmp[28 + 1];
35596
35597 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35598 if (result == NULL)
35599@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35600
35601 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35602 seq_printf(seq, "%-#8x", dst->module_id);
35603- seq_printf(seq, "%-29s",
35604- chtostr(tmp, dst->module_name_version, 28));
35605- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35606+ seq_printf(seq, "%-.28s", dst->module_name_version);
35607+ seq_printf(seq, "%-.8s", dst->date);
35608 seq_printf(seq, "%8d ", dst->module_size);
35609 seq_printf(seq, "%8d ", dst->mpb_size);
35610 seq_printf(seq, "0x%04x", dst->module_flags);
35611@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35612 // == (allow) 512d bytes (max)
35613 static u16 *work16 = (u16 *) work32;
35614 int token;
35615- char tmp[16 + 1];
35616
35617 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35618
35619@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35620 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35621 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35622 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35623- seq_printf(seq, "Vendor info : %s\n",
35624- chtostr(tmp, (u8 *) (work32 + 2), 16));
35625- seq_printf(seq, "Product info : %s\n",
35626- chtostr(tmp, (u8 *) (work32 + 6), 16));
35627- seq_printf(seq, "Description : %s\n",
35628- chtostr(tmp, (u8 *) (work32 + 10), 16));
35629- seq_printf(seq, "Product rev. : %s\n",
35630- chtostr(tmp, (u8 *) (work32 + 14), 8));
35631+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35632+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35633+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35634+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35635
35636 seq_printf(seq, "Serial number : ");
35637 print_serial_number(seq, (u8 *) (work32 + 16),
35638@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35639 u8 pad[256]; // allow up to 256 byte (max) serial number
35640 } result;
35641
35642- char tmp[24 + 1];
35643-
35644 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35645
35646 if (token < 0) {
35647@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35648 }
35649
35650 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35651- seq_printf(seq, "Module name : %s\n",
35652- chtostr(tmp, result.module_name, 24));
35653- seq_printf(seq, "Module revision : %s\n",
35654- chtostr(tmp, result.module_rev, 8));
35655+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
35656+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35657
35658 seq_printf(seq, "Serial number : ");
35659 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35660@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35661 u8 instance_number[4];
35662 } result;
35663
35664- char tmp[64 + 1];
35665-
35666 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35667
35668 if (token < 0) {
35669@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35670 return 0;
35671 }
35672
35673- seq_printf(seq, "Device name : %s\n",
35674- chtostr(tmp, result.device_name, 64));
35675- seq_printf(seq, "Service name : %s\n",
35676- chtostr(tmp, result.service_name, 64));
35677- seq_printf(seq, "Physical name : %s\n",
35678- chtostr(tmp, result.physical_location, 64));
35679- seq_printf(seq, "Instance number : %s\n",
35680- chtostr(tmp, result.instance_number, 4));
35681+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
35682+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
35683+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35684+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35685
35686 return 0;
35687 }
35688diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35689index a8c08f3..155fe3d 100644
35690--- a/drivers/message/i2o/iop.c
35691+++ b/drivers/message/i2o/iop.c
35692@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35693
35694 spin_lock_irqsave(&c->context_list_lock, flags);
35695
35696- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35697- atomic_inc(&c->context_list_counter);
35698+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35699+ atomic_inc_unchecked(&c->context_list_counter);
35700
35701- entry->context = atomic_read(&c->context_list_counter);
35702+ entry->context = atomic_read_unchecked(&c->context_list_counter);
35703
35704 list_add(&entry->list, &c->context_list);
35705
35706@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35707
35708 #if BITS_PER_LONG == 64
35709 spin_lock_init(&c->context_list_lock);
35710- atomic_set(&c->context_list_counter, 0);
35711+ atomic_set_unchecked(&c->context_list_counter, 0);
35712 INIT_LIST_HEAD(&c->context_list);
35713 #endif
35714
35715diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35716index 965c480..71f2db9 100644
35717--- a/drivers/mfd/janz-cmodio.c
35718+++ b/drivers/mfd/janz-cmodio.c
35719@@ -13,6 +13,7 @@
35720
35721 #include <linux/kernel.h>
35722 #include <linux/module.h>
35723+#include <linux/slab.h>
35724 #include <linux/init.h>
35725 #include <linux/pci.h>
35726 #include <linux/interrupt.h>
35727diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35728index 3aa9a96..59cf685 100644
35729--- a/drivers/misc/kgdbts.c
35730+++ b/drivers/misc/kgdbts.c
35731@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35732 char before[BREAK_INSTR_SIZE];
35733 char after[BREAK_INSTR_SIZE];
35734
35735- probe_kernel_read(before, (char *)kgdbts_break_test,
35736+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35737 BREAK_INSTR_SIZE);
35738 init_simple_test();
35739 ts.tst = plant_and_detach_test;
35740@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35741 /* Activate test with initial breakpoint */
35742 if (!is_early)
35743 kgdb_breakpoint();
35744- probe_kernel_read(after, (char *)kgdbts_break_test,
35745+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35746 BREAK_INSTR_SIZE);
35747 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35748 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35749diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35750index 4a87e5c..76bdf5c 100644
35751--- a/drivers/misc/lis3lv02d/lis3lv02d.c
35752+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35753@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35754 * the lid is closed. This leads to interrupts as soon as a little move
35755 * is done.
35756 */
35757- atomic_inc(&lis3->count);
35758+ atomic_inc_unchecked(&lis3->count);
35759
35760 wake_up_interruptible(&lis3->misc_wait);
35761 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35762@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35763 if (lis3->pm_dev)
35764 pm_runtime_get_sync(lis3->pm_dev);
35765
35766- atomic_set(&lis3->count, 0);
35767+ atomic_set_unchecked(&lis3->count, 0);
35768 return 0;
35769 }
35770
35771@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35772 add_wait_queue(&lis3->misc_wait, &wait);
35773 while (true) {
35774 set_current_state(TASK_INTERRUPTIBLE);
35775- data = atomic_xchg(&lis3->count, 0);
35776+ data = atomic_xchg_unchecked(&lis3->count, 0);
35777 if (data)
35778 break;
35779
35780@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35781 struct lis3lv02d, miscdev);
35782
35783 poll_wait(file, &lis3->misc_wait, wait);
35784- if (atomic_read(&lis3->count))
35785+ if (atomic_read_unchecked(&lis3->count))
35786 return POLLIN | POLLRDNORM;
35787 return 0;
35788 }
35789diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35790index c439c82..1f20f57 100644
35791--- a/drivers/misc/lis3lv02d/lis3lv02d.h
35792+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35793@@ -297,7 +297,7 @@ struct lis3lv02d {
35794 struct input_polled_dev *idev; /* input device */
35795 struct platform_device *pdev; /* platform device */
35796 struct regulator_bulk_data regulators[2];
35797- atomic_t count; /* interrupt count after last read */
35798+ atomic_unchecked_t count; /* interrupt count after last read */
35799 union axis_conversion ac; /* hw -> logical axis */
35800 int mapped_btns[3];
35801
35802diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
35803index 2f30bad..c4c13d0 100644
35804--- a/drivers/misc/sgi-gru/gruhandles.c
35805+++ b/drivers/misc/sgi-gru/gruhandles.c
35806@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
35807 unsigned long nsec;
35808
35809 nsec = CLKS2NSEC(clks);
35810- atomic_long_inc(&mcs_op_statistics[op].count);
35811- atomic_long_add(nsec, &mcs_op_statistics[op].total);
35812+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
35813+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
35814 if (mcs_op_statistics[op].max < nsec)
35815 mcs_op_statistics[op].max = nsec;
35816 }
35817diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
35818index 950dbe9..eeef0f8 100644
35819--- a/drivers/misc/sgi-gru/gruprocfs.c
35820+++ b/drivers/misc/sgi-gru/gruprocfs.c
35821@@ -32,9 +32,9 @@
35822
35823 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
35824
35825-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
35826+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
35827 {
35828- unsigned long val = atomic_long_read(v);
35829+ unsigned long val = atomic_long_read_unchecked(v);
35830
35831 seq_printf(s, "%16lu %s\n", val, id);
35832 }
35833@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
35834
35835 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
35836 for (op = 0; op < mcsop_last; op++) {
35837- count = atomic_long_read(&mcs_op_statistics[op].count);
35838- total = atomic_long_read(&mcs_op_statistics[op].total);
35839+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
35840+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
35841 max = mcs_op_statistics[op].max;
35842 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
35843 count ? total / count : 0, max);
35844diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
35845index 5c3ce24..4915ccb 100644
35846--- a/drivers/misc/sgi-gru/grutables.h
35847+++ b/drivers/misc/sgi-gru/grutables.h
35848@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
35849 * GRU statistics.
35850 */
35851 struct gru_stats_s {
35852- atomic_long_t vdata_alloc;
35853- atomic_long_t vdata_free;
35854- atomic_long_t gts_alloc;
35855- atomic_long_t gts_free;
35856- atomic_long_t gms_alloc;
35857- atomic_long_t gms_free;
35858- atomic_long_t gts_double_allocate;
35859- atomic_long_t assign_context;
35860- atomic_long_t assign_context_failed;
35861- atomic_long_t free_context;
35862- atomic_long_t load_user_context;
35863- atomic_long_t load_kernel_context;
35864- atomic_long_t lock_kernel_context;
35865- atomic_long_t unlock_kernel_context;
35866- atomic_long_t steal_user_context;
35867- atomic_long_t steal_kernel_context;
35868- atomic_long_t steal_context_failed;
35869- atomic_long_t nopfn;
35870- atomic_long_t asid_new;
35871- atomic_long_t asid_next;
35872- atomic_long_t asid_wrap;
35873- atomic_long_t asid_reuse;
35874- atomic_long_t intr;
35875- atomic_long_t intr_cbr;
35876- atomic_long_t intr_tfh;
35877- atomic_long_t intr_spurious;
35878- atomic_long_t intr_mm_lock_failed;
35879- atomic_long_t call_os;
35880- atomic_long_t call_os_wait_queue;
35881- atomic_long_t user_flush_tlb;
35882- atomic_long_t user_unload_context;
35883- atomic_long_t user_exception;
35884- atomic_long_t set_context_option;
35885- atomic_long_t check_context_retarget_intr;
35886- atomic_long_t check_context_unload;
35887- atomic_long_t tlb_dropin;
35888- atomic_long_t tlb_preload_page;
35889- atomic_long_t tlb_dropin_fail_no_asid;
35890- atomic_long_t tlb_dropin_fail_upm;
35891- atomic_long_t tlb_dropin_fail_invalid;
35892- atomic_long_t tlb_dropin_fail_range_active;
35893- atomic_long_t tlb_dropin_fail_idle;
35894- atomic_long_t tlb_dropin_fail_fmm;
35895- atomic_long_t tlb_dropin_fail_no_exception;
35896- atomic_long_t tfh_stale_on_fault;
35897- atomic_long_t mmu_invalidate_range;
35898- atomic_long_t mmu_invalidate_page;
35899- atomic_long_t flush_tlb;
35900- atomic_long_t flush_tlb_gru;
35901- atomic_long_t flush_tlb_gru_tgh;
35902- atomic_long_t flush_tlb_gru_zero_asid;
35903+ atomic_long_unchecked_t vdata_alloc;
35904+ atomic_long_unchecked_t vdata_free;
35905+ atomic_long_unchecked_t gts_alloc;
35906+ atomic_long_unchecked_t gts_free;
35907+ atomic_long_unchecked_t gms_alloc;
35908+ atomic_long_unchecked_t gms_free;
35909+ atomic_long_unchecked_t gts_double_allocate;
35910+ atomic_long_unchecked_t assign_context;
35911+ atomic_long_unchecked_t assign_context_failed;
35912+ atomic_long_unchecked_t free_context;
35913+ atomic_long_unchecked_t load_user_context;
35914+ atomic_long_unchecked_t load_kernel_context;
35915+ atomic_long_unchecked_t lock_kernel_context;
35916+ atomic_long_unchecked_t unlock_kernel_context;
35917+ atomic_long_unchecked_t steal_user_context;
35918+ atomic_long_unchecked_t steal_kernel_context;
35919+ atomic_long_unchecked_t steal_context_failed;
35920+ atomic_long_unchecked_t nopfn;
35921+ atomic_long_unchecked_t asid_new;
35922+ atomic_long_unchecked_t asid_next;
35923+ atomic_long_unchecked_t asid_wrap;
35924+ atomic_long_unchecked_t asid_reuse;
35925+ atomic_long_unchecked_t intr;
35926+ atomic_long_unchecked_t intr_cbr;
35927+ atomic_long_unchecked_t intr_tfh;
35928+ atomic_long_unchecked_t intr_spurious;
35929+ atomic_long_unchecked_t intr_mm_lock_failed;
35930+ atomic_long_unchecked_t call_os;
35931+ atomic_long_unchecked_t call_os_wait_queue;
35932+ atomic_long_unchecked_t user_flush_tlb;
35933+ atomic_long_unchecked_t user_unload_context;
35934+ atomic_long_unchecked_t user_exception;
35935+ atomic_long_unchecked_t set_context_option;
35936+ atomic_long_unchecked_t check_context_retarget_intr;
35937+ atomic_long_unchecked_t check_context_unload;
35938+ atomic_long_unchecked_t tlb_dropin;
35939+ atomic_long_unchecked_t tlb_preload_page;
35940+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
35941+ atomic_long_unchecked_t tlb_dropin_fail_upm;
35942+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
35943+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
35944+ atomic_long_unchecked_t tlb_dropin_fail_idle;
35945+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
35946+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
35947+ atomic_long_unchecked_t tfh_stale_on_fault;
35948+ atomic_long_unchecked_t mmu_invalidate_range;
35949+ atomic_long_unchecked_t mmu_invalidate_page;
35950+ atomic_long_unchecked_t flush_tlb;
35951+ atomic_long_unchecked_t flush_tlb_gru;
35952+ atomic_long_unchecked_t flush_tlb_gru_tgh;
35953+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
35954
35955- atomic_long_t copy_gpa;
35956- atomic_long_t read_gpa;
35957+ atomic_long_unchecked_t copy_gpa;
35958+ atomic_long_unchecked_t read_gpa;
35959
35960- atomic_long_t mesq_receive;
35961- atomic_long_t mesq_receive_none;
35962- atomic_long_t mesq_send;
35963- atomic_long_t mesq_send_failed;
35964- atomic_long_t mesq_noop;
35965- atomic_long_t mesq_send_unexpected_error;
35966- atomic_long_t mesq_send_lb_overflow;
35967- atomic_long_t mesq_send_qlimit_reached;
35968- atomic_long_t mesq_send_amo_nacked;
35969- atomic_long_t mesq_send_put_nacked;
35970- atomic_long_t mesq_page_overflow;
35971- atomic_long_t mesq_qf_locked;
35972- atomic_long_t mesq_qf_noop_not_full;
35973- atomic_long_t mesq_qf_switch_head_failed;
35974- atomic_long_t mesq_qf_unexpected_error;
35975- atomic_long_t mesq_noop_unexpected_error;
35976- atomic_long_t mesq_noop_lb_overflow;
35977- atomic_long_t mesq_noop_qlimit_reached;
35978- atomic_long_t mesq_noop_amo_nacked;
35979- atomic_long_t mesq_noop_put_nacked;
35980- atomic_long_t mesq_noop_page_overflow;
35981+ atomic_long_unchecked_t mesq_receive;
35982+ atomic_long_unchecked_t mesq_receive_none;
35983+ atomic_long_unchecked_t mesq_send;
35984+ atomic_long_unchecked_t mesq_send_failed;
35985+ atomic_long_unchecked_t mesq_noop;
35986+ atomic_long_unchecked_t mesq_send_unexpected_error;
35987+ atomic_long_unchecked_t mesq_send_lb_overflow;
35988+ atomic_long_unchecked_t mesq_send_qlimit_reached;
35989+ atomic_long_unchecked_t mesq_send_amo_nacked;
35990+ atomic_long_unchecked_t mesq_send_put_nacked;
35991+ atomic_long_unchecked_t mesq_page_overflow;
35992+ atomic_long_unchecked_t mesq_qf_locked;
35993+ atomic_long_unchecked_t mesq_qf_noop_not_full;
35994+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
35995+ atomic_long_unchecked_t mesq_qf_unexpected_error;
35996+ atomic_long_unchecked_t mesq_noop_unexpected_error;
35997+ atomic_long_unchecked_t mesq_noop_lb_overflow;
35998+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
35999+ atomic_long_unchecked_t mesq_noop_amo_nacked;
36000+ atomic_long_unchecked_t mesq_noop_put_nacked;
36001+ atomic_long_unchecked_t mesq_noop_page_overflow;
36002
36003 };
36004
36005@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36006 tghop_invalidate, mcsop_last};
36007
36008 struct mcs_op_statistic {
36009- atomic_long_t count;
36010- atomic_long_t total;
36011+ atomic_long_unchecked_t count;
36012+ atomic_long_unchecked_t total;
36013 unsigned long max;
36014 };
36015
36016@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36017
36018 #define STAT(id) do { \
36019 if (gru_options & OPT_STATS) \
36020- atomic_long_inc(&gru_stats.id); \
36021+ atomic_long_inc_unchecked(&gru_stats.id); \
36022 } while (0)
36023
36024 #ifdef CONFIG_SGI_GRU_DEBUG
36025diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36026index c862cd4..0d176fe 100644
36027--- a/drivers/misc/sgi-xp/xp.h
36028+++ b/drivers/misc/sgi-xp/xp.h
36029@@ -288,7 +288,7 @@ struct xpc_interface {
36030 xpc_notify_func, void *);
36031 void (*received) (short, int, void *);
36032 enum xp_retval (*partid_to_nasids) (short, void *);
36033-};
36034+} __no_const;
36035
36036 extern struct xpc_interface xpc_interface;
36037
36038diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36039index b94d5f7..7f494c5 100644
36040--- a/drivers/misc/sgi-xp/xpc.h
36041+++ b/drivers/misc/sgi-xp/xpc.h
36042@@ -835,6 +835,7 @@ struct xpc_arch_operations {
36043 void (*received_payload) (struct xpc_channel *, void *);
36044 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36045 };
36046+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36047
36048 /* struct xpc_partition act_state values (for XPC HB) */
36049
36050@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36051 /* found in xpc_main.c */
36052 extern struct device *xpc_part;
36053 extern struct device *xpc_chan;
36054-extern struct xpc_arch_operations xpc_arch_ops;
36055+extern xpc_arch_operations_no_const xpc_arch_ops;
36056 extern int xpc_disengage_timelimit;
36057 extern int xpc_disengage_timedout;
36058 extern int xpc_activate_IRQ_rcvd;
36059diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36060index d971817..33bdca5 100644
36061--- a/drivers/misc/sgi-xp/xpc_main.c
36062+++ b/drivers/misc/sgi-xp/xpc_main.c
36063@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36064 .notifier_call = xpc_system_die,
36065 };
36066
36067-struct xpc_arch_operations xpc_arch_ops;
36068+xpc_arch_operations_no_const xpc_arch_ops;
36069
36070 /*
36071 * Timer function to enforce the timelimit on the partition disengage.
36072@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36073
36074 if (((die_args->trapnr == X86_TRAP_MF) ||
36075 (die_args->trapnr == X86_TRAP_XF)) &&
36076- !user_mode_vm(die_args->regs))
36077+ !user_mode(die_args->regs))
36078 xpc_die_deactivate();
36079
36080 break;
36081diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36082index a0e1720..ee63d0b 100644
36083--- a/drivers/mmc/core/mmc_ops.c
36084+++ b/drivers/mmc/core/mmc_ops.c
36085@@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36086 void *data_buf;
36087 int is_on_stack;
36088
36089- is_on_stack = object_is_on_stack(buf);
36090+ is_on_stack = object_starts_on_stack(buf);
36091 if (is_on_stack) {
36092 /*
36093 * dma onto stack is unsafe/nonportable, but callers to this
36094diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36095index 53b8fd9..615b462 100644
36096--- a/drivers/mmc/host/dw_mmc.h
36097+++ b/drivers/mmc/host/dw_mmc.h
36098@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36099 int (*parse_dt)(struct dw_mci *host);
36100 int (*setup_bus)(struct dw_mci *host,
36101 struct device_node *slot_np, u8 bus_width);
36102-};
36103+} __do_const;
36104 #endif /* _DW_MMC_H_ */
36105diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
36106index c9ec725..178e79a 100644
36107--- a/drivers/mmc/host/sdhci-s3c.c
36108+++ b/drivers/mmc/host/sdhci-s3c.c
36109@@ -719,9 +719,11 @@ static int __devinit sdhci_s3c_probe(struct platform_device *pdev)
36110 * we can use overriding functions instead of default.
36111 */
36112 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
36113- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36114- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36115- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36116+ pax_open_kernel();
36117+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
36118+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
36119+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
36120+ pax_close_kernel();
36121 }
36122
36123 /* It supports additional host capabilities if needed */
36124diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36125index a4eb8b5..8c0628f 100644
36126--- a/drivers/mtd/devices/doc2000.c
36127+++ b/drivers/mtd/devices/doc2000.c
36128@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36129
36130 /* The ECC will not be calculated correctly if less than 512 is written */
36131 /* DBB-
36132- if (len != 0x200 && eccbuf)
36133+ if (len != 0x200)
36134 printk(KERN_WARNING
36135 "ECC needs a full sector write (adr: %lx size %lx)\n",
36136 (long) to, (long) len);
36137diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36138index e706a23..b3d262f 100644
36139--- a/drivers/mtd/nand/denali.c
36140+++ b/drivers/mtd/nand/denali.c
36141@@ -26,6 +26,7 @@
36142 #include <linux/pci.h>
36143 #include <linux/mtd/mtd.h>
36144 #include <linux/module.h>
36145+#include <linux/slab.h>
36146
36147 #include "denali.h"
36148
36149diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36150index 51b9d6a..52af9a7 100644
36151--- a/drivers/mtd/nftlmount.c
36152+++ b/drivers/mtd/nftlmount.c
36153@@ -24,6 +24,7 @@
36154 #include <asm/errno.h>
36155 #include <linux/delay.h>
36156 #include <linux/slab.h>
36157+#include <linux/sched.h>
36158 #include <linux/mtd/mtd.h>
36159 #include <linux/mtd/nand.h>
36160 #include <linux/mtd/nftl.h>
36161diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36162index 203ff9d..0968ca8 100644
36163--- a/drivers/net/ethernet/8390/ax88796.c
36164+++ b/drivers/net/ethernet/8390/ax88796.c
36165@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36166 if (ax->plat->reg_offsets)
36167 ei_local->reg_offset = ax->plat->reg_offsets;
36168 else {
36169+ resource_size_t _mem_size = mem_size;
36170+ do_div(_mem_size, 0x18);
36171 ei_local->reg_offset = ax->reg_offsets;
36172 for (ret = 0; ret < 0x18; ret++)
36173- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36174+ ax->reg_offsets[ret] = _mem_size * ret;
36175 }
36176
36177 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36178diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36179index 9c5ea6c..eaad276 100644
36180--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36181+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36182@@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36183 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36184 {
36185 /* RX_MODE controlling object */
36186- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36187+ bnx2x_init_rx_mode_obj(bp);
36188
36189 /* multicast configuration controlling object */
36190 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36191diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36192index 614981c..11216c7 100644
36193--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36194+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36195@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36196 return rc;
36197 }
36198
36199-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36200- struct bnx2x_rx_mode_obj *o)
36201+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36202 {
36203 if (CHIP_IS_E1x(bp)) {
36204- o->wait_comp = bnx2x_empty_rx_mode_wait;
36205- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36206+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36207+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36208 } else {
36209- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36210- o->config_rx_mode = bnx2x_set_rx_mode_e2;
36211+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36212+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36213 }
36214 }
36215
36216diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36217index acf2fe4..efb96df 100644
36218--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36219+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36220@@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36221
36222 /********************* RX MODE ****************/
36223
36224-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36225- struct bnx2x_rx_mode_obj *o);
36226+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36227
36228 /**
36229 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36230diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36231index d9308c32..d87b824 100644
36232--- a/drivers/net/ethernet/broadcom/tg3.h
36233+++ b/drivers/net/ethernet/broadcom/tg3.h
36234@@ -140,6 +140,7 @@
36235 #define CHIPREV_ID_5750_A0 0x4000
36236 #define CHIPREV_ID_5750_A1 0x4001
36237 #define CHIPREV_ID_5750_A3 0x4003
36238+#define CHIPREV_ID_5750_C1 0x4201
36239 #define CHIPREV_ID_5750_C2 0x4202
36240 #define CHIPREV_ID_5752_A0_HW 0x5000
36241 #define CHIPREV_ID_5752_A0 0x6000
36242diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36243index 8cffcdf..aadf043 100644
36244--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36245+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36246@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36247 */
36248 struct l2t_skb_cb {
36249 arp_failure_handler_func arp_failure_handler;
36250-};
36251+} __no_const;
36252
36253 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36254
36255diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36256index f879e92..726f20f 100644
36257--- a/drivers/net/ethernet/dec/tulip/de4x5.c
36258+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36259@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36260 for (i=0; i<ETH_ALEN; i++) {
36261 tmp.addr[i] = dev->dev_addr[i];
36262 }
36263- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36264+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36265 break;
36266
36267 case DE4X5_SET_HWADDR: /* Set the hardware address */
36268@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36269 spin_lock_irqsave(&lp->lock, flags);
36270 memcpy(&statbuf, &lp->pktStats, ioc->len);
36271 spin_unlock_irqrestore(&lp->lock, flags);
36272- if (copy_to_user(ioc->data, &statbuf, ioc->len))
36273+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36274 return -EFAULT;
36275 break;
36276 }
36277diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36278index d1b6cc5..cde0d97 100644
36279--- a/drivers/net/ethernet/emulex/benet/be_main.c
36280+++ b/drivers/net/ethernet/emulex/benet/be_main.c
36281@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36282
36283 if (wrapped)
36284 newacc += 65536;
36285- ACCESS_ONCE(*acc) = newacc;
36286+ ACCESS_ONCE_RW(*acc) = newacc;
36287 }
36288
36289 void be_parse_stats(struct be_adapter *adapter)
36290diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36291index 74d749e..eefb1bd 100644
36292--- a/drivers/net/ethernet/faraday/ftgmac100.c
36293+++ b/drivers/net/ethernet/faraday/ftgmac100.c
36294@@ -31,6 +31,8 @@
36295 #include <linux/netdevice.h>
36296 #include <linux/phy.h>
36297 #include <linux/platform_device.h>
36298+#include <linux/interrupt.h>
36299+#include <linux/irqreturn.h>
36300 #include <net/ip.h>
36301
36302 #include "ftgmac100.h"
36303diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36304index b901a01..1ff32ee 100644
36305--- a/drivers/net/ethernet/faraday/ftmac100.c
36306+++ b/drivers/net/ethernet/faraday/ftmac100.c
36307@@ -31,6 +31,8 @@
36308 #include <linux/module.h>
36309 #include <linux/netdevice.h>
36310 #include <linux/platform_device.h>
36311+#include <linux/interrupt.h>
36312+#include <linux/irqreturn.h>
36313
36314 #include "ftmac100.h"
36315
36316diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36317index d929131..aed108f 100644
36318--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36319+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36320@@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36321 /* store the new cycle speed */
36322 adapter->cycle_speed = cycle_speed;
36323
36324- ACCESS_ONCE(adapter->base_incval) = incval;
36325+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
36326 smp_mb();
36327
36328 /* grab the ptp lock */
36329diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36330index c2e420a..26a75e0 100644
36331--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36332+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36333@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36334 struct __vxge_hw_fifo *fifo;
36335 struct vxge_hw_fifo_config *config;
36336 u32 txdl_size, txdl_per_memblock;
36337- struct vxge_hw_mempool_cbs fifo_mp_callback;
36338+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36339+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36340+ };
36341+
36342 struct __vxge_hw_virtualpath *vpath;
36343
36344 if ((vp == NULL) || (attr == NULL)) {
36345@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36346 goto exit;
36347 }
36348
36349- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36350-
36351 fifo->mempool =
36352 __vxge_hw_mempool_create(vpath->hldev,
36353 fifo->config->memblock_size,
36354diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36355index 6afe74e..2e2950f 100644
36356--- a/drivers/net/ethernet/realtek/r8169.c
36357+++ b/drivers/net/ethernet/realtek/r8169.c
36358@@ -747,22 +747,22 @@ struct rtl8169_private {
36359 struct mdio_ops {
36360 void (*write)(struct rtl8169_private *, int, int);
36361 int (*read)(struct rtl8169_private *, int);
36362- } mdio_ops;
36363+ } __no_const mdio_ops;
36364
36365 struct pll_power_ops {
36366 void (*down)(struct rtl8169_private *);
36367 void (*up)(struct rtl8169_private *);
36368- } pll_power_ops;
36369+ } __no_const pll_power_ops;
36370
36371 struct jumbo_ops {
36372 void (*enable)(struct rtl8169_private *);
36373 void (*disable)(struct rtl8169_private *);
36374- } jumbo_ops;
36375+ } __no_const jumbo_ops;
36376
36377 struct csi_ops {
36378 void (*write)(struct rtl8169_private *, int, int);
36379 u32 (*read)(struct rtl8169_private *, int);
36380- } csi_ops;
36381+ } __no_const csi_ops;
36382
36383 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36384 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36385diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36386index 0767043f..08c2553 100644
36387--- a/drivers/net/ethernet/sfc/ptp.c
36388+++ b/drivers/net/ethernet/sfc/ptp.c
36389@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36390 (u32)((u64)ptp->start.dma_addr >> 32));
36391
36392 /* Clear flag that signals MC ready */
36393- ACCESS_ONCE(*start) = 0;
36394+ ACCESS_ONCE_RW(*start) = 0;
36395 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36396 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36397
36398diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36399index 0c74a70..3bc6f68 100644
36400--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36401+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36402@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36403
36404 writel(value, ioaddr + MMC_CNTRL);
36405
36406- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36407- MMC_CNTRL, value);
36408+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36409+// MMC_CNTRL, value);
36410 }
36411
36412 /* To mask all all interrupts.*/
36413diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36414index 5fd6f46..ee1f265 100644
36415--- a/drivers/net/hyperv/hyperv_net.h
36416+++ b/drivers/net/hyperv/hyperv_net.h
36417@@ -101,7 +101,7 @@ struct rndis_device {
36418
36419 enum rndis_device_state state;
36420 bool link_state;
36421- atomic_t new_req_id;
36422+ atomic_unchecked_t new_req_id;
36423
36424 spinlock_t request_lock;
36425 struct list_head req_list;
36426diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36427index 928148c..d83298e 100644
36428--- a/drivers/net/hyperv/rndis_filter.c
36429+++ b/drivers/net/hyperv/rndis_filter.c
36430@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36431 * template
36432 */
36433 set = &rndis_msg->msg.set_req;
36434- set->req_id = atomic_inc_return(&dev->new_req_id);
36435+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36436
36437 /* Add to the request list */
36438 spin_lock_irqsave(&dev->request_lock, flags);
36439@@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36440
36441 /* Setup the rndis set */
36442 halt = &request->request_msg.msg.halt_req;
36443- halt->req_id = atomic_inc_return(&dev->new_req_id);
36444+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36445
36446 /* Ignore return since this msg is optional. */
36447 rndis_filter_send_request(dev, request);
36448diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36449index 7d39add..037e1da 100644
36450--- a/drivers/net/ieee802154/fakehard.c
36451+++ b/drivers/net/ieee802154/fakehard.c
36452@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36453 phy->transmit_power = 0xbf;
36454
36455 dev->netdev_ops = &fake_ops;
36456- dev->ml_priv = &fake_mlme;
36457+ dev->ml_priv = (void *)&fake_mlme;
36458
36459 priv = netdev_priv(dev);
36460 priv->phy = phy;
36461diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36462index 0f0f9ce..0ca5819 100644
36463--- a/drivers/net/macvtap.c
36464+++ b/drivers/net/macvtap.c
36465@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36466 return NOTIFY_DONE;
36467 }
36468
36469-static struct notifier_block macvtap_notifier_block __read_mostly = {
36470+static struct notifier_block macvtap_notifier_block = {
36471 .notifier_call = macvtap_device_event,
36472 };
36473
36474diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36475index daec9b0..6428fcb 100644
36476--- a/drivers/net/phy/mdio-bitbang.c
36477+++ b/drivers/net/phy/mdio-bitbang.c
36478@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36479 struct mdiobb_ctrl *ctrl = bus->priv;
36480
36481 module_put(ctrl->ops->owner);
36482+ mdiobus_unregister(bus);
36483 mdiobus_free(bus);
36484 }
36485 EXPORT_SYMBOL(free_mdio_bitbang);
36486diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36487index eb3f5ce..d773730 100644
36488--- a/drivers/net/ppp/ppp_generic.c
36489+++ b/drivers/net/ppp/ppp_generic.c
36490@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36491 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36492 struct ppp_stats stats;
36493 struct ppp_comp_stats cstats;
36494- char *vers;
36495
36496 switch (cmd) {
36497 case SIOCGPPPSTATS:
36498@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36499 break;
36500
36501 case SIOCGPPPVER:
36502- vers = PPP_VERSION;
36503- if (copy_to_user(addr, vers, strlen(vers) + 1))
36504+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36505 break;
36506 err = 0;
36507 break;
36508diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36509index ad86660..9fd0884 100644
36510--- a/drivers/net/team/team.c
36511+++ b/drivers/net/team/team.c
36512@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36513 return NOTIFY_DONE;
36514 }
36515
36516-static struct notifier_block team_notifier_block __read_mostly = {
36517+static struct notifier_block team_notifier_block = {
36518 .notifier_call = team_device_event,
36519 };
36520
36521diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36522index 0873cdc..ddb178e 100644
36523--- a/drivers/net/tun.c
36524+++ b/drivers/net/tun.c
36525@@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36526 }
36527
36528 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36529- unsigned long arg, int ifreq_len)
36530+ unsigned long arg, size_t ifreq_len)
36531 {
36532 struct tun_file *tfile = file->private_data;
36533 struct tun_struct *tun;
36534@@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36535 int vnet_hdr_sz;
36536 int ret;
36537
36538+ if (ifreq_len > sizeof ifr)
36539+ return -EFAULT;
36540+
36541 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36542 if (copy_from_user(&ifr, argp, ifreq_len))
36543 return -EFAULT;
36544diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36545index 605a4ba..a883dd1 100644
36546--- a/drivers/net/usb/hso.c
36547+++ b/drivers/net/usb/hso.c
36548@@ -71,7 +71,7 @@
36549 #include <asm/byteorder.h>
36550 #include <linux/serial_core.h>
36551 #include <linux/serial.h>
36552-
36553+#include <asm/local.h>
36554
36555 #define MOD_AUTHOR "Option Wireless"
36556 #define MOD_DESCRIPTION "USB High Speed Option driver"
36557@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36558 struct urb *urb;
36559
36560 urb = serial->rx_urb[0];
36561- if (serial->port.count > 0) {
36562+ if (atomic_read(&serial->port.count) > 0) {
36563 count = put_rxbuf_data(urb, serial);
36564 if (count == -1)
36565 return;
36566@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36567 DUMP1(urb->transfer_buffer, urb->actual_length);
36568
36569 /* Anyone listening? */
36570- if (serial->port.count == 0)
36571+ if (atomic_read(&serial->port.count) == 0)
36572 return;
36573
36574 if (status == 0) {
36575@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36576 tty_port_tty_set(&serial->port, tty);
36577
36578 /* check for port already opened, if not set the termios */
36579- serial->port.count++;
36580- if (serial->port.count == 1) {
36581+ if (atomic_inc_return(&serial->port.count) == 1) {
36582 serial->rx_state = RX_IDLE;
36583 /* Force default termio settings */
36584 _hso_serial_set_termios(tty, NULL);
36585@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36586 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36587 if (result) {
36588 hso_stop_serial_device(serial->parent);
36589- serial->port.count--;
36590+ atomic_dec(&serial->port.count);
36591 kref_put(&serial->parent->ref, hso_serial_ref_free);
36592 }
36593 } else {
36594@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36595
36596 /* reset the rts and dtr */
36597 /* do the actual close */
36598- serial->port.count--;
36599+ atomic_dec(&serial->port.count);
36600
36601- if (serial->port.count <= 0) {
36602- serial->port.count = 0;
36603+ if (atomic_read(&serial->port.count) <= 0) {
36604+ atomic_set(&serial->port.count, 0);
36605 tty_port_tty_set(&serial->port, NULL);
36606 if (!usb_gone)
36607 hso_stop_serial_device(serial->parent);
36608@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36609
36610 /* the actual setup */
36611 spin_lock_irqsave(&serial->serial_lock, flags);
36612- if (serial->port.count)
36613+ if (atomic_read(&serial->port.count))
36614 _hso_serial_set_termios(tty, old);
36615 else
36616 tty->termios = *old;
36617@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36618 D1("Pending read interrupt on port %d\n", i);
36619 spin_lock(&serial->serial_lock);
36620 if (serial->rx_state == RX_IDLE &&
36621- serial->port.count > 0) {
36622+ atomic_read(&serial->port.count) > 0) {
36623 /* Setup and send a ctrl req read on
36624 * port i */
36625 if (!serial->rx_urb_filled[0]) {
36626@@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36627 /* Start all serial ports */
36628 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36629 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36630- if (dev2ser(serial_table[i])->port.count) {
36631+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36632 result =
36633 hso_start_serial_device(serial_table[i], GFP_NOIO);
36634 hso_kick_transmit(dev2ser(serial_table[i]));
36635diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c
36636index edb81ed..ab8931c 100644
36637--- a/drivers/net/usb/usbnet.c
36638+++ b/drivers/net/usb/usbnet.c
36639@@ -380,6 +380,12 @@ static int rx_submit (struct usbnet *dev, struct urb *urb, gfp_t flags)
36640 unsigned long lockflags;
36641 size_t size = dev->rx_urb_size;
36642
36643+ /* prevent rx skb allocation when error ratio is high */
36644+ if (test_bit(EVENT_RX_KILL, &dev->flags)) {
36645+ usb_free_urb(urb);
36646+ return -ENOLINK;
36647+ }
36648+
36649 skb = __netdev_alloc_skb_ip_align(dev->net, size, flags);
36650 if (!skb) {
36651 netif_dbg(dev, rx_err, dev->net, "no rx skb\n");
36652@@ -539,6 +545,17 @@ block:
36653 break;
36654 }
36655
36656+ /* stop rx if packet error rate is high */
36657+ if (++dev->pkt_cnt > 30) {
36658+ dev->pkt_cnt = 0;
36659+ dev->pkt_err = 0;
36660+ } else {
36661+ if (state == rx_cleanup)
36662+ dev->pkt_err++;
36663+ if (dev->pkt_err > 20)
36664+ set_bit(EVENT_RX_KILL, &dev->flags);
36665+ }
36666+
36667 state = defer_bh(dev, skb, &dev->rxq, state);
36668
36669 if (urb) {
36670@@ -790,6 +807,11 @@ int usbnet_open (struct net_device *net)
36671 (dev->driver_info->flags & FLAG_FRAMING_AX) ? "ASIX" :
36672 "simple");
36673
36674+ /* reset rx error state */
36675+ dev->pkt_cnt = 0;
36676+ dev->pkt_err = 0;
36677+ clear_bit(EVENT_RX_KILL, &dev->flags);
36678+
36679 // delay posting reads until we're fully open
36680 tasklet_schedule (&dev->bh);
36681 if (info->manage_power) {
36682@@ -1253,6 +1275,9 @@ static void usbnet_bh (unsigned long param)
36683 }
36684 }
36685
36686+ /* restart RX again after disabling due to high error rate */
36687+ clear_bit(EVENT_RX_KILL, &dev->flags);
36688+
36689 // waiting for all pending urbs to complete?
36690 if (dev->wait) {
36691 if ((dev->txq.qlen + dev->rxq.qlen + dev->done.qlen) == 0) {
36692diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36693index 8d78253..bebbb68 100644
36694--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36695+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36696@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36697 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36698 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36699
36700- ACCESS_ONCE(ads->ds_link) = i->link;
36701- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36702+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
36703+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36704
36705 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36706 ctl6 = SM(i->keytype, AR_EncrType);
36707@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36708
36709 if ((i->is_first || i->is_last) &&
36710 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36711- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36712+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36713 | set11nTries(i->rates, 1)
36714 | set11nTries(i->rates, 2)
36715 | set11nTries(i->rates, 3)
36716 | (i->dur_update ? AR_DurUpdateEna : 0)
36717 | SM(0, AR_BurstDur);
36718
36719- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36720+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36721 | set11nRate(i->rates, 1)
36722 | set11nRate(i->rates, 2)
36723 | set11nRate(i->rates, 3);
36724 } else {
36725- ACCESS_ONCE(ads->ds_ctl2) = 0;
36726- ACCESS_ONCE(ads->ds_ctl3) = 0;
36727+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36728+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36729 }
36730
36731 if (!i->is_first) {
36732- ACCESS_ONCE(ads->ds_ctl0) = 0;
36733- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36734- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36735+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36736+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36737+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36738 return;
36739 }
36740
36741@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36742 break;
36743 }
36744
36745- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36746+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36747 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36748 | SM(i->txpower, AR_XmitPower)
36749 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36750@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36751 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36752 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36753
36754- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36755- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36756+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36757+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36758
36759 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36760 return;
36761
36762- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36763+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36764 | set11nPktDurRTSCTS(i->rates, 1);
36765
36766- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36767+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36768 | set11nPktDurRTSCTS(i->rates, 3);
36769
36770- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36771+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36772 | set11nRateFlags(i->rates, 1)
36773 | set11nRateFlags(i->rates, 2)
36774 | set11nRateFlags(i->rates, 3)
36775diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36776index 301bf72..3f5654f 100644
36777--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36778+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36779@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36780 (i->qcu << AR_TxQcuNum_S) | desc_len;
36781
36782 checksum += val;
36783- ACCESS_ONCE(ads->info) = val;
36784+ ACCESS_ONCE_RW(ads->info) = val;
36785
36786 checksum += i->link;
36787- ACCESS_ONCE(ads->link) = i->link;
36788+ ACCESS_ONCE_RW(ads->link) = i->link;
36789
36790 checksum += i->buf_addr[0];
36791- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36792+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36793 checksum += i->buf_addr[1];
36794- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36795+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36796 checksum += i->buf_addr[2];
36797- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36798+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36799 checksum += i->buf_addr[3];
36800- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36801+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36802
36803 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36804- ACCESS_ONCE(ads->ctl3) = val;
36805+ ACCESS_ONCE_RW(ads->ctl3) = val;
36806 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36807- ACCESS_ONCE(ads->ctl5) = val;
36808+ ACCESS_ONCE_RW(ads->ctl5) = val;
36809 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36810- ACCESS_ONCE(ads->ctl7) = val;
36811+ ACCESS_ONCE_RW(ads->ctl7) = val;
36812 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36813- ACCESS_ONCE(ads->ctl9) = val;
36814+ ACCESS_ONCE_RW(ads->ctl9) = val;
36815
36816 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36817- ACCESS_ONCE(ads->ctl10) = checksum;
36818+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
36819
36820 if (i->is_first || i->is_last) {
36821- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36822+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36823 | set11nTries(i->rates, 1)
36824 | set11nTries(i->rates, 2)
36825 | set11nTries(i->rates, 3)
36826 | (i->dur_update ? AR_DurUpdateEna : 0)
36827 | SM(0, AR_BurstDur);
36828
36829- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36830+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36831 | set11nRate(i->rates, 1)
36832 | set11nRate(i->rates, 2)
36833 | set11nRate(i->rates, 3);
36834 } else {
36835- ACCESS_ONCE(ads->ctl13) = 0;
36836- ACCESS_ONCE(ads->ctl14) = 0;
36837+ ACCESS_ONCE_RW(ads->ctl13) = 0;
36838+ ACCESS_ONCE_RW(ads->ctl14) = 0;
36839 }
36840
36841 ads->ctl20 = 0;
36842@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36843
36844 ctl17 = SM(i->keytype, AR_EncrType);
36845 if (!i->is_first) {
36846- ACCESS_ONCE(ads->ctl11) = 0;
36847- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36848- ACCESS_ONCE(ads->ctl15) = 0;
36849- ACCESS_ONCE(ads->ctl16) = 0;
36850- ACCESS_ONCE(ads->ctl17) = ctl17;
36851- ACCESS_ONCE(ads->ctl18) = 0;
36852- ACCESS_ONCE(ads->ctl19) = 0;
36853+ ACCESS_ONCE_RW(ads->ctl11) = 0;
36854+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36855+ ACCESS_ONCE_RW(ads->ctl15) = 0;
36856+ ACCESS_ONCE_RW(ads->ctl16) = 0;
36857+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36858+ ACCESS_ONCE_RW(ads->ctl18) = 0;
36859+ ACCESS_ONCE_RW(ads->ctl19) = 0;
36860 return;
36861 }
36862
36863- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36864+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36865 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36866 | SM(i->txpower, AR_XmitPower)
36867 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36868@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36869 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36870 ctl12 |= SM(val, AR_PAPRDChainMask);
36871
36872- ACCESS_ONCE(ads->ctl12) = ctl12;
36873- ACCESS_ONCE(ads->ctl17) = ctl17;
36874+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36875+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36876
36877- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36878+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36879 | set11nPktDurRTSCTS(i->rates, 1);
36880
36881- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36882+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36883 | set11nPktDurRTSCTS(i->rates, 3);
36884
36885- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36886+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36887 | set11nRateFlags(i->rates, 1)
36888 | set11nRateFlags(i->rates, 2)
36889 | set11nRateFlags(i->rates, 3)
36890 | SM(i->rtscts_rate, AR_RTSCTSRate);
36891
36892- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
36893+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
36894 }
36895
36896 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
36897diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
36898index b68aaf5..fb20845 100644
36899--- a/drivers/net/wireless/ath/ath9k/hw.h
36900+++ b/drivers/net/wireless/ath/ath9k/hw.h
36901@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
36902
36903 /* ANI */
36904 void (*ani_cache_ini_regs)(struct ath_hw *ah);
36905-};
36906+} __no_const;
36907
36908 /**
36909 * struct ath_hw_ops - callbacks used by hardware code and driver code
36910@@ -687,7 +687,7 @@ struct ath_hw_ops {
36911 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
36912 struct ath_hw_antcomb_conf *antconf);
36913 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
36914-};
36915+} __no_const;
36916
36917 struct ath_nf_limits {
36918 s16 max;
36919diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36920index 71ced17..cd82b12 100644
36921--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36922+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
36923@@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
36924 struct net_device *ndev,
36925 const struct brcmf_event_msg *e,
36926 void *data);
36927-};
36928+} __no_const;
36929
36930 /* basic structure of scan request */
36931 struct brcmf_cfg80211_scan_req {
36932@@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
36933 struct brcmf_cfg80211_iscan_eloop {
36934 s32 (*handler[WL_SCAN_ERSULTS_LAST])
36935 (struct brcmf_cfg80211_info *cfg);
36936-};
36937+} __no_const;
36938
36939 /* dongle iscan controller */
36940 struct brcmf_cfg80211_iscan_ctrl {
36941diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
36942index e252acb..6ad1e65 100644
36943--- a/drivers/net/wireless/iwlegacy/3945-mac.c
36944+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
36945@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
36946 */
36947 if (il3945_mod_params.disable_hw_scan) {
36948 D_INFO("Disabling hw_scan\n");
36949- il3945_mac_ops.hw_scan = NULL;
36950+ pax_open_kernel();
36951+ *(void **)&il3945_mac_ops.hw_scan = NULL;
36952+ pax_close_kernel();
36953 }
36954
36955 D_INFO("*** LOAD DRIVER ***\n");
36956diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36957index 1a98fa3..51e6661 100644
36958--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36959+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
36960@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
36961 {
36962 struct iwl_priv *priv = file->private_data;
36963 char buf[64];
36964- int buf_size;
36965+ size_t buf_size;
36966 u32 offset, len;
36967
36968 memset(buf, 0, sizeof(buf));
36969@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
36970 struct iwl_priv *priv = file->private_data;
36971
36972 char buf[8];
36973- int buf_size;
36974+ size_t buf_size;
36975 u32 reset_flag;
36976
36977 memset(buf, 0, sizeof(buf));
36978@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
36979 {
36980 struct iwl_priv *priv = file->private_data;
36981 char buf[8];
36982- int buf_size;
36983+ size_t buf_size;
36984 int ht40;
36985
36986 memset(buf, 0, sizeof(buf));
36987@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
36988 {
36989 struct iwl_priv *priv = file->private_data;
36990 char buf[8];
36991- int buf_size;
36992+ size_t buf_size;
36993 int value;
36994
36995 memset(buf, 0, sizeof(buf));
36996@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
36997 {
36998 struct iwl_priv *priv = file->private_data;
36999 char buf[8];
37000- int buf_size;
37001+ size_t buf_size;
37002 int clear;
37003
37004 memset(buf, 0, sizeof(buf));
37005@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37006 {
37007 struct iwl_priv *priv = file->private_data;
37008 char buf[8];
37009- int buf_size;
37010+ size_t buf_size;
37011 int trace;
37012
37013 memset(buf, 0, sizeof(buf));
37014@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37015 {
37016 struct iwl_priv *priv = file->private_data;
37017 char buf[8];
37018- int buf_size;
37019+ size_t buf_size;
37020 int missed;
37021
37022 memset(buf, 0, sizeof(buf));
37023@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37024
37025 struct iwl_priv *priv = file->private_data;
37026 char buf[8];
37027- int buf_size;
37028+ size_t buf_size;
37029 int plcp;
37030
37031 memset(buf, 0, sizeof(buf));
37032@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37033
37034 struct iwl_priv *priv = file->private_data;
37035 char buf[8];
37036- int buf_size;
37037+ size_t buf_size;
37038 int flush;
37039
37040 memset(buf, 0, sizeof(buf));
37041@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37042
37043 struct iwl_priv *priv = file->private_data;
37044 char buf[8];
37045- int buf_size;
37046+ size_t buf_size;
37047 int rts;
37048
37049 if (!priv->cfg->ht_params)
37050@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37051 {
37052 struct iwl_priv *priv = file->private_data;
37053 char buf[8];
37054- int buf_size;
37055+ size_t buf_size;
37056
37057 memset(buf, 0, sizeof(buf));
37058 buf_size = min(count, sizeof(buf) - 1);
37059@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37060 struct iwl_priv *priv = file->private_data;
37061 u32 event_log_flag;
37062 char buf[8];
37063- int buf_size;
37064+ size_t buf_size;
37065
37066 /* check that the interface is up */
37067 if (!iwl_is_ready(priv))
37068@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37069 struct iwl_priv *priv = file->private_data;
37070 char buf[8];
37071 u32 calib_disabled;
37072- int buf_size;
37073+ size_t buf_size;
37074
37075 memset(buf, 0, sizeof(buf));
37076 buf_size = min(count, sizeof(buf) - 1);
37077diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37078index fe0fffd..b4c5724 100644
37079--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37080+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37081@@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37082 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37083
37084 char buf[8];
37085- int buf_size;
37086+ size_t buf_size;
37087 u32 reset_flag;
37088
37089 memset(buf, 0, sizeof(buf));
37090@@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37091 {
37092 struct iwl_trans *trans = file->private_data;
37093 char buf[8];
37094- int buf_size;
37095+ size_t buf_size;
37096 int csr;
37097
37098 memset(buf, 0, sizeof(buf));
37099diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37100index 429ca32..f86236b 100644
37101--- a/drivers/net/wireless/mac80211_hwsim.c
37102+++ b/drivers/net/wireless/mac80211_hwsim.c
37103@@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37104 return -EINVAL;
37105
37106 if (fake_hw_scan) {
37107- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37108- mac80211_hwsim_ops.sw_scan_start = NULL;
37109- mac80211_hwsim_ops.sw_scan_complete = NULL;
37110+ pax_open_kernel();
37111+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37112+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37113+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37114+ pax_close_kernel();
37115 }
37116
37117 spin_lock_init(&hwsim_radio_lock);
37118diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37119index bd1f0cb..db85ab0 100644
37120--- a/drivers/net/wireless/rndis_wlan.c
37121+++ b/drivers/net/wireless/rndis_wlan.c
37122@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37123
37124 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37125
37126- if (rts_threshold < 0 || rts_threshold > 2347)
37127+ if (rts_threshold > 2347)
37128 rts_threshold = 2347;
37129
37130 tmp = cpu_to_le32(rts_threshold);
37131diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37132index 0751b35..246ba3e 100644
37133--- a/drivers/net/wireless/rt2x00/rt2x00.h
37134+++ b/drivers/net/wireless/rt2x00/rt2x00.h
37135@@ -398,7 +398,7 @@ struct rt2x00_intf {
37136 * for hardware which doesn't support hardware
37137 * sequence counting.
37138 */
37139- atomic_t seqno;
37140+ atomic_unchecked_t seqno;
37141 };
37142
37143 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37144diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37145index e488b94..14b6a0c 100644
37146--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37147+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37148@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37149 * sequence counter given by mac80211.
37150 */
37151 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37152- seqno = atomic_add_return(0x10, &intf->seqno);
37153+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37154 else
37155- seqno = atomic_read(&intf->seqno);
37156+ seqno = atomic_read_unchecked(&intf->seqno);
37157
37158 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37159 hdr->seq_ctrl |= cpu_to_le16(seqno);
37160diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37161index e2750a1..797e179 100644
37162--- a/drivers/net/wireless/ti/wl1251/sdio.c
37163+++ b/drivers/net/wireless/ti/wl1251/sdio.c
37164@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37165
37166 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37167
37168- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37169- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37170+ pax_open_kernel();
37171+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37172+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37173+ pax_close_kernel();
37174
37175 wl1251_info("using dedicated interrupt line");
37176 } else {
37177- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37178- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37179+ pax_open_kernel();
37180+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37181+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37182+ pax_close_kernel();
37183
37184 wl1251_info("using SDIO interrupt");
37185 }
37186diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37187index dadf1db..d9db7a7 100644
37188--- a/drivers/net/wireless/ti/wl12xx/main.c
37189+++ b/drivers/net/wireless/ti/wl12xx/main.c
37190@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37191 sizeof(wl->conf.mem));
37192
37193 /* read data preparation is only needed by wl127x */
37194- wl->ops->prepare_read = wl127x_prepare_read;
37195+ pax_open_kernel();
37196+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37197+ pax_close_kernel();
37198
37199 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37200 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37201@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37202 sizeof(wl->conf.mem));
37203
37204 /* read data preparation is only needed by wl127x */
37205- wl->ops->prepare_read = wl127x_prepare_read;
37206+ pax_open_kernel();
37207+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37208+ pax_close_kernel();
37209
37210 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37211 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37212diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37213index a39682a..1e8220c 100644
37214--- a/drivers/net/wireless/ti/wl18xx/main.c
37215+++ b/drivers/net/wireless/ti/wl18xx/main.c
37216@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37217 }
37218
37219 if (!checksum_param) {
37220- wl18xx_ops.set_rx_csum = NULL;
37221- wl18xx_ops.init_vif = NULL;
37222+ pax_open_kernel();
37223+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
37224+ *(void **)&wl18xx_ops.init_vif = NULL;
37225+ pax_close_kernel();
37226 }
37227
37228 /* Enable 11a Band only if we have 5G antennas */
37229diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37230index d93b2b6..ae50401 100644
37231--- a/drivers/oprofile/buffer_sync.c
37232+++ b/drivers/oprofile/buffer_sync.c
37233@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37234 if (cookie == NO_COOKIE)
37235 offset = pc;
37236 if (cookie == INVALID_COOKIE) {
37237- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37238+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37239 offset = pc;
37240 }
37241 if (cookie != last_cookie) {
37242@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37243 /* add userspace sample */
37244
37245 if (!mm) {
37246- atomic_inc(&oprofile_stats.sample_lost_no_mm);
37247+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37248 return 0;
37249 }
37250
37251 cookie = lookup_dcookie(mm, s->eip, &offset);
37252
37253 if (cookie == INVALID_COOKIE) {
37254- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37255+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37256 return 0;
37257 }
37258
37259@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37260 /* ignore backtraces if failed to add a sample */
37261 if (state == sb_bt_start) {
37262 state = sb_bt_ignore;
37263- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37264+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37265 }
37266 }
37267 release_mm(mm);
37268diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37269index c0cc4e7..44d4e54 100644
37270--- a/drivers/oprofile/event_buffer.c
37271+++ b/drivers/oprofile/event_buffer.c
37272@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37273 }
37274
37275 if (buffer_pos == buffer_size) {
37276- atomic_inc(&oprofile_stats.event_lost_overflow);
37277+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37278 return;
37279 }
37280
37281diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37282index ed2c3ec..deda85a 100644
37283--- a/drivers/oprofile/oprof.c
37284+++ b/drivers/oprofile/oprof.c
37285@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37286 if (oprofile_ops.switch_events())
37287 return;
37288
37289- atomic_inc(&oprofile_stats.multiplex_counter);
37290+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37291 start_switch_worker();
37292 }
37293
37294diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37295index 917d28e..d62d981 100644
37296--- a/drivers/oprofile/oprofile_stats.c
37297+++ b/drivers/oprofile/oprofile_stats.c
37298@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37299 cpu_buf->sample_invalid_eip = 0;
37300 }
37301
37302- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37303- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37304- atomic_set(&oprofile_stats.event_lost_overflow, 0);
37305- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37306- atomic_set(&oprofile_stats.multiplex_counter, 0);
37307+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37308+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37309+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37310+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37311+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37312 }
37313
37314
37315diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37316index 38b6fc0..b5cbfce 100644
37317--- a/drivers/oprofile/oprofile_stats.h
37318+++ b/drivers/oprofile/oprofile_stats.h
37319@@ -13,11 +13,11 @@
37320 #include <linux/atomic.h>
37321
37322 struct oprofile_stat_struct {
37323- atomic_t sample_lost_no_mm;
37324- atomic_t sample_lost_no_mapping;
37325- atomic_t bt_lost_no_mapping;
37326- atomic_t event_lost_overflow;
37327- atomic_t multiplex_counter;
37328+ atomic_unchecked_t sample_lost_no_mm;
37329+ atomic_unchecked_t sample_lost_no_mapping;
37330+ atomic_unchecked_t bt_lost_no_mapping;
37331+ atomic_unchecked_t event_lost_overflow;
37332+ atomic_unchecked_t multiplex_counter;
37333 };
37334
37335 extern struct oprofile_stat_struct oprofile_stats;
37336diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37337index 849357c..b83c1e0 100644
37338--- a/drivers/oprofile/oprofilefs.c
37339+++ b/drivers/oprofile/oprofilefs.c
37340@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37341
37342
37343 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37344- char const *name, atomic_t *val)
37345+ char const *name, atomic_unchecked_t *val)
37346 {
37347 return __oprofilefs_create_file(sb, root, name,
37348 &atomic_ro_fops, 0444, val);
37349diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37350index 3f56bc0..707d642 100644
37351--- a/drivers/parport/procfs.c
37352+++ b/drivers/parport/procfs.c
37353@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37354
37355 *ppos += len;
37356
37357- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37358+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37359 }
37360
37361 #ifdef CONFIG_PARPORT_1284
37362@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37363
37364 *ppos += len;
37365
37366- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37367+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37368 }
37369 #endif /* IEEE1284.3 support. */
37370
37371diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37372index a6a71c4..c91097b 100644
37373--- a/drivers/pci/hotplug/cpcihp_generic.c
37374+++ b/drivers/pci/hotplug/cpcihp_generic.c
37375@@ -73,7 +73,6 @@ static u16 port;
37376 static unsigned int enum_bit;
37377 static u8 enum_mask;
37378
37379-static struct cpci_hp_controller_ops generic_hpc_ops;
37380 static struct cpci_hp_controller generic_hpc;
37381
37382 static int __init validate_parameters(void)
37383@@ -139,6 +138,10 @@ static int query_enum(void)
37384 return ((value & enum_mask) == enum_mask);
37385 }
37386
37387+static struct cpci_hp_controller_ops generic_hpc_ops = {
37388+ .query_enum = query_enum,
37389+};
37390+
37391 static int __init cpcihp_generic_init(void)
37392 {
37393 int status;
37394@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37395 pci_dev_put(dev);
37396
37397 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37398- generic_hpc_ops.query_enum = query_enum;
37399 generic_hpc.ops = &generic_hpc_ops;
37400
37401 status = cpci_hp_register_controller(&generic_hpc);
37402diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37403index 6bf8d2a..9711ce0 100644
37404--- a/drivers/pci/hotplug/cpcihp_zt5550.c
37405+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37406@@ -59,7 +59,6 @@
37407 /* local variables */
37408 static bool debug;
37409 static bool poll;
37410-static struct cpci_hp_controller_ops zt5550_hpc_ops;
37411 static struct cpci_hp_controller zt5550_hpc;
37412
37413 /* Primary cPCI bus bridge device */
37414@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37415 return 0;
37416 }
37417
37418+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37419+ .query_enum = zt5550_hc_query_enum,
37420+};
37421+
37422 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37423 {
37424 int status;
37425@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37426 dbg("returned from zt5550_hc_config");
37427
37428 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37429- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37430 zt5550_hpc.ops = &zt5550_hpc_ops;
37431 if(!poll) {
37432 zt5550_hpc.irq = hc_dev->irq;
37433 zt5550_hpc.irq_flags = IRQF_SHARED;
37434 zt5550_hpc.dev_id = hc_dev;
37435
37436- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37437- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37438- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37439+ pax_open_kernel();
37440+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37441+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37442+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37443+ pax_open_kernel();
37444 } else {
37445 info("using ENUM# polling mode");
37446 }
37447diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37448index 76ba8a1..20ca857 100644
37449--- a/drivers/pci/hotplug/cpqphp_nvram.c
37450+++ b/drivers/pci/hotplug/cpqphp_nvram.c
37451@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37452
37453 void compaq_nvram_init (void __iomem *rom_start)
37454 {
37455+
37456+#ifndef CONFIG_PAX_KERNEXEC
37457 if (rom_start) {
37458 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37459 }
37460+#endif
37461+
37462 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37463
37464 /* initialize our int15 lock */
37465diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37466index 449f257..0731e96 100644
37467--- a/drivers/pci/pcie/aspm.c
37468+++ b/drivers/pci/pcie/aspm.c
37469@@ -27,9 +27,9 @@
37470 #define MODULE_PARAM_PREFIX "pcie_aspm."
37471
37472 /* Note: those are not register definitions */
37473-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37474-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37475-#define ASPM_STATE_L1 (4) /* L1 state */
37476+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37477+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37478+#define ASPM_STATE_L1 (4U) /* L1 state */
37479 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37480 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37481
37482diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37483index ec909af..e7517f3 100644
37484--- a/drivers/pci/probe.c
37485+++ b/drivers/pci/probe.c
37486@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37487 struct pci_bus_region region;
37488 bool bar_too_big = false, bar_disabled = false;
37489
37490- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37491+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37492
37493 /* No printks while decoding is disabled! */
37494 if (!dev->mmio_always_on) {
37495diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37496index 9b8505c..f00870a 100644
37497--- a/drivers/pci/proc.c
37498+++ b/drivers/pci/proc.c
37499@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37500 static int __init pci_proc_init(void)
37501 {
37502 struct pci_dev *dev = NULL;
37503+
37504+#ifdef CONFIG_GRKERNSEC_PROC_ADD
37505+#ifdef CONFIG_GRKERNSEC_PROC_USER
37506+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37507+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37508+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37509+#endif
37510+#else
37511 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37512+#endif
37513 proc_create("devices", 0, proc_bus_pci_dir,
37514 &proc_bus_pci_dev_operations);
37515 proc_initialized = 1;
37516diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37517index 75dd651..2af4c9a 100644
37518--- a/drivers/platform/x86/thinkpad_acpi.c
37519+++ b/drivers/platform/x86/thinkpad_acpi.c
37520@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37521 return 0;
37522 }
37523
37524-void static hotkey_mask_warn_incomplete_mask(void)
37525+static void hotkey_mask_warn_incomplete_mask(void)
37526 {
37527 /* log only what the user can fix... */
37528 const u32 wantedmask = hotkey_driver_mask &
37529@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37530 }
37531 }
37532
37533-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37534- struct tp_nvram_state *newn,
37535- const u32 event_mask)
37536-{
37537-
37538 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37539 do { \
37540 if ((event_mask & (1 << __scancode)) && \
37541@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37542 tpacpi_hotkey_send_key(__scancode); \
37543 } while (0)
37544
37545- void issue_volchange(const unsigned int oldvol,
37546- const unsigned int newvol)
37547- {
37548- unsigned int i = oldvol;
37549+static void issue_volchange(const unsigned int oldvol,
37550+ const unsigned int newvol,
37551+ const u32 event_mask)
37552+{
37553+ unsigned int i = oldvol;
37554
37555- while (i > newvol) {
37556- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37557- i--;
37558- }
37559- while (i < newvol) {
37560- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37561- i++;
37562- }
37563+ while (i > newvol) {
37564+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37565+ i--;
37566 }
37567+ while (i < newvol) {
37568+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37569+ i++;
37570+ }
37571+}
37572
37573- void issue_brightnesschange(const unsigned int oldbrt,
37574- const unsigned int newbrt)
37575- {
37576- unsigned int i = oldbrt;
37577+static void issue_brightnesschange(const unsigned int oldbrt,
37578+ const unsigned int newbrt,
37579+ const u32 event_mask)
37580+{
37581+ unsigned int i = oldbrt;
37582
37583- while (i > newbrt) {
37584- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37585- i--;
37586- }
37587- while (i < newbrt) {
37588- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37589- i++;
37590- }
37591+ while (i > newbrt) {
37592+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37593+ i--;
37594+ }
37595+ while (i < newbrt) {
37596+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37597+ i++;
37598 }
37599+}
37600
37601+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37602+ struct tp_nvram_state *newn,
37603+ const u32 event_mask)
37604+{
37605 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37606 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37607 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37608@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37609 oldn->volume_level != newn->volume_level) {
37610 /* recently muted, or repeated mute keypress, or
37611 * multiple presses ending in mute */
37612- issue_volchange(oldn->volume_level, newn->volume_level);
37613+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37614 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37615 }
37616 } else {
37617@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37618 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37619 }
37620 if (oldn->volume_level != newn->volume_level) {
37621- issue_volchange(oldn->volume_level, newn->volume_level);
37622+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37623 } else if (oldn->volume_toggle != newn->volume_toggle) {
37624 /* repeated vol up/down keypress at end of scale ? */
37625 if (newn->volume_level == 0)
37626@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37627 /* handle brightness */
37628 if (oldn->brightness_level != newn->brightness_level) {
37629 issue_brightnesschange(oldn->brightness_level,
37630- newn->brightness_level);
37631+ newn->brightness_level,
37632+ event_mask);
37633 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37634 /* repeated key presses that didn't change state */
37635 if (newn->brightness_level == 0)
37636@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37637 && !tp_features.bright_unkfw)
37638 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37639 }
37640+}
37641
37642 #undef TPACPI_COMPARE_KEY
37643 #undef TPACPI_MAY_SEND_KEY
37644-}
37645
37646 /*
37647 * Polling driver
37648diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37649index 769d265..a3a05ca 100644
37650--- a/drivers/pnp/pnpbios/bioscalls.c
37651+++ b/drivers/pnp/pnpbios/bioscalls.c
37652@@ -58,7 +58,7 @@ do { \
37653 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37654 } while(0)
37655
37656-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37657+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37658 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37659
37660 /*
37661@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37662
37663 cpu = get_cpu();
37664 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37665+
37666+ pax_open_kernel();
37667 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37668+ pax_close_kernel();
37669
37670 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37671 spin_lock_irqsave(&pnp_bios_lock, flags);
37672@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37673 :"memory");
37674 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37675
37676+ pax_open_kernel();
37677 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37678+ pax_close_kernel();
37679+
37680 put_cpu();
37681
37682 /* If we get here and this is set then the PnP BIOS faulted on us. */
37683@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37684 return status;
37685 }
37686
37687-void pnpbios_calls_init(union pnp_bios_install_struct *header)
37688+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37689 {
37690 int i;
37691
37692@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37693 pnp_bios_callpoint.offset = header->fields.pm16offset;
37694 pnp_bios_callpoint.segment = PNP_CS16;
37695
37696+ pax_open_kernel();
37697+
37698 for_each_possible_cpu(i) {
37699 struct desc_struct *gdt = get_cpu_gdt_table(i);
37700 if (!gdt)
37701@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37702 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37703 (unsigned long)__va(header->fields.pm16dseg));
37704 }
37705+
37706+ pax_close_kernel();
37707 }
37708diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37709index b0ecacb..7c9da2e 100644
37710--- a/drivers/pnp/resource.c
37711+++ b/drivers/pnp/resource.c
37712@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37713 return 1;
37714
37715 /* check if the resource is valid */
37716- if (*irq < 0 || *irq > 15)
37717+ if (*irq > 15)
37718 return 0;
37719
37720 /* check if the resource is reserved */
37721@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37722 return 1;
37723
37724 /* check if the resource is valid */
37725- if (*dma < 0 || *dma == 4 || *dma > 7)
37726+ if (*dma == 4 || *dma > 7)
37727 return 0;
37728
37729 /* check if the resource is reserved */
37730diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37731index 7df7c5f..bd48c47 100644
37732--- a/drivers/power/pda_power.c
37733+++ b/drivers/power/pda_power.c
37734@@ -37,7 +37,11 @@ static int polling;
37735
37736 #ifdef CONFIG_USB_OTG_UTILS
37737 static struct usb_phy *transceiver;
37738-static struct notifier_block otg_nb;
37739+static int otg_handle_notification(struct notifier_block *nb,
37740+ unsigned long event, void *unused);
37741+static struct notifier_block otg_nb = {
37742+ .notifier_call = otg_handle_notification
37743+};
37744 #endif
37745
37746 static struct regulator *ac_draw;
37747@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37748
37749 #ifdef CONFIG_USB_OTG_UTILS
37750 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37751- otg_nb.notifier_call = otg_handle_notification;
37752 ret = usb_register_notifier(transceiver, &otg_nb);
37753 if (ret) {
37754 dev_err(dev, "failure to register otg notifier\n");
37755diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37756index 8d53174..04c65de 100644
37757--- a/drivers/regulator/max8660.c
37758+++ b/drivers/regulator/max8660.c
37759@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37760 max8660->shadow_regs[MAX8660_OVER1] = 5;
37761 } else {
37762 /* Otherwise devices can be toggled via software */
37763- max8660_dcdc_ops.enable = max8660_dcdc_enable;
37764- max8660_dcdc_ops.disable = max8660_dcdc_disable;
37765+ pax_open_kernel();
37766+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37767+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37768+ pax_close_kernel();
37769 }
37770
37771 /*
37772diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37773index 1fa6381..f58834e 100644
37774--- a/drivers/regulator/mc13892-regulator.c
37775+++ b/drivers/regulator/mc13892-regulator.c
37776@@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37777 }
37778 mc13xxx_unlock(mc13892);
37779
37780- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37781+ pax_open_kernel();
37782+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37783 = mc13892_vcam_set_mode;
37784- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37785+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37786 = mc13892_vcam_get_mode;
37787+ pax_close_kernel();
37788
37789 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37790 ARRAY_SIZE(mc13892_regulators));
37791diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37792index cace6d3..f623fda 100644
37793--- a/drivers/rtc/rtc-dev.c
37794+++ b/drivers/rtc/rtc-dev.c
37795@@ -14,6 +14,7 @@
37796 #include <linux/module.h>
37797 #include <linux/rtc.h>
37798 #include <linux/sched.h>
37799+#include <linux/grsecurity.h>
37800 #include "rtc-core.h"
37801
37802 static dev_t rtc_devt;
37803@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37804 if (copy_from_user(&tm, uarg, sizeof(tm)))
37805 return -EFAULT;
37806
37807+ gr_log_timechange();
37808+
37809 return rtc_set_time(rtc, &tm);
37810
37811 case RTC_PIE_ON:
37812diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37813index 4ad7e36..d004679 100644
37814--- a/drivers/scsi/bfa/bfa.h
37815+++ b/drivers/scsi/bfa/bfa.h
37816@@ -196,7 +196,7 @@ struct bfa_hwif_s {
37817 u32 *end);
37818 int cpe_vec_q0;
37819 int rme_vec_q0;
37820-};
37821+} __no_const;
37822 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37823
37824 struct bfa_faa_cbfn_s {
37825diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37826index e693af6..2e525b6 100644
37827--- a/drivers/scsi/bfa/bfa_fcpim.h
37828+++ b/drivers/scsi/bfa/bfa_fcpim.h
37829@@ -36,7 +36,7 @@ struct bfa_iotag_s {
37830
37831 struct bfa_itn_s {
37832 bfa_isr_func_t isr;
37833-};
37834+} __no_const;
37835
37836 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37837 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37838diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37839index 23a90e7..9cf04ee 100644
37840--- a/drivers/scsi/bfa/bfa_ioc.h
37841+++ b/drivers/scsi/bfa/bfa_ioc.h
37842@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37843 bfa_ioc_disable_cbfn_t disable_cbfn;
37844 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37845 bfa_ioc_reset_cbfn_t reset_cbfn;
37846-};
37847+} __no_const;
37848
37849 /*
37850 * IOC event notification mechanism.
37851@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37852 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37853 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37854 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37855-};
37856+} __no_const;
37857
37858 /*
37859 * Queue element to wait for room in request queue. FIFO order is
37860diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37861index 593085a..47aa999 100644
37862--- a/drivers/scsi/hosts.c
37863+++ b/drivers/scsi/hosts.c
37864@@ -42,7 +42,7 @@
37865 #include "scsi_logging.h"
37866
37867
37868-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37869+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37870
37871
37872 static void scsi_host_cls_release(struct device *dev)
37873@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37874 * subtract one because we increment first then return, but we need to
37875 * know what the next host number was before increment
37876 */
37877- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37878+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37879 shost->dma_channel = 0xff;
37880
37881 /* These three are default values which can be overridden */
37882diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37883index 4217e49..9c77e3e 100644
37884--- a/drivers/scsi/hpsa.c
37885+++ b/drivers/scsi/hpsa.c
37886@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37887 unsigned long flags;
37888
37889 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37890- return h->access.command_completed(h, q);
37891+ return h->access->command_completed(h, q);
37892
37893 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
37894 a = rq->head[rq->current_entry];
37895@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
37896 while (!list_empty(&h->reqQ)) {
37897 c = list_entry(h->reqQ.next, struct CommandList, list);
37898 /* can't do anything if fifo is full */
37899- if ((h->access.fifo_full(h))) {
37900+ if ((h->access->fifo_full(h))) {
37901 dev_warn(&h->pdev->dev, "fifo full\n");
37902 break;
37903 }
37904@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
37905
37906 /* Tell the controller execute command */
37907 spin_unlock_irqrestore(&h->lock, flags);
37908- h->access.submit_command(h, c);
37909+ h->access->submit_command(h, c);
37910 spin_lock_irqsave(&h->lock, flags);
37911 }
37912 spin_unlock_irqrestore(&h->lock, flags);
37913@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
37914
37915 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
37916 {
37917- return h->access.command_completed(h, q);
37918+ return h->access->command_completed(h, q);
37919 }
37920
37921 static inline bool interrupt_pending(struct ctlr_info *h)
37922 {
37923- return h->access.intr_pending(h);
37924+ return h->access->intr_pending(h);
37925 }
37926
37927 static inline long interrupt_not_for_us(struct ctlr_info *h)
37928 {
37929- return (h->access.intr_pending(h) == 0) ||
37930+ return (h->access->intr_pending(h) == 0) ||
37931 (h->interrupts_enabled == 0);
37932 }
37933
37934@@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
37935 if (prod_index < 0)
37936 return -ENODEV;
37937 h->product_name = products[prod_index].product_name;
37938- h->access = *(products[prod_index].access);
37939+ h->access = products[prod_index].access;
37940
37941 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
37942 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
37943@@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
37944
37945 assert_spin_locked(&lockup_detector_lock);
37946 remove_ctlr_from_lockup_detector_list(h);
37947- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37948+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37949 spin_lock_irqsave(&h->lock, flags);
37950 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
37951 spin_unlock_irqrestore(&h->lock, flags);
37952@@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
37953 }
37954
37955 /* make sure the board interrupts are off */
37956- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37957+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37958
37959 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
37960 goto clean2;
37961@@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
37962 * fake ones to scoop up any residual completions.
37963 */
37964 spin_lock_irqsave(&h->lock, flags);
37965- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37966+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37967 spin_unlock_irqrestore(&h->lock, flags);
37968 free_irqs(h);
37969 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
37970@@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
37971 dev_info(&h->pdev->dev, "Board READY.\n");
37972 dev_info(&h->pdev->dev,
37973 "Waiting for stale completions to drain.\n");
37974- h->access.set_intr_mask(h, HPSA_INTR_ON);
37975+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37976 msleep(10000);
37977- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37978+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37979
37980 rc = controller_reset_failed(h->cfgtable);
37981 if (rc)
37982@@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
37983 }
37984
37985 /* Turn the interrupts on so we can service requests */
37986- h->access.set_intr_mask(h, HPSA_INTR_ON);
37987+ h->access->set_intr_mask(h, HPSA_INTR_ON);
37988
37989 hpsa_hba_inquiry(h);
37990 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
37991@@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
37992 * To write all data in the battery backed cache to disks
37993 */
37994 hpsa_flush_cache(h);
37995- h->access.set_intr_mask(h, HPSA_INTR_OFF);
37996+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
37997 hpsa_free_irqs_and_disable_msix(h);
37998 }
37999
38000@@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38001 return;
38002 }
38003 /* Change the access methods to the performant access methods */
38004- h->access = SA5_performant_access;
38005+ h->access = &SA5_performant_access;
38006 h->transMethod = CFGTBL_Trans_Performant;
38007 }
38008
38009diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38010index 9816479..c5d4e97 100644
38011--- a/drivers/scsi/hpsa.h
38012+++ b/drivers/scsi/hpsa.h
38013@@ -79,7 +79,7 @@ struct ctlr_info {
38014 unsigned int msix_vector;
38015 unsigned int msi_vector;
38016 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38017- struct access_method access;
38018+ struct access_method *access;
38019
38020 /* queue and queue Info */
38021 struct list_head reqQ;
38022diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38023index c772d8d..35c362c 100644
38024--- a/drivers/scsi/libfc/fc_exch.c
38025+++ b/drivers/scsi/libfc/fc_exch.c
38026@@ -100,12 +100,12 @@ struct fc_exch_mgr {
38027 u16 pool_max_index;
38028
38029 struct {
38030- atomic_t no_free_exch;
38031- atomic_t no_free_exch_xid;
38032- atomic_t xid_not_found;
38033- atomic_t xid_busy;
38034- atomic_t seq_not_found;
38035- atomic_t non_bls_resp;
38036+ atomic_unchecked_t no_free_exch;
38037+ atomic_unchecked_t no_free_exch_xid;
38038+ atomic_unchecked_t xid_not_found;
38039+ atomic_unchecked_t xid_busy;
38040+ atomic_unchecked_t seq_not_found;
38041+ atomic_unchecked_t non_bls_resp;
38042 } stats;
38043 };
38044
38045@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38046 /* allocate memory for exchange */
38047 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38048 if (!ep) {
38049- atomic_inc(&mp->stats.no_free_exch);
38050+ atomic_inc_unchecked(&mp->stats.no_free_exch);
38051 goto out;
38052 }
38053 memset(ep, 0, sizeof(*ep));
38054@@ -786,7 +786,7 @@ out:
38055 return ep;
38056 err:
38057 spin_unlock_bh(&pool->lock);
38058- atomic_inc(&mp->stats.no_free_exch_xid);
38059+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38060 mempool_free(ep, mp->ep_pool);
38061 return NULL;
38062 }
38063@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38064 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38065 ep = fc_exch_find(mp, xid);
38066 if (!ep) {
38067- atomic_inc(&mp->stats.xid_not_found);
38068+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38069 reject = FC_RJT_OX_ID;
38070 goto out;
38071 }
38072@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38073 ep = fc_exch_find(mp, xid);
38074 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38075 if (ep) {
38076- atomic_inc(&mp->stats.xid_busy);
38077+ atomic_inc_unchecked(&mp->stats.xid_busy);
38078 reject = FC_RJT_RX_ID;
38079 goto rel;
38080 }
38081@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38082 }
38083 xid = ep->xid; /* get our XID */
38084 } else if (!ep) {
38085- atomic_inc(&mp->stats.xid_not_found);
38086+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38087 reject = FC_RJT_RX_ID; /* XID not found */
38088 goto out;
38089 }
38090@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38091 } else {
38092 sp = &ep->seq;
38093 if (sp->id != fh->fh_seq_id) {
38094- atomic_inc(&mp->stats.seq_not_found);
38095+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38096 if (f_ctl & FC_FC_END_SEQ) {
38097 /*
38098 * Update sequence_id based on incoming last
38099@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38100
38101 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38102 if (!ep) {
38103- atomic_inc(&mp->stats.xid_not_found);
38104+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38105 goto out;
38106 }
38107 if (ep->esb_stat & ESB_ST_COMPLETE) {
38108- atomic_inc(&mp->stats.xid_not_found);
38109+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38110 goto rel;
38111 }
38112 if (ep->rxid == FC_XID_UNKNOWN)
38113 ep->rxid = ntohs(fh->fh_rx_id);
38114 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38115- atomic_inc(&mp->stats.xid_not_found);
38116+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38117 goto rel;
38118 }
38119 if (ep->did != ntoh24(fh->fh_s_id) &&
38120 ep->did != FC_FID_FLOGI) {
38121- atomic_inc(&mp->stats.xid_not_found);
38122+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38123 goto rel;
38124 }
38125 sof = fr_sof(fp);
38126@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38127 sp->ssb_stat |= SSB_ST_RESP;
38128 sp->id = fh->fh_seq_id;
38129 } else if (sp->id != fh->fh_seq_id) {
38130- atomic_inc(&mp->stats.seq_not_found);
38131+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38132 goto rel;
38133 }
38134
38135@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38136 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38137
38138 if (!sp)
38139- atomic_inc(&mp->stats.xid_not_found);
38140+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38141 else
38142- atomic_inc(&mp->stats.non_bls_resp);
38143+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38144
38145 fc_frame_free(fp);
38146 }
38147@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38148
38149 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38150 mp = ema->mp;
38151- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38152+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38153 st->fc_no_free_exch_xid +=
38154- atomic_read(&mp->stats.no_free_exch_xid);
38155- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38156- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38157- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38158- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38159+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38160+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38161+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38162+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38163+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38164 }
38165 }
38166 EXPORT_SYMBOL(fc_exch_update_stats);
38167diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38168index bdb81cd..d3c7c2c 100644
38169--- a/drivers/scsi/libsas/sas_ata.c
38170+++ b/drivers/scsi/libsas/sas_ata.c
38171@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38172 .postreset = ata_std_postreset,
38173 .error_handler = ata_std_error_handler,
38174 .post_internal_cmd = sas_ata_post_internal,
38175- .qc_defer = ata_std_qc_defer,
38176+ .qc_defer = ata_std_qc_defer,
38177 .qc_prep = ata_noop_qc_prep,
38178 .qc_issue = sas_ata_qc_issue,
38179 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38180diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38181index 69b5993..1ac9dce 100644
38182--- a/drivers/scsi/lpfc/lpfc.h
38183+++ b/drivers/scsi/lpfc/lpfc.h
38184@@ -424,7 +424,7 @@ struct lpfc_vport {
38185 struct dentry *debug_nodelist;
38186 struct dentry *vport_debugfs_root;
38187 struct lpfc_debugfs_trc *disc_trc;
38188- atomic_t disc_trc_cnt;
38189+ atomic_unchecked_t disc_trc_cnt;
38190 #endif
38191 uint8_t stat_data_enabled;
38192 uint8_t stat_data_blocked;
38193@@ -840,8 +840,8 @@ struct lpfc_hba {
38194 struct timer_list fabric_block_timer;
38195 unsigned long bit_flags;
38196 #define FABRIC_COMANDS_BLOCKED 0
38197- atomic_t num_rsrc_err;
38198- atomic_t num_cmd_success;
38199+ atomic_unchecked_t num_rsrc_err;
38200+ atomic_unchecked_t num_cmd_success;
38201 unsigned long last_rsrc_error_time;
38202 unsigned long last_ramp_down_time;
38203 unsigned long last_ramp_up_time;
38204@@ -877,7 +877,7 @@ struct lpfc_hba {
38205
38206 struct dentry *debug_slow_ring_trc;
38207 struct lpfc_debugfs_trc *slow_ring_trc;
38208- atomic_t slow_ring_trc_cnt;
38209+ atomic_unchecked_t slow_ring_trc_cnt;
38210 /* iDiag debugfs sub-directory */
38211 struct dentry *idiag_root;
38212 struct dentry *idiag_pci_cfg;
38213diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38214index f63f5ff..de29189 100644
38215--- a/drivers/scsi/lpfc/lpfc_debugfs.c
38216+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38217@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38218
38219 #include <linux/debugfs.h>
38220
38221-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38222+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38223 static unsigned long lpfc_debugfs_start_time = 0L;
38224
38225 /* iDiag */
38226@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38227 lpfc_debugfs_enable = 0;
38228
38229 len = 0;
38230- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38231+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38232 (lpfc_debugfs_max_disc_trc - 1);
38233 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38234 dtp = vport->disc_trc + i;
38235@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38236 lpfc_debugfs_enable = 0;
38237
38238 len = 0;
38239- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38240+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38241 (lpfc_debugfs_max_slow_ring_trc - 1);
38242 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38243 dtp = phba->slow_ring_trc + i;
38244@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38245 !vport || !vport->disc_trc)
38246 return;
38247
38248- index = atomic_inc_return(&vport->disc_trc_cnt) &
38249+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38250 (lpfc_debugfs_max_disc_trc - 1);
38251 dtp = vport->disc_trc + index;
38252 dtp->fmt = fmt;
38253 dtp->data1 = data1;
38254 dtp->data2 = data2;
38255 dtp->data3 = data3;
38256- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38257+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38258 dtp->jif = jiffies;
38259 #endif
38260 return;
38261@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38262 !phba || !phba->slow_ring_trc)
38263 return;
38264
38265- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38266+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38267 (lpfc_debugfs_max_slow_ring_trc - 1);
38268 dtp = phba->slow_ring_trc + index;
38269 dtp->fmt = fmt;
38270 dtp->data1 = data1;
38271 dtp->data2 = data2;
38272 dtp->data3 = data3;
38273- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38274+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38275 dtp->jif = jiffies;
38276 #endif
38277 return;
38278@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38279 "slow_ring buffer\n");
38280 goto debug_failed;
38281 }
38282- atomic_set(&phba->slow_ring_trc_cnt, 0);
38283+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38284 memset(phba->slow_ring_trc, 0,
38285 (sizeof(struct lpfc_debugfs_trc) *
38286 lpfc_debugfs_max_slow_ring_trc));
38287@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38288 "buffer\n");
38289 goto debug_failed;
38290 }
38291- atomic_set(&vport->disc_trc_cnt, 0);
38292+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38293
38294 snprintf(name, sizeof(name), "discovery_trace");
38295 vport->debug_disc_trc =
38296diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38297index 7dc4218..3436f08 100644
38298--- a/drivers/scsi/lpfc/lpfc_init.c
38299+++ b/drivers/scsi/lpfc/lpfc_init.c
38300@@ -10589,8 +10589,10 @@ lpfc_init(void)
38301 "misc_register returned with status %d", error);
38302
38303 if (lpfc_enable_npiv) {
38304- lpfc_transport_functions.vport_create = lpfc_vport_create;
38305- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38306+ pax_open_kernel();
38307+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38308+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38309+ pax_close_kernel();
38310 }
38311 lpfc_transport_template =
38312 fc_attach_transport(&lpfc_transport_functions);
38313diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38314index 7f45ac9..cf62eda 100644
38315--- a/drivers/scsi/lpfc/lpfc_scsi.c
38316+++ b/drivers/scsi/lpfc/lpfc_scsi.c
38317@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38318 uint32_t evt_posted;
38319
38320 spin_lock_irqsave(&phba->hbalock, flags);
38321- atomic_inc(&phba->num_rsrc_err);
38322+ atomic_inc_unchecked(&phba->num_rsrc_err);
38323 phba->last_rsrc_error_time = jiffies;
38324
38325 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38326@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38327 unsigned long flags;
38328 struct lpfc_hba *phba = vport->phba;
38329 uint32_t evt_posted;
38330- atomic_inc(&phba->num_cmd_success);
38331+ atomic_inc_unchecked(&phba->num_cmd_success);
38332
38333 if (vport->cfg_lun_queue_depth <= queue_depth)
38334 return;
38335@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38336 unsigned long num_rsrc_err, num_cmd_success;
38337 int i;
38338
38339- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38340- num_cmd_success = atomic_read(&phba->num_cmd_success);
38341+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38342+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38343
38344 /*
38345 * The error and success command counters are global per
38346@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38347 }
38348 }
38349 lpfc_destroy_vport_work_array(phba, vports);
38350- atomic_set(&phba->num_rsrc_err, 0);
38351- atomic_set(&phba->num_cmd_success, 0);
38352+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38353+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38354 }
38355
38356 /**
38357@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38358 }
38359 }
38360 lpfc_destroy_vport_work_array(phba, vports);
38361- atomic_set(&phba->num_rsrc_err, 0);
38362- atomic_set(&phba->num_cmd_success, 0);
38363+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38364+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38365 }
38366
38367 /**
38368diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38369index af763ea..41904f7 100644
38370--- a/drivers/scsi/pmcraid.c
38371+++ b/drivers/scsi/pmcraid.c
38372@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38373 res->scsi_dev = scsi_dev;
38374 scsi_dev->hostdata = res;
38375 res->change_detected = 0;
38376- atomic_set(&res->read_failures, 0);
38377- atomic_set(&res->write_failures, 0);
38378+ atomic_set_unchecked(&res->read_failures, 0);
38379+ atomic_set_unchecked(&res->write_failures, 0);
38380 rc = 0;
38381 }
38382 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38383@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38384
38385 /* If this was a SCSI read/write command keep count of errors */
38386 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38387- atomic_inc(&res->read_failures);
38388+ atomic_inc_unchecked(&res->read_failures);
38389 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38390- atomic_inc(&res->write_failures);
38391+ atomic_inc_unchecked(&res->write_failures);
38392
38393 if (!RES_IS_GSCSI(res->cfg_entry) &&
38394 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38395@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38396 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38397 * hrrq_id assigned here in queuecommand
38398 */
38399- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38400+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38401 pinstance->num_hrrq;
38402 cmd->cmd_done = pmcraid_io_done;
38403
38404@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38405 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38406 * hrrq_id assigned here in queuecommand
38407 */
38408- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38409+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38410 pinstance->num_hrrq;
38411
38412 if (request_size) {
38413@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38414
38415 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38416 /* add resources only after host is added into system */
38417- if (!atomic_read(&pinstance->expose_resources))
38418+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38419 return;
38420
38421 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38422@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38423 init_waitqueue_head(&pinstance->reset_wait_q);
38424
38425 atomic_set(&pinstance->outstanding_cmds, 0);
38426- atomic_set(&pinstance->last_message_id, 0);
38427- atomic_set(&pinstance->expose_resources, 0);
38428+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38429+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38430
38431 INIT_LIST_HEAD(&pinstance->free_res_q);
38432 INIT_LIST_HEAD(&pinstance->used_res_q);
38433@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38434 /* Schedule worker thread to handle CCN and take care of adding and
38435 * removing devices to OS
38436 */
38437- atomic_set(&pinstance->expose_resources, 1);
38438+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38439 schedule_work(&pinstance->worker_q);
38440 return rc;
38441
38442diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38443index e1d150f..6c6df44 100644
38444--- a/drivers/scsi/pmcraid.h
38445+++ b/drivers/scsi/pmcraid.h
38446@@ -748,7 +748,7 @@ struct pmcraid_instance {
38447 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38448
38449 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38450- atomic_t last_message_id;
38451+ atomic_unchecked_t last_message_id;
38452
38453 /* configuration table */
38454 struct pmcraid_config_table *cfg_table;
38455@@ -777,7 +777,7 @@ struct pmcraid_instance {
38456 atomic_t outstanding_cmds;
38457
38458 /* should add/delete resources to mid-layer now ?*/
38459- atomic_t expose_resources;
38460+ atomic_unchecked_t expose_resources;
38461
38462
38463
38464@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38465 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38466 };
38467 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38468- atomic_t read_failures; /* count of failed READ commands */
38469- atomic_t write_failures; /* count of failed WRITE commands */
38470+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38471+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38472
38473 /* To indicate add/delete/modify during CCN */
38474 u8 change_detected;
38475diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38476index 83d7984..a27d947 100644
38477--- a/drivers/scsi/qla2xxx/qla_attr.c
38478+++ b/drivers/scsi/qla2xxx/qla_attr.c
38479@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38480 return 0;
38481 }
38482
38483-struct fc_function_template qla2xxx_transport_functions = {
38484+fc_function_template_no_const qla2xxx_transport_functions = {
38485
38486 .show_host_node_name = 1,
38487 .show_host_port_name = 1,
38488@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38489 .bsg_timeout = qla24xx_bsg_timeout,
38490 };
38491
38492-struct fc_function_template qla2xxx_transport_vport_functions = {
38493+fc_function_template_no_const qla2xxx_transport_vport_functions = {
38494
38495 .show_host_node_name = 1,
38496 .show_host_port_name = 1,
38497diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38498index 6acb397..d86e3e0 100644
38499--- a/drivers/scsi/qla2xxx/qla_gbl.h
38500+++ b/drivers/scsi/qla2xxx/qla_gbl.h
38501@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38502 struct device_attribute;
38503 extern struct device_attribute *qla2x00_host_attrs[];
38504 struct fc_function_template;
38505-extern struct fc_function_template qla2xxx_transport_functions;
38506-extern struct fc_function_template qla2xxx_transport_vport_functions;
38507+extern fc_function_template_no_const qla2xxx_transport_functions;
38508+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38509 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38510 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38511 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38512diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38513index f4b1fc8..a1ce4dd 100644
38514--- a/drivers/scsi/qla2xxx/qla_os.c
38515+++ b/drivers/scsi/qla2xxx/qla_os.c
38516@@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38517 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38518 /* Ok, a 64bit DMA mask is applicable. */
38519 ha->flags.enable_64bit_addressing = 1;
38520- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38521- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38522+ pax_open_kernel();
38523+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38524+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38525+ pax_close_kernel();
38526 return;
38527 }
38528 }
38529diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38530index 329d553..f20d31d 100644
38531--- a/drivers/scsi/qla4xxx/ql4_def.h
38532+++ b/drivers/scsi/qla4xxx/ql4_def.h
38533@@ -273,7 +273,7 @@ struct ddb_entry {
38534 * (4000 only) */
38535 atomic_t relogin_timer; /* Max Time to wait for
38536 * relogin to complete */
38537- atomic_t relogin_retry_count; /* Num of times relogin has been
38538+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38539 * retried */
38540 uint32_t default_time2wait; /* Default Min time between
38541 * relogins (+aens) */
38542diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38543index fbc546e..c7d1b48 100644
38544--- a/drivers/scsi/qla4xxx/ql4_os.c
38545+++ b/drivers/scsi/qla4xxx/ql4_os.c
38546@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38547 */
38548 if (!iscsi_is_session_online(cls_sess)) {
38549 /* Reset retry relogin timer */
38550- atomic_inc(&ddb_entry->relogin_retry_count);
38551+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38552 DEBUG2(ql4_printk(KERN_INFO, ha,
38553 "%s: index[%d] relogin timed out-retrying"
38554 " relogin (%d), retry (%d)\n", __func__,
38555 ddb_entry->fw_ddb_index,
38556- atomic_read(&ddb_entry->relogin_retry_count),
38557+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38558 ddb_entry->default_time2wait + 4));
38559 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38560 atomic_set(&ddb_entry->retry_relogin_timer,
38561@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38562
38563 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38564 atomic_set(&ddb_entry->relogin_timer, 0);
38565- atomic_set(&ddb_entry->relogin_retry_count, 0);
38566+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38567 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38568 ddb_entry->default_relogin_timeout =
38569 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38570diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38571index 2c0d0ec..4e8681a 100644
38572--- a/drivers/scsi/scsi.c
38573+++ b/drivers/scsi/scsi.c
38574@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38575 unsigned long timeout;
38576 int rtn = 0;
38577
38578- atomic_inc(&cmd->device->iorequest_cnt);
38579+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38580
38581 /* check if the device is still usable */
38582 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38583diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38584index 9032e91..7a805d0 100644
38585--- a/drivers/scsi/scsi_lib.c
38586+++ b/drivers/scsi/scsi_lib.c
38587@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38588 shost = sdev->host;
38589 scsi_init_cmd_errh(cmd);
38590 cmd->result = DID_NO_CONNECT << 16;
38591- atomic_inc(&cmd->device->iorequest_cnt);
38592+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38593
38594 /*
38595 * SCSI request completion path will do scsi_device_unbusy(),
38596@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38597
38598 INIT_LIST_HEAD(&cmd->eh_entry);
38599
38600- atomic_inc(&cmd->device->iodone_cnt);
38601+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
38602 if (cmd->result)
38603- atomic_inc(&cmd->device->ioerr_cnt);
38604+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38605
38606 disposition = scsi_decide_disposition(cmd);
38607 if (disposition != SUCCESS &&
38608diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38609index 931a7d9..0c2a754 100644
38610--- a/drivers/scsi/scsi_sysfs.c
38611+++ b/drivers/scsi/scsi_sysfs.c
38612@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38613 char *buf) \
38614 { \
38615 struct scsi_device *sdev = to_scsi_device(dev); \
38616- unsigned long long count = atomic_read(&sdev->field); \
38617+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
38618 return snprintf(buf, 20, "0x%llx\n", count); \
38619 } \
38620 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38621diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38622index 84a1fdf..693b0d6 100644
38623--- a/drivers/scsi/scsi_tgt_lib.c
38624+++ b/drivers/scsi/scsi_tgt_lib.c
38625@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38626 int err;
38627
38628 dprintk("%lx %u\n", uaddr, len);
38629- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38630+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38631 if (err) {
38632 /*
38633 * TODO: need to fixup sg_tablesize, max_segment_size,
38634diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38635index e894ca7..de9d7660 100644
38636--- a/drivers/scsi/scsi_transport_fc.c
38637+++ b/drivers/scsi/scsi_transport_fc.c
38638@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38639 * Netlink Infrastructure
38640 */
38641
38642-static atomic_t fc_event_seq;
38643+static atomic_unchecked_t fc_event_seq;
38644
38645 /**
38646 * fc_get_event_number - Obtain the next sequential FC event number
38647@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38648 u32
38649 fc_get_event_number(void)
38650 {
38651- return atomic_add_return(1, &fc_event_seq);
38652+ return atomic_add_return_unchecked(1, &fc_event_seq);
38653 }
38654 EXPORT_SYMBOL(fc_get_event_number);
38655
38656@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38657 {
38658 int error;
38659
38660- atomic_set(&fc_event_seq, 0);
38661+ atomic_set_unchecked(&fc_event_seq, 0);
38662
38663 error = transport_class_register(&fc_host_class);
38664 if (error)
38665@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38666 char *cp;
38667
38668 *val = simple_strtoul(buf, &cp, 0);
38669- if ((*cp && (*cp != '\n')) || (*val < 0))
38670+ if (*cp && (*cp != '\n'))
38671 return -EINVAL;
38672 /*
38673 * Check for overflow; dev_loss_tmo is u32
38674diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38675index 31969f2..2b348f0 100644
38676--- a/drivers/scsi/scsi_transport_iscsi.c
38677+++ b/drivers/scsi/scsi_transport_iscsi.c
38678@@ -79,7 +79,7 @@ struct iscsi_internal {
38679 struct transport_container session_cont;
38680 };
38681
38682-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38683+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38684 static struct workqueue_struct *iscsi_eh_timer_workq;
38685
38686 static DEFINE_IDA(iscsi_sess_ida);
38687@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38688 int err;
38689
38690 ihost = shost->shost_data;
38691- session->sid = atomic_add_return(1, &iscsi_session_nr);
38692+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38693
38694 if (target_id == ISCSI_MAX_TARGET) {
38695 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38696@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38697 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38698 ISCSI_TRANSPORT_VERSION);
38699
38700- atomic_set(&iscsi_session_nr, 0);
38701+ atomic_set_unchecked(&iscsi_session_nr, 0);
38702
38703 err = class_register(&iscsi_transport_class);
38704 if (err)
38705diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38706index 21a045e..ec89e03 100644
38707--- a/drivers/scsi/scsi_transport_srp.c
38708+++ b/drivers/scsi/scsi_transport_srp.c
38709@@ -33,7 +33,7 @@
38710 #include "scsi_transport_srp_internal.h"
38711
38712 struct srp_host_attrs {
38713- atomic_t next_port_id;
38714+ atomic_unchecked_t next_port_id;
38715 };
38716 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38717
38718@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38719 struct Scsi_Host *shost = dev_to_shost(dev);
38720 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38721
38722- atomic_set(&srp_host->next_port_id, 0);
38723+ atomic_set_unchecked(&srp_host->next_port_id, 0);
38724 return 0;
38725 }
38726
38727@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38728 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38729 rport->roles = ids->roles;
38730
38731- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38732+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38733 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38734
38735 transport_setup_device(&rport->dev);
38736diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38737index a45e12a..d9120cb 100644
38738--- a/drivers/scsi/sd.c
38739+++ b/drivers/scsi/sd.c
38740@@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38741 sdkp->disk = gd;
38742 sdkp->index = index;
38743 atomic_set(&sdkp->openers, 0);
38744- atomic_set(&sdkp->device->ioerr_cnt, 0);
38745+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38746
38747 if (!sdp->request_queue->rq_timeout) {
38748 if (sdp->type != TYPE_MOD)
38749diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38750index be2c9a6..275525c 100644
38751--- a/drivers/scsi/sg.c
38752+++ b/drivers/scsi/sg.c
38753@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38754 sdp->disk->disk_name,
38755 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38756 NULL,
38757- (char *)arg);
38758+ (char __user *)arg);
38759 case BLKTRACESTART:
38760 return blk_trace_startstop(sdp->device->request_queue, 1);
38761 case BLKTRACESTOP:
38762diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38763index 84c2861..ece0a31 100644
38764--- a/drivers/spi/spi.c
38765+++ b/drivers/spi/spi.c
38766@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38767 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38768
38769 /* portable code must never pass more than 32 bytes */
38770-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38771+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38772
38773 static u8 *buf;
38774
38775diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38776index 34afc16..ffe44dd 100644
38777--- a/drivers/staging/octeon/ethernet-rx.c
38778+++ b/drivers/staging/octeon/ethernet-rx.c
38779@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38780 /* Increment RX stats for virtual ports */
38781 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38782 #ifdef CONFIG_64BIT
38783- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38784- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38785+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38786+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38787 #else
38788- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38789- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38790+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38791+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38792 #endif
38793 }
38794 netif_receive_skb(skb);
38795@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38796 dev->name);
38797 */
38798 #ifdef CONFIG_64BIT
38799- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38800+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38801 #else
38802- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38803+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38804 #endif
38805 dev_kfree_skb_irq(skb);
38806 }
38807diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38808index 683bedc..86dba9a 100644
38809--- a/drivers/staging/octeon/ethernet.c
38810+++ b/drivers/staging/octeon/ethernet.c
38811@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38812 * since the RX tasklet also increments it.
38813 */
38814 #ifdef CONFIG_64BIT
38815- atomic64_add(rx_status.dropped_packets,
38816- (atomic64_t *)&priv->stats.rx_dropped);
38817+ atomic64_add_unchecked(rx_status.dropped_packets,
38818+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38819 #else
38820- atomic_add(rx_status.dropped_packets,
38821- (atomic_t *)&priv->stats.rx_dropped);
38822+ atomic_add_unchecked(rx_status.dropped_packets,
38823+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
38824 #endif
38825 }
38826
38827diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
38828index a2b7e03..aaf3630 100644
38829--- a/drivers/staging/ramster/tmem.c
38830+++ b/drivers/staging/ramster/tmem.c
38831@@ -50,25 +50,25 @@
38832 * A tmem host implementation must use this function to register callbacks
38833 * for memory allocation.
38834 */
38835-static struct tmem_hostops tmem_hostops;
38836+static struct tmem_hostops *tmem_hostops;
38837
38838 static void tmem_objnode_tree_init(void);
38839
38840 void tmem_register_hostops(struct tmem_hostops *m)
38841 {
38842 tmem_objnode_tree_init();
38843- tmem_hostops = *m;
38844+ tmem_hostops = m;
38845 }
38846
38847 /*
38848 * A tmem host implementation must use this function to register
38849 * callbacks for a page-accessible memory (PAM) implementation.
38850 */
38851-static struct tmem_pamops tmem_pamops;
38852+static struct tmem_pamops *tmem_pamops;
38853
38854 void tmem_register_pamops(struct tmem_pamops *m)
38855 {
38856- tmem_pamops = *m;
38857+ tmem_pamops = m;
38858 }
38859
38860 /*
38861@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
38862 obj->pampd_count = 0;
38863 #ifdef CONFIG_RAMSTER
38864 if (tmem_pamops.new_obj != NULL)
38865- (*tmem_pamops.new_obj)(obj);
38866+ (tmem_pamops->new_obj)(obj);
38867 #endif
38868 SET_SENTINEL(obj, OBJ);
38869
38870@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
38871 rbnode = rb_next(rbnode);
38872 tmem_pampd_destroy_all_in_obj(obj, true);
38873 tmem_obj_free(obj, hb);
38874- (*tmem_hostops.obj_free)(obj, pool);
38875+ (tmem_hostops->obj_free)(obj, pool);
38876 }
38877 spin_unlock(&hb->lock);
38878 }
38879@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
38880 ASSERT_SENTINEL(obj, OBJ);
38881 BUG_ON(obj->pool == NULL);
38882 ASSERT_SENTINEL(obj->pool, POOL);
38883- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
38884+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
38885 if (unlikely(objnode == NULL))
38886 goto out;
38887 objnode->obj = obj;
38888@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
38889 ASSERT_SENTINEL(pool, POOL);
38890 objnode->obj->objnode_count--;
38891 objnode->obj = NULL;
38892- (*tmem_hostops.objnode_free)(objnode, pool);
38893+ (tmem_hostops->objnode_free)(objnode, pool);
38894 }
38895
38896 /*
38897@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
38898 void *old_pampd = *(void **)slot;
38899 *(void **)slot = new_pampd;
38900 if (!no_free)
38901- (*tmem_pamops.free)(old_pampd, obj->pool,
38902+ (tmem_pamops->free)(old_pampd, obj->pool,
38903 NULL, 0, false);
38904 ret = new_pampd;
38905 }
38906@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
38907 if (objnode->slots[i]) {
38908 if (ht == 1) {
38909 obj->pampd_count--;
38910- (*tmem_pamops.free)(objnode->slots[i],
38911+ (tmem_pamops->free)(objnode->slots[i],
38912 obj->pool, NULL, 0, true);
38913 objnode->slots[i] = NULL;
38914 continue;
38915@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38916 return;
38917 if (obj->objnode_tree_height == 0) {
38918 obj->pampd_count--;
38919- (*tmem_pamops.free)(obj->objnode_tree_root,
38920+ (tmem_pamops->free)(obj->objnode_tree_root,
38921 obj->pool, NULL, 0, true);
38922 } else {
38923 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
38924@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
38925 obj->objnode_tree_root = NULL;
38926 #ifdef CONFIG_RAMSTER
38927 if (tmem_pamops.free_obj != NULL)
38928- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
38929+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
38930 #endif
38931 }
38932
38933@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38934 /* if found, is a dup put, flush the old one */
38935 pampd_del = tmem_pampd_delete_from_obj(obj, index);
38936 BUG_ON(pampd_del != pampd);
38937- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
38938+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
38939 if (obj->pampd_count == 0) {
38940 objnew = obj;
38941 objfound = NULL;
38942@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38943 pampd = NULL;
38944 }
38945 } else {
38946- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
38947+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
38948 if (unlikely(obj == NULL)) {
38949 ret = -ENOMEM;
38950 goto out;
38951@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
38952 if (unlikely(ret == -ENOMEM))
38953 /* may have partially built objnode tree ("stump") */
38954 goto delete_and_free;
38955- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
38956+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
38957 goto out;
38958
38959 delete_and_free:
38960 (void)tmem_pampd_delete_from_obj(obj, index);
38961 if (pampd)
38962- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
38963+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
38964 if (objnew) {
38965 tmem_obj_free(objnew, hb);
38966- (*tmem_hostops.obj_free)(objnew, pool);
38967+ (tmem_hostops->obj_free)(objnew, pool);
38968 }
38969 out:
38970 spin_unlock(&hb->lock);
38971@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
38972 if (pampd != NULL) {
38973 BUG_ON(obj == NULL);
38974 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
38975- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
38976+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
38977 } else if (delete) {
38978 BUG_ON(obj == NULL);
38979 (void)tmem_pampd_delete_from_obj(obj, index);
38980@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38981 int ret = 0;
38982
38983 if (!is_ephemeral(pool))
38984- new_pampd = (*tmem_pamops.repatriate_preload)(
38985+ new_pampd = (tmem_pamops->repatriate_preload)(
38986 old_pampd, pool, oidp, index, &intransit);
38987 if (intransit)
38988 ret = -EAGAIN;
38989@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
38990 /* must release the hb->lock else repatriate can't sleep */
38991 spin_unlock(&hb->lock);
38992 if (!intransit)
38993- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
38994+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
38995 oidp, index, free, data);
38996 if (ret == -EAGAIN) {
38997 /* rare I think, but should cond_resched()??? */
38998@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
38999 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39000 /* if we bug here, pamops wasn't properly set up for ramster */
39001 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39002- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39003+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39004 out:
39005 spin_unlock(&hb->lock);
39006 return ret;
39007@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39008 if (free) {
39009 if (obj->pampd_count == 0) {
39010 tmem_obj_free(obj, hb);
39011- (*tmem_hostops.obj_free)(obj, pool);
39012+ (tmem_hostops->obj_free)(obj, pool);
39013 obj = NULL;
39014 }
39015 }
39016 if (free)
39017- ret = (*tmem_pamops.get_data_and_free)(
39018+ ret = (tmem_pamops->get_data_and_free)(
39019 data, sizep, raw, pampd, pool, oidp, index);
39020 else
39021- ret = (*tmem_pamops.get_data)(
39022+ ret = (tmem_pamops->get_data)(
39023 data, sizep, raw, pampd, pool, oidp, index);
39024 if (ret < 0)
39025 goto out;
39026@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39027 pampd = tmem_pampd_delete_from_obj(obj, index);
39028 if (pampd == NULL)
39029 goto out;
39030- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39031+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
39032 if (obj->pampd_count == 0) {
39033 tmem_obj_free(obj, hb);
39034- (*tmem_hostops.obj_free)(obj, pool);
39035+ (tmem_hostops->obj_free)(obj, pool);
39036 }
39037 ret = 0;
39038
39039@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39040 goto out;
39041 tmem_pampd_destroy_all_in_obj(obj, false);
39042 tmem_obj_free(obj, hb);
39043- (*tmem_hostops.obj_free)(obj, pool);
39044+ (tmem_hostops->obj_free)(obj, pool);
39045 ret = 0;
39046
39047 out:
39048diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39049index dc23395..cf7e9b1 100644
39050--- a/drivers/staging/rtl8712/rtl871x_io.h
39051+++ b/drivers/staging/rtl8712/rtl871x_io.h
39052@@ -108,7 +108,7 @@ struct _io_ops {
39053 u8 *pmem);
39054 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39055 u8 *pmem);
39056-};
39057+} __no_const;
39058
39059 struct io_req {
39060 struct list_head list;
39061diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39062index 180c963..1f18377 100644
39063--- a/drivers/staging/sbe-2t3e3/netdev.c
39064+++ b/drivers/staging/sbe-2t3e3/netdev.c
39065@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39066 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39067
39068 if (rlen)
39069- if (copy_to_user(data, &resp, rlen))
39070+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39071 return -EFAULT;
39072
39073 return 0;
39074diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39075index c66b8b3..a4a035b 100644
39076--- a/drivers/staging/usbip/vhci.h
39077+++ b/drivers/staging/usbip/vhci.h
39078@@ -83,7 +83,7 @@ struct vhci_hcd {
39079 unsigned resuming:1;
39080 unsigned long re_timeout;
39081
39082- atomic_t seqnum;
39083+ atomic_unchecked_t seqnum;
39084
39085 /*
39086 * NOTE:
39087diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39088index 620d1be..1cd6711 100644
39089--- a/drivers/staging/usbip/vhci_hcd.c
39090+++ b/drivers/staging/usbip/vhci_hcd.c
39091@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39092 return;
39093 }
39094
39095- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39096+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39097 if (priv->seqnum == 0xffff)
39098 dev_info(&urb->dev->dev, "seqnum max\n");
39099
39100@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39101 return -ENOMEM;
39102 }
39103
39104- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39105+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39106 if (unlink->seqnum == 0xffff)
39107 pr_info("seqnum max\n");
39108
39109@@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39110 vdev->rhport = rhport;
39111 }
39112
39113- atomic_set(&vhci->seqnum, 0);
39114+ atomic_set_unchecked(&vhci->seqnum, 0);
39115 spin_lock_init(&vhci->lock);
39116
39117 hcd->power_budget = 0; /* no limit */
39118diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39119index f0eaf04..5a82e06 100644
39120--- a/drivers/staging/usbip/vhci_rx.c
39121+++ b/drivers/staging/usbip/vhci_rx.c
39122@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39123 if (!urb) {
39124 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39125 pr_info("max seqnum %d\n",
39126- atomic_read(&the_controller->seqnum));
39127+ atomic_read_unchecked(&the_controller->seqnum));
39128 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39129 return;
39130 }
39131diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39132index 67b1b88..6392fe9 100644
39133--- a/drivers/staging/vt6655/hostap.c
39134+++ b/drivers/staging/vt6655/hostap.c
39135@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39136 *
39137 */
39138
39139+static net_device_ops_no_const apdev_netdev_ops;
39140+
39141 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39142 {
39143 PSDevice apdev_priv;
39144 struct net_device *dev = pDevice->dev;
39145 int ret;
39146- const struct net_device_ops apdev_netdev_ops = {
39147- .ndo_start_xmit = pDevice->tx_80211,
39148- };
39149
39150 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39151
39152@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39153 *apdev_priv = *pDevice;
39154 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39155
39156+ /* only half broken now */
39157+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39158 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39159
39160 pDevice->apdev->type = ARPHRD_IEEE80211;
39161diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39162index 0a73d40..6fda560 100644
39163--- a/drivers/staging/vt6656/hostap.c
39164+++ b/drivers/staging/vt6656/hostap.c
39165@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39166 *
39167 */
39168
39169+static net_device_ops_no_const apdev_netdev_ops;
39170+
39171 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39172 {
39173 PSDevice apdev_priv;
39174 struct net_device *dev = pDevice->dev;
39175 int ret;
39176- const struct net_device_ops apdev_netdev_ops = {
39177- .ndo_start_xmit = pDevice->tx_80211,
39178- };
39179
39180 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39181
39182@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39183 *apdev_priv = *pDevice;
39184 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39185
39186+ /* only half broken now */
39187+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39188 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39189
39190 pDevice->apdev->type = ARPHRD_IEEE80211;
39191diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39192index 56c8e60..1920c63 100644
39193--- a/drivers/staging/zcache/tmem.c
39194+++ b/drivers/staging/zcache/tmem.c
39195@@ -39,7 +39,7 @@
39196 * A tmem host implementation must use this function to register callbacks
39197 * for memory allocation.
39198 */
39199-static struct tmem_hostops tmem_hostops;
39200+static tmem_hostops_no_const tmem_hostops;
39201
39202 static void tmem_objnode_tree_init(void);
39203
39204@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39205 * A tmem host implementation must use this function to register
39206 * callbacks for a page-accessible memory (PAM) implementation
39207 */
39208-static struct tmem_pamops tmem_pamops;
39209+static tmem_pamops_no_const tmem_pamops;
39210
39211 void tmem_register_pamops(struct tmem_pamops *m)
39212 {
39213diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39214index 0d4aa82..f7832d4 100644
39215--- a/drivers/staging/zcache/tmem.h
39216+++ b/drivers/staging/zcache/tmem.h
39217@@ -180,6 +180,7 @@ struct tmem_pamops {
39218 void (*new_obj)(struct tmem_obj *);
39219 int (*replace_in_obj)(void *, struct tmem_obj *);
39220 };
39221+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39222 extern void tmem_register_pamops(struct tmem_pamops *m);
39223
39224 /* memory allocation methods provided by the host implementation */
39225@@ -189,6 +190,7 @@ struct tmem_hostops {
39226 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39227 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39228 };
39229+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39230 extern void tmem_register_hostops(struct tmem_hostops *m);
39231
39232 /* core tmem accessor functions */
39233diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39234index 13fe16c..cbdc39a 100644
39235--- a/drivers/target/target_core_transport.c
39236+++ b/drivers/target/target_core_transport.c
39237@@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39238 spin_lock_init(&dev->se_port_lock);
39239 spin_lock_init(&dev->se_tmr_lock);
39240 spin_lock_init(&dev->qf_cmd_lock);
39241- atomic_set(&dev->dev_ordered_id, 0);
39242+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
39243
39244 se_dev_set_default_attribs(dev, dev_limits);
39245
39246@@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39247 * Used to determine when ORDERED commands should go from
39248 * Dormant to Active status.
39249 */
39250- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39251+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39252 smp_mb__after_atomic_inc();
39253 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39254 cmd->se_ordered_id, cmd->sam_task_attr,
39255diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39256index 0a6a0bc..5501b06 100644
39257--- a/drivers/tty/cyclades.c
39258+++ b/drivers/tty/cyclades.c
39259@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39260 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39261 info->port.count);
39262 #endif
39263- info->port.count++;
39264+ atomic_inc(&info->port.count);
39265 #ifdef CY_DEBUG_COUNT
39266 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39267- current->pid, info->port.count);
39268+ current->pid, atomic_read(&info->port.count));
39269 #endif
39270
39271 /*
39272@@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39273 for (j = 0; j < cy_card[i].nports; j++) {
39274 info = &cy_card[i].ports[j];
39275
39276- if (info->port.count) {
39277+ if (atomic_read(&info->port.count)) {
39278 /* XXX is the ldisc num worth this? */
39279 struct tty_struct *tty;
39280 struct tty_ldisc *ld;
39281diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39282index 13ee53b..418d164 100644
39283--- a/drivers/tty/hvc/hvc_console.c
39284+++ b/drivers/tty/hvc/hvc_console.c
39285@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39286
39287 spin_lock_irqsave(&hp->port.lock, flags);
39288 /* Check and then increment for fast path open. */
39289- if (hp->port.count++ > 0) {
39290+ if (atomic_inc_return(&hp->port.count) > 1) {
39291 spin_unlock_irqrestore(&hp->port.lock, flags);
39292 hvc_kick();
39293 return 0;
39294@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39295
39296 spin_lock_irqsave(&hp->port.lock, flags);
39297
39298- if (--hp->port.count == 0) {
39299+ if (atomic_dec_return(&hp->port.count) == 0) {
39300 spin_unlock_irqrestore(&hp->port.lock, flags);
39301 /* We are done with the tty pointer now. */
39302 tty_port_tty_set(&hp->port, NULL);
39303@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39304 */
39305 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39306 } else {
39307- if (hp->port.count < 0)
39308+ if (atomic_read(&hp->port.count) < 0)
39309 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39310- hp->vtermno, hp->port.count);
39311+ hp->vtermno, atomic_read(&hp->port.count));
39312 spin_unlock_irqrestore(&hp->port.lock, flags);
39313 }
39314 }
39315@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39316 * open->hangup case this can be called after the final close so prevent
39317 * that from happening for now.
39318 */
39319- if (hp->port.count <= 0) {
39320+ if (atomic_read(&hp->port.count) <= 0) {
39321 spin_unlock_irqrestore(&hp->port.lock, flags);
39322 return;
39323 }
39324
39325- hp->port.count = 0;
39326+ atomic_set(&hp->port.count, 0);
39327 spin_unlock_irqrestore(&hp->port.lock, flags);
39328 tty_port_tty_set(&hp->port, NULL);
39329
39330@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39331 return -EPIPE;
39332
39333 /* FIXME what's this (unprotected) check for? */
39334- if (hp->port.count <= 0)
39335+ if (atomic_read(&hp->port.count) <= 0)
39336 return -EIO;
39337
39338 spin_lock_irqsave(&hp->lock, flags);
39339diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39340index cab5c7a..4cc66ea 100644
39341--- a/drivers/tty/hvc/hvcs.c
39342+++ b/drivers/tty/hvc/hvcs.c
39343@@ -83,6 +83,7 @@
39344 #include <asm/hvcserver.h>
39345 #include <asm/uaccess.h>
39346 #include <asm/vio.h>
39347+#include <asm/local.h>
39348
39349 /*
39350 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39351@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39352
39353 spin_lock_irqsave(&hvcsd->lock, flags);
39354
39355- if (hvcsd->port.count > 0) {
39356+ if (atomic_read(&hvcsd->port.count) > 0) {
39357 spin_unlock_irqrestore(&hvcsd->lock, flags);
39358 printk(KERN_INFO "HVCS: vterm state unchanged. "
39359 "The hvcs device node is still in use.\n");
39360@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39361 }
39362 }
39363
39364- hvcsd->port.count = 0;
39365+ atomic_set(&hvcsd->port.count, 0);
39366 hvcsd->port.tty = tty;
39367 tty->driver_data = hvcsd;
39368
39369@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39370 unsigned long flags;
39371
39372 spin_lock_irqsave(&hvcsd->lock, flags);
39373- hvcsd->port.count++;
39374+ atomic_inc(&hvcsd->port.count);
39375 hvcsd->todo_mask |= HVCS_SCHED_READ;
39376 spin_unlock_irqrestore(&hvcsd->lock, flags);
39377
39378@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39379 hvcsd = tty->driver_data;
39380
39381 spin_lock_irqsave(&hvcsd->lock, flags);
39382- if (--hvcsd->port.count == 0) {
39383+ if (atomic_dec_and_test(&hvcsd->port.count)) {
39384
39385 vio_disable_interrupts(hvcsd->vdev);
39386
39387@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39388
39389 free_irq(irq, hvcsd);
39390 return;
39391- } else if (hvcsd->port.count < 0) {
39392+ } else if (atomic_read(&hvcsd->port.count) < 0) {
39393 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39394 " is missmanaged.\n",
39395- hvcsd->vdev->unit_address, hvcsd->port.count);
39396+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39397 }
39398
39399 spin_unlock_irqrestore(&hvcsd->lock, flags);
39400@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39401
39402 spin_lock_irqsave(&hvcsd->lock, flags);
39403 /* Preserve this so that we know how many kref refs to put */
39404- temp_open_count = hvcsd->port.count;
39405+ temp_open_count = atomic_read(&hvcsd->port.count);
39406
39407 /*
39408 * Don't kref put inside the spinlock because the destruction
39409@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39410 tty->driver_data = NULL;
39411 hvcsd->port.tty = NULL;
39412
39413- hvcsd->port.count = 0;
39414+ atomic_set(&hvcsd->port.count, 0);
39415
39416 /* This will drop any buffered data on the floor which is OK in a hangup
39417 * scenario. */
39418@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39419 * the middle of a write operation? This is a crummy place to do this
39420 * but we want to keep it all in the spinlock.
39421 */
39422- if (hvcsd->port.count <= 0) {
39423+ if (atomic_read(&hvcsd->port.count) <= 0) {
39424 spin_unlock_irqrestore(&hvcsd->lock, flags);
39425 return -ENODEV;
39426 }
39427@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39428 {
39429 struct hvcs_struct *hvcsd = tty->driver_data;
39430
39431- if (!hvcsd || hvcsd->port.count <= 0)
39432+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39433 return 0;
39434
39435 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39436diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39437index 160f0ad..588b853 100644
39438--- a/drivers/tty/ipwireless/tty.c
39439+++ b/drivers/tty/ipwireless/tty.c
39440@@ -29,6 +29,7 @@
39441 #include <linux/tty_driver.h>
39442 #include <linux/tty_flip.h>
39443 #include <linux/uaccess.h>
39444+#include <asm/local.h>
39445
39446 #include "tty.h"
39447 #include "network.h"
39448@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39449 mutex_unlock(&tty->ipw_tty_mutex);
39450 return -ENODEV;
39451 }
39452- if (tty->port.count == 0)
39453+ if (atomic_read(&tty->port.count) == 0)
39454 tty->tx_bytes_queued = 0;
39455
39456- tty->port.count++;
39457+ atomic_inc(&tty->port.count);
39458
39459 tty->port.tty = linux_tty;
39460 linux_tty->driver_data = tty;
39461@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39462
39463 static void do_ipw_close(struct ipw_tty *tty)
39464 {
39465- tty->port.count--;
39466-
39467- if (tty->port.count == 0) {
39468+ if (atomic_dec_return(&tty->port.count) == 0) {
39469 struct tty_struct *linux_tty = tty->port.tty;
39470
39471 if (linux_tty != NULL) {
39472@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39473 return;
39474
39475 mutex_lock(&tty->ipw_tty_mutex);
39476- if (tty->port.count == 0) {
39477+ if (atomic_read(&tty->port.count) == 0) {
39478 mutex_unlock(&tty->ipw_tty_mutex);
39479 return;
39480 }
39481@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39482 return;
39483 }
39484
39485- if (!tty->port.count) {
39486+ if (!atomic_read(&tty->port.count)) {
39487 mutex_unlock(&tty->ipw_tty_mutex);
39488 return;
39489 }
39490@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39491 return -ENODEV;
39492
39493 mutex_lock(&tty->ipw_tty_mutex);
39494- if (!tty->port.count) {
39495+ if (!atomic_read(&tty->port.count)) {
39496 mutex_unlock(&tty->ipw_tty_mutex);
39497 return -EINVAL;
39498 }
39499@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39500 if (!tty)
39501 return -ENODEV;
39502
39503- if (!tty->port.count)
39504+ if (!atomic_read(&tty->port.count))
39505 return -EINVAL;
39506
39507 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39508@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39509 if (!tty)
39510 return 0;
39511
39512- if (!tty->port.count)
39513+ if (!atomic_read(&tty->port.count))
39514 return 0;
39515
39516 return tty->tx_bytes_queued;
39517@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39518 if (!tty)
39519 return -ENODEV;
39520
39521- if (!tty->port.count)
39522+ if (!atomic_read(&tty->port.count))
39523 return -EINVAL;
39524
39525 return get_control_lines(tty);
39526@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39527 if (!tty)
39528 return -ENODEV;
39529
39530- if (!tty->port.count)
39531+ if (!atomic_read(&tty->port.count))
39532 return -EINVAL;
39533
39534 return set_control_lines(tty, set, clear);
39535@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39536 if (!tty)
39537 return -ENODEV;
39538
39539- if (!tty->port.count)
39540+ if (!atomic_read(&tty->port.count))
39541 return -EINVAL;
39542
39543 /* FIXME: Exactly how is the tty object locked here .. */
39544@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39545 * are gone */
39546 mutex_lock(&ttyj->ipw_tty_mutex);
39547 }
39548- while (ttyj->port.count)
39549+ while (atomic_read(&ttyj->port.count))
39550 do_ipw_close(ttyj);
39551 ipwireless_disassociate_network_ttys(network,
39552 ttyj->channel_idx);
39553diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39554index 56e616b..9d9f10a 100644
39555--- a/drivers/tty/moxa.c
39556+++ b/drivers/tty/moxa.c
39557@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39558 }
39559
39560 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39561- ch->port.count++;
39562+ atomic_inc(&ch->port.count);
39563 tty->driver_data = ch;
39564 tty_port_tty_set(&ch->port, tty);
39565 mutex_lock(&ch->port.mutex);
39566diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39567index 1e8e8ce..a9efc93 100644
39568--- a/drivers/tty/n_gsm.c
39569+++ b/drivers/tty/n_gsm.c
39570@@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39571 kref_init(&dlci->ref);
39572 mutex_init(&dlci->mutex);
39573 dlci->fifo = &dlci->_fifo;
39574- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39575+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39576 kfree(dlci);
39577 return NULL;
39578 }
39579@@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39580 struct gsm_dlci *dlci = tty->driver_data;
39581 struct tty_port *port = &dlci->port;
39582
39583- port->count++;
39584+ atomic_inc(&port->count);
39585 dlci_get(dlci);
39586 dlci_get(dlci->gsm->dlci[0]);
39587 mux_get(dlci->gsm);
39588diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39589index 8c0b7b4..e88f052 100644
39590--- a/drivers/tty/n_tty.c
39591+++ b/drivers/tty/n_tty.c
39592@@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39593 {
39594 *ops = tty_ldisc_N_TTY;
39595 ops->owner = NULL;
39596- ops->refcount = ops->flags = 0;
39597+ atomic_set(&ops->refcount, 0);
39598+ ops->flags = 0;
39599 }
39600 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39601diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39602index 8cf8d0a..4ef9ed0 100644
39603--- a/drivers/tty/pty.c
39604+++ b/drivers/tty/pty.c
39605@@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39606 panic("Couldn't register Unix98 pts driver");
39607
39608 /* Now create the /dev/ptmx special device */
39609+ pax_open_kernel();
39610 tty_default_fops(&ptmx_fops);
39611- ptmx_fops.open = ptmx_open;
39612+ *(void **)&ptmx_fops.open = ptmx_open;
39613+ pax_close_kernel();
39614
39615 cdev_init(&ptmx_cdev, &ptmx_fops);
39616 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39617diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39618index 9700d34..df7520c 100644
39619--- a/drivers/tty/rocket.c
39620+++ b/drivers/tty/rocket.c
39621@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39622 tty->driver_data = info;
39623 tty_port_tty_set(port, tty);
39624
39625- if (port->count++ == 0) {
39626+ if (atomic_inc_return(&port->count) == 1) {
39627 atomic_inc(&rp_num_ports_open);
39628
39629 #ifdef ROCKET_DEBUG_OPEN
39630@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39631 #endif
39632 }
39633 #ifdef ROCKET_DEBUG_OPEN
39634- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39635+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39636 #endif
39637
39638 /*
39639@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39640 spin_unlock_irqrestore(&info->port.lock, flags);
39641 return;
39642 }
39643- if (info->port.count)
39644+ if (atomic_read(&info->port.count))
39645 atomic_dec(&rp_num_ports_open);
39646 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39647 spin_unlock_irqrestore(&info->port.lock, flags);
39648diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39649index 1002054..dd644a8 100644
39650--- a/drivers/tty/serial/kgdboc.c
39651+++ b/drivers/tty/serial/kgdboc.c
39652@@ -24,8 +24,9 @@
39653 #define MAX_CONFIG_LEN 40
39654
39655 static struct kgdb_io kgdboc_io_ops;
39656+static struct kgdb_io kgdboc_io_ops_console;
39657
39658-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39659+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39660 static int configured = -1;
39661
39662 static char config[MAX_CONFIG_LEN];
39663@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39664 kgdboc_unregister_kbd();
39665 if (configured == 1)
39666 kgdb_unregister_io_module(&kgdboc_io_ops);
39667+ else if (configured == 2)
39668+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
39669 }
39670
39671 static int configure_kgdboc(void)
39672@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39673 int err;
39674 char *cptr = config;
39675 struct console *cons;
39676+ int is_console = 0;
39677
39678 err = kgdboc_option_setup(config);
39679 if (err || !strlen(config) || isspace(config[0]))
39680 goto noconfig;
39681
39682 err = -ENODEV;
39683- kgdboc_io_ops.is_console = 0;
39684 kgdb_tty_driver = NULL;
39685
39686 kgdboc_use_kms = 0;
39687@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39688 int idx;
39689 if (cons->device && cons->device(cons, &idx) == p &&
39690 idx == tty_line) {
39691- kgdboc_io_ops.is_console = 1;
39692+ is_console = 1;
39693 break;
39694 }
39695 cons = cons->next;
39696@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39697 kgdb_tty_line = tty_line;
39698
39699 do_register:
39700- err = kgdb_register_io_module(&kgdboc_io_ops);
39701+ if (is_console) {
39702+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
39703+ configured = 2;
39704+ } else {
39705+ err = kgdb_register_io_module(&kgdboc_io_ops);
39706+ configured = 1;
39707+ }
39708 if (err)
39709 goto noconfig;
39710
39711@@ -205,8 +214,6 @@ do_register:
39712 if (err)
39713 goto nmi_con_failed;
39714
39715- configured = 1;
39716-
39717 return 0;
39718
39719 nmi_con_failed:
39720@@ -223,7 +230,7 @@ noconfig:
39721 static int __init init_kgdboc(void)
39722 {
39723 /* Already configured? */
39724- if (configured == 1)
39725+ if (configured >= 1)
39726 return 0;
39727
39728 return configure_kgdboc();
39729@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39730 if (config[len - 1] == '\n')
39731 config[len - 1] = '\0';
39732
39733- if (configured == 1)
39734+ if (configured >= 1)
39735 cleanup_kgdboc();
39736
39737 /* Go and configure with the new params. */
39738@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39739 .post_exception = kgdboc_post_exp_handler,
39740 };
39741
39742+static struct kgdb_io kgdboc_io_ops_console = {
39743+ .name = "kgdboc",
39744+ .read_char = kgdboc_get_char,
39745+ .write_char = kgdboc_put_char,
39746+ .pre_exception = kgdboc_pre_exp_handler,
39747+ .post_exception = kgdboc_post_exp_handler,
39748+ .is_console = 1
39749+};
39750+
39751 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39752 /* This is only available if kgdboc is a built in for early debugging */
39753 static int __init kgdboc_early_init(char *opt)
39754diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39755index 7f04717..0f3794f 100644
39756--- a/drivers/tty/serial/samsung.c
39757+++ b/drivers/tty/serial/samsung.c
39758@@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39759 }
39760 }
39761
39762+static int s3c64xx_serial_startup(struct uart_port *port);
39763 static int s3c24xx_serial_startup(struct uart_port *port)
39764 {
39765 struct s3c24xx_uart_port *ourport = to_ourport(port);
39766 int ret;
39767
39768+ /* Startup sequence is different for s3c64xx and higher SoC's */
39769+ if (s3c24xx_serial_has_interrupt_mask(port))
39770+ return s3c64xx_serial_startup(port);
39771+
39772 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39773 port->mapbase, port->membase);
39774
39775@@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39776 /* setup info for port */
39777 port->dev = &platdev->dev;
39778
39779- /* Startup sequence is different for s3c64xx and higher SoC's */
39780- if (s3c24xx_serial_has_interrupt_mask(port))
39781- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39782-
39783 port->uartclk = 1;
39784
39785 if (cfg->uart_flags & UPF_CONS_FLOW) {
39786diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39787index 0fcfd98..8244fce 100644
39788--- a/drivers/tty/serial/serial_core.c
39789+++ b/drivers/tty/serial/serial_core.c
39790@@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
39791 uart_flush_buffer(tty);
39792 uart_shutdown(tty, state);
39793 spin_lock_irqsave(&port->lock, flags);
39794- port->count = 0;
39795+ atomic_set(&port->count, 0);
39796 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
39797 spin_unlock_irqrestore(&port->lock, flags);
39798 tty_port_tty_set(port, NULL);
39799@@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39800 goto end;
39801 }
39802
39803- port->count++;
39804+ atomic_inc(&port->count);
39805 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
39806 retval = -ENXIO;
39807 goto err_dec_count;
39808@@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39809 /*
39810 * Make sure the device is in D0 state.
39811 */
39812- if (port->count == 1)
39813+ if (atomic_read(&port->count) == 1)
39814 uart_change_pm(state, 0);
39815
39816 /*
39817@@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39818 end:
39819 return retval;
39820 err_dec_count:
39821- port->count--;
39822+ atomic_inc(&port->count);
39823 mutex_unlock(&port->mutex);
39824 goto end;
39825 }
39826diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
39827index 70e3a52..5742052 100644
39828--- a/drivers/tty/synclink.c
39829+++ b/drivers/tty/synclink.c
39830@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39831
39832 if (debug_level >= DEBUG_LEVEL_INFO)
39833 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
39834- __FILE__,__LINE__, info->device_name, info->port.count);
39835+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39836
39837 if (tty_port_close_start(&info->port, tty, filp) == 0)
39838 goto cleanup;
39839@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39840 cleanup:
39841 if (debug_level >= DEBUG_LEVEL_INFO)
39842 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
39843- tty->driver->name, info->port.count);
39844+ tty->driver->name, atomic_read(&info->port.count));
39845
39846 } /* end of mgsl_close() */
39847
39848@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
39849
39850 mgsl_flush_buffer(tty);
39851 shutdown(info);
39852-
39853- info->port.count = 0;
39854+
39855+ atomic_set(&info->port.count, 0);
39856 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39857 info->port.tty = NULL;
39858
39859@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39860
39861 if (debug_level >= DEBUG_LEVEL_INFO)
39862 printk("%s(%d):block_til_ready before block on %s count=%d\n",
39863- __FILE__,__LINE__, tty->driver->name, port->count );
39864+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39865
39866 spin_lock_irqsave(&info->irq_spinlock, flags);
39867 if (!tty_hung_up_p(filp)) {
39868 extra_count = true;
39869- port->count--;
39870+ atomic_dec(&port->count);
39871 }
39872 spin_unlock_irqrestore(&info->irq_spinlock, flags);
39873 port->blocked_open++;
39874@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39875
39876 if (debug_level >= DEBUG_LEVEL_INFO)
39877 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
39878- __FILE__,__LINE__, tty->driver->name, port->count );
39879+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39880
39881 tty_unlock(tty);
39882 schedule();
39883@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39884
39885 /* FIXME: Racy on hangup during close wait */
39886 if (extra_count)
39887- port->count++;
39888+ atomic_inc(&port->count);
39889 port->blocked_open--;
39890
39891 if (debug_level >= DEBUG_LEVEL_INFO)
39892 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
39893- __FILE__,__LINE__, tty->driver->name, port->count );
39894+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39895
39896 if (!retval)
39897 port->flags |= ASYNC_NORMAL_ACTIVE;
39898@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39899
39900 if (debug_level >= DEBUG_LEVEL_INFO)
39901 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
39902- __FILE__,__LINE__,tty->driver->name, info->port.count);
39903+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
39904
39905 /* If port is closing, signal caller to try again */
39906 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39907@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
39908 spin_unlock_irqrestore(&info->netlock, flags);
39909 goto cleanup;
39910 }
39911- info->port.count++;
39912+ atomic_inc(&info->port.count);
39913 spin_unlock_irqrestore(&info->netlock, flags);
39914
39915- if (info->port.count == 1) {
39916+ if (atomic_read(&info->port.count) == 1) {
39917 /* 1st open on this device, init hardware */
39918 retval = startup(info);
39919 if (retval < 0)
39920@@ -3451,8 +3451,8 @@ cleanup:
39921 if (retval) {
39922 if (tty->count == 1)
39923 info->port.tty = NULL; /* tty layer will release tty struct */
39924- if(info->port.count)
39925- info->port.count--;
39926+ if (atomic_read(&info->port.count))
39927+ atomic_dec(&info->port.count);
39928 }
39929
39930 return retval;
39931@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39932 unsigned short new_crctype;
39933
39934 /* return error if TTY interface open */
39935- if (info->port.count)
39936+ if (atomic_read(&info->port.count))
39937 return -EBUSY;
39938
39939 switch (encoding)
39940@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
39941
39942 /* arbitrate between network and tty opens */
39943 spin_lock_irqsave(&info->netlock, flags);
39944- if (info->port.count != 0 || info->netcount != 0) {
39945+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39946 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39947 spin_unlock_irqrestore(&info->netlock, flags);
39948 return -EBUSY;
39949@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39950 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
39951
39952 /* return error if TTY interface open */
39953- if (info->port.count)
39954+ if (atomic_read(&info->port.count))
39955 return -EBUSY;
39956
39957 if (cmd != SIOCWANDEV)
39958diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
39959index b38e954..ce45b38 100644
39960--- a/drivers/tty/synclink_gt.c
39961+++ b/drivers/tty/synclink_gt.c
39962@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
39963 tty->driver_data = info;
39964 info->port.tty = tty;
39965
39966- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
39967+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
39968
39969 /* If port is closing, signal caller to try again */
39970 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
39971@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
39972 mutex_unlock(&info->port.mutex);
39973 goto cleanup;
39974 }
39975- info->port.count++;
39976+ atomic_inc(&info->port.count);
39977 spin_unlock_irqrestore(&info->netlock, flags);
39978
39979- if (info->port.count == 1) {
39980+ if (atomic_read(&info->port.count) == 1) {
39981 /* 1st open on this device, init hardware */
39982 retval = startup(info);
39983 if (retval < 0) {
39984@@ -716,8 +716,8 @@ cleanup:
39985 if (retval) {
39986 if (tty->count == 1)
39987 info->port.tty = NULL; /* tty layer will release tty struct */
39988- if(info->port.count)
39989- info->port.count--;
39990+ if(atomic_read(&info->port.count))
39991+ atomic_dec(&info->port.count);
39992 }
39993
39994 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
39995@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
39996
39997 if (sanity_check(info, tty->name, "close"))
39998 return;
39999- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40000+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40001
40002 if (tty_port_close_start(&info->port, tty, filp) == 0)
40003 goto cleanup;
40004@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40005 tty_port_close_end(&info->port, tty);
40006 info->port.tty = NULL;
40007 cleanup:
40008- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40009+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40010 }
40011
40012 static void hangup(struct tty_struct *tty)
40013@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40014 shutdown(info);
40015
40016 spin_lock_irqsave(&info->port.lock, flags);
40017- info->port.count = 0;
40018+ atomic_set(&info->port.count, 0);
40019 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40020 info->port.tty = NULL;
40021 spin_unlock_irqrestore(&info->port.lock, flags);
40022@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40023 unsigned short new_crctype;
40024
40025 /* return error if TTY interface open */
40026- if (info->port.count)
40027+ if (atomic_read(&info->port.count))
40028 return -EBUSY;
40029
40030 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40031@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40032
40033 /* arbitrate between network and tty opens */
40034 spin_lock_irqsave(&info->netlock, flags);
40035- if (info->port.count != 0 || info->netcount != 0) {
40036+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40037 DBGINFO(("%s hdlc_open busy\n", dev->name));
40038 spin_unlock_irqrestore(&info->netlock, flags);
40039 return -EBUSY;
40040@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40041 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40042
40043 /* return error if TTY interface open */
40044- if (info->port.count)
40045+ if (atomic_read(&info->port.count))
40046 return -EBUSY;
40047
40048 if (cmd != SIOCWANDEV)
40049@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40050 if (port == NULL)
40051 continue;
40052 spin_lock(&port->lock);
40053- if ((port->port.count || port->netcount) &&
40054+ if ((atomic_read(&port->port.count) || port->netcount) &&
40055 port->pending_bh && !port->bh_running &&
40056 !port->bh_requested) {
40057 DBGISR(("%s bh queued\n", port->device_name));
40058@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40059 spin_lock_irqsave(&info->lock, flags);
40060 if (!tty_hung_up_p(filp)) {
40061 extra_count = true;
40062- port->count--;
40063+ atomic_dec(&port->count);
40064 }
40065 spin_unlock_irqrestore(&info->lock, flags);
40066 port->blocked_open++;
40067@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40068 remove_wait_queue(&port->open_wait, &wait);
40069
40070 if (extra_count)
40071- port->count++;
40072+ atomic_inc(&port->count);
40073 port->blocked_open--;
40074
40075 if (!retval)
40076diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40077index f17d9f3..27a041b 100644
40078--- a/drivers/tty/synclinkmp.c
40079+++ b/drivers/tty/synclinkmp.c
40080@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40081
40082 if (debug_level >= DEBUG_LEVEL_INFO)
40083 printk("%s(%d):%s open(), old ref count = %d\n",
40084- __FILE__,__LINE__,tty->driver->name, info->port.count);
40085+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40086
40087 /* If port is closing, signal caller to try again */
40088 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40089@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40090 spin_unlock_irqrestore(&info->netlock, flags);
40091 goto cleanup;
40092 }
40093- info->port.count++;
40094+ atomic_inc(&info->port.count);
40095 spin_unlock_irqrestore(&info->netlock, flags);
40096
40097- if (info->port.count == 1) {
40098+ if (atomic_read(&info->port.count) == 1) {
40099 /* 1st open on this device, init hardware */
40100 retval = startup(info);
40101 if (retval < 0)
40102@@ -797,8 +797,8 @@ cleanup:
40103 if (retval) {
40104 if (tty->count == 1)
40105 info->port.tty = NULL; /* tty layer will release tty struct */
40106- if(info->port.count)
40107- info->port.count--;
40108+ if(atomic_read(&info->port.count))
40109+ atomic_dec(&info->port.count);
40110 }
40111
40112 return retval;
40113@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40114
40115 if (debug_level >= DEBUG_LEVEL_INFO)
40116 printk("%s(%d):%s close() entry, count=%d\n",
40117- __FILE__,__LINE__, info->device_name, info->port.count);
40118+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40119
40120 if (tty_port_close_start(&info->port, tty, filp) == 0)
40121 goto cleanup;
40122@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40123 cleanup:
40124 if (debug_level >= DEBUG_LEVEL_INFO)
40125 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40126- tty->driver->name, info->port.count);
40127+ tty->driver->name, atomic_read(&info->port.count));
40128 }
40129
40130 /* Called by tty_hangup() when a hangup is signaled.
40131@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40132 shutdown(info);
40133
40134 spin_lock_irqsave(&info->port.lock, flags);
40135- info->port.count = 0;
40136+ atomic_set(&info->port.count, 0);
40137 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40138 info->port.tty = NULL;
40139 spin_unlock_irqrestore(&info->port.lock, flags);
40140@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40141 unsigned short new_crctype;
40142
40143 /* return error if TTY interface open */
40144- if (info->port.count)
40145+ if (atomic_read(&info->port.count))
40146 return -EBUSY;
40147
40148 switch (encoding)
40149@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40150
40151 /* arbitrate between network and tty opens */
40152 spin_lock_irqsave(&info->netlock, flags);
40153- if (info->port.count != 0 || info->netcount != 0) {
40154+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40155 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40156 spin_unlock_irqrestore(&info->netlock, flags);
40157 return -EBUSY;
40158@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40159 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40160
40161 /* return error if TTY interface open */
40162- if (info->port.count)
40163+ if (atomic_read(&info->port.count))
40164 return -EBUSY;
40165
40166 if (cmd != SIOCWANDEV)
40167@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40168 * do not request bottom half processing if the
40169 * device is not open in a normal mode.
40170 */
40171- if ( port && (port->port.count || port->netcount) &&
40172+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40173 port->pending_bh && !port->bh_running &&
40174 !port->bh_requested ) {
40175 if ( debug_level >= DEBUG_LEVEL_ISR )
40176@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40177
40178 if (debug_level >= DEBUG_LEVEL_INFO)
40179 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40180- __FILE__,__LINE__, tty->driver->name, port->count );
40181+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40182
40183 spin_lock_irqsave(&info->lock, flags);
40184 if (!tty_hung_up_p(filp)) {
40185 extra_count = true;
40186- port->count--;
40187+ atomic_dec(&port->count);
40188 }
40189 spin_unlock_irqrestore(&info->lock, flags);
40190 port->blocked_open++;
40191@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40192
40193 if (debug_level >= DEBUG_LEVEL_INFO)
40194 printk("%s(%d):%s block_til_ready() count=%d\n",
40195- __FILE__,__LINE__, tty->driver->name, port->count );
40196+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40197
40198 tty_unlock(tty);
40199 schedule();
40200@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40201 remove_wait_queue(&port->open_wait, &wait);
40202
40203 if (extra_count)
40204- port->count++;
40205+ atomic_inc(&port->count);
40206 port->blocked_open--;
40207
40208 if (debug_level >= DEBUG_LEVEL_INFO)
40209 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40210- __FILE__,__LINE__, tty->driver->name, port->count );
40211+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40212
40213 if (!retval)
40214 port->flags |= ASYNC_NORMAL_ACTIVE;
40215diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40216index 16ee6ce..bfcac57 100644
40217--- a/drivers/tty/sysrq.c
40218+++ b/drivers/tty/sysrq.c
40219@@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40220 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40221 size_t count, loff_t *ppos)
40222 {
40223- if (count) {
40224+ if (count && capable(CAP_SYS_ADMIN)) {
40225 char c;
40226
40227 if (get_user(c, buf))
40228diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40229index 2ea176b..2877bc8 100644
40230--- a/drivers/tty/tty_io.c
40231+++ b/drivers/tty/tty_io.c
40232@@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40233
40234 void tty_default_fops(struct file_operations *fops)
40235 {
40236- *fops = tty_fops;
40237+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40238 }
40239
40240 /*
40241diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40242index 0f2a2c5..471e228 100644
40243--- a/drivers/tty/tty_ldisc.c
40244+++ b/drivers/tty/tty_ldisc.c
40245@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40246 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40247 struct tty_ldisc_ops *ldo = ld->ops;
40248
40249- ldo->refcount--;
40250+ atomic_dec(&ldo->refcount);
40251 module_put(ldo->owner);
40252 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40253
40254@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40255 spin_lock_irqsave(&tty_ldisc_lock, flags);
40256 tty_ldiscs[disc] = new_ldisc;
40257 new_ldisc->num = disc;
40258- new_ldisc->refcount = 0;
40259+ atomic_set(&new_ldisc->refcount, 0);
40260 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40261
40262 return ret;
40263@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40264 return -EINVAL;
40265
40266 spin_lock_irqsave(&tty_ldisc_lock, flags);
40267- if (tty_ldiscs[disc]->refcount)
40268+ if (atomic_read(&tty_ldiscs[disc]->refcount))
40269 ret = -EBUSY;
40270 else
40271 tty_ldiscs[disc] = NULL;
40272@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40273 if (ldops) {
40274 ret = ERR_PTR(-EAGAIN);
40275 if (try_module_get(ldops->owner)) {
40276- ldops->refcount++;
40277+ atomic_inc(&ldops->refcount);
40278 ret = ldops;
40279 }
40280 }
40281@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40282 unsigned long flags;
40283
40284 spin_lock_irqsave(&tty_ldisc_lock, flags);
40285- ldops->refcount--;
40286+ atomic_dec(&ldops->refcount);
40287 module_put(ldops->owner);
40288 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40289 }
40290diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40291index d7bdd8d..feaef30 100644
40292--- a/drivers/tty/tty_port.c
40293+++ b/drivers/tty/tty_port.c
40294@@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40295 unsigned long flags;
40296
40297 spin_lock_irqsave(&port->lock, flags);
40298- port->count = 0;
40299+ atomic_set(&port->count, 0);
40300 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40301 if (port->tty) {
40302 set_bit(TTY_IO_ERROR, &port->tty->flags);
40303@@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40304 /* The port lock protects the port counts */
40305 spin_lock_irqsave(&port->lock, flags);
40306 if (!tty_hung_up_p(filp))
40307- port->count--;
40308+ atomic_dec(&port->count);
40309 port->blocked_open++;
40310 spin_unlock_irqrestore(&port->lock, flags);
40311
40312@@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40313 we must not mess that up further */
40314 spin_lock_irqsave(&port->lock, flags);
40315 if (!tty_hung_up_p(filp))
40316- port->count++;
40317+ atomic_inc(&port->count);
40318 port->blocked_open--;
40319 if (retval == 0)
40320 port->flags |= ASYNC_NORMAL_ACTIVE;
40321@@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40322 return 0;
40323 }
40324
40325- if (tty->count == 1 && port->count != 1) {
40326+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
40327 printk(KERN_WARNING
40328 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40329- port->count);
40330- port->count = 1;
40331+ atomic_read(&port->count));
40332+ atomic_set(&port->count, 1);
40333 }
40334- if (--port->count < 0) {
40335+ if (atomic_dec_return(&port->count) < 0) {
40336 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40337- port->count);
40338- port->count = 0;
40339+ atomic_read(&port->count));
40340+ atomic_set(&port->count, 0);
40341 }
40342
40343- if (port->count) {
40344+ if (atomic_read(&port->count)) {
40345 spin_unlock_irqrestore(&port->lock, flags);
40346 if (port->ops->drop)
40347 port->ops->drop(port);
40348@@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40349 {
40350 spin_lock_irq(&port->lock);
40351 if (!tty_hung_up_p(filp))
40352- ++port->count;
40353+ atomic_inc(&port->count);
40354 spin_unlock_irq(&port->lock);
40355 tty_port_tty_set(port, tty);
40356
40357diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40358index 681765b..d3ccdf2 100644
40359--- a/drivers/tty/vt/keyboard.c
40360+++ b/drivers/tty/vt/keyboard.c
40361@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40362 kbd->kbdmode == VC_OFF) &&
40363 value != KVAL(K_SAK))
40364 return; /* SAK is allowed even in raw mode */
40365+
40366+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40367+ {
40368+ void *func = fn_handler[value];
40369+ if (func == fn_show_state || func == fn_show_ptregs ||
40370+ func == fn_show_mem)
40371+ return;
40372+ }
40373+#endif
40374+
40375 fn_handler[value](vc);
40376 }
40377
40378@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40379 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40380 return -EFAULT;
40381
40382- if (!capable(CAP_SYS_TTY_CONFIG))
40383- perm = 0;
40384-
40385 switch (cmd) {
40386 case KDGKBENT:
40387 /* Ensure another thread doesn't free it under us */
40388@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40389 spin_unlock_irqrestore(&kbd_event_lock, flags);
40390 return put_user(val, &user_kbe->kb_value);
40391 case KDSKBENT:
40392+ if (!capable(CAP_SYS_TTY_CONFIG))
40393+ perm = 0;
40394+
40395 if (!perm)
40396 return -EPERM;
40397 if (!i && v == K_NOSUCHMAP) {
40398@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40399 int i, j, k;
40400 int ret;
40401
40402- if (!capable(CAP_SYS_TTY_CONFIG))
40403- perm = 0;
40404-
40405 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40406 if (!kbs) {
40407 ret = -ENOMEM;
40408@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40409 kfree(kbs);
40410 return ((p && *p) ? -EOVERFLOW : 0);
40411 case KDSKBSENT:
40412+ if (!capable(CAP_SYS_TTY_CONFIG))
40413+ perm = 0;
40414+
40415 if (!perm) {
40416 ret = -EPERM;
40417 goto reterr;
40418diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40419index 5110f36..8dc0a74 100644
40420--- a/drivers/uio/uio.c
40421+++ b/drivers/uio/uio.c
40422@@ -25,6 +25,7 @@
40423 #include <linux/kobject.h>
40424 #include <linux/cdev.h>
40425 #include <linux/uio_driver.h>
40426+#include <asm/local.h>
40427
40428 #define UIO_MAX_DEVICES (1U << MINORBITS)
40429
40430@@ -32,10 +33,10 @@ struct uio_device {
40431 struct module *owner;
40432 struct device *dev;
40433 int minor;
40434- atomic_t event;
40435+ atomic_unchecked_t event;
40436 struct fasync_struct *async_queue;
40437 wait_queue_head_t wait;
40438- int vma_count;
40439+ local_t vma_count;
40440 struct uio_info *info;
40441 struct kobject *map_dir;
40442 struct kobject *portio_dir;
40443@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40444 struct device_attribute *attr, char *buf)
40445 {
40446 struct uio_device *idev = dev_get_drvdata(dev);
40447- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40448+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40449 }
40450
40451 static struct device_attribute uio_class_attributes[] = {
40452@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40453 {
40454 struct uio_device *idev = info->uio_dev;
40455
40456- atomic_inc(&idev->event);
40457+ atomic_inc_unchecked(&idev->event);
40458 wake_up_interruptible(&idev->wait);
40459 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40460 }
40461@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40462 }
40463
40464 listener->dev = idev;
40465- listener->event_count = atomic_read(&idev->event);
40466+ listener->event_count = atomic_read_unchecked(&idev->event);
40467 filep->private_data = listener;
40468
40469 if (idev->info->open) {
40470@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40471 return -EIO;
40472
40473 poll_wait(filep, &idev->wait, wait);
40474- if (listener->event_count != atomic_read(&idev->event))
40475+ if (listener->event_count != atomic_read_unchecked(&idev->event))
40476 return POLLIN | POLLRDNORM;
40477 return 0;
40478 }
40479@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40480 do {
40481 set_current_state(TASK_INTERRUPTIBLE);
40482
40483- event_count = atomic_read(&idev->event);
40484+ event_count = atomic_read_unchecked(&idev->event);
40485 if (event_count != listener->event_count) {
40486 if (copy_to_user(buf, &event_count, count))
40487 retval = -EFAULT;
40488@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40489 static void uio_vma_open(struct vm_area_struct *vma)
40490 {
40491 struct uio_device *idev = vma->vm_private_data;
40492- idev->vma_count++;
40493+ local_inc(&idev->vma_count);
40494 }
40495
40496 static void uio_vma_close(struct vm_area_struct *vma)
40497 {
40498 struct uio_device *idev = vma->vm_private_data;
40499- idev->vma_count--;
40500+ local_dec(&idev->vma_count);
40501 }
40502
40503 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40504@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40505 idev->owner = owner;
40506 idev->info = info;
40507 init_waitqueue_head(&idev->wait);
40508- atomic_set(&idev->event, 0);
40509+ atomic_set_unchecked(&idev->event, 0);
40510
40511 ret = uio_get_minor(idev);
40512 if (ret)
40513diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40514index b7eb86a..36d28af 100644
40515--- a/drivers/usb/atm/cxacru.c
40516+++ b/drivers/usb/atm/cxacru.c
40517@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40518 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40519 if (ret < 2)
40520 return -EINVAL;
40521- if (index < 0 || index > 0x7f)
40522+ if (index > 0x7f)
40523 return -EINVAL;
40524 pos += tmp;
40525
40526diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40527index 35f10bf..6a38a0b 100644
40528--- a/drivers/usb/atm/usbatm.c
40529+++ b/drivers/usb/atm/usbatm.c
40530@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40531 if (printk_ratelimit())
40532 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40533 __func__, vpi, vci);
40534- atomic_inc(&vcc->stats->rx_err);
40535+ atomic_inc_unchecked(&vcc->stats->rx_err);
40536 return;
40537 }
40538
40539@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40540 if (length > ATM_MAX_AAL5_PDU) {
40541 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40542 __func__, length, vcc);
40543- atomic_inc(&vcc->stats->rx_err);
40544+ atomic_inc_unchecked(&vcc->stats->rx_err);
40545 goto out;
40546 }
40547
40548@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40549 if (sarb->len < pdu_length) {
40550 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40551 __func__, pdu_length, sarb->len, vcc);
40552- atomic_inc(&vcc->stats->rx_err);
40553+ atomic_inc_unchecked(&vcc->stats->rx_err);
40554 goto out;
40555 }
40556
40557 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40558 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40559 __func__, vcc);
40560- atomic_inc(&vcc->stats->rx_err);
40561+ atomic_inc_unchecked(&vcc->stats->rx_err);
40562 goto out;
40563 }
40564
40565@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40566 if (printk_ratelimit())
40567 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40568 __func__, length);
40569- atomic_inc(&vcc->stats->rx_drop);
40570+ atomic_inc_unchecked(&vcc->stats->rx_drop);
40571 goto out;
40572 }
40573
40574@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40575
40576 vcc->push(vcc, skb);
40577
40578- atomic_inc(&vcc->stats->rx);
40579+ atomic_inc_unchecked(&vcc->stats->rx);
40580 out:
40581 skb_trim(sarb, 0);
40582 }
40583@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40584 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40585
40586 usbatm_pop(vcc, skb);
40587- atomic_inc(&vcc->stats->tx);
40588+ atomic_inc_unchecked(&vcc->stats->tx);
40589
40590 skb = skb_dequeue(&instance->sndqueue);
40591 }
40592@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40593 if (!left--)
40594 return sprintf(page,
40595 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40596- atomic_read(&atm_dev->stats.aal5.tx),
40597- atomic_read(&atm_dev->stats.aal5.tx_err),
40598- atomic_read(&atm_dev->stats.aal5.rx),
40599- atomic_read(&atm_dev->stats.aal5.rx_err),
40600- atomic_read(&atm_dev->stats.aal5.rx_drop));
40601+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40602+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40603+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40604+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40605+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40606
40607 if (!left--) {
40608 if (instance->disconnected)
40609diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40610index f460de3..95ba1f6 100644
40611--- a/drivers/usb/core/devices.c
40612+++ b/drivers/usb/core/devices.c
40613@@ -126,7 +126,7 @@ static const char format_endpt[] =
40614 * time it gets called.
40615 */
40616 static struct device_connect_event {
40617- atomic_t count;
40618+ atomic_unchecked_t count;
40619 wait_queue_head_t wait;
40620 } device_event = {
40621 .count = ATOMIC_INIT(1),
40622@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40623
40624 void usbfs_conn_disc_event(void)
40625 {
40626- atomic_add(2, &device_event.count);
40627+ atomic_add_unchecked(2, &device_event.count);
40628 wake_up(&device_event.wait);
40629 }
40630
40631@@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40632
40633 poll_wait(file, &device_event.wait, wait);
40634
40635- event_count = atomic_read(&device_event.count);
40636+ event_count = atomic_read_unchecked(&device_event.count);
40637 if (file->f_version != event_count) {
40638 file->f_version = event_count;
40639 return POLLIN | POLLRDNORM;
40640diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40641index f034716..aed0368 100644
40642--- a/drivers/usb/core/hcd.c
40643+++ b/drivers/usb/core/hcd.c
40644@@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40645 */
40646 usb_get_urb(urb);
40647 atomic_inc(&urb->use_count);
40648- atomic_inc(&urb->dev->urbnum);
40649+ atomic_inc_unchecked(&urb->dev->urbnum);
40650 usbmon_urb_submit(&hcd->self, urb);
40651
40652 /* NOTE requirements on root-hub callers (usbfs and the hub
40653@@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40654 urb->hcpriv = NULL;
40655 INIT_LIST_HEAD(&urb->urb_list);
40656 atomic_dec(&urb->use_count);
40657- atomic_dec(&urb->dev->urbnum);
40658+ atomic_dec_unchecked(&urb->dev->urbnum);
40659 if (atomic_read(&urb->reject))
40660 wake_up(&usb_kill_urb_queue);
40661 usb_put_urb(urb);
40662diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40663index 818e4a0..0fc9589 100644
40664--- a/drivers/usb/core/sysfs.c
40665+++ b/drivers/usb/core/sysfs.c
40666@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40667 struct usb_device *udev;
40668
40669 udev = to_usb_device(dev);
40670- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40671+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40672 }
40673 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40674
40675diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40676index cd8fb44..17fbe0c 100644
40677--- a/drivers/usb/core/usb.c
40678+++ b/drivers/usb/core/usb.c
40679@@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40680 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40681 dev->state = USB_STATE_ATTACHED;
40682 dev->lpm_disable_count = 1;
40683- atomic_set(&dev->urbnum, 0);
40684+ atomic_set_unchecked(&dev->urbnum, 0);
40685
40686 INIT_LIST_HEAD(&dev->ep0.urb_list);
40687 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40688diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40689index 4bfa78a..902bfbd 100644
40690--- a/drivers/usb/early/ehci-dbgp.c
40691+++ b/drivers/usb/early/ehci-dbgp.c
40692@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40693
40694 #ifdef CONFIG_KGDB
40695 static struct kgdb_io kgdbdbgp_io_ops;
40696-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40697+static struct kgdb_io kgdbdbgp_io_ops_console;
40698+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40699 #else
40700 #define dbgp_kgdb_mode (0)
40701 #endif
40702@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40703 .write_char = kgdbdbgp_write_char,
40704 };
40705
40706+static struct kgdb_io kgdbdbgp_io_ops_console = {
40707+ .name = "kgdbdbgp",
40708+ .read_char = kgdbdbgp_read_char,
40709+ .write_char = kgdbdbgp_write_char,
40710+ .is_console = 1
40711+};
40712+
40713 static int kgdbdbgp_wait_time;
40714
40715 static int __init kgdbdbgp_parse_config(char *str)
40716@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40717 ptr++;
40718 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40719 }
40720- kgdb_register_io_module(&kgdbdbgp_io_ops);
40721- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40722+ if (early_dbgp_console.index != -1)
40723+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40724+ else
40725+ kgdb_register_io_module(&kgdbdbgp_io_ops);
40726
40727 return 0;
40728 }
40729diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40730index f173952..83d6ec0 100644
40731--- a/drivers/usb/gadget/u_serial.c
40732+++ b/drivers/usb/gadget/u_serial.c
40733@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40734 spin_lock_irq(&port->port_lock);
40735
40736 /* already open? Great. */
40737- if (port->port.count) {
40738+ if (atomic_read(&port->port.count)) {
40739 status = 0;
40740- port->port.count++;
40741+ atomic_inc(&port->port.count);
40742
40743 /* currently opening/closing? wait ... */
40744 } else if (port->openclose) {
40745@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40746 tty->driver_data = port;
40747 port->port.tty = tty;
40748
40749- port->port.count = 1;
40750+ atomic_set(&port->port.count, 1);
40751 port->openclose = false;
40752
40753 /* if connected, start the I/O stream */
40754@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40755
40756 spin_lock_irq(&port->port_lock);
40757
40758- if (port->port.count != 1) {
40759- if (port->port.count == 0)
40760+ if (atomic_read(&port->port.count) != 1) {
40761+ if (atomic_read(&port->port.count) == 0)
40762 WARN_ON(1);
40763 else
40764- --port->port.count;
40765+ atomic_dec(&port->port.count);
40766 goto exit;
40767 }
40768
40769@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40770 * and sleep if necessary
40771 */
40772 port->openclose = true;
40773- port->port.count = 0;
40774+ atomic_set(&port->port.count, 0);
40775
40776 gser = port->port_usb;
40777 if (gser && gser->disconnect)
40778@@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40779 int cond;
40780
40781 spin_lock_irq(&port->port_lock);
40782- cond = (port->port.count == 0) && !port->openclose;
40783+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40784 spin_unlock_irq(&port->port_lock);
40785 return cond;
40786 }
40787@@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40788 /* if it's already open, start I/O ... and notify the serial
40789 * protocol about open/close status (connect/disconnect).
40790 */
40791- if (port->port.count) {
40792+ if (atomic_read(&port->port.count)) {
40793 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
40794 gs_start_io(port);
40795 if (gser->connect)
40796@@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
40797
40798 port->port_usb = NULL;
40799 gser->ioport = NULL;
40800- if (port->port.count > 0 || port->openclose) {
40801+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
40802 wake_up_interruptible(&port->drain_wait);
40803 if (port->port.tty)
40804 tty_hangup(port->port.tty);
40805@@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
40806
40807 /* finally, free any unused/unusable I/O buffers */
40808 spin_lock_irqsave(&port->port_lock, flags);
40809- if (port->port.count == 0 && !port->openclose)
40810+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
40811 gs_buf_free(&port->port_write_buf);
40812 gs_free_requests(gser->out, &port->read_pool, NULL);
40813 gs_free_requests(gser->out, &port->read_queue, NULL);
40814diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
40815index 5f3bcd3..bfca43f 100644
40816--- a/drivers/usb/serial/console.c
40817+++ b/drivers/usb/serial/console.c
40818@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
40819
40820 info->port = port;
40821
40822- ++port->port.count;
40823+ atomic_inc(&port->port.count);
40824 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
40825 if (serial->type->set_termios) {
40826 /*
40827@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
40828 }
40829 /* Now that any required fake tty operations are completed restore
40830 * the tty port count */
40831- --port->port.count;
40832+ atomic_dec(&port->port.count);
40833 /* The console is special in terms of closing the device so
40834 * indicate this port is now acting as a system console. */
40835 port->port.console = 1;
40836@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
40837 free_tty:
40838 kfree(tty);
40839 reset_open_count:
40840- port->port.count = 0;
40841+ atomic_set(&port->port.count, 0);
40842 usb_autopm_put_interface(serial->interface);
40843 error_get_interface:
40844 usb_serial_put(serial);
40845diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
40846index d6bea3e..60b250e 100644
40847--- a/drivers/usb/wusbcore/wa-hc.h
40848+++ b/drivers/usb/wusbcore/wa-hc.h
40849@@ -192,7 +192,7 @@ struct wahc {
40850 struct list_head xfer_delayed_list;
40851 spinlock_t xfer_list_lock;
40852 struct work_struct xfer_work;
40853- atomic_t xfer_id_count;
40854+ atomic_unchecked_t xfer_id_count;
40855 };
40856
40857
40858@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
40859 INIT_LIST_HEAD(&wa->xfer_delayed_list);
40860 spin_lock_init(&wa->xfer_list_lock);
40861 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
40862- atomic_set(&wa->xfer_id_count, 1);
40863+ atomic_set_unchecked(&wa->xfer_id_count, 1);
40864 }
40865
40866 /**
40867diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
40868index 57c01ab..8a05959 100644
40869--- a/drivers/usb/wusbcore/wa-xfer.c
40870+++ b/drivers/usb/wusbcore/wa-xfer.c
40871@@ -296,7 +296,7 @@ out:
40872 */
40873 static void wa_xfer_id_init(struct wa_xfer *xfer)
40874 {
40875- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
40876+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
40877 }
40878
40879 /*
40880diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
40881index dedaf81..b0f11ab 100644
40882--- a/drivers/vhost/vhost.c
40883+++ b/drivers/vhost/vhost.c
40884@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
40885 return 0;
40886 }
40887
40888-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
40889+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
40890 {
40891 struct file *eventfp, *filep = NULL;
40892 bool pollstart = false, pollstop = false;
40893diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
40894index 0fefa84..7a9d581 100644
40895--- a/drivers/video/aty/aty128fb.c
40896+++ b/drivers/video/aty/aty128fb.c
40897@@ -149,7 +149,7 @@ enum {
40898 };
40899
40900 /* Must match above enum */
40901-static char * const r128_family[] __devinitconst = {
40902+static const char * const r128_family[] __devinitconst = {
40903 "AGP",
40904 "PCI",
40905 "PRO AGP",
40906diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
40907index 5c3960d..15cf8fc 100644
40908--- a/drivers/video/fbcmap.c
40909+++ b/drivers/video/fbcmap.c
40910@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
40911 rc = -ENODEV;
40912 goto out;
40913 }
40914- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
40915- !info->fbops->fb_setcmap)) {
40916+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
40917 rc = -EINVAL;
40918 goto out1;
40919 }
40920diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
40921index 3ff0105..7589d98 100644
40922--- a/drivers/video/fbmem.c
40923+++ b/drivers/video/fbmem.c
40924@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40925 image->dx += image->width + 8;
40926 }
40927 } else if (rotate == FB_ROTATE_UD) {
40928- for (x = 0; x < num && image->dx >= 0; x++) {
40929+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
40930 info->fbops->fb_imageblit(info, image);
40931 image->dx -= image->width + 8;
40932 }
40933@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
40934 image->dy += image->height + 8;
40935 }
40936 } else if (rotate == FB_ROTATE_CCW) {
40937- for (x = 0; x < num && image->dy >= 0; x++) {
40938+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
40939 info->fbops->fb_imageblit(info, image);
40940 image->dy -= image->height + 8;
40941 }
40942@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
40943 return -EFAULT;
40944 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
40945 return -EINVAL;
40946- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
40947+ if (con2fb.framebuffer >= FB_MAX)
40948 return -EINVAL;
40949 if (!registered_fb[con2fb.framebuffer])
40950 request_module("fb%d", con2fb.framebuffer);
40951diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
40952index 7672d2e..b56437f 100644
40953--- a/drivers/video/i810/i810_accel.c
40954+++ b/drivers/video/i810/i810_accel.c
40955@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
40956 }
40957 }
40958 printk("ringbuffer lockup!!!\n");
40959+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
40960 i810_report_error(mmio);
40961 par->dev_flags |= LOCKUP;
40962 info->pixmap.scan_align = 1;
40963diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
40964index 3c14e43..eafa544 100644
40965--- a/drivers/video/logo/logo_linux_clut224.ppm
40966+++ b/drivers/video/logo/logo_linux_clut224.ppm
40967@@ -1,1604 +1,1123 @@
40968 P3
40969-# Standard 224-color Linux logo
40970 80 80
40971 255
40972- 0 0 0 0 0 0 0 0 0 0 0 0
40973- 0 0 0 0 0 0 0 0 0 0 0 0
40974- 0 0 0 0 0 0 0 0 0 0 0 0
40975- 0 0 0 0 0 0 0 0 0 0 0 0
40976- 0 0 0 0 0 0 0 0 0 0 0 0
40977- 0 0 0 0 0 0 0 0 0 0 0 0
40978- 0 0 0 0 0 0 0 0 0 0 0 0
40979- 0 0 0 0 0 0 0 0 0 0 0 0
40980- 0 0 0 0 0 0 0 0 0 0 0 0
40981- 6 6 6 6 6 6 10 10 10 10 10 10
40982- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0
40986- 0 0 0 0 0 0 0 0 0 0 0 0
40987- 0 0 0 0 0 0 0 0 0 0 0 0
40988- 0 0 0 0 0 0 0 0 0 0 0 0
40989- 0 0 0 0 0 0 0 0 0 0 0 0
40990- 0 0 0 0 0 0 0 0 0 0 0 0
40991- 0 0 0 0 0 0 0 0 0 0 0 0
40992- 0 0 0 0 0 0 0 0 0 0 0 0
40993- 0 0 0 0 0 0 0 0 0 0 0 0
40994- 0 0 0 0 0 0 0 0 0 0 0 0
40995- 0 0 0 0 0 0 0 0 0 0 0 0
40996- 0 0 0 0 0 0 0 0 0 0 0 0
40997- 0 0 0 0 0 0 0 0 0 0 0 0
40998- 0 0 0 0 0 0 0 0 0 0 0 0
40999- 0 0 0 0 0 0 0 0 0 0 0 0
41000- 0 0 0 6 6 6 10 10 10 14 14 14
41001- 22 22 22 26 26 26 30 30 30 34 34 34
41002- 30 30 30 30 30 30 26 26 26 18 18 18
41003- 14 14 14 10 10 10 6 6 6 0 0 0
41004- 0 0 0 0 0 0 0 0 0 0 0 0
41005- 0 0 0 0 0 0 0 0 0 0 0 0
41006- 0 0 0 0 0 0 0 0 0 0 0 0
41007- 0 0 0 0 0 0 0 0 0 0 0 0
41008- 0 0 0 0 0 0 0 0 0 0 0 0
41009- 0 0 0 0 0 0 0 0 0 0 0 0
41010- 0 0 0 0 0 0 0 0 0 0 0 0
41011- 0 0 0 0 0 0 0 0 0 0 0 0
41012- 0 0 0 0 0 0 0 0 0 0 0 0
41013- 0 0 0 0 0 1 0 0 1 0 0 0
41014- 0 0 0 0 0 0 0 0 0 0 0 0
41015- 0 0 0 0 0 0 0 0 0 0 0 0
41016- 0 0 0 0 0 0 0 0 0 0 0 0
41017- 0 0 0 0 0 0 0 0 0 0 0 0
41018- 0 0 0 0 0 0 0 0 0 0 0 0
41019- 0 0 0 0 0 0 0 0 0 0 0 0
41020- 6 6 6 14 14 14 26 26 26 42 42 42
41021- 54 54 54 66 66 66 78 78 78 78 78 78
41022- 78 78 78 74 74 74 66 66 66 54 54 54
41023- 42 42 42 26 26 26 18 18 18 10 10 10
41024- 6 6 6 0 0 0 0 0 0 0 0 0
41025- 0 0 0 0 0 0 0 0 0 0 0 0
41026- 0 0 0 0 0 0 0 0 0 0 0 0
41027- 0 0 0 0 0 0 0 0 0 0 0 0
41028- 0 0 0 0 0 0 0 0 0 0 0 0
41029- 0 0 0 0 0 0 0 0 0 0 0 0
41030- 0 0 0 0 0 0 0 0 0 0 0 0
41031- 0 0 0 0 0 0 0 0 0 0 0 0
41032- 0 0 0 0 0 0 0 0 0 0 0 0
41033- 0 0 1 0 0 0 0 0 0 0 0 0
41034- 0 0 0 0 0 0 0 0 0 0 0 0
41035- 0 0 0 0 0 0 0 0 0 0 0 0
41036- 0 0 0 0 0 0 0 0 0 0 0 0
41037- 0 0 0 0 0 0 0 0 0 0 0 0
41038- 0 0 0 0 0 0 0 0 0 0 0 0
41039- 0 0 0 0 0 0 0 0 0 10 10 10
41040- 22 22 22 42 42 42 66 66 66 86 86 86
41041- 66 66 66 38 38 38 38 38 38 22 22 22
41042- 26 26 26 34 34 34 54 54 54 66 66 66
41043- 86 86 86 70 70 70 46 46 46 26 26 26
41044- 14 14 14 6 6 6 0 0 0 0 0 0
41045- 0 0 0 0 0 0 0 0 0 0 0 0
41046- 0 0 0 0 0 0 0 0 0 0 0 0
41047- 0 0 0 0 0 0 0 0 0 0 0 0
41048- 0 0 0 0 0 0 0 0 0 0 0 0
41049- 0 0 0 0 0 0 0 0 0 0 0 0
41050- 0 0 0 0 0 0 0 0 0 0 0 0
41051- 0 0 0 0 0 0 0 0 0 0 0 0
41052- 0 0 0 0 0 0 0 0 0 0 0 0
41053- 0 0 1 0 0 1 0 0 1 0 0 0
41054- 0 0 0 0 0 0 0 0 0 0 0 0
41055- 0 0 0 0 0 0 0 0 0 0 0 0
41056- 0 0 0 0 0 0 0 0 0 0 0 0
41057- 0 0 0 0 0 0 0 0 0 0 0 0
41058- 0 0 0 0 0 0 0 0 0 0 0 0
41059- 0 0 0 0 0 0 10 10 10 26 26 26
41060- 50 50 50 82 82 82 58 58 58 6 6 6
41061- 2 2 6 2 2 6 2 2 6 2 2 6
41062- 2 2 6 2 2 6 2 2 6 2 2 6
41063- 6 6 6 54 54 54 86 86 86 66 66 66
41064- 38 38 38 18 18 18 6 6 6 0 0 0
41065- 0 0 0 0 0 0 0 0 0 0 0 0
41066- 0 0 0 0 0 0 0 0 0 0 0 0
41067- 0 0 0 0 0 0 0 0 0 0 0 0
41068- 0 0 0 0 0 0 0 0 0 0 0 0
41069- 0 0 0 0 0 0 0 0 0 0 0 0
41070- 0 0 0 0 0 0 0 0 0 0 0 0
41071- 0 0 0 0 0 0 0 0 0 0 0 0
41072- 0 0 0 0 0 0 0 0 0 0 0 0
41073- 0 0 0 0 0 0 0 0 0 0 0 0
41074- 0 0 0 0 0 0 0 0 0 0 0 0
41075- 0 0 0 0 0 0 0 0 0 0 0 0
41076- 0 0 0 0 0 0 0 0 0 0 0 0
41077- 0 0 0 0 0 0 0 0 0 0 0 0
41078- 0 0 0 0 0 0 0 0 0 0 0 0
41079- 0 0 0 6 6 6 22 22 22 50 50 50
41080- 78 78 78 34 34 34 2 2 6 2 2 6
41081- 2 2 6 2 2 6 2 2 6 2 2 6
41082- 2 2 6 2 2 6 2 2 6 2 2 6
41083- 2 2 6 2 2 6 6 6 6 70 70 70
41084- 78 78 78 46 46 46 22 22 22 6 6 6
41085- 0 0 0 0 0 0 0 0 0 0 0 0
41086- 0 0 0 0 0 0 0 0 0 0 0 0
41087- 0 0 0 0 0 0 0 0 0 0 0 0
41088- 0 0 0 0 0 0 0 0 0 0 0 0
41089- 0 0 0 0 0 0 0 0 0 0 0 0
41090- 0 0 0 0 0 0 0 0 0 0 0 0
41091- 0 0 0 0 0 0 0 0 0 0 0 0
41092- 0 0 0 0 0 0 0 0 0 0 0 0
41093- 0 0 1 0 0 1 0 0 1 0 0 0
41094- 0 0 0 0 0 0 0 0 0 0 0 0
41095- 0 0 0 0 0 0 0 0 0 0 0 0
41096- 0 0 0 0 0 0 0 0 0 0 0 0
41097- 0 0 0 0 0 0 0 0 0 0 0 0
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 6 6 6 18 18 18 42 42 42 82 82 82
41100- 26 26 26 2 2 6 2 2 6 2 2 6
41101- 2 2 6 2 2 6 2 2 6 2 2 6
41102- 2 2 6 2 2 6 2 2 6 14 14 14
41103- 46 46 46 34 34 34 6 6 6 2 2 6
41104- 42 42 42 78 78 78 42 42 42 18 18 18
41105- 6 6 6 0 0 0 0 0 0 0 0 0
41106- 0 0 0 0 0 0 0 0 0 0 0 0
41107- 0 0 0 0 0 0 0 0 0 0 0 0
41108- 0 0 0 0 0 0 0 0 0 0 0 0
41109- 0 0 0 0 0 0 0 0 0 0 0 0
41110- 0 0 0 0 0 0 0 0 0 0 0 0
41111- 0 0 0 0 0 0 0 0 0 0 0 0
41112- 0 0 0 0 0 0 0 0 0 0 0 0
41113- 0 0 1 0 0 0 0 0 1 0 0 0
41114- 0 0 0 0 0 0 0 0 0 0 0 0
41115- 0 0 0 0 0 0 0 0 0 0 0 0
41116- 0 0 0 0 0 0 0 0 0 0 0 0
41117- 0 0 0 0 0 0 0 0 0 0 0 0
41118- 0 0 0 0 0 0 0 0 0 0 0 0
41119- 10 10 10 30 30 30 66 66 66 58 58 58
41120- 2 2 6 2 2 6 2 2 6 2 2 6
41121- 2 2 6 2 2 6 2 2 6 2 2 6
41122- 2 2 6 2 2 6 2 2 6 26 26 26
41123- 86 86 86 101 101 101 46 46 46 10 10 10
41124- 2 2 6 58 58 58 70 70 70 34 34 34
41125- 10 10 10 0 0 0 0 0 0 0 0 0
41126- 0 0 0 0 0 0 0 0 0 0 0 0
41127- 0 0 0 0 0 0 0 0 0 0 0 0
41128- 0 0 0 0 0 0 0 0 0 0 0 0
41129- 0 0 0 0 0 0 0 0 0 0 0 0
41130- 0 0 0 0 0 0 0 0 0 0 0 0
41131- 0 0 0 0 0 0 0 0 0 0 0 0
41132- 0 0 0 0 0 0 0 0 0 0 0 0
41133- 0 0 1 0 0 1 0 0 1 0 0 0
41134- 0 0 0 0 0 0 0 0 0 0 0 0
41135- 0 0 0 0 0 0 0 0 0 0 0 0
41136- 0 0 0 0 0 0 0 0 0 0 0 0
41137- 0 0 0 0 0 0 0 0 0 0 0 0
41138- 0 0 0 0 0 0 0 0 0 0 0 0
41139- 14 14 14 42 42 42 86 86 86 10 10 10
41140- 2 2 6 2 2 6 2 2 6 2 2 6
41141- 2 2 6 2 2 6 2 2 6 2 2 6
41142- 2 2 6 2 2 6 2 2 6 30 30 30
41143- 94 94 94 94 94 94 58 58 58 26 26 26
41144- 2 2 6 6 6 6 78 78 78 54 54 54
41145- 22 22 22 6 6 6 0 0 0 0 0 0
41146- 0 0 0 0 0 0 0 0 0 0 0 0
41147- 0 0 0 0 0 0 0 0 0 0 0 0
41148- 0 0 0 0 0 0 0 0 0 0 0 0
41149- 0 0 0 0 0 0 0 0 0 0 0 0
41150- 0 0 0 0 0 0 0 0 0 0 0 0
41151- 0 0 0 0 0 0 0 0 0 0 0 0
41152- 0 0 0 0 0 0 0 0 0 0 0 0
41153- 0 0 0 0 0 0 0 0 0 0 0 0
41154- 0 0 0 0 0 0 0 0 0 0 0 0
41155- 0 0 0 0 0 0 0 0 0 0 0 0
41156- 0 0 0 0 0 0 0 0 0 0 0 0
41157- 0 0 0 0 0 0 0 0 0 0 0 0
41158- 0 0 0 0 0 0 0 0 0 6 6 6
41159- 22 22 22 62 62 62 62 62 62 2 2 6
41160- 2 2 6 2 2 6 2 2 6 2 2 6
41161- 2 2 6 2 2 6 2 2 6 2 2 6
41162- 2 2 6 2 2 6 2 2 6 26 26 26
41163- 54 54 54 38 38 38 18 18 18 10 10 10
41164- 2 2 6 2 2 6 34 34 34 82 82 82
41165- 38 38 38 14 14 14 0 0 0 0 0 0
41166- 0 0 0 0 0 0 0 0 0 0 0 0
41167- 0 0 0 0 0 0 0 0 0 0 0 0
41168- 0 0 0 0 0 0 0 0 0 0 0 0
41169- 0 0 0 0 0 0 0 0 0 0 0 0
41170- 0 0 0 0 0 0 0 0 0 0 0 0
41171- 0 0 0 0 0 0 0 0 0 0 0 0
41172- 0 0 0 0 0 0 0 0 0 0 0 0
41173- 0 0 0 0 0 1 0 0 1 0 0 0
41174- 0 0 0 0 0 0 0 0 0 0 0 0
41175- 0 0 0 0 0 0 0 0 0 0 0 0
41176- 0 0 0 0 0 0 0 0 0 0 0 0
41177- 0 0 0 0 0 0 0 0 0 0 0 0
41178- 0 0 0 0 0 0 0 0 0 6 6 6
41179- 30 30 30 78 78 78 30 30 30 2 2 6
41180- 2 2 6 2 2 6 2 2 6 2 2 6
41181- 2 2 6 2 2 6 2 2 6 2 2 6
41182- 2 2 6 2 2 6 2 2 6 10 10 10
41183- 10 10 10 2 2 6 2 2 6 2 2 6
41184- 2 2 6 2 2 6 2 2 6 78 78 78
41185- 50 50 50 18 18 18 6 6 6 0 0 0
41186- 0 0 0 0 0 0 0 0 0 0 0 0
41187- 0 0 0 0 0 0 0 0 0 0 0 0
41188- 0 0 0 0 0 0 0 0 0 0 0 0
41189- 0 0 0 0 0 0 0 0 0 0 0 0
41190- 0 0 0 0 0 0 0 0 0 0 0 0
41191- 0 0 0 0 0 0 0 0 0 0 0 0
41192- 0 0 0 0 0 0 0 0 0 0 0 0
41193- 0 0 1 0 0 0 0 0 0 0 0 0
41194- 0 0 0 0 0 0 0 0 0 0 0 0
41195- 0 0 0 0 0 0 0 0 0 0 0 0
41196- 0 0 0 0 0 0 0 0 0 0 0 0
41197- 0 0 0 0 0 0 0 0 0 0 0 0
41198- 0 0 0 0 0 0 0 0 0 10 10 10
41199- 38 38 38 86 86 86 14 14 14 2 2 6
41200- 2 2 6 2 2 6 2 2 6 2 2 6
41201- 2 2 6 2 2 6 2 2 6 2 2 6
41202- 2 2 6 2 2 6 2 2 6 2 2 6
41203- 2 2 6 2 2 6 2 2 6 2 2 6
41204- 2 2 6 2 2 6 2 2 6 54 54 54
41205- 66 66 66 26 26 26 6 6 6 0 0 0
41206- 0 0 0 0 0 0 0 0 0 0 0 0
41207- 0 0 0 0 0 0 0 0 0 0 0 0
41208- 0 0 0 0 0 0 0 0 0 0 0 0
41209- 0 0 0 0 0 0 0 0 0 0 0 0
41210- 0 0 0 0 0 0 0 0 0 0 0 0
41211- 0 0 0 0 0 0 0 0 0 0 0 0
41212- 0 0 0 0 0 0 0 0 0 0 0 0
41213- 0 0 0 0 0 1 0 0 1 0 0 0
41214- 0 0 0 0 0 0 0 0 0 0 0 0
41215- 0 0 0 0 0 0 0 0 0 0 0 0
41216- 0 0 0 0 0 0 0 0 0 0 0 0
41217- 0 0 0 0 0 0 0 0 0 0 0 0
41218- 0 0 0 0 0 0 0 0 0 14 14 14
41219- 42 42 42 82 82 82 2 2 6 2 2 6
41220- 2 2 6 6 6 6 10 10 10 2 2 6
41221- 2 2 6 2 2 6 2 2 6 2 2 6
41222- 2 2 6 2 2 6 2 2 6 6 6 6
41223- 14 14 14 10 10 10 2 2 6 2 2 6
41224- 2 2 6 2 2 6 2 2 6 18 18 18
41225- 82 82 82 34 34 34 10 10 10 0 0 0
41226- 0 0 0 0 0 0 0 0 0 0 0 0
41227- 0 0 0 0 0 0 0 0 0 0 0 0
41228- 0 0 0 0 0 0 0 0 0 0 0 0
41229- 0 0 0 0 0 0 0 0 0 0 0 0
41230- 0 0 0 0 0 0 0 0 0 0 0 0
41231- 0 0 0 0 0 0 0 0 0 0 0 0
41232- 0 0 0 0 0 0 0 0 0 0 0 0
41233- 0 0 1 0 0 0 0 0 0 0 0 0
41234- 0 0 0 0 0 0 0 0 0 0 0 0
41235- 0 0 0 0 0 0 0 0 0 0 0 0
41236- 0 0 0 0 0 0 0 0 0 0 0 0
41237- 0 0 0 0 0 0 0 0 0 0 0 0
41238- 0 0 0 0 0 0 0 0 0 14 14 14
41239- 46 46 46 86 86 86 2 2 6 2 2 6
41240- 6 6 6 6 6 6 22 22 22 34 34 34
41241- 6 6 6 2 2 6 2 2 6 2 2 6
41242- 2 2 6 2 2 6 18 18 18 34 34 34
41243- 10 10 10 50 50 50 22 22 22 2 2 6
41244- 2 2 6 2 2 6 2 2 6 10 10 10
41245- 86 86 86 42 42 42 14 14 14 0 0 0
41246- 0 0 0 0 0 0 0 0 0 0 0 0
41247- 0 0 0 0 0 0 0 0 0 0 0 0
41248- 0 0 0 0 0 0 0 0 0 0 0 0
41249- 0 0 0 0 0 0 0 0 0 0 0 0
41250- 0 0 0 0 0 0 0 0 0 0 0 0
41251- 0 0 0 0 0 0 0 0 0 0 0 0
41252- 0 0 0 0 0 0 0 0 0 0 0 0
41253- 0 0 1 0 0 1 0 0 1 0 0 0
41254- 0 0 0 0 0 0 0 0 0 0 0 0
41255- 0 0 0 0 0 0 0 0 0 0 0 0
41256- 0 0 0 0 0 0 0 0 0 0 0 0
41257- 0 0 0 0 0 0 0 0 0 0 0 0
41258- 0 0 0 0 0 0 0 0 0 14 14 14
41259- 46 46 46 86 86 86 2 2 6 2 2 6
41260- 38 38 38 116 116 116 94 94 94 22 22 22
41261- 22 22 22 2 2 6 2 2 6 2 2 6
41262- 14 14 14 86 86 86 138 138 138 162 162 162
41263-154 154 154 38 38 38 26 26 26 6 6 6
41264- 2 2 6 2 2 6 2 2 6 2 2 6
41265- 86 86 86 46 46 46 14 14 14 0 0 0
41266- 0 0 0 0 0 0 0 0 0 0 0 0
41267- 0 0 0 0 0 0 0 0 0 0 0 0
41268- 0 0 0 0 0 0 0 0 0 0 0 0
41269- 0 0 0 0 0 0 0 0 0 0 0 0
41270- 0 0 0 0 0 0 0 0 0 0 0 0
41271- 0 0 0 0 0 0 0 0 0 0 0 0
41272- 0 0 0 0 0 0 0 0 0 0 0 0
41273- 0 0 0 0 0 0 0 0 0 0 0 0
41274- 0 0 0 0 0 0 0 0 0 0 0 0
41275- 0 0 0 0 0 0 0 0 0 0 0 0
41276- 0 0 0 0 0 0 0 0 0 0 0 0
41277- 0 0 0 0 0 0 0 0 0 0 0 0
41278- 0 0 0 0 0 0 0 0 0 14 14 14
41279- 46 46 46 86 86 86 2 2 6 14 14 14
41280-134 134 134 198 198 198 195 195 195 116 116 116
41281- 10 10 10 2 2 6 2 2 6 6 6 6
41282-101 98 89 187 187 187 210 210 210 218 218 218
41283-214 214 214 134 134 134 14 14 14 6 6 6
41284- 2 2 6 2 2 6 2 2 6 2 2 6
41285- 86 86 86 50 50 50 18 18 18 6 6 6
41286- 0 0 0 0 0 0 0 0 0 0 0 0
41287- 0 0 0 0 0 0 0 0 0 0 0 0
41288- 0 0 0 0 0 0 0 0 0 0 0 0
41289- 0 0 0 0 0 0 0 0 0 0 0 0
41290- 0 0 0 0 0 0 0 0 0 0 0 0
41291- 0 0 0 0 0 0 0 0 0 0 0 0
41292- 0 0 0 0 0 0 0 0 1 0 0 0
41293- 0 0 1 0 0 1 0 0 1 0 0 0
41294- 0 0 0 0 0 0 0 0 0 0 0 0
41295- 0 0 0 0 0 0 0 0 0 0 0 0
41296- 0 0 0 0 0 0 0 0 0 0 0 0
41297- 0 0 0 0 0 0 0 0 0 0 0 0
41298- 0 0 0 0 0 0 0 0 0 14 14 14
41299- 46 46 46 86 86 86 2 2 6 54 54 54
41300-218 218 218 195 195 195 226 226 226 246 246 246
41301- 58 58 58 2 2 6 2 2 6 30 30 30
41302-210 210 210 253 253 253 174 174 174 123 123 123
41303-221 221 221 234 234 234 74 74 74 2 2 6
41304- 2 2 6 2 2 6 2 2 6 2 2 6
41305- 70 70 70 58 58 58 22 22 22 6 6 6
41306- 0 0 0 0 0 0 0 0 0 0 0 0
41307- 0 0 0 0 0 0 0 0 0 0 0 0
41308- 0 0 0 0 0 0 0 0 0 0 0 0
41309- 0 0 0 0 0 0 0 0 0 0 0 0
41310- 0 0 0 0 0 0 0 0 0 0 0 0
41311- 0 0 0 0 0 0 0 0 0 0 0 0
41312- 0 0 0 0 0 0 0 0 0 0 0 0
41313- 0 0 0 0 0 0 0 0 0 0 0 0
41314- 0 0 0 0 0 0 0 0 0 0 0 0
41315- 0 0 0 0 0 0 0 0 0 0 0 0
41316- 0 0 0 0 0 0 0 0 0 0 0 0
41317- 0 0 0 0 0 0 0 0 0 0 0 0
41318- 0 0 0 0 0 0 0 0 0 14 14 14
41319- 46 46 46 82 82 82 2 2 6 106 106 106
41320-170 170 170 26 26 26 86 86 86 226 226 226
41321-123 123 123 10 10 10 14 14 14 46 46 46
41322-231 231 231 190 190 190 6 6 6 70 70 70
41323- 90 90 90 238 238 238 158 158 158 2 2 6
41324- 2 2 6 2 2 6 2 2 6 2 2 6
41325- 70 70 70 58 58 58 22 22 22 6 6 6
41326- 0 0 0 0 0 0 0 0 0 0 0 0
41327- 0 0 0 0 0 0 0 0 0 0 0 0
41328- 0 0 0 0 0 0 0 0 0 0 0 0
41329- 0 0 0 0 0 0 0 0 0 0 0 0
41330- 0 0 0 0 0 0 0 0 0 0 0 0
41331- 0 0 0 0 0 0 0 0 0 0 0 0
41332- 0 0 0 0 0 0 0 0 1 0 0 0
41333- 0 0 1 0 0 1 0 0 1 0 0 0
41334- 0 0 0 0 0 0 0 0 0 0 0 0
41335- 0 0 0 0 0 0 0 0 0 0 0 0
41336- 0 0 0 0 0 0 0 0 0 0 0 0
41337- 0 0 0 0 0 0 0 0 0 0 0 0
41338- 0 0 0 0 0 0 0 0 0 14 14 14
41339- 42 42 42 86 86 86 6 6 6 116 116 116
41340-106 106 106 6 6 6 70 70 70 149 149 149
41341-128 128 128 18 18 18 38 38 38 54 54 54
41342-221 221 221 106 106 106 2 2 6 14 14 14
41343- 46 46 46 190 190 190 198 198 198 2 2 6
41344- 2 2 6 2 2 6 2 2 6 2 2 6
41345- 74 74 74 62 62 62 22 22 22 6 6 6
41346- 0 0 0 0 0 0 0 0 0 0 0 0
41347- 0 0 0 0 0 0 0 0 0 0 0 0
41348- 0 0 0 0 0 0 0 0 0 0 0 0
41349- 0 0 0 0 0 0 0 0 0 0 0 0
41350- 0 0 0 0 0 0 0 0 0 0 0 0
41351- 0 0 0 0 0 0 0 0 0 0 0 0
41352- 0 0 0 0 0 0 0 0 1 0 0 0
41353- 0 0 1 0 0 0 0 0 1 0 0 0
41354- 0 0 0 0 0 0 0 0 0 0 0 0
41355- 0 0 0 0 0 0 0 0 0 0 0 0
41356- 0 0 0 0 0 0 0 0 0 0 0 0
41357- 0 0 0 0 0 0 0 0 0 0 0 0
41358- 0 0 0 0 0 0 0 0 0 14 14 14
41359- 42 42 42 94 94 94 14 14 14 101 101 101
41360-128 128 128 2 2 6 18 18 18 116 116 116
41361-118 98 46 121 92 8 121 92 8 98 78 10
41362-162 162 162 106 106 106 2 2 6 2 2 6
41363- 2 2 6 195 195 195 195 195 195 6 6 6
41364- 2 2 6 2 2 6 2 2 6 2 2 6
41365- 74 74 74 62 62 62 22 22 22 6 6 6
41366- 0 0 0 0 0 0 0 0 0 0 0 0
41367- 0 0 0 0 0 0 0 0 0 0 0 0
41368- 0 0 0 0 0 0 0 0 0 0 0 0
41369- 0 0 0 0 0 0 0 0 0 0 0 0
41370- 0 0 0 0 0 0 0 0 0 0 0 0
41371- 0 0 0 0 0 0 0 0 0 0 0 0
41372- 0 0 0 0 0 0 0 0 1 0 0 1
41373- 0 0 1 0 0 0 0 0 1 0 0 0
41374- 0 0 0 0 0 0 0 0 0 0 0 0
41375- 0 0 0 0 0 0 0 0 0 0 0 0
41376- 0 0 0 0 0 0 0 0 0 0 0 0
41377- 0 0 0 0 0 0 0 0 0 0 0 0
41378- 0 0 0 0 0 0 0 0 0 10 10 10
41379- 38 38 38 90 90 90 14 14 14 58 58 58
41380-210 210 210 26 26 26 54 38 6 154 114 10
41381-226 170 11 236 186 11 225 175 15 184 144 12
41382-215 174 15 175 146 61 37 26 9 2 2 6
41383- 70 70 70 246 246 246 138 138 138 2 2 6
41384- 2 2 6 2 2 6 2 2 6 2 2 6
41385- 70 70 70 66 66 66 26 26 26 6 6 6
41386- 0 0 0 0 0 0 0 0 0 0 0 0
41387- 0 0 0 0 0 0 0 0 0 0 0 0
41388- 0 0 0 0 0 0 0 0 0 0 0 0
41389- 0 0 0 0 0 0 0 0 0 0 0 0
41390- 0 0 0 0 0 0 0 0 0 0 0 0
41391- 0 0 0 0 0 0 0 0 0 0 0 0
41392- 0 0 0 0 0 0 0 0 0 0 0 0
41393- 0 0 0 0 0 0 0 0 0 0 0 0
41394- 0 0 0 0 0 0 0 0 0 0 0 0
41395- 0 0 0 0 0 0 0 0 0 0 0 0
41396- 0 0 0 0 0 0 0 0 0 0 0 0
41397- 0 0 0 0 0 0 0 0 0 0 0 0
41398- 0 0 0 0 0 0 0 0 0 10 10 10
41399- 38 38 38 86 86 86 14 14 14 10 10 10
41400-195 195 195 188 164 115 192 133 9 225 175 15
41401-239 182 13 234 190 10 232 195 16 232 200 30
41402-245 207 45 241 208 19 232 195 16 184 144 12
41403-218 194 134 211 206 186 42 42 42 2 2 6
41404- 2 2 6 2 2 6 2 2 6 2 2 6
41405- 50 50 50 74 74 74 30 30 30 6 6 6
41406- 0 0 0 0 0 0 0 0 0 0 0 0
41407- 0 0 0 0 0 0 0 0 0 0 0 0
41408- 0 0 0 0 0 0 0 0 0 0 0 0
41409- 0 0 0 0 0 0 0 0 0 0 0 0
41410- 0 0 0 0 0 0 0 0 0 0 0 0
41411- 0 0 0 0 0 0 0 0 0 0 0 0
41412- 0 0 0 0 0 0 0 0 0 0 0 0
41413- 0 0 0 0 0 0 0 0 0 0 0 0
41414- 0 0 0 0 0 0 0 0 0 0 0 0
41415- 0 0 0 0 0 0 0 0 0 0 0 0
41416- 0 0 0 0 0 0 0 0 0 0 0 0
41417- 0 0 0 0 0 0 0 0 0 0 0 0
41418- 0 0 0 0 0 0 0 0 0 10 10 10
41419- 34 34 34 86 86 86 14 14 14 2 2 6
41420-121 87 25 192 133 9 219 162 10 239 182 13
41421-236 186 11 232 195 16 241 208 19 244 214 54
41422-246 218 60 246 218 38 246 215 20 241 208 19
41423-241 208 19 226 184 13 121 87 25 2 2 6
41424- 2 2 6 2 2 6 2 2 6 2 2 6
41425- 50 50 50 82 82 82 34 34 34 10 10 10
41426- 0 0 0 0 0 0 0 0 0 0 0 0
41427- 0 0 0 0 0 0 0 0 0 0 0 0
41428- 0 0 0 0 0 0 0 0 0 0 0 0
41429- 0 0 0 0 0 0 0 0 0 0 0 0
41430- 0 0 0 0 0 0 0 0 0 0 0 0
41431- 0 0 0 0 0 0 0 0 0 0 0 0
41432- 0 0 0 0 0 0 0 0 0 0 0 0
41433- 0 0 0 0 0 0 0 0 0 0 0 0
41434- 0 0 0 0 0 0 0 0 0 0 0 0
41435- 0 0 0 0 0 0 0 0 0 0 0 0
41436- 0 0 0 0 0 0 0 0 0 0 0 0
41437- 0 0 0 0 0 0 0 0 0 0 0 0
41438- 0 0 0 0 0 0 0 0 0 10 10 10
41439- 34 34 34 82 82 82 30 30 30 61 42 6
41440-180 123 7 206 145 10 230 174 11 239 182 13
41441-234 190 10 238 202 15 241 208 19 246 218 74
41442-246 218 38 246 215 20 246 215 20 246 215 20
41443-226 184 13 215 174 15 184 144 12 6 6 6
41444- 2 2 6 2 2 6 2 2 6 2 2 6
41445- 26 26 26 94 94 94 42 42 42 14 14 14
41446- 0 0 0 0 0 0 0 0 0 0 0 0
41447- 0 0 0 0 0 0 0 0 0 0 0 0
41448- 0 0 0 0 0 0 0 0 0 0 0 0
41449- 0 0 0 0 0 0 0 0 0 0 0 0
41450- 0 0 0 0 0 0 0 0 0 0 0 0
41451- 0 0 0 0 0 0 0 0 0 0 0 0
41452- 0 0 0 0 0 0 0 0 0 0 0 0
41453- 0 0 0 0 0 0 0 0 0 0 0 0
41454- 0 0 0 0 0 0 0 0 0 0 0 0
41455- 0 0 0 0 0 0 0 0 0 0 0 0
41456- 0 0 0 0 0 0 0 0 0 0 0 0
41457- 0 0 0 0 0 0 0 0 0 0 0 0
41458- 0 0 0 0 0 0 0 0 0 10 10 10
41459- 30 30 30 78 78 78 50 50 50 104 69 6
41460-192 133 9 216 158 10 236 178 12 236 186 11
41461-232 195 16 241 208 19 244 214 54 245 215 43
41462-246 215 20 246 215 20 241 208 19 198 155 10
41463-200 144 11 216 158 10 156 118 10 2 2 6
41464- 2 2 6 2 2 6 2 2 6 2 2 6
41465- 6 6 6 90 90 90 54 54 54 18 18 18
41466- 6 6 6 0 0 0 0 0 0 0 0 0
41467- 0 0 0 0 0 0 0 0 0 0 0 0
41468- 0 0 0 0 0 0 0 0 0 0 0 0
41469- 0 0 0 0 0 0 0 0 0 0 0 0
41470- 0 0 0 0 0 0 0 0 0 0 0 0
41471- 0 0 0 0 0 0 0 0 0 0 0 0
41472- 0 0 0 0 0 0 0 0 0 0 0 0
41473- 0 0 0 0 0 0 0 0 0 0 0 0
41474- 0 0 0 0 0 0 0 0 0 0 0 0
41475- 0 0 0 0 0 0 0 0 0 0 0 0
41476- 0 0 0 0 0 0 0 0 0 0 0 0
41477- 0 0 0 0 0 0 0 0 0 0 0 0
41478- 0 0 0 0 0 0 0 0 0 10 10 10
41479- 30 30 30 78 78 78 46 46 46 22 22 22
41480-137 92 6 210 162 10 239 182 13 238 190 10
41481-238 202 15 241 208 19 246 215 20 246 215 20
41482-241 208 19 203 166 17 185 133 11 210 150 10
41483-216 158 10 210 150 10 102 78 10 2 2 6
41484- 6 6 6 54 54 54 14 14 14 2 2 6
41485- 2 2 6 62 62 62 74 74 74 30 30 30
41486- 10 10 10 0 0 0 0 0 0 0 0 0
41487- 0 0 0 0 0 0 0 0 0 0 0 0
41488- 0 0 0 0 0 0 0 0 0 0 0 0
41489- 0 0 0 0 0 0 0 0 0 0 0 0
41490- 0 0 0 0 0 0 0 0 0 0 0 0
41491- 0 0 0 0 0 0 0 0 0 0 0 0
41492- 0 0 0 0 0 0 0 0 0 0 0 0
41493- 0 0 0 0 0 0 0 0 0 0 0 0
41494- 0 0 0 0 0 0 0 0 0 0 0 0
41495- 0 0 0 0 0 0 0 0 0 0 0 0
41496- 0 0 0 0 0 0 0 0 0 0 0 0
41497- 0 0 0 0 0 0 0 0 0 0 0 0
41498- 0 0 0 0 0 0 0 0 0 10 10 10
41499- 34 34 34 78 78 78 50 50 50 6 6 6
41500- 94 70 30 139 102 15 190 146 13 226 184 13
41501-232 200 30 232 195 16 215 174 15 190 146 13
41502-168 122 10 192 133 9 210 150 10 213 154 11
41503-202 150 34 182 157 106 101 98 89 2 2 6
41504- 2 2 6 78 78 78 116 116 116 58 58 58
41505- 2 2 6 22 22 22 90 90 90 46 46 46
41506- 18 18 18 6 6 6 0 0 0 0 0 0
41507- 0 0 0 0 0 0 0 0 0 0 0 0
41508- 0 0 0 0 0 0 0 0 0 0 0 0
41509- 0 0 0 0 0 0 0 0 0 0 0 0
41510- 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 0 0 0
41515- 0 0 0 0 0 0 0 0 0 0 0 0
41516- 0 0 0 0 0 0 0 0 0 0 0 0
41517- 0 0 0 0 0 0 0 0 0 0 0 0
41518- 0 0 0 0 0 0 0 0 0 10 10 10
41519- 38 38 38 86 86 86 50 50 50 6 6 6
41520-128 128 128 174 154 114 156 107 11 168 122 10
41521-198 155 10 184 144 12 197 138 11 200 144 11
41522-206 145 10 206 145 10 197 138 11 188 164 115
41523-195 195 195 198 198 198 174 174 174 14 14 14
41524- 2 2 6 22 22 22 116 116 116 116 116 116
41525- 22 22 22 2 2 6 74 74 74 70 70 70
41526- 30 30 30 10 10 10 0 0 0 0 0 0
41527- 0 0 0 0 0 0 0 0 0 0 0 0
41528- 0 0 0 0 0 0 0 0 0 0 0 0
41529- 0 0 0 0 0 0 0 0 0 0 0 0
41530- 0 0 0 0 0 0 0 0 0 0 0 0
41531- 0 0 0 0 0 0 0 0 0 0 0 0
41532- 0 0 0 0 0 0 0 0 0 0 0 0
41533- 0 0 0 0 0 0 0 0 0 0 0 0
41534- 0 0 0 0 0 0 0 0 0 0 0 0
41535- 0 0 0 0 0 0 0 0 0 0 0 0
41536- 0 0 0 0 0 0 0 0 0 0 0 0
41537- 0 0 0 0 0 0 0 0 0 0 0 0
41538- 0 0 0 0 0 0 6 6 6 18 18 18
41539- 50 50 50 101 101 101 26 26 26 10 10 10
41540-138 138 138 190 190 190 174 154 114 156 107 11
41541-197 138 11 200 144 11 197 138 11 192 133 9
41542-180 123 7 190 142 34 190 178 144 187 187 187
41543-202 202 202 221 221 221 214 214 214 66 66 66
41544- 2 2 6 2 2 6 50 50 50 62 62 62
41545- 6 6 6 2 2 6 10 10 10 90 90 90
41546- 50 50 50 18 18 18 6 6 6 0 0 0
41547- 0 0 0 0 0 0 0 0 0 0 0 0
41548- 0 0 0 0 0 0 0 0 0 0 0 0
41549- 0 0 0 0 0 0 0 0 0 0 0 0
41550- 0 0 0 0 0 0 0 0 0 0 0 0
41551- 0 0 0 0 0 0 0 0 0 0 0 0
41552- 0 0 0 0 0 0 0 0 0 0 0 0
41553- 0 0 0 0 0 0 0 0 0 0 0 0
41554- 0 0 0 0 0 0 0 0 0 0 0 0
41555- 0 0 0 0 0 0 0 0 0 0 0 0
41556- 0 0 0 0 0 0 0 0 0 0 0 0
41557- 0 0 0 0 0 0 0 0 0 0 0 0
41558- 0 0 0 0 0 0 10 10 10 34 34 34
41559- 74 74 74 74 74 74 2 2 6 6 6 6
41560-144 144 144 198 198 198 190 190 190 178 166 146
41561-154 121 60 156 107 11 156 107 11 168 124 44
41562-174 154 114 187 187 187 190 190 190 210 210 210
41563-246 246 246 253 253 253 253 253 253 182 182 182
41564- 6 6 6 2 2 6 2 2 6 2 2 6
41565- 2 2 6 2 2 6 2 2 6 62 62 62
41566- 74 74 74 34 34 34 14 14 14 0 0 0
41567- 0 0 0 0 0 0 0 0 0 0 0 0
41568- 0 0 0 0 0 0 0 0 0 0 0 0
41569- 0 0 0 0 0 0 0 0 0 0 0 0
41570- 0 0 0 0 0 0 0 0 0 0 0 0
41571- 0 0 0 0 0 0 0 0 0 0 0 0
41572- 0 0 0 0 0 0 0 0 0 0 0 0
41573- 0 0 0 0 0 0 0 0 0 0 0 0
41574- 0 0 0 0 0 0 0 0 0 0 0 0
41575- 0 0 0 0 0 0 0 0 0 0 0 0
41576- 0 0 0 0 0 0 0 0 0 0 0 0
41577- 0 0 0 0 0 0 0 0 0 0 0 0
41578- 0 0 0 10 10 10 22 22 22 54 54 54
41579- 94 94 94 18 18 18 2 2 6 46 46 46
41580-234 234 234 221 221 221 190 190 190 190 190 190
41581-190 190 190 187 187 187 187 187 187 190 190 190
41582-190 190 190 195 195 195 214 214 214 242 242 242
41583-253 253 253 253 253 253 253 253 253 253 253 253
41584- 82 82 82 2 2 6 2 2 6 2 2 6
41585- 2 2 6 2 2 6 2 2 6 14 14 14
41586- 86 86 86 54 54 54 22 22 22 6 6 6
41587- 0 0 0 0 0 0 0 0 0 0 0 0
41588- 0 0 0 0 0 0 0 0 0 0 0 0
41589- 0 0 0 0 0 0 0 0 0 0 0 0
41590- 0 0 0 0 0 0 0 0 0 0 0 0
41591- 0 0 0 0 0 0 0 0 0 0 0 0
41592- 0 0 0 0 0 0 0 0 0 0 0 0
41593- 0 0 0 0 0 0 0 0 0 0 0 0
41594- 0 0 0 0 0 0 0 0 0 0 0 0
41595- 0 0 0 0 0 0 0 0 0 0 0 0
41596- 0 0 0 0 0 0 0 0 0 0 0 0
41597- 0 0 0 0 0 0 0 0 0 0 0 0
41598- 6 6 6 18 18 18 46 46 46 90 90 90
41599- 46 46 46 18 18 18 6 6 6 182 182 182
41600-253 253 253 246 246 246 206 206 206 190 190 190
41601-190 190 190 190 190 190 190 190 190 190 190 190
41602-206 206 206 231 231 231 250 250 250 253 253 253
41603-253 253 253 253 253 253 253 253 253 253 253 253
41604-202 202 202 14 14 14 2 2 6 2 2 6
41605- 2 2 6 2 2 6 2 2 6 2 2 6
41606- 42 42 42 86 86 86 42 42 42 18 18 18
41607- 6 6 6 0 0 0 0 0 0 0 0 0
41608- 0 0 0 0 0 0 0 0 0 0 0 0
41609- 0 0 0 0 0 0 0 0 0 0 0 0
41610- 0 0 0 0 0 0 0 0 0 0 0 0
41611- 0 0 0 0 0 0 0 0 0 0 0 0
41612- 0 0 0 0 0 0 0 0 0 0 0 0
41613- 0 0 0 0 0 0 0 0 0 0 0 0
41614- 0 0 0 0 0 0 0 0 0 0 0 0
41615- 0 0 0 0 0 0 0 0 0 0 0 0
41616- 0 0 0 0 0 0 0 0 0 0 0 0
41617- 0 0 0 0 0 0 0 0 0 6 6 6
41618- 14 14 14 38 38 38 74 74 74 66 66 66
41619- 2 2 6 6 6 6 90 90 90 250 250 250
41620-253 253 253 253 253 253 238 238 238 198 198 198
41621-190 190 190 190 190 190 195 195 195 221 221 221
41622-246 246 246 253 253 253 253 253 253 253 253 253
41623-253 253 253 253 253 253 253 253 253 253 253 253
41624-253 253 253 82 82 82 2 2 6 2 2 6
41625- 2 2 6 2 2 6 2 2 6 2 2 6
41626- 2 2 6 78 78 78 70 70 70 34 34 34
41627- 14 14 14 6 6 6 0 0 0 0 0 0
41628- 0 0 0 0 0 0 0 0 0 0 0 0
41629- 0 0 0 0 0 0 0 0 0 0 0 0
41630- 0 0 0 0 0 0 0 0 0 0 0 0
41631- 0 0 0 0 0 0 0 0 0 0 0 0
41632- 0 0 0 0 0 0 0 0 0 0 0 0
41633- 0 0 0 0 0 0 0 0 0 0 0 0
41634- 0 0 0 0 0 0 0 0 0 0 0 0
41635- 0 0 0 0 0 0 0 0 0 0 0 0
41636- 0 0 0 0 0 0 0 0 0 0 0 0
41637- 0 0 0 0 0 0 0 0 0 14 14 14
41638- 34 34 34 66 66 66 78 78 78 6 6 6
41639- 2 2 6 18 18 18 218 218 218 253 253 253
41640-253 253 253 253 253 253 253 253 253 246 246 246
41641-226 226 226 231 231 231 246 246 246 253 253 253
41642-253 253 253 253 253 253 253 253 253 253 253 253
41643-253 253 253 253 253 253 253 253 253 253 253 253
41644-253 253 253 178 178 178 2 2 6 2 2 6
41645- 2 2 6 2 2 6 2 2 6 2 2 6
41646- 2 2 6 18 18 18 90 90 90 62 62 62
41647- 30 30 30 10 10 10 0 0 0 0 0 0
41648- 0 0 0 0 0 0 0 0 0 0 0 0
41649- 0 0 0 0 0 0 0 0 0 0 0 0
41650- 0 0 0 0 0 0 0 0 0 0 0 0
41651- 0 0 0 0 0 0 0 0 0 0 0 0
41652- 0 0 0 0 0 0 0 0 0 0 0 0
41653- 0 0 0 0 0 0 0 0 0 0 0 0
41654- 0 0 0 0 0 0 0 0 0 0 0 0
41655- 0 0 0 0 0 0 0 0 0 0 0 0
41656- 0 0 0 0 0 0 0 0 0 0 0 0
41657- 0 0 0 0 0 0 10 10 10 26 26 26
41658- 58 58 58 90 90 90 18 18 18 2 2 6
41659- 2 2 6 110 110 110 253 253 253 253 253 253
41660-253 253 253 253 253 253 253 253 253 253 253 253
41661-250 250 250 253 253 253 253 253 253 253 253 253
41662-253 253 253 253 253 253 253 253 253 253 253 253
41663-253 253 253 253 253 253 253 253 253 253 253 253
41664-253 253 253 231 231 231 18 18 18 2 2 6
41665- 2 2 6 2 2 6 2 2 6 2 2 6
41666- 2 2 6 2 2 6 18 18 18 94 94 94
41667- 54 54 54 26 26 26 10 10 10 0 0 0
41668- 0 0 0 0 0 0 0 0 0 0 0 0
41669- 0 0 0 0 0 0 0 0 0 0 0 0
41670- 0 0 0 0 0 0 0 0 0 0 0 0
41671- 0 0 0 0 0 0 0 0 0 0 0 0
41672- 0 0 0 0 0 0 0 0 0 0 0 0
41673- 0 0 0 0 0 0 0 0 0 0 0 0
41674- 0 0 0 0 0 0 0 0 0 0 0 0
41675- 0 0 0 0 0 0 0 0 0 0 0 0
41676- 0 0 0 0 0 0 0 0 0 0 0 0
41677- 0 0 0 6 6 6 22 22 22 50 50 50
41678- 90 90 90 26 26 26 2 2 6 2 2 6
41679- 14 14 14 195 195 195 250 250 250 253 253 253
41680-253 253 253 253 253 253 253 253 253 253 253 253
41681-253 253 253 253 253 253 253 253 253 253 253 253
41682-253 253 253 253 253 253 253 253 253 253 253 253
41683-253 253 253 253 253 253 253 253 253 253 253 253
41684-250 250 250 242 242 242 54 54 54 2 2 6
41685- 2 2 6 2 2 6 2 2 6 2 2 6
41686- 2 2 6 2 2 6 2 2 6 38 38 38
41687- 86 86 86 50 50 50 22 22 22 6 6 6
41688- 0 0 0 0 0 0 0 0 0 0 0 0
41689- 0 0 0 0 0 0 0 0 0 0 0 0
41690- 0 0 0 0 0 0 0 0 0 0 0 0
41691- 0 0 0 0 0 0 0 0 0 0 0 0
41692- 0 0 0 0 0 0 0 0 0 0 0 0
41693- 0 0 0 0 0 0 0 0 0 0 0 0
41694- 0 0 0 0 0 0 0 0 0 0 0 0
41695- 0 0 0 0 0 0 0 0 0 0 0 0
41696- 0 0 0 0 0 0 0 0 0 0 0 0
41697- 6 6 6 14 14 14 38 38 38 82 82 82
41698- 34 34 34 2 2 6 2 2 6 2 2 6
41699- 42 42 42 195 195 195 246 246 246 253 253 253
41700-253 253 253 253 253 253 253 253 253 250 250 250
41701-242 242 242 242 242 242 250 250 250 253 253 253
41702-253 253 253 253 253 253 253 253 253 253 253 253
41703-253 253 253 250 250 250 246 246 246 238 238 238
41704-226 226 226 231 231 231 101 101 101 6 6 6
41705- 2 2 6 2 2 6 2 2 6 2 2 6
41706- 2 2 6 2 2 6 2 2 6 2 2 6
41707- 38 38 38 82 82 82 42 42 42 14 14 14
41708- 6 6 6 0 0 0 0 0 0 0 0 0
41709- 0 0 0 0 0 0 0 0 0 0 0 0
41710- 0 0 0 0 0 0 0 0 0 0 0 0
41711- 0 0 0 0 0 0 0 0 0 0 0 0
41712- 0 0 0 0 0 0 0 0 0 0 0 0
41713- 0 0 0 0 0 0 0 0 0 0 0 0
41714- 0 0 0 0 0 0 0 0 0 0 0 0
41715- 0 0 0 0 0 0 0 0 0 0 0 0
41716- 0 0 0 0 0 0 0 0 0 0 0 0
41717- 10 10 10 26 26 26 62 62 62 66 66 66
41718- 2 2 6 2 2 6 2 2 6 6 6 6
41719- 70 70 70 170 170 170 206 206 206 234 234 234
41720-246 246 246 250 250 250 250 250 250 238 238 238
41721-226 226 226 231 231 231 238 238 238 250 250 250
41722-250 250 250 250 250 250 246 246 246 231 231 231
41723-214 214 214 206 206 206 202 202 202 202 202 202
41724-198 198 198 202 202 202 182 182 182 18 18 18
41725- 2 2 6 2 2 6 2 2 6 2 2 6
41726- 2 2 6 2 2 6 2 2 6 2 2 6
41727- 2 2 6 62 62 62 66 66 66 30 30 30
41728- 10 10 10 0 0 0 0 0 0 0 0 0
41729- 0 0 0 0 0 0 0 0 0 0 0 0
41730- 0 0 0 0 0 0 0 0 0 0 0 0
41731- 0 0 0 0 0 0 0 0 0 0 0 0
41732- 0 0 0 0 0 0 0 0 0 0 0 0
41733- 0 0 0 0 0 0 0 0 0 0 0 0
41734- 0 0 0 0 0 0 0 0 0 0 0 0
41735- 0 0 0 0 0 0 0 0 0 0 0 0
41736- 0 0 0 0 0 0 0 0 0 0 0 0
41737- 14 14 14 42 42 42 82 82 82 18 18 18
41738- 2 2 6 2 2 6 2 2 6 10 10 10
41739- 94 94 94 182 182 182 218 218 218 242 242 242
41740-250 250 250 253 253 253 253 253 253 250 250 250
41741-234 234 234 253 253 253 253 253 253 253 253 253
41742-253 253 253 253 253 253 253 253 253 246 246 246
41743-238 238 238 226 226 226 210 210 210 202 202 202
41744-195 195 195 195 195 195 210 210 210 158 158 158
41745- 6 6 6 14 14 14 50 50 50 14 14 14
41746- 2 2 6 2 2 6 2 2 6 2 2 6
41747- 2 2 6 6 6 6 86 86 86 46 46 46
41748- 18 18 18 6 6 6 0 0 0 0 0 0
41749- 0 0 0 0 0 0 0 0 0 0 0 0
41750- 0 0 0 0 0 0 0 0 0 0 0 0
41751- 0 0 0 0 0 0 0 0 0 0 0 0
41752- 0 0 0 0 0 0 0 0 0 0 0 0
41753- 0 0 0 0 0 0 0 0 0 0 0 0
41754- 0 0 0 0 0 0 0 0 0 0 0 0
41755- 0 0 0 0 0 0 0 0 0 0 0 0
41756- 0 0 0 0 0 0 0 0 0 6 6 6
41757- 22 22 22 54 54 54 70 70 70 2 2 6
41758- 2 2 6 10 10 10 2 2 6 22 22 22
41759-166 166 166 231 231 231 250 250 250 253 253 253
41760-253 253 253 253 253 253 253 253 253 250 250 250
41761-242 242 242 253 253 253 253 253 253 253 253 253
41762-253 253 253 253 253 253 253 253 253 253 253 253
41763-253 253 253 253 253 253 253 253 253 246 246 246
41764-231 231 231 206 206 206 198 198 198 226 226 226
41765- 94 94 94 2 2 6 6 6 6 38 38 38
41766- 30 30 30 2 2 6 2 2 6 2 2 6
41767- 2 2 6 2 2 6 62 62 62 66 66 66
41768- 26 26 26 10 10 10 0 0 0 0 0 0
41769- 0 0 0 0 0 0 0 0 0 0 0 0
41770- 0 0 0 0 0 0 0 0 0 0 0 0
41771- 0 0 0 0 0 0 0 0 0 0 0 0
41772- 0 0 0 0 0 0 0 0 0 0 0 0
41773- 0 0 0 0 0 0 0 0 0 0 0 0
41774- 0 0 0 0 0 0 0 0 0 0 0 0
41775- 0 0 0 0 0 0 0 0 0 0 0 0
41776- 0 0 0 0 0 0 0 0 0 10 10 10
41777- 30 30 30 74 74 74 50 50 50 2 2 6
41778- 26 26 26 26 26 26 2 2 6 106 106 106
41779-238 238 238 253 253 253 253 253 253 253 253 253
41780-253 253 253 253 253 253 253 253 253 253 253 253
41781-253 253 253 253 253 253 253 253 253 253 253 253
41782-253 253 253 253 253 253 253 253 253 253 253 253
41783-253 253 253 253 253 253 253 253 253 253 253 253
41784-253 253 253 246 246 246 218 218 218 202 202 202
41785-210 210 210 14 14 14 2 2 6 2 2 6
41786- 30 30 30 22 22 22 2 2 6 2 2 6
41787- 2 2 6 2 2 6 18 18 18 86 86 86
41788- 42 42 42 14 14 14 0 0 0 0 0 0
41789- 0 0 0 0 0 0 0 0 0 0 0 0
41790- 0 0 0 0 0 0 0 0 0 0 0 0
41791- 0 0 0 0 0 0 0 0 0 0 0 0
41792- 0 0 0 0 0 0 0 0 0 0 0 0
41793- 0 0 0 0 0 0 0 0 0 0 0 0
41794- 0 0 0 0 0 0 0 0 0 0 0 0
41795- 0 0 0 0 0 0 0 0 0 0 0 0
41796- 0 0 0 0 0 0 0 0 0 14 14 14
41797- 42 42 42 90 90 90 22 22 22 2 2 6
41798- 42 42 42 2 2 6 18 18 18 218 218 218
41799-253 253 253 253 253 253 253 253 253 253 253 253
41800-253 253 253 253 253 253 253 253 253 253 253 253
41801-253 253 253 253 253 253 253 253 253 253 253 253
41802-253 253 253 253 253 253 253 253 253 253 253 253
41803-253 253 253 253 253 253 253 253 253 253 253 253
41804-253 253 253 253 253 253 250 250 250 221 221 221
41805-218 218 218 101 101 101 2 2 6 14 14 14
41806- 18 18 18 38 38 38 10 10 10 2 2 6
41807- 2 2 6 2 2 6 2 2 6 78 78 78
41808- 58 58 58 22 22 22 6 6 6 0 0 0
41809- 0 0 0 0 0 0 0 0 0 0 0 0
41810- 0 0 0 0 0 0 0 0 0 0 0 0
41811- 0 0 0 0 0 0 0 0 0 0 0 0
41812- 0 0 0 0 0 0 0 0 0 0 0 0
41813- 0 0 0 0 0 0 0 0 0 0 0 0
41814- 0 0 0 0 0 0 0 0 0 0 0 0
41815- 0 0 0 0 0 0 0 0 0 0 0 0
41816- 0 0 0 0 0 0 6 6 6 18 18 18
41817- 54 54 54 82 82 82 2 2 6 26 26 26
41818- 22 22 22 2 2 6 123 123 123 253 253 253
41819-253 253 253 253 253 253 253 253 253 253 253 253
41820-253 253 253 253 253 253 253 253 253 253 253 253
41821-253 253 253 253 253 253 253 253 253 253 253 253
41822-253 253 253 253 253 253 253 253 253 253 253 253
41823-253 253 253 253 253 253 253 253 253 253 253 253
41824-253 253 253 253 253 253 253 253 253 250 250 250
41825-238 238 238 198 198 198 6 6 6 38 38 38
41826- 58 58 58 26 26 26 38 38 38 2 2 6
41827- 2 2 6 2 2 6 2 2 6 46 46 46
41828- 78 78 78 30 30 30 10 10 10 0 0 0
41829- 0 0 0 0 0 0 0 0 0 0 0 0
41830- 0 0 0 0 0 0 0 0 0 0 0 0
41831- 0 0 0 0 0 0 0 0 0 0 0 0
41832- 0 0 0 0 0 0 0 0 0 0 0 0
41833- 0 0 0 0 0 0 0 0 0 0 0 0
41834- 0 0 0 0 0 0 0 0 0 0 0 0
41835- 0 0 0 0 0 0 0 0 0 0 0 0
41836- 0 0 0 0 0 0 10 10 10 30 30 30
41837- 74 74 74 58 58 58 2 2 6 42 42 42
41838- 2 2 6 22 22 22 231 231 231 253 253 253
41839-253 253 253 253 253 253 253 253 253 253 253 253
41840-253 253 253 253 253 253 253 253 253 250 250 250
41841-253 253 253 253 253 253 253 253 253 253 253 253
41842-253 253 253 253 253 253 253 253 253 253 253 253
41843-253 253 253 253 253 253 253 253 253 253 253 253
41844-253 253 253 253 253 253 253 253 253 253 253 253
41845-253 253 253 246 246 246 46 46 46 38 38 38
41846- 42 42 42 14 14 14 38 38 38 14 14 14
41847- 2 2 6 2 2 6 2 2 6 6 6 6
41848- 86 86 86 46 46 46 14 14 14 0 0 0
41849- 0 0 0 0 0 0 0 0 0 0 0 0
41850- 0 0 0 0 0 0 0 0 0 0 0 0
41851- 0 0 0 0 0 0 0 0 0 0 0 0
41852- 0 0 0 0 0 0 0 0 0 0 0 0
41853- 0 0 0 0 0 0 0 0 0 0 0 0
41854- 0 0 0 0 0 0 0 0 0 0 0 0
41855- 0 0 0 0 0 0 0 0 0 0 0 0
41856- 0 0 0 6 6 6 14 14 14 42 42 42
41857- 90 90 90 18 18 18 18 18 18 26 26 26
41858- 2 2 6 116 116 116 253 253 253 253 253 253
41859-253 253 253 253 253 253 253 253 253 253 253 253
41860-253 253 253 253 253 253 250 250 250 238 238 238
41861-253 253 253 253 253 253 253 253 253 253 253 253
41862-253 253 253 253 253 253 253 253 253 253 253 253
41863-253 253 253 253 253 253 253 253 253 253 253 253
41864-253 253 253 253 253 253 253 253 253 253 253 253
41865-253 253 253 253 253 253 94 94 94 6 6 6
41866- 2 2 6 2 2 6 10 10 10 34 34 34
41867- 2 2 6 2 2 6 2 2 6 2 2 6
41868- 74 74 74 58 58 58 22 22 22 6 6 6
41869- 0 0 0 0 0 0 0 0 0 0 0 0
41870- 0 0 0 0 0 0 0 0 0 0 0 0
41871- 0 0 0 0 0 0 0 0 0 0 0 0
41872- 0 0 0 0 0 0 0 0 0 0 0 0
41873- 0 0 0 0 0 0 0 0 0 0 0 0
41874- 0 0 0 0 0 0 0 0 0 0 0 0
41875- 0 0 0 0 0 0 0 0 0 0 0 0
41876- 0 0 0 10 10 10 26 26 26 66 66 66
41877- 82 82 82 2 2 6 38 38 38 6 6 6
41878- 14 14 14 210 210 210 253 253 253 253 253 253
41879-253 253 253 253 253 253 253 253 253 253 253 253
41880-253 253 253 253 253 253 246 246 246 242 242 242
41881-253 253 253 253 253 253 253 253 253 253 253 253
41882-253 253 253 253 253 253 253 253 253 253 253 253
41883-253 253 253 253 253 253 253 253 253 253 253 253
41884-253 253 253 253 253 253 253 253 253 253 253 253
41885-253 253 253 253 253 253 144 144 144 2 2 6
41886- 2 2 6 2 2 6 2 2 6 46 46 46
41887- 2 2 6 2 2 6 2 2 6 2 2 6
41888- 42 42 42 74 74 74 30 30 30 10 10 10
41889- 0 0 0 0 0 0 0 0 0 0 0 0
41890- 0 0 0 0 0 0 0 0 0 0 0 0
41891- 0 0 0 0 0 0 0 0 0 0 0 0
41892- 0 0 0 0 0 0 0 0 0 0 0 0
41893- 0 0 0 0 0 0 0 0 0 0 0 0
41894- 0 0 0 0 0 0 0 0 0 0 0 0
41895- 0 0 0 0 0 0 0 0 0 0 0 0
41896- 6 6 6 14 14 14 42 42 42 90 90 90
41897- 26 26 26 6 6 6 42 42 42 2 2 6
41898- 74 74 74 250 250 250 253 253 253 253 253 253
41899-253 253 253 253 253 253 253 253 253 253 253 253
41900-253 253 253 253 253 253 242 242 242 242 242 242
41901-253 253 253 253 253 253 253 253 253 253 253 253
41902-253 253 253 253 253 253 253 253 253 253 253 253
41903-253 253 253 253 253 253 253 253 253 253 253 253
41904-253 253 253 253 253 253 253 253 253 253 253 253
41905-253 253 253 253 253 253 182 182 182 2 2 6
41906- 2 2 6 2 2 6 2 2 6 46 46 46
41907- 2 2 6 2 2 6 2 2 6 2 2 6
41908- 10 10 10 86 86 86 38 38 38 10 10 10
41909- 0 0 0 0 0 0 0 0 0 0 0 0
41910- 0 0 0 0 0 0 0 0 0 0 0 0
41911- 0 0 0 0 0 0 0 0 0 0 0 0
41912- 0 0 0 0 0 0 0 0 0 0 0 0
41913- 0 0 0 0 0 0 0 0 0 0 0 0
41914- 0 0 0 0 0 0 0 0 0 0 0 0
41915- 0 0 0 0 0 0 0 0 0 0 0 0
41916- 10 10 10 26 26 26 66 66 66 82 82 82
41917- 2 2 6 22 22 22 18 18 18 2 2 6
41918-149 149 149 253 253 253 253 253 253 253 253 253
41919-253 253 253 253 253 253 253 253 253 253 253 253
41920-253 253 253 253 253 253 234 234 234 242 242 242
41921-253 253 253 253 253 253 253 253 253 253 253 253
41922-253 253 253 253 253 253 253 253 253 253 253 253
41923-253 253 253 253 253 253 253 253 253 253 253 253
41924-253 253 253 253 253 253 253 253 253 253 253 253
41925-253 253 253 253 253 253 206 206 206 2 2 6
41926- 2 2 6 2 2 6 2 2 6 38 38 38
41927- 2 2 6 2 2 6 2 2 6 2 2 6
41928- 6 6 6 86 86 86 46 46 46 14 14 14
41929- 0 0 0 0 0 0 0 0 0 0 0 0
41930- 0 0 0 0 0 0 0 0 0 0 0 0
41931- 0 0 0 0 0 0 0 0 0 0 0 0
41932- 0 0 0 0 0 0 0 0 0 0 0 0
41933- 0 0 0 0 0 0 0 0 0 0 0 0
41934- 0 0 0 0 0 0 0 0 0 0 0 0
41935- 0 0 0 0 0 0 0 0 0 6 6 6
41936- 18 18 18 46 46 46 86 86 86 18 18 18
41937- 2 2 6 34 34 34 10 10 10 6 6 6
41938-210 210 210 253 253 253 253 253 253 253 253 253
41939-253 253 253 253 253 253 253 253 253 253 253 253
41940-253 253 253 253 253 253 234 234 234 242 242 242
41941-253 253 253 253 253 253 253 253 253 253 253 253
41942-253 253 253 253 253 253 253 253 253 253 253 253
41943-253 253 253 253 253 253 253 253 253 253 253 253
41944-253 253 253 253 253 253 253 253 253 253 253 253
41945-253 253 253 253 253 253 221 221 221 6 6 6
41946- 2 2 6 2 2 6 6 6 6 30 30 30
41947- 2 2 6 2 2 6 2 2 6 2 2 6
41948- 2 2 6 82 82 82 54 54 54 18 18 18
41949- 6 6 6 0 0 0 0 0 0 0 0 0
41950- 0 0 0 0 0 0 0 0 0 0 0 0
41951- 0 0 0 0 0 0 0 0 0 0 0 0
41952- 0 0 0 0 0 0 0 0 0 0 0 0
41953- 0 0 0 0 0 0 0 0 0 0 0 0
41954- 0 0 0 0 0 0 0 0 0 0 0 0
41955- 0 0 0 0 0 0 0 0 0 10 10 10
41956- 26 26 26 66 66 66 62 62 62 2 2 6
41957- 2 2 6 38 38 38 10 10 10 26 26 26
41958-238 238 238 253 253 253 253 253 253 253 253 253
41959-253 253 253 253 253 253 253 253 253 253 253 253
41960-253 253 253 253 253 253 231 231 231 238 238 238
41961-253 253 253 253 253 253 253 253 253 253 253 253
41962-253 253 253 253 253 253 253 253 253 253 253 253
41963-253 253 253 253 253 253 253 253 253 253 253 253
41964-253 253 253 253 253 253 253 253 253 253 253 253
41965-253 253 253 253 253 253 231 231 231 6 6 6
41966- 2 2 6 2 2 6 10 10 10 30 30 30
41967- 2 2 6 2 2 6 2 2 6 2 2 6
41968- 2 2 6 66 66 66 58 58 58 22 22 22
41969- 6 6 6 0 0 0 0 0 0 0 0 0
41970- 0 0 0 0 0 0 0 0 0 0 0 0
41971- 0 0 0 0 0 0 0 0 0 0 0 0
41972- 0 0 0 0 0 0 0 0 0 0 0 0
41973- 0 0 0 0 0 0 0 0 0 0 0 0
41974- 0 0 0 0 0 0 0 0 0 0 0 0
41975- 0 0 0 0 0 0 0 0 0 10 10 10
41976- 38 38 38 78 78 78 6 6 6 2 2 6
41977- 2 2 6 46 46 46 14 14 14 42 42 42
41978-246 246 246 253 253 253 253 253 253 253 253 253
41979-253 253 253 253 253 253 253 253 253 253 253 253
41980-253 253 253 253 253 253 231 231 231 242 242 242
41981-253 253 253 253 253 253 253 253 253 253 253 253
41982-253 253 253 253 253 253 253 253 253 253 253 253
41983-253 253 253 253 253 253 253 253 253 253 253 253
41984-253 253 253 253 253 253 253 253 253 253 253 253
41985-253 253 253 253 253 253 234 234 234 10 10 10
41986- 2 2 6 2 2 6 22 22 22 14 14 14
41987- 2 2 6 2 2 6 2 2 6 2 2 6
41988- 2 2 6 66 66 66 62 62 62 22 22 22
41989- 6 6 6 0 0 0 0 0 0 0 0 0
41990- 0 0 0 0 0 0 0 0 0 0 0 0
41991- 0 0 0 0 0 0 0 0 0 0 0 0
41992- 0 0 0 0 0 0 0 0 0 0 0 0
41993- 0 0 0 0 0 0 0 0 0 0 0 0
41994- 0 0 0 0 0 0 0 0 0 0 0 0
41995- 0 0 0 0 0 0 6 6 6 18 18 18
41996- 50 50 50 74 74 74 2 2 6 2 2 6
41997- 14 14 14 70 70 70 34 34 34 62 62 62
41998-250 250 250 253 253 253 253 253 253 253 253 253
41999-253 253 253 253 253 253 253 253 253 253 253 253
42000-253 253 253 253 253 253 231 231 231 246 246 246
42001-253 253 253 253 253 253 253 253 253 253 253 253
42002-253 253 253 253 253 253 253 253 253 253 253 253
42003-253 253 253 253 253 253 253 253 253 253 253 253
42004-253 253 253 253 253 253 253 253 253 253 253 253
42005-253 253 253 253 253 253 234 234 234 14 14 14
42006- 2 2 6 2 2 6 30 30 30 2 2 6
42007- 2 2 6 2 2 6 2 2 6 2 2 6
42008- 2 2 6 66 66 66 62 62 62 22 22 22
42009- 6 6 6 0 0 0 0 0 0 0 0 0
42010- 0 0 0 0 0 0 0 0 0 0 0 0
42011- 0 0 0 0 0 0 0 0 0 0 0 0
42012- 0 0 0 0 0 0 0 0 0 0 0 0
42013- 0 0 0 0 0 0 0 0 0 0 0 0
42014- 0 0 0 0 0 0 0 0 0 0 0 0
42015- 0 0 0 0 0 0 6 6 6 18 18 18
42016- 54 54 54 62 62 62 2 2 6 2 2 6
42017- 2 2 6 30 30 30 46 46 46 70 70 70
42018-250 250 250 253 253 253 253 253 253 253 253 253
42019-253 253 253 253 253 253 253 253 253 253 253 253
42020-253 253 253 253 253 253 231 231 231 246 246 246
42021-253 253 253 253 253 253 253 253 253 253 253 253
42022-253 253 253 253 253 253 253 253 253 253 253 253
42023-253 253 253 253 253 253 253 253 253 253 253 253
42024-253 253 253 253 253 253 253 253 253 253 253 253
42025-253 253 253 253 253 253 226 226 226 10 10 10
42026- 2 2 6 6 6 6 30 30 30 2 2 6
42027- 2 2 6 2 2 6 2 2 6 2 2 6
42028- 2 2 6 66 66 66 58 58 58 22 22 22
42029- 6 6 6 0 0 0 0 0 0 0 0 0
42030- 0 0 0 0 0 0 0 0 0 0 0 0
42031- 0 0 0 0 0 0 0 0 0 0 0 0
42032- 0 0 0 0 0 0 0 0 0 0 0 0
42033- 0 0 0 0 0 0 0 0 0 0 0 0
42034- 0 0 0 0 0 0 0 0 0 0 0 0
42035- 0 0 0 0 0 0 6 6 6 22 22 22
42036- 58 58 58 62 62 62 2 2 6 2 2 6
42037- 2 2 6 2 2 6 30 30 30 78 78 78
42038-250 250 250 253 253 253 253 253 253 253 253 253
42039-253 253 253 253 253 253 253 253 253 253 253 253
42040-253 253 253 253 253 253 231 231 231 246 246 246
42041-253 253 253 253 253 253 253 253 253 253 253 253
42042-253 253 253 253 253 253 253 253 253 253 253 253
42043-253 253 253 253 253 253 253 253 253 253 253 253
42044-253 253 253 253 253 253 253 253 253 253 253 253
42045-253 253 253 253 253 253 206 206 206 2 2 6
42046- 22 22 22 34 34 34 18 14 6 22 22 22
42047- 26 26 26 18 18 18 6 6 6 2 2 6
42048- 2 2 6 82 82 82 54 54 54 18 18 18
42049- 6 6 6 0 0 0 0 0 0 0 0 0
42050- 0 0 0 0 0 0 0 0 0 0 0 0
42051- 0 0 0 0 0 0 0 0 0 0 0 0
42052- 0 0 0 0 0 0 0 0 0 0 0 0
42053- 0 0 0 0 0 0 0 0 0 0 0 0
42054- 0 0 0 0 0 0 0 0 0 0 0 0
42055- 0 0 0 0 0 0 6 6 6 26 26 26
42056- 62 62 62 106 106 106 74 54 14 185 133 11
42057-210 162 10 121 92 8 6 6 6 62 62 62
42058-238 238 238 253 253 253 253 253 253 253 253 253
42059-253 253 253 253 253 253 253 253 253 253 253 253
42060-253 253 253 253 253 253 231 231 231 246 246 246
42061-253 253 253 253 253 253 253 253 253 253 253 253
42062-253 253 253 253 253 253 253 253 253 253 253 253
42063-253 253 253 253 253 253 253 253 253 253 253 253
42064-253 253 253 253 253 253 253 253 253 253 253 253
42065-253 253 253 253 253 253 158 158 158 18 18 18
42066- 14 14 14 2 2 6 2 2 6 2 2 6
42067- 6 6 6 18 18 18 66 66 66 38 38 38
42068- 6 6 6 94 94 94 50 50 50 18 18 18
42069- 6 6 6 0 0 0 0 0 0 0 0 0
42070- 0 0 0 0 0 0 0 0 0 0 0 0
42071- 0 0 0 0 0 0 0 0 0 0 0 0
42072- 0 0 0 0 0 0 0 0 0 0 0 0
42073- 0 0 0 0 0 0 0 0 0 0 0 0
42074- 0 0 0 0 0 0 0 0 0 6 6 6
42075- 10 10 10 10 10 10 18 18 18 38 38 38
42076- 78 78 78 142 134 106 216 158 10 242 186 14
42077-246 190 14 246 190 14 156 118 10 10 10 10
42078- 90 90 90 238 238 238 253 253 253 253 253 253
42079-253 253 253 253 253 253 253 253 253 253 253 253
42080-253 253 253 253 253 253 231 231 231 250 250 250
42081-253 253 253 253 253 253 253 253 253 253 253 253
42082-253 253 253 253 253 253 253 253 253 253 253 253
42083-253 253 253 253 253 253 253 253 253 253 253 253
42084-253 253 253 253 253 253 253 253 253 246 230 190
42085-238 204 91 238 204 91 181 142 44 37 26 9
42086- 2 2 6 2 2 6 2 2 6 2 2 6
42087- 2 2 6 2 2 6 38 38 38 46 46 46
42088- 26 26 26 106 106 106 54 54 54 18 18 18
42089- 6 6 6 0 0 0 0 0 0 0 0 0
42090- 0 0 0 0 0 0 0 0 0 0 0 0
42091- 0 0 0 0 0 0 0 0 0 0 0 0
42092- 0 0 0 0 0 0 0 0 0 0 0 0
42093- 0 0 0 0 0 0 0 0 0 0 0 0
42094- 0 0 0 6 6 6 14 14 14 22 22 22
42095- 30 30 30 38 38 38 50 50 50 70 70 70
42096-106 106 106 190 142 34 226 170 11 242 186 14
42097-246 190 14 246 190 14 246 190 14 154 114 10
42098- 6 6 6 74 74 74 226 226 226 253 253 253
42099-253 253 253 253 253 253 253 253 253 253 253 253
42100-253 253 253 253 253 253 231 231 231 250 250 250
42101-253 253 253 253 253 253 253 253 253 253 253 253
42102-253 253 253 253 253 253 253 253 253 253 253 253
42103-253 253 253 253 253 253 253 253 253 253 253 253
42104-253 253 253 253 253 253 253 253 253 228 184 62
42105-241 196 14 241 208 19 232 195 16 38 30 10
42106- 2 2 6 2 2 6 2 2 6 2 2 6
42107- 2 2 6 6 6 6 30 30 30 26 26 26
42108-203 166 17 154 142 90 66 66 66 26 26 26
42109- 6 6 6 0 0 0 0 0 0 0 0 0
42110- 0 0 0 0 0 0 0 0 0 0 0 0
42111- 0 0 0 0 0 0 0 0 0 0 0 0
42112- 0 0 0 0 0 0 0 0 0 0 0 0
42113- 0 0 0 0 0 0 0 0 0 0 0 0
42114- 6 6 6 18 18 18 38 38 38 58 58 58
42115- 78 78 78 86 86 86 101 101 101 123 123 123
42116-175 146 61 210 150 10 234 174 13 246 186 14
42117-246 190 14 246 190 14 246 190 14 238 190 10
42118-102 78 10 2 2 6 46 46 46 198 198 198
42119-253 253 253 253 253 253 253 253 253 253 253 253
42120-253 253 253 253 253 253 234 234 234 242 242 242
42121-253 253 253 253 253 253 253 253 253 253 253 253
42122-253 253 253 253 253 253 253 253 253 253 253 253
42123-253 253 253 253 253 253 253 253 253 253 253 253
42124-253 253 253 253 253 253 253 253 253 224 178 62
42125-242 186 14 241 196 14 210 166 10 22 18 6
42126- 2 2 6 2 2 6 2 2 6 2 2 6
42127- 2 2 6 2 2 6 6 6 6 121 92 8
42128-238 202 15 232 195 16 82 82 82 34 34 34
42129- 10 10 10 0 0 0 0 0 0 0 0 0
42130- 0 0 0 0 0 0 0 0 0 0 0 0
42131- 0 0 0 0 0 0 0 0 0 0 0 0
42132- 0 0 0 0 0 0 0 0 0 0 0 0
42133- 0 0 0 0 0 0 0 0 0 0 0 0
42134- 14 14 14 38 38 38 70 70 70 154 122 46
42135-190 142 34 200 144 11 197 138 11 197 138 11
42136-213 154 11 226 170 11 242 186 14 246 190 14
42137-246 190 14 246 190 14 246 190 14 246 190 14
42138-225 175 15 46 32 6 2 2 6 22 22 22
42139-158 158 158 250 250 250 253 253 253 253 253 253
42140-253 253 253 253 253 253 253 253 253 253 253 253
42141-253 253 253 253 253 253 253 253 253 253 253 253
42142-253 253 253 253 253 253 253 253 253 253 253 253
42143-253 253 253 253 253 253 253 253 253 253 253 253
42144-253 253 253 250 250 250 242 242 242 224 178 62
42145-239 182 13 236 186 11 213 154 11 46 32 6
42146- 2 2 6 2 2 6 2 2 6 2 2 6
42147- 2 2 6 2 2 6 61 42 6 225 175 15
42148-238 190 10 236 186 11 112 100 78 42 42 42
42149- 14 14 14 0 0 0 0 0 0 0 0 0
42150- 0 0 0 0 0 0 0 0 0 0 0 0
42151- 0 0 0 0 0 0 0 0 0 0 0 0
42152- 0 0 0 0 0 0 0 0 0 0 0 0
42153- 0 0 0 0 0 0 0 0 0 6 6 6
42154- 22 22 22 54 54 54 154 122 46 213 154 11
42155-226 170 11 230 174 11 226 170 11 226 170 11
42156-236 178 12 242 186 14 246 190 14 246 190 14
42157-246 190 14 246 190 14 246 190 14 246 190 14
42158-241 196 14 184 144 12 10 10 10 2 2 6
42159- 6 6 6 116 116 116 242 242 242 253 253 253
42160-253 253 253 253 253 253 253 253 253 253 253 253
42161-253 253 253 253 253 253 253 253 253 253 253 253
42162-253 253 253 253 253 253 253 253 253 253 253 253
42163-253 253 253 253 253 253 253 253 253 253 253 253
42164-253 253 253 231 231 231 198 198 198 214 170 54
42165-236 178 12 236 178 12 210 150 10 137 92 6
42166- 18 14 6 2 2 6 2 2 6 2 2 6
42167- 6 6 6 70 47 6 200 144 11 236 178 12
42168-239 182 13 239 182 13 124 112 88 58 58 58
42169- 22 22 22 6 6 6 0 0 0 0 0 0
42170- 0 0 0 0 0 0 0 0 0 0 0 0
42171- 0 0 0 0 0 0 0 0 0 0 0 0
42172- 0 0 0 0 0 0 0 0 0 0 0 0
42173- 0 0 0 0 0 0 0 0 0 10 10 10
42174- 30 30 30 70 70 70 180 133 36 226 170 11
42175-239 182 13 242 186 14 242 186 14 246 186 14
42176-246 190 14 246 190 14 246 190 14 246 190 14
42177-246 190 14 246 190 14 246 190 14 246 190 14
42178-246 190 14 232 195 16 98 70 6 2 2 6
42179- 2 2 6 2 2 6 66 66 66 221 221 221
42180-253 253 253 253 253 253 253 253 253 253 253 253
42181-253 253 253 253 253 253 253 253 253 253 253 253
42182-253 253 253 253 253 253 253 253 253 253 253 253
42183-253 253 253 253 253 253 253 253 253 253 253 253
42184-253 253 253 206 206 206 198 198 198 214 166 58
42185-230 174 11 230 174 11 216 158 10 192 133 9
42186-163 110 8 116 81 8 102 78 10 116 81 8
42187-167 114 7 197 138 11 226 170 11 239 182 13
42188-242 186 14 242 186 14 162 146 94 78 78 78
42189- 34 34 34 14 14 14 6 6 6 0 0 0
42190- 0 0 0 0 0 0 0 0 0 0 0 0
42191- 0 0 0 0 0 0 0 0 0 0 0 0
42192- 0 0 0 0 0 0 0 0 0 0 0 0
42193- 0 0 0 0 0 0 0 0 0 6 6 6
42194- 30 30 30 78 78 78 190 142 34 226 170 11
42195-239 182 13 246 190 14 246 190 14 246 190 14
42196-246 190 14 246 190 14 246 190 14 246 190 14
42197-246 190 14 246 190 14 246 190 14 246 190 14
42198-246 190 14 241 196 14 203 166 17 22 18 6
42199- 2 2 6 2 2 6 2 2 6 38 38 38
42200-218 218 218 253 253 253 253 253 253 253 253 253
42201-253 253 253 253 253 253 253 253 253 253 253 253
42202-253 253 253 253 253 253 253 253 253 253 253 253
42203-253 253 253 253 253 253 253 253 253 253 253 253
42204-250 250 250 206 206 206 198 198 198 202 162 69
42205-226 170 11 236 178 12 224 166 10 210 150 10
42206-200 144 11 197 138 11 192 133 9 197 138 11
42207-210 150 10 226 170 11 242 186 14 246 190 14
42208-246 190 14 246 186 14 225 175 15 124 112 88
42209- 62 62 62 30 30 30 14 14 14 6 6 6
42210- 0 0 0 0 0 0 0 0 0 0 0 0
42211- 0 0 0 0 0 0 0 0 0 0 0 0
42212- 0 0 0 0 0 0 0 0 0 0 0 0
42213- 0 0 0 0 0 0 0 0 0 10 10 10
42214- 30 30 30 78 78 78 174 135 50 224 166 10
42215-239 182 13 246 190 14 246 190 14 246 190 14
42216-246 190 14 246 190 14 246 190 14 246 190 14
42217-246 190 14 246 190 14 246 190 14 246 190 14
42218-246 190 14 246 190 14 241 196 14 139 102 15
42219- 2 2 6 2 2 6 2 2 6 2 2 6
42220- 78 78 78 250 250 250 253 253 253 253 253 253
42221-253 253 253 253 253 253 253 253 253 253 253 253
42222-253 253 253 253 253 253 253 253 253 253 253 253
42223-253 253 253 253 253 253 253 253 253 253 253 253
42224-250 250 250 214 214 214 198 198 198 190 150 46
42225-219 162 10 236 178 12 234 174 13 224 166 10
42226-216 158 10 213 154 11 213 154 11 216 158 10
42227-226 170 11 239 182 13 246 190 14 246 190 14
42228-246 190 14 246 190 14 242 186 14 206 162 42
42229-101 101 101 58 58 58 30 30 30 14 14 14
42230- 6 6 6 0 0 0 0 0 0 0 0 0
42231- 0 0 0 0 0 0 0 0 0 0 0 0
42232- 0 0 0 0 0 0 0 0 0 0 0 0
42233- 0 0 0 0 0 0 0 0 0 10 10 10
42234- 30 30 30 74 74 74 174 135 50 216 158 10
42235-236 178 12 246 190 14 246 190 14 246 190 14
42236-246 190 14 246 190 14 246 190 14 246 190 14
42237-246 190 14 246 190 14 246 190 14 246 190 14
42238-246 190 14 246 190 14 241 196 14 226 184 13
42239- 61 42 6 2 2 6 2 2 6 2 2 6
42240- 22 22 22 238 238 238 253 253 253 253 253 253
42241-253 253 253 253 253 253 253 253 253 253 253 253
42242-253 253 253 253 253 253 253 253 253 253 253 253
42243-253 253 253 253 253 253 253 253 253 253 253 253
42244-253 253 253 226 226 226 187 187 187 180 133 36
42245-216 158 10 236 178 12 239 182 13 236 178 12
42246-230 174 11 226 170 11 226 170 11 230 174 11
42247-236 178 12 242 186 14 246 190 14 246 190 14
42248-246 190 14 246 190 14 246 186 14 239 182 13
42249-206 162 42 106 106 106 66 66 66 34 34 34
42250- 14 14 14 6 6 6 0 0 0 0 0 0
42251- 0 0 0 0 0 0 0 0 0 0 0 0
42252- 0 0 0 0 0 0 0 0 0 0 0 0
42253- 0 0 0 0 0 0 0 0 0 6 6 6
42254- 26 26 26 70 70 70 163 133 67 213 154 11
42255-236 178 12 246 190 14 246 190 14 246 190 14
42256-246 190 14 246 190 14 246 190 14 246 190 14
42257-246 190 14 246 190 14 246 190 14 246 190 14
42258-246 190 14 246 190 14 246 190 14 241 196 14
42259-190 146 13 18 14 6 2 2 6 2 2 6
42260- 46 46 46 246 246 246 253 253 253 253 253 253
42261-253 253 253 253 253 253 253 253 253 253 253 253
42262-253 253 253 253 253 253 253 253 253 253 253 253
42263-253 253 253 253 253 253 253 253 253 253 253 253
42264-253 253 253 221 221 221 86 86 86 156 107 11
42265-216 158 10 236 178 12 242 186 14 246 186 14
42266-242 186 14 239 182 13 239 182 13 242 186 14
42267-242 186 14 246 186 14 246 190 14 246 190 14
42268-246 190 14 246 190 14 246 190 14 246 190 14
42269-242 186 14 225 175 15 142 122 72 66 66 66
42270- 30 30 30 10 10 10 0 0 0 0 0 0
42271- 0 0 0 0 0 0 0 0 0 0 0 0
42272- 0 0 0 0 0 0 0 0 0 0 0 0
42273- 0 0 0 0 0 0 0 0 0 6 6 6
42274- 26 26 26 70 70 70 163 133 67 210 150 10
42275-236 178 12 246 190 14 246 190 14 246 190 14
42276-246 190 14 246 190 14 246 190 14 246 190 14
42277-246 190 14 246 190 14 246 190 14 246 190 14
42278-246 190 14 246 190 14 246 190 14 246 190 14
42279-232 195 16 121 92 8 34 34 34 106 106 106
42280-221 221 221 253 253 253 253 253 253 253 253 253
42281-253 253 253 253 253 253 253 253 253 253 253 253
42282-253 253 253 253 253 253 253 253 253 253 253 253
42283-253 253 253 253 253 253 253 253 253 253 253 253
42284-242 242 242 82 82 82 18 14 6 163 110 8
42285-216 158 10 236 178 12 242 186 14 246 190 14
42286-246 190 14 246 190 14 246 190 14 246 190 14
42287-246 190 14 246 190 14 246 190 14 246 190 14
42288-246 190 14 246 190 14 246 190 14 246 190 14
42289-246 190 14 246 190 14 242 186 14 163 133 67
42290- 46 46 46 18 18 18 6 6 6 0 0 0
42291- 0 0 0 0 0 0 0 0 0 0 0 0
42292- 0 0 0 0 0 0 0 0 0 0 0 0
42293- 0 0 0 0 0 0 0 0 0 10 10 10
42294- 30 30 30 78 78 78 163 133 67 210 150 10
42295-236 178 12 246 186 14 246 190 14 246 190 14
42296-246 190 14 246 190 14 246 190 14 246 190 14
42297-246 190 14 246 190 14 246 190 14 246 190 14
42298-246 190 14 246 190 14 246 190 14 246 190 14
42299-241 196 14 215 174 15 190 178 144 253 253 253
42300-253 253 253 253 253 253 253 253 253 253 253 253
42301-253 253 253 253 253 253 253 253 253 253 253 253
42302-253 253 253 253 253 253 253 253 253 253 253 253
42303-253 253 253 253 253 253 253 253 253 218 218 218
42304- 58 58 58 2 2 6 22 18 6 167 114 7
42305-216 158 10 236 178 12 246 186 14 246 190 14
42306-246 190 14 246 190 14 246 190 14 246 190 14
42307-246 190 14 246 190 14 246 190 14 246 190 14
42308-246 190 14 246 190 14 246 190 14 246 190 14
42309-246 190 14 246 186 14 242 186 14 190 150 46
42310- 54 54 54 22 22 22 6 6 6 0 0 0
42311- 0 0 0 0 0 0 0 0 0 0 0 0
42312- 0 0 0 0 0 0 0 0 0 0 0 0
42313- 0 0 0 0 0 0 0 0 0 14 14 14
42314- 38 38 38 86 86 86 180 133 36 213 154 11
42315-236 178 12 246 186 14 246 190 14 246 190 14
42316-246 190 14 246 190 14 246 190 14 246 190 14
42317-246 190 14 246 190 14 246 190 14 246 190 14
42318-246 190 14 246 190 14 246 190 14 246 190 14
42319-246 190 14 232 195 16 190 146 13 214 214 214
42320-253 253 253 253 253 253 253 253 253 253 253 253
42321-253 253 253 253 253 253 253 253 253 253 253 253
42322-253 253 253 253 253 253 253 253 253 253 253 253
42323-253 253 253 250 250 250 170 170 170 26 26 26
42324- 2 2 6 2 2 6 37 26 9 163 110 8
42325-219 162 10 239 182 13 246 186 14 246 190 14
42326-246 190 14 246 190 14 246 190 14 246 190 14
42327-246 190 14 246 190 14 246 190 14 246 190 14
42328-246 190 14 246 190 14 246 190 14 246 190 14
42329-246 186 14 236 178 12 224 166 10 142 122 72
42330- 46 46 46 18 18 18 6 6 6 0 0 0
42331- 0 0 0 0 0 0 0 0 0 0 0 0
42332- 0 0 0 0 0 0 0 0 0 0 0 0
42333- 0 0 0 0 0 0 6 6 6 18 18 18
42334- 50 50 50 109 106 95 192 133 9 224 166 10
42335-242 186 14 246 190 14 246 190 14 246 190 14
42336-246 190 14 246 190 14 246 190 14 246 190 14
42337-246 190 14 246 190 14 246 190 14 246 190 14
42338-246 190 14 246 190 14 246 190 14 246 190 14
42339-242 186 14 226 184 13 210 162 10 142 110 46
42340-226 226 226 253 253 253 253 253 253 253 253 253
42341-253 253 253 253 253 253 253 253 253 253 253 253
42342-253 253 253 253 253 253 253 253 253 253 253 253
42343-198 198 198 66 66 66 2 2 6 2 2 6
42344- 2 2 6 2 2 6 50 34 6 156 107 11
42345-219 162 10 239 182 13 246 186 14 246 190 14
42346-246 190 14 246 190 14 246 190 14 246 190 14
42347-246 190 14 246 190 14 246 190 14 246 190 14
42348-246 190 14 246 190 14 246 190 14 242 186 14
42349-234 174 13 213 154 11 154 122 46 66 66 66
42350- 30 30 30 10 10 10 0 0 0 0 0 0
42351- 0 0 0 0 0 0 0 0 0 0 0 0
42352- 0 0 0 0 0 0 0 0 0 0 0 0
42353- 0 0 0 0 0 0 6 6 6 22 22 22
42354- 58 58 58 154 121 60 206 145 10 234 174 13
42355-242 186 14 246 186 14 246 190 14 246 190 14
42356-246 190 14 246 190 14 246 190 14 246 190 14
42357-246 190 14 246 190 14 246 190 14 246 190 14
42358-246 190 14 246 190 14 246 190 14 246 190 14
42359-246 186 14 236 178 12 210 162 10 163 110 8
42360- 61 42 6 138 138 138 218 218 218 250 250 250
42361-253 253 253 253 253 253 253 253 253 250 250 250
42362-242 242 242 210 210 210 144 144 144 66 66 66
42363- 6 6 6 2 2 6 2 2 6 2 2 6
42364- 2 2 6 2 2 6 61 42 6 163 110 8
42365-216 158 10 236 178 12 246 190 14 246 190 14
42366-246 190 14 246 190 14 246 190 14 246 190 14
42367-246 190 14 246 190 14 246 190 14 246 190 14
42368-246 190 14 239 182 13 230 174 11 216 158 10
42369-190 142 34 124 112 88 70 70 70 38 38 38
42370- 18 18 18 6 6 6 0 0 0 0 0 0
42371- 0 0 0 0 0 0 0 0 0 0 0 0
42372- 0 0 0 0 0 0 0 0 0 0 0 0
42373- 0 0 0 0 0 0 6 6 6 22 22 22
42374- 62 62 62 168 124 44 206 145 10 224 166 10
42375-236 178 12 239 182 13 242 186 14 242 186 14
42376-246 186 14 246 190 14 246 190 14 246 190 14
42377-246 190 14 246 190 14 246 190 14 246 190 14
42378-246 190 14 246 190 14 246 190 14 246 190 14
42379-246 190 14 236 178 12 216 158 10 175 118 6
42380- 80 54 7 2 2 6 6 6 6 30 30 30
42381- 54 54 54 62 62 62 50 50 50 38 38 38
42382- 14 14 14 2 2 6 2 2 6 2 2 6
42383- 2 2 6 2 2 6 2 2 6 2 2 6
42384- 2 2 6 6 6 6 80 54 7 167 114 7
42385-213 154 11 236 178 12 246 190 14 246 190 14
42386-246 190 14 246 190 14 246 190 14 246 190 14
42387-246 190 14 242 186 14 239 182 13 239 182 13
42388-230 174 11 210 150 10 174 135 50 124 112 88
42389- 82 82 82 54 54 54 34 34 34 18 18 18
42390- 6 6 6 0 0 0 0 0 0 0 0 0
42391- 0 0 0 0 0 0 0 0 0 0 0 0
42392- 0 0 0 0 0 0 0 0 0 0 0 0
42393- 0 0 0 0 0 0 6 6 6 18 18 18
42394- 50 50 50 158 118 36 192 133 9 200 144 11
42395-216 158 10 219 162 10 224 166 10 226 170 11
42396-230 174 11 236 178 12 239 182 13 239 182 13
42397-242 186 14 246 186 14 246 190 14 246 190 14
42398-246 190 14 246 190 14 246 190 14 246 190 14
42399-246 186 14 230 174 11 210 150 10 163 110 8
42400-104 69 6 10 10 10 2 2 6 2 2 6
42401- 2 2 6 2 2 6 2 2 6 2 2 6
42402- 2 2 6 2 2 6 2 2 6 2 2 6
42403- 2 2 6 2 2 6 2 2 6 2 2 6
42404- 2 2 6 6 6 6 91 60 6 167 114 7
42405-206 145 10 230 174 11 242 186 14 246 190 14
42406-246 190 14 246 190 14 246 186 14 242 186 14
42407-239 182 13 230 174 11 224 166 10 213 154 11
42408-180 133 36 124 112 88 86 86 86 58 58 58
42409- 38 38 38 22 22 22 10 10 10 6 6 6
42410- 0 0 0 0 0 0 0 0 0 0 0 0
42411- 0 0 0 0 0 0 0 0 0 0 0 0
42412- 0 0 0 0 0 0 0 0 0 0 0 0
42413- 0 0 0 0 0 0 0 0 0 14 14 14
42414- 34 34 34 70 70 70 138 110 50 158 118 36
42415-167 114 7 180 123 7 192 133 9 197 138 11
42416-200 144 11 206 145 10 213 154 11 219 162 10
42417-224 166 10 230 174 11 239 182 13 242 186 14
42418-246 186 14 246 186 14 246 186 14 246 186 14
42419-239 182 13 216 158 10 185 133 11 152 99 6
42420-104 69 6 18 14 6 2 2 6 2 2 6
42421- 2 2 6 2 2 6 2 2 6 2 2 6
42422- 2 2 6 2 2 6 2 2 6 2 2 6
42423- 2 2 6 2 2 6 2 2 6 2 2 6
42424- 2 2 6 6 6 6 80 54 7 152 99 6
42425-192 133 9 219 162 10 236 178 12 239 182 13
42426-246 186 14 242 186 14 239 182 13 236 178 12
42427-224 166 10 206 145 10 192 133 9 154 121 60
42428- 94 94 94 62 62 62 42 42 42 22 22 22
42429- 14 14 14 6 6 6 0 0 0 0 0 0
42430- 0 0 0 0 0 0 0 0 0 0 0 0
42431- 0 0 0 0 0 0 0 0 0 0 0 0
42432- 0 0 0 0 0 0 0 0 0 0 0 0
42433- 0 0 0 0 0 0 0 0 0 6 6 6
42434- 18 18 18 34 34 34 58 58 58 78 78 78
42435-101 98 89 124 112 88 142 110 46 156 107 11
42436-163 110 8 167 114 7 175 118 6 180 123 7
42437-185 133 11 197 138 11 210 150 10 219 162 10
42438-226 170 11 236 178 12 236 178 12 234 174 13
42439-219 162 10 197 138 11 163 110 8 130 83 6
42440- 91 60 6 10 10 10 2 2 6 2 2 6
42441- 18 18 18 38 38 38 38 38 38 38 38 38
42442- 38 38 38 38 38 38 38 38 38 38 38 38
42443- 38 38 38 38 38 38 26 26 26 2 2 6
42444- 2 2 6 6 6 6 70 47 6 137 92 6
42445-175 118 6 200 144 11 219 162 10 230 174 11
42446-234 174 13 230 174 11 219 162 10 210 150 10
42447-192 133 9 163 110 8 124 112 88 82 82 82
42448- 50 50 50 30 30 30 14 14 14 6 6 6
42449- 0 0 0 0 0 0 0 0 0 0 0 0
42450- 0 0 0 0 0 0 0 0 0 0 0 0
42451- 0 0 0 0 0 0 0 0 0 0 0 0
42452- 0 0 0 0 0 0 0 0 0 0 0 0
42453- 0 0 0 0 0 0 0 0 0 0 0 0
42454- 6 6 6 14 14 14 22 22 22 34 34 34
42455- 42 42 42 58 58 58 74 74 74 86 86 86
42456-101 98 89 122 102 70 130 98 46 121 87 25
42457-137 92 6 152 99 6 163 110 8 180 123 7
42458-185 133 11 197 138 11 206 145 10 200 144 11
42459-180 123 7 156 107 11 130 83 6 104 69 6
42460- 50 34 6 54 54 54 110 110 110 101 98 89
42461- 86 86 86 82 82 82 78 78 78 78 78 78
42462- 78 78 78 78 78 78 78 78 78 78 78 78
42463- 78 78 78 82 82 82 86 86 86 94 94 94
42464-106 106 106 101 101 101 86 66 34 124 80 6
42465-156 107 11 180 123 7 192 133 9 200 144 11
42466-206 145 10 200 144 11 192 133 9 175 118 6
42467-139 102 15 109 106 95 70 70 70 42 42 42
42468- 22 22 22 10 10 10 0 0 0 0 0 0
42469- 0 0 0 0 0 0 0 0 0 0 0 0
42470- 0 0 0 0 0 0 0 0 0 0 0 0
42471- 0 0 0 0 0 0 0 0 0 0 0 0
42472- 0 0 0 0 0 0 0 0 0 0 0 0
42473- 0 0 0 0 0 0 0 0 0 0 0 0
42474- 0 0 0 0 0 0 6 6 6 10 10 10
42475- 14 14 14 22 22 22 30 30 30 38 38 38
42476- 50 50 50 62 62 62 74 74 74 90 90 90
42477-101 98 89 112 100 78 121 87 25 124 80 6
42478-137 92 6 152 99 6 152 99 6 152 99 6
42479-138 86 6 124 80 6 98 70 6 86 66 30
42480-101 98 89 82 82 82 58 58 58 46 46 46
42481- 38 38 38 34 34 34 34 34 34 34 34 34
42482- 34 34 34 34 34 34 34 34 34 34 34 34
42483- 34 34 34 34 34 34 38 38 38 42 42 42
42484- 54 54 54 82 82 82 94 86 76 91 60 6
42485-134 86 6 156 107 11 167 114 7 175 118 6
42486-175 118 6 167 114 7 152 99 6 121 87 25
42487-101 98 89 62 62 62 34 34 34 18 18 18
42488- 6 6 6 0 0 0 0 0 0 0 0 0
42489- 0 0 0 0 0 0 0 0 0 0 0 0
42490- 0 0 0 0 0 0 0 0 0 0 0 0
42491- 0 0 0 0 0 0 0 0 0 0 0 0
42492- 0 0 0 0 0 0 0 0 0 0 0 0
42493- 0 0 0 0 0 0 0 0 0 0 0 0
42494- 0 0 0 0 0 0 0 0 0 0 0 0
42495- 0 0 0 6 6 6 6 6 6 10 10 10
42496- 18 18 18 22 22 22 30 30 30 42 42 42
42497- 50 50 50 66 66 66 86 86 86 101 98 89
42498-106 86 58 98 70 6 104 69 6 104 69 6
42499-104 69 6 91 60 6 82 62 34 90 90 90
42500- 62 62 62 38 38 38 22 22 22 14 14 14
42501- 10 10 10 10 10 10 10 10 10 10 10 10
42502- 10 10 10 10 10 10 6 6 6 10 10 10
42503- 10 10 10 10 10 10 10 10 10 14 14 14
42504- 22 22 22 42 42 42 70 70 70 89 81 66
42505- 80 54 7 104 69 6 124 80 6 137 92 6
42506-134 86 6 116 81 8 100 82 52 86 86 86
42507- 58 58 58 30 30 30 14 14 14 6 6 6
42508- 0 0 0 0 0 0 0 0 0 0 0 0
42509- 0 0 0 0 0 0 0 0 0 0 0 0
42510- 0 0 0 0 0 0 0 0 0 0 0 0
42511- 0 0 0 0 0 0 0 0 0 0 0 0
42512- 0 0 0 0 0 0 0 0 0 0 0 0
42513- 0 0 0 0 0 0 0 0 0 0 0 0
42514- 0 0 0 0 0 0 0 0 0 0 0 0
42515- 0 0 0 0 0 0 0 0 0 0 0 0
42516- 0 0 0 6 6 6 10 10 10 14 14 14
42517- 18 18 18 26 26 26 38 38 38 54 54 54
42518- 70 70 70 86 86 86 94 86 76 89 81 66
42519- 89 81 66 86 86 86 74 74 74 50 50 50
42520- 30 30 30 14 14 14 6 6 6 0 0 0
42521- 0 0 0 0 0 0 0 0 0 0 0 0
42522- 0 0 0 0 0 0 0 0 0 0 0 0
42523- 0 0 0 0 0 0 0 0 0 0 0 0
42524- 6 6 6 18 18 18 34 34 34 58 58 58
42525- 82 82 82 89 81 66 89 81 66 89 81 66
42526- 94 86 66 94 86 76 74 74 74 50 50 50
42527- 26 26 26 14 14 14 6 6 6 0 0 0
42528- 0 0 0 0 0 0 0 0 0 0 0 0
42529- 0 0 0 0 0 0 0 0 0 0 0 0
42530- 0 0 0 0 0 0 0 0 0 0 0 0
42531- 0 0 0 0 0 0 0 0 0 0 0 0
42532- 0 0 0 0 0 0 0 0 0 0 0 0
42533- 0 0 0 0 0 0 0 0 0 0 0 0
42534- 0 0 0 0 0 0 0 0 0 0 0 0
42535- 0 0 0 0 0 0 0 0 0 0 0 0
42536- 0 0 0 0 0 0 0 0 0 0 0 0
42537- 6 6 6 6 6 6 14 14 14 18 18 18
42538- 30 30 30 38 38 38 46 46 46 54 54 54
42539- 50 50 50 42 42 42 30 30 30 18 18 18
42540- 10 10 10 0 0 0 0 0 0 0 0 0
42541- 0 0 0 0 0 0 0 0 0 0 0 0
42542- 0 0 0 0 0 0 0 0 0 0 0 0
42543- 0 0 0 0 0 0 0 0 0 0 0 0
42544- 0 0 0 6 6 6 14 14 14 26 26 26
42545- 38 38 38 50 50 50 58 58 58 58 58 58
42546- 54 54 54 42 42 42 30 30 30 18 18 18
42547- 10 10 10 0 0 0 0 0 0 0 0 0
42548- 0 0 0 0 0 0 0 0 0 0 0 0
42549- 0 0 0 0 0 0 0 0 0 0 0 0
42550- 0 0 0 0 0 0 0 0 0 0 0 0
42551- 0 0 0 0 0 0 0 0 0 0 0 0
42552- 0 0 0 0 0 0 0 0 0 0 0 0
42553- 0 0 0 0 0 0 0 0 0 0 0 0
42554- 0 0 0 0 0 0 0 0 0 0 0 0
42555- 0 0 0 0 0 0 0 0 0 0 0 0
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 6 6 6
42558- 6 6 6 10 10 10 14 14 14 18 18 18
42559- 18 18 18 14 14 14 10 10 10 6 6 6
42560- 0 0 0 0 0 0 0 0 0 0 0 0
42561- 0 0 0 0 0 0 0 0 0 0 0 0
42562- 0 0 0 0 0 0 0 0 0 0 0 0
42563- 0 0 0 0 0 0 0 0 0 0 0 0
42564- 0 0 0 0 0 0 0 0 0 6 6 6
42565- 14 14 14 18 18 18 22 22 22 22 22 22
42566- 18 18 18 14 14 14 10 10 10 6 6 6
42567- 0 0 0 0 0 0 0 0 0 0 0 0
42568- 0 0 0 0 0 0 0 0 0 0 0 0
42569- 0 0 0 0 0 0 0 0 0 0 0 0
42570- 0 0 0 0 0 0 0 0 0 0 0 0
42571- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4
42576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42578+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42592+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42606+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
42619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42620+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
42633+4 4 4 4 4 4 4 4 4 4 4 4 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
42642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42655+4 4 4 4 4 4
42656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42660+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42661+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
42662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42665+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42666+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42667+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42669+4 4 4 4 4 4
42670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42674+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42675+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42676+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42679+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42680+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42681+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42682+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42683+4 4 4 4 4 4
42684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42688+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42689+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42690+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42693+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42694+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42695+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42696+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42697+4 4 4 4 4 4
42698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42701+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42702+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42703+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42704+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42706+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42707+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42708+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42709+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42710+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42711+4 4 4 4 4 4
42712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42715+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42716+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42717+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42718+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42719+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42720+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42721+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42722+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42723+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42724+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42725+4 4 4 4 4 4
42726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42729+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42730+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42731+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42732+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42733+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42734+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42735+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42736+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42737+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42738+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42739+4 4 4 4 4 4
42740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42742+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42743+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42744+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42745+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42746+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42747+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42748+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42749+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42750+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42751+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42752+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42753+4 4 4 4 4 4
42754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42756+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42757+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42758+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42759+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42760+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42761+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42762+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42763+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42764+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42765+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42766+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42767+4 4 4 4 4 4
42768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42770+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42771+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42772+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42773+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42774+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42775+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42776+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42777+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42778+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42779+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42780+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42781+4 4 4 4 4 4
42782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42784+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42785+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42786+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42787+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42788+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42789+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
42790+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
42791+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
42792+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
42793+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
42794+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
42795+4 4 4 4 4 4
42796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42797+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
42798+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
42799+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
42800+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
42801+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
42802+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
42803+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
42804+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
42805+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
42806+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
42807+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
42808+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
42809+4 4 4 4 4 4
42810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42811+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
42812+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
42813+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
42814+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42815+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
42816+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
42817+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
42818+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
42819+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
42820+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
42821+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
42822+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
42823+0 0 0 4 4 4
42824+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42825+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
42826+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
42827+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
42828+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
42829+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
42830+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
42831+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
42832+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
42833+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
42834+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
42835+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
42836+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
42837+2 0 0 0 0 0
42838+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
42839+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
42840+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
42841+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
42842+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
42843+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
42844+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
42845+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
42846+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
42847+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
42848+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
42849+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
42850+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
42851+37 38 37 0 0 0
42852+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42853+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
42854+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
42855+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
42856+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
42857+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
42858+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
42859+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
42860+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
42861+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
42862+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
42863+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
42864+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
42865+85 115 134 4 0 0
42866+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
42867+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
42868+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
42869+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
42870+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
42871+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
42872+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
42873+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
42874+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
42875+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
42876+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
42877+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
42878+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
42879+60 73 81 4 0 0
42880+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
42881+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
42882+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
42883+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
42884+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
42885+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
42886+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
42887+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
42888+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
42889+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
42890+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
42891+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
42892+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
42893+16 19 21 4 0 0
42894+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
42895+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
42896+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
42897+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
42898+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
42899+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
42900+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
42901+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
42902+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
42903+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
42904+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
42905+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
42906+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
42907+4 0 0 4 3 3
42908+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
42909+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
42910+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
42911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
42912+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
42913+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
42914+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
42915+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
42916+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
42917+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
42918+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
42919+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
42920+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
42921+3 2 2 4 4 4
42922+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
42923+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
42924+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
42925+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42926+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
42927+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
42928+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
42929+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
42930+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
42931+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
42932+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
42933+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
42934+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
42935+4 4 4 4 4 4
42936+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
42937+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
42938+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
42939+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
42940+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
42941+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
42942+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
42943+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
42944+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
42945+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
42946+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
42947+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
42948+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
42949+4 4 4 4 4 4
42950+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
42951+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
42952+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
42953+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
42954+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
42955+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
42956+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
42957+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
42958+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
42959+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
42960+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
42961+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
42962+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
42963+5 5 5 5 5 5
42964+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
42965+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
42966+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
42967+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
42968+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
42969+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42970+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
42971+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
42972+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
42973+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
42974+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
42975+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
42976+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42977+5 5 5 4 4 4
42978+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
42979+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
42980+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
42981+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
42982+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
42983+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
42984+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
42985+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
42986+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
42987+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
42988+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
42989+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42991+4 4 4 4 4 4
42992+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
42993+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
42994+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
42995+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
42996+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
42997+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42998+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
42999+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43000+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43001+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43002+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43003+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43005+4 4 4 4 4 4
43006+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43007+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43008+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43009+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43010+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43011+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43012+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43013+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43014+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43015+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43016+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43019+4 4 4 4 4 4
43020+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43021+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43022+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43023+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43024+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43025+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43026+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43027+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43028+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43029+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43030+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43033+4 4 4 4 4 4
43034+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43035+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43036+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43037+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43038+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43039+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43040+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43041+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43042+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43043+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43044+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43047+4 4 4 4 4 4
43048+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43049+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43050+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43051+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43052+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43053+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43054+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43055+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43056+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43057+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43058+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43061+4 4 4 4 4 4
43062+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43063+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43064+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43065+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43066+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43067+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43068+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43069+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43070+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43071+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43072+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43075+4 4 4 4 4 4
43076+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43077+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43078+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43079+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43080+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43081+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43082+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43083+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43084+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43085+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43086+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43089+4 4 4 4 4 4
43090+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43091+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43092+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43093+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43094+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43095+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43096+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43097+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43098+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43099+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43100+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43103+4 4 4 4 4 4
43104+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43105+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43106+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43107+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43108+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43109+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43110+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43111+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43112+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43113+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43114+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43115+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43117+4 4 4 4 4 4
43118+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43119+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43120+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43121+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43122+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43123+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43124+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43125+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43126+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43127+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43128+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43129+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43130+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43131+4 4 4 4 4 4
43132+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43133+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43134+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43135+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43136+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43137+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43138+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43139+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43140+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43141+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43142+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43143+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43144+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43145+4 4 4 4 4 4
43146+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43147+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43148+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43149+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43150+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43151+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43152+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43153+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43154+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43155+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43156+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43157+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43159+4 4 4 4 4 4
43160+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43161+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43162+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43163+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43164+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43165+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43166+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43167+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43168+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43169+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43170+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43171+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43173+4 4 4 4 4 4
43174+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43175+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43176+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43177+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43178+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43179+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43180+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43181+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43182+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43183+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43184+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43185+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43187+4 4 4 4 4 4
43188+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43189+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43190+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43191+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43192+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43193+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43194+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43195+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43196+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43197+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43198+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43201+4 4 4 4 4 4
43202+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43203+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43204+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43205+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43206+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43207+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43208+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43209+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43210+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43211+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43212+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43215+4 4 4 4 4 4
43216+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43217+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43218+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43219+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43220+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43221+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43222+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43223+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43224+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43225+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43226+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43229+4 4 4 4 4 4
43230+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43231+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43232+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43233+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43234+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43235+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43236+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43237+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43238+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43239+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43240+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43243+4 4 4 4 4 4
43244+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43245+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43246+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43247+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43248+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43249+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43250+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43251+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43252+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43253+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43254+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43257+4 4 4 4 4 4
43258+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43259+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43260+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43261+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43262+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43263+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43264+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43265+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43266+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43267+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43268+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43271+4 4 4 4 4 4
43272+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43273+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43274+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43275+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43276+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43277+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43278+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43279+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43280+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43281+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43282+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43285+4 4 4 4 4 4
43286+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43287+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43288+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43289+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43290+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43291+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43292+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43293+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43294+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43295+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43296+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43299+4 4 4 4 4 4
43300+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43301+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43302+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43303+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43304+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43305+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43306+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43307+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43308+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43309+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43310+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43313+4 4 4 4 4 4
43314+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43315+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43316+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43317+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43318+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43319+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43320+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43321+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43322+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43323+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43324+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43327+4 4 4 4 4 4
43328+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43329+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43330+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43331+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43332+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43333+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43334+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43335+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43336+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43337+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43338+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43341+4 4 4 4 4 4
43342+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43343+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43344+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43345+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43346+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43347+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43348+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43349+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43350+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43351+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43352+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43355+4 4 4 4 4 4
43356+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43357+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43358+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43359+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43360+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43361+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43362+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43363+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43364+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43365+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43366+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43369+4 4 4 4 4 4
43370+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43371+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43372+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43373+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43374+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43375+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43376+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43377+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43378+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43379+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43380+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43383+4 4 4 4 4 4
43384+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43385+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43386+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43387+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43388+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43389+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43390+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43391+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43392+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43393+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43397+4 4 4 4 4 4
43398+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43399+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43400+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43401+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43402+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43403+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43404+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43405+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43406+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43407+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43410+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43411+4 4 4 4 4 4
43412+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43413+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43414+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43415+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43416+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43417+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43418+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43419+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43420+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43421+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43424+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43425+4 4 4 4 4 4
43426+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43427+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43428+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43429+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43430+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43431+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43432+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43433+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43434+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43435+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43439+4 4 4 4 4 4
43440+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43441+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43442+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43443+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43444+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43445+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43446+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43447+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43448+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43451+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43453+4 4 4 4 4 4
43454+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43455+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43456+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43457+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43458+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43459+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43460+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43461+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43462+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43465+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43467+4 4 4 4 4 4
43468+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43469+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43470+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43471+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43472+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43473+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43474+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43475+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43476+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43479+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43481+4 4 4 4 4 4
43482+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43483+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43484+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43485+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43486+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43487+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43488+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43489+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43490+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43495+4 4 4 4 4 4
43496+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43497+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43498+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43499+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43500+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43501+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43502+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43503+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43504+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43506+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43509+4 4 4 4 4 4
43510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43511+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43512+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43513+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43514+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43515+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43516+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43517+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
43518+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43520+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43523+4 4 4 4 4 4
43524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43525+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43526+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43527+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43528+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43529+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43530+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43531+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
43532+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43533+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43537+4 4 4 4 4 4
43538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43539+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43540+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43541+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43542+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43543+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43544+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43545+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43546+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43547+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43551+4 4 4 4 4 4
43552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43554+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43555+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43556+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43557+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43558+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43559+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43560+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43561+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43565+4 4 4 4 4 4
43566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43568+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43569+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43570+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43571+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43572+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
43573+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43574+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43575+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43579+4 4 4 4 4 4
43580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43582+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43583+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43584+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43585+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43586+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43587+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43588+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43589+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43593+4 4 4 4 4 4
43594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43597+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43598+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43599+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43600+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43601+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43602+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43603+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43607+4 4 4 4 4 4
43608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43611+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43612+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43613+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43614+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43615+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43621+4 4 4 4 4 4
43622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43626+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43627+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43628+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43629+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43635+4 4 4 4 4 4
43636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43640+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43641+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43642+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43643+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43649+4 4 4 4 4 4
43650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43654+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43655+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43656+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43657+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43663+4 4 4 4 4 4
43664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43668+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43669+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43671+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43677+4 4 4 4 4 4
43678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43682+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43683+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43691+4 4 4 4 4 4
43692diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43693index 86d449e..af6a7f7 100644
43694--- a/drivers/video/udlfb.c
43695+++ b/drivers/video/udlfb.c
43696@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43697 dlfb_urb_completion(urb);
43698
43699 error:
43700- atomic_add(bytes_sent, &dev->bytes_sent);
43701- atomic_add(bytes_identical, &dev->bytes_identical);
43702- atomic_add(width*height*2, &dev->bytes_rendered);
43703+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43704+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43705+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43706 end_cycles = get_cycles();
43707- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43708+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43709 >> 10)), /* Kcycles */
43710 &dev->cpu_kcycles_used);
43711
43712@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43713 dlfb_urb_completion(urb);
43714
43715 error:
43716- atomic_add(bytes_sent, &dev->bytes_sent);
43717- atomic_add(bytes_identical, &dev->bytes_identical);
43718- atomic_add(bytes_rendered, &dev->bytes_rendered);
43719+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43720+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43721+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43722 end_cycles = get_cycles();
43723- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43724+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43725 >> 10)), /* Kcycles */
43726 &dev->cpu_kcycles_used);
43727 }
43728@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43729 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43730 struct dlfb_data *dev = fb_info->par;
43731 return snprintf(buf, PAGE_SIZE, "%u\n",
43732- atomic_read(&dev->bytes_rendered));
43733+ atomic_read_unchecked(&dev->bytes_rendered));
43734 }
43735
43736 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43737@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43738 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43739 struct dlfb_data *dev = fb_info->par;
43740 return snprintf(buf, PAGE_SIZE, "%u\n",
43741- atomic_read(&dev->bytes_identical));
43742+ atomic_read_unchecked(&dev->bytes_identical));
43743 }
43744
43745 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43746@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43747 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43748 struct dlfb_data *dev = fb_info->par;
43749 return snprintf(buf, PAGE_SIZE, "%u\n",
43750- atomic_read(&dev->bytes_sent));
43751+ atomic_read_unchecked(&dev->bytes_sent));
43752 }
43753
43754 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43755@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43756 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43757 struct dlfb_data *dev = fb_info->par;
43758 return snprintf(buf, PAGE_SIZE, "%u\n",
43759- atomic_read(&dev->cpu_kcycles_used));
43760+ atomic_read_unchecked(&dev->cpu_kcycles_used));
43761 }
43762
43763 static ssize_t edid_show(
43764@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43765 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43766 struct dlfb_data *dev = fb_info->par;
43767
43768- atomic_set(&dev->bytes_rendered, 0);
43769- atomic_set(&dev->bytes_identical, 0);
43770- atomic_set(&dev->bytes_sent, 0);
43771- atomic_set(&dev->cpu_kcycles_used, 0);
43772+ atomic_set_unchecked(&dev->bytes_rendered, 0);
43773+ atomic_set_unchecked(&dev->bytes_identical, 0);
43774+ atomic_set_unchecked(&dev->bytes_sent, 0);
43775+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43776
43777 return count;
43778 }
43779diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43780index 2f8f82d..191de37 100644
43781--- a/drivers/video/uvesafb.c
43782+++ b/drivers/video/uvesafb.c
43783@@ -19,6 +19,7 @@
43784 #include <linux/io.h>
43785 #include <linux/mutex.h>
43786 #include <linux/slab.h>
43787+#include <linux/moduleloader.h>
43788 #include <video/edid.h>
43789 #include <video/uvesafb.h>
43790 #ifdef CONFIG_X86
43791@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
43792 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43793 par->pmi_setpal = par->ypan = 0;
43794 } else {
43795+
43796+#ifdef CONFIG_PAX_KERNEXEC
43797+#ifdef CONFIG_MODULES
43798+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43799+#endif
43800+ if (!par->pmi_code) {
43801+ par->pmi_setpal = par->ypan = 0;
43802+ return 0;
43803+ }
43804+#endif
43805+
43806 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43807 + task->t.regs.edi);
43808+
43809+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43810+ pax_open_kernel();
43811+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43812+ pax_close_kernel();
43813+
43814+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43815+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43816+#else
43817 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43818 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43819+#endif
43820+
43821 printk(KERN_INFO "uvesafb: protected mode interface info at "
43822 "%04x:%04x\n",
43823 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43824@@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
43825 par->ypan = ypan;
43826
43827 if (par->pmi_setpal || par->ypan) {
43828+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
43829 if (__supported_pte_mask & _PAGE_NX) {
43830 par->pmi_setpal = par->ypan = 0;
43831 printk(KERN_WARNING "uvesafb: NX protection is actively."
43832 "We have better not to use the PMI.\n");
43833- } else {
43834+ } else
43835+#endif
43836 uvesafb_vbe_getpmi(task, par);
43837- }
43838 }
43839 #else
43840 /* The protected mode interface is not available on non-x86. */
43841@@ -1838,6 +1862,11 @@ out:
43842 if (par->vbe_modes)
43843 kfree(par->vbe_modes);
43844
43845+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43846+ if (par->pmi_code)
43847+ module_free_exec(NULL, par->pmi_code);
43848+#endif
43849+
43850 framebuffer_release(info);
43851 return err;
43852 }
43853@@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
43854 kfree(par->vbe_state_orig);
43855 if (par->vbe_state_saved)
43856 kfree(par->vbe_state_saved);
43857+
43858+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43859+ if (par->pmi_code)
43860+ module_free_exec(NULL, par->pmi_code);
43861+#endif
43862+
43863 }
43864
43865 framebuffer_release(info);
43866diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
43867index 501b340..86bd4cf 100644
43868--- a/drivers/video/vesafb.c
43869+++ b/drivers/video/vesafb.c
43870@@ -9,6 +9,7 @@
43871 */
43872
43873 #include <linux/module.h>
43874+#include <linux/moduleloader.h>
43875 #include <linux/kernel.h>
43876 #include <linux/errno.h>
43877 #include <linux/string.h>
43878@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
43879 static int vram_total __initdata; /* Set total amount of memory */
43880 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43881 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43882-static void (*pmi_start)(void) __read_mostly;
43883-static void (*pmi_pal) (void) __read_mostly;
43884+static void (*pmi_start)(void) __read_only;
43885+static void (*pmi_pal) (void) __read_only;
43886 static int depth __read_mostly;
43887 static int vga_compat __read_mostly;
43888 /* --------------------------------------------------------------------- */
43889@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
43890 unsigned int size_vmode;
43891 unsigned int size_remap;
43892 unsigned int size_total;
43893+ void *pmi_code = NULL;
43894
43895 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
43896 return -ENODEV;
43897@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
43898 size_remap = size_total;
43899 vesafb_fix.smem_len = size_remap;
43900
43901-#ifndef __i386__
43902- screen_info.vesapm_seg = 0;
43903-#endif
43904-
43905 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
43906 printk(KERN_WARNING
43907 "vesafb: cannot reserve video memory at 0x%lx\n",
43908@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
43909 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
43910 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
43911
43912+#ifdef __i386__
43913+
43914+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43915+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
43916+ if (!pmi_code)
43917+#elif !defined(CONFIG_PAX_KERNEXEC)
43918+ if (0)
43919+#endif
43920+
43921+#endif
43922+ screen_info.vesapm_seg = 0;
43923+
43924 if (screen_info.vesapm_seg) {
43925- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
43926- screen_info.vesapm_seg,screen_info.vesapm_off);
43927+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
43928+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
43929 }
43930
43931 if (screen_info.vesapm_seg < 0xc000)
43932@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
43933
43934 if (ypan || pmi_setpal) {
43935 unsigned short *pmi_base;
43936+
43937 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
43938- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
43939- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
43940+
43941+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43942+ pax_open_kernel();
43943+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
43944+#else
43945+ pmi_code = pmi_base;
43946+#endif
43947+
43948+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
43949+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
43950+
43951+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43952+ pmi_start = ktva_ktla(pmi_start);
43953+ pmi_pal = ktva_ktla(pmi_pal);
43954+ pax_close_kernel();
43955+#endif
43956+
43957 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
43958 if (pmi_base[3]) {
43959 printk(KERN_INFO "vesafb: pmi: ports = ");
43960@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
43961 info->node, info->fix.id);
43962 return 0;
43963 err:
43964+
43965+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43966+ module_free_exec(NULL, pmi_code);
43967+#endif
43968+
43969 if (info->screen_base)
43970 iounmap(info->screen_base);
43971 framebuffer_release(info);
43972diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
43973index 88714ae..16c2e11 100644
43974--- a/drivers/video/via/via_clock.h
43975+++ b/drivers/video/via/via_clock.h
43976@@ -56,7 +56,7 @@ struct via_clock {
43977
43978 void (*set_engine_pll_state)(u8 state);
43979 void (*set_engine_pll)(struct via_pll_config config);
43980-};
43981+} __no_const;
43982
43983
43984 static inline u32 get_pll_internal_frequency(u32 ref_freq,
43985diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
43986index 6b1b7e1..b2fa4d5 100644
43987--- a/drivers/virtio/virtio_mmio.c
43988+++ b/drivers/virtio/virtio_mmio.c
43989@@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
43990
43991 resources[0].end = memparse(device, &str) - 1;
43992
43993- processed = sscanf(str, "@%lli:%u%n:%d%n",
43994+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
43995 &base, &resources[1].start, &consumed,
43996 &vm_cmdline_id, &consumed);
43997
43998diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
43999index fef20db..d28b1ab 100644
44000--- a/drivers/xen/xenfs/xenstored.c
44001+++ b/drivers/xen/xenfs/xenstored.c
44002@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44003 static int xsd_kva_open(struct inode *inode, struct file *file)
44004 {
44005 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44006+#ifdef CONFIG_GRKERNSEC_HIDESYM
44007+ NULL);
44008+#else
44009 xen_store_interface);
44010+#endif
44011+
44012 if (!file->private_data)
44013 return -ENOMEM;
44014 return 0;
44015diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44016index 890bed5..17ae73e 100644
44017--- a/fs/9p/vfs_inode.c
44018+++ b/fs/9p/vfs_inode.c
44019@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44020 void
44021 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44022 {
44023- char *s = nd_get_link(nd);
44024+ const char *s = nd_get_link(nd);
44025
44026 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44027 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44028diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44029index 0efd152..b5802ad 100644
44030--- a/fs/Kconfig.binfmt
44031+++ b/fs/Kconfig.binfmt
44032@@ -89,7 +89,7 @@ config HAVE_AOUT
44033
44034 config BINFMT_AOUT
44035 tristate "Kernel support for a.out and ECOFF binaries"
44036- depends on HAVE_AOUT
44037+ depends on HAVE_AOUT && BROKEN
44038 ---help---
44039 A.out (Assembler.OUTput) is a set of formats for libraries and
44040 executables used in the earliest versions of UNIX. Linux used
44041diff --git a/fs/aio.c b/fs/aio.c
44042index 71f613c..9d01f1f 100644
44043--- a/fs/aio.c
44044+++ b/fs/aio.c
44045@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44046 size += sizeof(struct io_event) * nr_events;
44047 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44048
44049- if (nr_pages < 0)
44050+ if (nr_pages <= 0)
44051 return -EINVAL;
44052
44053 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44054@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44055 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44056 {
44057 ssize_t ret;
44058+ struct iovec iovstack;
44059
44060 #ifdef CONFIG_COMPAT
44061 if (compat)
44062 ret = compat_rw_copy_check_uvector(type,
44063 (struct compat_iovec __user *)kiocb->ki_buf,
44064- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44065+ kiocb->ki_nbytes, 1, &iovstack,
44066 &kiocb->ki_iovec);
44067 else
44068 #endif
44069 ret = rw_copy_check_uvector(type,
44070 (struct iovec __user *)kiocb->ki_buf,
44071- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44072+ kiocb->ki_nbytes, 1, &iovstack,
44073 &kiocb->ki_iovec);
44074 if (ret < 0)
44075 goto out;
44076@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44077 if (ret < 0)
44078 goto out;
44079
44080+ if (kiocb->ki_iovec == &iovstack) {
44081+ kiocb->ki_inline_vec = iovstack;
44082+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
44083+ }
44084 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44085 kiocb->ki_cur_seg = 0;
44086 /* ki_nbytes/left now reflect bytes instead of segs */
44087diff --git a/fs/attr.c b/fs/attr.c
44088index cce7df5..eaa2731 100644
44089--- a/fs/attr.c
44090+++ b/fs/attr.c
44091@@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44092 unsigned long limit;
44093
44094 limit = rlimit(RLIMIT_FSIZE);
44095+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44096 if (limit != RLIM_INFINITY && offset > limit)
44097 goto out_sig;
44098 if (offset > inode->i_sb->s_maxbytes)
44099diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44100index dce436e..55e670d 100644
44101--- a/fs/autofs4/waitq.c
44102+++ b/fs/autofs4/waitq.c
44103@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44104 {
44105 unsigned long sigpipe, flags;
44106 mm_segment_t fs;
44107- const char *data = (const char *)addr;
44108+ const char __user *data = (const char __force_user *)addr;
44109 ssize_t wr = 0;
44110
44111 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44112@@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44113 return 1;
44114 }
44115
44116+#ifdef CONFIG_GRKERNSEC_HIDESYM
44117+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44118+#endif
44119+
44120 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44121 enum autofs_notify notify)
44122 {
44123@@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44124
44125 /* If this is a direct mount request create a dummy name */
44126 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44127+#ifdef CONFIG_GRKERNSEC_HIDESYM
44128+ /* this name does get written to userland via autofs4_write() */
44129+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44130+#else
44131 qstr.len = sprintf(name, "%p", dentry);
44132+#endif
44133 else {
44134 qstr.len = autofs4_getpath(sbi, dentry, &name);
44135 if (!qstr.len) {
44136diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44137index 2b3bda8..6a2d4be 100644
44138--- a/fs/befs/linuxvfs.c
44139+++ b/fs/befs/linuxvfs.c
44140@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44141 {
44142 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44143 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44144- char *link = nd_get_link(nd);
44145+ const char *link = nd_get_link(nd);
44146 if (!IS_ERR(link))
44147 kfree(link);
44148 }
44149diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44150index 0e7a6f8..332b1ca 100644
44151--- a/fs/binfmt_aout.c
44152+++ b/fs/binfmt_aout.c
44153@@ -16,6 +16,7 @@
44154 #include <linux/string.h>
44155 #include <linux/fs.h>
44156 #include <linux/file.h>
44157+#include <linux/security.h>
44158 #include <linux/stat.h>
44159 #include <linux/fcntl.h>
44160 #include <linux/ptrace.h>
44161@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44162 #endif
44163 # define START_STACK(u) ((void __user *)u.start_stack)
44164
44165+ memset(&dump, 0, sizeof(dump));
44166+
44167 fs = get_fs();
44168 set_fs(KERNEL_DS);
44169 has_dumped = 1;
44170@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44171
44172 /* If the size of the dump file exceeds the rlimit, then see what would happen
44173 if we wrote the stack, but not the data area. */
44174+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44175 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44176 dump.u_dsize = 0;
44177
44178 /* Make sure we have enough room to write the stack and data areas. */
44179+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44180 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44181 dump.u_ssize = 0;
44182
44183@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44184 rlim = rlimit(RLIMIT_DATA);
44185 if (rlim >= RLIM_INFINITY)
44186 rlim = ~0;
44187+
44188+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44189 if (ex.a_data + ex.a_bss > rlim)
44190 return -ENOMEM;
44191
44192@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44193
44194 install_exec_creds(bprm);
44195
44196+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44197+ current->mm->pax_flags = 0UL;
44198+#endif
44199+
44200+#ifdef CONFIG_PAX_PAGEEXEC
44201+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44202+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44203+
44204+#ifdef CONFIG_PAX_EMUTRAMP
44205+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44206+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44207+#endif
44208+
44209+#ifdef CONFIG_PAX_MPROTECT
44210+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44211+ current->mm->pax_flags |= MF_PAX_MPROTECT;
44212+#endif
44213+
44214+ }
44215+#endif
44216+
44217 if (N_MAGIC(ex) == OMAGIC) {
44218 unsigned long text_addr, map_size;
44219 loff_t pos;
44220@@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44221 }
44222
44223 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44224- PROT_READ | PROT_WRITE | PROT_EXEC,
44225+ PROT_READ | PROT_WRITE,
44226 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44227 fd_offset + ex.a_text);
44228 if (error != N_DATADDR(ex)) {
44229diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44230index fbd9f60..0b845dd 100644
44231--- a/fs/binfmt_elf.c
44232+++ b/fs/binfmt_elf.c
44233@@ -33,6 +33,7 @@
44234 #include <linux/elf.h>
44235 #include <linux/utsname.h>
44236 #include <linux/coredump.h>
44237+#include <linux/xattr.h>
44238 #include <asm/uaccess.h>
44239 #include <asm/param.h>
44240 #include <asm/page.h>
44241@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44242 #define elf_core_dump NULL
44243 #endif
44244
44245+#ifdef CONFIG_PAX_MPROTECT
44246+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44247+#endif
44248+
44249 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44250 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44251 #else
44252@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44253 .load_binary = load_elf_binary,
44254 .load_shlib = load_elf_library,
44255 .core_dump = elf_core_dump,
44256+
44257+#ifdef CONFIG_PAX_MPROTECT
44258+ .handle_mprotect= elf_handle_mprotect,
44259+#endif
44260+
44261 .min_coredump = ELF_EXEC_PAGESIZE,
44262 };
44263
44264@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44265
44266 static int set_brk(unsigned long start, unsigned long end)
44267 {
44268+ unsigned long e = end;
44269+
44270 start = ELF_PAGEALIGN(start);
44271 end = ELF_PAGEALIGN(end);
44272 if (end > start) {
44273@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44274 if (BAD_ADDR(addr))
44275 return addr;
44276 }
44277- current->mm->start_brk = current->mm->brk = end;
44278+ current->mm->start_brk = current->mm->brk = e;
44279 return 0;
44280 }
44281
44282@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44283 elf_addr_t __user *u_rand_bytes;
44284 const char *k_platform = ELF_PLATFORM;
44285 const char *k_base_platform = ELF_BASE_PLATFORM;
44286- unsigned char k_rand_bytes[16];
44287+ u32 k_rand_bytes[4];
44288 int items;
44289 elf_addr_t *elf_info;
44290 int ei_index = 0;
44291 const struct cred *cred = current_cred();
44292 struct vm_area_struct *vma;
44293+ unsigned long saved_auxv[AT_VECTOR_SIZE];
44294
44295 /*
44296 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44297@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44298 * Generate 16 random bytes for userspace PRNG seeding.
44299 */
44300 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44301- u_rand_bytes = (elf_addr_t __user *)
44302- STACK_ALLOC(p, sizeof(k_rand_bytes));
44303+ srandom32(k_rand_bytes[0] ^ random32());
44304+ srandom32(k_rand_bytes[1] ^ random32());
44305+ srandom32(k_rand_bytes[2] ^ random32());
44306+ srandom32(k_rand_bytes[3] ^ random32());
44307+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
44308+ u_rand_bytes = (elf_addr_t __user *) p;
44309 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44310 return -EFAULT;
44311
44312@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44313 return -EFAULT;
44314 current->mm->env_end = p;
44315
44316+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44317+
44318 /* Put the elf_info on the stack in the right place. */
44319 sp = (elf_addr_t __user *)envp + 1;
44320- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44321+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44322 return -EFAULT;
44323 return 0;
44324 }
44325@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44326 an ELF header */
44327
44328 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44329- struct file *interpreter, unsigned long *interp_map_addr,
44330- unsigned long no_base)
44331+ struct file *interpreter, unsigned long no_base)
44332 {
44333 struct elf_phdr *elf_phdata;
44334 struct elf_phdr *eppnt;
44335- unsigned long load_addr = 0;
44336+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44337 int load_addr_set = 0;
44338 unsigned long last_bss = 0, elf_bss = 0;
44339- unsigned long error = ~0UL;
44340+ unsigned long error = -EINVAL;
44341 unsigned long total_size;
44342 int retval, i, size;
44343
44344@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44345 goto out_close;
44346 }
44347
44348+#ifdef CONFIG_PAX_SEGMEXEC
44349+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44350+ pax_task_size = SEGMEXEC_TASK_SIZE;
44351+#endif
44352+
44353 eppnt = elf_phdata;
44354 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44355 if (eppnt->p_type == PT_LOAD) {
44356@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44357 map_addr = elf_map(interpreter, load_addr + vaddr,
44358 eppnt, elf_prot, elf_type, total_size);
44359 total_size = 0;
44360- if (!*interp_map_addr)
44361- *interp_map_addr = map_addr;
44362 error = map_addr;
44363 if (BAD_ADDR(map_addr))
44364 goto out_close;
44365@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44366 k = load_addr + eppnt->p_vaddr;
44367 if (BAD_ADDR(k) ||
44368 eppnt->p_filesz > eppnt->p_memsz ||
44369- eppnt->p_memsz > TASK_SIZE ||
44370- TASK_SIZE - eppnt->p_memsz < k) {
44371+ eppnt->p_memsz > pax_task_size ||
44372+ pax_task_size - eppnt->p_memsz < k) {
44373 error = -ENOMEM;
44374 goto out_close;
44375 }
44376@@ -530,6 +551,315 @@ out:
44377 return error;
44378 }
44379
44380+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44381+#ifdef CONFIG_PAX_SOFTMODE
44382+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44383+{
44384+ unsigned long pax_flags = 0UL;
44385+
44386+#ifdef CONFIG_PAX_PAGEEXEC
44387+ if (elf_phdata->p_flags & PF_PAGEEXEC)
44388+ pax_flags |= MF_PAX_PAGEEXEC;
44389+#endif
44390+
44391+#ifdef CONFIG_PAX_SEGMEXEC
44392+ if (elf_phdata->p_flags & PF_SEGMEXEC)
44393+ pax_flags |= MF_PAX_SEGMEXEC;
44394+#endif
44395+
44396+#ifdef CONFIG_PAX_EMUTRAMP
44397+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44398+ pax_flags |= MF_PAX_EMUTRAMP;
44399+#endif
44400+
44401+#ifdef CONFIG_PAX_MPROTECT
44402+ if (elf_phdata->p_flags & PF_MPROTECT)
44403+ pax_flags |= MF_PAX_MPROTECT;
44404+#endif
44405+
44406+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44407+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44408+ pax_flags |= MF_PAX_RANDMMAP;
44409+#endif
44410+
44411+ return pax_flags;
44412+}
44413+#endif
44414+
44415+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44416+{
44417+ unsigned long pax_flags = 0UL;
44418+
44419+#ifdef CONFIG_PAX_PAGEEXEC
44420+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44421+ pax_flags |= MF_PAX_PAGEEXEC;
44422+#endif
44423+
44424+#ifdef CONFIG_PAX_SEGMEXEC
44425+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44426+ pax_flags |= MF_PAX_SEGMEXEC;
44427+#endif
44428+
44429+#ifdef CONFIG_PAX_EMUTRAMP
44430+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44431+ pax_flags |= MF_PAX_EMUTRAMP;
44432+#endif
44433+
44434+#ifdef CONFIG_PAX_MPROTECT
44435+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44436+ pax_flags |= MF_PAX_MPROTECT;
44437+#endif
44438+
44439+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44440+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44441+ pax_flags |= MF_PAX_RANDMMAP;
44442+#endif
44443+
44444+ return pax_flags;
44445+}
44446+#endif
44447+
44448+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44449+#ifdef CONFIG_PAX_SOFTMODE
44450+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44451+{
44452+ unsigned long pax_flags = 0UL;
44453+
44454+#ifdef CONFIG_PAX_PAGEEXEC
44455+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44456+ pax_flags |= MF_PAX_PAGEEXEC;
44457+#endif
44458+
44459+#ifdef CONFIG_PAX_SEGMEXEC
44460+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44461+ pax_flags |= MF_PAX_SEGMEXEC;
44462+#endif
44463+
44464+#ifdef CONFIG_PAX_EMUTRAMP
44465+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44466+ pax_flags |= MF_PAX_EMUTRAMP;
44467+#endif
44468+
44469+#ifdef CONFIG_PAX_MPROTECT
44470+ if (pax_flags_softmode & MF_PAX_MPROTECT)
44471+ pax_flags |= MF_PAX_MPROTECT;
44472+#endif
44473+
44474+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44475+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44476+ pax_flags |= MF_PAX_RANDMMAP;
44477+#endif
44478+
44479+ return pax_flags;
44480+}
44481+#endif
44482+
44483+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44484+{
44485+ unsigned long pax_flags = 0UL;
44486+
44487+#ifdef CONFIG_PAX_PAGEEXEC
44488+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44489+ pax_flags |= MF_PAX_PAGEEXEC;
44490+#endif
44491+
44492+#ifdef CONFIG_PAX_SEGMEXEC
44493+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44494+ pax_flags |= MF_PAX_SEGMEXEC;
44495+#endif
44496+
44497+#ifdef CONFIG_PAX_EMUTRAMP
44498+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44499+ pax_flags |= MF_PAX_EMUTRAMP;
44500+#endif
44501+
44502+#ifdef CONFIG_PAX_MPROTECT
44503+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44504+ pax_flags |= MF_PAX_MPROTECT;
44505+#endif
44506+
44507+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44508+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44509+ pax_flags |= MF_PAX_RANDMMAP;
44510+#endif
44511+
44512+ return pax_flags;
44513+}
44514+#endif
44515+
44516+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44517+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44518+{
44519+ unsigned long pax_flags = 0UL;
44520+
44521+#ifdef CONFIG_PAX_EI_PAX
44522+
44523+#ifdef CONFIG_PAX_PAGEEXEC
44524+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44525+ pax_flags |= MF_PAX_PAGEEXEC;
44526+#endif
44527+
44528+#ifdef CONFIG_PAX_SEGMEXEC
44529+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44530+ pax_flags |= MF_PAX_SEGMEXEC;
44531+#endif
44532+
44533+#ifdef CONFIG_PAX_EMUTRAMP
44534+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44535+ pax_flags |= MF_PAX_EMUTRAMP;
44536+#endif
44537+
44538+#ifdef CONFIG_PAX_MPROTECT
44539+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44540+ pax_flags |= MF_PAX_MPROTECT;
44541+#endif
44542+
44543+#ifdef CONFIG_PAX_ASLR
44544+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44545+ pax_flags |= MF_PAX_RANDMMAP;
44546+#endif
44547+
44548+#else
44549+
44550+#ifdef CONFIG_PAX_PAGEEXEC
44551+ pax_flags |= MF_PAX_PAGEEXEC;
44552+#endif
44553+
44554+#ifdef CONFIG_PAX_SEGMEXEC
44555+ pax_flags |= MF_PAX_SEGMEXEC;
44556+#endif
44557+
44558+#ifdef CONFIG_PAX_MPROTECT
44559+ pax_flags |= MF_PAX_MPROTECT;
44560+#endif
44561+
44562+#ifdef CONFIG_PAX_RANDMMAP
44563+ if (randomize_va_space)
44564+ pax_flags |= MF_PAX_RANDMMAP;
44565+#endif
44566+
44567+#endif
44568+
44569+ return pax_flags;
44570+}
44571+
44572+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44573+{
44574+
44575+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44576+ unsigned long i;
44577+
44578+ for (i = 0UL; i < elf_ex->e_phnum; i++)
44579+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44580+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44581+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44582+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44583+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44584+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44585+ return ~0UL;
44586+
44587+#ifdef CONFIG_PAX_SOFTMODE
44588+ if (pax_softmode)
44589+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44590+ else
44591+#endif
44592+
44593+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44594+ break;
44595+ }
44596+#endif
44597+
44598+ return ~0UL;
44599+}
44600+
44601+static unsigned long pax_parse_xattr_pax(struct file * const file)
44602+{
44603+
44604+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44605+ ssize_t xattr_size, i;
44606+ unsigned char xattr_value[5];
44607+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44608+
44609+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44610+ if (xattr_size <= 0 || xattr_size > 5)
44611+ return ~0UL;
44612+
44613+ for (i = 0; i < xattr_size; i++)
44614+ switch (xattr_value[i]) {
44615+ default:
44616+ return ~0UL;
44617+
44618+#define parse_flag(option1, option2, flag) \
44619+ case option1: \
44620+ if (pax_flags_hardmode & MF_PAX_##flag) \
44621+ return ~0UL; \
44622+ pax_flags_hardmode |= MF_PAX_##flag; \
44623+ break; \
44624+ case option2: \
44625+ if (pax_flags_softmode & MF_PAX_##flag) \
44626+ return ~0UL; \
44627+ pax_flags_softmode |= MF_PAX_##flag; \
44628+ break;
44629+
44630+ parse_flag('p', 'P', PAGEEXEC);
44631+ parse_flag('e', 'E', EMUTRAMP);
44632+ parse_flag('m', 'M', MPROTECT);
44633+ parse_flag('r', 'R', RANDMMAP);
44634+ parse_flag('s', 'S', SEGMEXEC);
44635+
44636+#undef parse_flag
44637+ }
44638+
44639+ if (pax_flags_hardmode & pax_flags_softmode)
44640+ return ~0UL;
44641+
44642+#ifdef CONFIG_PAX_SOFTMODE
44643+ if (pax_softmode)
44644+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44645+ else
44646+#endif
44647+
44648+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44649+#else
44650+ return ~0UL;
44651+#endif
44652+
44653+}
44654+
44655+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44656+{
44657+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44658+
44659+ pax_flags = pax_parse_ei_pax(elf_ex);
44660+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44661+ xattr_pax_flags = pax_parse_xattr_pax(file);
44662+
44663+ if (pt_pax_flags == ~0UL)
44664+ pt_pax_flags = xattr_pax_flags;
44665+ else if (xattr_pax_flags == ~0UL)
44666+ xattr_pax_flags = pt_pax_flags;
44667+ if (pt_pax_flags != xattr_pax_flags)
44668+ return -EINVAL;
44669+ if (pt_pax_flags != ~0UL)
44670+ pax_flags = pt_pax_flags;
44671+
44672+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44673+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44674+ if ((__supported_pte_mask & _PAGE_NX))
44675+ pax_flags &= ~MF_PAX_SEGMEXEC;
44676+ else
44677+ pax_flags &= ~MF_PAX_PAGEEXEC;
44678+ }
44679+#endif
44680+
44681+ if (0 > pax_check_flags(&pax_flags))
44682+ return -EINVAL;
44683+
44684+ current->mm->pax_flags = pax_flags;
44685+ return 0;
44686+}
44687+#endif
44688+
44689 /*
44690 * These are the functions used to load ELF style executables and shared
44691 * libraries. There is no binary dependent code anywhere else.
44692@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44693 {
44694 unsigned int random_variable = 0;
44695
44696+#ifdef CONFIG_PAX_RANDUSTACK
44697+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
44698+ return stack_top - current->mm->delta_stack;
44699+#endif
44700+
44701 if ((current->flags & PF_RANDOMIZE) &&
44702 !(current->personality & ADDR_NO_RANDOMIZE)) {
44703 random_variable = get_random_int() & STACK_RND_MASK;
44704@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44705 unsigned long load_addr = 0, load_bias = 0;
44706 int load_addr_set = 0;
44707 char * elf_interpreter = NULL;
44708- unsigned long error;
44709+ unsigned long error = 0;
44710 struct elf_phdr *elf_ppnt, *elf_phdata;
44711 unsigned long elf_bss, elf_brk;
44712 int retval, i;
44713@@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44714 unsigned long start_code, end_code, start_data, end_data;
44715 unsigned long reloc_func_desc __maybe_unused = 0;
44716 int executable_stack = EXSTACK_DEFAULT;
44717- unsigned long def_flags = 0;
44718 struct {
44719 struct elfhdr elf_ex;
44720 struct elfhdr interp_elf_ex;
44721 } *loc;
44722+ unsigned long pax_task_size = TASK_SIZE;
44723
44724 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44725 if (!loc) {
44726@@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44727 goto out_free_dentry;
44728
44729 /* OK, This is the point of no return */
44730- current->mm->def_flags = def_flags;
44731+
44732+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44733+ current->mm->pax_flags = 0UL;
44734+#endif
44735+
44736+#ifdef CONFIG_PAX_DLRESOLVE
44737+ current->mm->call_dl_resolve = 0UL;
44738+#endif
44739+
44740+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44741+ current->mm->call_syscall = 0UL;
44742+#endif
44743+
44744+#ifdef CONFIG_PAX_ASLR
44745+ current->mm->delta_mmap = 0UL;
44746+ current->mm->delta_stack = 0UL;
44747+#endif
44748+
44749+ current->mm->def_flags = 0;
44750+
44751+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44752+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44753+ send_sig(SIGKILL, current, 0);
44754+ goto out_free_dentry;
44755+ }
44756+#endif
44757+
44758+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44759+ pax_set_initial_flags(bprm);
44760+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44761+ if (pax_set_initial_flags_func)
44762+ (pax_set_initial_flags_func)(bprm);
44763+#endif
44764+
44765+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44766+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44767+ current->mm->context.user_cs_limit = PAGE_SIZE;
44768+ current->mm->def_flags |= VM_PAGEEXEC;
44769+ }
44770+#endif
44771+
44772+#ifdef CONFIG_PAX_SEGMEXEC
44773+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44774+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44775+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44776+ pax_task_size = SEGMEXEC_TASK_SIZE;
44777+ current->mm->def_flags |= VM_NOHUGEPAGE;
44778+ }
44779+#endif
44780+
44781+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44782+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44783+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44784+ put_cpu();
44785+ }
44786+#endif
44787
44788 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44789 may depend on the personality. */
44790 SET_PERSONALITY(loc->elf_ex);
44791+
44792+#ifdef CONFIG_PAX_ASLR
44793+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44794+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
44795+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
44796+ }
44797+#endif
44798+
44799+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44800+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44801+ executable_stack = EXSTACK_DISABLE_X;
44802+ current->personality &= ~READ_IMPLIES_EXEC;
44803+ } else
44804+#endif
44805+
44806 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
44807 current->personality |= READ_IMPLIES_EXEC;
44808
44809@@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44810 #else
44811 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
44812 #endif
44813+
44814+#ifdef CONFIG_PAX_RANDMMAP
44815+ /* PaX: randomize base address at the default exe base if requested */
44816+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
44817+#ifdef CONFIG_SPARC64
44818+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
44819+#else
44820+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
44821+#endif
44822+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
44823+ elf_flags |= MAP_FIXED;
44824+ }
44825+#endif
44826+
44827 }
44828
44829 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
44830@@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44831 * allowed task size. Note that p_filesz must always be
44832 * <= p_memsz so it is only necessary to check p_memsz.
44833 */
44834- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44835- elf_ppnt->p_memsz > TASK_SIZE ||
44836- TASK_SIZE - elf_ppnt->p_memsz < k) {
44837+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44838+ elf_ppnt->p_memsz > pax_task_size ||
44839+ pax_task_size - elf_ppnt->p_memsz < k) {
44840 /* set_brk can never work. Avoid overflows. */
44841 send_sig(SIGKILL, current, 0);
44842 retval = -EINVAL;
44843@@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44844 goto out_free_dentry;
44845 }
44846 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
44847- send_sig(SIGSEGV, current, 0);
44848- retval = -EFAULT; /* Nobody gets to see this, but.. */
44849- goto out_free_dentry;
44850+ /*
44851+ * This bss-zeroing can fail if the ELF
44852+ * file specifies odd protections. So
44853+ * we don't check the return value
44854+ */
44855 }
44856
44857+#ifdef CONFIG_PAX_RANDMMAP
44858+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44859+ unsigned long start, size;
44860+
44861+ start = ELF_PAGEALIGN(elf_brk);
44862+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
44863+ down_read(&current->mm->mmap_sem);
44864+ retval = -ENOMEM;
44865+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
44866+ unsigned long prot = PROT_NONE;
44867+
44868+ up_read(&current->mm->mmap_sem);
44869+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
44870+// if (current->personality & ADDR_NO_RANDOMIZE)
44871+// prot = PROT_READ;
44872+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
44873+ retval = IS_ERR_VALUE(start) ? start : 0;
44874+ } else
44875+ up_read(&current->mm->mmap_sem);
44876+ if (retval == 0)
44877+ retval = set_brk(start + size, start + size + PAGE_SIZE);
44878+ if (retval < 0) {
44879+ send_sig(SIGKILL, current, 0);
44880+ goto out_free_dentry;
44881+ }
44882+ }
44883+#endif
44884+
44885 if (elf_interpreter) {
44886- unsigned long interp_map_addr = 0;
44887-
44888 elf_entry = load_elf_interp(&loc->interp_elf_ex,
44889 interpreter,
44890- &interp_map_addr,
44891 load_bias);
44892 if (!IS_ERR((void *)elf_entry)) {
44893 /*
44894@@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
44895 * Decide what to dump of a segment, part, all or none.
44896 */
44897 static unsigned long vma_dump_size(struct vm_area_struct *vma,
44898- unsigned long mm_flags)
44899+ unsigned long mm_flags, long signr)
44900 {
44901 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
44902
44903@@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
44904 if (vma->vm_file == NULL)
44905 return 0;
44906
44907- if (FILTER(MAPPED_PRIVATE))
44908+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
44909 goto whole;
44910
44911 /*
44912@@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
44913 {
44914 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
44915 int i = 0;
44916- do
44917+ do {
44918 i += 2;
44919- while (auxv[i - 2] != AT_NULL);
44920+ } while (auxv[i - 2] != AT_NULL);
44921 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
44922 }
44923
44924@@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
44925 }
44926
44927 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
44928- unsigned long mm_flags)
44929+ struct coredump_params *cprm)
44930 {
44931 struct vm_area_struct *vma;
44932 size_t size = 0;
44933
44934 for (vma = first_vma(current, gate_vma); vma != NULL;
44935 vma = next_vma(vma, gate_vma))
44936- size += vma_dump_size(vma, mm_flags);
44937+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44938 return size;
44939 }
44940
44941@@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44942
44943 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
44944
44945- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
44946+ offset += elf_core_vma_data_size(gate_vma, cprm);
44947 offset += elf_core_extra_data_size();
44948 e_shoff = offset;
44949
44950@@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
44951 offset = dataoff;
44952
44953 size += sizeof(*elf);
44954+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44955 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
44956 goto end_coredump;
44957
44958 size += sizeof(*phdr4note);
44959+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44960 if (size > cprm->limit
44961 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
44962 goto end_coredump;
44963@@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44964 phdr.p_offset = offset;
44965 phdr.p_vaddr = vma->vm_start;
44966 phdr.p_paddr = 0;
44967- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
44968+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44969 phdr.p_memsz = vma->vm_end - vma->vm_start;
44970 offset += phdr.p_filesz;
44971 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
44972@@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44973 phdr.p_align = ELF_EXEC_PAGESIZE;
44974
44975 size += sizeof(phdr);
44976+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
44977 if (size > cprm->limit
44978 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
44979 goto end_coredump;
44980@@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44981 unsigned long addr;
44982 unsigned long end;
44983
44984- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
44985+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
44986
44987 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
44988 struct page *page;
44989@@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44990 page = get_dump_page(addr);
44991 if (page) {
44992 void *kaddr = kmap(page);
44993+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
44994 stop = ((size += PAGE_SIZE) > cprm->limit) ||
44995 !dump_write(cprm->file, kaddr,
44996 PAGE_SIZE);
44997@@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
44998
44999 if (e_phnum == PN_XNUM) {
45000 size += sizeof(*shdr4extnum);
45001+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45002 if (size > cprm->limit
45003 || !dump_write(cprm->file, shdr4extnum,
45004 sizeof(*shdr4extnum)))
45005@@ -2216,6 +2667,97 @@ out:
45006
45007 #endif /* CONFIG_ELF_CORE */
45008
45009+#ifdef CONFIG_PAX_MPROTECT
45010+/* PaX: non-PIC ELF libraries need relocations on their executable segments
45011+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45012+ * we'll remove VM_MAYWRITE for good on RELRO segments.
45013+ *
45014+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45015+ * basis because we want to allow the common case and not the special ones.
45016+ */
45017+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45018+{
45019+ struct elfhdr elf_h;
45020+ struct elf_phdr elf_p;
45021+ unsigned long i;
45022+ unsigned long oldflags;
45023+ bool is_textrel_rw, is_textrel_rx, is_relro;
45024+
45025+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45026+ return;
45027+
45028+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45029+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45030+
45031+#ifdef CONFIG_PAX_ELFRELOCS
45032+ /* possible TEXTREL */
45033+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45034+ 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);
45035+#else
45036+ is_textrel_rw = false;
45037+ is_textrel_rx = false;
45038+#endif
45039+
45040+ /* possible RELRO */
45041+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45042+
45043+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45044+ return;
45045+
45046+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45047+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45048+
45049+#ifdef CONFIG_PAX_ETEXECRELOCS
45050+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45051+#else
45052+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45053+#endif
45054+
45055+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45056+ !elf_check_arch(&elf_h) ||
45057+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45058+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45059+ return;
45060+
45061+ for (i = 0UL; i < elf_h.e_phnum; i++) {
45062+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45063+ return;
45064+ switch (elf_p.p_type) {
45065+ case PT_DYNAMIC:
45066+ if (!is_textrel_rw && !is_textrel_rx)
45067+ continue;
45068+ i = 0UL;
45069+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45070+ elf_dyn dyn;
45071+
45072+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45073+ return;
45074+ if (dyn.d_tag == DT_NULL)
45075+ return;
45076+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45077+ gr_log_textrel(vma);
45078+ if (is_textrel_rw)
45079+ vma->vm_flags |= VM_MAYWRITE;
45080+ else
45081+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45082+ vma->vm_flags &= ~VM_MAYWRITE;
45083+ return;
45084+ }
45085+ i++;
45086+ }
45087+ return;
45088+
45089+ case PT_GNU_RELRO:
45090+ if (!is_relro)
45091+ continue;
45092+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45093+ vma->vm_flags &= ~VM_MAYWRITE;
45094+ return;
45095+ }
45096+ }
45097+}
45098+#endif
45099+
45100 static int __init init_elf_binfmt(void)
45101 {
45102 register_binfmt(&elf_format);
45103diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45104index e280352..7b2f231 100644
45105--- a/fs/binfmt_flat.c
45106+++ b/fs/binfmt_flat.c
45107@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45108 realdatastart = (unsigned long) -ENOMEM;
45109 printk("Unable to allocate RAM for process data, errno %d\n",
45110 (int)-realdatastart);
45111+ down_write(&current->mm->mmap_sem);
45112 vm_munmap(textpos, text_len);
45113+ up_write(&current->mm->mmap_sem);
45114 ret = realdatastart;
45115 goto err;
45116 }
45117@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45118 }
45119 if (IS_ERR_VALUE(result)) {
45120 printk("Unable to read data+bss, errno %d\n", (int)-result);
45121+ down_write(&current->mm->mmap_sem);
45122 vm_munmap(textpos, text_len);
45123 vm_munmap(realdatastart, len);
45124+ up_write(&current->mm->mmap_sem);
45125 ret = result;
45126 goto err;
45127 }
45128@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45129 }
45130 if (IS_ERR_VALUE(result)) {
45131 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45132+ down_write(&current->mm->mmap_sem);
45133 vm_munmap(textpos, text_len + data_len + extra +
45134 MAX_SHARED_LIBS * sizeof(unsigned long));
45135+ up_write(&current->mm->mmap_sem);
45136 ret = result;
45137 goto err;
45138 }
45139diff --git a/fs/bio.c b/fs/bio.c
45140index b96fc6c..431d628 100644
45141--- a/fs/bio.c
45142+++ b/fs/bio.c
45143@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45144 /*
45145 * Overflow, abort
45146 */
45147- if (end < start)
45148+ if (end < start || end - start > INT_MAX - nr_pages)
45149 return ERR_PTR(-EINVAL);
45150
45151 nr_pages += end - start;
45152@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45153 /*
45154 * Overflow, abort
45155 */
45156- if (end < start)
45157+ if (end < start || end - start > INT_MAX - nr_pages)
45158 return ERR_PTR(-EINVAL);
45159
45160 nr_pages += end - start;
45161@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45162 const int read = bio_data_dir(bio) == READ;
45163 struct bio_map_data *bmd = bio->bi_private;
45164 int i;
45165- char *p = bmd->sgvecs[0].iov_base;
45166+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45167
45168 __bio_for_each_segment(bvec, bio, i, 0) {
45169 char *addr = page_address(bvec->bv_page);
45170diff --git a/fs/block_dev.c b/fs/block_dev.c
45171index ab3a456..7da538b 100644
45172--- a/fs/block_dev.c
45173+++ b/fs/block_dev.c
45174@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45175 else if (bdev->bd_contains == bdev)
45176 return true; /* is a whole device which isn't held */
45177
45178- else if (whole->bd_holder == bd_may_claim)
45179+ else if (whole->bd_holder == (void *)bd_may_claim)
45180 return true; /* is a partition of a device that is being partitioned */
45181 else if (whole->bd_holder != NULL)
45182 return false; /* is a partition of a held device */
45183diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45184index cdfb4c4..da736d4 100644
45185--- a/fs/btrfs/ctree.c
45186+++ b/fs/btrfs/ctree.c
45187@@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45188 free_extent_buffer(buf);
45189 add_root_to_dirty_list(root);
45190 } else {
45191- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45192- parent_start = parent->start;
45193- else
45194+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45195+ if (parent)
45196+ parent_start = parent->start;
45197+ else
45198+ parent_start = 0;
45199+ } else
45200 parent_start = 0;
45201
45202 WARN_ON(trans->transid != btrfs_header_generation(parent));
45203diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45204index 95542a1..95a8727 100644
45205--- a/fs/btrfs/inode.c
45206+++ b/fs/btrfs/inode.c
45207@@ -7243,7 +7243,7 @@ fail:
45208 return -ENOMEM;
45209 }
45210
45211-static int btrfs_getattr(struct vfsmount *mnt,
45212+int btrfs_getattr(struct vfsmount *mnt,
45213 struct dentry *dentry, struct kstat *stat)
45214 {
45215 struct inode *inode = dentry->d_inode;
45216@@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45217 return 0;
45218 }
45219
45220+EXPORT_SYMBOL(btrfs_getattr);
45221+
45222+dev_t get_btrfs_dev_from_inode(struct inode *inode)
45223+{
45224+ return BTRFS_I(inode)->root->anon_dev;
45225+}
45226+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45227+
45228 /*
45229 * If a file is moved, it will inherit the cow and compression flags of the new
45230 * directory.
45231diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45232index 8fcf9a5..a200000 100644
45233--- a/fs/btrfs/ioctl.c
45234+++ b/fs/btrfs/ioctl.c
45235@@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45236 for (i = 0; i < num_types; i++) {
45237 struct btrfs_space_info *tmp;
45238
45239+ /* Don't copy in more than we allocated */
45240 if (!slot_count)
45241 break;
45242
45243+ slot_count--;
45244+
45245 info = NULL;
45246 rcu_read_lock();
45247 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45248@@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45249 memcpy(dest, &space, sizeof(space));
45250 dest++;
45251 space_args.total_spaces++;
45252- slot_count--;
45253 }
45254- if (!slot_count)
45255- break;
45256 }
45257 up_read(&info->groups_sem);
45258 }
45259diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45260index 776f0aa..3aad281 100644
45261--- a/fs/btrfs/relocation.c
45262+++ b/fs/btrfs/relocation.c
45263@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45264 }
45265 spin_unlock(&rc->reloc_root_tree.lock);
45266
45267- BUG_ON((struct btrfs_root *)node->data != root);
45268+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
45269
45270 if (!del) {
45271 spin_lock(&rc->reloc_root_tree.lock);
45272diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45273index 622f469..e8d2d55 100644
45274--- a/fs/cachefiles/bind.c
45275+++ b/fs/cachefiles/bind.c
45276@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45277 args);
45278
45279 /* start by checking things over */
45280- ASSERT(cache->fstop_percent >= 0 &&
45281- cache->fstop_percent < cache->fcull_percent &&
45282+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
45283 cache->fcull_percent < cache->frun_percent &&
45284 cache->frun_percent < 100);
45285
45286- ASSERT(cache->bstop_percent >= 0 &&
45287- cache->bstop_percent < cache->bcull_percent &&
45288+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
45289 cache->bcull_percent < cache->brun_percent &&
45290 cache->brun_percent < 100);
45291
45292diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45293index 0a1467b..6a53245 100644
45294--- a/fs/cachefiles/daemon.c
45295+++ b/fs/cachefiles/daemon.c
45296@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45297 if (n > buflen)
45298 return -EMSGSIZE;
45299
45300- if (copy_to_user(_buffer, buffer, n) != 0)
45301+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45302 return -EFAULT;
45303
45304 return n;
45305@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45306 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45307 return -EIO;
45308
45309- if (datalen < 0 || datalen > PAGE_SIZE - 1)
45310+ if (datalen > PAGE_SIZE - 1)
45311 return -EOPNOTSUPP;
45312
45313 /* drag the command string into the kernel so we can parse it */
45314@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45315 if (args[0] != '%' || args[1] != '\0')
45316 return -EINVAL;
45317
45318- if (fstop < 0 || fstop >= cache->fcull_percent)
45319+ if (fstop >= cache->fcull_percent)
45320 return cachefiles_daemon_range_error(cache, args);
45321
45322 cache->fstop_percent = fstop;
45323@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45324 if (args[0] != '%' || args[1] != '\0')
45325 return -EINVAL;
45326
45327- if (bstop < 0 || bstop >= cache->bcull_percent)
45328+ if (bstop >= cache->bcull_percent)
45329 return cachefiles_daemon_range_error(cache, args);
45330
45331 cache->bstop_percent = bstop;
45332diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45333index bd6bc1b..b627b53 100644
45334--- a/fs/cachefiles/internal.h
45335+++ b/fs/cachefiles/internal.h
45336@@ -57,7 +57,7 @@ struct cachefiles_cache {
45337 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45338 struct rb_root active_nodes; /* active nodes (can't be culled) */
45339 rwlock_t active_lock; /* lock for active_nodes */
45340- atomic_t gravecounter; /* graveyard uniquifier */
45341+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45342 unsigned frun_percent; /* when to stop culling (% files) */
45343 unsigned fcull_percent; /* when to start culling (% files) */
45344 unsigned fstop_percent; /* when to stop allocating (% files) */
45345@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45346 * proc.c
45347 */
45348 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45349-extern atomic_t cachefiles_lookup_histogram[HZ];
45350-extern atomic_t cachefiles_mkdir_histogram[HZ];
45351-extern atomic_t cachefiles_create_histogram[HZ];
45352+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45353+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45354+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45355
45356 extern int __init cachefiles_proc_init(void);
45357 extern void cachefiles_proc_cleanup(void);
45358 static inline
45359-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45360+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45361 {
45362 unsigned long jif = jiffies - start_jif;
45363 if (jif >= HZ)
45364 jif = HZ - 1;
45365- atomic_inc(&histogram[jif]);
45366+ atomic_inc_unchecked(&histogram[jif]);
45367 }
45368
45369 #else
45370diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45371index b0b5f7c..039bb26 100644
45372--- a/fs/cachefiles/namei.c
45373+++ b/fs/cachefiles/namei.c
45374@@ -318,7 +318,7 @@ try_again:
45375 /* first step is to make up a grave dentry in the graveyard */
45376 sprintf(nbuffer, "%08x%08x",
45377 (uint32_t) get_seconds(),
45378- (uint32_t) atomic_inc_return(&cache->gravecounter));
45379+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45380
45381 /* do the multiway lock magic */
45382 trap = lock_rename(cache->graveyard, dir);
45383diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45384index eccd339..4c1d995 100644
45385--- a/fs/cachefiles/proc.c
45386+++ b/fs/cachefiles/proc.c
45387@@ -14,9 +14,9 @@
45388 #include <linux/seq_file.h>
45389 #include "internal.h"
45390
45391-atomic_t cachefiles_lookup_histogram[HZ];
45392-atomic_t cachefiles_mkdir_histogram[HZ];
45393-atomic_t cachefiles_create_histogram[HZ];
45394+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45395+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45396+atomic_unchecked_t cachefiles_create_histogram[HZ];
45397
45398 /*
45399 * display the latency histogram
45400@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45401 return 0;
45402 default:
45403 index = (unsigned long) v - 3;
45404- x = atomic_read(&cachefiles_lookup_histogram[index]);
45405- y = atomic_read(&cachefiles_mkdir_histogram[index]);
45406- z = atomic_read(&cachefiles_create_histogram[index]);
45407+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45408+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45409+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45410 if (x == 0 && y == 0 && z == 0)
45411 return 0;
45412
45413diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45414index c994691..2a1537f 100644
45415--- a/fs/cachefiles/rdwr.c
45416+++ b/fs/cachefiles/rdwr.c
45417@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45418 old_fs = get_fs();
45419 set_fs(KERNEL_DS);
45420 ret = file->f_op->write(
45421- file, (const void __user *) data, len, &pos);
45422+ file, (const void __force_user *) data, len, &pos);
45423 set_fs(old_fs);
45424 kunmap(page);
45425 if (ret != len)
45426diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45427index e5b7731..b9c59fb 100644
45428--- a/fs/ceph/dir.c
45429+++ b/fs/ceph/dir.c
45430@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45431 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45432 struct ceph_mds_client *mdsc = fsc->mdsc;
45433 unsigned frag = fpos_frag(filp->f_pos);
45434- int off = fpos_off(filp->f_pos);
45435+ unsigned int off = fpos_off(filp->f_pos);
45436 int err;
45437 u32 ftype;
45438 struct ceph_mds_reply_info_parsed *rinfo;
45439diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45440index d9ea6ed..1e6c8ac 100644
45441--- a/fs/cifs/cifs_debug.c
45442+++ b/fs/cifs/cifs_debug.c
45443@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45444
45445 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45446 #ifdef CONFIG_CIFS_STATS2
45447- atomic_set(&totBufAllocCount, 0);
45448- atomic_set(&totSmBufAllocCount, 0);
45449+ atomic_set_unchecked(&totBufAllocCount, 0);
45450+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45451 #endif /* CONFIG_CIFS_STATS2 */
45452 spin_lock(&cifs_tcp_ses_lock);
45453 list_for_each(tmp1, &cifs_tcp_ses_list) {
45454@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45455 tcon = list_entry(tmp3,
45456 struct cifs_tcon,
45457 tcon_list);
45458- atomic_set(&tcon->num_smbs_sent, 0);
45459+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45460 if (server->ops->clear_stats)
45461 server->ops->clear_stats(tcon);
45462 }
45463@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45464 smBufAllocCount.counter, cifs_min_small);
45465 #ifdef CONFIG_CIFS_STATS2
45466 seq_printf(m, "Total Large %d Small %d Allocations\n",
45467- atomic_read(&totBufAllocCount),
45468- atomic_read(&totSmBufAllocCount));
45469+ atomic_read_unchecked(&totBufAllocCount),
45470+ atomic_read_unchecked(&totSmBufAllocCount));
45471 #endif /* CONFIG_CIFS_STATS2 */
45472
45473 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45474@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45475 if (tcon->need_reconnect)
45476 seq_puts(m, "\tDISCONNECTED ");
45477 seq_printf(m, "\nSMBs: %d",
45478- atomic_read(&tcon->num_smbs_sent));
45479+ atomic_read_unchecked(&tcon->num_smbs_sent));
45480 if (server->ops->print_stats)
45481 server->ops->print_stats(m, tcon);
45482 }
45483diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45484index e7931cc..76a1ab9 100644
45485--- a/fs/cifs/cifsfs.c
45486+++ b/fs/cifs/cifsfs.c
45487@@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45488 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45489 cifs_req_cachep = kmem_cache_create("cifs_request",
45490 CIFSMaxBufSize + max_hdr_size, 0,
45491- SLAB_HWCACHE_ALIGN, NULL);
45492+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45493 if (cifs_req_cachep == NULL)
45494 return -ENOMEM;
45495
45496@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45497 efficient to alloc 1 per page off the slab compared to 17K (5page)
45498 alloc of large cifs buffers even when page debugging is on */
45499 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45500- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45501+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45502 NULL);
45503 if (cifs_sm_req_cachep == NULL) {
45504 mempool_destroy(cifs_req_poolp);
45505@@ -1111,8 +1111,8 @@ init_cifs(void)
45506 atomic_set(&bufAllocCount, 0);
45507 atomic_set(&smBufAllocCount, 0);
45508 #ifdef CONFIG_CIFS_STATS2
45509- atomic_set(&totBufAllocCount, 0);
45510- atomic_set(&totSmBufAllocCount, 0);
45511+ atomic_set_unchecked(&totBufAllocCount, 0);
45512+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45513 #endif /* CONFIG_CIFS_STATS2 */
45514
45515 atomic_set(&midCount, 0);
45516diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45517index f5af252..489b5f2 100644
45518--- a/fs/cifs/cifsglob.h
45519+++ b/fs/cifs/cifsglob.h
45520@@ -751,35 +751,35 @@ struct cifs_tcon {
45521 __u16 Flags; /* optional support bits */
45522 enum statusEnum tidStatus;
45523 #ifdef CONFIG_CIFS_STATS
45524- atomic_t num_smbs_sent;
45525+ atomic_unchecked_t num_smbs_sent;
45526 union {
45527 struct {
45528- atomic_t num_writes;
45529- atomic_t num_reads;
45530- atomic_t num_flushes;
45531- atomic_t num_oplock_brks;
45532- atomic_t num_opens;
45533- atomic_t num_closes;
45534- atomic_t num_deletes;
45535- atomic_t num_mkdirs;
45536- atomic_t num_posixopens;
45537- atomic_t num_posixmkdirs;
45538- atomic_t num_rmdirs;
45539- atomic_t num_renames;
45540- atomic_t num_t2renames;
45541- atomic_t num_ffirst;
45542- atomic_t num_fnext;
45543- atomic_t num_fclose;
45544- atomic_t num_hardlinks;
45545- atomic_t num_symlinks;
45546- atomic_t num_locks;
45547- atomic_t num_acl_get;
45548- atomic_t num_acl_set;
45549+ atomic_unchecked_t num_writes;
45550+ atomic_unchecked_t num_reads;
45551+ atomic_unchecked_t num_flushes;
45552+ atomic_unchecked_t num_oplock_brks;
45553+ atomic_unchecked_t num_opens;
45554+ atomic_unchecked_t num_closes;
45555+ atomic_unchecked_t num_deletes;
45556+ atomic_unchecked_t num_mkdirs;
45557+ atomic_unchecked_t num_posixopens;
45558+ atomic_unchecked_t num_posixmkdirs;
45559+ atomic_unchecked_t num_rmdirs;
45560+ atomic_unchecked_t num_renames;
45561+ atomic_unchecked_t num_t2renames;
45562+ atomic_unchecked_t num_ffirst;
45563+ atomic_unchecked_t num_fnext;
45564+ atomic_unchecked_t num_fclose;
45565+ atomic_unchecked_t num_hardlinks;
45566+ atomic_unchecked_t num_symlinks;
45567+ atomic_unchecked_t num_locks;
45568+ atomic_unchecked_t num_acl_get;
45569+ atomic_unchecked_t num_acl_set;
45570 } cifs_stats;
45571 #ifdef CONFIG_CIFS_SMB2
45572 struct {
45573- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45574- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45575+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45576+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45577 } smb2_stats;
45578 #endif /* CONFIG_CIFS_SMB2 */
45579 } stats;
45580@@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45581 }
45582
45583 #ifdef CONFIG_CIFS_STATS
45584-#define cifs_stats_inc atomic_inc
45585+#define cifs_stats_inc atomic_inc_unchecked
45586
45587 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45588 unsigned int bytes)
45589@@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45590 /* Various Debug counters */
45591 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45592 #ifdef CONFIG_CIFS_STATS2
45593-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45594-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45595+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45596+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45597 #endif
45598 GLOBAL_EXTERN atomic_t smBufAllocCount;
45599 GLOBAL_EXTERN atomic_t midCount;
45600diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45601index 51dc2fb..1e12a33 100644
45602--- a/fs/cifs/link.c
45603+++ b/fs/cifs/link.c
45604@@ -616,7 +616,7 @@ symlink_exit:
45605
45606 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45607 {
45608- char *p = nd_get_link(nd);
45609+ const char *p = nd_get_link(nd);
45610 if (!IS_ERR(p))
45611 kfree(p);
45612 }
45613diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45614index 3a00c0d..42d901c 100644
45615--- a/fs/cifs/misc.c
45616+++ b/fs/cifs/misc.c
45617@@ -169,7 +169,7 @@ cifs_buf_get(void)
45618 memset(ret_buf, 0, buf_size + 3);
45619 atomic_inc(&bufAllocCount);
45620 #ifdef CONFIG_CIFS_STATS2
45621- atomic_inc(&totBufAllocCount);
45622+ atomic_inc_unchecked(&totBufAllocCount);
45623 #endif /* CONFIG_CIFS_STATS2 */
45624 }
45625
45626@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45627 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45628 atomic_inc(&smBufAllocCount);
45629 #ifdef CONFIG_CIFS_STATS2
45630- atomic_inc(&totSmBufAllocCount);
45631+ atomic_inc_unchecked(&totSmBufAllocCount);
45632 #endif /* CONFIG_CIFS_STATS2 */
45633
45634 }
45635diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45636index 591bf19..690d600 100644
45637--- a/fs/cifs/smb1ops.c
45638+++ b/fs/cifs/smb1ops.c
45639@@ -617,27 +617,27 @@ static void
45640 cifs_clear_stats(struct cifs_tcon *tcon)
45641 {
45642 #ifdef CONFIG_CIFS_STATS
45643- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45644- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45645- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45646- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45647- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45648- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45649- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45650- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45651- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45652- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45653- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45654- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45655- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45656- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45657- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45658- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45659- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45660- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45661- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45662- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45663- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45664+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45665+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45666+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45667+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45668+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45669+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45670+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45671+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45672+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45673+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45674+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45675+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45676+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45677+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45678+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45679+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45680+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45681+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45682+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45683+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45684+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45685 #endif
45686 }
45687
45688@@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45689 {
45690 #ifdef CONFIG_CIFS_STATS
45691 seq_printf(m, " Oplocks breaks: %d",
45692- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45693+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45694 seq_printf(m, "\nReads: %d Bytes: %llu",
45695- atomic_read(&tcon->stats.cifs_stats.num_reads),
45696+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45697 (long long)(tcon->bytes_read));
45698 seq_printf(m, "\nWrites: %d Bytes: %llu",
45699- atomic_read(&tcon->stats.cifs_stats.num_writes),
45700+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45701 (long long)(tcon->bytes_written));
45702 seq_printf(m, "\nFlushes: %d",
45703- atomic_read(&tcon->stats.cifs_stats.num_flushes));
45704+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45705 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45706- atomic_read(&tcon->stats.cifs_stats.num_locks),
45707- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45708- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45709+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45710+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45711+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45712 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45713- atomic_read(&tcon->stats.cifs_stats.num_opens),
45714- atomic_read(&tcon->stats.cifs_stats.num_closes),
45715- atomic_read(&tcon->stats.cifs_stats.num_deletes));
45716+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45717+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45718+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45719 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45720- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45721- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45722+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45723+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45724 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45725- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45726- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45727+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45728+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45729 seq_printf(m, "\nRenames: %d T2 Renames %d",
45730- atomic_read(&tcon->stats.cifs_stats.num_renames),
45731- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45732+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45733+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45734 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45735- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45736- atomic_read(&tcon->stats.cifs_stats.num_fnext),
45737- atomic_read(&tcon->stats.cifs_stats.num_fclose));
45738+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45739+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45740+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45741 #endif
45742 }
45743
45744diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45745index 4d9dbe0..0af4601 100644
45746--- a/fs/cifs/smb2ops.c
45747+++ b/fs/cifs/smb2ops.c
45748@@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45749 #ifdef CONFIG_CIFS_STATS
45750 int i;
45751 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45752- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45753- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45754+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45755+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45756 }
45757 #endif
45758 }
45759@@ -301,66 +301,66 @@ static void
45760 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45761 {
45762 #ifdef CONFIG_CIFS_STATS
45763- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45764- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45765+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45766+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45767 seq_printf(m, "\nNegotiates: %d sent %d failed",
45768- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45769- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45770+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45771+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45772 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45773- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45774- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45775+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45776+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45777 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45778 seq_printf(m, "\nLogoffs: %d sent %d failed",
45779- atomic_read(&sent[SMB2_LOGOFF_HE]),
45780- atomic_read(&failed[SMB2_LOGOFF_HE]));
45781+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45782+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45783 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45784- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45785- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45786+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45787+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45788 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45789- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
45790- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
45791+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
45792+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
45793 seq_printf(m, "\nCreates: %d sent %d failed",
45794- atomic_read(&sent[SMB2_CREATE_HE]),
45795- atomic_read(&failed[SMB2_CREATE_HE]));
45796+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
45797+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
45798 seq_printf(m, "\nCloses: %d sent %d failed",
45799- atomic_read(&sent[SMB2_CLOSE_HE]),
45800- atomic_read(&failed[SMB2_CLOSE_HE]));
45801+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
45802+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
45803 seq_printf(m, "\nFlushes: %d sent %d failed",
45804- atomic_read(&sent[SMB2_FLUSH_HE]),
45805- atomic_read(&failed[SMB2_FLUSH_HE]));
45806+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
45807+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
45808 seq_printf(m, "\nReads: %d sent %d failed",
45809- atomic_read(&sent[SMB2_READ_HE]),
45810- atomic_read(&failed[SMB2_READ_HE]));
45811+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
45812+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
45813 seq_printf(m, "\nWrites: %d sent %d failed",
45814- atomic_read(&sent[SMB2_WRITE_HE]),
45815- atomic_read(&failed[SMB2_WRITE_HE]));
45816+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
45817+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
45818 seq_printf(m, "\nLocks: %d sent %d failed",
45819- atomic_read(&sent[SMB2_LOCK_HE]),
45820- atomic_read(&failed[SMB2_LOCK_HE]));
45821+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
45822+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
45823 seq_printf(m, "\nIOCTLs: %d sent %d failed",
45824- atomic_read(&sent[SMB2_IOCTL_HE]),
45825- atomic_read(&failed[SMB2_IOCTL_HE]));
45826+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
45827+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
45828 seq_printf(m, "\nCancels: %d sent %d failed",
45829- atomic_read(&sent[SMB2_CANCEL_HE]),
45830- atomic_read(&failed[SMB2_CANCEL_HE]));
45831+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
45832+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
45833 seq_printf(m, "\nEchos: %d sent %d failed",
45834- atomic_read(&sent[SMB2_ECHO_HE]),
45835- atomic_read(&failed[SMB2_ECHO_HE]));
45836+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
45837+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
45838 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
45839- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
45840- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
45841+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
45842+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
45843 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
45844- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
45845- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
45846+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
45847+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
45848 seq_printf(m, "\nQueryInfos: %d sent %d failed",
45849- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
45850- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
45851+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
45852+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
45853 seq_printf(m, "\nSetInfos: %d sent %d failed",
45854- atomic_read(&sent[SMB2_SET_INFO_HE]),
45855- atomic_read(&failed[SMB2_SET_INFO_HE]));
45856+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
45857+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
45858 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
45859- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
45860- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
45861+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
45862+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
45863 #endif
45864 }
45865
45866diff --git a/fs/coda/cache.c b/fs/coda/cache.c
45867index 958ae0e..505c9d0 100644
45868--- a/fs/coda/cache.c
45869+++ b/fs/coda/cache.c
45870@@ -24,7 +24,7 @@
45871 #include "coda_linux.h"
45872 #include "coda_cache.h"
45873
45874-static atomic_t permission_epoch = ATOMIC_INIT(0);
45875+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
45876
45877 /* replace or extend an acl cache hit */
45878 void coda_cache_enter(struct inode *inode, int mask)
45879@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
45880 struct coda_inode_info *cii = ITOC(inode);
45881
45882 spin_lock(&cii->c_lock);
45883- cii->c_cached_epoch = atomic_read(&permission_epoch);
45884+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
45885 if (cii->c_uid != current_fsuid()) {
45886 cii->c_uid = current_fsuid();
45887 cii->c_cached_perm = mask;
45888@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
45889 {
45890 struct coda_inode_info *cii = ITOC(inode);
45891 spin_lock(&cii->c_lock);
45892- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
45893+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
45894 spin_unlock(&cii->c_lock);
45895 }
45896
45897 /* remove all acl caches */
45898 void coda_cache_clear_all(struct super_block *sb)
45899 {
45900- atomic_inc(&permission_epoch);
45901+ atomic_inc_unchecked(&permission_epoch);
45902 }
45903
45904
45905@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
45906 spin_lock(&cii->c_lock);
45907 hit = (mask & cii->c_cached_perm) == mask &&
45908 cii->c_uid == current_fsuid() &&
45909- cii->c_cached_epoch == atomic_read(&permission_epoch);
45910+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
45911 spin_unlock(&cii->c_lock);
45912
45913 return hit;
45914diff --git a/fs/compat.c b/fs/compat.c
45915index 015e1e1..5ce8e54 100644
45916--- a/fs/compat.c
45917+++ b/fs/compat.c
45918@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
45919
45920 set_fs(KERNEL_DS);
45921 /* The __user pointer cast is valid because of the set_fs() */
45922- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
45923+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
45924 set_fs(oldfs);
45925 /* truncating is ok because it's a user address */
45926 if (!ret)
45927@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
45928 goto out;
45929
45930 ret = -EINVAL;
45931- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
45932+ if (nr_segs > UIO_MAXIOV)
45933 goto out;
45934 if (nr_segs > fast_segs) {
45935 ret = -ENOMEM;
45936@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
45937
45938 struct compat_readdir_callback {
45939 struct compat_old_linux_dirent __user *dirent;
45940+ struct file * file;
45941 int result;
45942 };
45943
45944@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
45945 buf->result = -EOVERFLOW;
45946 return -EOVERFLOW;
45947 }
45948+
45949+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45950+ return 0;
45951+
45952 buf->result++;
45953 dirent = buf->dirent;
45954 if (!access_ok(VERIFY_WRITE, dirent,
45955@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
45956
45957 buf.result = 0;
45958 buf.dirent = dirent;
45959+ buf.file = f.file;
45960
45961 error = vfs_readdir(f.file, compat_fillonedir, &buf);
45962 if (buf.result)
45963@@ -897,6 +903,7 @@ struct compat_linux_dirent {
45964 struct compat_getdents_callback {
45965 struct compat_linux_dirent __user *current_dir;
45966 struct compat_linux_dirent __user *previous;
45967+ struct file * file;
45968 int count;
45969 int error;
45970 };
45971@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
45972 buf->error = -EOVERFLOW;
45973 return -EOVERFLOW;
45974 }
45975+
45976+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
45977+ return 0;
45978+
45979 dirent = buf->previous;
45980 if (dirent) {
45981 if (__put_user(offset, &dirent->d_off))
45982@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45983 buf.previous = NULL;
45984 buf.count = count;
45985 buf.error = 0;
45986+ buf.file = f.file;
45987
45988 error = vfs_readdir(f.file, compat_filldir, &buf);
45989 if (error >= 0)
45990@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
45991 struct compat_getdents_callback64 {
45992 struct linux_dirent64 __user *current_dir;
45993 struct linux_dirent64 __user *previous;
45994+ struct file * file;
45995 int count;
45996 int error;
45997 };
45998@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
45999 buf->error = -EINVAL; /* only used if we fail.. */
46000 if (reclen > buf->count)
46001 return -EINVAL;
46002+
46003+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46004+ return 0;
46005+
46006 dirent = buf->previous;
46007
46008 if (dirent) {
46009@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46010 buf.previous = NULL;
46011 buf.count = count;
46012 buf.error = 0;
46013+ buf.file = f.file;
46014
46015 error = vfs_readdir(f.file, compat_filldir64, &buf);
46016 if (error >= 0)
46017 error = buf.error;
46018 lastdirent = buf.previous;
46019 if (lastdirent) {
46020- typeof(lastdirent->d_off) d_off = f.file->f_pos;
46021+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46022 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46023 error = -EFAULT;
46024 else
46025diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46026index a81147e..20bf2b5 100644
46027--- a/fs/compat_binfmt_elf.c
46028+++ b/fs/compat_binfmt_elf.c
46029@@ -30,11 +30,13 @@
46030 #undef elf_phdr
46031 #undef elf_shdr
46032 #undef elf_note
46033+#undef elf_dyn
46034 #undef elf_addr_t
46035 #define elfhdr elf32_hdr
46036 #define elf_phdr elf32_phdr
46037 #define elf_shdr elf32_shdr
46038 #define elf_note elf32_note
46039+#define elf_dyn Elf32_Dyn
46040 #define elf_addr_t Elf32_Addr
46041
46042 /*
46043diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46044index 4c6285f..b7a2411 100644
46045--- a/fs/compat_ioctl.c
46046+++ b/fs/compat_ioctl.c
46047@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46048 return -EFAULT;
46049 if (__get_user(udata, &ss32->iomem_base))
46050 return -EFAULT;
46051- ss.iomem_base = compat_ptr(udata);
46052+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46053 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46054 __get_user(ss.port_high, &ss32->port_high))
46055 return -EFAULT;
46056@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46057 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46058 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46059 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46060- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46061+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46062 return -EFAULT;
46063
46064 return ioctl_preallocate(file, p);
46065@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46066 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46067 {
46068 unsigned int a, b;
46069- a = *(unsigned int *)p;
46070- b = *(unsigned int *)q;
46071+ a = *(const unsigned int *)p;
46072+ b = *(const unsigned int *)q;
46073 if (a > b)
46074 return 1;
46075 if (a < b)
46076diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46077index 7414ae2..d98ad6d 100644
46078--- a/fs/configfs/dir.c
46079+++ b/fs/configfs/dir.c
46080@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46081 }
46082 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46083 struct configfs_dirent *next;
46084- const char * name;
46085+ const unsigned char * name;
46086+ char d_name[sizeof(next->s_dentry->d_iname)];
46087 int len;
46088 struct inode *inode = NULL;
46089
46090@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46091 continue;
46092
46093 name = configfs_get_name(next);
46094- len = strlen(name);
46095+ if (next->s_dentry && name == next->s_dentry->d_iname) {
46096+ len = next->s_dentry->d_name.len;
46097+ memcpy(d_name, name, len);
46098+ name = d_name;
46099+ } else
46100+ len = strlen(name);
46101
46102 /*
46103 * We'll have a dentry and an inode for
46104diff --git a/fs/coredump.c b/fs/coredump.c
46105index ce47379..68c8e43 100644
46106--- a/fs/coredump.c
46107+++ b/fs/coredump.c
46108@@ -52,7 +52,7 @@ struct core_name {
46109 char *corename;
46110 int used, size;
46111 };
46112-static atomic_t call_count = ATOMIC_INIT(1);
46113+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46114
46115 /* The maximal length of core_pattern is also specified in sysctl.c */
46116
46117@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46118 {
46119 char *old_corename = cn->corename;
46120
46121- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46122+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46123 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46124
46125 if (!cn->corename) {
46126@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46127 int pid_in_pattern = 0;
46128 int err = 0;
46129
46130- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46131+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46132 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46133 cn->used = 0;
46134
46135@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46136 pipe = file->f_path.dentry->d_inode->i_pipe;
46137
46138 pipe_lock(pipe);
46139- pipe->readers++;
46140- pipe->writers--;
46141+ atomic_inc(&pipe->readers);
46142+ atomic_dec(&pipe->writers);
46143
46144- while ((pipe->readers > 1) && (!signal_pending(current))) {
46145+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46146 wake_up_interruptible_sync(&pipe->wait);
46147 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46148 pipe_wait(pipe);
46149 }
46150
46151- pipe->readers--;
46152- pipe->writers++;
46153+ atomic_dec(&pipe->readers);
46154+ atomic_inc(&pipe->writers);
46155 pipe_unlock(pipe);
46156
46157 }
46158@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46159 int ispipe;
46160 struct files_struct *displaced;
46161 bool need_nonrelative = false;
46162- static atomic_t core_dump_count = ATOMIC_INIT(0);
46163+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46164+ long signr = siginfo->si_signo;
46165 struct coredump_params cprm = {
46166 .siginfo = siginfo,
46167 .regs = regs,
46168@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46169 .mm_flags = mm->flags,
46170 };
46171
46172- audit_core_dumps(siginfo->si_signo);
46173+ audit_core_dumps(signr);
46174+
46175+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46176+ gr_handle_brute_attach(cprm.mm_flags);
46177
46178 binfmt = mm->binfmt;
46179 if (!binfmt || !binfmt->core_dump)
46180@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46181 need_nonrelative = true;
46182 }
46183
46184- retval = coredump_wait(siginfo->si_signo, &core_state);
46185+ retval = coredump_wait(signr, &core_state);
46186 if (retval < 0)
46187 goto fail_creds;
46188
46189@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46190 }
46191 cprm.limit = RLIM_INFINITY;
46192
46193- dump_count = atomic_inc_return(&core_dump_count);
46194+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
46195 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46196 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46197 task_tgid_vnr(current), current->comm);
46198@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46199 } else {
46200 struct inode *inode;
46201
46202+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46203+
46204 if (cprm.limit < binfmt->min_coredump)
46205 goto fail_unlock;
46206
46207@@ -640,7 +646,7 @@ close_fail:
46208 filp_close(cprm.file, NULL);
46209 fail_dropcount:
46210 if (ispipe)
46211- atomic_dec(&core_dump_count);
46212+ atomic_dec_unchecked(&core_dump_count);
46213 fail_unlock:
46214 kfree(cn.corename);
46215 fail_corename:
46216@@ -659,7 +665,7 @@ fail:
46217 */
46218 int dump_write(struct file *file, const void *addr, int nr)
46219 {
46220- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46221+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46222 }
46223 EXPORT_SYMBOL(dump_write);
46224
46225diff --git a/fs/dcache.c b/fs/dcache.c
46226index 0d0adb6..f4646e9 100644
46227--- a/fs/dcache.c
46228+++ b/fs/dcache.c
46229@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46230 mempages -= reserve;
46231
46232 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46233- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46234+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46235
46236 dcache_init();
46237 inode_init();
46238diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46239index b607d92..41fda09 100644
46240--- a/fs/debugfs/inode.c
46241+++ b/fs/debugfs/inode.c
46242@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46243 */
46244 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46245 {
46246+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46247+ return __create_file(name, S_IFDIR | S_IRWXU,
46248+#else
46249 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46250+#endif
46251 parent, NULL, NULL);
46252 }
46253 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46254diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46255index cc7709e..7e7211f 100644
46256--- a/fs/ecryptfs/inode.c
46257+++ b/fs/ecryptfs/inode.c
46258@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46259 old_fs = get_fs();
46260 set_fs(get_ds());
46261 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46262- (char __user *)lower_buf,
46263+ (char __force_user *)lower_buf,
46264 PATH_MAX);
46265 set_fs(old_fs);
46266 if (rc < 0)
46267@@ -706,7 +706,7 @@ out:
46268 static void
46269 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46270 {
46271- char *buf = nd_get_link(nd);
46272+ const char *buf = nd_get_link(nd);
46273 if (!IS_ERR(buf)) {
46274 /* Free the char* */
46275 kfree(buf);
46276diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46277index 412e6ed..4292d22 100644
46278--- a/fs/ecryptfs/miscdev.c
46279+++ b/fs/ecryptfs/miscdev.c
46280@@ -315,7 +315,7 @@ check_list:
46281 goto out_unlock_msg_ctx;
46282 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46283 if (msg_ctx->msg) {
46284- if (copy_to_user(&buf[i], packet_length, packet_length_size))
46285+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46286 goto out_unlock_msg_ctx;
46287 i += packet_length_size;
46288 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46289diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46290index b2a34a1..162fa69 100644
46291--- a/fs/ecryptfs/read_write.c
46292+++ b/fs/ecryptfs/read_write.c
46293@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46294 return -EIO;
46295 fs_save = get_fs();
46296 set_fs(get_ds());
46297- rc = vfs_write(lower_file, data, size, &offset);
46298+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46299 set_fs(fs_save);
46300 mark_inode_dirty_sync(ecryptfs_inode);
46301 return rc;
46302@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46303 return -EIO;
46304 fs_save = get_fs();
46305 set_fs(get_ds());
46306- rc = vfs_read(lower_file, data, size, &offset);
46307+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46308 set_fs(fs_save);
46309 return rc;
46310 }
46311diff --git a/fs/exec.c b/fs/exec.c
46312index c6e6de4..45e71ad 100644
46313--- a/fs/exec.c
46314+++ b/fs/exec.c
46315@@ -55,6 +55,17 @@
46316 #include <linux/pipe_fs_i.h>
46317 #include <linux/oom.h>
46318 #include <linux/compat.h>
46319+#include <linux/random.h>
46320+#include <linux/seq_file.h>
46321+#include <linux/coredump.h>
46322+#include <linux/mman.h>
46323+
46324+#ifdef CONFIG_PAX_REFCOUNT
46325+#include <linux/kallsyms.h>
46326+#include <linux/kdebug.h>
46327+#endif
46328+
46329+#include <trace/events/fs.h>
46330
46331 #include <asm/uaccess.h>
46332 #include <asm/mmu_context.h>
46333@@ -66,6 +77,18 @@
46334
46335 #include <trace/events/sched.h>
46336
46337+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46338+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46339+{
46340+ pr_warn_once("PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
46341+}
46342+#endif
46343+
46344+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46345+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46346+EXPORT_SYMBOL(pax_set_initial_flags_func);
46347+#endif
46348+
46349 int suid_dumpable = 0;
46350
46351 static LIST_HEAD(formats);
46352@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46353 int write)
46354 {
46355 struct page *page;
46356- int ret;
46357
46358-#ifdef CONFIG_STACK_GROWSUP
46359- if (write) {
46360- ret = expand_downwards(bprm->vma, pos);
46361- if (ret < 0)
46362- return NULL;
46363- }
46364-#endif
46365- ret = get_user_pages(current, bprm->mm, pos,
46366- 1, write, 1, &page, NULL);
46367- if (ret <= 0)
46368+ if (0 > expand_downwards(bprm->vma, pos))
46369+ return NULL;
46370+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46371 return NULL;
46372
46373 if (write) {
46374@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46375 if (size <= ARG_MAX)
46376 return page;
46377
46378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46379+ // only allow 512KB for argv+env on suid/sgid binaries
46380+ // to prevent easy ASLR exhaustion
46381+ if (((bprm->cred->euid != current_euid()) ||
46382+ (bprm->cred->egid != current_egid())) &&
46383+ (size > (512 * 1024))) {
46384+ put_page(page);
46385+ return NULL;
46386+ }
46387+#endif
46388+
46389 /*
46390 * Limit to 1/4-th the stack size for the argv+env strings.
46391 * This ensures that:
46392@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46393 vma->vm_end = STACK_TOP_MAX;
46394 vma->vm_start = vma->vm_end - PAGE_SIZE;
46395 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46396+
46397+#ifdef CONFIG_PAX_SEGMEXEC
46398+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46399+#endif
46400+
46401 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46402 INIT_LIST_HEAD(&vma->anon_vma_chain);
46403
46404@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46405 mm->stack_vm = mm->total_vm = 1;
46406 up_write(&mm->mmap_sem);
46407 bprm->p = vma->vm_end - sizeof(void *);
46408+
46409+#ifdef CONFIG_PAX_RANDUSTACK
46410+ if (randomize_va_space)
46411+ bprm->p ^= random32() & ~PAGE_MASK;
46412+#endif
46413+
46414 return 0;
46415 err:
46416 up_write(&mm->mmap_sem);
46417@@ -384,19 +421,7 @@ err:
46418 return err;
46419 }
46420
46421-struct user_arg_ptr {
46422-#ifdef CONFIG_COMPAT
46423- bool is_compat;
46424-#endif
46425- union {
46426- const char __user *const __user *native;
46427-#ifdef CONFIG_COMPAT
46428- const compat_uptr_t __user *compat;
46429-#endif
46430- } ptr;
46431-};
46432-
46433-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46434+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46435 {
46436 const char __user *native;
46437
46438@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46439 compat_uptr_t compat;
46440
46441 if (get_user(compat, argv.ptr.compat + nr))
46442- return ERR_PTR(-EFAULT);
46443+ return (const char __force_user *)ERR_PTR(-EFAULT);
46444
46445 return compat_ptr(compat);
46446 }
46447 #endif
46448
46449 if (get_user(native, argv.ptr.native + nr))
46450- return ERR_PTR(-EFAULT);
46451+ return (const char __force_user *)ERR_PTR(-EFAULT);
46452
46453 return native;
46454 }
46455@@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46456 if (!p)
46457 break;
46458
46459- if (IS_ERR(p))
46460+ if (IS_ERR((const char __force_kernel *)p))
46461 return -EFAULT;
46462
46463- if (i++ >= max)
46464+ if (i >= max)
46465 return -E2BIG;
46466+ ++i;
46467
46468 if (fatal_signal_pending(current))
46469 return -ERESTARTNOHAND;
46470@@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46471
46472 ret = -EFAULT;
46473 str = get_user_arg_ptr(argv, argc);
46474- if (IS_ERR(str))
46475+ if (IS_ERR((const char __force_kernel *)str))
46476 goto out;
46477
46478 len = strnlen_user(str, MAX_ARG_STRLEN);
46479@@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46480 int r;
46481 mm_segment_t oldfs = get_fs();
46482 struct user_arg_ptr argv = {
46483- .ptr.native = (const char __user *const __user *)__argv,
46484+ .ptr.native = (const char __force_user *const __force_user *)__argv,
46485 };
46486
46487 set_fs(KERNEL_DS);
46488@@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46489 unsigned long new_end = old_end - shift;
46490 struct mmu_gather tlb;
46491
46492- BUG_ON(new_start > new_end);
46493+ if (new_start >= new_end || new_start < mmap_min_addr)
46494+ return -ENOMEM;
46495
46496 /*
46497 * ensure there are no vmas between where we want to go
46498@@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46499 if (vma != find_vma(mm, new_start))
46500 return -EFAULT;
46501
46502+#ifdef CONFIG_PAX_SEGMEXEC
46503+ BUG_ON(pax_find_mirror_vma(vma));
46504+#endif
46505+
46506 /*
46507 * cover the whole range: [new_start, old_end)
46508 */
46509@@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46510 stack_top = arch_align_stack(stack_top);
46511 stack_top = PAGE_ALIGN(stack_top);
46512
46513- if (unlikely(stack_top < mmap_min_addr) ||
46514- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46515- return -ENOMEM;
46516-
46517 stack_shift = vma->vm_end - stack_top;
46518
46519 bprm->p -= stack_shift;
46520@@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46521 bprm->exec -= stack_shift;
46522
46523 down_write(&mm->mmap_sem);
46524+
46525+ /* Move stack pages down in memory. */
46526+ if (stack_shift) {
46527+ ret = shift_arg_pages(vma, stack_shift);
46528+ if (ret)
46529+ goto out_unlock;
46530+ }
46531+
46532 vm_flags = VM_STACK_FLAGS;
46533
46534+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46535+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46536+ vm_flags &= ~VM_EXEC;
46537+
46538+#ifdef CONFIG_PAX_MPROTECT
46539+ if (mm->pax_flags & MF_PAX_MPROTECT)
46540+ vm_flags &= ~VM_MAYEXEC;
46541+#endif
46542+
46543+ }
46544+#endif
46545+
46546 /*
46547 * Adjust stack execute permissions; explicitly enable for
46548 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46549@@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46550 goto out_unlock;
46551 BUG_ON(prev != vma);
46552
46553- /* Move stack pages down in memory. */
46554- if (stack_shift) {
46555- ret = shift_arg_pages(vma, stack_shift);
46556- if (ret)
46557- goto out_unlock;
46558- }
46559-
46560 /* mprotect_fixup is overkill to remove the temporary stack flags */
46561 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46562
46563@@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46564 #endif
46565 current->mm->start_stack = bprm->p;
46566 ret = expand_stack(vma, stack_base);
46567+
46568+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46569+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46570+ unsigned long size, flags, vm_flags;
46571+
46572+ size = STACK_TOP - vma->vm_end;
46573+ flags = MAP_FIXED | MAP_PRIVATE;
46574+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46575+
46576+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46577+
46578+#ifdef CONFIG_X86
46579+ if (!ret) {
46580+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46581+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46582+ }
46583+#endif
46584+
46585+ }
46586+#endif
46587+
46588 if (ret)
46589 ret = -EFAULT;
46590
46591@@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46592
46593 fsnotify_open(file);
46594
46595+ trace_open_exec(name);
46596+
46597 err = deny_write_access(file);
46598 if (err)
46599 goto exit;
46600@@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46601 old_fs = get_fs();
46602 set_fs(get_ds());
46603 /* The cast to a user pointer is valid due to the set_fs() */
46604- result = vfs_read(file, (void __user *)addr, count, &pos);
46605+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
46606 set_fs(old_fs);
46607 return result;
46608 }
46609@@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46610 }
46611 rcu_read_unlock();
46612
46613- if (p->fs->users > n_fs) {
46614+ if (atomic_read(&p->fs->users) > n_fs) {
46615 bprm->unsafe |= LSM_UNSAFE_SHARE;
46616 } else {
46617 res = -EAGAIN;
46618@@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46619
46620 EXPORT_SYMBOL(search_binary_handler);
46621
46622+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46623+static DEFINE_PER_CPU(u64, exec_counter);
46624+static int __init init_exec_counters(void)
46625+{
46626+ unsigned int cpu;
46627+
46628+ for_each_possible_cpu(cpu) {
46629+ per_cpu(exec_counter, cpu) = (u64)cpu;
46630+ }
46631+
46632+ return 0;
46633+}
46634+early_initcall(init_exec_counters);
46635+static inline void increment_exec_counter(void)
46636+{
46637+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
46638+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46639+}
46640+#else
46641+static inline void increment_exec_counter(void) {}
46642+#endif
46643+
46644 /*
46645 * sys_execve() executes a new program.
46646 */
46647@@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
46648 struct user_arg_ptr envp,
46649 struct pt_regs *regs)
46650 {
46651+#ifdef CONFIG_GRKERNSEC
46652+ struct file *old_exec_file;
46653+ struct acl_subject_label *old_acl;
46654+ struct rlimit old_rlim[RLIM_NLIMITS];
46655+#endif
46656 struct linux_binprm *bprm;
46657 struct file *file;
46658 struct files_struct *displaced;
46659@@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
46660 int retval;
46661 const struct cred *cred = current_cred();
46662
46663+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46664+
46665 /*
46666 * We move the actual failure in case of RLIMIT_NPROC excess from
46667 * set*uid() to execve() because too many poorly written programs
46668@@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
46669 if (IS_ERR(file))
46670 goto out_unmark;
46671
46672+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
46673+ retval = -EPERM;
46674+ goto out_file;
46675+ }
46676+
46677 sched_exec();
46678
46679 bprm->file = file;
46680 bprm->filename = filename;
46681 bprm->interp = filename;
46682
46683+ if (gr_process_user_ban()) {
46684+ retval = -EPERM;
46685+ goto out_file;
46686+ }
46687+
46688+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46689+ retval = -EACCES;
46690+ goto out_file;
46691+ }
46692+
46693 retval = bprm_mm_init(bprm);
46694 if (retval)
46695 goto out_file;
46696@@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
46697 if (retval < 0)
46698 goto out;
46699
46700+#ifdef CONFIG_GRKERNSEC
46701+ old_acl = current->acl;
46702+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46703+ old_exec_file = current->exec_file;
46704+ get_file(file);
46705+ current->exec_file = file;
46706+#endif
46707+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46708+ /* limit suid stack to 8MB
46709+ we saved the old limits above and will restore them if this exec fails
46710+ */
46711+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46712+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46713+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46714+#endif
46715+
46716+ if (!gr_tpe_allow(file)) {
46717+ retval = -EACCES;
46718+ goto out_fail;
46719+ }
46720+
46721+ if (gr_check_crash_exec(file)) {
46722+ retval = -EACCES;
46723+ goto out_fail;
46724+ }
46725+
46726+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46727+ bprm->unsafe);
46728+ if (retval < 0)
46729+ goto out_fail;
46730+
46731 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46732 if (retval < 0)
46733- goto out;
46734+ goto out_fail;
46735
46736 bprm->exec = bprm->p;
46737 retval = copy_strings(bprm->envc, envp, bprm);
46738 if (retval < 0)
46739- goto out;
46740+ goto out_fail;
46741
46742 retval = copy_strings(bprm->argc, argv, bprm);
46743 if (retval < 0)
46744- goto out;
46745+ goto out_fail;
46746+
46747+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46748+
46749+ gr_handle_exec_args(bprm, argv);
46750
46751 retval = search_binary_handler(bprm,regs);
46752 if (retval < 0)
46753- goto out;
46754+ goto out_fail;
46755+#ifdef CONFIG_GRKERNSEC
46756+ if (old_exec_file)
46757+ fput(old_exec_file);
46758+#endif
46759
46760 /* execve succeeded */
46761+
46762+ increment_exec_counter();
46763 current->fs->in_exec = 0;
46764 current->in_execve = 0;
46765 acct_update_integrals(current);
46766@@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
46767 put_files_struct(displaced);
46768 return retval;
46769
46770+out_fail:
46771+#ifdef CONFIG_GRKERNSEC
46772+ current->acl = old_acl;
46773+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46774+ fput(current->exec_file);
46775+ current->exec_file = old_exec_file;
46776+#endif
46777+
46778 out:
46779 if (bprm->mm) {
46780 acct_arg_size(bprm, 0);
46781@@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
46782 ret_from_kernel_execve(p);
46783 }
46784 #endif
46785+
46786+int pax_check_flags(unsigned long *flags)
46787+{
46788+ int retval = 0;
46789+
46790+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
46791+ if (*flags & MF_PAX_SEGMEXEC)
46792+ {
46793+ *flags &= ~MF_PAX_SEGMEXEC;
46794+ retval = -EINVAL;
46795+ }
46796+#endif
46797+
46798+ if ((*flags & MF_PAX_PAGEEXEC)
46799+
46800+#ifdef CONFIG_PAX_PAGEEXEC
46801+ && (*flags & MF_PAX_SEGMEXEC)
46802+#endif
46803+
46804+ )
46805+ {
46806+ *flags &= ~MF_PAX_PAGEEXEC;
46807+ retval = -EINVAL;
46808+ }
46809+
46810+ if ((*flags & MF_PAX_MPROTECT)
46811+
46812+#ifdef CONFIG_PAX_MPROTECT
46813+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46814+#endif
46815+
46816+ )
46817+ {
46818+ *flags &= ~MF_PAX_MPROTECT;
46819+ retval = -EINVAL;
46820+ }
46821+
46822+ if ((*flags & MF_PAX_EMUTRAMP)
46823+
46824+#ifdef CONFIG_PAX_EMUTRAMP
46825+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46826+#endif
46827+
46828+ )
46829+ {
46830+ *flags &= ~MF_PAX_EMUTRAMP;
46831+ retval = -EINVAL;
46832+ }
46833+
46834+ return retval;
46835+}
46836+
46837+EXPORT_SYMBOL(pax_check_flags);
46838+
46839+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46840+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
46841+{
46842+ struct task_struct *tsk = current;
46843+ struct mm_struct *mm = current->mm;
46844+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
46845+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
46846+ char *path_exec = NULL;
46847+ char *path_fault = NULL;
46848+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
46849+ siginfo_t info = { };
46850+
46851+ if (buffer_exec && buffer_fault) {
46852+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
46853+
46854+ down_read(&mm->mmap_sem);
46855+ vma = mm->mmap;
46856+ while (vma && (!vma_exec || !vma_fault)) {
46857+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
46858+ vma_exec = vma;
46859+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
46860+ vma_fault = vma;
46861+ vma = vma->vm_next;
46862+ }
46863+ if (vma_exec) {
46864+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
46865+ if (IS_ERR(path_exec))
46866+ path_exec = "<path too long>";
46867+ else {
46868+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
46869+ if (path_exec) {
46870+ *path_exec = 0;
46871+ path_exec = buffer_exec;
46872+ } else
46873+ path_exec = "<path too long>";
46874+ }
46875+ }
46876+ if (vma_fault) {
46877+ start = vma_fault->vm_start;
46878+ end = vma_fault->vm_end;
46879+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
46880+ if (vma_fault->vm_file) {
46881+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
46882+ if (IS_ERR(path_fault))
46883+ path_fault = "<path too long>";
46884+ else {
46885+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
46886+ if (path_fault) {
46887+ *path_fault = 0;
46888+ path_fault = buffer_fault;
46889+ } else
46890+ path_fault = "<path too long>";
46891+ }
46892+ } else
46893+ path_fault = "<anonymous mapping>";
46894+ }
46895+ up_read(&mm->mmap_sem);
46896+ }
46897+ if (tsk->signal->curr_ip)
46898+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
46899+ else
46900+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
46901+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
46902+ from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
46903+ free_page((unsigned long)buffer_exec);
46904+ free_page((unsigned long)buffer_fault);
46905+ pax_report_insns(regs, pc, sp);
46906+ info.si_signo = SIGKILL;
46907+ info.si_errno = 0;
46908+ info.si_code = SI_KERNEL;
46909+ info.si_pid = 0;
46910+ info.si_uid = 0;
46911+ do_coredump(&info, regs);
46912+}
46913+#endif
46914+
46915+#ifdef CONFIG_PAX_REFCOUNT
46916+void pax_report_refcount_overflow(struct pt_regs *regs)
46917+{
46918+ if (current->signal->curr_ip)
46919+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
46920+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
46921+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
46922+ else
46923+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
46924+ from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
46925+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
46926+ show_regs(regs);
46927+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
46928+}
46929+#endif
46930+
46931+#ifdef CONFIG_PAX_USERCOPY
46932+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
46933+static noinline int check_stack_object(const void *obj, unsigned long len)
46934+{
46935+ const void * const stack = task_stack_page(current);
46936+ const void * const stackend = stack + THREAD_SIZE;
46937+
46938+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46939+ const void *frame = NULL;
46940+ const void *oldframe;
46941+#endif
46942+
46943+ if (obj + len < obj)
46944+ return -1;
46945+
46946+ if (obj + len <= stack || stackend <= obj)
46947+ return 0;
46948+
46949+ if (obj < stack || stackend < obj + len)
46950+ return -1;
46951+
46952+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
46953+ oldframe = __builtin_frame_address(1);
46954+ if (oldframe)
46955+ frame = __builtin_frame_address(2);
46956+ /*
46957+ low ----------------------------------------------> high
46958+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
46959+ ^----------------^
46960+ allow copies only within here
46961+ */
46962+ while (stack <= frame && frame < stackend) {
46963+ /* if obj + len extends past the last frame, this
46964+ check won't pass and the next frame will be 0,
46965+ causing us to bail out and correctly report
46966+ the copy as invalid
46967+ */
46968+ if (obj + len <= frame)
46969+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
46970+ oldframe = frame;
46971+ frame = *(const void * const *)frame;
46972+ }
46973+ return -1;
46974+#else
46975+ return 1;
46976+#endif
46977+}
46978+
46979+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
46980+{
46981+ if (current->signal->curr_ip)
46982+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46983+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46984+ else
46985+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
46986+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
46987+ dump_stack();
46988+ gr_handle_kernel_exploit();
46989+ do_group_exit(SIGKILL);
46990+}
46991+#endif
46992+
46993+void __check_object_size(const void *ptr, unsigned long n, bool to)
46994+{
46995+
46996+#ifdef CONFIG_PAX_USERCOPY
46997+ const char *type;
46998+
46999+ if (!n)
47000+ return;
47001+
47002+ type = check_heap_object(ptr, n);
47003+ if (!type) {
47004+ if (check_stack_object(ptr, n) != -1)
47005+ return;
47006+ type = "<process stack>";
47007+ }
47008+
47009+ pax_report_usercopy(ptr, n, to, type);
47010+#endif
47011+
47012+}
47013+EXPORT_SYMBOL(__check_object_size);
47014+
47015+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47016+void pax_track_stack(void)
47017+{
47018+ unsigned long sp = (unsigned long)&sp;
47019+ if (sp < current_thread_info()->lowest_stack &&
47020+ sp > (unsigned long)task_stack_page(current))
47021+ current_thread_info()->lowest_stack = sp;
47022+}
47023+EXPORT_SYMBOL(pax_track_stack);
47024+#endif
47025+
47026+#ifdef CONFIG_PAX_SIZE_OVERFLOW
47027+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47028+{
47029+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47030+ dump_stack();
47031+ do_group_exit(SIGKILL);
47032+}
47033+EXPORT_SYMBOL(report_size_overflow);
47034+#endif
47035diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47036index 2616d0e..2ffdec9 100644
47037--- a/fs/ext2/balloc.c
47038+++ b/fs/ext2/balloc.c
47039@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47040
47041 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47042 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47043- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47044+ if (free_blocks < root_blocks + 1 &&
47045 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47046 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47047- !in_group_p (sbi->s_resgid))) {
47048+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47049 return 0;
47050 }
47051 return 1;
47052diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47053index 22548f5..41521d8 100644
47054--- a/fs/ext3/balloc.c
47055+++ b/fs/ext3/balloc.c
47056@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47057
47058 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47059 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47060- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47061+ if (free_blocks < root_blocks + 1 &&
47062 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47063 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47064- !in_group_p (sbi->s_resgid))) {
47065+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47066 return 0;
47067 }
47068 return 1;
47069diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47070index cf18217..8f6b9c3 100644
47071--- a/fs/ext4/balloc.c
47072+++ b/fs/ext4/balloc.c
47073@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47074 /* Hm, nope. Are (enough) root reserved clusters available? */
47075 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47076 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47077- capable(CAP_SYS_RESOURCE) ||
47078- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47079+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47080+ capable_nolog(CAP_SYS_RESOURCE)) {
47081
47082 if (free_clusters >= (nclusters + dirty_clusters))
47083 return 1;
47084diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47085index 3c20de1..6ff2460 100644
47086--- a/fs/ext4/ext4.h
47087+++ b/fs/ext4/ext4.h
47088@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47089 unsigned long s_mb_last_start;
47090
47091 /* stats for buddy allocator */
47092- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47093- atomic_t s_bal_success; /* we found long enough chunks */
47094- atomic_t s_bal_allocated; /* in blocks */
47095- atomic_t s_bal_ex_scanned; /* total extents scanned */
47096- atomic_t s_bal_goals; /* goal hits */
47097- atomic_t s_bal_breaks; /* too long searches */
47098- atomic_t s_bal_2orders; /* 2^order hits */
47099+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47100+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47101+ atomic_unchecked_t s_bal_allocated; /* in blocks */
47102+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47103+ atomic_unchecked_t s_bal_goals; /* goal hits */
47104+ atomic_unchecked_t s_bal_breaks; /* too long searches */
47105+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47106 spinlock_t s_bal_lock;
47107 unsigned long s_mb_buddies_generated;
47108 unsigned long long s_mb_generation_time;
47109- atomic_t s_mb_lost_chunks;
47110- atomic_t s_mb_preallocated;
47111- atomic_t s_mb_discarded;
47112+ atomic_unchecked_t s_mb_lost_chunks;
47113+ atomic_unchecked_t s_mb_preallocated;
47114+ atomic_unchecked_t s_mb_discarded;
47115 atomic_t s_lock_busy;
47116
47117 /* locality groups */
47118diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47119index 526e553..3f2de85 100644
47120--- a/fs/ext4/mballoc.c
47121+++ b/fs/ext4/mballoc.c
47122@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47123 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47124
47125 if (EXT4_SB(sb)->s_mb_stats)
47126- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47127+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47128
47129 break;
47130 }
47131@@ -2044,7 +2044,7 @@ repeat:
47132 ac->ac_status = AC_STATUS_CONTINUE;
47133 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47134 cr = 3;
47135- atomic_inc(&sbi->s_mb_lost_chunks);
47136+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47137 goto repeat;
47138 }
47139 }
47140@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47141 if (sbi->s_mb_stats) {
47142 ext4_msg(sb, KERN_INFO,
47143 "mballoc: %u blocks %u reqs (%u success)",
47144- atomic_read(&sbi->s_bal_allocated),
47145- atomic_read(&sbi->s_bal_reqs),
47146- atomic_read(&sbi->s_bal_success));
47147+ atomic_read_unchecked(&sbi->s_bal_allocated),
47148+ atomic_read_unchecked(&sbi->s_bal_reqs),
47149+ atomic_read_unchecked(&sbi->s_bal_success));
47150 ext4_msg(sb, KERN_INFO,
47151 "mballoc: %u extents scanned, %u goal hits, "
47152 "%u 2^N hits, %u breaks, %u lost",
47153- atomic_read(&sbi->s_bal_ex_scanned),
47154- atomic_read(&sbi->s_bal_goals),
47155- atomic_read(&sbi->s_bal_2orders),
47156- atomic_read(&sbi->s_bal_breaks),
47157- atomic_read(&sbi->s_mb_lost_chunks));
47158+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47159+ atomic_read_unchecked(&sbi->s_bal_goals),
47160+ atomic_read_unchecked(&sbi->s_bal_2orders),
47161+ atomic_read_unchecked(&sbi->s_bal_breaks),
47162+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47163 ext4_msg(sb, KERN_INFO,
47164 "mballoc: %lu generated and it took %Lu",
47165 sbi->s_mb_buddies_generated,
47166 sbi->s_mb_generation_time);
47167 ext4_msg(sb, KERN_INFO,
47168 "mballoc: %u preallocated, %u discarded",
47169- atomic_read(&sbi->s_mb_preallocated),
47170- atomic_read(&sbi->s_mb_discarded));
47171+ atomic_read_unchecked(&sbi->s_mb_preallocated),
47172+ atomic_read_unchecked(&sbi->s_mb_discarded));
47173 }
47174
47175 free_percpu(sbi->s_locality_groups);
47176@@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47177 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47178
47179 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47180- atomic_inc(&sbi->s_bal_reqs);
47181- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47182+ atomic_inc_unchecked(&sbi->s_bal_reqs);
47183+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47184 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47185- atomic_inc(&sbi->s_bal_success);
47186- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47187+ atomic_inc_unchecked(&sbi->s_bal_success);
47188+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47189 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47190 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47191- atomic_inc(&sbi->s_bal_goals);
47192+ atomic_inc_unchecked(&sbi->s_bal_goals);
47193 if (ac->ac_found > sbi->s_mb_max_to_scan)
47194- atomic_inc(&sbi->s_bal_breaks);
47195+ atomic_inc_unchecked(&sbi->s_bal_breaks);
47196 }
47197
47198 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47199@@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47200 trace_ext4_mb_new_inode_pa(ac, pa);
47201
47202 ext4_mb_use_inode_pa(ac, pa);
47203- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47204+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47205
47206 ei = EXT4_I(ac->ac_inode);
47207 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47208@@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47209 trace_ext4_mb_new_group_pa(ac, pa);
47210
47211 ext4_mb_use_group_pa(ac, pa);
47212- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47213+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47214
47215 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47216 lg = ac->ac_lg;
47217@@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47218 * from the bitmap and continue.
47219 */
47220 }
47221- atomic_add(free, &sbi->s_mb_discarded);
47222+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
47223
47224 return err;
47225 }
47226@@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47227 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47228 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47229 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47230- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47231+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47232 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47233
47234 return 0;
47235diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47236index d59b351..775f8c8 100644
47237--- a/fs/ext4/super.c
47238+++ b/fs/ext4/super.c
47239@@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47240 ext4_fsblk_t overhead = 0;
47241 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47242
47243- memset(buf, 0, PAGE_SIZE);
47244 if (!buf)
47245 return -ENOMEM;
47246
47247diff --git a/fs/fcntl.c b/fs/fcntl.c
47248index 71a600a..20d87b1 100644
47249--- a/fs/fcntl.c
47250+++ b/fs/fcntl.c
47251@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47252 if (err)
47253 return err;
47254
47255+ if (gr_handle_chroot_fowner(pid, type))
47256+ return -ENOENT;
47257+ if (gr_check_protected_task_fowner(pid, type))
47258+ return -EACCES;
47259+
47260 f_modown(filp, pid, type, force);
47261 return 0;
47262 }
47263diff --git a/fs/fhandle.c b/fs/fhandle.c
47264index f775bfd..629bd4c 100644
47265--- a/fs/fhandle.c
47266+++ b/fs/fhandle.c
47267@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47268 } else
47269 retval = 0;
47270 /* copy the mount id */
47271- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47272- sizeof(*mnt_id)) ||
47273+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47274 copy_to_user(ufh, handle,
47275 sizeof(struct file_handle) + handle_bytes))
47276 retval = -EFAULT;
47277diff --git a/fs/fifo.c b/fs/fifo.c
47278index cf6f434..3d7942c 100644
47279--- a/fs/fifo.c
47280+++ b/fs/fifo.c
47281@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47282 */
47283 filp->f_op = &read_pipefifo_fops;
47284 pipe->r_counter++;
47285- if (pipe->readers++ == 0)
47286+ if (atomic_inc_return(&pipe->readers) == 1)
47287 wake_up_partner(inode);
47288
47289- if (!pipe->writers) {
47290+ if (!atomic_read(&pipe->writers)) {
47291 if ((filp->f_flags & O_NONBLOCK)) {
47292 /* suppress POLLHUP until we have
47293 * seen a writer */
47294@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47295 * errno=ENXIO when there is no process reading the FIFO.
47296 */
47297 ret = -ENXIO;
47298- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47299+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47300 goto err;
47301
47302 filp->f_op = &write_pipefifo_fops;
47303 pipe->w_counter++;
47304- if (!pipe->writers++)
47305+ if (atomic_inc_return(&pipe->writers) == 1)
47306 wake_up_partner(inode);
47307
47308- if (!pipe->readers) {
47309+ if (!atomic_read(&pipe->readers)) {
47310 if (wait_for_partner(inode, &pipe->r_counter))
47311 goto err_wr;
47312 }
47313@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47314 */
47315 filp->f_op = &rdwr_pipefifo_fops;
47316
47317- pipe->readers++;
47318- pipe->writers++;
47319+ atomic_inc(&pipe->readers);
47320+ atomic_inc(&pipe->writers);
47321 pipe->r_counter++;
47322 pipe->w_counter++;
47323- if (pipe->readers == 1 || pipe->writers == 1)
47324+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47325 wake_up_partner(inode);
47326 break;
47327
47328@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47329 return 0;
47330
47331 err_rd:
47332- if (!--pipe->readers)
47333+ if (atomic_dec_and_test(&pipe->readers))
47334 wake_up_interruptible(&pipe->wait);
47335 ret = -ERESTARTSYS;
47336 goto err;
47337
47338 err_wr:
47339- if (!--pipe->writers)
47340+ if (atomic_dec_and_test(&pipe->writers))
47341 wake_up_interruptible(&pipe->wait);
47342 ret = -ERESTARTSYS;
47343 goto err;
47344
47345 err:
47346- if (!pipe->readers && !pipe->writers)
47347+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47348 free_pipe_info(inode);
47349
47350 err_nocleanup:
47351diff --git a/fs/file.c b/fs/file.c
47352index eff2316..8c8930c 100644
47353--- a/fs/file.c
47354+++ b/fs/file.c
47355@@ -16,6 +16,7 @@
47356 #include <linux/slab.h>
47357 #include <linux/vmalloc.h>
47358 #include <linux/file.h>
47359+#include <linux/security.h>
47360 #include <linux/fdtable.h>
47361 #include <linux/bitops.h>
47362 #include <linux/interrupt.h>
47363@@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47364 if (!file)
47365 return __close_fd(files, fd);
47366
47367+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47368 if (fd >= rlimit(RLIMIT_NOFILE))
47369 return -EBADF;
47370
47371@@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47372 if (unlikely(oldfd == newfd))
47373 return -EINVAL;
47374
47375+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47376 if (newfd >= rlimit(RLIMIT_NOFILE))
47377 return -EBADF;
47378
47379@@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47380 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47381 {
47382 int err;
47383+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47384 if (from >= rlimit(RLIMIT_NOFILE))
47385 return -EINVAL;
47386 err = alloc_fd(from, flags);
47387diff --git a/fs/filesystems.c b/fs/filesystems.c
47388index da165f6..3671bdb 100644
47389--- a/fs/filesystems.c
47390+++ b/fs/filesystems.c
47391@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47392 int len = dot ? dot - name : strlen(name);
47393
47394 fs = __get_fs_type(name, len);
47395+
47396+#ifdef CONFIG_GRKERNSEC_MODHARDEN
47397+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47398+#else
47399 if (!fs && (request_module("%.*s", len, name) == 0))
47400+#endif
47401 fs = __get_fs_type(name, len);
47402
47403 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47404diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47405index 5df4775..9d9336f 100644
47406--- a/fs/fs_struct.c
47407+++ b/fs/fs_struct.c
47408@@ -4,6 +4,7 @@
47409 #include <linux/path.h>
47410 #include <linux/slab.h>
47411 #include <linux/fs_struct.h>
47412+#include <linux/grsecurity.h>
47413 #include "internal.h"
47414
47415 /*
47416@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47417 write_seqcount_begin(&fs->seq);
47418 old_root = fs->root;
47419 fs->root = *path;
47420+ gr_set_chroot_entries(current, path);
47421 write_seqcount_end(&fs->seq);
47422 spin_unlock(&fs->lock);
47423 if (old_root.dentry)
47424@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47425 return 1;
47426 }
47427
47428+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47429+{
47430+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47431+ return 0;
47432+ *p = *new;
47433+
47434+ /* This function is only called from pivot_root(). Leave our
47435+ gr_chroot_dentry and is_chrooted flags as-is, so that a
47436+ pivoted root isn't treated as a chroot
47437+ */
47438+ //gr_set_chroot_entries(task, new);
47439+
47440+ return 1;
47441+}
47442+
47443 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47444 {
47445 struct task_struct *g, *p;
47446@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47447 int hits = 0;
47448 spin_lock(&fs->lock);
47449 write_seqcount_begin(&fs->seq);
47450- hits += replace_path(&fs->root, old_root, new_root);
47451+ hits += replace_root_path(p, &fs->root, old_root, new_root);
47452 hits += replace_path(&fs->pwd, old_root, new_root);
47453 write_seqcount_end(&fs->seq);
47454 while (hits--) {
47455@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47456 task_lock(tsk);
47457 spin_lock(&fs->lock);
47458 tsk->fs = NULL;
47459- kill = !--fs->users;
47460+ gr_clear_chroot_entries(tsk);
47461+ kill = !atomic_dec_return(&fs->users);
47462 spin_unlock(&fs->lock);
47463 task_unlock(tsk);
47464 if (kill)
47465@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47466 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47467 /* We don't need to lock fs - think why ;-) */
47468 if (fs) {
47469- fs->users = 1;
47470+ atomic_set(&fs->users, 1);
47471 fs->in_exec = 0;
47472 spin_lock_init(&fs->lock);
47473 seqcount_init(&fs->seq);
47474@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47475 spin_lock(&old->lock);
47476 fs->root = old->root;
47477 path_get(&fs->root);
47478+ /* instead of calling gr_set_chroot_entries here,
47479+ we call it from every caller of this function
47480+ */
47481 fs->pwd = old->pwd;
47482 path_get(&fs->pwd);
47483 spin_unlock(&old->lock);
47484@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47485
47486 task_lock(current);
47487 spin_lock(&fs->lock);
47488- kill = !--fs->users;
47489+ kill = !atomic_dec_return(&fs->users);
47490 current->fs = new_fs;
47491+ gr_set_chroot_entries(current, &new_fs->root);
47492 spin_unlock(&fs->lock);
47493 task_unlock(current);
47494
47495@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47496
47497 int current_umask(void)
47498 {
47499- return current->fs->umask;
47500+ return current->fs->umask | gr_acl_umask();
47501 }
47502 EXPORT_SYMBOL(current_umask);
47503
47504 /* to be mentioned only in INIT_TASK */
47505 struct fs_struct init_fs = {
47506- .users = 1,
47507+ .users = ATOMIC_INIT(1),
47508 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47509 .seq = SEQCNT_ZERO,
47510 .umask = 0022,
47511@@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47512 task_lock(current);
47513
47514 spin_lock(&init_fs.lock);
47515- init_fs.users++;
47516+ atomic_inc(&init_fs.users);
47517 spin_unlock(&init_fs.lock);
47518
47519 spin_lock(&fs->lock);
47520 current->fs = &init_fs;
47521- kill = !--fs->users;
47522+ gr_set_chroot_entries(current, &current->fs->root);
47523+ kill = !atomic_dec_return(&fs->users);
47524 spin_unlock(&fs->lock);
47525
47526 task_unlock(current);
47527diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47528index 9905350..02eaec4 100644
47529--- a/fs/fscache/cookie.c
47530+++ b/fs/fscache/cookie.c
47531@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47532 parent ? (char *) parent->def->name : "<no-parent>",
47533 def->name, netfs_data);
47534
47535- fscache_stat(&fscache_n_acquires);
47536+ fscache_stat_unchecked(&fscache_n_acquires);
47537
47538 /* if there's no parent cookie, then we don't create one here either */
47539 if (!parent) {
47540- fscache_stat(&fscache_n_acquires_null);
47541+ fscache_stat_unchecked(&fscache_n_acquires_null);
47542 _leave(" [no parent]");
47543 return NULL;
47544 }
47545@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47546 /* allocate and initialise a cookie */
47547 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47548 if (!cookie) {
47549- fscache_stat(&fscache_n_acquires_oom);
47550+ fscache_stat_unchecked(&fscache_n_acquires_oom);
47551 _leave(" [ENOMEM]");
47552 return NULL;
47553 }
47554@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47555
47556 switch (cookie->def->type) {
47557 case FSCACHE_COOKIE_TYPE_INDEX:
47558- fscache_stat(&fscache_n_cookie_index);
47559+ fscache_stat_unchecked(&fscache_n_cookie_index);
47560 break;
47561 case FSCACHE_COOKIE_TYPE_DATAFILE:
47562- fscache_stat(&fscache_n_cookie_data);
47563+ fscache_stat_unchecked(&fscache_n_cookie_data);
47564 break;
47565 default:
47566- fscache_stat(&fscache_n_cookie_special);
47567+ fscache_stat_unchecked(&fscache_n_cookie_special);
47568 break;
47569 }
47570
47571@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47572 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47573 atomic_dec(&parent->n_children);
47574 __fscache_cookie_put(cookie);
47575- fscache_stat(&fscache_n_acquires_nobufs);
47576+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47577 _leave(" = NULL");
47578 return NULL;
47579 }
47580 }
47581
47582- fscache_stat(&fscache_n_acquires_ok);
47583+ fscache_stat_unchecked(&fscache_n_acquires_ok);
47584 _leave(" = %p", cookie);
47585 return cookie;
47586 }
47587@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47588 cache = fscache_select_cache_for_object(cookie->parent);
47589 if (!cache) {
47590 up_read(&fscache_addremove_sem);
47591- fscache_stat(&fscache_n_acquires_no_cache);
47592+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47593 _leave(" = -ENOMEDIUM [no cache]");
47594 return -ENOMEDIUM;
47595 }
47596@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47597 object = cache->ops->alloc_object(cache, cookie);
47598 fscache_stat_d(&fscache_n_cop_alloc_object);
47599 if (IS_ERR(object)) {
47600- fscache_stat(&fscache_n_object_no_alloc);
47601+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
47602 ret = PTR_ERR(object);
47603 goto error;
47604 }
47605
47606- fscache_stat(&fscache_n_object_alloc);
47607+ fscache_stat_unchecked(&fscache_n_object_alloc);
47608
47609 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47610
47611@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47612 struct fscache_object *object;
47613 struct hlist_node *_p;
47614
47615- fscache_stat(&fscache_n_updates);
47616+ fscache_stat_unchecked(&fscache_n_updates);
47617
47618 if (!cookie) {
47619- fscache_stat(&fscache_n_updates_null);
47620+ fscache_stat_unchecked(&fscache_n_updates_null);
47621 _leave(" [no cookie]");
47622 return;
47623 }
47624@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47625 struct fscache_object *object;
47626 unsigned long event;
47627
47628- fscache_stat(&fscache_n_relinquishes);
47629+ fscache_stat_unchecked(&fscache_n_relinquishes);
47630 if (retire)
47631- fscache_stat(&fscache_n_relinquishes_retire);
47632+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47633
47634 if (!cookie) {
47635- fscache_stat(&fscache_n_relinquishes_null);
47636+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
47637 _leave(" [no cookie]");
47638 return;
47639 }
47640@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47641
47642 /* wait for the cookie to finish being instantiated (or to fail) */
47643 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47644- fscache_stat(&fscache_n_relinquishes_waitcrt);
47645+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47646 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47647 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47648 }
47649diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47650index f6aad48..88dcf26 100644
47651--- a/fs/fscache/internal.h
47652+++ b/fs/fscache/internal.h
47653@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47654 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47655 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47656
47657-extern atomic_t fscache_n_op_pend;
47658-extern atomic_t fscache_n_op_run;
47659-extern atomic_t fscache_n_op_enqueue;
47660-extern atomic_t fscache_n_op_deferred_release;
47661-extern atomic_t fscache_n_op_release;
47662-extern atomic_t fscache_n_op_gc;
47663-extern atomic_t fscache_n_op_cancelled;
47664-extern atomic_t fscache_n_op_rejected;
47665+extern atomic_unchecked_t fscache_n_op_pend;
47666+extern atomic_unchecked_t fscache_n_op_run;
47667+extern atomic_unchecked_t fscache_n_op_enqueue;
47668+extern atomic_unchecked_t fscache_n_op_deferred_release;
47669+extern atomic_unchecked_t fscache_n_op_release;
47670+extern atomic_unchecked_t fscache_n_op_gc;
47671+extern atomic_unchecked_t fscache_n_op_cancelled;
47672+extern atomic_unchecked_t fscache_n_op_rejected;
47673
47674-extern atomic_t fscache_n_attr_changed;
47675-extern atomic_t fscache_n_attr_changed_ok;
47676-extern atomic_t fscache_n_attr_changed_nobufs;
47677-extern atomic_t fscache_n_attr_changed_nomem;
47678-extern atomic_t fscache_n_attr_changed_calls;
47679+extern atomic_unchecked_t fscache_n_attr_changed;
47680+extern atomic_unchecked_t fscache_n_attr_changed_ok;
47681+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47682+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47683+extern atomic_unchecked_t fscache_n_attr_changed_calls;
47684
47685-extern atomic_t fscache_n_allocs;
47686-extern atomic_t fscache_n_allocs_ok;
47687-extern atomic_t fscache_n_allocs_wait;
47688-extern atomic_t fscache_n_allocs_nobufs;
47689-extern atomic_t fscache_n_allocs_intr;
47690-extern atomic_t fscache_n_allocs_object_dead;
47691-extern atomic_t fscache_n_alloc_ops;
47692-extern atomic_t fscache_n_alloc_op_waits;
47693+extern atomic_unchecked_t fscache_n_allocs;
47694+extern atomic_unchecked_t fscache_n_allocs_ok;
47695+extern atomic_unchecked_t fscache_n_allocs_wait;
47696+extern atomic_unchecked_t fscache_n_allocs_nobufs;
47697+extern atomic_unchecked_t fscache_n_allocs_intr;
47698+extern atomic_unchecked_t fscache_n_allocs_object_dead;
47699+extern atomic_unchecked_t fscache_n_alloc_ops;
47700+extern atomic_unchecked_t fscache_n_alloc_op_waits;
47701
47702-extern atomic_t fscache_n_retrievals;
47703-extern atomic_t fscache_n_retrievals_ok;
47704-extern atomic_t fscache_n_retrievals_wait;
47705-extern atomic_t fscache_n_retrievals_nodata;
47706-extern atomic_t fscache_n_retrievals_nobufs;
47707-extern atomic_t fscache_n_retrievals_intr;
47708-extern atomic_t fscache_n_retrievals_nomem;
47709-extern atomic_t fscache_n_retrievals_object_dead;
47710-extern atomic_t fscache_n_retrieval_ops;
47711-extern atomic_t fscache_n_retrieval_op_waits;
47712+extern atomic_unchecked_t fscache_n_retrievals;
47713+extern atomic_unchecked_t fscache_n_retrievals_ok;
47714+extern atomic_unchecked_t fscache_n_retrievals_wait;
47715+extern atomic_unchecked_t fscache_n_retrievals_nodata;
47716+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47717+extern atomic_unchecked_t fscache_n_retrievals_intr;
47718+extern atomic_unchecked_t fscache_n_retrievals_nomem;
47719+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47720+extern atomic_unchecked_t fscache_n_retrieval_ops;
47721+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47722
47723-extern atomic_t fscache_n_stores;
47724-extern atomic_t fscache_n_stores_ok;
47725-extern atomic_t fscache_n_stores_again;
47726-extern atomic_t fscache_n_stores_nobufs;
47727-extern atomic_t fscache_n_stores_oom;
47728-extern atomic_t fscache_n_store_ops;
47729-extern atomic_t fscache_n_store_calls;
47730-extern atomic_t fscache_n_store_pages;
47731-extern atomic_t fscache_n_store_radix_deletes;
47732-extern atomic_t fscache_n_store_pages_over_limit;
47733+extern atomic_unchecked_t fscache_n_stores;
47734+extern atomic_unchecked_t fscache_n_stores_ok;
47735+extern atomic_unchecked_t fscache_n_stores_again;
47736+extern atomic_unchecked_t fscache_n_stores_nobufs;
47737+extern atomic_unchecked_t fscache_n_stores_oom;
47738+extern atomic_unchecked_t fscache_n_store_ops;
47739+extern atomic_unchecked_t fscache_n_store_calls;
47740+extern atomic_unchecked_t fscache_n_store_pages;
47741+extern atomic_unchecked_t fscache_n_store_radix_deletes;
47742+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47743
47744-extern atomic_t fscache_n_store_vmscan_not_storing;
47745-extern atomic_t fscache_n_store_vmscan_gone;
47746-extern atomic_t fscache_n_store_vmscan_busy;
47747-extern atomic_t fscache_n_store_vmscan_cancelled;
47748+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47749+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47750+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47751+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47752
47753-extern atomic_t fscache_n_marks;
47754-extern atomic_t fscache_n_uncaches;
47755+extern atomic_unchecked_t fscache_n_marks;
47756+extern atomic_unchecked_t fscache_n_uncaches;
47757
47758-extern atomic_t fscache_n_acquires;
47759-extern atomic_t fscache_n_acquires_null;
47760-extern atomic_t fscache_n_acquires_no_cache;
47761-extern atomic_t fscache_n_acquires_ok;
47762-extern atomic_t fscache_n_acquires_nobufs;
47763-extern atomic_t fscache_n_acquires_oom;
47764+extern atomic_unchecked_t fscache_n_acquires;
47765+extern atomic_unchecked_t fscache_n_acquires_null;
47766+extern atomic_unchecked_t fscache_n_acquires_no_cache;
47767+extern atomic_unchecked_t fscache_n_acquires_ok;
47768+extern atomic_unchecked_t fscache_n_acquires_nobufs;
47769+extern atomic_unchecked_t fscache_n_acquires_oom;
47770
47771-extern atomic_t fscache_n_updates;
47772-extern atomic_t fscache_n_updates_null;
47773-extern atomic_t fscache_n_updates_run;
47774+extern atomic_unchecked_t fscache_n_updates;
47775+extern atomic_unchecked_t fscache_n_updates_null;
47776+extern atomic_unchecked_t fscache_n_updates_run;
47777
47778-extern atomic_t fscache_n_relinquishes;
47779-extern atomic_t fscache_n_relinquishes_null;
47780-extern atomic_t fscache_n_relinquishes_waitcrt;
47781-extern atomic_t fscache_n_relinquishes_retire;
47782+extern atomic_unchecked_t fscache_n_relinquishes;
47783+extern atomic_unchecked_t fscache_n_relinquishes_null;
47784+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47785+extern atomic_unchecked_t fscache_n_relinquishes_retire;
47786
47787-extern atomic_t fscache_n_cookie_index;
47788-extern atomic_t fscache_n_cookie_data;
47789-extern atomic_t fscache_n_cookie_special;
47790+extern atomic_unchecked_t fscache_n_cookie_index;
47791+extern atomic_unchecked_t fscache_n_cookie_data;
47792+extern atomic_unchecked_t fscache_n_cookie_special;
47793
47794-extern atomic_t fscache_n_object_alloc;
47795-extern atomic_t fscache_n_object_no_alloc;
47796-extern atomic_t fscache_n_object_lookups;
47797-extern atomic_t fscache_n_object_lookups_negative;
47798-extern atomic_t fscache_n_object_lookups_positive;
47799-extern atomic_t fscache_n_object_lookups_timed_out;
47800-extern atomic_t fscache_n_object_created;
47801-extern atomic_t fscache_n_object_avail;
47802-extern atomic_t fscache_n_object_dead;
47803+extern atomic_unchecked_t fscache_n_object_alloc;
47804+extern atomic_unchecked_t fscache_n_object_no_alloc;
47805+extern atomic_unchecked_t fscache_n_object_lookups;
47806+extern atomic_unchecked_t fscache_n_object_lookups_negative;
47807+extern atomic_unchecked_t fscache_n_object_lookups_positive;
47808+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
47809+extern atomic_unchecked_t fscache_n_object_created;
47810+extern atomic_unchecked_t fscache_n_object_avail;
47811+extern atomic_unchecked_t fscache_n_object_dead;
47812
47813-extern atomic_t fscache_n_checkaux_none;
47814-extern atomic_t fscache_n_checkaux_okay;
47815-extern atomic_t fscache_n_checkaux_update;
47816-extern atomic_t fscache_n_checkaux_obsolete;
47817+extern atomic_unchecked_t fscache_n_checkaux_none;
47818+extern atomic_unchecked_t fscache_n_checkaux_okay;
47819+extern atomic_unchecked_t fscache_n_checkaux_update;
47820+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
47821
47822 extern atomic_t fscache_n_cop_alloc_object;
47823 extern atomic_t fscache_n_cop_lookup_object;
47824@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
47825 atomic_inc(stat);
47826 }
47827
47828+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
47829+{
47830+ atomic_inc_unchecked(stat);
47831+}
47832+
47833 static inline void fscache_stat_d(atomic_t *stat)
47834 {
47835 atomic_dec(stat);
47836@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
47837
47838 #define __fscache_stat(stat) (NULL)
47839 #define fscache_stat(stat) do {} while (0)
47840+#define fscache_stat_unchecked(stat) do {} while (0)
47841 #define fscache_stat_d(stat) do {} while (0)
47842 #endif
47843
47844diff --git a/fs/fscache/object.c b/fs/fscache/object.c
47845index b6b897c..0ffff9c 100644
47846--- a/fs/fscache/object.c
47847+++ b/fs/fscache/object.c
47848@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47849 /* update the object metadata on disk */
47850 case FSCACHE_OBJECT_UPDATING:
47851 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
47852- fscache_stat(&fscache_n_updates_run);
47853+ fscache_stat_unchecked(&fscache_n_updates_run);
47854 fscache_stat(&fscache_n_cop_update_object);
47855 object->cache->ops->update_object(object);
47856 fscache_stat_d(&fscache_n_cop_update_object);
47857@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47858 spin_lock(&object->lock);
47859 object->state = FSCACHE_OBJECT_DEAD;
47860 spin_unlock(&object->lock);
47861- fscache_stat(&fscache_n_object_dead);
47862+ fscache_stat_unchecked(&fscache_n_object_dead);
47863 goto terminal_transit;
47864
47865 /* handle the parent cache of this object being withdrawn from
47866@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47867 spin_lock(&object->lock);
47868 object->state = FSCACHE_OBJECT_DEAD;
47869 spin_unlock(&object->lock);
47870- fscache_stat(&fscache_n_object_dead);
47871+ fscache_stat_unchecked(&fscache_n_object_dead);
47872 goto terminal_transit;
47873
47874 /* complain about the object being woken up once it is
47875@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47876 parent->cookie->def->name, cookie->def->name,
47877 object->cache->tag->name);
47878
47879- fscache_stat(&fscache_n_object_lookups);
47880+ fscache_stat_unchecked(&fscache_n_object_lookups);
47881 fscache_stat(&fscache_n_cop_lookup_object);
47882 ret = object->cache->ops->lookup_object(object);
47883 fscache_stat_d(&fscache_n_cop_lookup_object);
47884@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47885 if (ret == -ETIMEDOUT) {
47886 /* probably stuck behind another object, so move this one to
47887 * the back of the queue */
47888- fscache_stat(&fscache_n_object_lookups_timed_out);
47889+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
47890 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47891 }
47892
47893@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
47894
47895 spin_lock(&object->lock);
47896 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47897- fscache_stat(&fscache_n_object_lookups_negative);
47898+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
47899
47900 /* transit here to allow write requests to begin stacking up
47901 * and read requests to begin returning ENODATA */
47902@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
47903 * result, in which case there may be data available */
47904 spin_lock(&object->lock);
47905 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
47906- fscache_stat(&fscache_n_object_lookups_positive);
47907+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
47908
47909 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
47910
47911@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
47912 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47913 } else {
47914 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
47915- fscache_stat(&fscache_n_object_created);
47916+ fscache_stat_unchecked(&fscache_n_object_created);
47917
47918 object->state = FSCACHE_OBJECT_AVAILABLE;
47919 spin_unlock(&object->lock);
47920@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
47921 fscache_enqueue_dependents(object);
47922
47923 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
47924- fscache_stat(&fscache_n_object_avail);
47925+ fscache_stat_unchecked(&fscache_n_object_avail);
47926
47927 _leave("");
47928 }
47929@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47930 enum fscache_checkaux result;
47931
47932 if (!object->cookie->def->check_aux) {
47933- fscache_stat(&fscache_n_checkaux_none);
47934+ fscache_stat_unchecked(&fscache_n_checkaux_none);
47935 return FSCACHE_CHECKAUX_OKAY;
47936 }
47937
47938@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
47939 switch (result) {
47940 /* entry okay as is */
47941 case FSCACHE_CHECKAUX_OKAY:
47942- fscache_stat(&fscache_n_checkaux_okay);
47943+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
47944 break;
47945
47946 /* entry requires update */
47947 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
47948- fscache_stat(&fscache_n_checkaux_update);
47949+ fscache_stat_unchecked(&fscache_n_checkaux_update);
47950 break;
47951
47952 /* entry requires deletion */
47953 case FSCACHE_CHECKAUX_OBSOLETE:
47954- fscache_stat(&fscache_n_checkaux_obsolete);
47955+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
47956 break;
47957
47958 default:
47959diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
47960index 30afdfa..2256596 100644
47961--- a/fs/fscache/operation.c
47962+++ b/fs/fscache/operation.c
47963@@ -17,7 +17,7 @@
47964 #include <linux/slab.h>
47965 #include "internal.h"
47966
47967-atomic_t fscache_op_debug_id;
47968+atomic_unchecked_t fscache_op_debug_id;
47969 EXPORT_SYMBOL(fscache_op_debug_id);
47970
47971 /**
47972@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
47973 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
47974 ASSERTCMP(atomic_read(&op->usage), >, 0);
47975
47976- fscache_stat(&fscache_n_op_enqueue);
47977+ fscache_stat_unchecked(&fscache_n_op_enqueue);
47978 switch (op->flags & FSCACHE_OP_TYPE) {
47979 case FSCACHE_OP_ASYNC:
47980 _debug("queue async");
47981@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
47982 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
47983 if (op->processor)
47984 fscache_enqueue_operation(op);
47985- fscache_stat(&fscache_n_op_run);
47986+ fscache_stat_unchecked(&fscache_n_op_run);
47987 }
47988
47989 /*
47990@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
47991 if (object->n_ops > 1) {
47992 atomic_inc(&op->usage);
47993 list_add_tail(&op->pend_link, &object->pending_ops);
47994- fscache_stat(&fscache_n_op_pend);
47995+ fscache_stat_unchecked(&fscache_n_op_pend);
47996 } else if (!list_empty(&object->pending_ops)) {
47997 atomic_inc(&op->usage);
47998 list_add_tail(&op->pend_link, &object->pending_ops);
47999- fscache_stat(&fscache_n_op_pend);
48000+ fscache_stat_unchecked(&fscache_n_op_pend);
48001 fscache_start_operations(object);
48002 } else {
48003 ASSERTCMP(object->n_in_progress, ==, 0);
48004@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48005 object->n_exclusive++; /* reads and writes must wait */
48006 atomic_inc(&op->usage);
48007 list_add_tail(&op->pend_link, &object->pending_ops);
48008- fscache_stat(&fscache_n_op_pend);
48009+ fscache_stat_unchecked(&fscache_n_op_pend);
48010 ret = 0;
48011 } else {
48012 /* not allowed to submit ops in any other state */
48013@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48014 if (object->n_exclusive > 0) {
48015 atomic_inc(&op->usage);
48016 list_add_tail(&op->pend_link, &object->pending_ops);
48017- fscache_stat(&fscache_n_op_pend);
48018+ fscache_stat_unchecked(&fscache_n_op_pend);
48019 } else if (!list_empty(&object->pending_ops)) {
48020 atomic_inc(&op->usage);
48021 list_add_tail(&op->pend_link, &object->pending_ops);
48022- fscache_stat(&fscache_n_op_pend);
48023+ fscache_stat_unchecked(&fscache_n_op_pend);
48024 fscache_start_operations(object);
48025 } else {
48026 ASSERTCMP(object->n_exclusive, ==, 0);
48027@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48028 object->n_ops++;
48029 atomic_inc(&op->usage);
48030 list_add_tail(&op->pend_link, &object->pending_ops);
48031- fscache_stat(&fscache_n_op_pend);
48032+ fscache_stat_unchecked(&fscache_n_op_pend);
48033 ret = 0;
48034 } else if (object->state == FSCACHE_OBJECT_DYING ||
48035 object->state == FSCACHE_OBJECT_LC_DYING ||
48036 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48037- fscache_stat(&fscache_n_op_rejected);
48038+ fscache_stat_unchecked(&fscache_n_op_rejected);
48039 ret = -ENOBUFS;
48040 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48041 fscache_report_unexpected_submission(object, op, ostate);
48042@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48043
48044 ret = -EBUSY;
48045 if (!list_empty(&op->pend_link)) {
48046- fscache_stat(&fscache_n_op_cancelled);
48047+ fscache_stat_unchecked(&fscache_n_op_cancelled);
48048 list_del_init(&op->pend_link);
48049 object->n_ops--;
48050 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48051@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48052 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48053 BUG();
48054
48055- fscache_stat(&fscache_n_op_release);
48056+ fscache_stat_unchecked(&fscache_n_op_release);
48057
48058 if (op->release) {
48059 op->release(op);
48060@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48061 * lock, and defer it otherwise */
48062 if (!spin_trylock(&object->lock)) {
48063 _debug("defer put");
48064- fscache_stat(&fscache_n_op_deferred_release);
48065+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
48066
48067 cache = object->cache;
48068 spin_lock(&cache->op_gc_list_lock);
48069@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48070
48071 _debug("GC DEFERRED REL OBJ%x OP%x",
48072 object->debug_id, op->debug_id);
48073- fscache_stat(&fscache_n_op_gc);
48074+ fscache_stat_unchecked(&fscache_n_op_gc);
48075
48076 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48077
48078diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48079index 3f7a59b..cf196cc 100644
48080--- a/fs/fscache/page.c
48081+++ b/fs/fscache/page.c
48082@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48083 val = radix_tree_lookup(&cookie->stores, page->index);
48084 if (!val) {
48085 rcu_read_unlock();
48086- fscache_stat(&fscache_n_store_vmscan_not_storing);
48087+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48088 __fscache_uncache_page(cookie, page);
48089 return true;
48090 }
48091@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48092 spin_unlock(&cookie->stores_lock);
48093
48094 if (xpage) {
48095- fscache_stat(&fscache_n_store_vmscan_cancelled);
48096- fscache_stat(&fscache_n_store_radix_deletes);
48097+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48098+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48099 ASSERTCMP(xpage, ==, page);
48100 } else {
48101- fscache_stat(&fscache_n_store_vmscan_gone);
48102+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48103 }
48104
48105 wake_up_bit(&cookie->flags, 0);
48106@@ -107,7 +107,7 @@ page_busy:
48107 /* we might want to wait here, but that could deadlock the allocator as
48108 * the work threads writing to the cache may all end up sleeping
48109 * on memory allocation */
48110- fscache_stat(&fscache_n_store_vmscan_busy);
48111+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48112 return false;
48113 }
48114 EXPORT_SYMBOL(__fscache_maybe_release_page);
48115@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48116 FSCACHE_COOKIE_STORING_TAG);
48117 if (!radix_tree_tag_get(&cookie->stores, page->index,
48118 FSCACHE_COOKIE_PENDING_TAG)) {
48119- fscache_stat(&fscache_n_store_radix_deletes);
48120+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48121 xpage = radix_tree_delete(&cookie->stores, page->index);
48122 }
48123 spin_unlock(&cookie->stores_lock);
48124@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48125
48126 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48127
48128- fscache_stat(&fscache_n_attr_changed_calls);
48129+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48130
48131 if (fscache_object_is_active(object)) {
48132 fscache_stat(&fscache_n_cop_attr_changed);
48133@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48134
48135 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48136
48137- fscache_stat(&fscache_n_attr_changed);
48138+ fscache_stat_unchecked(&fscache_n_attr_changed);
48139
48140 op = kzalloc(sizeof(*op), GFP_KERNEL);
48141 if (!op) {
48142- fscache_stat(&fscache_n_attr_changed_nomem);
48143+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48144 _leave(" = -ENOMEM");
48145 return -ENOMEM;
48146 }
48147@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48148 if (fscache_submit_exclusive_op(object, op) < 0)
48149 goto nobufs;
48150 spin_unlock(&cookie->lock);
48151- fscache_stat(&fscache_n_attr_changed_ok);
48152+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48153 fscache_put_operation(op);
48154 _leave(" = 0");
48155 return 0;
48156@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48157 nobufs:
48158 spin_unlock(&cookie->lock);
48159 kfree(op);
48160- fscache_stat(&fscache_n_attr_changed_nobufs);
48161+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48162 _leave(" = %d", -ENOBUFS);
48163 return -ENOBUFS;
48164 }
48165@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48166 /* allocate a retrieval operation and attempt to submit it */
48167 op = kzalloc(sizeof(*op), GFP_NOIO);
48168 if (!op) {
48169- fscache_stat(&fscache_n_retrievals_nomem);
48170+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48171 return NULL;
48172 }
48173
48174@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48175 return 0;
48176 }
48177
48178- fscache_stat(&fscache_n_retrievals_wait);
48179+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
48180
48181 jif = jiffies;
48182 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48183 fscache_wait_bit_interruptible,
48184 TASK_INTERRUPTIBLE) != 0) {
48185- fscache_stat(&fscache_n_retrievals_intr);
48186+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48187 _leave(" = -ERESTARTSYS");
48188 return -ERESTARTSYS;
48189 }
48190@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48191 */
48192 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48193 struct fscache_retrieval *op,
48194- atomic_t *stat_op_waits,
48195- atomic_t *stat_object_dead)
48196+ atomic_unchecked_t *stat_op_waits,
48197+ atomic_unchecked_t *stat_object_dead)
48198 {
48199 int ret;
48200
48201@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48202 goto check_if_dead;
48203
48204 _debug(">>> WT");
48205- fscache_stat(stat_op_waits);
48206+ fscache_stat_unchecked(stat_op_waits);
48207 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48208 fscache_wait_bit_interruptible,
48209 TASK_INTERRUPTIBLE) < 0) {
48210@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48211
48212 check_if_dead:
48213 if (unlikely(fscache_object_is_dead(object))) {
48214- fscache_stat(stat_object_dead);
48215+ fscache_stat_unchecked(stat_object_dead);
48216 return -ENOBUFS;
48217 }
48218 return 0;
48219@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48220
48221 _enter("%p,%p,,,", cookie, page);
48222
48223- fscache_stat(&fscache_n_retrievals);
48224+ fscache_stat_unchecked(&fscache_n_retrievals);
48225
48226 if (hlist_empty(&cookie->backing_objects))
48227 goto nobufs;
48228@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48229 goto nobufs_unlock;
48230 spin_unlock(&cookie->lock);
48231
48232- fscache_stat(&fscache_n_retrieval_ops);
48233+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48234
48235 /* pin the netfs read context in case we need to do the actual netfs
48236 * read because we've encountered a cache read failure */
48237@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48238
48239 error:
48240 if (ret == -ENOMEM)
48241- fscache_stat(&fscache_n_retrievals_nomem);
48242+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48243 else if (ret == -ERESTARTSYS)
48244- fscache_stat(&fscache_n_retrievals_intr);
48245+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48246 else if (ret == -ENODATA)
48247- fscache_stat(&fscache_n_retrievals_nodata);
48248+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48249 else if (ret < 0)
48250- fscache_stat(&fscache_n_retrievals_nobufs);
48251+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48252 else
48253- fscache_stat(&fscache_n_retrievals_ok);
48254+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48255
48256 fscache_put_retrieval(op);
48257 _leave(" = %d", ret);
48258@@ -429,7 +429,7 @@ nobufs_unlock:
48259 spin_unlock(&cookie->lock);
48260 kfree(op);
48261 nobufs:
48262- fscache_stat(&fscache_n_retrievals_nobufs);
48263+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48264 _leave(" = -ENOBUFS");
48265 return -ENOBUFS;
48266 }
48267@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48268
48269 _enter("%p,,%d,,,", cookie, *nr_pages);
48270
48271- fscache_stat(&fscache_n_retrievals);
48272+ fscache_stat_unchecked(&fscache_n_retrievals);
48273
48274 if (hlist_empty(&cookie->backing_objects))
48275 goto nobufs;
48276@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48277 goto nobufs_unlock;
48278 spin_unlock(&cookie->lock);
48279
48280- fscache_stat(&fscache_n_retrieval_ops);
48281+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48282
48283 /* pin the netfs read context in case we need to do the actual netfs
48284 * read because we've encountered a cache read failure */
48285@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48286
48287 error:
48288 if (ret == -ENOMEM)
48289- fscache_stat(&fscache_n_retrievals_nomem);
48290+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48291 else if (ret == -ERESTARTSYS)
48292- fscache_stat(&fscache_n_retrievals_intr);
48293+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48294 else if (ret == -ENODATA)
48295- fscache_stat(&fscache_n_retrievals_nodata);
48296+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48297 else if (ret < 0)
48298- fscache_stat(&fscache_n_retrievals_nobufs);
48299+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48300 else
48301- fscache_stat(&fscache_n_retrievals_ok);
48302+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48303
48304 fscache_put_retrieval(op);
48305 _leave(" = %d", ret);
48306@@ -545,7 +545,7 @@ nobufs_unlock:
48307 spin_unlock(&cookie->lock);
48308 kfree(op);
48309 nobufs:
48310- fscache_stat(&fscache_n_retrievals_nobufs);
48311+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48312 _leave(" = -ENOBUFS");
48313 return -ENOBUFS;
48314 }
48315@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48316
48317 _enter("%p,%p,,,", cookie, page);
48318
48319- fscache_stat(&fscache_n_allocs);
48320+ fscache_stat_unchecked(&fscache_n_allocs);
48321
48322 if (hlist_empty(&cookie->backing_objects))
48323 goto nobufs;
48324@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48325 goto nobufs_unlock;
48326 spin_unlock(&cookie->lock);
48327
48328- fscache_stat(&fscache_n_alloc_ops);
48329+ fscache_stat_unchecked(&fscache_n_alloc_ops);
48330
48331 ret = fscache_wait_for_retrieval_activation(
48332 object, op,
48333@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48334
48335 error:
48336 if (ret == -ERESTARTSYS)
48337- fscache_stat(&fscache_n_allocs_intr);
48338+ fscache_stat_unchecked(&fscache_n_allocs_intr);
48339 else if (ret < 0)
48340- fscache_stat(&fscache_n_allocs_nobufs);
48341+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48342 else
48343- fscache_stat(&fscache_n_allocs_ok);
48344+ fscache_stat_unchecked(&fscache_n_allocs_ok);
48345
48346 fscache_put_retrieval(op);
48347 _leave(" = %d", ret);
48348@@ -625,7 +625,7 @@ nobufs_unlock:
48349 spin_unlock(&cookie->lock);
48350 kfree(op);
48351 nobufs:
48352- fscache_stat(&fscache_n_allocs_nobufs);
48353+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48354 _leave(" = -ENOBUFS");
48355 return -ENOBUFS;
48356 }
48357@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48358
48359 spin_lock(&cookie->stores_lock);
48360
48361- fscache_stat(&fscache_n_store_calls);
48362+ fscache_stat_unchecked(&fscache_n_store_calls);
48363
48364 /* find a page to store */
48365 page = NULL;
48366@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48367 page = results[0];
48368 _debug("gang %d [%lx]", n, page->index);
48369 if (page->index > op->store_limit) {
48370- fscache_stat(&fscache_n_store_pages_over_limit);
48371+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48372 goto superseded;
48373 }
48374
48375@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48376 spin_unlock(&cookie->stores_lock);
48377 spin_unlock(&object->lock);
48378
48379- fscache_stat(&fscache_n_store_pages);
48380+ fscache_stat_unchecked(&fscache_n_store_pages);
48381 fscache_stat(&fscache_n_cop_write_page);
48382 ret = object->cache->ops->write_page(op, page);
48383 fscache_stat_d(&fscache_n_cop_write_page);
48384@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48385 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48386 ASSERT(PageFsCache(page));
48387
48388- fscache_stat(&fscache_n_stores);
48389+ fscache_stat_unchecked(&fscache_n_stores);
48390
48391 op = kzalloc(sizeof(*op), GFP_NOIO);
48392 if (!op)
48393@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48394 spin_unlock(&cookie->stores_lock);
48395 spin_unlock(&object->lock);
48396
48397- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48398+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48399 op->store_limit = object->store_limit;
48400
48401 if (fscache_submit_op(object, &op->op) < 0)
48402@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48403
48404 spin_unlock(&cookie->lock);
48405 radix_tree_preload_end();
48406- fscache_stat(&fscache_n_store_ops);
48407- fscache_stat(&fscache_n_stores_ok);
48408+ fscache_stat_unchecked(&fscache_n_store_ops);
48409+ fscache_stat_unchecked(&fscache_n_stores_ok);
48410
48411 /* the work queue now carries its own ref on the object */
48412 fscache_put_operation(&op->op);
48413@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48414 return 0;
48415
48416 already_queued:
48417- fscache_stat(&fscache_n_stores_again);
48418+ fscache_stat_unchecked(&fscache_n_stores_again);
48419 already_pending:
48420 spin_unlock(&cookie->stores_lock);
48421 spin_unlock(&object->lock);
48422 spin_unlock(&cookie->lock);
48423 radix_tree_preload_end();
48424 kfree(op);
48425- fscache_stat(&fscache_n_stores_ok);
48426+ fscache_stat_unchecked(&fscache_n_stores_ok);
48427 _leave(" = 0");
48428 return 0;
48429
48430@@ -851,14 +851,14 @@ nobufs:
48431 spin_unlock(&cookie->lock);
48432 radix_tree_preload_end();
48433 kfree(op);
48434- fscache_stat(&fscache_n_stores_nobufs);
48435+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
48436 _leave(" = -ENOBUFS");
48437 return -ENOBUFS;
48438
48439 nomem_free:
48440 kfree(op);
48441 nomem:
48442- fscache_stat(&fscache_n_stores_oom);
48443+ fscache_stat_unchecked(&fscache_n_stores_oom);
48444 _leave(" = -ENOMEM");
48445 return -ENOMEM;
48446 }
48447@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48448 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48449 ASSERTCMP(page, !=, NULL);
48450
48451- fscache_stat(&fscache_n_uncaches);
48452+ fscache_stat_unchecked(&fscache_n_uncaches);
48453
48454 /* cache withdrawal may beat us to it */
48455 if (!PageFsCache(page))
48456@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48457 unsigned long loop;
48458
48459 #ifdef CONFIG_FSCACHE_STATS
48460- atomic_add(pagevec->nr, &fscache_n_marks);
48461+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48462 #endif
48463
48464 for (loop = 0; loop < pagevec->nr; loop++) {
48465diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48466index 4765190..2a067f2 100644
48467--- a/fs/fscache/stats.c
48468+++ b/fs/fscache/stats.c
48469@@ -18,95 +18,95 @@
48470 /*
48471 * operation counters
48472 */
48473-atomic_t fscache_n_op_pend;
48474-atomic_t fscache_n_op_run;
48475-atomic_t fscache_n_op_enqueue;
48476-atomic_t fscache_n_op_requeue;
48477-atomic_t fscache_n_op_deferred_release;
48478-atomic_t fscache_n_op_release;
48479-atomic_t fscache_n_op_gc;
48480-atomic_t fscache_n_op_cancelled;
48481-atomic_t fscache_n_op_rejected;
48482+atomic_unchecked_t fscache_n_op_pend;
48483+atomic_unchecked_t fscache_n_op_run;
48484+atomic_unchecked_t fscache_n_op_enqueue;
48485+atomic_unchecked_t fscache_n_op_requeue;
48486+atomic_unchecked_t fscache_n_op_deferred_release;
48487+atomic_unchecked_t fscache_n_op_release;
48488+atomic_unchecked_t fscache_n_op_gc;
48489+atomic_unchecked_t fscache_n_op_cancelled;
48490+atomic_unchecked_t fscache_n_op_rejected;
48491
48492-atomic_t fscache_n_attr_changed;
48493-atomic_t fscache_n_attr_changed_ok;
48494-atomic_t fscache_n_attr_changed_nobufs;
48495-atomic_t fscache_n_attr_changed_nomem;
48496-atomic_t fscache_n_attr_changed_calls;
48497+atomic_unchecked_t fscache_n_attr_changed;
48498+atomic_unchecked_t fscache_n_attr_changed_ok;
48499+atomic_unchecked_t fscache_n_attr_changed_nobufs;
48500+atomic_unchecked_t fscache_n_attr_changed_nomem;
48501+atomic_unchecked_t fscache_n_attr_changed_calls;
48502
48503-atomic_t fscache_n_allocs;
48504-atomic_t fscache_n_allocs_ok;
48505-atomic_t fscache_n_allocs_wait;
48506-atomic_t fscache_n_allocs_nobufs;
48507-atomic_t fscache_n_allocs_intr;
48508-atomic_t fscache_n_allocs_object_dead;
48509-atomic_t fscache_n_alloc_ops;
48510-atomic_t fscache_n_alloc_op_waits;
48511+atomic_unchecked_t fscache_n_allocs;
48512+atomic_unchecked_t fscache_n_allocs_ok;
48513+atomic_unchecked_t fscache_n_allocs_wait;
48514+atomic_unchecked_t fscache_n_allocs_nobufs;
48515+atomic_unchecked_t fscache_n_allocs_intr;
48516+atomic_unchecked_t fscache_n_allocs_object_dead;
48517+atomic_unchecked_t fscache_n_alloc_ops;
48518+atomic_unchecked_t fscache_n_alloc_op_waits;
48519
48520-atomic_t fscache_n_retrievals;
48521-atomic_t fscache_n_retrievals_ok;
48522-atomic_t fscache_n_retrievals_wait;
48523-atomic_t fscache_n_retrievals_nodata;
48524-atomic_t fscache_n_retrievals_nobufs;
48525-atomic_t fscache_n_retrievals_intr;
48526-atomic_t fscache_n_retrievals_nomem;
48527-atomic_t fscache_n_retrievals_object_dead;
48528-atomic_t fscache_n_retrieval_ops;
48529-atomic_t fscache_n_retrieval_op_waits;
48530+atomic_unchecked_t fscache_n_retrievals;
48531+atomic_unchecked_t fscache_n_retrievals_ok;
48532+atomic_unchecked_t fscache_n_retrievals_wait;
48533+atomic_unchecked_t fscache_n_retrievals_nodata;
48534+atomic_unchecked_t fscache_n_retrievals_nobufs;
48535+atomic_unchecked_t fscache_n_retrievals_intr;
48536+atomic_unchecked_t fscache_n_retrievals_nomem;
48537+atomic_unchecked_t fscache_n_retrievals_object_dead;
48538+atomic_unchecked_t fscache_n_retrieval_ops;
48539+atomic_unchecked_t fscache_n_retrieval_op_waits;
48540
48541-atomic_t fscache_n_stores;
48542-atomic_t fscache_n_stores_ok;
48543-atomic_t fscache_n_stores_again;
48544-atomic_t fscache_n_stores_nobufs;
48545-atomic_t fscache_n_stores_oom;
48546-atomic_t fscache_n_store_ops;
48547-atomic_t fscache_n_store_calls;
48548-atomic_t fscache_n_store_pages;
48549-atomic_t fscache_n_store_radix_deletes;
48550-atomic_t fscache_n_store_pages_over_limit;
48551+atomic_unchecked_t fscache_n_stores;
48552+atomic_unchecked_t fscache_n_stores_ok;
48553+atomic_unchecked_t fscache_n_stores_again;
48554+atomic_unchecked_t fscache_n_stores_nobufs;
48555+atomic_unchecked_t fscache_n_stores_oom;
48556+atomic_unchecked_t fscache_n_store_ops;
48557+atomic_unchecked_t fscache_n_store_calls;
48558+atomic_unchecked_t fscache_n_store_pages;
48559+atomic_unchecked_t fscache_n_store_radix_deletes;
48560+atomic_unchecked_t fscache_n_store_pages_over_limit;
48561
48562-atomic_t fscache_n_store_vmscan_not_storing;
48563-atomic_t fscache_n_store_vmscan_gone;
48564-atomic_t fscache_n_store_vmscan_busy;
48565-atomic_t fscache_n_store_vmscan_cancelled;
48566+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48567+atomic_unchecked_t fscache_n_store_vmscan_gone;
48568+atomic_unchecked_t fscache_n_store_vmscan_busy;
48569+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48570
48571-atomic_t fscache_n_marks;
48572-atomic_t fscache_n_uncaches;
48573+atomic_unchecked_t fscache_n_marks;
48574+atomic_unchecked_t fscache_n_uncaches;
48575
48576-atomic_t fscache_n_acquires;
48577-atomic_t fscache_n_acquires_null;
48578-atomic_t fscache_n_acquires_no_cache;
48579-atomic_t fscache_n_acquires_ok;
48580-atomic_t fscache_n_acquires_nobufs;
48581-atomic_t fscache_n_acquires_oom;
48582+atomic_unchecked_t fscache_n_acquires;
48583+atomic_unchecked_t fscache_n_acquires_null;
48584+atomic_unchecked_t fscache_n_acquires_no_cache;
48585+atomic_unchecked_t fscache_n_acquires_ok;
48586+atomic_unchecked_t fscache_n_acquires_nobufs;
48587+atomic_unchecked_t fscache_n_acquires_oom;
48588
48589-atomic_t fscache_n_updates;
48590-atomic_t fscache_n_updates_null;
48591-atomic_t fscache_n_updates_run;
48592+atomic_unchecked_t fscache_n_updates;
48593+atomic_unchecked_t fscache_n_updates_null;
48594+atomic_unchecked_t fscache_n_updates_run;
48595
48596-atomic_t fscache_n_relinquishes;
48597-atomic_t fscache_n_relinquishes_null;
48598-atomic_t fscache_n_relinquishes_waitcrt;
48599-atomic_t fscache_n_relinquishes_retire;
48600+atomic_unchecked_t fscache_n_relinquishes;
48601+atomic_unchecked_t fscache_n_relinquishes_null;
48602+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48603+atomic_unchecked_t fscache_n_relinquishes_retire;
48604
48605-atomic_t fscache_n_cookie_index;
48606-atomic_t fscache_n_cookie_data;
48607-atomic_t fscache_n_cookie_special;
48608+atomic_unchecked_t fscache_n_cookie_index;
48609+atomic_unchecked_t fscache_n_cookie_data;
48610+atomic_unchecked_t fscache_n_cookie_special;
48611
48612-atomic_t fscache_n_object_alloc;
48613-atomic_t fscache_n_object_no_alloc;
48614-atomic_t fscache_n_object_lookups;
48615-atomic_t fscache_n_object_lookups_negative;
48616-atomic_t fscache_n_object_lookups_positive;
48617-atomic_t fscache_n_object_lookups_timed_out;
48618-atomic_t fscache_n_object_created;
48619-atomic_t fscache_n_object_avail;
48620-atomic_t fscache_n_object_dead;
48621+atomic_unchecked_t fscache_n_object_alloc;
48622+atomic_unchecked_t fscache_n_object_no_alloc;
48623+atomic_unchecked_t fscache_n_object_lookups;
48624+atomic_unchecked_t fscache_n_object_lookups_negative;
48625+atomic_unchecked_t fscache_n_object_lookups_positive;
48626+atomic_unchecked_t fscache_n_object_lookups_timed_out;
48627+atomic_unchecked_t fscache_n_object_created;
48628+atomic_unchecked_t fscache_n_object_avail;
48629+atomic_unchecked_t fscache_n_object_dead;
48630
48631-atomic_t fscache_n_checkaux_none;
48632-atomic_t fscache_n_checkaux_okay;
48633-atomic_t fscache_n_checkaux_update;
48634-atomic_t fscache_n_checkaux_obsolete;
48635+atomic_unchecked_t fscache_n_checkaux_none;
48636+atomic_unchecked_t fscache_n_checkaux_okay;
48637+atomic_unchecked_t fscache_n_checkaux_update;
48638+atomic_unchecked_t fscache_n_checkaux_obsolete;
48639
48640 atomic_t fscache_n_cop_alloc_object;
48641 atomic_t fscache_n_cop_lookup_object;
48642@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48643 seq_puts(m, "FS-Cache statistics\n");
48644
48645 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48646- atomic_read(&fscache_n_cookie_index),
48647- atomic_read(&fscache_n_cookie_data),
48648- atomic_read(&fscache_n_cookie_special));
48649+ atomic_read_unchecked(&fscache_n_cookie_index),
48650+ atomic_read_unchecked(&fscache_n_cookie_data),
48651+ atomic_read_unchecked(&fscache_n_cookie_special));
48652
48653 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48654- atomic_read(&fscache_n_object_alloc),
48655- atomic_read(&fscache_n_object_no_alloc),
48656- atomic_read(&fscache_n_object_avail),
48657- atomic_read(&fscache_n_object_dead));
48658+ atomic_read_unchecked(&fscache_n_object_alloc),
48659+ atomic_read_unchecked(&fscache_n_object_no_alloc),
48660+ atomic_read_unchecked(&fscache_n_object_avail),
48661+ atomic_read_unchecked(&fscache_n_object_dead));
48662 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48663- atomic_read(&fscache_n_checkaux_none),
48664- atomic_read(&fscache_n_checkaux_okay),
48665- atomic_read(&fscache_n_checkaux_update),
48666- atomic_read(&fscache_n_checkaux_obsolete));
48667+ atomic_read_unchecked(&fscache_n_checkaux_none),
48668+ atomic_read_unchecked(&fscache_n_checkaux_okay),
48669+ atomic_read_unchecked(&fscache_n_checkaux_update),
48670+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48671
48672 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48673- atomic_read(&fscache_n_marks),
48674- atomic_read(&fscache_n_uncaches));
48675+ atomic_read_unchecked(&fscache_n_marks),
48676+ atomic_read_unchecked(&fscache_n_uncaches));
48677
48678 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48679 " oom=%u\n",
48680- atomic_read(&fscache_n_acquires),
48681- atomic_read(&fscache_n_acquires_null),
48682- atomic_read(&fscache_n_acquires_no_cache),
48683- atomic_read(&fscache_n_acquires_ok),
48684- atomic_read(&fscache_n_acquires_nobufs),
48685- atomic_read(&fscache_n_acquires_oom));
48686+ atomic_read_unchecked(&fscache_n_acquires),
48687+ atomic_read_unchecked(&fscache_n_acquires_null),
48688+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
48689+ atomic_read_unchecked(&fscache_n_acquires_ok),
48690+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
48691+ atomic_read_unchecked(&fscache_n_acquires_oom));
48692
48693 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48694- atomic_read(&fscache_n_object_lookups),
48695- atomic_read(&fscache_n_object_lookups_negative),
48696- atomic_read(&fscache_n_object_lookups_positive),
48697- atomic_read(&fscache_n_object_created),
48698- atomic_read(&fscache_n_object_lookups_timed_out));
48699+ atomic_read_unchecked(&fscache_n_object_lookups),
48700+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
48701+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
48702+ atomic_read_unchecked(&fscache_n_object_created),
48703+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48704
48705 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48706- atomic_read(&fscache_n_updates),
48707- atomic_read(&fscache_n_updates_null),
48708- atomic_read(&fscache_n_updates_run));
48709+ atomic_read_unchecked(&fscache_n_updates),
48710+ atomic_read_unchecked(&fscache_n_updates_null),
48711+ atomic_read_unchecked(&fscache_n_updates_run));
48712
48713 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48714- atomic_read(&fscache_n_relinquishes),
48715- atomic_read(&fscache_n_relinquishes_null),
48716- atomic_read(&fscache_n_relinquishes_waitcrt),
48717- atomic_read(&fscache_n_relinquishes_retire));
48718+ atomic_read_unchecked(&fscache_n_relinquishes),
48719+ atomic_read_unchecked(&fscache_n_relinquishes_null),
48720+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48721+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
48722
48723 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48724- atomic_read(&fscache_n_attr_changed),
48725- atomic_read(&fscache_n_attr_changed_ok),
48726- atomic_read(&fscache_n_attr_changed_nobufs),
48727- atomic_read(&fscache_n_attr_changed_nomem),
48728- atomic_read(&fscache_n_attr_changed_calls));
48729+ atomic_read_unchecked(&fscache_n_attr_changed),
48730+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
48731+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48732+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48733+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
48734
48735 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48736- atomic_read(&fscache_n_allocs),
48737- atomic_read(&fscache_n_allocs_ok),
48738- atomic_read(&fscache_n_allocs_wait),
48739- atomic_read(&fscache_n_allocs_nobufs),
48740- atomic_read(&fscache_n_allocs_intr));
48741+ atomic_read_unchecked(&fscache_n_allocs),
48742+ atomic_read_unchecked(&fscache_n_allocs_ok),
48743+ atomic_read_unchecked(&fscache_n_allocs_wait),
48744+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
48745+ atomic_read_unchecked(&fscache_n_allocs_intr));
48746 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48747- atomic_read(&fscache_n_alloc_ops),
48748- atomic_read(&fscache_n_alloc_op_waits),
48749- atomic_read(&fscache_n_allocs_object_dead));
48750+ atomic_read_unchecked(&fscache_n_alloc_ops),
48751+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
48752+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
48753
48754 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48755 " int=%u oom=%u\n",
48756- atomic_read(&fscache_n_retrievals),
48757- atomic_read(&fscache_n_retrievals_ok),
48758- atomic_read(&fscache_n_retrievals_wait),
48759- atomic_read(&fscache_n_retrievals_nodata),
48760- atomic_read(&fscache_n_retrievals_nobufs),
48761- atomic_read(&fscache_n_retrievals_intr),
48762- atomic_read(&fscache_n_retrievals_nomem));
48763+ atomic_read_unchecked(&fscache_n_retrievals),
48764+ atomic_read_unchecked(&fscache_n_retrievals_ok),
48765+ atomic_read_unchecked(&fscache_n_retrievals_wait),
48766+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
48767+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48768+ atomic_read_unchecked(&fscache_n_retrievals_intr),
48769+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
48770 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48771- atomic_read(&fscache_n_retrieval_ops),
48772- atomic_read(&fscache_n_retrieval_op_waits),
48773- atomic_read(&fscache_n_retrievals_object_dead));
48774+ atomic_read_unchecked(&fscache_n_retrieval_ops),
48775+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48776+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48777
48778 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48779- atomic_read(&fscache_n_stores),
48780- atomic_read(&fscache_n_stores_ok),
48781- atomic_read(&fscache_n_stores_again),
48782- atomic_read(&fscache_n_stores_nobufs),
48783- atomic_read(&fscache_n_stores_oom));
48784+ atomic_read_unchecked(&fscache_n_stores),
48785+ atomic_read_unchecked(&fscache_n_stores_ok),
48786+ atomic_read_unchecked(&fscache_n_stores_again),
48787+ atomic_read_unchecked(&fscache_n_stores_nobufs),
48788+ atomic_read_unchecked(&fscache_n_stores_oom));
48789 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
48790- atomic_read(&fscache_n_store_ops),
48791- atomic_read(&fscache_n_store_calls),
48792- atomic_read(&fscache_n_store_pages),
48793- atomic_read(&fscache_n_store_radix_deletes),
48794- atomic_read(&fscache_n_store_pages_over_limit));
48795+ atomic_read_unchecked(&fscache_n_store_ops),
48796+ atomic_read_unchecked(&fscache_n_store_calls),
48797+ atomic_read_unchecked(&fscache_n_store_pages),
48798+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
48799+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
48800
48801 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
48802- atomic_read(&fscache_n_store_vmscan_not_storing),
48803- atomic_read(&fscache_n_store_vmscan_gone),
48804- atomic_read(&fscache_n_store_vmscan_busy),
48805- atomic_read(&fscache_n_store_vmscan_cancelled));
48806+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
48807+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
48808+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
48809+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
48810
48811 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
48812- atomic_read(&fscache_n_op_pend),
48813- atomic_read(&fscache_n_op_run),
48814- atomic_read(&fscache_n_op_enqueue),
48815- atomic_read(&fscache_n_op_cancelled),
48816- atomic_read(&fscache_n_op_rejected));
48817+ atomic_read_unchecked(&fscache_n_op_pend),
48818+ atomic_read_unchecked(&fscache_n_op_run),
48819+ atomic_read_unchecked(&fscache_n_op_enqueue),
48820+ atomic_read_unchecked(&fscache_n_op_cancelled),
48821+ atomic_read_unchecked(&fscache_n_op_rejected));
48822 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
48823- atomic_read(&fscache_n_op_deferred_release),
48824- atomic_read(&fscache_n_op_release),
48825- atomic_read(&fscache_n_op_gc));
48826+ atomic_read_unchecked(&fscache_n_op_deferred_release),
48827+ atomic_read_unchecked(&fscache_n_op_release),
48828+ atomic_read_unchecked(&fscache_n_op_gc));
48829
48830 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
48831 atomic_read(&fscache_n_cop_alloc_object),
48832diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
48833index ee8d550..7189d8c 100644
48834--- a/fs/fuse/cuse.c
48835+++ b/fs/fuse/cuse.c
48836@@ -585,10 +585,12 @@ static int __init cuse_init(void)
48837 INIT_LIST_HEAD(&cuse_conntbl[i]);
48838
48839 /* inherit and extend fuse_dev_operations */
48840- cuse_channel_fops = fuse_dev_operations;
48841- cuse_channel_fops.owner = THIS_MODULE;
48842- cuse_channel_fops.open = cuse_channel_open;
48843- cuse_channel_fops.release = cuse_channel_release;
48844+ pax_open_kernel();
48845+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
48846+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
48847+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
48848+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
48849+ pax_close_kernel();
48850
48851 cuse_class = class_create(THIS_MODULE, "cuse");
48852 if (IS_ERR(cuse_class))
48853diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
48854index 8c23fa7..0e3aac7 100644
48855--- a/fs/fuse/dev.c
48856+++ b/fs/fuse/dev.c
48857@@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
48858 ret = 0;
48859 pipe_lock(pipe);
48860
48861- if (!pipe->readers) {
48862+ if (!atomic_read(&pipe->readers)) {
48863 send_sig(SIGPIPE, current, 0);
48864 if (!ret)
48865 ret = -EPIPE;
48866diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
48867index 324bc08..4fdd56e 100644
48868--- a/fs/fuse/dir.c
48869+++ b/fs/fuse/dir.c
48870@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
48871 return link;
48872 }
48873
48874-static void free_link(char *link)
48875+static void free_link(const char *link)
48876 {
48877 if (!IS_ERR(link))
48878 free_page((unsigned long) link);
48879diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
48880index 381893c..3793318 100644
48881--- a/fs/gfs2/inode.c
48882+++ b/fs/gfs2/inode.c
48883@@ -1490,7 +1490,7 @@ out:
48884
48885 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48886 {
48887- char *s = nd_get_link(nd);
48888+ const char *s = nd_get_link(nd);
48889 if (!IS_ERR(s))
48890 kfree(s);
48891 }
48892diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
48893index c5bc355..163a13e 100644
48894--- a/fs/hugetlbfs/inode.c
48895+++ b/fs/hugetlbfs/inode.c
48896@@ -153,6 +153,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
48897 struct vm_area_struct *vma;
48898 unsigned long start_addr;
48899 struct hstate *h = hstate_file(file);
48900+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
48901
48902 if (len & ~huge_page_mask(h))
48903 return -EINVAL;
48904@@ -165,18 +166,21 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
48905 return addr;
48906 }
48907
48908+#ifdef CONFIG_PAX_RANDMMAP
48909+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
48910+#endif
48911+
48912 if (addr) {
48913 addr = ALIGN(addr, huge_page_size(h));
48914 vma = find_vma(mm, addr);
48915- if (TASK_SIZE - len >= addr &&
48916- (!vma || addr + len <= vma->vm_start))
48917+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
48918 return addr;
48919 }
48920
48921 if (len > mm->cached_hole_size)
48922 start_addr = mm->free_area_cache;
48923 else {
48924- start_addr = TASK_UNMAPPED_BASE;
48925+ start_addr = mm->mmap_base;
48926 mm->cached_hole_size = 0;
48927 }
48928
48929@@ -190,15 +194,15 @@ full_search:
48930 * Start a new search - just in case we missed
48931 * some holes.
48932 */
48933- if (start_addr != TASK_UNMAPPED_BASE) {
48934- start_addr = TASK_UNMAPPED_BASE;
48935+ if (start_addr != mm->mmap_base) {
48936+ start_addr = mm->mmap_base;
48937 mm->cached_hole_size = 0;
48938 goto full_search;
48939 }
48940 return -ENOMEM;
48941 }
48942
48943- if (!vma || addr + len <= vma->vm_start) {
48944+ if (check_heap_stack_gap(vma, addr, len, offset)) {
48945 mm->free_area_cache = addr + len;
48946 return addr;
48947 }
48948@@ -923,7 +927,7 @@ static struct file_system_type hugetlbfs_fs_type = {
48949 .kill_sb = kill_litter_super,
48950 };
48951
48952-static struct vfsmount *hugetlbfs_vfsmount;
48953+struct vfsmount *hugetlbfs_vfsmount;
48954
48955 static int can_do_hugetlb_shm(void)
48956 {
48957diff --git a/fs/inode.c b/fs/inode.c
48958index 64999f1..8fad608 100644
48959--- a/fs/inode.c
48960+++ b/fs/inode.c
48961@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
48962
48963 #ifdef CONFIG_SMP
48964 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
48965- static atomic_t shared_last_ino;
48966- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
48967+ static atomic_unchecked_t shared_last_ino;
48968+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
48969
48970 res = next - LAST_INO_BATCH;
48971 }
48972diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
48973index 4a6cf28..d3a29d3 100644
48974--- a/fs/jffs2/erase.c
48975+++ b/fs/jffs2/erase.c
48976@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
48977 struct jffs2_unknown_node marker = {
48978 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
48979 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48980- .totlen = cpu_to_je32(c->cleanmarker_size)
48981+ .totlen = cpu_to_je32(c->cleanmarker_size),
48982+ .hdr_crc = cpu_to_je32(0)
48983 };
48984
48985 jffs2_prealloc_raw_node_refs(c, jeb, 1);
48986diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
48987index a6597d6..41b30ec 100644
48988--- a/fs/jffs2/wbuf.c
48989+++ b/fs/jffs2/wbuf.c
48990@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
48991 {
48992 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
48993 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
48994- .totlen = constant_cpu_to_je32(8)
48995+ .totlen = constant_cpu_to_je32(8),
48996+ .hdr_crc = constant_cpu_to_je32(0)
48997 };
48998
48999 /*
49000diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49001index 1a543be..d803c40 100644
49002--- a/fs/jfs/super.c
49003+++ b/fs/jfs/super.c
49004@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49005
49006 jfs_inode_cachep =
49007 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49008- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49009+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49010 init_once);
49011 if (jfs_inode_cachep == NULL)
49012 return -ENOMEM;
49013diff --git a/fs/libfs.c b/fs/libfs.c
49014index 7cc37ca..b3e3eec 100644
49015--- a/fs/libfs.c
49016+++ b/fs/libfs.c
49017@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49018
49019 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49020 struct dentry *next;
49021+ char d_name[sizeof(next->d_iname)];
49022+ const unsigned char *name;
49023+
49024 next = list_entry(p, struct dentry, d_u.d_child);
49025 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49026 if (!simple_positive(next)) {
49027@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49028
49029 spin_unlock(&next->d_lock);
49030 spin_unlock(&dentry->d_lock);
49031- if (filldir(dirent, next->d_name.name,
49032+ name = next->d_name.name;
49033+ if (name == next->d_iname) {
49034+ memcpy(d_name, name, next->d_name.len);
49035+ name = d_name;
49036+ }
49037+ if (filldir(dirent, name,
49038 next->d_name.len, filp->f_pos,
49039 next->d_inode->i_ino,
49040 dt_type(next->d_inode)) < 0)
49041diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49042index 05d2912..760abfa 100644
49043--- a/fs/lockd/clntproc.c
49044+++ b/fs/lockd/clntproc.c
49045@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49046 /*
49047 * Cookie counter for NLM requests
49048 */
49049-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49050+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49051
49052 void nlmclnt_next_cookie(struct nlm_cookie *c)
49053 {
49054- u32 cookie = atomic_inc_return(&nlm_cookie);
49055+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49056
49057 memcpy(c->data, &cookie, 4);
49058 c->len=4;
49059diff --git a/fs/locks.c b/fs/locks.c
49060index a94e331..060bce3 100644
49061--- a/fs/locks.c
49062+++ b/fs/locks.c
49063@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49064 return;
49065
49066 if (filp->f_op && filp->f_op->flock) {
49067- struct file_lock fl = {
49068+ struct file_lock flock = {
49069 .fl_pid = current->tgid,
49070 .fl_file = filp,
49071 .fl_flags = FL_FLOCK,
49072 .fl_type = F_UNLCK,
49073 .fl_end = OFFSET_MAX,
49074 };
49075- filp->f_op->flock(filp, F_SETLKW, &fl);
49076- if (fl.fl_ops && fl.fl_ops->fl_release_private)
49077- fl.fl_ops->fl_release_private(&fl);
49078+ filp->f_op->flock(filp, F_SETLKW, &flock);
49079+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
49080+ flock.fl_ops->fl_release_private(&flock);
49081 }
49082
49083 lock_flocks();
49084diff --git a/fs/namei.c b/fs/namei.c
49085index 5f4cdf3..959a013 100644
49086--- a/fs/namei.c
49087+++ b/fs/namei.c
49088@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49089 if (ret != -EACCES)
49090 return ret;
49091
49092+#ifdef CONFIG_GRKERNSEC
49093+ /* we'll block if we have to log due to a denied capability use */
49094+ if (mask & MAY_NOT_BLOCK)
49095+ return -ECHILD;
49096+#endif
49097+
49098 if (S_ISDIR(inode->i_mode)) {
49099 /* DACs are overridable for directories */
49100- if (inode_capable(inode, CAP_DAC_OVERRIDE))
49101- return 0;
49102 if (!(mask & MAY_WRITE))
49103- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49104+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49105+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49106 return 0;
49107+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
49108+ return 0;
49109 return -EACCES;
49110 }
49111 /*
49112+ * Searching includes executable on directories, else just read.
49113+ */
49114+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49115+ if (mask == MAY_READ)
49116+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49117+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49118+ return 0;
49119+
49120+ /*
49121 * Read/write DACs are always overridable.
49122 * Executable DACs are overridable when there is
49123 * at least one exec bit set.
49124@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49125 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49126 return 0;
49127
49128- /*
49129- * Searching includes executable on directories, else just read.
49130- */
49131- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49132- if (mask == MAY_READ)
49133- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49134- return 0;
49135-
49136 return -EACCES;
49137 }
49138
49139@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49140 {
49141 struct dentry *dentry = link->dentry;
49142 int error;
49143- char *s;
49144+ const char *s;
49145
49146 BUG_ON(nd->flags & LOOKUP_RCU);
49147
49148@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49149 if (error)
49150 goto out_put_nd_path;
49151
49152+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
49153+ dentry->d_inode, dentry, nd->path.mnt)) {
49154+ error = -EACCES;
49155+ goto out_put_nd_path;
49156+ }
49157+
49158 nd->last_type = LAST_BIND;
49159 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49160 error = PTR_ERR(*p);
49161@@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49162 break;
49163 res = walk_component(nd, path, &nd->last,
49164 nd->last_type, LOOKUP_FOLLOW);
49165+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49166+ res = -EACCES;
49167 put_link(nd, &link, cookie);
49168 } while (res > 0);
49169
49170@@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49171 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49172 {
49173 unsigned long a, b, adata, bdata, mask, hash, len;
49174- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49175+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49176
49177 hash = a = 0;
49178 len = -sizeof(unsigned long);
49179@@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49180 if (err)
49181 break;
49182 err = lookup_last(nd, &path);
49183+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
49184+ err = -EACCES;
49185 put_link(nd, &link, cookie);
49186 }
49187 }
49188@@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49189 if (!err)
49190 err = complete_walk(nd);
49191
49192+ if (!(nd->flags & LOOKUP_PARENT)) {
49193+#ifdef CONFIG_GRKERNSEC
49194+ if (flags & LOOKUP_RCU) {
49195+ if (!err)
49196+ path_put(&nd->path);
49197+ err = -ECHILD;
49198+ } else
49199+#endif
49200+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49201+ if (!err)
49202+ path_put(&nd->path);
49203+ err = -ENOENT;
49204+ }
49205+ }
49206+
49207 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49208 if (!nd->inode->i_op->lookup) {
49209 path_put(&nd->path);
49210@@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49211 retval = path_lookupat(dfd, name->name,
49212 flags | LOOKUP_REVAL, nd);
49213
49214- if (likely(!retval))
49215+ if (likely(!retval)) {
49216+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49217+#ifdef CONFIG_GRKERNSEC
49218+ if (flags & LOOKUP_RCU)
49219+ return -ECHILD;
49220+#endif
49221+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49222+ return -ENOENT;
49223+ }
49224 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49225+ }
49226 return retval;
49227 }
49228
49229@@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49230 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49231 return -EPERM;
49232
49233+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49234+ return -EPERM;
49235+ if (gr_handle_rawio(inode))
49236+ return -EPERM;
49237+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49238+ return -EACCES;
49239+
49240 return 0;
49241 }
49242
49243@@ -2623,7 +2672,7 @@ looked_up:
49244 * cleared otherwise prior to returning.
49245 */
49246 static int lookup_open(struct nameidata *nd, struct path *path,
49247- struct file *file,
49248+ struct path *link, struct file *file,
49249 const struct open_flags *op,
49250 bool got_write, int *opened)
49251 {
49252@@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49253 /* Negative dentry, just create the file */
49254 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49255 umode_t mode = op->mode;
49256+
49257+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49258+ error = -EACCES;
49259+ goto out_dput;
49260+ }
49261+
49262+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49263+ error = -EACCES;
49264+ goto out_dput;
49265+ }
49266+
49267 if (!IS_POSIXACL(dir->d_inode))
49268 mode &= ~current_umask();
49269 /*
49270@@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49271 nd->flags & LOOKUP_EXCL);
49272 if (error)
49273 goto out_dput;
49274+ else
49275+ gr_handle_create(dentry, nd->path.mnt);
49276 }
49277 out_no_open:
49278 path->dentry = dentry;
49279@@ -2693,7 +2755,7 @@ out_dput:
49280 /*
49281 * Handle the last step of open()
49282 */
49283-static int do_last(struct nameidata *nd, struct path *path,
49284+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49285 struct file *file, const struct open_flags *op,
49286 int *opened, struct filename *name)
49287 {
49288@@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49289 error = complete_walk(nd);
49290 if (error)
49291 return error;
49292+#ifdef CONFIG_GRKERNSEC
49293+ if (nd->flags & LOOKUP_RCU) {
49294+ error = -ECHILD;
49295+ goto out;
49296+ }
49297+#endif
49298+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49299+ error = -ENOENT;
49300+ goto out;
49301+ }
49302 audit_inode(name, nd->path.dentry, 0);
49303 if (open_flag & O_CREAT) {
49304 error = -EISDIR;
49305 goto out;
49306 }
49307+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49308+ error = -EACCES;
49309+ goto out;
49310+ }
49311 goto finish_open;
49312 case LAST_BIND:
49313 error = complete_walk(nd);
49314 if (error)
49315 return error;
49316+#ifdef CONFIG_GRKERNSEC
49317+ if (nd->flags & LOOKUP_RCU) {
49318+ error = -ECHILD;
49319+ goto out;
49320+ }
49321+#endif
49322+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49323+ error = -ENOENT;
49324+ goto out;
49325+ }
49326+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49327+ error = -EACCES;
49328+ goto out;
49329+ }
49330 audit_inode(name, dir, 0);
49331 goto finish_open;
49332 }
49333@@ -2780,7 +2870,7 @@ retry_lookup:
49334 */
49335 }
49336 mutex_lock(&dir->d_inode->i_mutex);
49337- error = lookup_open(nd, path, file, op, got_write, opened);
49338+ error = lookup_open(nd, path, link, file, op, got_write, opened);
49339 mutex_unlock(&dir->d_inode->i_mutex);
49340
49341 if (error <= 0) {
49342@@ -2804,11 +2894,28 @@ retry_lookup:
49343 goto finish_open_created;
49344 }
49345
49346+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49347+ error = -ENOENT;
49348+ goto exit_dput;
49349+ }
49350+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49351+ error = -EACCES;
49352+ goto exit_dput;
49353+ }
49354+
49355 /*
49356 * create/update audit record if it already exists.
49357 */
49358- if (path->dentry->d_inode)
49359+ if (path->dentry->d_inode) {
49360+ /* only check if O_CREAT is specified, all other checks need to go
49361+ into may_open */
49362+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49363+ error = -EACCES;
49364+ goto exit_dput;
49365+ }
49366+
49367 audit_inode(name, path->dentry, 0);
49368+ }
49369
49370 /*
49371 * If atomic_open() acquired write access it is dropped now due to
49372@@ -2849,6 +2956,11 @@ finish_lookup:
49373 }
49374 }
49375 BUG_ON(inode != path->dentry->d_inode);
49376+ /* if we're resolving a symlink to another symlink */
49377+ if (link && gr_handle_symlink_owner(link, inode)) {
49378+ error = -EACCES;
49379+ goto out;
49380+ }
49381 return 1;
49382 }
49383
49384@@ -2858,7 +2970,6 @@ finish_lookup:
49385 save_parent.dentry = nd->path.dentry;
49386 save_parent.mnt = mntget(path->mnt);
49387 nd->path.dentry = path->dentry;
49388-
49389 }
49390 nd->inode = inode;
49391 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49392@@ -2867,6 +2978,22 @@ finish_lookup:
49393 path_put(&save_parent);
49394 return error;
49395 }
49396+
49397+#ifdef CONFIG_GRKERNSEC
49398+ if (nd->flags & LOOKUP_RCU) {
49399+ error = -ECHILD;
49400+ goto out;
49401+ }
49402+#endif
49403+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49404+ error = -ENOENT;
49405+ goto out;
49406+ }
49407+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49408+ error = -EACCES;
49409+ goto out;
49410+ }
49411+
49412 error = -EISDIR;
49413 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49414 goto out;
49415@@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49416 if (unlikely(error))
49417 goto out;
49418
49419- error = do_last(nd, &path, file, op, &opened, pathname);
49420+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49421 while (unlikely(error > 0)) { /* trailing symlink */
49422 struct path link = path;
49423 void *cookie;
49424@@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49425 error = follow_link(&link, nd, &cookie);
49426 if (unlikely(error))
49427 break;
49428- error = do_last(nd, &path, file, op, &opened, pathname);
49429+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
49430 put_link(nd, &link, cookie);
49431 }
49432 out:
49433@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49434 goto unlock;
49435
49436 error = -EEXIST;
49437- if (dentry->d_inode)
49438+ if (dentry->d_inode) {
49439+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49440+ error = -ENOENT;
49441+ }
49442 goto fail;
49443+ }
49444 /*
49445 * Special case - lookup gave negative, but... we had foo/bar/
49446 * From the vfs_mknod() POV we just have a negative dentry -
49447@@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49448 }
49449 EXPORT_SYMBOL(user_path_create);
49450
49451+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49452+{
49453+ struct filename *tmp = getname(pathname);
49454+ struct dentry *res;
49455+ if (IS_ERR(tmp))
49456+ return ERR_CAST(tmp);
49457+ res = kern_path_create(dfd, tmp->name, path, is_dir);
49458+ if (IS_ERR(res))
49459+ putname(tmp);
49460+ else
49461+ *to = tmp;
49462+ return res;
49463+}
49464+
49465 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49466 {
49467 int error = may_create(dir, dentry);
49468@@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49469
49470 if (!IS_POSIXACL(path.dentry->d_inode))
49471 mode &= ~current_umask();
49472+
49473+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49474+ error = -EPERM;
49475+ goto out;
49476+ }
49477+
49478+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49479+ error = -EACCES;
49480+ goto out;
49481+ }
49482+
49483 error = security_path_mknod(&path, dentry, mode, dev);
49484 if (error)
49485 goto out;
49486@@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49487 break;
49488 }
49489 out:
49490+ if (!error)
49491+ gr_handle_create(dentry, path.mnt);
49492 done_path_create(&path, dentry);
49493 return error;
49494 }
49495@@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49496
49497 if (!IS_POSIXACL(path.dentry->d_inode))
49498 mode &= ~current_umask();
49499+
49500+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49501+ error = -EACCES;
49502+ goto out;
49503+ }
49504+
49505 error = security_path_mkdir(&path, dentry, mode);
49506 if (!error)
49507 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49508+ if (!error)
49509+ gr_handle_create(dentry, path.mnt);
49510+out:
49511 done_path_create(&path, dentry);
49512 return error;
49513 }
49514@@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49515 struct filename *name;
49516 struct dentry *dentry;
49517 struct nameidata nd;
49518+ ino_t saved_ino = 0;
49519+ dev_t saved_dev = 0;
49520
49521 name = user_path_parent(dfd, pathname, &nd);
49522 if (IS_ERR(name))
49523@@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49524 error = -ENOENT;
49525 goto exit3;
49526 }
49527+
49528+ saved_ino = dentry->d_inode->i_ino;
49529+ saved_dev = gr_get_dev_from_dentry(dentry);
49530+
49531+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49532+ error = -EACCES;
49533+ goto exit3;
49534+ }
49535+
49536 error = security_path_rmdir(&nd.path, dentry);
49537 if (error)
49538 goto exit3;
49539 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49540+ if (!error && (saved_dev || saved_ino))
49541+ gr_handle_delete(saved_ino, saved_dev);
49542 exit3:
49543 dput(dentry);
49544 exit2:
49545@@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49546 struct dentry *dentry;
49547 struct nameidata nd;
49548 struct inode *inode = NULL;
49549+ ino_t saved_ino = 0;
49550+ dev_t saved_dev = 0;
49551
49552 name = user_path_parent(dfd, pathname, &nd);
49553 if (IS_ERR(name))
49554@@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49555 if (!inode)
49556 goto slashes;
49557 ihold(inode);
49558+
49559+ if (inode->i_nlink <= 1) {
49560+ saved_ino = inode->i_ino;
49561+ saved_dev = gr_get_dev_from_dentry(dentry);
49562+ }
49563+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49564+ error = -EACCES;
49565+ goto exit2;
49566+ }
49567+
49568 error = security_path_unlink(&nd.path, dentry);
49569 if (error)
49570 goto exit2;
49571 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49572+ if (!error && (saved_ino || saved_dev))
49573+ gr_handle_delete(saved_ino, saved_dev);
49574 exit2:
49575 dput(dentry);
49576 }
49577@@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49578 if (IS_ERR(dentry))
49579 goto out_putname;
49580
49581+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49582+ error = -EACCES;
49583+ goto out;
49584+ }
49585+
49586 error = security_path_symlink(&path, dentry, from->name);
49587 if (!error)
49588 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49589+ if (!error)
49590+ gr_handle_create(dentry, path.mnt);
49591+out:
49592 done_path_create(&path, dentry);
49593 out_putname:
49594 putname(from);
49595@@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49596 {
49597 struct dentry *new_dentry;
49598 struct path old_path, new_path;
49599+ struct filename *to = NULL;
49600 int how = 0;
49601 int error;
49602
49603@@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49604 if (error)
49605 return error;
49606
49607- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49608+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49609 error = PTR_ERR(new_dentry);
49610 if (IS_ERR(new_dentry))
49611 goto out;
49612@@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49613 error = may_linkat(&old_path);
49614 if (unlikely(error))
49615 goto out_dput;
49616+
49617+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49618+ old_path.dentry->d_inode,
49619+ old_path.dentry->d_inode->i_mode, to)) {
49620+ error = -EACCES;
49621+ goto out_dput;
49622+ }
49623+
49624+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49625+ old_path.dentry, old_path.mnt, to)) {
49626+ error = -EACCES;
49627+ goto out_dput;
49628+ }
49629+
49630 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49631 if (error)
49632 goto out_dput;
49633 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49634+ if (!error)
49635+ gr_handle_create(new_dentry, new_path.mnt);
49636 out_dput:
49637+ putname(to);
49638 done_path_create(&new_path, new_dentry);
49639 out:
49640 path_put(&old_path);
49641@@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49642 if (new_dentry == trap)
49643 goto exit5;
49644
49645+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49646+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
49647+ to);
49648+ if (error)
49649+ goto exit5;
49650+
49651 error = security_path_rename(&oldnd.path, old_dentry,
49652 &newnd.path, new_dentry);
49653 if (error)
49654 goto exit5;
49655 error = vfs_rename(old_dir->d_inode, old_dentry,
49656 new_dir->d_inode, new_dentry);
49657+ if (!error)
49658+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49659+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49660 exit5:
49661 dput(new_dentry);
49662 exit4:
49663@@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49664
49665 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49666 {
49667+ char tmpbuf[64];
49668+ const char *newlink;
49669 int len;
49670
49671 len = PTR_ERR(link);
49672@@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49673 len = strlen(link);
49674 if (len > (unsigned) buflen)
49675 len = buflen;
49676- if (copy_to_user(buffer, link, len))
49677+
49678+ if (len < sizeof(tmpbuf)) {
49679+ memcpy(tmpbuf, link, len);
49680+ newlink = tmpbuf;
49681+ } else
49682+ newlink = link;
49683+
49684+ if (copy_to_user(buffer, newlink, len))
49685 len = -EFAULT;
49686 out:
49687 return len;
49688diff --git a/fs/namespace.c b/fs/namespace.c
49689index 2496062..e26f6d6 100644
49690--- a/fs/namespace.c
49691+++ b/fs/namespace.c
49692@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49693 if (!(sb->s_flags & MS_RDONLY))
49694 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49695 up_write(&sb->s_umount);
49696+
49697+ gr_log_remount(mnt->mnt_devname, retval);
49698+
49699 return retval;
49700 }
49701
49702@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49703 br_write_unlock(&vfsmount_lock);
49704 up_write(&namespace_sem);
49705 release_mounts(&umount_list);
49706+
49707+ gr_log_unmount(mnt->mnt_devname, retval);
49708+
49709 return retval;
49710 }
49711
49712@@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49713 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49714 MS_STRICTATIME);
49715
49716+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49717+ retval = -EPERM;
49718+ goto dput_out;
49719+ }
49720+
49721+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49722+ retval = -EPERM;
49723+ goto dput_out;
49724+ }
49725+
49726 if (flags & MS_REMOUNT)
49727 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49728 data_page);
49729@@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49730 dev_name, data_page);
49731 dput_out:
49732 path_put(&path);
49733+
49734+ gr_log_mount(dev_name, dir_name, retval);
49735+
49736 return retval;
49737 }
49738
49739@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49740 if (error)
49741 goto out2;
49742
49743+ if (gr_handle_chroot_pivot()) {
49744+ error = -EPERM;
49745+ goto out2;
49746+ }
49747+
49748 get_fs_root(current->fs, &root);
49749 error = lock_mount(&old);
49750 if (error)
49751diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49752index 6fa01ae..2790820 100644
49753--- a/fs/nfs/inode.c
49754+++ b/fs/nfs/inode.c
49755@@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49756 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49757 }
49758
49759-static atomic_long_t nfs_attr_generation_counter;
49760+static atomic_long_unchecked_t nfs_attr_generation_counter;
49761
49762 static unsigned long nfs_read_attr_generation_counter(void)
49763 {
49764- return atomic_long_read(&nfs_attr_generation_counter);
49765+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49766 }
49767
49768 unsigned long nfs_inc_attr_generation_counter(void)
49769 {
49770- return atomic_long_inc_return(&nfs_attr_generation_counter);
49771+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49772 }
49773
49774 void nfs_fattr_init(struct nfs_fattr *fattr)
49775diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49776index f59169e..fd7d359 100644
49777--- a/fs/nfsd/vfs.c
49778+++ b/fs/nfsd/vfs.c
49779@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49780 } else {
49781 oldfs = get_fs();
49782 set_fs(KERNEL_DS);
49783- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49784+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49785 set_fs(oldfs);
49786 }
49787
49788@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49789
49790 /* Write the data. */
49791 oldfs = get_fs(); set_fs(KERNEL_DS);
49792- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
49793+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
49794 set_fs(oldfs);
49795 if (host_err < 0)
49796 goto out_nfserr;
49797@@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
49798 */
49799
49800 oldfs = get_fs(); set_fs(KERNEL_DS);
49801- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
49802+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
49803 set_fs(oldfs);
49804
49805 if (host_err < 0)
49806diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
49807index 6fcaeb8..9d16d04 100644
49808--- a/fs/notify/fanotify/fanotify_user.c
49809+++ b/fs/notify/fanotify/fanotify_user.c
49810@@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
49811
49812 fd = fanotify_event_metadata.fd;
49813 ret = -EFAULT;
49814- if (copy_to_user(buf, &fanotify_event_metadata,
49815- fanotify_event_metadata.event_len))
49816+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
49817+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
49818 goto out_close_fd;
49819
49820 ret = prepare_for_access_response(group, event, fd);
49821diff --git a/fs/notify/notification.c b/fs/notify/notification.c
49822index c887b13..0fdf472 100644
49823--- a/fs/notify/notification.c
49824+++ b/fs/notify/notification.c
49825@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
49826 * get set to 0 so it will never get 'freed'
49827 */
49828 static struct fsnotify_event *q_overflow_event;
49829-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49830+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49831
49832 /**
49833 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
49834@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49835 */
49836 u32 fsnotify_get_cookie(void)
49837 {
49838- return atomic_inc_return(&fsnotify_sync_cookie);
49839+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
49840 }
49841 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
49842
49843diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
49844index 99e3610..02c1068 100644
49845--- a/fs/ntfs/dir.c
49846+++ b/fs/ntfs/dir.c
49847@@ -1329,7 +1329,7 @@ find_next_index_buffer:
49848 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
49849 ~(s64)(ndir->itype.index.block_size - 1)));
49850 /* Bounds checks. */
49851- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49852+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49853 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
49854 "inode 0x%lx or driver bug.", vdir->i_ino);
49855 goto err_out;
49856diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
49857index 1ecf464..e1ff8bf 100644
49858--- a/fs/ntfs/file.c
49859+++ b/fs/ntfs/file.c
49860@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
49861 #endif /* NTFS_RW */
49862 };
49863
49864-const struct file_operations ntfs_empty_file_ops = {};
49865+const struct file_operations ntfs_empty_file_ops __read_only;
49866
49867-const struct inode_operations ntfs_empty_inode_ops = {};
49868+const struct inode_operations ntfs_empty_inode_ops __read_only;
49869diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
49870index a9f78c7..ed8a381 100644
49871--- a/fs/ocfs2/localalloc.c
49872+++ b/fs/ocfs2/localalloc.c
49873@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
49874 goto bail;
49875 }
49876
49877- atomic_inc(&osb->alloc_stats.moves);
49878+ atomic_inc_unchecked(&osb->alloc_stats.moves);
49879
49880 bail:
49881 if (handle)
49882diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
49883index d355e6e..578d905 100644
49884--- a/fs/ocfs2/ocfs2.h
49885+++ b/fs/ocfs2/ocfs2.h
49886@@ -235,11 +235,11 @@ enum ocfs2_vol_state
49887
49888 struct ocfs2_alloc_stats
49889 {
49890- atomic_t moves;
49891- atomic_t local_data;
49892- atomic_t bitmap_data;
49893- atomic_t bg_allocs;
49894- atomic_t bg_extends;
49895+ atomic_unchecked_t moves;
49896+ atomic_unchecked_t local_data;
49897+ atomic_unchecked_t bitmap_data;
49898+ atomic_unchecked_t bg_allocs;
49899+ atomic_unchecked_t bg_extends;
49900 };
49901
49902 enum ocfs2_local_alloc_state
49903diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
49904index f169da4..9112253 100644
49905--- a/fs/ocfs2/suballoc.c
49906+++ b/fs/ocfs2/suballoc.c
49907@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
49908 mlog_errno(status);
49909 goto bail;
49910 }
49911- atomic_inc(&osb->alloc_stats.bg_extends);
49912+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49913
49914 /* You should never ask for this much metadata */
49915 BUG_ON(bits_wanted >
49916@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
49917 mlog_errno(status);
49918 goto bail;
49919 }
49920- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49921+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49922
49923 *suballoc_loc = res.sr_bg_blkno;
49924 *suballoc_bit_start = res.sr_bit_offset;
49925@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
49926 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49927 res->sr_bits);
49928
49929- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49930+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49931
49932 BUG_ON(res->sr_bits != 1);
49933
49934@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
49935 mlog_errno(status);
49936 goto bail;
49937 }
49938- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49939+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49940
49941 BUG_ON(res.sr_bits != 1);
49942
49943@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49944 cluster_start,
49945 num_clusters);
49946 if (!status)
49947- atomic_inc(&osb->alloc_stats.local_data);
49948+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
49949 } else {
49950 if (min_clusters > (osb->bitmap_cpg - 1)) {
49951 /* The only paths asking for contiguousness
49952@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49953 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
49954 res.sr_bg_blkno,
49955 res.sr_bit_offset);
49956- atomic_inc(&osb->alloc_stats.bitmap_data);
49957+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
49958 *num_clusters = res.sr_bits;
49959 }
49960 }
49961diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
49962index 0e91ec2..f4b3fc6 100644
49963--- a/fs/ocfs2/super.c
49964+++ b/fs/ocfs2/super.c
49965@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
49966 "%10s => GlobalAllocs: %d LocalAllocs: %d "
49967 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
49968 "Stats",
49969- atomic_read(&osb->alloc_stats.bitmap_data),
49970- atomic_read(&osb->alloc_stats.local_data),
49971- atomic_read(&osb->alloc_stats.bg_allocs),
49972- atomic_read(&osb->alloc_stats.moves),
49973- atomic_read(&osb->alloc_stats.bg_extends));
49974+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
49975+ atomic_read_unchecked(&osb->alloc_stats.local_data),
49976+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
49977+ atomic_read_unchecked(&osb->alloc_stats.moves),
49978+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
49979
49980 out += snprintf(buf + out, len - out,
49981 "%10s => State: %u Descriptor: %llu Size: %u bits "
49982@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
49983 spin_lock_init(&osb->osb_xattr_lock);
49984 ocfs2_init_steal_slots(osb);
49985
49986- atomic_set(&osb->alloc_stats.moves, 0);
49987- atomic_set(&osb->alloc_stats.local_data, 0);
49988- atomic_set(&osb->alloc_stats.bitmap_data, 0);
49989- atomic_set(&osb->alloc_stats.bg_allocs, 0);
49990- atomic_set(&osb->alloc_stats.bg_extends, 0);
49991+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
49992+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
49993+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
49994+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
49995+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
49996
49997 /* Copy the blockcheck stats from the superblock probe */
49998 osb->osb_ecc_stats = *stats;
49999diff --git a/fs/open.c b/fs/open.c
50000index 59071f5..c6229a0 100644
50001--- a/fs/open.c
50002+++ b/fs/open.c
50003@@ -31,6 +31,8 @@
50004 #include <linux/ima.h>
50005 #include <linux/dnotify.h>
50006
50007+#define CREATE_TRACE_POINTS
50008+#include <trace/events/fs.h>
50009 #include "internal.h"
50010
50011 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50012@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50013 error = locks_verify_truncate(inode, NULL, length);
50014 if (!error)
50015 error = security_path_truncate(&path);
50016+
50017+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50018+ error = -EACCES;
50019+
50020 if (!error)
50021 error = do_truncate(path.dentry, length, 0, NULL);
50022
50023@@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50024 if (__mnt_is_readonly(path.mnt))
50025 res = -EROFS;
50026
50027+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50028+ res = -EACCES;
50029+
50030 out_path_release:
50031 path_put(&path);
50032 out:
50033@@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50034 if (error)
50035 goto dput_and_out;
50036
50037+ gr_log_chdir(path.dentry, path.mnt);
50038+
50039 set_fs_pwd(current->fs, &path);
50040
50041 dput_and_out:
50042@@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50043 goto out_putf;
50044
50045 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50046+
50047+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50048+ error = -EPERM;
50049+
50050+ if (!error)
50051+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50052+
50053 if (!error)
50054 set_fs_pwd(current->fs, &f.file->f_path);
50055 out_putf:
50056@@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50057 if (error)
50058 goto dput_and_out;
50059
50060+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50061+ goto dput_and_out;
50062+
50063 set_fs_root(current->fs, &path);
50064+
50065+ gr_handle_chroot_chdir(&path);
50066+
50067 error = 0;
50068 dput_and_out:
50069 path_put(&path);
50070@@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50071 if (error)
50072 return error;
50073 mutex_lock(&inode->i_mutex);
50074+
50075+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50076+ error = -EACCES;
50077+ goto out_unlock;
50078+ }
50079+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50080+ error = -EACCES;
50081+ goto out_unlock;
50082+ }
50083+
50084 error = security_path_chmod(path, mode);
50085 if (error)
50086 goto out_unlock;
50087@@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50088 uid = make_kuid(current_user_ns(), user);
50089 gid = make_kgid(current_user_ns(), group);
50090
50091+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
50092+ return -EACCES;
50093+
50094 newattrs.ia_valid = ATTR_CTIME;
50095 if (user != (uid_t) -1) {
50096 if (!uid_valid(uid))
50097@@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50098 } else {
50099 fsnotify_open(f);
50100 fd_install(fd, f);
50101+ trace_do_sys_open(tmp->name, flags, mode);
50102 }
50103 }
50104 putname(tmp);
50105diff --git a/fs/pipe.c b/fs/pipe.c
50106index bd3479d..fb92c4d 100644
50107--- a/fs/pipe.c
50108+++ b/fs/pipe.c
50109@@ -438,9 +438,9 @@ redo:
50110 }
50111 if (bufs) /* More to do? */
50112 continue;
50113- if (!pipe->writers)
50114+ if (!atomic_read(&pipe->writers))
50115 break;
50116- if (!pipe->waiting_writers) {
50117+ if (!atomic_read(&pipe->waiting_writers)) {
50118 /* syscall merging: Usually we must not sleep
50119 * if O_NONBLOCK is set, or if we got some data.
50120 * But if a writer sleeps in kernel space, then
50121@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50122 mutex_lock(&inode->i_mutex);
50123 pipe = inode->i_pipe;
50124
50125- if (!pipe->readers) {
50126+ if (!atomic_read(&pipe->readers)) {
50127 send_sig(SIGPIPE, current, 0);
50128 ret = -EPIPE;
50129 goto out;
50130@@ -553,7 +553,7 @@ redo1:
50131 for (;;) {
50132 int bufs;
50133
50134- if (!pipe->readers) {
50135+ if (!atomic_read(&pipe->readers)) {
50136 send_sig(SIGPIPE, current, 0);
50137 if (!ret)
50138 ret = -EPIPE;
50139@@ -644,9 +644,9 @@ redo2:
50140 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50141 do_wakeup = 0;
50142 }
50143- pipe->waiting_writers++;
50144+ atomic_inc(&pipe->waiting_writers);
50145 pipe_wait(pipe);
50146- pipe->waiting_writers--;
50147+ atomic_dec(&pipe->waiting_writers);
50148 }
50149 out:
50150 mutex_unlock(&inode->i_mutex);
50151@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50152 mask = 0;
50153 if (filp->f_mode & FMODE_READ) {
50154 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50155- if (!pipe->writers && filp->f_version != pipe->w_counter)
50156+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50157 mask |= POLLHUP;
50158 }
50159
50160@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50161 * Most Unices do not set POLLERR for FIFOs but on Linux they
50162 * behave exactly like pipes for poll().
50163 */
50164- if (!pipe->readers)
50165+ if (!atomic_read(&pipe->readers))
50166 mask |= POLLERR;
50167 }
50168
50169@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50170
50171 mutex_lock(&inode->i_mutex);
50172 pipe = inode->i_pipe;
50173- pipe->readers -= decr;
50174- pipe->writers -= decw;
50175+ atomic_sub(decr, &pipe->readers);
50176+ atomic_sub(decw, &pipe->writers);
50177
50178- if (!pipe->readers && !pipe->writers) {
50179+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50180 free_pipe_info(inode);
50181 } else {
50182 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50183@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50184
50185 if (inode->i_pipe) {
50186 ret = 0;
50187- inode->i_pipe->readers++;
50188+ atomic_inc(&inode->i_pipe->readers);
50189 }
50190
50191 mutex_unlock(&inode->i_mutex);
50192@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50193
50194 if (inode->i_pipe) {
50195 ret = 0;
50196- inode->i_pipe->writers++;
50197+ atomic_inc(&inode->i_pipe->writers);
50198 }
50199
50200 mutex_unlock(&inode->i_mutex);
50201@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50202 if (inode->i_pipe) {
50203 ret = 0;
50204 if (filp->f_mode & FMODE_READ)
50205- inode->i_pipe->readers++;
50206+ atomic_inc(&inode->i_pipe->readers);
50207 if (filp->f_mode & FMODE_WRITE)
50208- inode->i_pipe->writers++;
50209+ atomic_inc(&inode->i_pipe->writers);
50210 }
50211
50212 mutex_unlock(&inode->i_mutex);
50213@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50214 inode->i_pipe = NULL;
50215 }
50216
50217-static struct vfsmount *pipe_mnt __read_mostly;
50218+struct vfsmount *pipe_mnt __read_mostly;
50219
50220 /*
50221 * pipefs_dname() is called from d_path().
50222@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50223 goto fail_iput;
50224 inode->i_pipe = pipe;
50225
50226- pipe->readers = pipe->writers = 1;
50227+ atomic_set(&pipe->readers, 1);
50228+ atomic_set(&pipe->writers, 1);
50229 inode->i_fop = &rdwr_pipefifo_fops;
50230
50231 /*
50232diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50233index 15af622..0e9f4467 100644
50234--- a/fs/proc/Kconfig
50235+++ b/fs/proc/Kconfig
50236@@ -30,12 +30,12 @@ config PROC_FS
50237
50238 config PROC_KCORE
50239 bool "/proc/kcore support" if !ARM
50240- depends on PROC_FS && MMU
50241+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50242
50243 config PROC_VMCORE
50244 bool "/proc/vmcore support"
50245- depends on PROC_FS && CRASH_DUMP
50246- default y
50247+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50248+ default n
50249 help
50250 Exports the dump image of crashed kernel in ELF format.
50251
50252@@ -59,8 +59,8 @@ config PROC_SYSCTL
50253 limited in memory.
50254
50255 config PROC_PAGE_MONITOR
50256- default y
50257- depends on PROC_FS && MMU
50258+ default n
50259+ depends on PROC_FS && MMU && !GRKERNSEC
50260 bool "Enable /proc page monitoring" if EXPERT
50261 help
50262 Various /proc files exist to monitor process memory utilization:
50263diff --git a/fs/proc/array.c b/fs/proc/array.c
50264index bd31e02..15cae71 100644
50265--- a/fs/proc/array.c
50266+++ b/fs/proc/array.c
50267@@ -60,6 +60,7 @@
50268 #include <linux/tty.h>
50269 #include <linux/string.h>
50270 #include <linux/mman.h>
50271+#include <linux/grsecurity.h>
50272 #include <linux/proc_fs.h>
50273 #include <linux/ioport.h>
50274 #include <linux/uaccess.h>
50275@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50276 seq_putc(m, '\n');
50277 }
50278
50279+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50280+static inline void task_pax(struct seq_file *m, struct task_struct *p)
50281+{
50282+ if (p->mm)
50283+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50284+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50285+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50286+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50287+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50288+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50289+ else
50290+ seq_printf(m, "PaX:\t-----\n");
50291+}
50292+#endif
50293+
50294 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50295 struct pid *pid, struct task_struct *task)
50296 {
50297@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50298 task_cpus_allowed(m, task);
50299 cpuset_task_status_allowed(m, task);
50300 task_context_switch_counts(m, task);
50301+
50302+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50303+ task_pax(m, task);
50304+#endif
50305+
50306+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50307+ task_grsec_rbac(m, task);
50308+#endif
50309+
50310 return 0;
50311 }
50312
50313+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50314+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50315+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50316+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50317+#endif
50318+
50319 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50320 struct pid *pid, struct task_struct *task, int whole)
50321 {
50322@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50323 char tcomm[sizeof(task->comm)];
50324 unsigned long flags;
50325
50326+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50327+ if (current->exec_id != m->exec_id) {
50328+ gr_log_badprocpid("stat");
50329+ return 0;
50330+ }
50331+#endif
50332+
50333 state = *get_task_state(task);
50334 vsize = eip = esp = 0;
50335 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50336@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50337 gtime = task->gtime;
50338 }
50339
50340+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50341+ if (PAX_RAND_FLAGS(mm)) {
50342+ eip = 0;
50343+ esp = 0;
50344+ wchan = 0;
50345+ }
50346+#endif
50347+#ifdef CONFIG_GRKERNSEC_HIDESYM
50348+ wchan = 0;
50349+ eip =0;
50350+ esp =0;
50351+#endif
50352+
50353 /* scale priority and nice values from timeslices to -20..20 */
50354 /* to make it look like a "normal" Unix priority/nice value */
50355 priority = task_prio(task);
50356@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50357 seq_put_decimal_ull(m, ' ', vsize);
50358 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50359 seq_put_decimal_ull(m, ' ', rsslim);
50360+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50361+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50362+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50363+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50364+#else
50365 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50366 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50367 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50368+#endif
50369 seq_put_decimal_ull(m, ' ', esp);
50370 seq_put_decimal_ull(m, ' ', eip);
50371 /* The signal information here is obsolete.
50372@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50373 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50374 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50375
50376- if (mm && permitted) {
50377+ if (mm && permitted
50378+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50379+ && !PAX_RAND_FLAGS(mm)
50380+#endif
50381+ ) {
50382 seq_put_decimal_ull(m, ' ', mm->start_data);
50383 seq_put_decimal_ull(m, ' ', mm->end_data);
50384 seq_put_decimal_ull(m, ' ', mm->start_brk);
50385@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50386 struct pid *pid, struct task_struct *task)
50387 {
50388 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50389- struct mm_struct *mm = get_task_mm(task);
50390+ struct mm_struct *mm;
50391
50392+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50393+ if (current->exec_id != m->exec_id) {
50394+ gr_log_badprocpid("statm");
50395+ return 0;
50396+ }
50397+#endif
50398+ mm = get_task_mm(task);
50399 if (mm) {
50400 size = task_statm(mm, &shared, &text, &data, &resident);
50401 mmput(mm);
50402@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50403 return 0;
50404 }
50405
50406+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50407+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50408+{
50409+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50410+}
50411+#endif
50412+
50413 #ifdef CONFIG_CHECKPOINT_RESTORE
50414 static struct pid *
50415 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50416diff --git a/fs/proc/base.c b/fs/proc/base.c
50417index 9e28356..c485b3c 100644
50418--- a/fs/proc/base.c
50419+++ b/fs/proc/base.c
50420@@ -111,6 +111,14 @@ struct pid_entry {
50421 union proc_op op;
50422 };
50423
50424+struct getdents_callback {
50425+ struct linux_dirent __user * current_dir;
50426+ struct linux_dirent __user * previous;
50427+ struct file * file;
50428+ int count;
50429+ int error;
50430+};
50431+
50432 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50433 .name = (NAME), \
50434 .len = sizeof(NAME) - 1, \
50435@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50436 if (!mm->arg_end)
50437 goto out_mm; /* Shh! No looking before we're done */
50438
50439+ if (gr_acl_handle_procpidmem(task))
50440+ goto out_mm;
50441+
50442 len = mm->arg_end - mm->arg_start;
50443
50444 if (len > PAGE_SIZE)
50445@@ -235,12 +246,28 @@ out:
50446 return res;
50447 }
50448
50449+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50450+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50451+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50452+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50453+#endif
50454+
50455 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50456 {
50457 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50458 int res = PTR_ERR(mm);
50459 if (mm && !IS_ERR(mm)) {
50460 unsigned int nwords = 0;
50461+
50462+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50463+ /* allow if we're currently ptracing this task */
50464+ if (PAX_RAND_FLAGS(mm) &&
50465+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50466+ mmput(mm);
50467+ return 0;
50468+ }
50469+#endif
50470+
50471 do {
50472 nwords += 2;
50473 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50474@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50475 }
50476
50477
50478-#ifdef CONFIG_KALLSYMS
50479+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50480 /*
50481 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50482 * Returns the resolved symbol. If that fails, simply return the address.
50483@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50484 mutex_unlock(&task->signal->cred_guard_mutex);
50485 }
50486
50487-#ifdef CONFIG_STACKTRACE
50488+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50489
50490 #define MAX_STACK_TRACE_DEPTH 64
50491
50492@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50493 return count;
50494 }
50495
50496-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50497+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50498 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50499 {
50500 long nr;
50501@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50502 /************************************************************************/
50503
50504 /* permission checks */
50505-static int proc_fd_access_allowed(struct inode *inode)
50506+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50507 {
50508 struct task_struct *task;
50509 int allowed = 0;
50510@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50511 */
50512 task = get_proc_task(inode);
50513 if (task) {
50514- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50515+ if (log)
50516+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50517+ else
50518+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50519 put_task_struct(task);
50520 }
50521 return allowed;
50522@@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50523 struct task_struct *task,
50524 int hide_pid_min)
50525 {
50526+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50527+ return false;
50528+
50529+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50530+ rcu_read_lock();
50531+ {
50532+ const struct cred *tmpcred = current_cred();
50533+ const struct cred *cred = __task_cred(task);
50534+
50535+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50536+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50537+ || in_group_p(grsec_proc_gid)
50538+#endif
50539+ ) {
50540+ rcu_read_unlock();
50541+ return true;
50542+ }
50543+ }
50544+ rcu_read_unlock();
50545+
50546+ if (!pid->hide_pid)
50547+ return false;
50548+#endif
50549+
50550 if (pid->hide_pid < hide_pid_min)
50551 return true;
50552 if (in_group_p(pid->pid_gid))
50553 return true;
50554+
50555 return ptrace_may_access(task, PTRACE_MODE_READ);
50556 }
50557
50558@@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50559 put_task_struct(task);
50560
50561 if (!has_perms) {
50562+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50563+ {
50564+#else
50565 if (pid->hide_pid == 2) {
50566+#endif
50567 /*
50568 * Let's make getdents(), stat(), and open()
50569 * consistent with each other. If a process
50570@@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50571 if (!task)
50572 return -ESRCH;
50573
50574+ if (gr_acl_handle_procpidmem(task)) {
50575+ put_task_struct(task);
50576+ return -EPERM;
50577+ }
50578+
50579 mm = mm_access(task, mode);
50580 put_task_struct(task);
50581
50582@@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50583
50584 file->private_data = mm;
50585
50586+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50587+ file->f_version = current->exec_id;
50588+#endif
50589+
50590 return 0;
50591 }
50592
50593@@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50594 ssize_t copied;
50595 char *page;
50596
50597+#ifdef CONFIG_GRKERNSEC
50598+ if (write)
50599+ return -EPERM;
50600+#endif
50601+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50602+ if (file->f_version != current->exec_id) {
50603+ gr_log_badprocpid("mem");
50604+ return 0;
50605+ }
50606+#endif
50607+
50608 if (!mm)
50609 return 0;
50610
50611@@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50612 if (!mm)
50613 return 0;
50614
50615+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50616+ if (file->f_version != current->exec_id) {
50617+ gr_log_badprocpid("environ");
50618+ return 0;
50619+ }
50620+#endif
50621+
50622 page = (char *)__get_free_page(GFP_TEMPORARY);
50623 if (!page)
50624 return -ENOMEM;
50625@@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50626 int error = -EACCES;
50627
50628 /* Are we allowed to snoop on the tasks file descriptors? */
50629- if (!proc_fd_access_allowed(inode))
50630+ if (!proc_fd_access_allowed(inode, 0))
50631 goto out;
50632
50633 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50634@@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50635 struct path path;
50636
50637 /* Are we allowed to snoop on the tasks file descriptors? */
50638- if (!proc_fd_access_allowed(inode))
50639- goto out;
50640+ /* logging this is needed for learning on chromium to work properly,
50641+ but we don't want to flood the logs from 'ps' which does a readlink
50642+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50643+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
50644+ */
50645+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50646+ if (!proc_fd_access_allowed(inode,0))
50647+ goto out;
50648+ } else {
50649+ if (!proc_fd_access_allowed(inode,1))
50650+ goto out;
50651+ }
50652
50653 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50654 if (error)
50655@@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50656 rcu_read_lock();
50657 cred = __task_cred(task);
50658 inode->i_uid = cred->euid;
50659+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50660+ inode->i_gid = grsec_proc_gid;
50661+#else
50662 inode->i_gid = cred->egid;
50663+#endif
50664 rcu_read_unlock();
50665 }
50666 security_task_to_inode(task, inode);
50667@@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50668 return -ENOENT;
50669 }
50670 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50671+#ifdef CONFIG_GRKERNSEC_PROC_USER
50672+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50673+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50674+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50675+#endif
50676 task_dumpable(task)) {
50677 cred = __task_cred(task);
50678 stat->uid = cred->euid;
50679+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50680+ stat->gid = grsec_proc_gid;
50681+#else
50682 stat->gid = cred->egid;
50683+#endif
50684 }
50685 }
50686 rcu_read_unlock();
50687@@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50688
50689 if (task) {
50690 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50691+#ifdef CONFIG_GRKERNSEC_PROC_USER
50692+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50693+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50694+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50695+#endif
50696 task_dumpable(task)) {
50697 rcu_read_lock();
50698 cred = __task_cred(task);
50699 inode->i_uid = cred->euid;
50700+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50701+ inode->i_gid = grsec_proc_gid;
50702+#else
50703 inode->i_gid = cred->egid;
50704+#endif
50705 rcu_read_unlock();
50706 } else {
50707 inode->i_uid = GLOBAL_ROOT_UID;
50708@@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50709 if (!task)
50710 goto out_no_task;
50711
50712+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50713+ goto out;
50714+
50715 /*
50716 * Yes, it does not scale. And it should not. Don't add
50717 * new entries into /proc/<tgid>/ without very good reasons.
50718@@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50719 if (!task)
50720 goto out_no_task;
50721
50722+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50723+ goto out;
50724+
50725 ret = 0;
50726 i = filp->f_pos;
50727 switch (i) {
50728@@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50729 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50730 void *cookie)
50731 {
50732- char *s = nd_get_link(nd);
50733+ const char *s = nd_get_link(nd);
50734 if (!IS_ERR(s))
50735 kfree(s);
50736 }
50737@@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50738 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50739 #endif
50740 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50741-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50742+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50743 INF("syscall", S_IRUGO, proc_pid_syscall),
50744 #endif
50745 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50746@@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50747 #ifdef CONFIG_SECURITY
50748 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50749 #endif
50750-#ifdef CONFIG_KALLSYMS
50751+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50752 INF("wchan", S_IRUGO, proc_pid_wchan),
50753 #endif
50754-#ifdef CONFIG_STACKTRACE
50755+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50756 ONE("stack", S_IRUGO, proc_pid_stack),
50757 #endif
50758 #ifdef CONFIG_SCHEDSTATS
50759@@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50760 #ifdef CONFIG_HARDWALL
50761 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50762 #endif
50763+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50764+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50765+#endif
50766 #ifdef CONFIG_USER_NS
50767 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50768 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50769@@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50770 if (!inode)
50771 goto out;
50772
50773+#ifdef CONFIG_GRKERNSEC_PROC_USER
50774+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50775+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50776+ inode->i_gid = grsec_proc_gid;
50777+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50778+#else
50779 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50780+#endif
50781 inode->i_op = &proc_tgid_base_inode_operations;
50782 inode->i_fop = &proc_tgid_base_operations;
50783 inode->i_flags|=S_IMMUTABLE;
50784@@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50785 if (!task)
50786 goto out;
50787
50788+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50789+ goto out_put_task;
50790+
50791 result = proc_pid_instantiate(dir, dentry, task, NULL);
50792+out_put_task:
50793 put_task_struct(task);
50794 out:
50795 return result;
50796@@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
50797 static int fake_filldir(void *buf, const char *name, int namelen,
50798 loff_t offset, u64 ino, unsigned d_type)
50799 {
50800+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
50801+ __buf->error = -EINVAL;
50802 return 0;
50803 }
50804
50805@@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
50806 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50807 #endif
50808 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50809-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50810+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50811 INF("syscall", S_IRUGO, proc_pid_syscall),
50812 #endif
50813 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50814@@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
50815 #ifdef CONFIG_SECURITY
50816 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50817 #endif
50818-#ifdef CONFIG_KALLSYMS
50819+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50820 INF("wchan", S_IRUGO, proc_pid_wchan),
50821 #endif
50822-#ifdef CONFIG_STACKTRACE
50823+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50824 ONE("stack", S_IRUGO, proc_pid_stack),
50825 #endif
50826 #ifdef CONFIG_SCHEDSTATS
50827diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
50828index 82676e3..5f8518a 100644
50829--- a/fs/proc/cmdline.c
50830+++ b/fs/proc/cmdline.c
50831@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
50832
50833 static int __init proc_cmdline_init(void)
50834 {
50835+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50836+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50837+#else
50838 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50839+#endif
50840 return 0;
50841 }
50842 module_init(proc_cmdline_init);
50843diff --git a/fs/proc/devices.c b/fs/proc/devices.c
50844index b143471..bb105e5 100644
50845--- a/fs/proc/devices.c
50846+++ b/fs/proc/devices.c
50847@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
50848
50849 static int __init proc_devices_init(void)
50850 {
50851+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50852+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50853+#else
50854 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50855+#endif
50856 return 0;
50857 }
50858 module_init(proc_devices_init);
50859diff --git a/fs/proc/fd.c b/fs/proc/fd.c
50860index f28a875..c467953 100644
50861--- a/fs/proc/fd.c
50862+++ b/fs/proc/fd.c
50863@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
50864 if (!task)
50865 return -ENOENT;
50866
50867- files = get_files_struct(task);
50868+ if (!gr_acl_handle_procpidmem(task))
50869+ files = get_files_struct(task);
50870 put_task_struct(task);
50871
50872 if (files) {
50873@@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
50874 */
50875 int proc_fd_permission(struct inode *inode, int mask)
50876 {
50877+ struct task_struct *task;
50878 int rv = generic_permission(inode, mask);
50879- if (rv == 0)
50880- return 0;
50881+
50882 if (task_pid(current) == proc_pid(inode))
50883 rv = 0;
50884+
50885+ task = get_proc_task(inode);
50886+ if (task == NULL)
50887+ return rv;
50888+
50889+ if (gr_acl_handle_procpidmem(task))
50890+ rv = -EACCES;
50891+
50892+ put_task_struct(task);
50893+
50894 return rv;
50895 }
50896
50897diff --git a/fs/proc/inode.c b/fs/proc/inode.c
50898index 3b22bbd..895b58c 100644
50899--- a/fs/proc/inode.c
50900+++ b/fs/proc/inode.c
50901@@ -21,11 +21,17 @@
50902 #include <linux/seq_file.h>
50903 #include <linux/slab.h>
50904 #include <linux/mount.h>
50905+#include <linux/grsecurity.h>
50906
50907 #include <asm/uaccess.h>
50908
50909 #include "internal.h"
50910
50911+#ifdef CONFIG_PROC_SYSCTL
50912+extern const struct inode_operations proc_sys_inode_operations;
50913+extern const struct inode_operations proc_sys_dir_operations;
50914+#endif
50915+
50916 static void proc_evict_inode(struct inode *inode)
50917 {
50918 struct proc_dir_entry *de;
50919@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
50920 ns_ops = PROC_I(inode)->ns_ops;
50921 if (ns_ops && ns_ops->put)
50922 ns_ops->put(PROC_I(inode)->ns);
50923+
50924+#ifdef CONFIG_PROC_SYSCTL
50925+ if (inode->i_op == &proc_sys_inode_operations ||
50926+ inode->i_op == &proc_sys_dir_operations)
50927+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
50928+#endif
50929+
50930 }
50931
50932 static struct kmem_cache * proc_inode_cachep;
50933@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
50934 if (de->mode) {
50935 inode->i_mode = de->mode;
50936 inode->i_uid = de->uid;
50937+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50938+ inode->i_gid = grsec_proc_gid;
50939+#else
50940 inode->i_gid = de->gid;
50941+#endif
50942 }
50943 if (de->size)
50944 inode->i_size = de->size;
50945diff --git a/fs/proc/internal.h b/fs/proc/internal.h
50946index 43973b0..a20e704 100644
50947--- a/fs/proc/internal.h
50948+++ b/fs/proc/internal.h
50949@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50950 struct pid *pid, struct task_struct *task);
50951 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50952 struct pid *pid, struct task_struct *task);
50953+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50954+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
50955+#endif
50956 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
50957
50958 extern const struct file_operations proc_tid_children_operations;
50959diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
50960index 86c67ee..cdca321 100644
50961--- a/fs/proc/kcore.c
50962+++ b/fs/proc/kcore.c
50963@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50964 * the addresses in the elf_phdr on our list.
50965 */
50966 start = kc_offset_to_vaddr(*fpos - elf_buflen);
50967- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
50968+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
50969+ if (tsz > buflen)
50970 tsz = buflen;
50971-
50972+
50973 while (buflen) {
50974 struct kcore_list *m;
50975
50976@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
50977 kfree(elf_buf);
50978 } else {
50979 if (kern_addr_valid(start)) {
50980- unsigned long n;
50981+ char *elf_buf;
50982+ mm_segment_t oldfs;
50983
50984- n = copy_to_user(buffer, (char *)start, tsz);
50985- /*
50986- * We cannot distinguish between fault on source
50987- * and fault on destination. When this happens
50988- * we clear too and hope it will trigger the
50989- * EFAULT again.
50990- */
50991- if (n) {
50992- if (clear_user(buffer + tsz - n,
50993- n))
50994+ elf_buf = kmalloc(tsz, GFP_KERNEL);
50995+ if (!elf_buf)
50996+ return -ENOMEM;
50997+ oldfs = get_fs();
50998+ set_fs(KERNEL_DS);
50999+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51000+ set_fs(oldfs);
51001+ if (copy_to_user(buffer, elf_buf, tsz)) {
51002+ kfree(elf_buf);
51003 return -EFAULT;
51004+ }
51005 }
51006+ set_fs(oldfs);
51007+ kfree(elf_buf);
51008 } else {
51009 if (clear_user(buffer, tsz))
51010 return -EFAULT;
51011@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51012
51013 static int open_kcore(struct inode *inode, struct file *filp)
51014 {
51015+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51016+ return -EPERM;
51017+#endif
51018 if (!capable(CAP_SYS_RAWIO))
51019 return -EPERM;
51020 if (kcore_need_update)
51021diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51022index 80e4645..53e5fcf 100644
51023--- a/fs/proc/meminfo.c
51024+++ b/fs/proc/meminfo.c
51025@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51026 vmi.used >> 10,
51027 vmi.largest_chunk >> 10
51028 #ifdef CONFIG_MEMORY_FAILURE
51029- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51030+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51031 #endif
51032 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51033 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51034diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51035index b1822dd..df622cb 100644
51036--- a/fs/proc/nommu.c
51037+++ b/fs/proc/nommu.c
51038@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51039 if (len < 1)
51040 len = 1;
51041 seq_printf(m, "%*c", len, ' ');
51042- seq_path(m, &file->f_path, "");
51043+ seq_path(m, &file->f_path, "\n\\");
51044 }
51045
51046 seq_putc(m, '\n');
51047diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51048index fe72cd0..cb9b67d 100644
51049--- a/fs/proc/proc_net.c
51050+++ b/fs/proc/proc_net.c
51051@@ -23,6 +23,7 @@
51052 #include <linux/nsproxy.h>
51053 #include <net/net_namespace.h>
51054 #include <linux/seq_file.h>
51055+#include <linux/grsecurity.h>
51056
51057 #include "internal.h"
51058
51059@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51060 struct task_struct *task;
51061 struct nsproxy *ns;
51062 struct net *net = NULL;
51063+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51064+ const struct cred *cred = current_cred();
51065+#endif
51066+
51067+#ifdef CONFIG_GRKERNSEC_PROC_USER
51068+ if (cred->fsuid)
51069+ return net;
51070+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51071+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
51072+ return net;
51073+#endif
51074
51075 rcu_read_lock();
51076 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51077diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51078index a781bdf..6665284 100644
51079--- a/fs/proc/proc_sysctl.c
51080+++ b/fs/proc/proc_sysctl.c
51081@@ -12,11 +12,15 @@
51082 #include <linux/module.h>
51083 #include "internal.h"
51084
51085+extern int gr_handle_chroot_sysctl(const int op);
51086+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51087+ const int op);
51088+
51089 static const struct dentry_operations proc_sys_dentry_operations;
51090 static const struct file_operations proc_sys_file_operations;
51091-static const struct inode_operations proc_sys_inode_operations;
51092+const struct inode_operations proc_sys_inode_operations;
51093 static const struct file_operations proc_sys_dir_file_operations;
51094-static const struct inode_operations proc_sys_dir_operations;
51095+const struct inode_operations proc_sys_dir_operations;
51096
51097 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51098 {
51099@@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51100
51101 err = NULL;
51102 d_set_d_op(dentry, &proc_sys_dentry_operations);
51103+
51104+ gr_handle_proc_create(dentry, inode);
51105+
51106 d_add(dentry, inode);
51107
51108 out:
51109@@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51110 struct inode *inode = filp->f_path.dentry->d_inode;
51111 struct ctl_table_header *head = grab_header(inode);
51112 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51113+ int op = write ? MAY_WRITE : MAY_READ;
51114 ssize_t error;
51115 size_t res;
51116
51117 if (IS_ERR(head))
51118 return PTR_ERR(head);
51119
51120+
51121 /*
51122 * At this point we know that the sysctl was not unregistered
51123 * and won't be until we finish.
51124 */
51125 error = -EPERM;
51126- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51127+ if (sysctl_perm(head->root, table, op))
51128 goto out;
51129
51130 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51131@@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51132 if (!table->proc_handler)
51133 goto out;
51134
51135+#ifdef CONFIG_GRKERNSEC
51136+ error = -EPERM;
51137+ if (gr_handle_chroot_sysctl(op))
51138+ goto out;
51139+ dget(filp->f_path.dentry);
51140+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51141+ dput(filp->f_path.dentry);
51142+ goto out;
51143+ }
51144+ dput(filp->f_path.dentry);
51145+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51146+ goto out;
51147+ if (write && !capable(CAP_SYS_ADMIN))
51148+ goto out;
51149+#endif
51150+
51151 /* careful: calling conventions are nasty here */
51152 res = count;
51153 error = table->proc_handler(table, write, buf, &res, ppos);
51154@@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51155 return -ENOMEM;
51156 } else {
51157 d_set_d_op(child, &proc_sys_dentry_operations);
51158+
51159+ gr_handle_proc_create(child, inode);
51160+
51161 d_add(child, inode);
51162 }
51163 } else {
51164@@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51165 if ((*pos)++ < file->f_pos)
51166 return 0;
51167
51168+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51169+ return 0;
51170+
51171 if (unlikely(S_ISLNK(table->mode)))
51172 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51173 else
51174@@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51175 if (IS_ERR(head))
51176 return PTR_ERR(head);
51177
51178+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51179+ return -ENOENT;
51180+
51181 generic_fillattr(inode, stat);
51182 if (table)
51183 stat->mode = (stat->mode & S_IFMT) | table->mode;
51184@@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51185 .llseek = generic_file_llseek,
51186 };
51187
51188-static const struct inode_operations proc_sys_inode_operations = {
51189+const struct inode_operations proc_sys_inode_operations = {
51190 .permission = proc_sys_permission,
51191 .setattr = proc_sys_setattr,
51192 .getattr = proc_sys_getattr,
51193 };
51194
51195-static const struct inode_operations proc_sys_dir_operations = {
51196+const struct inode_operations proc_sys_dir_operations = {
51197 .lookup = proc_sys_lookup,
51198 .permission = proc_sys_permission,
51199 .setattr = proc_sys_setattr,
51200diff --git a/fs/proc/root.c b/fs/proc/root.c
51201index 9889a92..2613b48 100644
51202--- a/fs/proc/root.c
51203+++ b/fs/proc/root.c
51204@@ -187,7 +187,15 @@ void __init proc_root_init(void)
51205 #ifdef CONFIG_PROC_DEVICETREE
51206 proc_device_tree_init();
51207 #endif
51208+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51209+#ifdef CONFIG_GRKERNSEC_PROC_USER
51210+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51211+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51212+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51213+#endif
51214+#else
51215 proc_mkdir("bus", NULL);
51216+#endif
51217 proc_sys_init();
51218 }
51219
51220diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51221index 90c63f9..e662cfc 100644
51222--- a/fs/proc/task_mmu.c
51223+++ b/fs/proc/task_mmu.c
51224@@ -11,12 +11,19 @@
51225 #include <linux/rmap.h>
51226 #include <linux/swap.h>
51227 #include <linux/swapops.h>
51228+#include <linux/grsecurity.h>
51229
51230 #include <asm/elf.h>
51231 #include <asm/uaccess.h>
51232 #include <asm/tlbflush.h>
51233 #include "internal.h"
51234
51235+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51236+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51237+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51238+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51239+#endif
51240+
51241 void task_mem(struct seq_file *m, struct mm_struct *mm)
51242 {
51243 unsigned long data, text, lib, swap;
51244@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51245 "VmExe:\t%8lu kB\n"
51246 "VmLib:\t%8lu kB\n"
51247 "VmPTE:\t%8lu kB\n"
51248- "VmSwap:\t%8lu kB\n",
51249- hiwater_vm << (PAGE_SHIFT-10),
51250+ "VmSwap:\t%8lu kB\n"
51251+
51252+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51253+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51254+#endif
51255+
51256+ ,hiwater_vm << (PAGE_SHIFT-10),
51257 total_vm << (PAGE_SHIFT-10),
51258 mm->locked_vm << (PAGE_SHIFT-10),
51259 mm->pinned_vm << (PAGE_SHIFT-10),
51260@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51261 data << (PAGE_SHIFT-10),
51262 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51263 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51264- swap << (PAGE_SHIFT-10));
51265+ swap << (PAGE_SHIFT-10)
51266+
51267+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51268+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51269+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51270+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51271+#else
51272+ , mm->context.user_cs_base
51273+ , mm->context.user_cs_limit
51274+#endif
51275+#endif
51276+
51277+ );
51278 }
51279
51280 unsigned long task_vsize(struct mm_struct *mm)
51281@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51282 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51283 }
51284
51285- /* We don't show the stack guard page in /proc/maps */
51286+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51287+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51288+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51289+#else
51290 start = vma->vm_start;
51291- if (stack_guard_page_start(vma, start))
51292- start += PAGE_SIZE;
51293 end = vma->vm_end;
51294- if (stack_guard_page_end(vma, end))
51295- end -= PAGE_SIZE;
51296+#endif
51297
51298 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51299 start,
51300@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51301 flags & VM_WRITE ? 'w' : '-',
51302 flags & VM_EXEC ? 'x' : '-',
51303 flags & VM_MAYSHARE ? 's' : 'p',
51304+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51305+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51306+#else
51307 pgoff,
51308+#endif
51309 MAJOR(dev), MINOR(dev), ino, &len);
51310
51311 /*
51312@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51313 */
51314 if (file) {
51315 pad_len_spaces(m, len);
51316- seq_path(m, &file->f_path, "\n");
51317+ seq_path(m, &file->f_path, "\n\\");
51318 goto done;
51319 }
51320
51321@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51322 * Thread stack in /proc/PID/task/TID/maps or
51323 * the main process stack.
51324 */
51325- if (!is_pid || (vma->vm_start <= mm->start_stack &&
51326- vma->vm_end >= mm->start_stack)) {
51327+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51328+ (vma->vm_start <= mm->start_stack &&
51329+ vma->vm_end >= mm->start_stack)) {
51330 name = "[stack]";
51331 } else {
51332 /* Thread stack in /proc/PID/maps */
51333@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51334 struct proc_maps_private *priv = m->private;
51335 struct task_struct *task = priv->task;
51336
51337+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51338+ if (current->exec_id != m->exec_id) {
51339+ gr_log_badprocpid("maps");
51340+ return 0;
51341+ }
51342+#endif
51343+
51344 show_map_vma(m, vma, is_pid);
51345
51346 if (m->count < m->size) /* vma is copied successfully */
51347@@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51348 .private = &mss,
51349 };
51350
51351+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51352+ if (current->exec_id != m->exec_id) {
51353+ gr_log_badprocpid("smaps");
51354+ return 0;
51355+ }
51356+#endif
51357 memset(&mss, 0, sizeof mss);
51358- mss.vma = vma;
51359- /* mmap_sem is held in m_start */
51360- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51361- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51362-
51363+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51364+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51365+#endif
51366+ mss.vma = vma;
51367+ /* mmap_sem is held in m_start */
51368+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51369+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51370+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51371+ }
51372+#endif
51373 show_map_vma(m, vma, is_pid);
51374
51375 seq_printf(m,
51376@@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51377 "KernelPageSize: %8lu kB\n"
51378 "MMUPageSize: %8lu kB\n"
51379 "Locked: %8lu kB\n",
51380+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51381+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51382+#else
51383 (vma->vm_end - vma->vm_start) >> 10,
51384+#endif
51385 mss.resident >> 10,
51386 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51387 mss.shared_clean >> 10,
51388@@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51389 int n;
51390 char buffer[50];
51391
51392+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51393+ if (current->exec_id != m->exec_id) {
51394+ gr_log_badprocpid("numa_maps");
51395+ return 0;
51396+ }
51397+#endif
51398+
51399 if (!mm)
51400 return 0;
51401
51402@@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51403 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51404 mpol_cond_put(pol);
51405
51406+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51407+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51408+#else
51409 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51410+#endif
51411
51412 if (file) {
51413 seq_printf(m, " file=");
51414- seq_path(m, &file->f_path, "\n\t= ");
51415+ seq_path(m, &file->f_path, "\n\t\\= ");
51416 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51417 seq_printf(m, " heap");
51418 } else {
51419diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51420index 1ccfa53..0848f95 100644
51421--- a/fs/proc/task_nommu.c
51422+++ b/fs/proc/task_nommu.c
51423@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51424 else
51425 bytes += kobjsize(mm);
51426
51427- if (current->fs && current->fs->users > 1)
51428+ if (current->fs && atomic_read(&current->fs->users) > 1)
51429 sbytes += kobjsize(current->fs);
51430 else
51431 bytes += kobjsize(current->fs);
51432@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51433
51434 if (file) {
51435 pad_len_spaces(m, len);
51436- seq_path(m, &file->f_path, "");
51437+ seq_path(m, &file->f_path, "\n\\");
51438 } else if (mm) {
51439 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51440
51441diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51442index 2d57e1a..43b1280 100644
51443--- a/fs/pstore/ftrace.c
51444+++ b/fs/pstore/ftrace.c
51445@@ -28,7 +28,9 @@
51446 #include "internal.h"
51447
51448 static void notrace pstore_ftrace_call(unsigned long ip,
51449- unsigned long parent_ip)
51450+ unsigned long parent_ip,
51451+ struct ftrace_ops *op,
51452+ struct pt_regs *regs)
51453 {
51454 unsigned long flags;
51455 struct pstore_ftrace_record rec = {};
51456diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51457index 16e8abb..2dcf914 100644
51458--- a/fs/quota/netlink.c
51459+++ b/fs/quota/netlink.c
51460@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51461 void quota_send_warning(struct kqid qid, dev_t dev,
51462 const char warntype)
51463 {
51464- static atomic_t seq;
51465+ static atomic_unchecked_t seq;
51466 struct sk_buff *skb;
51467 void *msg_head;
51468 int ret;
51469@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51470 "VFS: Not enough memory to send quota warning.\n");
51471 return;
51472 }
51473- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51474+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51475 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51476 if (!msg_head) {
51477 printk(KERN_ERR
51478diff --git a/fs/read_write.c b/fs/read_write.c
51479index d065348..8e2b43d 100644
51480--- a/fs/read_write.c
51481+++ b/fs/read_write.c
51482@@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51483 if (retval > 0) {
51484 add_rchar(current, retval);
51485 add_wchar(current, retval);
51486+ fsnotify_access(in.file);
51487+ fsnotify_modify(out.file);
51488 }
51489
51490 inc_syscr(current);
51491diff --git a/fs/readdir.c b/fs/readdir.c
51492index 5e69ef5..e5d9099 100644
51493--- a/fs/readdir.c
51494+++ b/fs/readdir.c
51495@@ -17,6 +17,7 @@
51496 #include <linux/security.h>
51497 #include <linux/syscalls.h>
51498 #include <linux/unistd.h>
51499+#include <linux/namei.h>
51500
51501 #include <asm/uaccess.h>
51502
51503@@ -67,6 +68,7 @@ struct old_linux_dirent {
51504
51505 struct readdir_callback {
51506 struct old_linux_dirent __user * dirent;
51507+ struct file * file;
51508 int result;
51509 };
51510
51511@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51512 buf->result = -EOVERFLOW;
51513 return -EOVERFLOW;
51514 }
51515+
51516+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51517+ return 0;
51518+
51519 buf->result++;
51520 dirent = buf->dirent;
51521 if (!access_ok(VERIFY_WRITE, dirent,
51522@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51523
51524 buf.result = 0;
51525 buf.dirent = dirent;
51526+ buf.file = f.file;
51527
51528 error = vfs_readdir(f.file, fillonedir, &buf);
51529 if (buf.result)
51530@@ -139,6 +146,7 @@ struct linux_dirent {
51531 struct getdents_callback {
51532 struct linux_dirent __user * current_dir;
51533 struct linux_dirent __user * previous;
51534+ struct file * file;
51535 int count;
51536 int error;
51537 };
51538@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51539 buf->error = -EOVERFLOW;
51540 return -EOVERFLOW;
51541 }
51542+
51543+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51544+ return 0;
51545+
51546 dirent = buf->previous;
51547 if (dirent) {
51548 if (__put_user(offset, &dirent->d_off))
51549@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51550 buf.previous = NULL;
51551 buf.count = count;
51552 buf.error = 0;
51553+ buf.file = f.file;
51554
51555 error = vfs_readdir(f.file, filldir, &buf);
51556 if (error >= 0)
51557@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51558 struct getdents_callback64 {
51559 struct linux_dirent64 __user * current_dir;
51560 struct linux_dirent64 __user * previous;
51561+ struct file *file;
51562 int count;
51563 int error;
51564 };
51565@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51566 buf->error = -EINVAL; /* only used if we fail.. */
51567 if (reclen > buf->count)
51568 return -EINVAL;
51569+
51570+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51571+ return 0;
51572+
51573 dirent = buf->previous;
51574 if (dirent) {
51575 if (__put_user(offset, &dirent->d_off))
51576@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51577
51578 buf.current_dir = dirent;
51579 buf.previous = NULL;
51580+ buf.file = f.file;
51581 buf.count = count;
51582 buf.error = 0;
51583
51584@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51585 error = buf.error;
51586 lastdirent = buf.previous;
51587 if (lastdirent) {
51588- typeof(lastdirent->d_off) d_off = f.file->f_pos;
51589+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51590 if (__put_user(d_off, &lastdirent->d_off))
51591 error = -EFAULT;
51592 else
51593diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51594index 2b7882b..1c5ef48 100644
51595--- a/fs/reiserfs/do_balan.c
51596+++ b/fs/reiserfs/do_balan.c
51597@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51598 return;
51599 }
51600
51601- atomic_inc(&(fs_generation(tb->tb_sb)));
51602+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51603 do_balance_starts(tb);
51604
51605 /* balance leaf returns 0 except if combining L R and S into
51606diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51607index e60e870..f40ac16 100644
51608--- a/fs/reiserfs/procfs.c
51609+++ b/fs/reiserfs/procfs.c
51610@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51611 "SMALL_TAILS " : "NO_TAILS ",
51612 replay_only(sb) ? "REPLAY_ONLY " : "",
51613 convert_reiserfs(sb) ? "CONV " : "",
51614- atomic_read(&r->s_generation_counter),
51615+ atomic_read_unchecked(&r->s_generation_counter),
51616 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51617 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51618 SF(s_good_search_by_key_reada), SF(s_bmaps),
51619diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51620index 33215f5..c5d427a 100644
51621--- a/fs/reiserfs/reiserfs.h
51622+++ b/fs/reiserfs/reiserfs.h
51623@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51624 /* Comment? -Hans */
51625 wait_queue_head_t s_wait;
51626 /* To be obsoleted soon by per buffer seals.. -Hans */
51627- atomic_t s_generation_counter; // increased by one every time the
51628+ atomic_unchecked_t s_generation_counter; // increased by one every time the
51629 // tree gets re-balanced
51630 unsigned long s_properties; /* File system properties. Currently holds
51631 on-disk FS format */
51632@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51633 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51634
51635 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51636-#define get_generation(s) atomic_read (&fs_generation(s))
51637+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51638 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51639 #define __fs_changed(gen,s) (gen != get_generation (s))
51640 #define fs_changed(gen,s) \
51641diff --git a/fs/select.c b/fs/select.c
51642index 2ef72d9..f213b17 100644
51643--- a/fs/select.c
51644+++ b/fs/select.c
51645@@ -20,6 +20,7 @@
51646 #include <linux/export.h>
51647 #include <linux/slab.h>
51648 #include <linux/poll.h>
51649+#include <linux/security.h>
51650 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51651 #include <linux/file.h>
51652 #include <linux/fdtable.h>
51653@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51654 struct poll_list *walk = head;
51655 unsigned long todo = nfds;
51656
51657+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51658 if (nfds > rlimit(RLIMIT_NOFILE))
51659 return -EINVAL;
51660
51661diff --git a/fs/seq_file.c b/fs/seq_file.c
51662index 99dffab..e4fcb71 100644
51663--- a/fs/seq_file.c
51664+++ b/fs/seq_file.c
51665@@ -10,6 +10,7 @@
51666 #include <linux/seq_file.h>
51667 #include <linux/slab.h>
51668 #include <linux/cred.h>
51669+#include <linux/sched.h>
51670
51671 #include <asm/uaccess.h>
51672 #include <asm/page.h>
51673@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51674 #ifdef CONFIG_USER_NS
51675 p->user_ns = file->f_cred->user_ns;
51676 #endif
51677+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51678+ p->exec_id = current->exec_id;
51679+#endif
51680
51681 /*
51682 * Wrappers around seq_open(e.g. swaps_open) need to be
51683@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51684 return 0;
51685 }
51686 if (!m->buf) {
51687- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51688+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51689 if (!m->buf)
51690 return -ENOMEM;
51691 }
51692@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51693 Eoverflow:
51694 m->op->stop(m, p);
51695 kfree(m->buf);
51696- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51697+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51698 return !m->buf ? -ENOMEM : -EAGAIN;
51699 }
51700
51701@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51702
51703 /* grab buffer if we didn't have one */
51704 if (!m->buf) {
51705- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51706+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51707 if (!m->buf)
51708 goto Enomem;
51709 }
51710@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51711 goto Fill;
51712 m->op->stop(m, p);
51713 kfree(m->buf);
51714- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51715+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51716 if (!m->buf)
51717 goto Enomem;
51718 m->count = 0;
51719@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51720 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51721 void *data)
51722 {
51723- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51724+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
51725 int res = -ENOMEM;
51726
51727 if (op) {
51728diff --git a/fs/splice.c b/fs/splice.c
51729index 48c7bd1..d0740e4 100644
51730--- a/fs/splice.c
51731+++ b/fs/splice.c
51732@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51733 pipe_lock(pipe);
51734
51735 for (;;) {
51736- if (!pipe->readers) {
51737+ if (!atomic_read(&pipe->readers)) {
51738 send_sig(SIGPIPE, current, 0);
51739 if (!ret)
51740 ret = -EPIPE;
51741@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51742 do_wakeup = 0;
51743 }
51744
51745- pipe->waiting_writers++;
51746+ atomic_inc(&pipe->waiting_writers);
51747 pipe_wait(pipe);
51748- pipe->waiting_writers--;
51749+ atomic_dec(&pipe->waiting_writers);
51750 }
51751
51752 pipe_unlock(pipe);
51753@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51754 old_fs = get_fs();
51755 set_fs(get_ds());
51756 /* The cast to a user pointer is valid due to the set_fs() */
51757- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51758+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51759 set_fs(old_fs);
51760
51761 return res;
51762@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51763 old_fs = get_fs();
51764 set_fs(get_ds());
51765 /* The cast to a user pointer is valid due to the set_fs() */
51766- res = vfs_write(file, (const char __user *)buf, count, &pos);
51767+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51768 set_fs(old_fs);
51769
51770 return res;
51771@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51772 goto err;
51773
51774 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51775- vec[i].iov_base = (void __user *) page_address(page);
51776+ vec[i].iov_base = (void __force_user *) page_address(page);
51777 vec[i].iov_len = this_len;
51778 spd.pages[i] = page;
51779 spd.nr_pages++;
51780@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51781 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51782 {
51783 while (!pipe->nrbufs) {
51784- if (!pipe->writers)
51785+ if (!atomic_read(&pipe->writers))
51786 return 0;
51787
51788- if (!pipe->waiting_writers && sd->num_spliced)
51789+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
51790 return 0;
51791
51792 if (sd->flags & SPLICE_F_NONBLOCK)
51793@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
51794 * out of the pipe right after the splice_to_pipe(). So set
51795 * PIPE_READERS appropriately.
51796 */
51797- pipe->readers = 1;
51798+ atomic_set(&pipe->readers, 1);
51799
51800 current->splice_pipe = pipe;
51801 }
51802@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51803 ret = -ERESTARTSYS;
51804 break;
51805 }
51806- if (!pipe->writers)
51807+ if (!atomic_read(&pipe->writers))
51808 break;
51809- if (!pipe->waiting_writers) {
51810+ if (!atomic_read(&pipe->waiting_writers)) {
51811 if (flags & SPLICE_F_NONBLOCK) {
51812 ret = -EAGAIN;
51813 break;
51814@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51815 pipe_lock(pipe);
51816
51817 while (pipe->nrbufs >= pipe->buffers) {
51818- if (!pipe->readers) {
51819+ if (!atomic_read(&pipe->readers)) {
51820 send_sig(SIGPIPE, current, 0);
51821 ret = -EPIPE;
51822 break;
51823@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51824 ret = -ERESTARTSYS;
51825 break;
51826 }
51827- pipe->waiting_writers++;
51828+ atomic_inc(&pipe->waiting_writers);
51829 pipe_wait(pipe);
51830- pipe->waiting_writers--;
51831+ atomic_dec(&pipe->waiting_writers);
51832 }
51833
51834 pipe_unlock(pipe);
51835@@ -1826,14 +1826,14 @@ retry:
51836 pipe_double_lock(ipipe, opipe);
51837
51838 do {
51839- if (!opipe->readers) {
51840+ if (!atomic_read(&opipe->readers)) {
51841 send_sig(SIGPIPE, current, 0);
51842 if (!ret)
51843 ret = -EPIPE;
51844 break;
51845 }
51846
51847- if (!ipipe->nrbufs && !ipipe->writers)
51848+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51849 break;
51850
51851 /*
51852@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51853 pipe_double_lock(ipipe, opipe);
51854
51855 do {
51856- if (!opipe->readers) {
51857+ if (!atomic_read(&opipe->readers)) {
51858 send_sig(SIGPIPE, current, 0);
51859 if (!ret)
51860 ret = -EPIPE;
51861@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51862 * return EAGAIN if we have the potential of some data in the
51863 * future, otherwise just return 0
51864 */
51865- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51866+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51867 ret = -EAGAIN;
51868
51869 pipe_unlock(ipipe);
51870diff --git a/fs/stat.c b/fs/stat.c
51871index eae4946..6198f55 100644
51872--- a/fs/stat.c
51873+++ b/fs/stat.c
51874@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
51875 stat->gid = inode->i_gid;
51876 stat->rdev = inode->i_rdev;
51877 stat->size = i_size_read(inode);
51878- stat->atime = inode->i_atime;
51879- stat->mtime = inode->i_mtime;
51880+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51881+ stat->atime = inode->i_ctime;
51882+ stat->mtime = inode->i_ctime;
51883+ } else {
51884+ stat->atime = inode->i_atime;
51885+ stat->mtime = inode->i_mtime;
51886+ }
51887 stat->ctime = inode->i_ctime;
51888 stat->blksize = (1 << inode->i_blkbits);
51889 stat->blocks = inode->i_blocks;
51890@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51891 if (retval)
51892 return retval;
51893
51894- if (inode->i_op->getattr)
51895- return inode->i_op->getattr(mnt, dentry, stat);
51896+ if (inode->i_op->getattr) {
51897+ retval = inode->i_op->getattr(mnt, dentry, stat);
51898+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51899+ stat->atime = stat->ctime;
51900+ stat->mtime = stat->ctime;
51901+ }
51902+ return retval;
51903+ }
51904
51905 generic_fillattr(inode, stat);
51906 return 0;
51907diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
51908index 2fbdff6..5530a61 100644
51909--- a/fs/sysfs/dir.c
51910+++ b/fs/sysfs/dir.c
51911@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
51912 struct sysfs_dirent *sd;
51913 int rc;
51914
51915+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51916+ const char *parent_name = parent_sd->s_name;
51917+
51918+ mode = S_IFDIR | S_IRWXU;
51919+
51920+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
51921+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
51922+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
51923+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
51924+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
51925+#endif
51926+
51927 /* allocate */
51928 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
51929 if (!sd)
51930diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
51931index 00012e3..8392349 100644
51932--- a/fs/sysfs/file.c
51933+++ b/fs/sysfs/file.c
51934@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
51935
51936 struct sysfs_open_dirent {
51937 atomic_t refcnt;
51938- atomic_t event;
51939+ atomic_unchecked_t event;
51940 wait_queue_head_t poll;
51941 struct list_head buffers; /* goes through sysfs_buffer.list */
51942 };
51943@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
51944 if (!sysfs_get_active(attr_sd))
51945 return -ENODEV;
51946
51947- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
51948+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
51949 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
51950
51951 sysfs_put_active(attr_sd);
51952@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
51953 return -ENOMEM;
51954
51955 atomic_set(&new_od->refcnt, 0);
51956- atomic_set(&new_od->event, 1);
51957+ atomic_set_unchecked(&new_od->event, 1);
51958 init_waitqueue_head(&new_od->poll);
51959 INIT_LIST_HEAD(&new_od->buffers);
51960 goto retry;
51961@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
51962
51963 sysfs_put_active(attr_sd);
51964
51965- if (buffer->event != atomic_read(&od->event))
51966+ if (buffer->event != atomic_read_unchecked(&od->event))
51967 goto trigger;
51968
51969 return DEFAULT_POLLMASK;
51970@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
51971
51972 od = sd->s_attr.open;
51973 if (od) {
51974- atomic_inc(&od->event);
51975+ atomic_inc_unchecked(&od->event);
51976 wake_up_interruptible(&od->poll);
51977 }
51978
51979diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
51980index 3c9eb56..9dea5be 100644
51981--- a/fs/sysfs/symlink.c
51982+++ b/fs/sysfs/symlink.c
51983@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
51984
51985 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
51986 {
51987- char *page = nd_get_link(nd);
51988+ const char *page = nd_get_link(nd);
51989 if (!IS_ERR(page))
51990 free_page((unsigned long)page);
51991 }
51992diff --git a/fs/udf/misc.c b/fs/udf/misc.c
51993index c175b4d..8f36a16 100644
51994--- a/fs/udf/misc.c
51995+++ b/fs/udf/misc.c
51996@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
51997
51998 u8 udf_tag_checksum(const struct tag *t)
51999 {
52000- u8 *data = (u8 *)t;
52001+ const u8 *data = (const u8 *)t;
52002 u8 checksum = 0;
52003 int i;
52004 for (i = 0; i < sizeof(struct tag); ++i)
52005diff --git a/fs/utimes.c b/fs/utimes.c
52006index bb0696a..552054b 100644
52007--- a/fs/utimes.c
52008+++ b/fs/utimes.c
52009@@ -1,6 +1,7 @@
52010 #include <linux/compiler.h>
52011 #include <linux/file.h>
52012 #include <linux/fs.h>
52013+#include <linux/security.h>
52014 #include <linux/linkage.h>
52015 #include <linux/mount.h>
52016 #include <linux/namei.h>
52017@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52018 goto mnt_drop_write_and_out;
52019 }
52020 }
52021+
52022+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52023+ error = -EACCES;
52024+ goto mnt_drop_write_and_out;
52025+ }
52026+
52027 mutex_lock(&inode->i_mutex);
52028 error = notify_change(path->dentry, &newattrs);
52029 mutex_unlock(&inode->i_mutex);
52030diff --git a/fs/xattr.c b/fs/xattr.c
52031index e21c119..21dfc7c 100644
52032--- a/fs/xattr.c
52033+++ b/fs/xattr.c
52034@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52035 * Extended attribute SET operations
52036 */
52037 static long
52038-setxattr(struct dentry *d, const char __user *name, const void __user *value,
52039+setxattr(struct path *path, const char __user *name, const void __user *value,
52040 size_t size, int flags)
52041 {
52042 int error;
52043@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52044 posix_acl_fix_xattr_from_user(kvalue, size);
52045 }
52046
52047- error = vfs_setxattr(d, kname, kvalue, size, flags);
52048+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52049+ error = -EACCES;
52050+ goto out;
52051+ }
52052+
52053+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52054 out:
52055 if (vvalue)
52056 vfree(vvalue);
52057@@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52058 return error;
52059 error = mnt_want_write(path.mnt);
52060 if (!error) {
52061- error = setxattr(path.dentry, name, value, size, flags);
52062+ error = setxattr(&path, name, value, size, flags);
52063 mnt_drop_write(path.mnt);
52064 }
52065 path_put(&path);
52066@@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52067 return error;
52068 error = mnt_want_write(path.mnt);
52069 if (!error) {
52070- error = setxattr(path.dentry, name, value, size, flags);
52071+ error = setxattr(&path, name, value, size, flags);
52072 mnt_drop_write(path.mnt);
52073 }
52074 path_put(&path);
52075@@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52076 const void __user *,value, size_t, size, int, flags)
52077 {
52078 struct fd f = fdget(fd);
52079- struct dentry *dentry;
52080 int error = -EBADF;
52081
52082 if (!f.file)
52083 return error;
52084- dentry = f.file->f_path.dentry;
52085- audit_inode(NULL, dentry, 0);
52086+ audit_inode(NULL, f.file->f_path.dentry, 0);
52087 error = mnt_want_write_file(f.file);
52088 if (!error) {
52089- error = setxattr(dentry, name, value, size, flags);
52090+ error = setxattr(&f.file->f_path, name, value, size, flags);
52091 mnt_drop_write_file(f.file);
52092 }
52093 fdput(f);
52094diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52095index 9fbea87..6b19972 100644
52096--- a/fs/xattr_acl.c
52097+++ b/fs/xattr_acl.c
52098@@ -76,8 +76,8 @@ struct posix_acl *
52099 posix_acl_from_xattr(struct user_namespace *user_ns,
52100 const void *value, size_t size)
52101 {
52102- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52103- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52104+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52105+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52106 int count;
52107 struct posix_acl *acl;
52108 struct posix_acl_entry *acl_e;
52109diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52110index 83d0cf3..2ef526b 100644
52111--- a/fs/xfs/xfs_bmap.c
52112+++ b/fs/xfs/xfs_bmap.c
52113@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52114 int nmap,
52115 int ret_nmap);
52116 #else
52117-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52118+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52119 #endif /* DEBUG */
52120
52121 STATIC int
52122diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52123index 1b9fc3e..e1bdde0 100644
52124--- a/fs/xfs/xfs_dir2_sf.c
52125+++ b/fs/xfs/xfs_dir2_sf.c
52126@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52127 }
52128
52129 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52130- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52131+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52132+ char name[sfep->namelen];
52133+ memcpy(name, sfep->name, sfep->namelen);
52134+ if (filldir(dirent, name, sfep->namelen,
52135+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
52136+ *offset = off & 0x7fffffff;
52137+ return 0;
52138+ }
52139+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52140 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52141 *offset = off & 0x7fffffff;
52142 return 0;
52143diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52144index c1df3c6..f987db6 100644
52145--- a/fs/xfs/xfs_ioctl.c
52146+++ b/fs/xfs/xfs_ioctl.c
52147@@ -126,7 +126,7 @@ xfs_find_handle(
52148 }
52149
52150 error = -EFAULT;
52151- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52152+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52153 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52154 goto out_put;
52155
52156diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52157index 4e00cf0..3374374 100644
52158--- a/fs/xfs/xfs_iops.c
52159+++ b/fs/xfs/xfs_iops.c
52160@@ -394,7 +394,7 @@ xfs_vn_put_link(
52161 struct nameidata *nd,
52162 void *p)
52163 {
52164- char *s = nd_get_link(nd);
52165+ const char *s = nd_get_link(nd);
52166
52167 if (!IS_ERR(s))
52168 kfree(s);
52169diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52170new file mode 100644
52171index 0000000..92247e4
52172--- /dev/null
52173+++ b/grsecurity/Kconfig
52174@@ -0,0 +1,1021 @@
52175+#
52176+# grecurity configuration
52177+#
52178+menu "Memory Protections"
52179+depends on GRKERNSEC
52180+
52181+config GRKERNSEC_KMEM
52182+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52183+ default y if GRKERNSEC_CONFIG_AUTO
52184+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52185+ help
52186+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52187+ be written to or read from to modify or leak the contents of the running
52188+ kernel. /dev/port will also not be allowed to be opened and support
52189+ for /dev/cpu/*/msr will be removed. If you have module
52190+ support disabled, enabling this will close up five ways that are
52191+ currently used to insert malicious code into the running kernel.
52192+
52193+ Even with all these features enabled, we still highly recommend that
52194+ you use the RBAC system, as it is still possible for an attacker to
52195+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52196+
52197+ If you are not using XFree86, you may be able to stop this additional
52198+ case by enabling the 'Disable privileged I/O' option. Though nothing
52199+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52200+ but only to video memory, which is the only writing we allow in this
52201+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52202+ not be allowed to mprotect it with PROT_WRITE later.
52203+ Enabling this feature will prevent the "cpupower" and "powertop" tools
52204+ from working.
52205+
52206+ It is highly recommended that you say Y here if you meet all the
52207+ conditions above.
52208+
52209+config GRKERNSEC_VM86
52210+ bool "Restrict VM86 mode"
52211+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52212+ depends on X86_32
52213+
52214+ help
52215+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52216+ make use of a special execution mode on 32bit x86 processors called
52217+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52218+ video cards and will still work with this option enabled. The purpose
52219+ of the option is to prevent exploitation of emulation errors in
52220+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52221+ Nearly all users should be able to enable this option.
52222+
52223+config GRKERNSEC_IO
52224+ bool "Disable privileged I/O"
52225+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52226+ depends on X86
52227+ select RTC_CLASS
52228+ select RTC_INTF_DEV
52229+ select RTC_DRV_CMOS
52230+
52231+ help
52232+ If you say Y here, all ioperm and iopl calls will return an error.
52233+ Ioperm and iopl can be used to modify the running kernel.
52234+ Unfortunately, some programs need this access to operate properly,
52235+ the most notable of which are XFree86 and hwclock. hwclock can be
52236+ remedied by having RTC support in the kernel, so real-time
52237+ clock support is enabled if this option is enabled, to ensure
52238+ that hwclock operates correctly. XFree86 still will not
52239+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52240+ IF YOU USE XFree86. If you use XFree86 and you still want to
52241+ protect your kernel against modification, use the RBAC system.
52242+
52243+config GRKERNSEC_JIT_HARDEN
52244+ bool "Harden BPF JIT against spray attacks"
52245+ default y if GRKERNSEC_CONFIG_AUTO
52246+ depends on BPF_JIT
52247+ help
52248+ If you say Y here, the native code generated by the kernel's Berkeley
52249+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52250+ attacks that attempt to fit attacker-beneficial instructions in
52251+ 32bit immediate fields of JIT-generated native instructions. The
52252+ attacker will generally aim to cause an unintended instruction sequence
52253+ of JIT-generated native code to execute by jumping into the middle of
52254+ a generated instruction. This feature effectively randomizes the 32bit
52255+ immediate constants present in the generated code to thwart such attacks.
52256+
52257+ If you're using KERNEXEC, it's recommended that you enable this option
52258+ to supplement the hardening of the kernel.
52259+
52260+config GRKERNSEC_RAND_THREADSTACK
52261+ bool "Insert random gaps between thread stacks"
52262+ default y if GRKERNSEC_CONFIG_AUTO
52263+ depends on PAX_RANDMMAP && !PPC
52264+ help
52265+ If you say Y here, a random-sized gap will be enforced between allocated
52266+ thread stacks. Glibc's NPTL and other threading libraries that
52267+ pass MAP_STACK to the kernel for thread stack allocation are supported.
52268+ The implementation currently provides 8 bits of entropy for the gap.
52269+
52270+ Many distributions do not compile threaded remote services with the
52271+ -fstack-check argument to GCC, causing the variable-sized stack-based
52272+ allocator, alloca(), to not probe the stack on allocation. This
52273+ permits an unbounded alloca() to skip over any guard page and potentially
52274+ modify another thread's stack reliably. An enforced random gap
52275+ reduces the reliability of such an attack and increases the chance
52276+ that such a read/write to another thread's stack instead lands in
52277+ an unmapped area, causing a crash and triggering grsecurity's
52278+ anti-bruteforcing logic.
52279+
52280+config GRKERNSEC_PROC_MEMMAP
52281+ bool "Harden ASLR against information leaks and entropy reduction"
52282+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52283+ depends on PAX_NOEXEC || PAX_ASLR
52284+ help
52285+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52286+ give no information about the addresses of its mappings if
52287+ PaX features that rely on random addresses are enabled on the task.
52288+ In addition to sanitizing this information and disabling other
52289+ dangerous sources of information, this option causes reads of sensitive
52290+ /proc/<pid> entries where the file descriptor was opened in a different
52291+ task than the one performing the read. Such attempts are logged.
52292+ This option also limits argv/env strings for suid/sgid binaries
52293+ to 512KB to prevent a complete exhaustion of the stack entropy provided
52294+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52295+ binaries to prevent alternative mmap layouts from being abused.
52296+
52297+ If you use PaX it is essential that you say Y here as it closes up
52298+ several holes that make full ASLR useless locally.
52299+
52300+config GRKERNSEC_BRUTE
52301+ bool "Deter exploit bruteforcing"
52302+ default y if GRKERNSEC_CONFIG_AUTO
52303+ help
52304+ If you say Y here, attempts to bruteforce exploits against forking
52305+ daemons such as apache or sshd, as well as against suid/sgid binaries
52306+ will be deterred. When a child of a forking daemon is killed by PaX
52307+ or crashes due to an illegal instruction or other suspicious signal,
52308+ the parent process will be delayed 30 seconds upon every subsequent
52309+ fork until the administrator is able to assess the situation and
52310+ restart the daemon.
52311+ In the suid/sgid case, the attempt is logged, the user has all their
52312+ processes terminated, and they are prevented from executing any further
52313+ processes for 15 minutes.
52314+ It is recommended that you also enable signal logging in the auditing
52315+ section so that logs are generated when a process triggers a suspicious
52316+ signal.
52317+ If the sysctl option is enabled, a sysctl option with name
52318+ "deter_bruteforce" is created.
52319+
52320+
52321+config GRKERNSEC_MODHARDEN
52322+ bool "Harden module auto-loading"
52323+ default y if GRKERNSEC_CONFIG_AUTO
52324+ depends on MODULES
52325+ help
52326+ If you say Y here, module auto-loading in response to use of some
52327+ feature implemented by an unloaded module will be restricted to
52328+ root users. Enabling this option helps defend against attacks
52329+ by unprivileged users who abuse the auto-loading behavior to
52330+ cause a vulnerable module to load that is then exploited.
52331+
52332+ If this option prevents a legitimate use of auto-loading for a
52333+ non-root user, the administrator can execute modprobe manually
52334+ with the exact name of the module mentioned in the alert log.
52335+ Alternatively, the administrator can add the module to the list
52336+ of modules loaded at boot by modifying init scripts.
52337+
52338+ Modification of init scripts will most likely be needed on
52339+ Ubuntu servers with encrypted home directory support enabled,
52340+ as the first non-root user logging in will cause the ecb(aes),
52341+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52342+
52343+config GRKERNSEC_HIDESYM
52344+ bool "Hide kernel symbols"
52345+ default y if GRKERNSEC_CONFIG_AUTO
52346+ select PAX_USERCOPY_SLABS
52347+ help
52348+ If you say Y here, getting information on loaded modules, and
52349+ displaying all kernel symbols through a syscall will be restricted
52350+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52351+ /proc/kallsyms will be restricted to the root user. The RBAC
52352+ system can hide that entry even from root.
52353+
52354+ This option also prevents leaking of kernel addresses through
52355+ several /proc entries.
52356+
52357+ Note that this option is only effective provided the following
52358+ conditions are met:
52359+ 1) The kernel using grsecurity is not precompiled by some distribution
52360+ 2) You have also enabled GRKERNSEC_DMESG
52361+ 3) You are using the RBAC system and hiding other files such as your
52362+ kernel image and System.map. Alternatively, enabling this option
52363+ causes the permissions on /boot, /lib/modules, and the kernel
52364+ source directory to change at compile time to prevent
52365+ reading by non-root users.
52366+ If the above conditions are met, this option will aid in providing a
52367+ useful protection against local kernel exploitation of overflows
52368+ and arbitrary read/write vulnerabilities.
52369+
52370+config GRKERNSEC_KERN_LOCKOUT
52371+ bool "Active kernel exploit response"
52372+ default y if GRKERNSEC_CONFIG_AUTO
52373+ depends on X86 || ARM || PPC || SPARC
52374+ help
52375+ If you say Y here, when a PaX alert is triggered due to suspicious
52376+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52377+ or an OOPS occurs due to bad memory accesses, instead of just
52378+ terminating the offending process (and potentially allowing
52379+ a subsequent exploit from the same user), we will take one of two
52380+ actions:
52381+ If the user was root, we will panic the system
52382+ If the user was non-root, we will log the attempt, terminate
52383+ all processes owned by the user, then prevent them from creating
52384+ any new processes until the system is restarted
52385+ This deters repeated kernel exploitation/bruteforcing attempts
52386+ and is useful for later forensics.
52387+
52388+endmenu
52389+menu "Role Based Access Control Options"
52390+depends on GRKERNSEC
52391+
52392+config GRKERNSEC_RBAC_DEBUG
52393+ bool
52394+
52395+config GRKERNSEC_NO_RBAC
52396+ bool "Disable RBAC system"
52397+ help
52398+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52399+ preventing the RBAC system from being enabled. You should only say Y
52400+ here if you have no intention of using the RBAC system, so as to prevent
52401+ an attacker with root access from misusing the RBAC system to hide files
52402+ and processes when loadable module support and /dev/[k]mem have been
52403+ locked down.
52404+
52405+config GRKERNSEC_ACL_HIDEKERN
52406+ bool "Hide kernel processes"
52407+ help
52408+ If you say Y here, all kernel threads will be hidden to all
52409+ processes but those whose subject has the "view hidden processes"
52410+ flag.
52411+
52412+config GRKERNSEC_ACL_MAXTRIES
52413+ int "Maximum tries before password lockout"
52414+ default 3
52415+ help
52416+ This option enforces the maximum number of times a user can attempt
52417+ to authorize themselves with the grsecurity RBAC system before being
52418+ denied the ability to attempt authorization again for a specified time.
52419+ The lower the number, the harder it will be to brute-force a password.
52420+
52421+config GRKERNSEC_ACL_TIMEOUT
52422+ int "Time to wait after max password tries, in seconds"
52423+ default 30
52424+ help
52425+ This option specifies the time the user must wait after attempting to
52426+ authorize to the RBAC system with the maximum number of invalid
52427+ passwords. The higher the number, the harder it will be to brute-force
52428+ a password.
52429+
52430+endmenu
52431+menu "Filesystem Protections"
52432+depends on GRKERNSEC
52433+
52434+config GRKERNSEC_PROC
52435+ bool "Proc restrictions"
52436+ default y if GRKERNSEC_CONFIG_AUTO
52437+ help
52438+ If you say Y here, the permissions of the /proc filesystem
52439+ will be altered to enhance system security and privacy. You MUST
52440+ choose either a user only restriction or a user and group restriction.
52441+ Depending upon the option you choose, you can either restrict users to
52442+ see only the processes they themselves run, or choose a group that can
52443+ view all processes and files normally restricted to root if you choose
52444+ the "restrict to user only" option. NOTE: If you're running identd or
52445+ ntpd as a non-root user, you will have to run it as the group you
52446+ specify here.
52447+
52448+config GRKERNSEC_PROC_USER
52449+ bool "Restrict /proc to user only"
52450+ depends on GRKERNSEC_PROC
52451+ help
52452+ If you say Y here, non-root users will only be able to view their own
52453+ processes, and restricts them from viewing network-related information,
52454+ and viewing kernel symbol and module information.
52455+
52456+config GRKERNSEC_PROC_USERGROUP
52457+ bool "Allow special group"
52458+ default y if GRKERNSEC_CONFIG_AUTO
52459+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52460+ help
52461+ If you say Y here, you will be able to select a group that will be
52462+ able to view all processes and network-related information. If you've
52463+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52464+ remain hidden. This option is useful if you want to run identd as
52465+ a non-root user. The group you select may also be chosen at boot time
52466+ via "grsec_proc_gid=" on the kernel commandline.
52467+
52468+config GRKERNSEC_PROC_GID
52469+ int "GID for special group"
52470+ depends on GRKERNSEC_PROC_USERGROUP
52471+ default 1001
52472+
52473+config GRKERNSEC_PROC_ADD
52474+ bool "Additional restrictions"
52475+ default y if GRKERNSEC_CONFIG_AUTO
52476+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52477+ help
52478+ If you say Y here, additional restrictions will be placed on
52479+ /proc that keep normal users from viewing device information and
52480+ slabinfo information that could be useful for exploits.
52481+
52482+config GRKERNSEC_LINK
52483+ bool "Linking restrictions"
52484+ default y if GRKERNSEC_CONFIG_AUTO
52485+ help
52486+ If you say Y here, /tmp race exploits will be prevented, since users
52487+ will no longer be able to follow symlinks owned by other users in
52488+ world-writable +t directories (e.g. /tmp), unless the owner of the
52489+ symlink is the owner of the directory. users will also not be
52490+ able to hardlink to files they do not own. If the sysctl option is
52491+ enabled, a sysctl option with name "linking_restrictions" is created.
52492+
52493+config GRKERNSEC_SYMLINKOWN
52494+ bool "Kernel-enforced SymlinksIfOwnerMatch"
52495+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52496+ help
52497+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
52498+ that prevents it from being used as a security feature. As Apache
52499+ verifies the symlink by performing a stat() against the target of
52500+ the symlink before it is followed, an attacker can setup a symlink
52501+ to point to a same-owned file, then replace the symlink with one
52502+ that targets another user's file just after Apache "validates" the
52503+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
52504+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52505+ will be in place for the group you specify. If the sysctl option
52506+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
52507+ created.
52508+
52509+config GRKERNSEC_SYMLINKOWN_GID
52510+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52511+ depends on GRKERNSEC_SYMLINKOWN
52512+ default 1006
52513+ help
52514+ Setting this GID determines what group kernel-enforced
52515+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52516+ is enabled, a sysctl option with name "symlinkown_gid" is created.
52517+
52518+config GRKERNSEC_FIFO
52519+ bool "FIFO restrictions"
52520+ default y if GRKERNSEC_CONFIG_AUTO
52521+ help
52522+ If you say Y here, users will not be able to write to FIFOs they don't
52523+ own in world-writable +t directories (e.g. /tmp), unless the owner of
52524+ the FIFO is the same owner of the directory it's held in. If the sysctl
52525+ option is enabled, a sysctl option with name "fifo_restrictions" is
52526+ created.
52527+
52528+config GRKERNSEC_SYSFS_RESTRICT
52529+ bool "Sysfs/debugfs restriction"
52530+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52531+ depends on SYSFS
52532+ help
52533+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52534+ any filesystem normally mounted under it (e.g. debugfs) will be
52535+ mostly accessible only by root. These filesystems generally provide access
52536+ to hardware and debug information that isn't appropriate for unprivileged
52537+ users of the system. Sysfs and debugfs have also become a large source
52538+ of new vulnerabilities, ranging from infoleaks to local compromise.
52539+ There has been very little oversight with an eye toward security involved
52540+ in adding new exporters of information to these filesystems, so their
52541+ use is discouraged.
52542+ For reasons of compatibility, a few directories have been whitelisted
52543+ for access by non-root users:
52544+ /sys/fs/selinux
52545+ /sys/fs/fuse
52546+ /sys/devices/system/cpu
52547+
52548+config GRKERNSEC_ROFS
52549+ bool "Runtime read-only mount protection"
52550+ help
52551+ If you say Y here, a sysctl option with name "romount_protect" will
52552+ be created. By setting this option to 1 at runtime, filesystems
52553+ will be protected in the following ways:
52554+ * No new writable mounts will be allowed
52555+ * Existing read-only mounts won't be able to be remounted read/write
52556+ * Write operations will be denied on all block devices
52557+ This option acts independently of grsec_lock: once it is set to 1,
52558+ it cannot be turned off. Therefore, please be mindful of the resulting
52559+ behavior if this option is enabled in an init script on a read-only
52560+ filesystem. This feature is mainly intended for secure embedded systems.
52561+
52562+config GRKERNSEC_DEVICE_SIDECHANNEL
52563+ bool "Eliminate stat/notify-based device sidechannels"
52564+ default y if GRKERNSEC_CONFIG_AUTO
52565+ help
52566+ If you say Y here, timing analyses on block or character
52567+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52568+ will be thwarted for unprivileged users. If a process without
52569+ CAP_MKNOD stats such a device, the last access and last modify times
52570+ will match the device's create time. No access or modify events
52571+ will be triggered through inotify/dnotify/fanotify for such devices.
52572+ This feature will prevent attacks that may at a minimum
52573+ allow an attacker to determine the administrator's password length.
52574+
52575+config GRKERNSEC_CHROOT
52576+ bool "Chroot jail restrictions"
52577+ default y if GRKERNSEC_CONFIG_AUTO
52578+ help
52579+ If you say Y here, you will be able to choose several options that will
52580+ make breaking out of a chrooted jail much more difficult. If you
52581+ encounter no software incompatibilities with the following options, it
52582+ is recommended that you enable each one.
52583+
52584+config GRKERNSEC_CHROOT_MOUNT
52585+ bool "Deny mounts"
52586+ default y if GRKERNSEC_CONFIG_AUTO
52587+ depends on GRKERNSEC_CHROOT
52588+ help
52589+ If you say Y here, processes inside a chroot will not be able to
52590+ mount or remount filesystems. If the sysctl option is enabled, a
52591+ sysctl option with name "chroot_deny_mount" is created.
52592+
52593+config GRKERNSEC_CHROOT_DOUBLE
52594+ bool "Deny double-chroots"
52595+ default y if GRKERNSEC_CONFIG_AUTO
52596+ depends on GRKERNSEC_CHROOT
52597+ help
52598+ If you say Y here, processes inside a chroot will not be able to chroot
52599+ again outside the chroot. This is a widely used method of breaking
52600+ out of a chroot jail and should not be allowed. If the sysctl
52601+ option is enabled, a sysctl option with name
52602+ "chroot_deny_chroot" is created.
52603+
52604+config GRKERNSEC_CHROOT_PIVOT
52605+ bool "Deny pivot_root in chroot"
52606+ default y if GRKERNSEC_CONFIG_AUTO
52607+ depends on GRKERNSEC_CHROOT
52608+ help
52609+ If you say Y here, processes inside a chroot will not be able to use
52610+ a function called pivot_root() that was introduced in Linux 2.3.41. It
52611+ works similar to chroot in that it changes the root filesystem. This
52612+ function could be misused in a chrooted process to attempt to break out
52613+ of the chroot, and therefore should not be allowed. If the sysctl
52614+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
52615+ created.
52616+
52617+config GRKERNSEC_CHROOT_CHDIR
52618+ bool "Enforce chdir(\"/\") on all chroots"
52619+ default y if GRKERNSEC_CONFIG_AUTO
52620+ depends on GRKERNSEC_CHROOT
52621+ help
52622+ If you say Y here, the current working directory of all newly-chrooted
52623+ applications will be set to the the root directory of the chroot.
52624+ The man page on chroot(2) states:
52625+ Note that this call does not change the current working
52626+ directory, so that `.' can be outside the tree rooted at
52627+ `/'. In particular, the super-user can escape from a
52628+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52629+
52630+ It is recommended that you say Y here, since it's not known to break
52631+ any software. If the sysctl option is enabled, a sysctl option with
52632+ name "chroot_enforce_chdir" is created.
52633+
52634+config GRKERNSEC_CHROOT_CHMOD
52635+ bool "Deny (f)chmod +s"
52636+ default y if GRKERNSEC_CONFIG_AUTO
52637+ depends on GRKERNSEC_CHROOT
52638+ help
52639+ If you say Y here, processes inside a chroot will not be able to chmod
52640+ or fchmod files to make them have suid or sgid bits. This protects
52641+ against another published method of breaking a chroot. If the sysctl
52642+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
52643+ created.
52644+
52645+config GRKERNSEC_CHROOT_FCHDIR
52646+ bool "Deny fchdir out of chroot"
52647+ default y if GRKERNSEC_CONFIG_AUTO
52648+ depends on GRKERNSEC_CHROOT
52649+ help
52650+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
52651+ to a file descriptor of the chrooting process that points to a directory
52652+ outside the filesystem will be stopped. If the sysctl option
52653+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52654+
52655+config GRKERNSEC_CHROOT_MKNOD
52656+ bool "Deny mknod"
52657+ default y if GRKERNSEC_CONFIG_AUTO
52658+ depends on GRKERNSEC_CHROOT
52659+ help
52660+ If you say Y here, processes inside a chroot will not be allowed to
52661+ mknod. The problem with using mknod inside a chroot is that it
52662+ would allow an attacker to create a device entry that is the same
52663+ as one on the physical root of your system, which could range from
52664+ anything from the console device to a device for your harddrive (which
52665+ they could then use to wipe the drive or steal data). It is recommended
52666+ that you say Y here, unless you run into software incompatibilities.
52667+ If the sysctl option is enabled, a sysctl option with name
52668+ "chroot_deny_mknod" is created.
52669+
52670+config GRKERNSEC_CHROOT_SHMAT
52671+ bool "Deny shmat() out of chroot"
52672+ default y if GRKERNSEC_CONFIG_AUTO
52673+ depends on GRKERNSEC_CHROOT
52674+ help
52675+ If you say Y here, processes inside a chroot will not be able to attach
52676+ to shared memory segments that were created outside of the chroot jail.
52677+ It is recommended that you say Y here. If the sysctl option is enabled,
52678+ a sysctl option with name "chroot_deny_shmat" is created.
52679+
52680+config GRKERNSEC_CHROOT_UNIX
52681+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
52682+ default y if GRKERNSEC_CONFIG_AUTO
52683+ depends on GRKERNSEC_CHROOT
52684+ help
52685+ If you say Y here, processes inside a chroot will not be able to
52686+ connect to abstract (meaning not belonging to a filesystem) Unix
52687+ domain sockets that were bound outside of a chroot. It is recommended
52688+ that you say Y here. If the sysctl option is enabled, a sysctl option
52689+ with name "chroot_deny_unix" is created.
52690+
52691+config GRKERNSEC_CHROOT_FINDTASK
52692+ bool "Protect outside processes"
52693+ default y if GRKERNSEC_CONFIG_AUTO
52694+ depends on GRKERNSEC_CHROOT
52695+ help
52696+ If you say Y here, processes inside a chroot will not be able to
52697+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52698+ getsid, or view any process outside of the chroot. If the sysctl
52699+ option is enabled, a sysctl option with name "chroot_findtask" is
52700+ created.
52701+
52702+config GRKERNSEC_CHROOT_NICE
52703+ bool "Restrict priority changes"
52704+ default y if GRKERNSEC_CONFIG_AUTO
52705+ depends on GRKERNSEC_CHROOT
52706+ help
52707+ If you say Y here, processes inside a chroot will not be able to raise
52708+ the priority of processes in the chroot, or alter the priority of
52709+ processes outside the chroot. This provides more security than simply
52710+ removing CAP_SYS_NICE from the process' capability set. If the
52711+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52712+ is created.
52713+
52714+config GRKERNSEC_CHROOT_SYSCTL
52715+ bool "Deny sysctl writes"
52716+ default y if GRKERNSEC_CONFIG_AUTO
52717+ depends on GRKERNSEC_CHROOT
52718+ help
52719+ If you say Y here, an attacker in a chroot will not be able to
52720+ write to sysctl entries, either by sysctl(2) or through a /proc
52721+ interface. It is strongly recommended that you say Y here. If the
52722+ sysctl option is enabled, a sysctl option with name
52723+ "chroot_deny_sysctl" is created.
52724+
52725+config GRKERNSEC_CHROOT_CAPS
52726+ bool "Capability restrictions"
52727+ default y if GRKERNSEC_CONFIG_AUTO
52728+ depends on GRKERNSEC_CHROOT
52729+ help
52730+ If you say Y here, the capabilities on all processes within a
52731+ chroot jail will be lowered to stop module insertion, raw i/o,
52732+ system and net admin tasks, rebooting the system, modifying immutable
52733+ files, modifying IPC owned by another, and changing the system time.
52734+ This is left an option because it can break some apps. Disable this
52735+ if your chrooted apps are having problems performing those kinds of
52736+ tasks. If the sysctl option is enabled, a sysctl option with
52737+ name "chroot_caps" is created.
52738+
52739+endmenu
52740+menu "Kernel Auditing"
52741+depends on GRKERNSEC
52742+
52743+config GRKERNSEC_AUDIT_GROUP
52744+ bool "Single group for auditing"
52745+ help
52746+ If you say Y here, the exec and chdir logging features will only operate
52747+ on a group you specify. This option is recommended if you only want to
52748+ watch certain users instead of having a large amount of logs from the
52749+ entire system. If the sysctl option is enabled, a sysctl option with
52750+ name "audit_group" is created.
52751+
52752+config GRKERNSEC_AUDIT_GID
52753+ int "GID for auditing"
52754+ depends on GRKERNSEC_AUDIT_GROUP
52755+ default 1007
52756+
52757+config GRKERNSEC_EXECLOG
52758+ bool "Exec logging"
52759+ help
52760+ If you say Y here, all execve() calls will be logged (since the
52761+ other exec*() calls are frontends to execve(), all execution
52762+ will be logged). Useful for shell-servers that like to keep track
52763+ of their users. If the sysctl option is enabled, a sysctl option with
52764+ name "exec_logging" is created.
52765+ WARNING: This option when enabled will produce a LOT of logs, especially
52766+ on an active system.
52767+
52768+config GRKERNSEC_RESLOG
52769+ bool "Resource logging"
52770+ default y if GRKERNSEC_CONFIG_AUTO
52771+ help
52772+ If you say Y here, all attempts to overstep resource limits will
52773+ be logged with the resource name, the requested size, and the current
52774+ limit. It is highly recommended that you say Y here. If the sysctl
52775+ option is enabled, a sysctl option with name "resource_logging" is
52776+ created. If the RBAC system is enabled, the sysctl value is ignored.
52777+
52778+config GRKERNSEC_CHROOT_EXECLOG
52779+ bool "Log execs within chroot"
52780+ help
52781+ If you say Y here, all executions inside a chroot jail will be logged
52782+ to syslog. This can cause a large amount of logs if certain
52783+ applications (eg. djb's daemontools) are installed on the system, and
52784+ is therefore left as an option. If the sysctl option is enabled, a
52785+ sysctl option with name "chroot_execlog" is created.
52786+
52787+config GRKERNSEC_AUDIT_PTRACE
52788+ bool "Ptrace logging"
52789+ help
52790+ If you say Y here, all attempts to attach to a process via ptrace
52791+ will be logged. If the sysctl option is enabled, a sysctl option
52792+ with name "audit_ptrace" is created.
52793+
52794+config GRKERNSEC_AUDIT_CHDIR
52795+ bool "Chdir logging"
52796+ help
52797+ If you say Y here, all chdir() calls will be logged. If the sysctl
52798+ option is enabled, a sysctl option with name "audit_chdir" is created.
52799+
52800+config GRKERNSEC_AUDIT_MOUNT
52801+ bool "(Un)Mount logging"
52802+ help
52803+ If you say Y here, all mounts and unmounts will be logged. If the
52804+ sysctl option is enabled, a sysctl option with name "audit_mount" is
52805+ created.
52806+
52807+config GRKERNSEC_SIGNAL
52808+ bool "Signal logging"
52809+ default y if GRKERNSEC_CONFIG_AUTO
52810+ help
52811+ If you say Y here, certain important signals will be logged, such as
52812+ SIGSEGV, which will as a result inform you of when a error in a program
52813+ occurred, which in some cases could mean a possible exploit attempt.
52814+ If the sysctl option is enabled, a sysctl option with name
52815+ "signal_logging" is created.
52816+
52817+config GRKERNSEC_FORKFAIL
52818+ bool "Fork failure logging"
52819+ help
52820+ If you say Y here, all failed fork() attempts will be logged.
52821+ This could suggest a fork bomb, or someone attempting to overstep
52822+ their process limit. If the sysctl option is enabled, a sysctl option
52823+ with name "forkfail_logging" is created.
52824+
52825+config GRKERNSEC_TIME
52826+ bool "Time change logging"
52827+ default y if GRKERNSEC_CONFIG_AUTO
52828+ help
52829+ If you say Y here, any changes of the system clock will be logged.
52830+ If the sysctl option is enabled, a sysctl option with name
52831+ "timechange_logging" is created.
52832+
52833+config GRKERNSEC_PROC_IPADDR
52834+ bool "/proc/<pid>/ipaddr support"
52835+ default y if GRKERNSEC_CONFIG_AUTO
52836+ help
52837+ If you say Y here, a new entry will be added to each /proc/<pid>
52838+ directory that contains the IP address of the person using the task.
52839+ The IP is carried across local TCP and AF_UNIX stream sockets.
52840+ This information can be useful for IDS/IPSes to perform remote response
52841+ to a local attack. The entry is readable by only the owner of the
52842+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
52843+ the RBAC system), and thus does not create privacy concerns.
52844+
52845+config GRKERNSEC_RWXMAP_LOG
52846+ bool 'Denied RWX mmap/mprotect logging'
52847+ default y if GRKERNSEC_CONFIG_AUTO
52848+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
52849+ help
52850+ If you say Y here, calls to mmap() and mprotect() with explicit
52851+ usage of PROT_WRITE and PROT_EXEC together will be logged when
52852+ denied by the PAX_MPROTECT feature. If the sysctl option is
52853+ enabled, a sysctl option with name "rwxmap_logging" is created.
52854+
52855+config GRKERNSEC_AUDIT_TEXTREL
52856+ bool 'ELF text relocations logging (READ HELP)'
52857+ depends on PAX_MPROTECT
52858+ help
52859+ If you say Y here, text relocations will be logged with the filename
52860+ of the offending library or binary. The purpose of the feature is
52861+ to help Linux distribution developers get rid of libraries and
52862+ binaries that need text relocations which hinder the future progress
52863+ of PaX. Only Linux distribution developers should say Y here, and
52864+ never on a production machine, as this option creates an information
52865+ leak that could aid an attacker in defeating the randomization of
52866+ a single memory region. If the sysctl option is enabled, a sysctl
52867+ option with name "audit_textrel" is created.
52868+
52869+endmenu
52870+
52871+menu "Executable Protections"
52872+depends on GRKERNSEC
52873+
52874+config GRKERNSEC_DMESG
52875+ bool "Dmesg(8) restriction"
52876+ default y if GRKERNSEC_CONFIG_AUTO
52877+ help
52878+ If you say Y here, non-root users will not be able to use dmesg(8)
52879+ to view the contents of the kernel's circular log buffer.
52880+ The kernel's log buffer often contains kernel addresses and other
52881+ identifying information useful to an attacker in fingerprinting a
52882+ system for a targeted exploit.
52883+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
52884+ created.
52885+
52886+config GRKERNSEC_HARDEN_PTRACE
52887+ bool "Deter ptrace-based process snooping"
52888+ default y if GRKERNSEC_CONFIG_AUTO
52889+ help
52890+ If you say Y here, TTY sniffers and other malicious monitoring
52891+ programs implemented through ptrace will be defeated. If you
52892+ have been using the RBAC system, this option has already been
52893+ enabled for several years for all users, with the ability to make
52894+ fine-grained exceptions.
52895+
52896+ This option only affects the ability of non-root users to ptrace
52897+ processes that are not a descendent of the ptracing process.
52898+ This means that strace ./binary and gdb ./binary will still work,
52899+ but attaching to arbitrary processes will not. If the sysctl
52900+ option is enabled, a sysctl option with name "harden_ptrace" is
52901+ created.
52902+
52903+config GRKERNSEC_PTRACE_READEXEC
52904+ bool "Require read access to ptrace sensitive binaries"
52905+ default y if GRKERNSEC_CONFIG_AUTO
52906+ help
52907+ If you say Y here, unprivileged users will not be able to ptrace unreadable
52908+ binaries. This option is useful in environments that
52909+ remove the read bits (e.g. file mode 4711) from suid binaries to
52910+ prevent infoleaking of their contents. This option adds
52911+ consistency to the use of that file mode, as the binary could normally
52912+ be read out when run without privileges while ptracing.
52913+
52914+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
52915+ is created.
52916+
52917+config GRKERNSEC_SETXID
52918+ bool "Enforce consistent multithreaded privileges"
52919+ default y if GRKERNSEC_CONFIG_AUTO
52920+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
52921+ help
52922+ If you say Y here, a change from a root uid to a non-root uid
52923+ in a multithreaded application will cause the resulting uids,
52924+ gids, supplementary groups, and capabilities in that thread
52925+ to be propagated to the other threads of the process. In most
52926+ cases this is unnecessary, as glibc will emulate this behavior
52927+ on behalf of the application. Other libcs do not act in the
52928+ same way, allowing the other threads of the process to continue
52929+ running with root privileges. If the sysctl option is enabled,
52930+ a sysctl option with name "consistent_setxid" is created.
52931+
52932+config GRKERNSEC_TPE
52933+ bool "Trusted Path Execution (TPE)"
52934+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52935+ help
52936+ If you say Y here, you will be able to choose a gid to add to the
52937+ supplementary groups of users you want to mark as "untrusted."
52938+ These users will not be able to execute any files that are not in
52939+ root-owned directories writable only by root. If the sysctl option
52940+ is enabled, a sysctl option with name "tpe" is created.
52941+
52942+config GRKERNSEC_TPE_ALL
52943+ bool "Partially restrict all non-root users"
52944+ depends on GRKERNSEC_TPE
52945+ help
52946+ If you say Y here, all non-root users will be covered under
52947+ a weaker TPE restriction. This is separate from, and in addition to,
52948+ the main TPE options that you have selected elsewhere. Thus, if a
52949+ "trusted" GID is chosen, this restriction applies to even that GID.
52950+ Under this restriction, all non-root users will only be allowed to
52951+ execute files in directories they own that are not group or
52952+ world-writable, or in directories owned by root and writable only by
52953+ root. If the sysctl option is enabled, a sysctl option with name
52954+ "tpe_restrict_all" is created.
52955+
52956+config GRKERNSEC_TPE_INVERT
52957+ bool "Invert GID option"
52958+ depends on GRKERNSEC_TPE
52959+ help
52960+ If you say Y here, the group you specify in the TPE configuration will
52961+ decide what group TPE restrictions will be *disabled* for. This
52962+ option is useful if you want TPE restrictions to be applied to most
52963+ users on the system. If the sysctl option is enabled, a sysctl option
52964+ with name "tpe_invert" is created. Unlike other sysctl options, this
52965+ entry will default to on for backward-compatibility.
52966+
52967+config GRKERNSEC_TPE_GID
52968+ int
52969+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
52970+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
52971+
52972+config GRKERNSEC_TPE_UNTRUSTED_GID
52973+ int "GID for TPE-untrusted users"
52974+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
52975+ default 1005
52976+ help
52977+ Setting this GID determines what group TPE restrictions will be
52978+ *enabled* for. If the sysctl option is enabled, a sysctl option
52979+ with name "tpe_gid" is created.
52980+
52981+config GRKERNSEC_TPE_TRUSTED_GID
52982+ int "GID for TPE-trusted users"
52983+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
52984+ default 1005
52985+ help
52986+ Setting this GID determines what group TPE restrictions will be
52987+ *disabled* for. If the sysctl option is enabled, a sysctl option
52988+ with name "tpe_gid" is created.
52989+
52990+endmenu
52991+menu "Network Protections"
52992+depends on GRKERNSEC
52993+
52994+config GRKERNSEC_RANDNET
52995+ bool "Larger entropy pools"
52996+ default y if GRKERNSEC_CONFIG_AUTO
52997+ help
52998+ If you say Y here, the entropy pools used for many features of Linux
52999+ and grsecurity will be doubled in size. Since several grsecurity
53000+ features use additional randomness, it is recommended that you say Y
53001+ here. Saying Y here has a similar effect as modifying
53002+ /proc/sys/kernel/random/poolsize.
53003+
53004+config GRKERNSEC_BLACKHOLE
53005+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53006+ default y if GRKERNSEC_CONFIG_AUTO
53007+ depends on NET
53008+ help
53009+ If you say Y here, neither TCP resets nor ICMP
53010+ destination-unreachable packets will be sent in response to packets
53011+ sent to ports for which no associated listening process exists.
53012+ This feature supports both IPV4 and IPV6 and exempts the
53013+ loopback interface from blackholing. Enabling this feature
53014+ makes a host more resilient to DoS attacks and reduces network
53015+ visibility against scanners.
53016+
53017+ The blackhole feature as-implemented is equivalent to the FreeBSD
53018+ blackhole feature, as it prevents RST responses to all packets, not
53019+ just SYNs. Under most application behavior this causes no
53020+ problems, but applications (like haproxy) may not close certain
53021+ connections in a way that cleanly terminates them on the remote
53022+ end, leaving the remote host in LAST_ACK state. Because of this
53023+ side-effect and to prevent intentional LAST_ACK DoSes, this
53024+ feature also adds automatic mitigation against such attacks.
53025+ The mitigation drastically reduces the amount of time a socket
53026+ can spend in LAST_ACK state. If you're using haproxy and not
53027+ all servers it connects to have this option enabled, consider
53028+ disabling this feature on the haproxy host.
53029+
53030+ If the sysctl option is enabled, two sysctl options with names
53031+ "ip_blackhole" and "lastack_retries" will be created.
53032+ While "ip_blackhole" takes the standard zero/non-zero on/off
53033+ toggle, "lastack_retries" uses the same kinds of values as
53034+ "tcp_retries1" and "tcp_retries2". The default value of 4
53035+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53036+ state.
53037+
53038+config GRKERNSEC_NO_SIMULT_CONNECT
53039+ bool "Disable TCP Simultaneous Connect"
53040+ default y if GRKERNSEC_CONFIG_AUTO
53041+ depends on NET
53042+ help
53043+ If you say Y here, a feature by Willy Tarreau will be enabled that
53044+ removes a weakness in Linux's strict implementation of TCP that
53045+ allows two clients to connect to each other without either entering
53046+ a listening state. The weakness allows an attacker to easily prevent
53047+ a client from connecting to a known server provided the source port
53048+ for the connection is guessed correctly.
53049+
53050+ As the weakness could be used to prevent an antivirus or IPS from
53051+ fetching updates, or prevent an SSL gateway from fetching a CRL,
53052+ it should be eliminated by enabling this option. Though Linux is
53053+ one of few operating systems supporting simultaneous connect, it
53054+ has no legitimate use in practice and is rarely supported by firewalls.
53055+
53056+config GRKERNSEC_SOCKET
53057+ bool "Socket restrictions"
53058+ depends on NET
53059+ help
53060+ If you say Y here, you will be able to choose from several options.
53061+ If you assign a GID on your system and add it to the supplementary
53062+ groups of users you want to restrict socket access to, this patch
53063+ will perform up to three things, based on the option(s) you choose.
53064+
53065+config GRKERNSEC_SOCKET_ALL
53066+ bool "Deny any sockets to group"
53067+ depends on GRKERNSEC_SOCKET
53068+ help
53069+ If you say Y here, you will be able to choose a GID of whose users will
53070+ be unable to connect to other hosts from your machine or run server
53071+ applications from your machine. If the sysctl option is enabled, a
53072+ sysctl option with name "socket_all" is created.
53073+
53074+config GRKERNSEC_SOCKET_ALL_GID
53075+ int "GID to deny all sockets for"
53076+ depends on GRKERNSEC_SOCKET_ALL
53077+ default 1004
53078+ help
53079+ Here you can choose the GID to disable socket access for. Remember to
53080+ add the users you want socket access disabled for to the GID
53081+ specified here. If the sysctl option is enabled, a sysctl option
53082+ with name "socket_all_gid" is created.
53083+
53084+config GRKERNSEC_SOCKET_CLIENT
53085+ bool "Deny client sockets to group"
53086+ depends on GRKERNSEC_SOCKET
53087+ help
53088+ If you say Y here, you will be able to choose a GID of whose users will
53089+ be unable to connect to other hosts from your machine, but will be
53090+ able to run servers. If this option is enabled, all users in the group
53091+ you specify will have to use passive mode when initiating ftp transfers
53092+ from the shell on your machine. If the sysctl option is enabled, a
53093+ sysctl option with name "socket_client" is created.
53094+
53095+config GRKERNSEC_SOCKET_CLIENT_GID
53096+ int "GID to deny client sockets for"
53097+ depends on GRKERNSEC_SOCKET_CLIENT
53098+ default 1003
53099+ help
53100+ Here you can choose the GID to disable client socket access for.
53101+ Remember to add the users you want client socket access disabled for to
53102+ the GID specified here. If the sysctl option is enabled, a sysctl
53103+ option with name "socket_client_gid" is created.
53104+
53105+config GRKERNSEC_SOCKET_SERVER
53106+ bool "Deny server sockets to group"
53107+ depends on GRKERNSEC_SOCKET
53108+ help
53109+ If you say Y here, you will be able to choose a GID of whose users will
53110+ be unable to run server applications from your machine. If the sysctl
53111+ option is enabled, a sysctl option with name "socket_server" is created.
53112+
53113+config GRKERNSEC_SOCKET_SERVER_GID
53114+ int "GID to deny server sockets for"
53115+ depends on GRKERNSEC_SOCKET_SERVER
53116+ default 1002
53117+ help
53118+ Here you can choose the GID to disable server socket access for.
53119+ Remember to add the users you want server socket access disabled for to
53120+ the GID specified here. If the sysctl option is enabled, a sysctl
53121+ option with name "socket_server_gid" is created.
53122+
53123+endmenu
53124+menu "Sysctl Support"
53125+depends on GRKERNSEC && SYSCTL
53126+
53127+config GRKERNSEC_SYSCTL
53128+ bool "Sysctl support"
53129+ default y if GRKERNSEC_CONFIG_AUTO
53130+ help
53131+ If you say Y here, you will be able to change the options that
53132+ grsecurity runs with at bootup, without having to recompile your
53133+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53134+ to enable (1) or disable (0) various features. All the sysctl entries
53135+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53136+ All features enabled in the kernel configuration are disabled at boot
53137+ if you do not say Y to the "Turn on features by default" option.
53138+ All options should be set at startup, and the grsec_lock entry should
53139+ be set to a non-zero value after all the options are set.
53140+ *THIS IS EXTREMELY IMPORTANT*
53141+
53142+config GRKERNSEC_SYSCTL_DISTRO
53143+ bool "Extra sysctl support for distro makers (READ HELP)"
53144+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53145+ help
53146+ If you say Y here, additional sysctl options will be created
53147+ for features that affect processes running as root. Therefore,
53148+ it is critical when using this option that the grsec_lock entry be
53149+ enabled after boot. Only distros with prebuilt kernel packages
53150+ with this option enabled that can ensure grsec_lock is enabled
53151+ after boot should use this option.
53152+ *Failure to set grsec_lock after boot makes all grsec features
53153+ this option covers useless*
53154+
53155+ Currently this option creates the following sysctl entries:
53156+ "Disable Privileged I/O": "disable_priv_io"
53157+
53158+config GRKERNSEC_SYSCTL_ON
53159+ bool "Turn on features by default"
53160+ default y if GRKERNSEC_CONFIG_AUTO
53161+ depends on GRKERNSEC_SYSCTL
53162+ help
53163+ If you say Y here, instead of having all features enabled in the
53164+ kernel configuration disabled at boot time, the features will be
53165+ enabled at boot time. It is recommended you say Y here unless
53166+ there is some reason you would want all sysctl-tunable features to
53167+ be disabled by default. As mentioned elsewhere, it is important
53168+ to enable the grsec_lock entry once you have finished modifying
53169+ the sysctl entries.
53170+
53171+endmenu
53172+menu "Logging Options"
53173+depends on GRKERNSEC
53174+
53175+config GRKERNSEC_FLOODTIME
53176+ int "Seconds in between log messages (minimum)"
53177+ default 10
53178+ help
53179+ This option allows you to enforce the number of seconds between
53180+ grsecurity log messages. The default should be suitable for most
53181+ people, however, if you choose to change it, choose a value small enough
53182+ to allow informative logs to be produced, but large enough to
53183+ prevent flooding.
53184+
53185+config GRKERNSEC_FLOODBURST
53186+ int "Number of messages in a burst (maximum)"
53187+ default 6
53188+ help
53189+ This option allows you to choose the maximum number of messages allowed
53190+ within the flood time interval you chose in a separate option. The
53191+ default should be suitable for most people, however if you find that
53192+ many of your logs are being interpreted as flooding, you may want to
53193+ raise this value.
53194+
53195+endmenu
53196diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53197new file mode 100644
53198index 0000000..1b9afa9
53199--- /dev/null
53200+++ b/grsecurity/Makefile
53201@@ -0,0 +1,38 @@
53202+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53203+# during 2001-2009 it has been completely redesigned by Brad Spengler
53204+# into an RBAC system
53205+#
53206+# All code in this directory and various hooks inserted throughout the kernel
53207+# are copyright Brad Spengler - Open Source Security, Inc., and released
53208+# under the GPL v2 or higher
53209+
53210+KBUILD_CFLAGS += -Werror
53211+
53212+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53213+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53214+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53215+
53216+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53217+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53218+ gracl_learn.o grsec_log.o
53219+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53220+
53221+ifdef CONFIG_NET
53222+obj-y += grsec_sock.o
53223+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53224+endif
53225+
53226+ifndef CONFIG_GRKERNSEC
53227+obj-y += grsec_disabled.o
53228+endif
53229+
53230+ifdef CONFIG_GRKERNSEC_HIDESYM
53231+extra-y := grsec_hidesym.o
53232+$(obj)/grsec_hidesym.o:
53233+ @-chmod -f 500 /boot
53234+ @-chmod -f 500 /lib/modules
53235+ @-chmod -f 500 /lib64/modules
53236+ @-chmod -f 500 /lib32/modules
53237+ @-chmod -f 700 .
53238+ @echo ' grsec: protected kernel image paths'
53239+endif
53240diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53241new file mode 100644
53242index 0000000..960766a
53243--- /dev/null
53244+++ b/grsecurity/gracl.c
53245@@ -0,0 +1,4003 @@
53246+#include <linux/kernel.h>
53247+#include <linux/module.h>
53248+#include <linux/sched.h>
53249+#include <linux/mm.h>
53250+#include <linux/file.h>
53251+#include <linux/fs.h>
53252+#include <linux/namei.h>
53253+#include <linux/mount.h>
53254+#include <linux/tty.h>
53255+#include <linux/proc_fs.h>
53256+#include <linux/lglock.h>
53257+#include <linux/slab.h>
53258+#include <linux/vmalloc.h>
53259+#include <linux/types.h>
53260+#include <linux/sysctl.h>
53261+#include <linux/netdevice.h>
53262+#include <linux/ptrace.h>
53263+#include <linux/gracl.h>
53264+#include <linux/gralloc.h>
53265+#include <linux/security.h>
53266+#include <linux/grinternal.h>
53267+#include <linux/pid_namespace.h>
53268+#include <linux/stop_machine.h>
53269+#include <linux/fdtable.h>
53270+#include <linux/percpu.h>
53271+#include <linux/lglock.h>
53272+#include "../fs/mount.h"
53273+
53274+#include <asm/uaccess.h>
53275+#include <asm/errno.h>
53276+#include <asm/mman.h>
53277+
53278+extern struct lglock vfsmount_lock;
53279+
53280+static struct acl_role_db acl_role_set;
53281+static struct name_db name_set;
53282+static struct inodev_db inodev_set;
53283+
53284+/* for keeping track of userspace pointers used for subjects, so we
53285+ can share references in the kernel as well
53286+*/
53287+
53288+static struct path real_root;
53289+
53290+static struct acl_subj_map_db subj_map_set;
53291+
53292+static struct acl_role_label *default_role;
53293+
53294+static struct acl_role_label *role_list;
53295+
53296+static u16 acl_sp_role_value;
53297+
53298+extern char *gr_shared_page[4];
53299+static DEFINE_MUTEX(gr_dev_mutex);
53300+DEFINE_RWLOCK(gr_inode_lock);
53301+
53302+struct gr_arg *gr_usermode;
53303+
53304+static unsigned int gr_status __read_only = GR_STATUS_INIT;
53305+
53306+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53307+extern void gr_clear_learn_entries(void);
53308+
53309+unsigned char *gr_system_salt;
53310+unsigned char *gr_system_sum;
53311+
53312+static struct sprole_pw **acl_special_roles = NULL;
53313+static __u16 num_sprole_pws = 0;
53314+
53315+static struct acl_role_label *kernel_role = NULL;
53316+
53317+static unsigned int gr_auth_attempts = 0;
53318+static unsigned long gr_auth_expires = 0UL;
53319+
53320+#ifdef CONFIG_NET
53321+extern struct vfsmount *sock_mnt;
53322+#endif
53323+
53324+extern struct vfsmount *pipe_mnt;
53325+extern struct vfsmount *shm_mnt;
53326+#ifdef CONFIG_HUGETLBFS
53327+extern struct vfsmount *hugetlbfs_vfsmount;
53328+#endif
53329+
53330+static struct acl_object_label *fakefs_obj_rw;
53331+static struct acl_object_label *fakefs_obj_rwx;
53332+
53333+extern int gr_init_uidset(void);
53334+extern void gr_free_uidset(void);
53335+extern void gr_remove_uid(uid_t uid);
53336+extern int gr_find_uid(uid_t uid);
53337+
53338+__inline__ int
53339+gr_acl_is_enabled(void)
53340+{
53341+ return (gr_status & GR_READY);
53342+}
53343+
53344+#ifdef CONFIG_BTRFS_FS
53345+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53346+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53347+#endif
53348+
53349+static inline dev_t __get_dev(const struct dentry *dentry)
53350+{
53351+#ifdef CONFIG_BTRFS_FS
53352+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53353+ return get_btrfs_dev_from_inode(dentry->d_inode);
53354+ else
53355+#endif
53356+ return dentry->d_inode->i_sb->s_dev;
53357+}
53358+
53359+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53360+{
53361+ return __get_dev(dentry);
53362+}
53363+
53364+static char gr_task_roletype_to_char(struct task_struct *task)
53365+{
53366+ switch (task->role->roletype &
53367+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53368+ GR_ROLE_SPECIAL)) {
53369+ case GR_ROLE_DEFAULT:
53370+ return 'D';
53371+ case GR_ROLE_USER:
53372+ return 'U';
53373+ case GR_ROLE_GROUP:
53374+ return 'G';
53375+ case GR_ROLE_SPECIAL:
53376+ return 'S';
53377+ }
53378+
53379+ return 'X';
53380+}
53381+
53382+char gr_roletype_to_char(void)
53383+{
53384+ return gr_task_roletype_to_char(current);
53385+}
53386+
53387+__inline__ int
53388+gr_acl_tpe_check(void)
53389+{
53390+ if (unlikely(!(gr_status & GR_READY)))
53391+ return 0;
53392+ if (current->role->roletype & GR_ROLE_TPE)
53393+ return 1;
53394+ else
53395+ return 0;
53396+}
53397+
53398+int
53399+gr_handle_rawio(const struct inode *inode)
53400+{
53401+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53402+ if (inode && S_ISBLK(inode->i_mode) &&
53403+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53404+ !capable(CAP_SYS_RAWIO))
53405+ return 1;
53406+#endif
53407+ return 0;
53408+}
53409+
53410+static int
53411+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53412+{
53413+ if (likely(lena != lenb))
53414+ return 0;
53415+
53416+ return !memcmp(a, b, lena);
53417+}
53418+
53419+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53420+{
53421+ *buflen -= namelen;
53422+ if (*buflen < 0)
53423+ return -ENAMETOOLONG;
53424+ *buffer -= namelen;
53425+ memcpy(*buffer, str, namelen);
53426+ return 0;
53427+}
53428+
53429+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53430+{
53431+ return prepend(buffer, buflen, name->name, name->len);
53432+}
53433+
53434+static int prepend_path(const struct path *path, struct path *root,
53435+ char **buffer, int *buflen)
53436+{
53437+ struct dentry *dentry = path->dentry;
53438+ struct vfsmount *vfsmnt = path->mnt;
53439+ struct mount *mnt = real_mount(vfsmnt);
53440+ bool slash = false;
53441+ int error = 0;
53442+
53443+ while (dentry != root->dentry || vfsmnt != root->mnt) {
53444+ struct dentry * parent;
53445+
53446+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53447+ /* Global root? */
53448+ if (!mnt_has_parent(mnt)) {
53449+ goto out;
53450+ }
53451+ dentry = mnt->mnt_mountpoint;
53452+ mnt = mnt->mnt_parent;
53453+ vfsmnt = &mnt->mnt;
53454+ continue;
53455+ }
53456+ parent = dentry->d_parent;
53457+ prefetch(parent);
53458+ spin_lock(&dentry->d_lock);
53459+ error = prepend_name(buffer, buflen, &dentry->d_name);
53460+ spin_unlock(&dentry->d_lock);
53461+ if (!error)
53462+ error = prepend(buffer, buflen, "/", 1);
53463+ if (error)
53464+ break;
53465+
53466+ slash = true;
53467+ dentry = parent;
53468+ }
53469+
53470+out:
53471+ if (!error && !slash)
53472+ error = prepend(buffer, buflen, "/", 1);
53473+
53474+ return error;
53475+}
53476+
53477+/* this must be called with vfsmount_lock and rename_lock held */
53478+
53479+static char *__our_d_path(const struct path *path, struct path *root,
53480+ char *buf, int buflen)
53481+{
53482+ char *res = buf + buflen;
53483+ int error;
53484+
53485+ prepend(&res, &buflen, "\0", 1);
53486+ error = prepend_path(path, root, &res, &buflen);
53487+ if (error)
53488+ return ERR_PTR(error);
53489+
53490+ return res;
53491+}
53492+
53493+static char *
53494+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53495+{
53496+ char *retval;
53497+
53498+ retval = __our_d_path(path, root, buf, buflen);
53499+ if (unlikely(IS_ERR(retval)))
53500+ retval = strcpy(buf, "<path too long>");
53501+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53502+ retval[1] = '\0';
53503+
53504+ return retval;
53505+}
53506+
53507+static char *
53508+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53509+ char *buf, int buflen)
53510+{
53511+ struct path path;
53512+ char *res;
53513+
53514+ path.dentry = (struct dentry *)dentry;
53515+ path.mnt = (struct vfsmount *)vfsmnt;
53516+
53517+ /* we can use real_root.dentry, real_root.mnt, because this is only called
53518+ by the RBAC system */
53519+ res = gen_full_path(&path, &real_root, buf, buflen);
53520+
53521+ return res;
53522+}
53523+
53524+static char *
53525+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53526+ char *buf, int buflen)
53527+{
53528+ char *res;
53529+ struct path path;
53530+ struct path root;
53531+ struct task_struct *reaper = init_pid_ns.child_reaper;
53532+
53533+ path.dentry = (struct dentry *)dentry;
53534+ path.mnt = (struct vfsmount *)vfsmnt;
53535+
53536+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53537+ get_fs_root(reaper->fs, &root);
53538+
53539+ write_seqlock(&rename_lock);
53540+ br_read_lock(&vfsmount_lock);
53541+ res = gen_full_path(&path, &root, buf, buflen);
53542+ br_read_unlock(&vfsmount_lock);
53543+ write_sequnlock(&rename_lock);
53544+
53545+ path_put(&root);
53546+ return res;
53547+}
53548+
53549+static char *
53550+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53551+{
53552+ char *ret;
53553+ write_seqlock(&rename_lock);
53554+ br_read_lock(&vfsmount_lock);
53555+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53556+ PAGE_SIZE);
53557+ br_read_unlock(&vfsmount_lock);
53558+ write_sequnlock(&rename_lock);
53559+ return ret;
53560+}
53561+
53562+static char *
53563+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53564+{
53565+ char *ret;
53566+ char *buf;
53567+ int buflen;
53568+
53569+ write_seqlock(&rename_lock);
53570+ br_read_lock(&vfsmount_lock);
53571+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53572+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53573+ buflen = (int)(ret - buf);
53574+ if (buflen >= 5)
53575+ prepend(&ret, &buflen, "/proc", 5);
53576+ else
53577+ ret = strcpy(buf, "<path too long>");
53578+ br_read_unlock(&vfsmount_lock);
53579+ write_sequnlock(&rename_lock);
53580+ return ret;
53581+}
53582+
53583+char *
53584+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53585+{
53586+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53587+ PAGE_SIZE);
53588+}
53589+
53590+char *
53591+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53592+{
53593+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53594+ PAGE_SIZE);
53595+}
53596+
53597+char *
53598+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53599+{
53600+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53601+ PAGE_SIZE);
53602+}
53603+
53604+char *
53605+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53606+{
53607+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53608+ PAGE_SIZE);
53609+}
53610+
53611+char *
53612+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53613+{
53614+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53615+ PAGE_SIZE);
53616+}
53617+
53618+__inline__ __u32
53619+to_gr_audit(const __u32 reqmode)
53620+{
53621+ /* masks off auditable permission flags, then shifts them to create
53622+ auditing flags, and adds the special case of append auditing if
53623+ we're requesting write */
53624+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53625+}
53626+
53627+struct acl_subject_label *
53628+lookup_subject_map(const struct acl_subject_label *userp)
53629+{
53630+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
53631+ struct subject_map *match;
53632+
53633+ match = subj_map_set.s_hash[index];
53634+
53635+ while (match && match->user != userp)
53636+ match = match->next;
53637+
53638+ if (match != NULL)
53639+ return match->kernel;
53640+ else
53641+ return NULL;
53642+}
53643+
53644+static void
53645+insert_subj_map_entry(struct subject_map *subjmap)
53646+{
53647+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53648+ struct subject_map **curr;
53649+
53650+ subjmap->prev = NULL;
53651+
53652+ curr = &subj_map_set.s_hash[index];
53653+ if (*curr != NULL)
53654+ (*curr)->prev = subjmap;
53655+
53656+ subjmap->next = *curr;
53657+ *curr = subjmap;
53658+
53659+ return;
53660+}
53661+
53662+static struct acl_role_label *
53663+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53664+ const gid_t gid)
53665+{
53666+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53667+ struct acl_role_label *match;
53668+ struct role_allowed_ip *ipp;
53669+ unsigned int x;
53670+ u32 curr_ip = task->signal->curr_ip;
53671+
53672+ task->signal->saved_ip = curr_ip;
53673+
53674+ match = acl_role_set.r_hash[index];
53675+
53676+ while (match) {
53677+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53678+ for (x = 0; x < match->domain_child_num; x++) {
53679+ if (match->domain_children[x] == uid)
53680+ goto found;
53681+ }
53682+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53683+ break;
53684+ match = match->next;
53685+ }
53686+found:
53687+ if (match == NULL) {
53688+ try_group:
53689+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53690+ match = acl_role_set.r_hash[index];
53691+
53692+ while (match) {
53693+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53694+ for (x = 0; x < match->domain_child_num; x++) {
53695+ if (match->domain_children[x] == gid)
53696+ goto found2;
53697+ }
53698+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53699+ break;
53700+ match = match->next;
53701+ }
53702+found2:
53703+ if (match == NULL)
53704+ match = default_role;
53705+ if (match->allowed_ips == NULL)
53706+ return match;
53707+ else {
53708+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53709+ if (likely
53710+ ((ntohl(curr_ip) & ipp->netmask) ==
53711+ (ntohl(ipp->addr) & ipp->netmask)))
53712+ return match;
53713+ }
53714+ match = default_role;
53715+ }
53716+ } else if (match->allowed_ips == NULL) {
53717+ return match;
53718+ } else {
53719+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53720+ if (likely
53721+ ((ntohl(curr_ip) & ipp->netmask) ==
53722+ (ntohl(ipp->addr) & ipp->netmask)))
53723+ return match;
53724+ }
53725+ goto try_group;
53726+ }
53727+
53728+ return match;
53729+}
53730+
53731+struct acl_subject_label *
53732+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53733+ const struct acl_role_label *role)
53734+{
53735+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53736+ struct acl_subject_label *match;
53737+
53738+ match = role->subj_hash[index];
53739+
53740+ while (match && (match->inode != ino || match->device != dev ||
53741+ (match->mode & GR_DELETED))) {
53742+ match = match->next;
53743+ }
53744+
53745+ if (match && !(match->mode & GR_DELETED))
53746+ return match;
53747+ else
53748+ return NULL;
53749+}
53750+
53751+struct acl_subject_label *
53752+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53753+ const struct acl_role_label *role)
53754+{
53755+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53756+ struct acl_subject_label *match;
53757+
53758+ match = role->subj_hash[index];
53759+
53760+ while (match && (match->inode != ino || match->device != dev ||
53761+ !(match->mode & GR_DELETED))) {
53762+ match = match->next;
53763+ }
53764+
53765+ if (match && (match->mode & GR_DELETED))
53766+ return match;
53767+ else
53768+ return NULL;
53769+}
53770+
53771+static struct acl_object_label *
53772+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53773+ const struct acl_subject_label *subj)
53774+{
53775+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53776+ struct acl_object_label *match;
53777+
53778+ match = subj->obj_hash[index];
53779+
53780+ while (match && (match->inode != ino || match->device != dev ||
53781+ (match->mode & GR_DELETED))) {
53782+ match = match->next;
53783+ }
53784+
53785+ if (match && !(match->mode & GR_DELETED))
53786+ return match;
53787+ else
53788+ return NULL;
53789+}
53790+
53791+static struct acl_object_label *
53792+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
53793+ const struct acl_subject_label *subj)
53794+{
53795+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53796+ struct acl_object_label *match;
53797+
53798+ match = subj->obj_hash[index];
53799+
53800+ while (match && (match->inode != ino || match->device != dev ||
53801+ !(match->mode & GR_DELETED))) {
53802+ match = match->next;
53803+ }
53804+
53805+ if (match && (match->mode & GR_DELETED))
53806+ return match;
53807+
53808+ match = subj->obj_hash[index];
53809+
53810+ while (match && (match->inode != ino || match->device != dev ||
53811+ (match->mode & GR_DELETED))) {
53812+ match = match->next;
53813+ }
53814+
53815+ if (match && !(match->mode & GR_DELETED))
53816+ return match;
53817+ else
53818+ return NULL;
53819+}
53820+
53821+static struct name_entry *
53822+lookup_name_entry(const char *name)
53823+{
53824+ unsigned int len = strlen(name);
53825+ unsigned int key = full_name_hash(name, len);
53826+ unsigned int index = key % name_set.n_size;
53827+ struct name_entry *match;
53828+
53829+ match = name_set.n_hash[index];
53830+
53831+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
53832+ match = match->next;
53833+
53834+ return match;
53835+}
53836+
53837+static struct name_entry *
53838+lookup_name_entry_create(const char *name)
53839+{
53840+ unsigned int len = strlen(name);
53841+ unsigned int key = full_name_hash(name, len);
53842+ unsigned int index = key % name_set.n_size;
53843+ struct name_entry *match;
53844+
53845+ match = name_set.n_hash[index];
53846+
53847+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53848+ !match->deleted))
53849+ match = match->next;
53850+
53851+ if (match && match->deleted)
53852+ return match;
53853+
53854+ match = name_set.n_hash[index];
53855+
53856+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53857+ match->deleted))
53858+ match = match->next;
53859+
53860+ if (match && !match->deleted)
53861+ return match;
53862+ else
53863+ return NULL;
53864+}
53865+
53866+static struct inodev_entry *
53867+lookup_inodev_entry(const ino_t ino, const dev_t dev)
53868+{
53869+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
53870+ struct inodev_entry *match;
53871+
53872+ match = inodev_set.i_hash[index];
53873+
53874+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
53875+ match = match->next;
53876+
53877+ return match;
53878+}
53879+
53880+static void
53881+insert_inodev_entry(struct inodev_entry *entry)
53882+{
53883+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
53884+ inodev_set.i_size);
53885+ struct inodev_entry **curr;
53886+
53887+ entry->prev = NULL;
53888+
53889+ curr = &inodev_set.i_hash[index];
53890+ if (*curr != NULL)
53891+ (*curr)->prev = entry;
53892+
53893+ entry->next = *curr;
53894+ *curr = entry;
53895+
53896+ return;
53897+}
53898+
53899+static void
53900+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
53901+{
53902+ unsigned int index =
53903+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
53904+ struct acl_role_label **curr;
53905+ struct acl_role_label *tmp, *tmp2;
53906+
53907+ curr = &acl_role_set.r_hash[index];
53908+
53909+ /* simple case, slot is empty, just set it to our role */
53910+ if (*curr == NULL) {
53911+ *curr = role;
53912+ } else {
53913+ /* example:
53914+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
53915+ 2 -> 3
53916+ */
53917+ /* first check to see if we can already be reached via this slot */
53918+ tmp = *curr;
53919+ while (tmp && tmp != role)
53920+ tmp = tmp->next;
53921+ if (tmp == role) {
53922+ /* we don't need to add ourselves to this slot's chain */
53923+ return;
53924+ }
53925+ /* we need to add ourselves to this chain, two cases */
53926+ if (role->next == NULL) {
53927+ /* simple case, append the current chain to our role */
53928+ role->next = *curr;
53929+ *curr = role;
53930+ } else {
53931+ /* 1 -> 2 -> 3 -> 4
53932+ 2 -> 3 -> 4
53933+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
53934+ */
53935+ /* trickier case: walk our role's chain until we find
53936+ the role for the start of the current slot's chain */
53937+ tmp = role;
53938+ tmp2 = *curr;
53939+ while (tmp->next && tmp->next != tmp2)
53940+ tmp = tmp->next;
53941+ if (tmp->next == tmp2) {
53942+ /* from example above, we found 3, so just
53943+ replace this slot's chain with ours */
53944+ *curr = role;
53945+ } else {
53946+ /* we didn't find a subset of our role's chain
53947+ in the current slot's chain, so append their
53948+ chain to ours, and set us as the first role in
53949+ the slot's chain
53950+
53951+ we could fold this case with the case above,
53952+ but making it explicit for clarity
53953+ */
53954+ tmp->next = tmp2;
53955+ *curr = role;
53956+ }
53957+ }
53958+ }
53959+
53960+ return;
53961+}
53962+
53963+static void
53964+insert_acl_role_label(struct acl_role_label *role)
53965+{
53966+ int i;
53967+
53968+ if (role_list == NULL) {
53969+ role_list = role;
53970+ role->prev = NULL;
53971+ } else {
53972+ role->prev = role_list;
53973+ role_list = role;
53974+ }
53975+
53976+ /* used for hash chains */
53977+ role->next = NULL;
53978+
53979+ if (role->roletype & GR_ROLE_DOMAIN) {
53980+ for (i = 0; i < role->domain_child_num; i++)
53981+ __insert_acl_role_label(role, role->domain_children[i]);
53982+ } else
53983+ __insert_acl_role_label(role, role->uidgid);
53984+}
53985+
53986+static int
53987+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
53988+{
53989+ struct name_entry **curr, *nentry;
53990+ struct inodev_entry *ientry;
53991+ unsigned int len = strlen(name);
53992+ unsigned int key = full_name_hash(name, len);
53993+ unsigned int index = key % name_set.n_size;
53994+
53995+ curr = &name_set.n_hash[index];
53996+
53997+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
53998+ curr = &((*curr)->next);
53999+
54000+ if (*curr != NULL)
54001+ return 1;
54002+
54003+ nentry = acl_alloc(sizeof (struct name_entry));
54004+ if (nentry == NULL)
54005+ return 0;
54006+ ientry = acl_alloc(sizeof (struct inodev_entry));
54007+ if (ientry == NULL)
54008+ return 0;
54009+ ientry->nentry = nentry;
54010+
54011+ nentry->key = key;
54012+ nentry->name = name;
54013+ nentry->inode = inode;
54014+ nentry->device = device;
54015+ nentry->len = len;
54016+ nentry->deleted = deleted;
54017+
54018+ nentry->prev = NULL;
54019+ curr = &name_set.n_hash[index];
54020+ if (*curr != NULL)
54021+ (*curr)->prev = nentry;
54022+ nentry->next = *curr;
54023+ *curr = nentry;
54024+
54025+ /* insert us into the table searchable by inode/dev */
54026+ insert_inodev_entry(ientry);
54027+
54028+ return 1;
54029+}
54030+
54031+static void
54032+insert_acl_obj_label(struct acl_object_label *obj,
54033+ struct acl_subject_label *subj)
54034+{
54035+ unsigned int index =
54036+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54037+ struct acl_object_label **curr;
54038+
54039+
54040+ obj->prev = NULL;
54041+
54042+ curr = &subj->obj_hash[index];
54043+ if (*curr != NULL)
54044+ (*curr)->prev = obj;
54045+
54046+ obj->next = *curr;
54047+ *curr = obj;
54048+
54049+ return;
54050+}
54051+
54052+static void
54053+insert_acl_subj_label(struct acl_subject_label *obj,
54054+ struct acl_role_label *role)
54055+{
54056+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54057+ struct acl_subject_label **curr;
54058+
54059+ obj->prev = NULL;
54060+
54061+ curr = &role->subj_hash[index];
54062+ if (*curr != NULL)
54063+ (*curr)->prev = obj;
54064+
54065+ obj->next = *curr;
54066+ *curr = obj;
54067+
54068+ return;
54069+}
54070+
54071+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54072+
54073+static void *
54074+create_table(__u32 * len, int elementsize)
54075+{
54076+ unsigned int table_sizes[] = {
54077+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54078+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54079+ 4194301, 8388593, 16777213, 33554393, 67108859
54080+ };
54081+ void *newtable = NULL;
54082+ unsigned int pwr = 0;
54083+
54084+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54085+ table_sizes[pwr] <= *len)
54086+ pwr++;
54087+
54088+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54089+ return newtable;
54090+
54091+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54092+ newtable =
54093+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54094+ else
54095+ newtable = vmalloc(table_sizes[pwr] * elementsize);
54096+
54097+ *len = table_sizes[pwr];
54098+
54099+ return newtable;
54100+}
54101+
54102+static int
54103+init_variables(const struct gr_arg *arg)
54104+{
54105+ struct task_struct *reaper = init_pid_ns.child_reaper;
54106+ unsigned int stacksize;
54107+
54108+ subj_map_set.s_size = arg->role_db.num_subjects;
54109+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54110+ name_set.n_size = arg->role_db.num_objects;
54111+ inodev_set.i_size = arg->role_db.num_objects;
54112+
54113+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
54114+ !name_set.n_size || !inodev_set.i_size)
54115+ return 1;
54116+
54117+ if (!gr_init_uidset())
54118+ return 1;
54119+
54120+ /* set up the stack that holds allocation info */
54121+
54122+ stacksize = arg->role_db.num_pointers + 5;
54123+
54124+ if (!acl_alloc_stack_init(stacksize))
54125+ return 1;
54126+
54127+ /* grab reference for the real root dentry and vfsmount */
54128+ get_fs_root(reaper->fs, &real_root);
54129+
54130+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54131+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54132+#endif
54133+
54134+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54135+ if (fakefs_obj_rw == NULL)
54136+ return 1;
54137+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54138+
54139+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54140+ if (fakefs_obj_rwx == NULL)
54141+ return 1;
54142+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54143+
54144+ subj_map_set.s_hash =
54145+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54146+ acl_role_set.r_hash =
54147+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54148+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54149+ inodev_set.i_hash =
54150+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54151+
54152+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54153+ !name_set.n_hash || !inodev_set.i_hash)
54154+ return 1;
54155+
54156+ memset(subj_map_set.s_hash, 0,
54157+ sizeof(struct subject_map *) * subj_map_set.s_size);
54158+ memset(acl_role_set.r_hash, 0,
54159+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
54160+ memset(name_set.n_hash, 0,
54161+ sizeof (struct name_entry *) * name_set.n_size);
54162+ memset(inodev_set.i_hash, 0,
54163+ sizeof (struct inodev_entry *) * inodev_set.i_size);
54164+
54165+ return 0;
54166+}
54167+
54168+/* free information not needed after startup
54169+ currently contains user->kernel pointer mappings for subjects
54170+*/
54171+
54172+static void
54173+free_init_variables(void)
54174+{
54175+ __u32 i;
54176+
54177+ if (subj_map_set.s_hash) {
54178+ for (i = 0; i < subj_map_set.s_size; i++) {
54179+ if (subj_map_set.s_hash[i]) {
54180+ kfree(subj_map_set.s_hash[i]);
54181+ subj_map_set.s_hash[i] = NULL;
54182+ }
54183+ }
54184+
54185+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54186+ PAGE_SIZE)
54187+ kfree(subj_map_set.s_hash);
54188+ else
54189+ vfree(subj_map_set.s_hash);
54190+ }
54191+
54192+ return;
54193+}
54194+
54195+static void
54196+free_variables(void)
54197+{
54198+ struct acl_subject_label *s;
54199+ struct acl_role_label *r;
54200+ struct task_struct *task, *task2;
54201+ unsigned int x;
54202+
54203+ gr_clear_learn_entries();
54204+
54205+ read_lock(&tasklist_lock);
54206+ do_each_thread(task2, task) {
54207+ task->acl_sp_role = 0;
54208+ task->acl_role_id = 0;
54209+ task->acl = NULL;
54210+ task->role = NULL;
54211+ } while_each_thread(task2, task);
54212+ read_unlock(&tasklist_lock);
54213+
54214+ /* release the reference to the real root dentry and vfsmount */
54215+ path_put(&real_root);
54216+ memset(&real_root, 0, sizeof(real_root));
54217+
54218+ /* free all object hash tables */
54219+
54220+ FOR_EACH_ROLE_START(r)
54221+ if (r->subj_hash == NULL)
54222+ goto next_role;
54223+ FOR_EACH_SUBJECT_START(r, s, x)
54224+ if (s->obj_hash == NULL)
54225+ break;
54226+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54227+ kfree(s->obj_hash);
54228+ else
54229+ vfree(s->obj_hash);
54230+ FOR_EACH_SUBJECT_END(s, x)
54231+ FOR_EACH_NESTED_SUBJECT_START(r, s)
54232+ if (s->obj_hash == NULL)
54233+ break;
54234+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54235+ kfree(s->obj_hash);
54236+ else
54237+ vfree(s->obj_hash);
54238+ FOR_EACH_NESTED_SUBJECT_END(s)
54239+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54240+ kfree(r->subj_hash);
54241+ else
54242+ vfree(r->subj_hash);
54243+ r->subj_hash = NULL;
54244+next_role:
54245+ FOR_EACH_ROLE_END(r)
54246+
54247+ acl_free_all();
54248+
54249+ if (acl_role_set.r_hash) {
54250+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54251+ PAGE_SIZE)
54252+ kfree(acl_role_set.r_hash);
54253+ else
54254+ vfree(acl_role_set.r_hash);
54255+ }
54256+ if (name_set.n_hash) {
54257+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
54258+ PAGE_SIZE)
54259+ kfree(name_set.n_hash);
54260+ else
54261+ vfree(name_set.n_hash);
54262+ }
54263+
54264+ if (inodev_set.i_hash) {
54265+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54266+ PAGE_SIZE)
54267+ kfree(inodev_set.i_hash);
54268+ else
54269+ vfree(inodev_set.i_hash);
54270+ }
54271+
54272+ gr_free_uidset();
54273+
54274+ memset(&name_set, 0, sizeof (struct name_db));
54275+ memset(&inodev_set, 0, sizeof (struct inodev_db));
54276+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54277+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54278+
54279+ default_role = NULL;
54280+ kernel_role = NULL;
54281+ role_list = NULL;
54282+
54283+ return;
54284+}
54285+
54286+static __u32
54287+count_user_objs(struct acl_object_label *userp)
54288+{
54289+ struct acl_object_label o_tmp;
54290+ __u32 num = 0;
54291+
54292+ while (userp) {
54293+ if (copy_from_user(&o_tmp, userp,
54294+ sizeof (struct acl_object_label)))
54295+ break;
54296+
54297+ userp = o_tmp.prev;
54298+ num++;
54299+ }
54300+
54301+ return num;
54302+}
54303+
54304+static struct acl_subject_label *
54305+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54306+
54307+static int
54308+copy_user_glob(struct acl_object_label *obj)
54309+{
54310+ struct acl_object_label *g_tmp, **guser;
54311+ unsigned int len;
54312+ char *tmp;
54313+
54314+ if (obj->globbed == NULL)
54315+ return 0;
54316+
54317+ guser = &obj->globbed;
54318+ while (*guser) {
54319+ g_tmp = (struct acl_object_label *)
54320+ acl_alloc(sizeof (struct acl_object_label));
54321+ if (g_tmp == NULL)
54322+ return -ENOMEM;
54323+
54324+ if (copy_from_user(g_tmp, *guser,
54325+ sizeof (struct acl_object_label)))
54326+ return -EFAULT;
54327+
54328+ len = strnlen_user(g_tmp->filename, PATH_MAX);
54329+
54330+ if (!len || len >= PATH_MAX)
54331+ return -EINVAL;
54332+
54333+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54334+ return -ENOMEM;
54335+
54336+ if (copy_from_user(tmp, g_tmp->filename, len))
54337+ return -EFAULT;
54338+ tmp[len-1] = '\0';
54339+ g_tmp->filename = tmp;
54340+
54341+ *guser = g_tmp;
54342+ guser = &(g_tmp->next);
54343+ }
54344+
54345+ return 0;
54346+}
54347+
54348+static int
54349+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54350+ struct acl_role_label *role)
54351+{
54352+ struct acl_object_label *o_tmp;
54353+ unsigned int len;
54354+ int ret;
54355+ char *tmp;
54356+
54357+ while (userp) {
54358+ if ((o_tmp = (struct acl_object_label *)
54359+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
54360+ return -ENOMEM;
54361+
54362+ if (copy_from_user(o_tmp, userp,
54363+ sizeof (struct acl_object_label)))
54364+ return -EFAULT;
54365+
54366+ userp = o_tmp->prev;
54367+
54368+ len = strnlen_user(o_tmp->filename, PATH_MAX);
54369+
54370+ if (!len || len >= PATH_MAX)
54371+ return -EINVAL;
54372+
54373+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54374+ return -ENOMEM;
54375+
54376+ if (copy_from_user(tmp, o_tmp->filename, len))
54377+ return -EFAULT;
54378+ tmp[len-1] = '\0';
54379+ o_tmp->filename = tmp;
54380+
54381+ insert_acl_obj_label(o_tmp, subj);
54382+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54383+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54384+ return -ENOMEM;
54385+
54386+ ret = copy_user_glob(o_tmp);
54387+ if (ret)
54388+ return ret;
54389+
54390+ if (o_tmp->nested) {
54391+ int already_copied;
54392+
54393+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54394+ if (IS_ERR(o_tmp->nested))
54395+ return PTR_ERR(o_tmp->nested);
54396+
54397+ /* insert into nested subject list if we haven't copied this one yet
54398+ to prevent duplicate entries */
54399+ if (!already_copied) {
54400+ o_tmp->nested->next = role->hash->first;
54401+ role->hash->first = o_tmp->nested;
54402+ }
54403+ }
54404+ }
54405+
54406+ return 0;
54407+}
54408+
54409+static __u32
54410+count_user_subjs(struct acl_subject_label *userp)
54411+{
54412+ struct acl_subject_label s_tmp;
54413+ __u32 num = 0;
54414+
54415+ while (userp) {
54416+ if (copy_from_user(&s_tmp, userp,
54417+ sizeof (struct acl_subject_label)))
54418+ break;
54419+
54420+ userp = s_tmp.prev;
54421+ }
54422+
54423+ return num;
54424+}
54425+
54426+static int
54427+copy_user_allowedips(struct acl_role_label *rolep)
54428+{
54429+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54430+
54431+ ruserip = rolep->allowed_ips;
54432+
54433+ while (ruserip) {
54434+ rlast = rtmp;
54435+
54436+ if ((rtmp = (struct role_allowed_ip *)
54437+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54438+ return -ENOMEM;
54439+
54440+ if (copy_from_user(rtmp, ruserip,
54441+ sizeof (struct role_allowed_ip)))
54442+ return -EFAULT;
54443+
54444+ ruserip = rtmp->prev;
54445+
54446+ if (!rlast) {
54447+ rtmp->prev = NULL;
54448+ rolep->allowed_ips = rtmp;
54449+ } else {
54450+ rlast->next = rtmp;
54451+ rtmp->prev = rlast;
54452+ }
54453+
54454+ if (!ruserip)
54455+ rtmp->next = NULL;
54456+ }
54457+
54458+ return 0;
54459+}
54460+
54461+static int
54462+copy_user_transitions(struct acl_role_label *rolep)
54463+{
54464+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
54465+
54466+ unsigned int len;
54467+ char *tmp;
54468+
54469+ rusertp = rolep->transitions;
54470+
54471+ while (rusertp) {
54472+ rlast = rtmp;
54473+
54474+ if ((rtmp = (struct role_transition *)
54475+ acl_alloc(sizeof (struct role_transition))) == NULL)
54476+ return -ENOMEM;
54477+
54478+ if (copy_from_user(rtmp, rusertp,
54479+ sizeof (struct role_transition)))
54480+ return -EFAULT;
54481+
54482+ rusertp = rtmp->prev;
54483+
54484+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54485+
54486+ if (!len || len >= GR_SPROLE_LEN)
54487+ return -EINVAL;
54488+
54489+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54490+ return -ENOMEM;
54491+
54492+ if (copy_from_user(tmp, rtmp->rolename, len))
54493+ return -EFAULT;
54494+ tmp[len-1] = '\0';
54495+ rtmp->rolename = tmp;
54496+
54497+ if (!rlast) {
54498+ rtmp->prev = NULL;
54499+ rolep->transitions = rtmp;
54500+ } else {
54501+ rlast->next = rtmp;
54502+ rtmp->prev = rlast;
54503+ }
54504+
54505+ if (!rusertp)
54506+ rtmp->next = NULL;
54507+ }
54508+
54509+ return 0;
54510+}
54511+
54512+static struct acl_subject_label *
54513+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54514+{
54515+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54516+ unsigned int len;
54517+ char *tmp;
54518+ __u32 num_objs;
54519+ struct acl_ip_label **i_tmp, *i_utmp2;
54520+ struct gr_hash_struct ghash;
54521+ struct subject_map *subjmap;
54522+ unsigned int i_num;
54523+ int err;
54524+
54525+ if (already_copied != NULL)
54526+ *already_copied = 0;
54527+
54528+ s_tmp = lookup_subject_map(userp);
54529+
54530+ /* we've already copied this subject into the kernel, just return
54531+ the reference to it, and don't copy it over again
54532+ */
54533+ if (s_tmp) {
54534+ if (already_copied != NULL)
54535+ *already_copied = 1;
54536+ return(s_tmp);
54537+ }
54538+
54539+ if ((s_tmp = (struct acl_subject_label *)
54540+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54541+ return ERR_PTR(-ENOMEM);
54542+
54543+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54544+ if (subjmap == NULL)
54545+ return ERR_PTR(-ENOMEM);
54546+
54547+ subjmap->user = userp;
54548+ subjmap->kernel = s_tmp;
54549+ insert_subj_map_entry(subjmap);
54550+
54551+ if (copy_from_user(s_tmp, userp,
54552+ sizeof (struct acl_subject_label)))
54553+ return ERR_PTR(-EFAULT);
54554+
54555+ len = strnlen_user(s_tmp->filename, PATH_MAX);
54556+
54557+ if (!len || len >= PATH_MAX)
54558+ return ERR_PTR(-EINVAL);
54559+
54560+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54561+ return ERR_PTR(-ENOMEM);
54562+
54563+ if (copy_from_user(tmp, s_tmp->filename, len))
54564+ return ERR_PTR(-EFAULT);
54565+ tmp[len-1] = '\0';
54566+ s_tmp->filename = tmp;
54567+
54568+ if (!strcmp(s_tmp->filename, "/"))
54569+ role->root_label = s_tmp;
54570+
54571+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54572+ return ERR_PTR(-EFAULT);
54573+
54574+ /* copy user and group transition tables */
54575+
54576+ if (s_tmp->user_trans_num) {
54577+ uid_t *uidlist;
54578+
54579+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54580+ if (uidlist == NULL)
54581+ return ERR_PTR(-ENOMEM);
54582+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54583+ return ERR_PTR(-EFAULT);
54584+
54585+ s_tmp->user_transitions = uidlist;
54586+ }
54587+
54588+ if (s_tmp->group_trans_num) {
54589+ gid_t *gidlist;
54590+
54591+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54592+ if (gidlist == NULL)
54593+ return ERR_PTR(-ENOMEM);
54594+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54595+ return ERR_PTR(-EFAULT);
54596+
54597+ s_tmp->group_transitions = gidlist;
54598+ }
54599+
54600+ /* set up object hash table */
54601+ num_objs = count_user_objs(ghash.first);
54602+
54603+ s_tmp->obj_hash_size = num_objs;
54604+ s_tmp->obj_hash =
54605+ (struct acl_object_label **)
54606+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54607+
54608+ if (!s_tmp->obj_hash)
54609+ return ERR_PTR(-ENOMEM);
54610+
54611+ memset(s_tmp->obj_hash, 0,
54612+ s_tmp->obj_hash_size *
54613+ sizeof (struct acl_object_label *));
54614+
54615+ /* add in objects */
54616+ err = copy_user_objs(ghash.first, s_tmp, role);
54617+
54618+ if (err)
54619+ return ERR_PTR(err);
54620+
54621+ /* set pointer for parent subject */
54622+ if (s_tmp->parent_subject) {
54623+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54624+
54625+ if (IS_ERR(s_tmp2))
54626+ return s_tmp2;
54627+
54628+ s_tmp->parent_subject = s_tmp2;
54629+ }
54630+
54631+ /* add in ip acls */
54632+
54633+ if (!s_tmp->ip_num) {
54634+ s_tmp->ips = NULL;
54635+ goto insert;
54636+ }
54637+
54638+ i_tmp =
54639+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54640+ sizeof (struct acl_ip_label *));
54641+
54642+ if (!i_tmp)
54643+ return ERR_PTR(-ENOMEM);
54644+
54645+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54646+ *(i_tmp + i_num) =
54647+ (struct acl_ip_label *)
54648+ acl_alloc(sizeof (struct acl_ip_label));
54649+ if (!*(i_tmp + i_num))
54650+ return ERR_PTR(-ENOMEM);
54651+
54652+ if (copy_from_user
54653+ (&i_utmp2, s_tmp->ips + i_num,
54654+ sizeof (struct acl_ip_label *)))
54655+ return ERR_PTR(-EFAULT);
54656+
54657+ if (copy_from_user
54658+ (*(i_tmp + i_num), i_utmp2,
54659+ sizeof (struct acl_ip_label)))
54660+ return ERR_PTR(-EFAULT);
54661+
54662+ if ((*(i_tmp + i_num))->iface == NULL)
54663+ continue;
54664+
54665+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54666+ if (!len || len >= IFNAMSIZ)
54667+ return ERR_PTR(-EINVAL);
54668+ tmp = acl_alloc(len);
54669+ if (tmp == NULL)
54670+ return ERR_PTR(-ENOMEM);
54671+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54672+ return ERR_PTR(-EFAULT);
54673+ (*(i_tmp + i_num))->iface = tmp;
54674+ }
54675+
54676+ s_tmp->ips = i_tmp;
54677+
54678+insert:
54679+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54680+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54681+ return ERR_PTR(-ENOMEM);
54682+
54683+ return s_tmp;
54684+}
54685+
54686+static int
54687+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54688+{
54689+ struct acl_subject_label s_pre;
54690+ struct acl_subject_label * ret;
54691+ int err;
54692+
54693+ while (userp) {
54694+ if (copy_from_user(&s_pre, userp,
54695+ sizeof (struct acl_subject_label)))
54696+ return -EFAULT;
54697+
54698+ ret = do_copy_user_subj(userp, role, NULL);
54699+
54700+ err = PTR_ERR(ret);
54701+ if (IS_ERR(ret))
54702+ return err;
54703+
54704+ insert_acl_subj_label(ret, role);
54705+
54706+ userp = s_pre.prev;
54707+ }
54708+
54709+ return 0;
54710+}
54711+
54712+static int
54713+copy_user_acl(struct gr_arg *arg)
54714+{
54715+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54716+ struct acl_subject_label *subj_list;
54717+ struct sprole_pw *sptmp;
54718+ struct gr_hash_struct *ghash;
54719+ uid_t *domainlist;
54720+ unsigned int r_num;
54721+ unsigned int len;
54722+ char *tmp;
54723+ int err = 0;
54724+ __u16 i;
54725+ __u32 num_subjs;
54726+
54727+ /* we need a default and kernel role */
54728+ if (arg->role_db.num_roles < 2)
54729+ return -EINVAL;
54730+
54731+ /* copy special role authentication info from userspace */
54732+
54733+ num_sprole_pws = arg->num_sprole_pws;
54734+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54735+
54736+ if (!acl_special_roles && num_sprole_pws)
54737+ return -ENOMEM;
54738+
54739+ for (i = 0; i < num_sprole_pws; i++) {
54740+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54741+ if (!sptmp)
54742+ return -ENOMEM;
54743+ if (copy_from_user(sptmp, arg->sprole_pws + i,
54744+ sizeof (struct sprole_pw)))
54745+ return -EFAULT;
54746+
54747+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54748+
54749+ if (!len || len >= GR_SPROLE_LEN)
54750+ return -EINVAL;
54751+
54752+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54753+ return -ENOMEM;
54754+
54755+ if (copy_from_user(tmp, sptmp->rolename, len))
54756+ return -EFAULT;
54757+
54758+ tmp[len-1] = '\0';
54759+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54760+ printk(KERN_ALERT "Copying special role %s\n", tmp);
54761+#endif
54762+ sptmp->rolename = tmp;
54763+ acl_special_roles[i] = sptmp;
54764+ }
54765+
54766+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54767+
54768+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54769+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
54770+
54771+ if (!r_tmp)
54772+ return -ENOMEM;
54773+
54774+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
54775+ sizeof (struct acl_role_label *)))
54776+ return -EFAULT;
54777+
54778+ if (copy_from_user(r_tmp, r_utmp2,
54779+ sizeof (struct acl_role_label)))
54780+ return -EFAULT;
54781+
54782+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54783+
54784+ if (!len || len >= PATH_MAX)
54785+ return -EINVAL;
54786+
54787+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54788+ return -ENOMEM;
54789+
54790+ if (copy_from_user(tmp, r_tmp->rolename, len))
54791+ return -EFAULT;
54792+
54793+ tmp[len-1] = '\0';
54794+ r_tmp->rolename = tmp;
54795+
54796+ if (!strcmp(r_tmp->rolename, "default")
54797+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
54798+ default_role = r_tmp;
54799+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
54800+ kernel_role = r_tmp;
54801+ }
54802+
54803+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
54804+ return -ENOMEM;
54805+
54806+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
54807+ return -EFAULT;
54808+
54809+ r_tmp->hash = ghash;
54810+
54811+ num_subjs = count_user_subjs(r_tmp->hash->first);
54812+
54813+ r_tmp->subj_hash_size = num_subjs;
54814+ r_tmp->subj_hash =
54815+ (struct acl_subject_label **)
54816+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
54817+
54818+ if (!r_tmp->subj_hash)
54819+ return -ENOMEM;
54820+
54821+ err = copy_user_allowedips(r_tmp);
54822+ if (err)
54823+ return err;
54824+
54825+ /* copy domain info */
54826+ if (r_tmp->domain_children != NULL) {
54827+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
54828+ if (domainlist == NULL)
54829+ return -ENOMEM;
54830+
54831+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
54832+ return -EFAULT;
54833+
54834+ r_tmp->domain_children = domainlist;
54835+ }
54836+
54837+ err = copy_user_transitions(r_tmp);
54838+ if (err)
54839+ return err;
54840+
54841+ memset(r_tmp->subj_hash, 0,
54842+ r_tmp->subj_hash_size *
54843+ sizeof (struct acl_subject_label *));
54844+
54845+ /* acquire the list of subjects, then NULL out
54846+ the list prior to parsing the subjects for this role,
54847+ as during this parsing the list is replaced with a list
54848+ of *nested* subjects for the role
54849+ */
54850+ subj_list = r_tmp->hash->first;
54851+
54852+ /* set nested subject list to null */
54853+ r_tmp->hash->first = NULL;
54854+
54855+ err = copy_user_subjs(subj_list, r_tmp);
54856+
54857+ if (err)
54858+ return err;
54859+
54860+ insert_acl_role_label(r_tmp);
54861+ }
54862+
54863+ if (default_role == NULL || kernel_role == NULL)
54864+ return -EINVAL;
54865+
54866+ return err;
54867+}
54868+
54869+static int
54870+gracl_init(struct gr_arg *args)
54871+{
54872+ int error = 0;
54873+
54874+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
54875+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
54876+
54877+ if (init_variables(args)) {
54878+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
54879+ error = -ENOMEM;
54880+ free_variables();
54881+ goto out;
54882+ }
54883+
54884+ error = copy_user_acl(args);
54885+ free_init_variables();
54886+ if (error) {
54887+ free_variables();
54888+ goto out;
54889+ }
54890+
54891+ if ((error = gr_set_acls(0))) {
54892+ free_variables();
54893+ goto out;
54894+ }
54895+
54896+ pax_open_kernel();
54897+ gr_status |= GR_READY;
54898+ pax_close_kernel();
54899+
54900+ out:
54901+ return error;
54902+}
54903+
54904+/* derived from glibc fnmatch() 0: match, 1: no match*/
54905+
54906+static int
54907+glob_match(const char *p, const char *n)
54908+{
54909+ char c;
54910+
54911+ while ((c = *p++) != '\0') {
54912+ switch (c) {
54913+ case '?':
54914+ if (*n == '\0')
54915+ return 1;
54916+ else if (*n == '/')
54917+ return 1;
54918+ break;
54919+ case '\\':
54920+ if (*n != c)
54921+ return 1;
54922+ break;
54923+ case '*':
54924+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
54925+ if (*n == '/')
54926+ return 1;
54927+ else if (c == '?') {
54928+ if (*n == '\0')
54929+ return 1;
54930+ else
54931+ ++n;
54932+ }
54933+ }
54934+ if (c == '\0') {
54935+ return 0;
54936+ } else {
54937+ const char *endp;
54938+
54939+ if ((endp = strchr(n, '/')) == NULL)
54940+ endp = n + strlen(n);
54941+
54942+ if (c == '[') {
54943+ for (--p; n < endp; ++n)
54944+ if (!glob_match(p, n))
54945+ return 0;
54946+ } else if (c == '/') {
54947+ while (*n != '\0' && *n != '/')
54948+ ++n;
54949+ if (*n == '/' && !glob_match(p, n + 1))
54950+ return 0;
54951+ } else {
54952+ for (--p; n < endp; ++n)
54953+ if (*n == c && !glob_match(p, n))
54954+ return 0;
54955+ }
54956+
54957+ return 1;
54958+ }
54959+ case '[':
54960+ {
54961+ int not;
54962+ char cold;
54963+
54964+ if (*n == '\0' || *n == '/')
54965+ return 1;
54966+
54967+ not = (*p == '!' || *p == '^');
54968+ if (not)
54969+ ++p;
54970+
54971+ c = *p++;
54972+ for (;;) {
54973+ unsigned char fn = (unsigned char)*n;
54974+
54975+ if (c == '\0')
54976+ return 1;
54977+ else {
54978+ if (c == fn)
54979+ goto matched;
54980+ cold = c;
54981+ c = *p++;
54982+
54983+ if (c == '-' && *p != ']') {
54984+ unsigned char cend = *p++;
54985+
54986+ if (cend == '\0')
54987+ return 1;
54988+
54989+ if (cold <= fn && fn <= cend)
54990+ goto matched;
54991+
54992+ c = *p++;
54993+ }
54994+ }
54995+
54996+ if (c == ']')
54997+ break;
54998+ }
54999+ if (!not)
55000+ return 1;
55001+ break;
55002+ matched:
55003+ while (c != ']') {
55004+ if (c == '\0')
55005+ return 1;
55006+
55007+ c = *p++;
55008+ }
55009+ if (not)
55010+ return 1;
55011+ }
55012+ break;
55013+ default:
55014+ if (c != *n)
55015+ return 1;
55016+ }
55017+
55018+ ++n;
55019+ }
55020+
55021+ if (*n == '\0')
55022+ return 0;
55023+
55024+ if (*n == '/')
55025+ return 0;
55026+
55027+ return 1;
55028+}
55029+
55030+static struct acl_object_label *
55031+chk_glob_label(struct acl_object_label *globbed,
55032+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55033+{
55034+ struct acl_object_label *tmp;
55035+
55036+ if (*path == NULL)
55037+ *path = gr_to_filename_nolock(dentry, mnt);
55038+
55039+ tmp = globbed;
55040+
55041+ while (tmp) {
55042+ if (!glob_match(tmp->filename, *path))
55043+ return tmp;
55044+ tmp = tmp->next;
55045+ }
55046+
55047+ return NULL;
55048+}
55049+
55050+static struct acl_object_label *
55051+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55052+ const ino_t curr_ino, const dev_t curr_dev,
55053+ const struct acl_subject_label *subj, char **path, const int checkglob)
55054+{
55055+ struct acl_subject_label *tmpsubj;
55056+ struct acl_object_label *retval;
55057+ struct acl_object_label *retval2;
55058+
55059+ tmpsubj = (struct acl_subject_label *) subj;
55060+ read_lock(&gr_inode_lock);
55061+ do {
55062+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55063+ if (retval) {
55064+ if (checkglob && retval->globbed) {
55065+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55066+ if (retval2)
55067+ retval = retval2;
55068+ }
55069+ break;
55070+ }
55071+ } while ((tmpsubj = tmpsubj->parent_subject));
55072+ read_unlock(&gr_inode_lock);
55073+
55074+ return retval;
55075+}
55076+
55077+static __inline__ struct acl_object_label *
55078+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55079+ struct dentry *curr_dentry,
55080+ const struct acl_subject_label *subj, char **path, const int checkglob)
55081+{
55082+ int newglob = checkglob;
55083+ ino_t inode;
55084+ dev_t device;
55085+
55086+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55087+ as we don't want a / * rule to match instead of the / object
55088+ don't do this for create lookups that call this function though, since they're looking up
55089+ on the parent and thus need globbing checks on all paths
55090+ */
55091+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55092+ newglob = GR_NO_GLOB;
55093+
55094+ spin_lock(&curr_dentry->d_lock);
55095+ inode = curr_dentry->d_inode->i_ino;
55096+ device = __get_dev(curr_dentry);
55097+ spin_unlock(&curr_dentry->d_lock);
55098+
55099+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55100+}
55101+
55102+static struct acl_object_label *
55103+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55104+ const struct acl_subject_label *subj, char *path, const int checkglob)
55105+{
55106+ struct dentry *dentry = (struct dentry *) l_dentry;
55107+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55108+ struct mount *real_mnt = real_mount(mnt);
55109+ struct acl_object_label *retval;
55110+ struct dentry *parent;
55111+
55112+ write_seqlock(&rename_lock);
55113+ br_read_lock(&vfsmount_lock);
55114+
55115+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55116+#ifdef CONFIG_NET
55117+ mnt == sock_mnt ||
55118+#endif
55119+#ifdef CONFIG_HUGETLBFS
55120+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55121+#endif
55122+ /* ignore Eric Biederman */
55123+ IS_PRIVATE(l_dentry->d_inode))) {
55124+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55125+ goto out;
55126+ }
55127+
55128+ for (;;) {
55129+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55130+ break;
55131+
55132+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55133+ if (!mnt_has_parent(real_mnt))
55134+ break;
55135+
55136+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55137+ if (retval != NULL)
55138+ goto out;
55139+
55140+ dentry = real_mnt->mnt_mountpoint;
55141+ real_mnt = real_mnt->mnt_parent;
55142+ mnt = &real_mnt->mnt;
55143+ continue;
55144+ }
55145+
55146+ parent = dentry->d_parent;
55147+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55148+ if (retval != NULL)
55149+ goto out;
55150+
55151+ dentry = parent;
55152+ }
55153+
55154+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55155+
55156+ /* real_root is pinned so we don't have to hold a reference */
55157+ if (retval == NULL)
55158+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55159+out:
55160+ br_read_unlock(&vfsmount_lock);
55161+ write_sequnlock(&rename_lock);
55162+
55163+ BUG_ON(retval == NULL);
55164+
55165+ return retval;
55166+}
55167+
55168+static __inline__ struct acl_object_label *
55169+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55170+ const struct acl_subject_label *subj)
55171+{
55172+ char *path = NULL;
55173+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55174+}
55175+
55176+static __inline__ struct acl_object_label *
55177+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55178+ const struct acl_subject_label *subj)
55179+{
55180+ char *path = NULL;
55181+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55182+}
55183+
55184+static __inline__ struct acl_object_label *
55185+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55186+ const struct acl_subject_label *subj, char *path)
55187+{
55188+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55189+}
55190+
55191+static struct acl_subject_label *
55192+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55193+ const struct acl_role_label *role)
55194+{
55195+ struct dentry *dentry = (struct dentry *) l_dentry;
55196+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55197+ struct mount *real_mnt = real_mount(mnt);
55198+ struct acl_subject_label *retval;
55199+ struct dentry *parent;
55200+
55201+ write_seqlock(&rename_lock);
55202+ br_read_lock(&vfsmount_lock);
55203+
55204+ for (;;) {
55205+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55206+ break;
55207+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55208+ if (!mnt_has_parent(real_mnt))
55209+ break;
55210+
55211+ spin_lock(&dentry->d_lock);
55212+ read_lock(&gr_inode_lock);
55213+ retval =
55214+ lookup_acl_subj_label(dentry->d_inode->i_ino,
55215+ __get_dev(dentry), role);
55216+ read_unlock(&gr_inode_lock);
55217+ spin_unlock(&dentry->d_lock);
55218+ if (retval != NULL)
55219+ goto out;
55220+
55221+ dentry = real_mnt->mnt_mountpoint;
55222+ real_mnt = real_mnt->mnt_parent;
55223+ mnt = &real_mnt->mnt;
55224+ continue;
55225+ }
55226+
55227+ spin_lock(&dentry->d_lock);
55228+ read_lock(&gr_inode_lock);
55229+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55230+ __get_dev(dentry), role);
55231+ read_unlock(&gr_inode_lock);
55232+ parent = dentry->d_parent;
55233+ spin_unlock(&dentry->d_lock);
55234+
55235+ if (retval != NULL)
55236+ goto out;
55237+
55238+ dentry = parent;
55239+ }
55240+
55241+ spin_lock(&dentry->d_lock);
55242+ read_lock(&gr_inode_lock);
55243+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55244+ __get_dev(dentry), role);
55245+ read_unlock(&gr_inode_lock);
55246+ spin_unlock(&dentry->d_lock);
55247+
55248+ if (unlikely(retval == NULL)) {
55249+ /* real_root is pinned, we don't need to hold a reference */
55250+ read_lock(&gr_inode_lock);
55251+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55252+ __get_dev(real_root.dentry), role);
55253+ read_unlock(&gr_inode_lock);
55254+ }
55255+out:
55256+ br_read_unlock(&vfsmount_lock);
55257+ write_sequnlock(&rename_lock);
55258+
55259+ BUG_ON(retval == NULL);
55260+
55261+ return retval;
55262+}
55263+
55264+static void
55265+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55266+{
55267+ struct task_struct *task = current;
55268+ const struct cred *cred = current_cred();
55269+
55270+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55271+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55272+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55273+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55274+
55275+ return;
55276+}
55277+
55278+static void
55279+gr_log_learn_id_change(const char type, const unsigned int real,
55280+ const unsigned int effective, const unsigned int fs)
55281+{
55282+ struct task_struct *task = current;
55283+ const struct cred *cred = current_cred();
55284+
55285+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55286+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55287+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55288+ type, real, effective, fs, &task->signal->saved_ip);
55289+
55290+ return;
55291+}
55292+
55293+__u32
55294+gr_search_file(const struct dentry * dentry, const __u32 mode,
55295+ const struct vfsmount * mnt)
55296+{
55297+ __u32 retval = mode;
55298+ struct acl_subject_label *curracl;
55299+ struct acl_object_label *currobj;
55300+
55301+ if (unlikely(!(gr_status & GR_READY)))
55302+ return (mode & ~GR_AUDITS);
55303+
55304+ curracl = current->acl;
55305+
55306+ currobj = chk_obj_label(dentry, mnt, curracl);
55307+ retval = currobj->mode & mode;
55308+
55309+ /* if we're opening a specified transfer file for writing
55310+ (e.g. /dev/initctl), then transfer our role to init
55311+ */
55312+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55313+ current->role->roletype & GR_ROLE_PERSIST)) {
55314+ struct task_struct *task = init_pid_ns.child_reaper;
55315+
55316+ if (task->role != current->role) {
55317+ task->acl_sp_role = 0;
55318+ task->acl_role_id = current->acl_role_id;
55319+ task->role = current->role;
55320+ rcu_read_lock();
55321+ read_lock(&grsec_exec_file_lock);
55322+ gr_apply_subject_to_task(task);
55323+ read_unlock(&grsec_exec_file_lock);
55324+ rcu_read_unlock();
55325+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55326+ }
55327+ }
55328+
55329+ if (unlikely
55330+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55331+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55332+ __u32 new_mode = mode;
55333+
55334+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55335+
55336+ retval = new_mode;
55337+
55338+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55339+ new_mode |= GR_INHERIT;
55340+
55341+ if (!(mode & GR_NOLEARN))
55342+ gr_log_learn(dentry, mnt, new_mode);
55343+ }
55344+
55345+ return retval;
55346+}
55347+
55348+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55349+ const struct dentry *parent,
55350+ const struct vfsmount *mnt)
55351+{
55352+ struct name_entry *match;
55353+ struct acl_object_label *matchpo;
55354+ struct acl_subject_label *curracl;
55355+ char *path;
55356+
55357+ if (unlikely(!(gr_status & GR_READY)))
55358+ return NULL;
55359+
55360+ preempt_disable();
55361+ path = gr_to_filename_rbac(new_dentry, mnt);
55362+ match = lookup_name_entry_create(path);
55363+
55364+ curracl = current->acl;
55365+
55366+ if (match) {
55367+ read_lock(&gr_inode_lock);
55368+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55369+ read_unlock(&gr_inode_lock);
55370+
55371+ if (matchpo) {
55372+ preempt_enable();
55373+ return matchpo;
55374+ }
55375+ }
55376+
55377+ // lookup parent
55378+
55379+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55380+
55381+ preempt_enable();
55382+ return matchpo;
55383+}
55384+
55385+__u32
55386+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55387+ const struct vfsmount * mnt, const __u32 mode)
55388+{
55389+ struct acl_object_label *matchpo;
55390+ __u32 retval;
55391+
55392+ if (unlikely(!(gr_status & GR_READY)))
55393+ return (mode & ~GR_AUDITS);
55394+
55395+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
55396+
55397+ retval = matchpo->mode & mode;
55398+
55399+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55400+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55401+ __u32 new_mode = mode;
55402+
55403+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55404+
55405+ gr_log_learn(new_dentry, mnt, new_mode);
55406+ return new_mode;
55407+ }
55408+
55409+ return retval;
55410+}
55411+
55412+__u32
55413+gr_check_link(const struct dentry * new_dentry,
55414+ const struct dentry * parent_dentry,
55415+ const struct vfsmount * parent_mnt,
55416+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55417+{
55418+ struct acl_object_label *obj;
55419+ __u32 oldmode, newmode;
55420+ __u32 needmode;
55421+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55422+ GR_DELETE | GR_INHERIT;
55423+
55424+ if (unlikely(!(gr_status & GR_READY)))
55425+ return (GR_CREATE | GR_LINK);
55426+
55427+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55428+ oldmode = obj->mode;
55429+
55430+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55431+ newmode = obj->mode;
55432+
55433+ needmode = newmode & checkmodes;
55434+
55435+ // old name for hardlink must have at least the permissions of the new name
55436+ if ((oldmode & needmode) != needmode)
55437+ goto bad;
55438+
55439+ // if old name had restrictions/auditing, make sure the new name does as well
55440+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55441+
55442+ // don't allow hardlinking of suid/sgid/fcapped files without permission
55443+ if (is_privileged_binary(old_dentry))
55444+ needmode |= GR_SETID;
55445+
55446+ if ((newmode & needmode) != needmode)
55447+ goto bad;
55448+
55449+ // enforce minimum permissions
55450+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55451+ return newmode;
55452+bad:
55453+ needmode = oldmode;
55454+ if (is_privileged_binary(old_dentry))
55455+ needmode |= GR_SETID;
55456+
55457+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55458+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55459+ return (GR_CREATE | GR_LINK);
55460+ } else if (newmode & GR_SUPPRESS)
55461+ return GR_SUPPRESS;
55462+ else
55463+ return 0;
55464+}
55465+
55466+int
55467+gr_check_hidden_task(const struct task_struct *task)
55468+{
55469+ if (unlikely(!(gr_status & GR_READY)))
55470+ return 0;
55471+
55472+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55473+ return 1;
55474+
55475+ return 0;
55476+}
55477+
55478+int
55479+gr_check_protected_task(const struct task_struct *task)
55480+{
55481+ if (unlikely(!(gr_status & GR_READY) || !task))
55482+ return 0;
55483+
55484+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55485+ task->acl != current->acl)
55486+ return 1;
55487+
55488+ return 0;
55489+}
55490+
55491+int
55492+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55493+{
55494+ struct task_struct *p;
55495+ int ret = 0;
55496+
55497+ if (unlikely(!(gr_status & GR_READY) || !pid))
55498+ return ret;
55499+
55500+ read_lock(&tasklist_lock);
55501+ do_each_pid_task(pid, type, p) {
55502+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55503+ p->acl != current->acl) {
55504+ ret = 1;
55505+ goto out;
55506+ }
55507+ } while_each_pid_task(pid, type, p);
55508+out:
55509+ read_unlock(&tasklist_lock);
55510+
55511+ return ret;
55512+}
55513+
55514+void
55515+gr_copy_label(struct task_struct *tsk)
55516+{
55517+ tsk->signal->used_accept = 0;
55518+ tsk->acl_sp_role = 0;
55519+ tsk->acl_role_id = current->acl_role_id;
55520+ tsk->acl = current->acl;
55521+ tsk->role = current->role;
55522+ tsk->signal->curr_ip = current->signal->curr_ip;
55523+ tsk->signal->saved_ip = current->signal->saved_ip;
55524+ if (current->exec_file)
55525+ get_file(current->exec_file);
55526+ tsk->exec_file = current->exec_file;
55527+ tsk->is_writable = current->is_writable;
55528+ if (unlikely(current->signal->used_accept)) {
55529+ current->signal->curr_ip = 0;
55530+ current->signal->saved_ip = 0;
55531+ }
55532+
55533+ return;
55534+}
55535+
55536+static void
55537+gr_set_proc_res(struct task_struct *task)
55538+{
55539+ struct acl_subject_label *proc;
55540+ unsigned short i;
55541+
55542+ proc = task->acl;
55543+
55544+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55545+ return;
55546+
55547+ for (i = 0; i < RLIM_NLIMITS; i++) {
55548+ if (!(proc->resmask & (1 << i)))
55549+ continue;
55550+
55551+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55552+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55553+ }
55554+
55555+ return;
55556+}
55557+
55558+extern int __gr_process_user_ban(struct user_struct *user);
55559+
55560+int
55561+gr_check_user_change(int real, int effective, int fs)
55562+{
55563+ unsigned int i;
55564+ __u16 num;
55565+ uid_t *uidlist;
55566+ int curuid;
55567+ int realok = 0;
55568+ int effectiveok = 0;
55569+ int fsok = 0;
55570+
55571+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55572+ struct user_struct *user;
55573+
55574+ if (real == -1)
55575+ goto skipit;
55576+
55577+ user = find_user(real);
55578+ if (user == NULL)
55579+ goto skipit;
55580+
55581+ if (__gr_process_user_ban(user)) {
55582+ /* for find_user */
55583+ free_uid(user);
55584+ return 1;
55585+ }
55586+
55587+ /* for find_user */
55588+ free_uid(user);
55589+
55590+skipit:
55591+#endif
55592+
55593+ if (unlikely(!(gr_status & GR_READY)))
55594+ return 0;
55595+
55596+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55597+ gr_log_learn_id_change('u', real, effective, fs);
55598+
55599+ num = current->acl->user_trans_num;
55600+ uidlist = current->acl->user_transitions;
55601+
55602+ if (uidlist == NULL)
55603+ return 0;
55604+
55605+ if (real == -1)
55606+ realok = 1;
55607+ if (effective == -1)
55608+ effectiveok = 1;
55609+ if (fs == -1)
55610+ fsok = 1;
55611+
55612+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
55613+ for (i = 0; i < num; i++) {
55614+ curuid = (int)uidlist[i];
55615+ if (real == curuid)
55616+ realok = 1;
55617+ if (effective == curuid)
55618+ effectiveok = 1;
55619+ if (fs == curuid)
55620+ fsok = 1;
55621+ }
55622+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
55623+ for (i = 0; i < num; i++) {
55624+ curuid = (int)uidlist[i];
55625+ if (real == curuid)
55626+ break;
55627+ if (effective == curuid)
55628+ break;
55629+ if (fs == curuid)
55630+ break;
55631+ }
55632+ /* not in deny list */
55633+ if (i == num) {
55634+ realok = 1;
55635+ effectiveok = 1;
55636+ fsok = 1;
55637+ }
55638+ }
55639+
55640+ if (realok && effectiveok && fsok)
55641+ return 0;
55642+ else {
55643+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55644+ return 1;
55645+ }
55646+}
55647+
55648+int
55649+gr_check_group_change(int real, int effective, int fs)
55650+{
55651+ unsigned int i;
55652+ __u16 num;
55653+ gid_t *gidlist;
55654+ int curgid;
55655+ int realok = 0;
55656+ int effectiveok = 0;
55657+ int fsok = 0;
55658+
55659+ if (unlikely(!(gr_status & GR_READY)))
55660+ return 0;
55661+
55662+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55663+ gr_log_learn_id_change('g', real, effective, fs);
55664+
55665+ num = current->acl->group_trans_num;
55666+ gidlist = current->acl->group_transitions;
55667+
55668+ if (gidlist == NULL)
55669+ return 0;
55670+
55671+ if (real == -1)
55672+ realok = 1;
55673+ if (effective == -1)
55674+ effectiveok = 1;
55675+ if (fs == -1)
55676+ fsok = 1;
55677+
55678+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
55679+ for (i = 0; i < num; i++) {
55680+ curgid = (int)gidlist[i];
55681+ if (real == curgid)
55682+ realok = 1;
55683+ if (effective == curgid)
55684+ effectiveok = 1;
55685+ if (fs == curgid)
55686+ fsok = 1;
55687+ }
55688+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
55689+ for (i = 0; i < num; i++) {
55690+ curgid = (int)gidlist[i];
55691+ if (real == curgid)
55692+ break;
55693+ if (effective == curgid)
55694+ break;
55695+ if (fs == curgid)
55696+ break;
55697+ }
55698+ /* not in deny list */
55699+ if (i == num) {
55700+ realok = 1;
55701+ effectiveok = 1;
55702+ fsok = 1;
55703+ }
55704+ }
55705+
55706+ if (realok && effectiveok && fsok)
55707+ return 0;
55708+ else {
55709+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55710+ return 1;
55711+ }
55712+}
55713+
55714+extern int gr_acl_is_capable(const int cap);
55715+
55716+void
55717+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55718+{
55719+ struct acl_role_label *role = task->role;
55720+ struct acl_subject_label *subj = NULL;
55721+ struct acl_object_label *obj;
55722+ struct file *filp;
55723+
55724+ if (unlikely(!(gr_status & GR_READY)))
55725+ return;
55726+
55727+ filp = task->exec_file;
55728+
55729+ /* kernel process, we'll give them the kernel role */
55730+ if (unlikely(!filp)) {
55731+ task->role = kernel_role;
55732+ task->acl = kernel_role->root_label;
55733+ return;
55734+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55735+ role = lookup_acl_role_label(task, uid, gid);
55736+
55737+ /* don't change the role if we're not a privileged process */
55738+ if (role && task->role != role &&
55739+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55740+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55741+ return;
55742+
55743+ /* perform subject lookup in possibly new role
55744+ we can use this result below in the case where role == task->role
55745+ */
55746+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55747+
55748+ /* if we changed uid/gid, but result in the same role
55749+ and are using inheritance, don't lose the inherited subject
55750+ if current subject is other than what normal lookup
55751+ would result in, we arrived via inheritance, don't
55752+ lose subject
55753+ */
55754+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55755+ (subj == task->acl)))
55756+ task->acl = subj;
55757+
55758+ task->role = role;
55759+
55760+ task->is_writable = 0;
55761+
55762+ /* ignore additional mmap checks for processes that are writable
55763+ by the default ACL */
55764+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55765+ if (unlikely(obj->mode & GR_WRITE))
55766+ task->is_writable = 1;
55767+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55768+ if (unlikely(obj->mode & GR_WRITE))
55769+ task->is_writable = 1;
55770+
55771+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55772+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55773+#endif
55774+
55775+ gr_set_proc_res(task);
55776+
55777+ return;
55778+}
55779+
55780+int
55781+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55782+ const int unsafe_flags)
55783+{
55784+ struct task_struct *task = current;
55785+ struct acl_subject_label *newacl;
55786+ struct acl_object_label *obj;
55787+ __u32 retmode;
55788+
55789+ if (unlikely(!(gr_status & GR_READY)))
55790+ return 0;
55791+
55792+ newacl = chk_subj_label(dentry, mnt, task->role);
55793+
55794+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
55795+ did an exec
55796+ */
55797+ rcu_read_lock();
55798+ read_lock(&tasklist_lock);
55799+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
55800+ (task->parent->acl->mode & GR_POVERRIDE))) {
55801+ read_unlock(&tasklist_lock);
55802+ rcu_read_unlock();
55803+ goto skip_check;
55804+ }
55805+ read_unlock(&tasklist_lock);
55806+ rcu_read_unlock();
55807+
55808+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
55809+ !(task->role->roletype & GR_ROLE_GOD) &&
55810+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
55811+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55812+ if (unsafe_flags & LSM_UNSAFE_SHARE)
55813+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
55814+ else
55815+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
55816+ return -EACCES;
55817+ }
55818+
55819+skip_check:
55820+
55821+ obj = chk_obj_label(dentry, mnt, task->acl);
55822+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
55823+
55824+ if (!(task->acl->mode & GR_INHERITLEARN) &&
55825+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
55826+ if (obj->nested)
55827+ task->acl = obj->nested;
55828+ else
55829+ task->acl = newacl;
55830+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
55831+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
55832+
55833+ task->is_writable = 0;
55834+
55835+ /* ignore additional mmap checks for processes that are writable
55836+ by the default ACL */
55837+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
55838+ if (unlikely(obj->mode & GR_WRITE))
55839+ task->is_writable = 1;
55840+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
55841+ if (unlikely(obj->mode & GR_WRITE))
55842+ task->is_writable = 1;
55843+
55844+ gr_set_proc_res(task);
55845+
55846+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55847+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55848+#endif
55849+ return 0;
55850+}
55851+
55852+/* always called with valid inodev ptr */
55853+static void
55854+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
55855+{
55856+ struct acl_object_label *matchpo;
55857+ struct acl_subject_label *matchps;
55858+ struct acl_subject_label *subj;
55859+ struct acl_role_label *role;
55860+ unsigned int x;
55861+
55862+ FOR_EACH_ROLE_START(role)
55863+ FOR_EACH_SUBJECT_START(role, subj, x)
55864+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55865+ matchpo->mode |= GR_DELETED;
55866+ FOR_EACH_SUBJECT_END(subj,x)
55867+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
55868+ /* nested subjects aren't in the role's subj_hash table */
55869+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55870+ matchpo->mode |= GR_DELETED;
55871+ FOR_EACH_NESTED_SUBJECT_END(subj)
55872+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
55873+ matchps->mode |= GR_DELETED;
55874+ FOR_EACH_ROLE_END(role)
55875+
55876+ inodev->nentry->deleted = 1;
55877+
55878+ return;
55879+}
55880+
55881+void
55882+gr_handle_delete(const ino_t ino, const dev_t dev)
55883+{
55884+ struct inodev_entry *inodev;
55885+
55886+ if (unlikely(!(gr_status & GR_READY)))
55887+ return;
55888+
55889+ write_lock(&gr_inode_lock);
55890+ inodev = lookup_inodev_entry(ino, dev);
55891+ if (inodev != NULL)
55892+ do_handle_delete(inodev, ino, dev);
55893+ write_unlock(&gr_inode_lock);
55894+
55895+ return;
55896+}
55897+
55898+static void
55899+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
55900+ const ino_t newinode, const dev_t newdevice,
55901+ struct acl_subject_label *subj)
55902+{
55903+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
55904+ struct acl_object_label *match;
55905+
55906+ match = subj->obj_hash[index];
55907+
55908+ while (match && (match->inode != oldinode ||
55909+ match->device != olddevice ||
55910+ !(match->mode & GR_DELETED)))
55911+ match = match->next;
55912+
55913+ if (match && (match->inode == oldinode)
55914+ && (match->device == olddevice)
55915+ && (match->mode & GR_DELETED)) {
55916+ if (match->prev == NULL) {
55917+ subj->obj_hash[index] = match->next;
55918+ if (match->next != NULL)
55919+ match->next->prev = NULL;
55920+ } else {
55921+ match->prev->next = match->next;
55922+ if (match->next != NULL)
55923+ match->next->prev = match->prev;
55924+ }
55925+ match->prev = NULL;
55926+ match->next = NULL;
55927+ match->inode = newinode;
55928+ match->device = newdevice;
55929+ match->mode &= ~GR_DELETED;
55930+
55931+ insert_acl_obj_label(match, subj);
55932+ }
55933+
55934+ return;
55935+}
55936+
55937+static void
55938+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
55939+ const ino_t newinode, const dev_t newdevice,
55940+ struct acl_role_label *role)
55941+{
55942+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
55943+ struct acl_subject_label *match;
55944+
55945+ match = role->subj_hash[index];
55946+
55947+ while (match && (match->inode != oldinode ||
55948+ match->device != olddevice ||
55949+ !(match->mode & GR_DELETED)))
55950+ match = match->next;
55951+
55952+ if (match && (match->inode == oldinode)
55953+ && (match->device == olddevice)
55954+ && (match->mode & GR_DELETED)) {
55955+ if (match->prev == NULL) {
55956+ role->subj_hash[index] = match->next;
55957+ if (match->next != NULL)
55958+ match->next->prev = NULL;
55959+ } else {
55960+ match->prev->next = match->next;
55961+ if (match->next != NULL)
55962+ match->next->prev = match->prev;
55963+ }
55964+ match->prev = NULL;
55965+ match->next = NULL;
55966+ match->inode = newinode;
55967+ match->device = newdevice;
55968+ match->mode &= ~GR_DELETED;
55969+
55970+ insert_acl_subj_label(match, role);
55971+ }
55972+
55973+ return;
55974+}
55975+
55976+static void
55977+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
55978+ const ino_t newinode, const dev_t newdevice)
55979+{
55980+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
55981+ struct inodev_entry *match;
55982+
55983+ match = inodev_set.i_hash[index];
55984+
55985+ while (match && (match->nentry->inode != oldinode ||
55986+ match->nentry->device != olddevice || !match->nentry->deleted))
55987+ match = match->next;
55988+
55989+ if (match && (match->nentry->inode == oldinode)
55990+ && (match->nentry->device == olddevice) &&
55991+ match->nentry->deleted) {
55992+ if (match->prev == NULL) {
55993+ inodev_set.i_hash[index] = match->next;
55994+ if (match->next != NULL)
55995+ match->next->prev = NULL;
55996+ } else {
55997+ match->prev->next = match->next;
55998+ if (match->next != NULL)
55999+ match->next->prev = match->prev;
56000+ }
56001+ match->prev = NULL;
56002+ match->next = NULL;
56003+ match->nentry->inode = newinode;
56004+ match->nentry->device = newdevice;
56005+ match->nentry->deleted = 0;
56006+
56007+ insert_inodev_entry(match);
56008+ }
56009+
56010+ return;
56011+}
56012+
56013+static void
56014+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56015+{
56016+ struct acl_subject_label *subj;
56017+ struct acl_role_label *role;
56018+ unsigned int x;
56019+
56020+ FOR_EACH_ROLE_START(role)
56021+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56022+
56023+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
56024+ if ((subj->inode == ino) && (subj->device == dev)) {
56025+ subj->inode = ino;
56026+ subj->device = dev;
56027+ }
56028+ /* nested subjects aren't in the role's subj_hash table */
56029+ update_acl_obj_label(matchn->inode, matchn->device,
56030+ ino, dev, subj);
56031+ FOR_EACH_NESTED_SUBJECT_END(subj)
56032+ FOR_EACH_SUBJECT_START(role, subj, x)
56033+ update_acl_obj_label(matchn->inode, matchn->device,
56034+ ino, dev, subj);
56035+ FOR_EACH_SUBJECT_END(subj,x)
56036+ FOR_EACH_ROLE_END(role)
56037+
56038+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56039+
56040+ return;
56041+}
56042+
56043+static void
56044+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56045+ const struct vfsmount *mnt)
56046+{
56047+ ino_t ino = dentry->d_inode->i_ino;
56048+ dev_t dev = __get_dev(dentry);
56049+
56050+ __do_handle_create(matchn, ino, dev);
56051+
56052+ return;
56053+}
56054+
56055+void
56056+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56057+{
56058+ struct name_entry *matchn;
56059+
56060+ if (unlikely(!(gr_status & GR_READY)))
56061+ return;
56062+
56063+ preempt_disable();
56064+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56065+
56066+ if (unlikely((unsigned long)matchn)) {
56067+ write_lock(&gr_inode_lock);
56068+ do_handle_create(matchn, dentry, mnt);
56069+ write_unlock(&gr_inode_lock);
56070+ }
56071+ preempt_enable();
56072+
56073+ return;
56074+}
56075+
56076+void
56077+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56078+{
56079+ struct name_entry *matchn;
56080+
56081+ if (unlikely(!(gr_status & GR_READY)))
56082+ return;
56083+
56084+ preempt_disable();
56085+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56086+
56087+ if (unlikely((unsigned long)matchn)) {
56088+ write_lock(&gr_inode_lock);
56089+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56090+ write_unlock(&gr_inode_lock);
56091+ }
56092+ preempt_enable();
56093+
56094+ return;
56095+}
56096+
56097+void
56098+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56099+ struct dentry *old_dentry,
56100+ struct dentry *new_dentry,
56101+ struct vfsmount *mnt, const __u8 replace)
56102+{
56103+ struct name_entry *matchn;
56104+ struct inodev_entry *inodev;
56105+ struct inode *inode = new_dentry->d_inode;
56106+ ino_t old_ino = old_dentry->d_inode->i_ino;
56107+ dev_t old_dev = __get_dev(old_dentry);
56108+
56109+ /* vfs_rename swaps the name and parent link for old_dentry and
56110+ new_dentry
56111+ at this point, old_dentry has the new name, parent link, and inode
56112+ for the renamed file
56113+ if a file is being replaced by a rename, new_dentry has the inode
56114+ and name for the replaced file
56115+ */
56116+
56117+ if (unlikely(!(gr_status & GR_READY)))
56118+ return;
56119+
56120+ preempt_disable();
56121+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56122+
56123+ /* we wouldn't have to check d_inode if it weren't for
56124+ NFS silly-renaming
56125+ */
56126+
56127+ write_lock(&gr_inode_lock);
56128+ if (unlikely(replace && inode)) {
56129+ ino_t new_ino = inode->i_ino;
56130+ dev_t new_dev = __get_dev(new_dentry);
56131+
56132+ inodev = lookup_inodev_entry(new_ino, new_dev);
56133+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56134+ do_handle_delete(inodev, new_ino, new_dev);
56135+ }
56136+
56137+ inodev = lookup_inodev_entry(old_ino, old_dev);
56138+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56139+ do_handle_delete(inodev, old_ino, old_dev);
56140+
56141+ if (unlikely((unsigned long)matchn))
56142+ do_handle_create(matchn, old_dentry, mnt);
56143+
56144+ write_unlock(&gr_inode_lock);
56145+ preempt_enable();
56146+
56147+ return;
56148+}
56149+
56150+static int
56151+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56152+ unsigned char **sum)
56153+{
56154+ struct acl_role_label *r;
56155+ struct role_allowed_ip *ipp;
56156+ struct role_transition *trans;
56157+ unsigned int i;
56158+ int found = 0;
56159+ u32 curr_ip = current->signal->curr_ip;
56160+
56161+ current->signal->saved_ip = curr_ip;
56162+
56163+ /* check transition table */
56164+
56165+ for (trans = current->role->transitions; trans; trans = trans->next) {
56166+ if (!strcmp(rolename, trans->rolename)) {
56167+ found = 1;
56168+ break;
56169+ }
56170+ }
56171+
56172+ if (!found)
56173+ return 0;
56174+
56175+ /* handle special roles that do not require authentication
56176+ and check ip */
56177+
56178+ FOR_EACH_ROLE_START(r)
56179+ if (!strcmp(rolename, r->rolename) &&
56180+ (r->roletype & GR_ROLE_SPECIAL)) {
56181+ found = 0;
56182+ if (r->allowed_ips != NULL) {
56183+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56184+ if ((ntohl(curr_ip) & ipp->netmask) ==
56185+ (ntohl(ipp->addr) & ipp->netmask))
56186+ found = 1;
56187+ }
56188+ } else
56189+ found = 2;
56190+ if (!found)
56191+ return 0;
56192+
56193+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56194+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56195+ *salt = NULL;
56196+ *sum = NULL;
56197+ return 1;
56198+ }
56199+ }
56200+ FOR_EACH_ROLE_END(r)
56201+
56202+ for (i = 0; i < num_sprole_pws; i++) {
56203+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56204+ *salt = acl_special_roles[i]->salt;
56205+ *sum = acl_special_roles[i]->sum;
56206+ return 1;
56207+ }
56208+ }
56209+
56210+ return 0;
56211+}
56212+
56213+static void
56214+assign_special_role(char *rolename)
56215+{
56216+ struct acl_object_label *obj;
56217+ struct acl_role_label *r;
56218+ struct acl_role_label *assigned = NULL;
56219+ struct task_struct *tsk;
56220+ struct file *filp;
56221+
56222+ FOR_EACH_ROLE_START(r)
56223+ if (!strcmp(rolename, r->rolename) &&
56224+ (r->roletype & GR_ROLE_SPECIAL)) {
56225+ assigned = r;
56226+ break;
56227+ }
56228+ FOR_EACH_ROLE_END(r)
56229+
56230+ if (!assigned)
56231+ return;
56232+
56233+ read_lock(&tasklist_lock);
56234+ read_lock(&grsec_exec_file_lock);
56235+
56236+ tsk = current->real_parent;
56237+ if (tsk == NULL)
56238+ goto out_unlock;
56239+
56240+ filp = tsk->exec_file;
56241+ if (filp == NULL)
56242+ goto out_unlock;
56243+
56244+ tsk->is_writable = 0;
56245+
56246+ tsk->acl_sp_role = 1;
56247+ tsk->acl_role_id = ++acl_sp_role_value;
56248+ tsk->role = assigned;
56249+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56250+
56251+ /* ignore additional mmap checks for processes that are writable
56252+ by the default ACL */
56253+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56254+ if (unlikely(obj->mode & GR_WRITE))
56255+ tsk->is_writable = 1;
56256+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56257+ if (unlikely(obj->mode & GR_WRITE))
56258+ tsk->is_writable = 1;
56259+
56260+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56261+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56262+#endif
56263+
56264+out_unlock:
56265+ read_unlock(&grsec_exec_file_lock);
56266+ read_unlock(&tasklist_lock);
56267+ return;
56268+}
56269+
56270+int gr_check_secure_terminal(struct task_struct *task)
56271+{
56272+ struct task_struct *p, *p2, *p3;
56273+ struct files_struct *files;
56274+ struct fdtable *fdt;
56275+ struct file *our_file = NULL, *file;
56276+ int i;
56277+
56278+ if (task->signal->tty == NULL)
56279+ return 1;
56280+
56281+ files = get_files_struct(task);
56282+ if (files != NULL) {
56283+ rcu_read_lock();
56284+ fdt = files_fdtable(files);
56285+ for (i=0; i < fdt->max_fds; i++) {
56286+ file = fcheck_files(files, i);
56287+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56288+ get_file(file);
56289+ our_file = file;
56290+ }
56291+ }
56292+ rcu_read_unlock();
56293+ put_files_struct(files);
56294+ }
56295+
56296+ if (our_file == NULL)
56297+ return 1;
56298+
56299+ read_lock(&tasklist_lock);
56300+ do_each_thread(p2, p) {
56301+ files = get_files_struct(p);
56302+ if (files == NULL ||
56303+ (p->signal && p->signal->tty == task->signal->tty)) {
56304+ if (files != NULL)
56305+ put_files_struct(files);
56306+ continue;
56307+ }
56308+ rcu_read_lock();
56309+ fdt = files_fdtable(files);
56310+ for (i=0; i < fdt->max_fds; i++) {
56311+ file = fcheck_files(files, i);
56312+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56313+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56314+ p3 = task;
56315+ while (p3->pid > 0) {
56316+ if (p3 == p)
56317+ break;
56318+ p3 = p3->real_parent;
56319+ }
56320+ if (p3 == p)
56321+ break;
56322+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56323+ gr_handle_alertkill(p);
56324+ rcu_read_unlock();
56325+ put_files_struct(files);
56326+ read_unlock(&tasklist_lock);
56327+ fput(our_file);
56328+ return 0;
56329+ }
56330+ }
56331+ rcu_read_unlock();
56332+ put_files_struct(files);
56333+ } while_each_thread(p2, p);
56334+ read_unlock(&tasklist_lock);
56335+
56336+ fput(our_file);
56337+ return 1;
56338+}
56339+
56340+static int gr_rbac_disable(void *unused)
56341+{
56342+ pax_open_kernel();
56343+ gr_status &= ~GR_READY;
56344+ pax_close_kernel();
56345+
56346+ return 0;
56347+}
56348+
56349+ssize_t
56350+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56351+{
56352+ struct gr_arg_wrapper uwrap;
56353+ unsigned char *sprole_salt = NULL;
56354+ unsigned char *sprole_sum = NULL;
56355+ int error = sizeof (struct gr_arg_wrapper);
56356+ int error2 = 0;
56357+
56358+ mutex_lock(&gr_dev_mutex);
56359+
56360+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56361+ error = -EPERM;
56362+ goto out;
56363+ }
56364+
56365+ if (count != sizeof (struct gr_arg_wrapper)) {
56366+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56367+ error = -EINVAL;
56368+ goto out;
56369+ }
56370+
56371+
56372+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56373+ gr_auth_expires = 0;
56374+ gr_auth_attempts = 0;
56375+ }
56376+
56377+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56378+ error = -EFAULT;
56379+ goto out;
56380+ }
56381+
56382+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56383+ error = -EINVAL;
56384+ goto out;
56385+ }
56386+
56387+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56388+ error = -EFAULT;
56389+ goto out;
56390+ }
56391+
56392+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56393+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56394+ time_after(gr_auth_expires, get_seconds())) {
56395+ error = -EBUSY;
56396+ goto out;
56397+ }
56398+
56399+ /* if non-root trying to do anything other than use a special role,
56400+ do not attempt authentication, do not count towards authentication
56401+ locking
56402+ */
56403+
56404+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56405+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56406+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56407+ error = -EPERM;
56408+ goto out;
56409+ }
56410+
56411+ /* ensure pw and special role name are null terminated */
56412+
56413+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56414+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56415+
56416+ /* Okay.
56417+ * We have our enough of the argument structure..(we have yet
56418+ * to copy_from_user the tables themselves) . Copy the tables
56419+ * only if we need them, i.e. for loading operations. */
56420+
56421+ switch (gr_usermode->mode) {
56422+ case GR_STATUS:
56423+ if (gr_status & GR_READY) {
56424+ error = 1;
56425+ if (!gr_check_secure_terminal(current))
56426+ error = 3;
56427+ } else
56428+ error = 2;
56429+ goto out;
56430+ case GR_SHUTDOWN:
56431+ if ((gr_status & GR_READY)
56432+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56433+ stop_machine(gr_rbac_disable, NULL, NULL);
56434+ free_variables();
56435+ memset(gr_usermode, 0, sizeof (struct gr_arg));
56436+ memset(gr_system_salt, 0, GR_SALT_LEN);
56437+ memset(gr_system_sum, 0, GR_SHA_LEN);
56438+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56439+ } else if (gr_status & GR_READY) {
56440+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56441+ error = -EPERM;
56442+ } else {
56443+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56444+ error = -EAGAIN;
56445+ }
56446+ break;
56447+ case GR_ENABLE:
56448+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56449+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56450+ else {
56451+ if (gr_status & GR_READY)
56452+ error = -EAGAIN;
56453+ else
56454+ error = error2;
56455+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56456+ }
56457+ break;
56458+ case GR_RELOAD:
56459+ if (!(gr_status & GR_READY)) {
56460+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56461+ error = -EAGAIN;
56462+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56463+ stop_machine(gr_rbac_disable, NULL, NULL);
56464+ free_variables();
56465+ error2 = gracl_init(gr_usermode);
56466+ if (!error2)
56467+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56468+ else {
56469+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56470+ error = error2;
56471+ }
56472+ } else {
56473+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56474+ error = -EPERM;
56475+ }
56476+ break;
56477+ case GR_SEGVMOD:
56478+ if (unlikely(!(gr_status & GR_READY))) {
56479+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56480+ error = -EAGAIN;
56481+ break;
56482+ }
56483+
56484+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56485+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56486+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56487+ struct acl_subject_label *segvacl;
56488+ segvacl =
56489+ lookup_acl_subj_label(gr_usermode->segv_inode,
56490+ gr_usermode->segv_device,
56491+ current->role);
56492+ if (segvacl) {
56493+ segvacl->crashes = 0;
56494+ segvacl->expires = 0;
56495+ }
56496+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56497+ gr_remove_uid(gr_usermode->segv_uid);
56498+ }
56499+ } else {
56500+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56501+ error = -EPERM;
56502+ }
56503+ break;
56504+ case GR_SPROLE:
56505+ case GR_SPROLEPAM:
56506+ if (unlikely(!(gr_status & GR_READY))) {
56507+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56508+ error = -EAGAIN;
56509+ break;
56510+ }
56511+
56512+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56513+ current->role->expires = 0;
56514+ current->role->auth_attempts = 0;
56515+ }
56516+
56517+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56518+ time_after(current->role->expires, get_seconds())) {
56519+ error = -EBUSY;
56520+ goto out;
56521+ }
56522+
56523+ if (lookup_special_role_auth
56524+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56525+ && ((!sprole_salt && !sprole_sum)
56526+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56527+ char *p = "";
56528+ assign_special_role(gr_usermode->sp_role);
56529+ read_lock(&tasklist_lock);
56530+ if (current->real_parent)
56531+ p = current->real_parent->role->rolename;
56532+ read_unlock(&tasklist_lock);
56533+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56534+ p, acl_sp_role_value);
56535+ } else {
56536+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56537+ error = -EPERM;
56538+ if(!(current->role->auth_attempts++))
56539+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56540+
56541+ goto out;
56542+ }
56543+ break;
56544+ case GR_UNSPROLE:
56545+ if (unlikely(!(gr_status & GR_READY))) {
56546+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56547+ error = -EAGAIN;
56548+ break;
56549+ }
56550+
56551+ if (current->role->roletype & GR_ROLE_SPECIAL) {
56552+ char *p = "";
56553+ int i = 0;
56554+
56555+ read_lock(&tasklist_lock);
56556+ if (current->real_parent) {
56557+ p = current->real_parent->role->rolename;
56558+ i = current->real_parent->acl_role_id;
56559+ }
56560+ read_unlock(&tasklist_lock);
56561+
56562+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56563+ gr_set_acls(1);
56564+ } else {
56565+ error = -EPERM;
56566+ goto out;
56567+ }
56568+ break;
56569+ default:
56570+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56571+ error = -EINVAL;
56572+ break;
56573+ }
56574+
56575+ if (error != -EPERM)
56576+ goto out;
56577+
56578+ if(!(gr_auth_attempts++))
56579+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56580+
56581+ out:
56582+ mutex_unlock(&gr_dev_mutex);
56583+ return error;
56584+}
56585+
56586+/* must be called with
56587+ rcu_read_lock();
56588+ read_lock(&tasklist_lock);
56589+ read_lock(&grsec_exec_file_lock);
56590+*/
56591+int gr_apply_subject_to_task(struct task_struct *task)
56592+{
56593+ struct acl_object_label *obj;
56594+ char *tmpname;
56595+ struct acl_subject_label *tmpsubj;
56596+ struct file *filp;
56597+ struct name_entry *nmatch;
56598+
56599+ filp = task->exec_file;
56600+ if (filp == NULL)
56601+ return 0;
56602+
56603+ /* the following is to apply the correct subject
56604+ on binaries running when the RBAC system
56605+ is enabled, when the binaries have been
56606+ replaced or deleted since their execution
56607+ -----
56608+ when the RBAC system starts, the inode/dev
56609+ from exec_file will be one the RBAC system
56610+ is unaware of. It only knows the inode/dev
56611+ of the present file on disk, or the absence
56612+ of it.
56613+ */
56614+ preempt_disable();
56615+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56616+
56617+ nmatch = lookup_name_entry(tmpname);
56618+ preempt_enable();
56619+ tmpsubj = NULL;
56620+ if (nmatch) {
56621+ if (nmatch->deleted)
56622+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56623+ else
56624+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56625+ if (tmpsubj != NULL)
56626+ task->acl = tmpsubj;
56627+ }
56628+ if (tmpsubj == NULL)
56629+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56630+ task->role);
56631+ if (task->acl) {
56632+ task->is_writable = 0;
56633+ /* ignore additional mmap checks for processes that are writable
56634+ by the default ACL */
56635+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56636+ if (unlikely(obj->mode & GR_WRITE))
56637+ task->is_writable = 1;
56638+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56639+ if (unlikely(obj->mode & GR_WRITE))
56640+ task->is_writable = 1;
56641+
56642+ gr_set_proc_res(task);
56643+
56644+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56645+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56646+#endif
56647+ } else {
56648+ return 1;
56649+ }
56650+
56651+ return 0;
56652+}
56653+
56654+int
56655+gr_set_acls(const int type)
56656+{
56657+ struct task_struct *task, *task2;
56658+ struct acl_role_label *role = current->role;
56659+ __u16 acl_role_id = current->acl_role_id;
56660+ const struct cred *cred;
56661+ int ret;
56662+
56663+ rcu_read_lock();
56664+ read_lock(&tasklist_lock);
56665+ read_lock(&grsec_exec_file_lock);
56666+ do_each_thread(task2, task) {
56667+ /* check to see if we're called from the exit handler,
56668+ if so, only replace ACLs that have inherited the admin
56669+ ACL */
56670+
56671+ if (type && (task->role != role ||
56672+ task->acl_role_id != acl_role_id))
56673+ continue;
56674+
56675+ task->acl_role_id = 0;
56676+ task->acl_sp_role = 0;
56677+
56678+ if (task->exec_file) {
56679+ cred = __task_cred(task);
56680+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56681+ ret = gr_apply_subject_to_task(task);
56682+ if (ret) {
56683+ read_unlock(&grsec_exec_file_lock);
56684+ read_unlock(&tasklist_lock);
56685+ rcu_read_unlock();
56686+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56687+ return ret;
56688+ }
56689+ } else {
56690+ // it's a kernel process
56691+ task->role = kernel_role;
56692+ task->acl = kernel_role->root_label;
56693+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56694+ task->acl->mode &= ~GR_PROCFIND;
56695+#endif
56696+ }
56697+ } while_each_thread(task2, task);
56698+ read_unlock(&grsec_exec_file_lock);
56699+ read_unlock(&tasklist_lock);
56700+ rcu_read_unlock();
56701+
56702+ return 0;
56703+}
56704+
56705+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
56706+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
56707+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
56708+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
56709+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
56710+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
56711+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
56712+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
56713+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
56714+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
56715+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
56716+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
56717+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
56718+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
56719+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
56720+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
56721+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
56722+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
56723+};
56724+
56725+void
56726+gr_learn_resource(const struct task_struct *task,
56727+ const int res, const unsigned long wanted, const int gt)
56728+{
56729+ struct acl_subject_label *acl;
56730+ const struct cred *cred;
56731+
56732+ if (unlikely((gr_status & GR_READY) &&
56733+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56734+ goto skip_reslog;
56735+
56736+ gr_log_resource(task, res, wanted, gt);
56737+skip_reslog:
56738+
56739+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56740+ return;
56741+
56742+ acl = task->acl;
56743+
56744+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56745+ !(acl->resmask & (1 << (unsigned short) res))))
56746+ return;
56747+
56748+ if (wanted >= acl->res[res].rlim_cur) {
56749+ unsigned long res_add;
56750+
56751+ res_add = wanted + res_learn_bumps[res];
56752+
56753+ acl->res[res].rlim_cur = res_add;
56754+
56755+ if (wanted > acl->res[res].rlim_max)
56756+ acl->res[res].rlim_max = res_add;
56757+
56758+ /* only log the subject filename, since resource logging is supported for
56759+ single-subject learning only */
56760+ rcu_read_lock();
56761+ cred = __task_cred(task);
56762+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56763+ task->role->roletype, cred->uid, cred->gid, acl->filename,
56764+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56765+ "", (unsigned long) res, &task->signal->saved_ip);
56766+ rcu_read_unlock();
56767+ }
56768+
56769+ return;
56770+}
56771+EXPORT_SYMBOL(gr_learn_resource);
56772+#endif
56773+
56774+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56775+void
56776+pax_set_initial_flags(struct linux_binprm *bprm)
56777+{
56778+ struct task_struct *task = current;
56779+ struct acl_subject_label *proc;
56780+ unsigned long flags;
56781+
56782+ if (unlikely(!(gr_status & GR_READY)))
56783+ return;
56784+
56785+ flags = pax_get_flags(task);
56786+
56787+ proc = task->acl;
56788+
56789+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
56790+ flags &= ~MF_PAX_PAGEEXEC;
56791+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
56792+ flags &= ~MF_PAX_SEGMEXEC;
56793+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
56794+ flags &= ~MF_PAX_RANDMMAP;
56795+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
56796+ flags &= ~MF_PAX_EMUTRAMP;
56797+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
56798+ flags &= ~MF_PAX_MPROTECT;
56799+
56800+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
56801+ flags |= MF_PAX_PAGEEXEC;
56802+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
56803+ flags |= MF_PAX_SEGMEXEC;
56804+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
56805+ flags |= MF_PAX_RANDMMAP;
56806+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
56807+ flags |= MF_PAX_EMUTRAMP;
56808+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
56809+ flags |= MF_PAX_MPROTECT;
56810+
56811+ pax_set_flags(task, flags);
56812+
56813+ return;
56814+}
56815+#endif
56816+
56817+int
56818+gr_handle_proc_ptrace(struct task_struct *task)
56819+{
56820+ struct file *filp;
56821+ struct task_struct *tmp = task;
56822+ struct task_struct *curtemp = current;
56823+ __u32 retmode;
56824+
56825+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56826+ if (unlikely(!(gr_status & GR_READY)))
56827+ return 0;
56828+#endif
56829+
56830+ read_lock(&tasklist_lock);
56831+ read_lock(&grsec_exec_file_lock);
56832+ filp = task->exec_file;
56833+
56834+ while (tmp->pid > 0) {
56835+ if (tmp == curtemp)
56836+ break;
56837+ tmp = tmp->real_parent;
56838+ }
56839+
56840+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56841+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
56842+ read_unlock(&grsec_exec_file_lock);
56843+ read_unlock(&tasklist_lock);
56844+ return 1;
56845+ }
56846+
56847+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56848+ if (!(gr_status & GR_READY)) {
56849+ read_unlock(&grsec_exec_file_lock);
56850+ read_unlock(&tasklist_lock);
56851+ return 0;
56852+ }
56853+#endif
56854+
56855+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
56856+ read_unlock(&grsec_exec_file_lock);
56857+ read_unlock(&tasklist_lock);
56858+
56859+ if (retmode & GR_NOPTRACE)
56860+ return 1;
56861+
56862+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
56863+ && (current->acl != task->acl || (current->acl != current->role->root_label
56864+ && current->pid != task->pid)))
56865+ return 1;
56866+
56867+ return 0;
56868+}
56869+
56870+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
56871+{
56872+ if (unlikely(!(gr_status & GR_READY)))
56873+ return;
56874+
56875+ if (!(current->role->roletype & GR_ROLE_GOD))
56876+ return;
56877+
56878+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
56879+ p->role->rolename, gr_task_roletype_to_char(p),
56880+ p->acl->filename);
56881+}
56882+
56883+int
56884+gr_handle_ptrace(struct task_struct *task, const long request)
56885+{
56886+ struct task_struct *tmp = task;
56887+ struct task_struct *curtemp = current;
56888+ __u32 retmode;
56889+
56890+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56891+ if (unlikely(!(gr_status & GR_READY)))
56892+ return 0;
56893+#endif
56894+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
56895+ read_lock(&tasklist_lock);
56896+ while (tmp->pid > 0) {
56897+ if (tmp == curtemp)
56898+ break;
56899+ tmp = tmp->real_parent;
56900+ }
56901+
56902+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56903+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
56904+ read_unlock(&tasklist_lock);
56905+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56906+ return 1;
56907+ }
56908+ read_unlock(&tasklist_lock);
56909+ }
56910+
56911+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56912+ if (!(gr_status & GR_READY))
56913+ return 0;
56914+#endif
56915+
56916+ read_lock(&grsec_exec_file_lock);
56917+ if (unlikely(!task->exec_file)) {
56918+ read_unlock(&grsec_exec_file_lock);
56919+ return 0;
56920+ }
56921+
56922+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
56923+ read_unlock(&grsec_exec_file_lock);
56924+
56925+ if (retmode & GR_NOPTRACE) {
56926+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56927+ return 1;
56928+ }
56929+
56930+ if (retmode & GR_PTRACERD) {
56931+ switch (request) {
56932+ case PTRACE_SEIZE:
56933+ case PTRACE_POKETEXT:
56934+ case PTRACE_POKEDATA:
56935+ case PTRACE_POKEUSR:
56936+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
56937+ case PTRACE_SETREGS:
56938+ case PTRACE_SETFPREGS:
56939+#endif
56940+#ifdef CONFIG_X86
56941+ case PTRACE_SETFPXREGS:
56942+#endif
56943+#ifdef CONFIG_ALTIVEC
56944+ case PTRACE_SETVRREGS:
56945+#endif
56946+ return 1;
56947+ default:
56948+ return 0;
56949+ }
56950+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
56951+ !(current->role->roletype & GR_ROLE_GOD) &&
56952+ (current->acl != task->acl)) {
56953+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56954+ return 1;
56955+ }
56956+
56957+ return 0;
56958+}
56959+
56960+static int is_writable_mmap(const struct file *filp)
56961+{
56962+ struct task_struct *task = current;
56963+ struct acl_object_label *obj, *obj2;
56964+
56965+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
56966+ !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))) {
56967+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56968+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
56969+ task->role->root_label);
56970+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
56971+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
56972+ return 1;
56973+ }
56974+ }
56975+ return 0;
56976+}
56977+
56978+int
56979+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
56980+{
56981+ __u32 mode;
56982+
56983+ if (unlikely(!file || !(prot & PROT_EXEC)))
56984+ return 1;
56985+
56986+ if (is_writable_mmap(file))
56987+ return 0;
56988+
56989+ mode =
56990+ gr_search_file(file->f_path.dentry,
56991+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
56992+ file->f_path.mnt);
56993+
56994+ if (!gr_tpe_allow(file))
56995+ return 0;
56996+
56997+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
56998+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
56999+ return 0;
57000+ } else if (unlikely(!(mode & GR_EXEC))) {
57001+ return 0;
57002+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57003+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57004+ return 1;
57005+ }
57006+
57007+ return 1;
57008+}
57009+
57010+int
57011+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57012+{
57013+ __u32 mode;
57014+
57015+ if (unlikely(!file || !(prot & PROT_EXEC)))
57016+ return 1;
57017+
57018+ if (is_writable_mmap(file))
57019+ return 0;
57020+
57021+ mode =
57022+ gr_search_file(file->f_path.dentry,
57023+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57024+ file->f_path.mnt);
57025+
57026+ if (!gr_tpe_allow(file))
57027+ return 0;
57028+
57029+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57030+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57031+ return 0;
57032+ } else if (unlikely(!(mode & GR_EXEC))) {
57033+ return 0;
57034+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57035+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57036+ return 1;
57037+ }
57038+
57039+ return 1;
57040+}
57041+
57042+void
57043+gr_acl_handle_psacct(struct task_struct *task, const long code)
57044+{
57045+ unsigned long runtime;
57046+ unsigned long cputime;
57047+ unsigned int wday, cday;
57048+ __u8 whr, chr;
57049+ __u8 wmin, cmin;
57050+ __u8 wsec, csec;
57051+ struct timespec timeval;
57052+
57053+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57054+ !(task->acl->mode & GR_PROCACCT)))
57055+ return;
57056+
57057+ do_posix_clock_monotonic_gettime(&timeval);
57058+ runtime = timeval.tv_sec - task->start_time.tv_sec;
57059+ wday = runtime / (3600 * 24);
57060+ runtime -= wday * (3600 * 24);
57061+ whr = runtime / 3600;
57062+ runtime -= whr * 3600;
57063+ wmin = runtime / 60;
57064+ runtime -= wmin * 60;
57065+ wsec = runtime;
57066+
57067+ cputime = (task->utime + task->stime) / HZ;
57068+ cday = cputime / (3600 * 24);
57069+ cputime -= cday * (3600 * 24);
57070+ chr = cputime / 3600;
57071+ cputime -= chr * 3600;
57072+ cmin = cputime / 60;
57073+ cputime -= cmin * 60;
57074+ csec = cputime;
57075+
57076+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57077+
57078+ return;
57079+}
57080+
57081+void gr_set_kernel_label(struct task_struct *task)
57082+{
57083+ if (gr_status & GR_READY) {
57084+ task->role = kernel_role;
57085+ task->acl = kernel_role->root_label;
57086+ }
57087+ return;
57088+}
57089+
57090+#ifdef CONFIG_TASKSTATS
57091+int gr_is_taskstats_denied(int pid)
57092+{
57093+ struct task_struct *task;
57094+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57095+ const struct cred *cred;
57096+#endif
57097+ int ret = 0;
57098+
57099+ /* restrict taskstats viewing to un-chrooted root users
57100+ who have the 'view' subject flag if the RBAC system is enabled
57101+ */
57102+
57103+ rcu_read_lock();
57104+ read_lock(&tasklist_lock);
57105+ task = find_task_by_vpid(pid);
57106+ if (task) {
57107+#ifdef CONFIG_GRKERNSEC_CHROOT
57108+ if (proc_is_chrooted(task))
57109+ ret = -EACCES;
57110+#endif
57111+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57112+ cred = __task_cred(task);
57113+#ifdef CONFIG_GRKERNSEC_PROC_USER
57114+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57115+ ret = -EACCES;
57116+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57117+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57118+ ret = -EACCES;
57119+#endif
57120+#endif
57121+ if (gr_status & GR_READY) {
57122+ if (!(task->acl->mode & GR_VIEW))
57123+ ret = -EACCES;
57124+ }
57125+ } else
57126+ ret = -ENOENT;
57127+
57128+ read_unlock(&tasklist_lock);
57129+ rcu_read_unlock();
57130+
57131+ return ret;
57132+}
57133+#endif
57134+
57135+/* AUXV entries are filled via a descendant of search_binary_handler
57136+ after we've already applied the subject for the target
57137+*/
57138+int gr_acl_enable_at_secure(void)
57139+{
57140+ if (unlikely(!(gr_status & GR_READY)))
57141+ return 0;
57142+
57143+ if (current->acl->mode & GR_ATSECURE)
57144+ return 1;
57145+
57146+ return 0;
57147+}
57148+
57149+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57150+{
57151+ struct task_struct *task = current;
57152+ struct dentry *dentry = file->f_path.dentry;
57153+ struct vfsmount *mnt = file->f_path.mnt;
57154+ struct acl_object_label *obj, *tmp;
57155+ struct acl_subject_label *subj;
57156+ unsigned int bufsize;
57157+ int is_not_root;
57158+ char *path;
57159+ dev_t dev = __get_dev(dentry);
57160+
57161+ if (unlikely(!(gr_status & GR_READY)))
57162+ return 1;
57163+
57164+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57165+ return 1;
57166+
57167+ /* ignore Eric Biederman */
57168+ if (IS_PRIVATE(dentry->d_inode))
57169+ return 1;
57170+
57171+ subj = task->acl;
57172+ read_lock(&gr_inode_lock);
57173+ do {
57174+ obj = lookup_acl_obj_label(ino, dev, subj);
57175+ if (obj != NULL) {
57176+ read_unlock(&gr_inode_lock);
57177+ return (obj->mode & GR_FIND) ? 1 : 0;
57178+ }
57179+ } while ((subj = subj->parent_subject));
57180+ read_unlock(&gr_inode_lock);
57181+
57182+ /* this is purely an optimization since we're looking for an object
57183+ for the directory we're doing a readdir on
57184+ if it's possible for any globbed object to match the entry we're
57185+ filling into the directory, then the object we find here will be
57186+ an anchor point with attached globbed objects
57187+ */
57188+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57189+ if (obj->globbed == NULL)
57190+ return (obj->mode & GR_FIND) ? 1 : 0;
57191+
57192+ is_not_root = ((obj->filename[0] == '/') &&
57193+ (obj->filename[1] == '\0')) ? 0 : 1;
57194+ bufsize = PAGE_SIZE - namelen - is_not_root;
57195+
57196+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
57197+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57198+ return 1;
57199+
57200+ preempt_disable();
57201+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57202+ bufsize);
57203+
57204+ bufsize = strlen(path);
57205+
57206+ /* if base is "/", don't append an additional slash */
57207+ if (is_not_root)
57208+ *(path + bufsize) = '/';
57209+ memcpy(path + bufsize + is_not_root, name, namelen);
57210+ *(path + bufsize + namelen + is_not_root) = '\0';
57211+
57212+ tmp = obj->globbed;
57213+ while (tmp) {
57214+ if (!glob_match(tmp->filename, path)) {
57215+ preempt_enable();
57216+ return (tmp->mode & GR_FIND) ? 1 : 0;
57217+ }
57218+ tmp = tmp->next;
57219+ }
57220+ preempt_enable();
57221+ return (obj->mode & GR_FIND) ? 1 : 0;
57222+}
57223+
57224+void gr_put_exec_file(struct task_struct *task)
57225+{
57226+ struct file *filp;
57227+
57228+ write_lock(&grsec_exec_file_lock);
57229+ filp = task->exec_file;
57230+ task->exec_file = NULL;
57231+ write_unlock(&grsec_exec_file_lock);
57232+
57233+ if (filp)
57234+ fput(filp);
57235+
57236+ return;
57237+}
57238+
57239+
57240+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57241+EXPORT_SYMBOL(gr_acl_is_enabled);
57242+#endif
57243+EXPORT_SYMBOL(gr_set_kernel_label);
57244+#ifdef CONFIG_SECURITY
57245+EXPORT_SYMBOL(gr_check_user_change);
57246+EXPORT_SYMBOL(gr_check_group_change);
57247+#endif
57248+
57249diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57250new file mode 100644
57251index 0000000..34fefda
57252--- /dev/null
57253+++ b/grsecurity/gracl_alloc.c
57254@@ -0,0 +1,105 @@
57255+#include <linux/kernel.h>
57256+#include <linux/mm.h>
57257+#include <linux/slab.h>
57258+#include <linux/vmalloc.h>
57259+#include <linux/gracl.h>
57260+#include <linux/grsecurity.h>
57261+
57262+static unsigned long alloc_stack_next = 1;
57263+static unsigned long alloc_stack_size = 1;
57264+static void **alloc_stack;
57265+
57266+static __inline__ int
57267+alloc_pop(void)
57268+{
57269+ if (alloc_stack_next == 1)
57270+ return 0;
57271+
57272+ kfree(alloc_stack[alloc_stack_next - 2]);
57273+
57274+ alloc_stack_next--;
57275+
57276+ return 1;
57277+}
57278+
57279+static __inline__ int
57280+alloc_push(void *buf)
57281+{
57282+ if (alloc_stack_next >= alloc_stack_size)
57283+ return 1;
57284+
57285+ alloc_stack[alloc_stack_next - 1] = buf;
57286+
57287+ alloc_stack_next++;
57288+
57289+ return 0;
57290+}
57291+
57292+void *
57293+acl_alloc(unsigned long len)
57294+{
57295+ void *ret = NULL;
57296+
57297+ if (!len || len > PAGE_SIZE)
57298+ goto out;
57299+
57300+ ret = kmalloc(len, GFP_KERNEL);
57301+
57302+ if (ret) {
57303+ if (alloc_push(ret)) {
57304+ kfree(ret);
57305+ ret = NULL;
57306+ }
57307+ }
57308+
57309+out:
57310+ return ret;
57311+}
57312+
57313+void *
57314+acl_alloc_num(unsigned long num, unsigned long len)
57315+{
57316+ if (!len || (num > (PAGE_SIZE / len)))
57317+ return NULL;
57318+
57319+ return acl_alloc(num * len);
57320+}
57321+
57322+void
57323+acl_free_all(void)
57324+{
57325+ if (gr_acl_is_enabled() || !alloc_stack)
57326+ return;
57327+
57328+ while (alloc_pop()) ;
57329+
57330+ if (alloc_stack) {
57331+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57332+ kfree(alloc_stack);
57333+ else
57334+ vfree(alloc_stack);
57335+ }
57336+
57337+ alloc_stack = NULL;
57338+ alloc_stack_size = 1;
57339+ alloc_stack_next = 1;
57340+
57341+ return;
57342+}
57343+
57344+int
57345+acl_alloc_stack_init(unsigned long size)
57346+{
57347+ if ((size * sizeof (void *)) <= PAGE_SIZE)
57348+ alloc_stack =
57349+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57350+ else
57351+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
57352+
57353+ alloc_stack_size = size;
57354+
57355+ if (!alloc_stack)
57356+ return 0;
57357+ else
57358+ return 1;
57359+}
57360diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57361new file mode 100644
57362index 0000000..6d21049
57363--- /dev/null
57364+++ b/grsecurity/gracl_cap.c
57365@@ -0,0 +1,110 @@
57366+#include <linux/kernel.h>
57367+#include <linux/module.h>
57368+#include <linux/sched.h>
57369+#include <linux/gracl.h>
57370+#include <linux/grsecurity.h>
57371+#include <linux/grinternal.h>
57372+
57373+extern const char *captab_log[];
57374+extern int captab_log_entries;
57375+
57376+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57377+{
57378+ struct acl_subject_label *curracl;
57379+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57380+ kernel_cap_t cap_audit = __cap_empty_set;
57381+
57382+ if (!gr_acl_is_enabled())
57383+ return 1;
57384+
57385+ curracl = task->acl;
57386+
57387+ cap_drop = curracl->cap_lower;
57388+ cap_mask = curracl->cap_mask;
57389+ cap_audit = curracl->cap_invert_audit;
57390+
57391+ while ((curracl = curracl->parent_subject)) {
57392+ /* if the cap isn't specified in the current computed mask but is specified in the
57393+ current level subject, and is lowered in the current level subject, then add
57394+ it to the set of dropped capabilities
57395+ otherwise, add the current level subject's mask to the current computed mask
57396+ */
57397+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57398+ cap_raise(cap_mask, cap);
57399+ if (cap_raised(curracl->cap_lower, cap))
57400+ cap_raise(cap_drop, cap);
57401+ if (cap_raised(curracl->cap_invert_audit, cap))
57402+ cap_raise(cap_audit, cap);
57403+ }
57404+ }
57405+
57406+ if (!cap_raised(cap_drop, cap)) {
57407+ if (cap_raised(cap_audit, cap))
57408+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57409+ return 1;
57410+ }
57411+
57412+ curracl = task->acl;
57413+
57414+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57415+ && cap_raised(cred->cap_effective, cap)) {
57416+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57417+ task->role->roletype, cred->uid,
57418+ cred->gid, task->exec_file ?
57419+ gr_to_filename(task->exec_file->f_path.dentry,
57420+ task->exec_file->f_path.mnt) : curracl->filename,
57421+ curracl->filename, 0UL,
57422+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57423+ return 1;
57424+ }
57425+
57426+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57427+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57428+
57429+ return 0;
57430+}
57431+
57432+int
57433+gr_acl_is_capable(const int cap)
57434+{
57435+ return gr_task_acl_is_capable(current, current_cred(), cap);
57436+}
57437+
57438+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57439+{
57440+ struct acl_subject_label *curracl;
57441+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57442+
57443+ if (!gr_acl_is_enabled())
57444+ return 1;
57445+
57446+ curracl = task->acl;
57447+
57448+ cap_drop = curracl->cap_lower;
57449+ cap_mask = curracl->cap_mask;
57450+
57451+ while ((curracl = curracl->parent_subject)) {
57452+ /* if the cap isn't specified in the current computed mask but is specified in the
57453+ current level subject, and is lowered in the current level subject, then add
57454+ it to the set of dropped capabilities
57455+ otherwise, add the current level subject's mask to the current computed mask
57456+ */
57457+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57458+ cap_raise(cap_mask, cap);
57459+ if (cap_raised(curracl->cap_lower, cap))
57460+ cap_raise(cap_drop, cap);
57461+ }
57462+ }
57463+
57464+ if (!cap_raised(cap_drop, cap))
57465+ return 1;
57466+
57467+ return 0;
57468+}
57469+
57470+int
57471+gr_acl_is_capable_nolog(const int cap)
57472+{
57473+ return gr_task_acl_is_capable_nolog(current, cap);
57474+}
57475+
57476diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57477new file mode 100644
57478index 0000000..a340c17
57479--- /dev/null
57480+++ b/grsecurity/gracl_fs.c
57481@@ -0,0 +1,431 @@
57482+#include <linux/kernel.h>
57483+#include <linux/sched.h>
57484+#include <linux/types.h>
57485+#include <linux/fs.h>
57486+#include <linux/file.h>
57487+#include <linux/stat.h>
57488+#include <linux/grsecurity.h>
57489+#include <linux/grinternal.h>
57490+#include <linux/gracl.h>
57491+
57492+umode_t
57493+gr_acl_umask(void)
57494+{
57495+ if (unlikely(!gr_acl_is_enabled()))
57496+ return 0;
57497+
57498+ return current->role->umask;
57499+}
57500+
57501+__u32
57502+gr_acl_handle_hidden_file(const struct dentry * dentry,
57503+ const struct vfsmount * mnt)
57504+{
57505+ __u32 mode;
57506+
57507+ if (unlikely(!dentry->d_inode))
57508+ return GR_FIND;
57509+
57510+ mode =
57511+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57512+
57513+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57514+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57515+ return mode;
57516+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57517+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57518+ return 0;
57519+ } else if (unlikely(!(mode & GR_FIND)))
57520+ return 0;
57521+
57522+ return GR_FIND;
57523+}
57524+
57525+__u32
57526+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57527+ int acc_mode)
57528+{
57529+ __u32 reqmode = GR_FIND;
57530+ __u32 mode;
57531+
57532+ if (unlikely(!dentry->d_inode))
57533+ return reqmode;
57534+
57535+ if (acc_mode & MAY_APPEND)
57536+ reqmode |= GR_APPEND;
57537+ else if (acc_mode & MAY_WRITE)
57538+ reqmode |= GR_WRITE;
57539+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57540+ reqmode |= GR_READ;
57541+
57542+ mode =
57543+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57544+ mnt);
57545+
57546+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57547+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57548+ reqmode & GR_READ ? " reading" : "",
57549+ reqmode & GR_WRITE ? " writing" : reqmode &
57550+ GR_APPEND ? " appending" : "");
57551+ return reqmode;
57552+ } else
57553+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57554+ {
57555+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57556+ reqmode & GR_READ ? " reading" : "",
57557+ reqmode & GR_WRITE ? " writing" : reqmode &
57558+ GR_APPEND ? " appending" : "");
57559+ return 0;
57560+ } else if (unlikely((mode & reqmode) != reqmode))
57561+ return 0;
57562+
57563+ return reqmode;
57564+}
57565+
57566+__u32
57567+gr_acl_handle_creat(const struct dentry * dentry,
57568+ const struct dentry * p_dentry,
57569+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57570+ const int imode)
57571+{
57572+ __u32 reqmode = GR_WRITE | GR_CREATE;
57573+ __u32 mode;
57574+
57575+ if (acc_mode & MAY_APPEND)
57576+ reqmode |= GR_APPEND;
57577+ // if a directory was required or the directory already exists, then
57578+ // don't count this open as a read
57579+ if ((acc_mode & MAY_READ) &&
57580+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57581+ reqmode |= GR_READ;
57582+ if ((open_flags & O_CREAT) &&
57583+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57584+ reqmode |= GR_SETID;
57585+
57586+ mode =
57587+ gr_check_create(dentry, p_dentry, p_mnt,
57588+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57589+
57590+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57591+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57592+ reqmode & GR_READ ? " reading" : "",
57593+ reqmode & GR_WRITE ? " writing" : reqmode &
57594+ GR_APPEND ? " appending" : "");
57595+ return reqmode;
57596+ } else
57597+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57598+ {
57599+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57600+ reqmode & GR_READ ? " reading" : "",
57601+ reqmode & GR_WRITE ? " writing" : reqmode &
57602+ GR_APPEND ? " appending" : "");
57603+ return 0;
57604+ } else if (unlikely((mode & reqmode) != reqmode))
57605+ return 0;
57606+
57607+ return reqmode;
57608+}
57609+
57610+__u32
57611+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57612+ const int fmode)
57613+{
57614+ __u32 mode, reqmode = GR_FIND;
57615+
57616+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57617+ reqmode |= GR_EXEC;
57618+ if (fmode & S_IWOTH)
57619+ reqmode |= GR_WRITE;
57620+ if (fmode & S_IROTH)
57621+ reqmode |= GR_READ;
57622+
57623+ mode =
57624+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57625+ mnt);
57626+
57627+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57628+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57629+ reqmode & GR_READ ? " reading" : "",
57630+ reqmode & GR_WRITE ? " writing" : "",
57631+ reqmode & GR_EXEC ? " executing" : "");
57632+ return reqmode;
57633+ } else
57634+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57635+ {
57636+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57637+ reqmode & GR_READ ? " reading" : "",
57638+ reqmode & GR_WRITE ? " writing" : "",
57639+ reqmode & GR_EXEC ? " executing" : "");
57640+ return 0;
57641+ } else if (unlikely((mode & reqmode) != reqmode))
57642+ return 0;
57643+
57644+ return reqmode;
57645+}
57646+
57647+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57648+{
57649+ __u32 mode;
57650+
57651+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57652+
57653+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57654+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57655+ return mode;
57656+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57657+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57658+ return 0;
57659+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57660+ return 0;
57661+
57662+ return (reqmode);
57663+}
57664+
57665+__u32
57666+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57667+{
57668+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57669+}
57670+
57671+__u32
57672+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57673+{
57674+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57675+}
57676+
57677+__u32
57678+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57679+{
57680+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57681+}
57682+
57683+__u32
57684+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57685+{
57686+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57687+}
57688+
57689+__u32
57690+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57691+ umode_t *modeptr)
57692+{
57693+ umode_t mode;
57694+
57695+ *modeptr &= ~gr_acl_umask();
57696+ mode = *modeptr;
57697+
57698+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57699+ return 1;
57700+
57701+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57702+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57703+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57704+ GR_CHMOD_ACL_MSG);
57705+ } else {
57706+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57707+ }
57708+}
57709+
57710+__u32
57711+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57712+{
57713+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57714+}
57715+
57716+__u32
57717+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57718+{
57719+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57720+}
57721+
57722+__u32
57723+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57724+{
57725+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57726+}
57727+
57728+__u32
57729+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57730+{
57731+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57732+ GR_UNIXCONNECT_ACL_MSG);
57733+}
57734+
57735+/* hardlinks require at minimum create and link permission,
57736+ any additional privilege required is based on the
57737+ privilege of the file being linked to
57738+*/
57739+__u32
57740+gr_acl_handle_link(const struct dentry * new_dentry,
57741+ const struct dentry * parent_dentry,
57742+ const struct vfsmount * parent_mnt,
57743+ const struct dentry * old_dentry,
57744+ const struct vfsmount * old_mnt, const struct filename *to)
57745+{
57746+ __u32 mode;
57747+ __u32 needmode = GR_CREATE | GR_LINK;
57748+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57749+
57750+ mode =
57751+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57752+ old_mnt);
57753+
57754+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57755+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57756+ return mode;
57757+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57758+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57759+ return 0;
57760+ } else if (unlikely((mode & needmode) != needmode))
57761+ return 0;
57762+
57763+ return 1;
57764+}
57765+
57766+__u32
57767+gr_acl_handle_symlink(const struct dentry * new_dentry,
57768+ const struct dentry * parent_dentry,
57769+ const struct vfsmount * parent_mnt, const struct filename *from)
57770+{
57771+ __u32 needmode = GR_WRITE | GR_CREATE;
57772+ __u32 mode;
57773+
57774+ mode =
57775+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
57776+ GR_CREATE | GR_AUDIT_CREATE |
57777+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57778+
57779+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57780+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57781+ return mode;
57782+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57783+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57784+ return 0;
57785+ } else if (unlikely((mode & needmode) != needmode))
57786+ return 0;
57787+
57788+ return (GR_WRITE | GR_CREATE);
57789+}
57790+
57791+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)
57792+{
57793+ __u32 mode;
57794+
57795+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57796+
57797+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57798+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
57799+ return mode;
57800+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57801+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
57802+ return 0;
57803+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57804+ return 0;
57805+
57806+ return (reqmode);
57807+}
57808+
57809+__u32
57810+gr_acl_handle_mknod(const struct dentry * new_dentry,
57811+ const struct dentry * parent_dentry,
57812+ const struct vfsmount * parent_mnt,
57813+ const int mode)
57814+{
57815+ __u32 reqmode = GR_WRITE | GR_CREATE;
57816+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57817+ reqmode |= GR_SETID;
57818+
57819+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57820+ reqmode, GR_MKNOD_ACL_MSG);
57821+}
57822+
57823+__u32
57824+gr_acl_handle_mkdir(const struct dentry *new_dentry,
57825+ const struct dentry *parent_dentry,
57826+ const struct vfsmount *parent_mnt)
57827+{
57828+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57829+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
57830+}
57831+
57832+#define RENAME_CHECK_SUCCESS(old, new) \
57833+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
57834+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
57835+
57836+int
57837+gr_acl_handle_rename(struct dentry *new_dentry,
57838+ struct dentry *parent_dentry,
57839+ const struct vfsmount *parent_mnt,
57840+ struct dentry *old_dentry,
57841+ struct inode *old_parent_inode,
57842+ struct vfsmount *old_mnt, const struct filename *newname)
57843+{
57844+ __u32 comp1, comp2;
57845+ int error = 0;
57846+
57847+ if (unlikely(!gr_acl_is_enabled()))
57848+ return 0;
57849+
57850+ if (!new_dentry->d_inode) {
57851+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
57852+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
57853+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
57854+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
57855+ GR_DELETE | GR_AUDIT_DELETE |
57856+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57857+ GR_SUPPRESS, old_mnt);
57858+ } else {
57859+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
57860+ GR_CREATE | GR_DELETE |
57861+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
57862+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57863+ GR_SUPPRESS, parent_mnt);
57864+ comp2 =
57865+ gr_search_file(old_dentry,
57866+ GR_READ | GR_WRITE | GR_AUDIT_READ |
57867+ GR_DELETE | GR_AUDIT_DELETE |
57868+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
57869+ }
57870+
57871+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
57872+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
57873+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57874+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
57875+ && !(comp2 & GR_SUPPRESS)) {
57876+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57877+ error = -EACCES;
57878+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
57879+ error = -EACCES;
57880+
57881+ return error;
57882+}
57883+
57884+void
57885+gr_acl_handle_exit(void)
57886+{
57887+ u16 id;
57888+ char *rolename;
57889+
57890+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
57891+ !(current->role->roletype & GR_ROLE_PERSIST))) {
57892+ id = current->acl_role_id;
57893+ rolename = current->role->rolename;
57894+ gr_set_acls(1);
57895+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
57896+ }
57897+
57898+ gr_put_exec_file(current);
57899+ return;
57900+}
57901+
57902+int
57903+gr_acl_handle_procpidmem(const struct task_struct *task)
57904+{
57905+ if (unlikely(!gr_acl_is_enabled()))
57906+ return 0;
57907+
57908+ if (task != current && task->acl->mode & GR_PROTPROCFD)
57909+ return -EACCES;
57910+
57911+ return 0;
57912+}
57913diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
57914new file mode 100644
57915index 0000000..58800a7
57916--- /dev/null
57917+++ b/grsecurity/gracl_ip.c
57918@@ -0,0 +1,384 @@
57919+#include <linux/kernel.h>
57920+#include <asm/uaccess.h>
57921+#include <asm/errno.h>
57922+#include <net/sock.h>
57923+#include <linux/file.h>
57924+#include <linux/fs.h>
57925+#include <linux/net.h>
57926+#include <linux/in.h>
57927+#include <linux/skbuff.h>
57928+#include <linux/ip.h>
57929+#include <linux/udp.h>
57930+#include <linux/types.h>
57931+#include <linux/sched.h>
57932+#include <linux/netdevice.h>
57933+#include <linux/inetdevice.h>
57934+#include <linux/gracl.h>
57935+#include <linux/grsecurity.h>
57936+#include <linux/grinternal.h>
57937+
57938+#define GR_BIND 0x01
57939+#define GR_CONNECT 0x02
57940+#define GR_INVERT 0x04
57941+#define GR_BINDOVERRIDE 0x08
57942+#define GR_CONNECTOVERRIDE 0x10
57943+#define GR_SOCK_FAMILY 0x20
57944+
57945+static const char * gr_protocols[IPPROTO_MAX] = {
57946+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
57947+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
57948+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
57949+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
57950+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
57951+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
57952+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
57953+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
57954+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
57955+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
57956+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
57957+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
57958+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
57959+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
57960+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
57961+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
57962+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
57963+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
57964+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
57965+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
57966+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
57967+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
57968+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
57969+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
57970+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
57971+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
57972+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
57973+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
57974+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
57975+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
57976+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
57977+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
57978+ };
57979+
57980+static const char * gr_socktypes[SOCK_MAX] = {
57981+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
57982+ "unknown:7", "unknown:8", "unknown:9", "packet"
57983+ };
57984+
57985+static const char * gr_sockfamilies[AF_MAX+1] = {
57986+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
57987+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
57988+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
57989+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
57990+ };
57991+
57992+const char *
57993+gr_proto_to_name(unsigned char proto)
57994+{
57995+ return gr_protocols[proto];
57996+}
57997+
57998+const char *
57999+gr_socktype_to_name(unsigned char type)
58000+{
58001+ return gr_socktypes[type];
58002+}
58003+
58004+const char *
58005+gr_sockfamily_to_name(unsigned char family)
58006+{
58007+ return gr_sockfamilies[family];
58008+}
58009+
58010+int
58011+gr_search_socket(const int domain, const int type, const int protocol)
58012+{
58013+ struct acl_subject_label *curr;
58014+ const struct cred *cred = current_cred();
58015+
58016+ if (unlikely(!gr_acl_is_enabled()))
58017+ goto exit;
58018+
58019+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
58020+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58021+ goto exit; // let the kernel handle it
58022+
58023+ curr = current->acl;
58024+
58025+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58026+ /* the family is allowed, if this is PF_INET allow it only if
58027+ the extra sock type/protocol checks pass */
58028+ if (domain == PF_INET)
58029+ goto inet_check;
58030+ goto exit;
58031+ } else {
58032+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58033+ __u32 fakeip = 0;
58034+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58035+ current->role->roletype, cred->uid,
58036+ cred->gid, current->exec_file ?
58037+ gr_to_filename(current->exec_file->f_path.dentry,
58038+ current->exec_file->f_path.mnt) :
58039+ curr->filename, curr->filename,
58040+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58041+ &current->signal->saved_ip);
58042+ goto exit;
58043+ }
58044+ goto exit_fail;
58045+ }
58046+
58047+inet_check:
58048+ /* the rest of this checking is for IPv4 only */
58049+ if (!curr->ips)
58050+ goto exit;
58051+
58052+ if ((curr->ip_type & (1 << type)) &&
58053+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58054+ goto exit;
58055+
58056+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58057+ /* we don't place acls on raw sockets , and sometimes
58058+ dgram/ip sockets are opened for ioctl and not
58059+ bind/connect, so we'll fake a bind learn log */
58060+ if (type == SOCK_RAW || type == SOCK_PACKET) {
58061+ __u32 fakeip = 0;
58062+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58063+ current->role->roletype, cred->uid,
58064+ cred->gid, current->exec_file ?
58065+ gr_to_filename(current->exec_file->f_path.dentry,
58066+ current->exec_file->f_path.mnt) :
58067+ curr->filename, curr->filename,
58068+ &fakeip, 0, type,
58069+ protocol, GR_CONNECT, &current->signal->saved_ip);
58070+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58071+ __u32 fakeip = 0;
58072+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58073+ current->role->roletype, cred->uid,
58074+ cred->gid, current->exec_file ?
58075+ gr_to_filename(current->exec_file->f_path.dentry,
58076+ current->exec_file->f_path.mnt) :
58077+ curr->filename, curr->filename,
58078+ &fakeip, 0, type,
58079+ protocol, GR_BIND, &current->signal->saved_ip);
58080+ }
58081+ /* we'll log when they use connect or bind */
58082+ goto exit;
58083+ }
58084+
58085+exit_fail:
58086+ if (domain == PF_INET)
58087+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58088+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
58089+ else
58090+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58091+ gr_socktype_to_name(type), protocol);
58092+
58093+ return 0;
58094+exit:
58095+ return 1;
58096+}
58097+
58098+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)
58099+{
58100+ if ((ip->mode & mode) &&
58101+ (ip_port >= ip->low) &&
58102+ (ip_port <= ip->high) &&
58103+ ((ntohl(ip_addr) & our_netmask) ==
58104+ (ntohl(our_addr) & our_netmask))
58105+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58106+ && (ip->type & (1 << type))) {
58107+ if (ip->mode & GR_INVERT)
58108+ return 2; // specifically denied
58109+ else
58110+ return 1; // allowed
58111+ }
58112+
58113+ return 0; // not specifically allowed, may continue parsing
58114+}
58115+
58116+static int
58117+gr_search_connectbind(const int full_mode, struct sock *sk,
58118+ struct sockaddr_in *addr, const int type)
58119+{
58120+ char iface[IFNAMSIZ] = {0};
58121+ struct acl_subject_label *curr;
58122+ struct acl_ip_label *ip;
58123+ struct inet_sock *isk;
58124+ struct net_device *dev;
58125+ struct in_device *idev;
58126+ unsigned long i;
58127+ int ret;
58128+ int mode = full_mode & (GR_BIND | GR_CONNECT);
58129+ __u32 ip_addr = 0;
58130+ __u32 our_addr;
58131+ __u32 our_netmask;
58132+ char *p;
58133+ __u16 ip_port = 0;
58134+ const struct cred *cred = current_cred();
58135+
58136+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58137+ return 0;
58138+
58139+ curr = current->acl;
58140+ isk = inet_sk(sk);
58141+
58142+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58143+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58144+ addr->sin_addr.s_addr = curr->inaddr_any_override;
58145+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58146+ struct sockaddr_in saddr;
58147+ int err;
58148+
58149+ saddr.sin_family = AF_INET;
58150+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
58151+ saddr.sin_port = isk->inet_sport;
58152+
58153+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58154+ if (err)
58155+ return err;
58156+
58157+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58158+ if (err)
58159+ return err;
58160+ }
58161+
58162+ if (!curr->ips)
58163+ return 0;
58164+
58165+ ip_addr = addr->sin_addr.s_addr;
58166+ ip_port = ntohs(addr->sin_port);
58167+
58168+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58169+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58170+ current->role->roletype, cred->uid,
58171+ cred->gid, current->exec_file ?
58172+ gr_to_filename(current->exec_file->f_path.dentry,
58173+ current->exec_file->f_path.mnt) :
58174+ curr->filename, curr->filename,
58175+ &ip_addr, ip_port, type,
58176+ sk->sk_protocol, mode, &current->signal->saved_ip);
58177+ return 0;
58178+ }
58179+
58180+ for (i = 0; i < curr->ip_num; i++) {
58181+ ip = *(curr->ips + i);
58182+ if (ip->iface != NULL) {
58183+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
58184+ p = strchr(iface, ':');
58185+ if (p != NULL)
58186+ *p = '\0';
58187+ dev = dev_get_by_name(sock_net(sk), iface);
58188+ if (dev == NULL)
58189+ continue;
58190+ idev = in_dev_get(dev);
58191+ if (idev == NULL) {
58192+ dev_put(dev);
58193+ continue;
58194+ }
58195+ rcu_read_lock();
58196+ for_ifa(idev) {
58197+ if (!strcmp(ip->iface, ifa->ifa_label)) {
58198+ our_addr = ifa->ifa_address;
58199+ our_netmask = 0xffffffff;
58200+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58201+ if (ret == 1) {
58202+ rcu_read_unlock();
58203+ in_dev_put(idev);
58204+ dev_put(dev);
58205+ return 0;
58206+ } else if (ret == 2) {
58207+ rcu_read_unlock();
58208+ in_dev_put(idev);
58209+ dev_put(dev);
58210+ goto denied;
58211+ }
58212+ }
58213+ } endfor_ifa(idev);
58214+ rcu_read_unlock();
58215+ in_dev_put(idev);
58216+ dev_put(dev);
58217+ } else {
58218+ our_addr = ip->addr;
58219+ our_netmask = ip->netmask;
58220+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58221+ if (ret == 1)
58222+ return 0;
58223+ else if (ret == 2)
58224+ goto denied;
58225+ }
58226+ }
58227+
58228+denied:
58229+ if (mode == GR_BIND)
58230+ 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));
58231+ else if (mode == GR_CONNECT)
58232+ 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));
58233+
58234+ return -EACCES;
58235+}
58236+
58237+int
58238+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58239+{
58240+ /* always allow disconnection of dgram sockets with connect */
58241+ if (addr->sin_family == AF_UNSPEC)
58242+ return 0;
58243+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58244+}
58245+
58246+int
58247+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58248+{
58249+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58250+}
58251+
58252+int gr_search_listen(struct socket *sock)
58253+{
58254+ struct sock *sk = sock->sk;
58255+ struct sockaddr_in addr;
58256+
58257+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58258+ addr.sin_port = inet_sk(sk)->inet_sport;
58259+
58260+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58261+}
58262+
58263+int gr_search_accept(struct socket *sock)
58264+{
58265+ struct sock *sk = sock->sk;
58266+ struct sockaddr_in addr;
58267+
58268+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58269+ addr.sin_port = inet_sk(sk)->inet_sport;
58270+
58271+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58272+}
58273+
58274+int
58275+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58276+{
58277+ if (addr)
58278+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58279+ else {
58280+ struct sockaddr_in sin;
58281+ const struct inet_sock *inet = inet_sk(sk);
58282+
58283+ sin.sin_addr.s_addr = inet->inet_daddr;
58284+ sin.sin_port = inet->inet_dport;
58285+
58286+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58287+ }
58288+}
58289+
58290+int
58291+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58292+{
58293+ struct sockaddr_in sin;
58294+
58295+ if (unlikely(skb->len < sizeof (struct udphdr)))
58296+ return 0; // skip this packet
58297+
58298+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58299+ sin.sin_port = udp_hdr(skb)->source;
58300+
58301+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58302+}
58303diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58304new file mode 100644
58305index 0000000..25f54ef
58306--- /dev/null
58307+++ b/grsecurity/gracl_learn.c
58308@@ -0,0 +1,207 @@
58309+#include <linux/kernel.h>
58310+#include <linux/mm.h>
58311+#include <linux/sched.h>
58312+#include <linux/poll.h>
58313+#include <linux/string.h>
58314+#include <linux/file.h>
58315+#include <linux/types.h>
58316+#include <linux/vmalloc.h>
58317+#include <linux/grinternal.h>
58318+
58319+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58320+ size_t count, loff_t *ppos);
58321+extern int gr_acl_is_enabled(void);
58322+
58323+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58324+static int gr_learn_attached;
58325+
58326+/* use a 512k buffer */
58327+#define LEARN_BUFFER_SIZE (512 * 1024)
58328+
58329+static DEFINE_SPINLOCK(gr_learn_lock);
58330+static DEFINE_MUTEX(gr_learn_user_mutex);
58331+
58332+/* we need to maintain two buffers, so that the kernel context of grlearn
58333+ uses a semaphore around the userspace copying, and the other kernel contexts
58334+ use a spinlock when copying into the buffer, since they cannot sleep
58335+*/
58336+static char *learn_buffer;
58337+static char *learn_buffer_user;
58338+static int learn_buffer_len;
58339+static int learn_buffer_user_len;
58340+
58341+static ssize_t
58342+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58343+{
58344+ DECLARE_WAITQUEUE(wait, current);
58345+ ssize_t retval = 0;
58346+
58347+ add_wait_queue(&learn_wait, &wait);
58348+ set_current_state(TASK_INTERRUPTIBLE);
58349+ do {
58350+ mutex_lock(&gr_learn_user_mutex);
58351+ spin_lock(&gr_learn_lock);
58352+ if (learn_buffer_len)
58353+ break;
58354+ spin_unlock(&gr_learn_lock);
58355+ mutex_unlock(&gr_learn_user_mutex);
58356+ if (file->f_flags & O_NONBLOCK) {
58357+ retval = -EAGAIN;
58358+ goto out;
58359+ }
58360+ if (signal_pending(current)) {
58361+ retval = -ERESTARTSYS;
58362+ goto out;
58363+ }
58364+
58365+ schedule();
58366+ } while (1);
58367+
58368+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58369+ learn_buffer_user_len = learn_buffer_len;
58370+ retval = learn_buffer_len;
58371+ learn_buffer_len = 0;
58372+
58373+ spin_unlock(&gr_learn_lock);
58374+
58375+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58376+ retval = -EFAULT;
58377+
58378+ mutex_unlock(&gr_learn_user_mutex);
58379+out:
58380+ set_current_state(TASK_RUNNING);
58381+ remove_wait_queue(&learn_wait, &wait);
58382+ return retval;
58383+}
58384+
58385+static unsigned int
58386+poll_learn(struct file * file, poll_table * wait)
58387+{
58388+ poll_wait(file, &learn_wait, wait);
58389+
58390+ if (learn_buffer_len)
58391+ return (POLLIN | POLLRDNORM);
58392+
58393+ return 0;
58394+}
58395+
58396+void
58397+gr_clear_learn_entries(void)
58398+{
58399+ char *tmp;
58400+
58401+ mutex_lock(&gr_learn_user_mutex);
58402+ spin_lock(&gr_learn_lock);
58403+ tmp = learn_buffer;
58404+ learn_buffer = NULL;
58405+ spin_unlock(&gr_learn_lock);
58406+ if (tmp)
58407+ vfree(tmp);
58408+ if (learn_buffer_user != NULL) {
58409+ vfree(learn_buffer_user);
58410+ learn_buffer_user = NULL;
58411+ }
58412+ learn_buffer_len = 0;
58413+ mutex_unlock(&gr_learn_user_mutex);
58414+
58415+ return;
58416+}
58417+
58418+void
58419+gr_add_learn_entry(const char *fmt, ...)
58420+{
58421+ va_list args;
58422+ unsigned int len;
58423+
58424+ if (!gr_learn_attached)
58425+ return;
58426+
58427+ spin_lock(&gr_learn_lock);
58428+
58429+ /* leave a gap at the end so we know when it's "full" but don't have to
58430+ compute the exact length of the string we're trying to append
58431+ */
58432+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58433+ spin_unlock(&gr_learn_lock);
58434+ wake_up_interruptible(&learn_wait);
58435+ return;
58436+ }
58437+ if (learn_buffer == NULL) {
58438+ spin_unlock(&gr_learn_lock);
58439+ return;
58440+ }
58441+
58442+ va_start(args, fmt);
58443+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58444+ va_end(args);
58445+
58446+ learn_buffer_len += len + 1;
58447+
58448+ spin_unlock(&gr_learn_lock);
58449+ wake_up_interruptible(&learn_wait);
58450+
58451+ return;
58452+}
58453+
58454+static int
58455+open_learn(struct inode *inode, struct file *file)
58456+{
58457+ if (file->f_mode & FMODE_READ && gr_learn_attached)
58458+ return -EBUSY;
58459+ if (file->f_mode & FMODE_READ) {
58460+ int retval = 0;
58461+ mutex_lock(&gr_learn_user_mutex);
58462+ if (learn_buffer == NULL)
58463+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58464+ if (learn_buffer_user == NULL)
58465+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58466+ if (learn_buffer == NULL) {
58467+ retval = -ENOMEM;
58468+ goto out_error;
58469+ }
58470+ if (learn_buffer_user == NULL) {
58471+ retval = -ENOMEM;
58472+ goto out_error;
58473+ }
58474+ learn_buffer_len = 0;
58475+ learn_buffer_user_len = 0;
58476+ gr_learn_attached = 1;
58477+out_error:
58478+ mutex_unlock(&gr_learn_user_mutex);
58479+ return retval;
58480+ }
58481+ return 0;
58482+}
58483+
58484+static int
58485+close_learn(struct inode *inode, struct file *file)
58486+{
58487+ if (file->f_mode & FMODE_READ) {
58488+ char *tmp = NULL;
58489+ mutex_lock(&gr_learn_user_mutex);
58490+ spin_lock(&gr_learn_lock);
58491+ tmp = learn_buffer;
58492+ learn_buffer = NULL;
58493+ spin_unlock(&gr_learn_lock);
58494+ if (tmp)
58495+ vfree(tmp);
58496+ if (learn_buffer_user != NULL) {
58497+ vfree(learn_buffer_user);
58498+ learn_buffer_user = NULL;
58499+ }
58500+ learn_buffer_len = 0;
58501+ learn_buffer_user_len = 0;
58502+ gr_learn_attached = 0;
58503+ mutex_unlock(&gr_learn_user_mutex);
58504+ }
58505+
58506+ return 0;
58507+}
58508+
58509+const struct file_operations grsec_fops = {
58510+ .read = read_learn,
58511+ .write = write_grsec_handler,
58512+ .open = open_learn,
58513+ .release = close_learn,
58514+ .poll = poll_learn,
58515+};
58516diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58517new file mode 100644
58518index 0000000..39645c9
58519--- /dev/null
58520+++ b/grsecurity/gracl_res.c
58521@@ -0,0 +1,68 @@
58522+#include <linux/kernel.h>
58523+#include <linux/sched.h>
58524+#include <linux/gracl.h>
58525+#include <linux/grinternal.h>
58526+
58527+static const char *restab_log[] = {
58528+ [RLIMIT_CPU] = "RLIMIT_CPU",
58529+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58530+ [RLIMIT_DATA] = "RLIMIT_DATA",
58531+ [RLIMIT_STACK] = "RLIMIT_STACK",
58532+ [RLIMIT_CORE] = "RLIMIT_CORE",
58533+ [RLIMIT_RSS] = "RLIMIT_RSS",
58534+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
58535+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58536+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58537+ [RLIMIT_AS] = "RLIMIT_AS",
58538+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58539+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58540+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58541+ [RLIMIT_NICE] = "RLIMIT_NICE",
58542+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58543+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58544+ [GR_CRASH_RES] = "RLIMIT_CRASH"
58545+};
58546+
58547+void
58548+gr_log_resource(const struct task_struct *task,
58549+ const int res, const unsigned long wanted, const int gt)
58550+{
58551+ const struct cred *cred;
58552+ unsigned long rlim;
58553+
58554+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
58555+ return;
58556+
58557+ // not yet supported resource
58558+ if (unlikely(!restab_log[res]))
58559+ return;
58560+
58561+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58562+ rlim = task_rlimit_max(task, res);
58563+ else
58564+ rlim = task_rlimit(task, res);
58565+
58566+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58567+ return;
58568+
58569+ rcu_read_lock();
58570+ cred = __task_cred(task);
58571+
58572+ if (res == RLIMIT_NPROC &&
58573+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58574+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58575+ goto out_rcu_unlock;
58576+ else if (res == RLIMIT_MEMLOCK &&
58577+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58578+ goto out_rcu_unlock;
58579+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58580+ goto out_rcu_unlock;
58581+ rcu_read_unlock();
58582+
58583+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58584+
58585+ return;
58586+out_rcu_unlock:
58587+ rcu_read_unlock();
58588+ return;
58589+}
58590diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58591new file mode 100644
58592index 0000000..25197e9
58593--- /dev/null
58594+++ b/grsecurity/gracl_segv.c
58595@@ -0,0 +1,299 @@
58596+#include <linux/kernel.h>
58597+#include <linux/mm.h>
58598+#include <asm/uaccess.h>
58599+#include <asm/errno.h>
58600+#include <asm/mman.h>
58601+#include <net/sock.h>
58602+#include <linux/file.h>
58603+#include <linux/fs.h>
58604+#include <linux/net.h>
58605+#include <linux/in.h>
58606+#include <linux/slab.h>
58607+#include <linux/types.h>
58608+#include <linux/sched.h>
58609+#include <linux/timer.h>
58610+#include <linux/gracl.h>
58611+#include <linux/grsecurity.h>
58612+#include <linux/grinternal.h>
58613+
58614+static struct crash_uid *uid_set;
58615+static unsigned short uid_used;
58616+static DEFINE_SPINLOCK(gr_uid_lock);
58617+extern rwlock_t gr_inode_lock;
58618+extern struct acl_subject_label *
58619+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58620+ struct acl_role_label *role);
58621+
58622+#ifdef CONFIG_BTRFS_FS
58623+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58624+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58625+#endif
58626+
58627+static inline dev_t __get_dev(const struct dentry *dentry)
58628+{
58629+#ifdef CONFIG_BTRFS_FS
58630+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58631+ return get_btrfs_dev_from_inode(dentry->d_inode);
58632+ else
58633+#endif
58634+ return dentry->d_inode->i_sb->s_dev;
58635+}
58636+
58637+int
58638+gr_init_uidset(void)
58639+{
58640+ uid_set =
58641+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58642+ uid_used = 0;
58643+
58644+ return uid_set ? 1 : 0;
58645+}
58646+
58647+void
58648+gr_free_uidset(void)
58649+{
58650+ if (uid_set)
58651+ kfree(uid_set);
58652+
58653+ return;
58654+}
58655+
58656+int
58657+gr_find_uid(const uid_t uid)
58658+{
58659+ struct crash_uid *tmp = uid_set;
58660+ uid_t buid;
58661+ int low = 0, high = uid_used - 1, mid;
58662+
58663+ while (high >= low) {
58664+ mid = (low + high) >> 1;
58665+ buid = tmp[mid].uid;
58666+ if (buid == uid)
58667+ return mid;
58668+ if (buid > uid)
58669+ high = mid - 1;
58670+ if (buid < uid)
58671+ low = mid + 1;
58672+ }
58673+
58674+ return -1;
58675+}
58676+
58677+static __inline__ void
58678+gr_insertsort(void)
58679+{
58680+ unsigned short i, j;
58681+ struct crash_uid index;
58682+
58683+ for (i = 1; i < uid_used; i++) {
58684+ index = uid_set[i];
58685+ j = i;
58686+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58687+ uid_set[j] = uid_set[j - 1];
58688+ j--;
58689+ }
58690+ uid_set[j] = index;
58691+ }
58692+
58693+ return;
58694+}
58695+
58696+static __inline__ void
58697+gr_insert_uid(const uid_t uid, const unsigned long expires)
58698+{
58699+ int loc;
58700+
58701+ if (uid_used == GR_UIDTABLE_MAX)
58702+ return;
58703+
58704+ loc = gr_find_uid(uid);
58705+
58706+ if (loc >= 0) {
58707+ uid_set[loc].expires = expires;
58708+ return;
58709+ }
58710+
58711+ uid_set[uid_used].uid = uid;
58712+ uid_set[uid_used].expires = expires;
58713+ uid_used++;
58714+
58715+ gr_insertsort();
58716+
58717+ return;
58718+}
58719+
58720+void
58721+gr_remove_uid(const unsigned short loc)
58722+{
58723+ unsigned short i;
58724+
58725+ for (i = loc + 1; i < uid_used; i++)
58726+ uid_set[i - 1] = uid_set[i];
58727+
58728+ uid_used--;
58729+
58730+ return;
58731+}
58732+
58733+int
58734+gr_check_crash_uid(const uid_t uid)
58735+{
58736+ int loc;
58737+ int ret = 0;
58738+
58739+ if (unlikely(!gr_acl_is_enabled()))
58740+ return 0;
58741+
58742+ spin_lock(&gr_uid_lock);
58743+ loc = gr_find_uid(uid);
58744+
58745+ if (loc < 0)
58746+ goto out_unlock;
58747+
58748+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
58749+ gr_remove_uid(loc);
58750+ else
58751+ ret = 1;
58752+
58753+out_unlock:
58754+ spin_unlock(&gr_uid_lock);
58755+ return ret;
58756+}
58757+
58758+static __inline__ int
58759+proc_is_setxid(const struct cred *cred)
58760+{
58761+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58762+ !uid_eq(cred->uid, cred->fsuid))
58763+ return 1;
58764+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58765+ !uid_eq(cred->gid, cred->fsgid))
58766+ return 1;
58767+
58768+ return 0;
58769+}
58770+
58771+extern int gr_fake_force_sig(int sig, struct task_struct *t);
58772+
58773+void
58774+gr_handle_crash(struct task_struct *task, const int sig)
58775+{
58776+ struct acl_subject_label *curr;
58777+ struct task_struct *tsk, *tsk2;
58778+ const struct cred *cred;
58779+ const struct cred *cred2;
58780+
58781+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58782+ return;
58783+
58784+ if (unlikely(!gr_acl_is_enabled()))
58785+ return;
58786+
58787+ curr = task->acl;
58788+
58789+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
58790+ return;
58791+
58792+ if (time_before_eq(curr->expires, get_seconds())) {
58793+ curr->expires = 0;
58794+ curr->crashes = 0;
58795+ }
58796+
58797+ curr->crashes++;
58798+
58799+ if (!curr->expires)
58800+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
58801+
58802+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58803+ time_after(curr->expires, get_seconds())) {
58804+ rcu_read_lock();
58805+ cred = __task_cred(task);
58806+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
58807+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58808+ spin_lock(&gr_uid_lock);
58809+ gr_insert_uid(cred->uid, curr->expires);
58810+ spin_unlock(&gr_uid_lock);
58811+ curr->expires = 0;
58812+ curr->crashes = 0;
58813+ read_lock(&tasklist_lock);
58814+ do_each_thread(tsk2, tsk) {
58815+ cred2 = __task_cred(tsk);
58816+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
58817+ gr_fake_force_sig(SIGKILL, tsk);
58818+ } while_each_thread(tsk2, tsk);
58819+ read_unlock(&tasklist_lock);
58820+ } else {
58821+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58822+ read_lock(&tasklist_lock);
58823+ read_lock(&grsec_exec_file_lock);
58824+ do_each_thread(tsk2, tsk) {
58825+ if (likely(tsk != task)) {
58826+ // if this thread has the same subject as the one that triggered
58827+ // RES_CRASH and it's the same binary, kill it
58828+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
58829+ gr_fake_force_sig(SIGKILL, tsk);
58830+ }
58831+ } while_each_thread(tsk2, tsk);
58832+ read_unlock(&grsec_exec_file_lock);
58833+ read_unlock(&tasklist_lock);
58834+ }
58835+ rcu_read_unlock();
58836+ }
58837+
58838+ return;
58839+}
58840+
58841+int
58842+gr_check_crash_exec(const struct file *filp)
58843+{
58844+ struct acl_subject_label *curr;
58845+
58846+ if (unlikely(!gr_acl_is_enabled()))
58847+ return 0;
58848+
58849+ read_lock(&gr_inode_lock);
58850+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
58851+ __get_dev(filp->f_path.dentry),
58852+ current->role);
58853+ read_unlock(&gr_inode_lock);
58854+
58855+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
58856+ (!curr->crashes && !curr->expires))
58857+ return 0;
58858+
58859+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58860+ time_after(curr->expires, get_seconds()))
58861+ return 1;
58862+ else if (time_before_eq(curr->expires, get_seconds())) {
58863+ curr->crashes = 0;
58864+ curr->expires = 0;
58865+ }
58866+
58867+ return 0;
58868+}
58869+
58870+void
58871+gr_handle_alertkill(struct task_struct *task)
58872+{
58873+ struct acl_subject_label *curracl;
58874+ __u32 curr_ip;
58875+ struct task_struct *p, *p2;
58876+
58877+ if (unlikely(!gr_acl_is_enabled()))
58878+ return;
58879+
58880+ curracl = task->acl;
58881+ curr_ip = task->signal->curr_ip;
58882+
58883+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
58884+ read_lock(&tasklist_lock);
58885+ do_each_thread(p2, p) {
58886+ if (p->signal->curr_ip == curr_ip)
58887+ gr_fake_force_sig(SIGKILL, p);
58888+ } while_each_thread(p2, p);
58889+ read_unlock(&tasklist_lock);
58890+ } else if (curracl->mode & GR_KILLPROC)
58891+ gr_fake_force_sig(SIGKILL, task);
58892+
58893+ return;
58894+}
58895diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
58896new file mode 100644
58897index 0000000..9d83a69
58898--- /dev/null
58899+++ b/grsecurity/gracl_shm.c
58900@@ -0,0 +1,40 @@
58901+#include <linux/kernel.h>
58902+#include <linux/mm.h>
58903+#include <linux/sched.h>
58904+#include <linux/file.h>
58905+#include <linux/ipc.h>
58906+#include <linux/gracl.h>
58907+#include <linux/grsecurity.h>
58908+#include <linux/grinternal.h>
58909+
58910+int
58911+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58912+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58913+{
58914+ struct task_struct *task;
58915+
58916+ if (!gr_acl_is_enabled())
58917+ return 1;
58918+
58919+ rcu_read_lock();
58920+ read_lock(&tasklist_lock);
58921+
58922+ task = find_task_by_vpid(shm_cprid);
58923+
58924+ if (unlikely(!task))
58925+ task = find_task_by_vpid(shm_lapid);
58926+
58927+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
58928+ (task->pid == shm_lapid)) &&
58929+ (task->acl->mode & GR_PROTSHM) &&
58930+ (task->acl != current->acl))) {
58931+ read_unlock(&tasklist_lock);
58932+ rcu_read_unlock();
58933+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
58934+ return 0;
58935+ }
58936+ read_unlock(&tasklist_lock);
58937+ rcu_read_unlock();
58938+
58939+ return 1;
58940+}
58941diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
58942new file mode 100644
58943index 0000000..bc0be01
58944--- /dev/null
58945+++ b/grsecurity/grsec_chdir.c
58946@@ -0,0 +1,19 @@
58947+#include <linux/kernel.h>
58948+#include <linux/sched.h>
58949+#include <linux/fs.h>
58950+#include <linux/file.h>
58951+#include <linux/grsecurity.h>
58952+#include <linux/grinternal.h>
58953+
58954+void
58955+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
58956+{
58957+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58958+ if ((grsec_enable_chdir && grsec_enable_group &&
58959+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
58960+ !grsec_enable_group)) {
58961+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
58962+ }
58963+#endif
58964+ return;
58965+}
58966diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
58967new file mode 100644
58968index 0000000..70fe0ae
58969--- /dev/null
58970+++ b/grsecurity/grsec_chroot.c
58971@@ -0,0 +1,357 @@
58972+#include <linux/kernel.h>
58973+#include <linux/module.h>
58974+#include <linux/sched.h>
58975+#include <linux/file.h>
58976+#include <linux/fs.h>
58977+#include <linux/mount.h>
58978+#include <linux/types.h>
58979+#include "../fs/mount.h"
58980+#include <linux/grsecurity.h>
58981+#include <linux/grinternal.h>
58982+
58983+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
58984+{
58985+#ifdef CONFIG_GRKERNSEC
58986+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
58987+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
58988+ task->gr_is_chrooted = 1;
58989+ else
58990+ task->gr_is_chrooted = 0;
58991+
58992+ task->gr_chroot_dentry = path->dentry;
58993+#endif
58994+ return;
58995+}
58996+
58997+void gr_clear_chroot_entries(struct task_struct *task)
58998+{
58999+#ifdef CONFIG_GRKERNSEC
59000+ task->gr_is_chrooted = 0;
59001+ task->gr_chroot_dentry = NULL;
59002+#endif
59003+ return;
59004+}
59005+
59006+int
59007+gr_handle_chroot_unix(const pid_t pid)
59008+{
59009+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59010+ struct task_struct *p;
59011+
59012+ if (unlikely(!grsec_enable_chroot_unix))
59013+ return 1;
59014+
59015+ if (likely(!proc_is_chrooted(current)))
59016+ return 1;
59017+
59018+ rcu_read_lock();
59019+ read_lock(&tasklist_lock);
59020+ p = find_task_by_vpid_unrestricted(pid);
59021+ if (unlikely(p && !have_same_root(current, p))) {
59022+ read_unlock(&tasklist_lock);
59023+ rcu_read_unlock();
59024+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59025+ return 0;
59026+ }
59027+ read_unlock(&tasklist_lock);
59028+ rcu_read_unlock();
59029+#endif
59030+ return 1;
59031+}
59032+
59033+int
59034+gr_handle_chroot_nice(void)
59035+{
59036+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59037+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59038+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59039+ return -EPERM;
59040+ }
59041+#endif
59042+ return 0;
59043+}
59044+
59045+int
59046+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59047+{
59048+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59049+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59050+ && proc_is_chrooted(current)) {
59051+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59052+ return -EACCES;
59053+ }
59054+#endif
59055+ return 0;
59056+}
59057+
59058+int
59059+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59060+{
59061+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59062+ struct task_struct *p;
59063+ int ret = 0;
59064+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59065+ return ret;
59066+
59067+ read_lock(&tasklist_lock);
59068+ do_each_pid_task(pid, type, p) {
59069+ if (!have_same_root(current, p)) {
59070+ ret = 1;
59071+ goto out;
59072+ }
59073+ } while_each_pid_task(pid, type, p);
59074+out:
59075+ read_unlock(&tasklist_lock);
59076+ return ret;
59077+#endif
59078+ return 0;
59079+}
59080+
59081+int
59082+gr_pid_is_chrooted(struct task_struct *p)
59083+{
59084+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59085+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59086+ return 0;
59087+
59088+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59089+ !have_same_root(current, p)) {
59090+ return 1;
59091+ }
59092+#endif
59093+ return 0;
59094+}
59095+
59096+EXPORT_SYMBOL(gr_pid_is_chrooted);
59097+
59098+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59099+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59100+{
59101+ struct path path, currentroot;
59102+ int ret = 0;
59103+
59104+ path.dentry = (struct dentry *)u_dentry;
59105+ path.mnt = (struct vfsmount *)u_mnt;
59106+ get_fs_root(current->fs, &currentroot);
59107+ if (path_is_under(&path, &currentroot))
59108+ ret = 1;
59109+ path_put(&currentroot);
59110+
59111+ return ret;
59112+}
59113+#endif
59114+
59115+int
59116+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59117+{
59118+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59119+ if (!grsec_enable_chroot_fchdir)
59120+ return 1;
59121+
59122+ if (!proc_is_chrooted(current))
59123+ return 1;
59124+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59125+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59126+ return 0;
59127+ }
59128+#endif
59129+ return 1;
59130+}
59131+
59132+int
59133+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59134+ const time_t shm_createtime)
59135+{
59136+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59137+ struct task_struct *p;
59138+ time_t starttime;
59139+
59140+ if (unlikely(!grsec_enable_chroot_shmat))
59141+ return 1;
59142+
59143+ if (likely(!proc_is_chrooted(current)))
59144+ return 1;
59145+
59146+ rcu_read_lock();
59147+ read_lock(&tasklist_lock);
59148+
59149+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59150+ starttime = p->start_time.tv_sec;
59151+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59152+ if (have_same_root(current, p)) {
59153+ goto allow;
59154+ } else {
59155+ read_unlock(&tasklist_lock);
59156+ rcu_read_unlock();
59157+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59158+ return 0;
59159+ }
59160+ }
59161+ /* creator exited, pid reuse, fall through to next check */
59162+ }
59163+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59164+ if (unlikely(!have_same_root(current, p))) {
59165+ read_unlock(&tasklist_lock);
59166+ rcu_read_unlock();
59167+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59168+ return 0;
59169+ }
59170+ }
59171+
59172+allow:
59173+ read_unlock(&tasklist_lock);
59174+ rcu_read_unlock();
59175+#endif
59176+ return 1;
59177+}
59178+
59179+void
59180+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59181+{
59182+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59183+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59184+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59185+#endif
59186+ return;
59187+}
59188+
59189+int
59190+gr_handle_chroot_mknod(const struct dentry *dentry,
59191+ const struct vfsmount *mnt, const int mode)
59192+{
59193+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59194+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59195+ proc_is_chrooted(current)) {
59196+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59197+ return -EPERM;
59198+ }
59199+#endif
59200+ return 0;
59201+}
59202+
59203+int
59204+gr_handle_chroot_mount(const struct dentry *dentry,
59205+ const struct vfsmount *mnt, const char *dev_name)
59206+{
59207+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59208+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59209+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59210+ return -EPERM;
59211+ }
59212+#endif
59213+ return 0;
59214+}
59215+
59216+int
59217+gr_handle_chroot_pivot(void)
59218+{
59219+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59220+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59221+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59222+ return -EPERM;
59223+ }
59224+#endif
59225+ return 0;
59226+}
59227+
59228+int
59229+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59230+{
59231+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59232+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59233+ !gr_is_outside_chroot(dentry, mnt)) {
59234+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59235+ return -EPERM;
59236+ }
59237+#endif
59238+ return 0;
59239+}
59240+
59241+extern const char *captab_log[];
59242+extern int captab_log_entries;
59243+
59244+int
59245+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59246+{
59247+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59248+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59249+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59250+ if (cap_raised(chroot_caps, cap)) {
59251+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59252+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59253+ }
59254+ return 0;
59255+ }
59256+ }
59257+#endif
59258+ return 1;
59259+}
59260+
59261+int
59262+gr_chroot_is_capable(const int cap)
59263+{
59264+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59265+ return gr_task_chroot_is_capable(current, current_cred(), cap);
59266+#endif
59267+ return 1;
59268+}
59269+
59270+int
59271+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59272+{
59273+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59274+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59275+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59276+ if (cap_raised(chroot_caps, cap)) {
59277+ return 0;
59278+ }
59279+ }
59280+#endif
59281+ return 1;
59282+}
59283+
59284+int
59285+gr_chroot_is_capable_nolog(const int cap)
59286+{
59287+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59288+ return gr_task_chroot_is_capable_nolog(current, cap);
59289+#endif
59290+ return 1;
59291+}
59292+
59293+int
59294+gr_handle_chroot_sysctl(const int op)
59295+{
59296+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59297+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59298+ proc_is_chrooted(current))
59299+ return -EACCES;
59300+#endif
59301+ return 0;
59302+}
59303+
59304+void
59305+gr_handle_chroot_chdir(struct path *path)
59306+{
59307+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59308+ if (grsec_enable_chroot_chdir)
59309+ set_fs_pwd(current->fs, path);
59310+#endif
59311+ return;
59312+}
59313+
59314+int
59315+gr_handle_chroot_chmod(const struct dentry *dentry,
59316+ const struct vfsmount *mnt, const int mode)
59317+{
59318+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59319+ /* allow chmod +s on directories, but not files */
59320+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59321+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59322+ proc_is_chrooted(current)) {
59323+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59324+ return -EPERM;
59325+ }
59326+#endif
59327+ return 0;
59328+}
59329diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59330new file mode 100644
59331index 0000000..e6796b3
59332--- /dev/null
59333+++ b/grsecurity/grsec_disabled.c
59334@@ -0,0 +1,434 @@
59335+#include <linux/kernel.h>
59336+#include <linux/module.h>
59337+#include <linux/sched.h>
59338+#include <linux/file.h>
59339+#include <linux/fs.h>
59340+#include <linux/kdev_t.h>
59341+#include <linux/net.h>
59342+#include <linux/in.h>
59343+#include <linux/ip.h>
59344+#include <linux/skbuff.h>
59345+#include <linux/sysctl.h>
59346+
59347+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59348+void
59349+pax_set_initial_flags(struct linux_binprm *bprm)
59350+{
59351+ return;
59352+}
59353+#endif
59354+
59355+#ifdef CONFIG_SYSCTL
59356+__u32
59357+gr_handle_sysctl(const struct ctl_table * table, const int op)
59358+{
59359+ return 0;
59360+}
59361+#endif
59362+
59363+#ifdef CONFIG_TASKSTATS
59364+int gr_is_taskstats_denied(int pid)
59365+{
59366+ return 0;
59367+}
59368+#endif
59369+
59370+int
59371+gr_acl_is_enabled(void)
59372+{
59373+ return 0;
59374+}
59375+
59376+void
59377+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59378+{
59379+ return;
59380+}
59381+
59382+int
59383+gr_handle_rawio(const struct inode *inode)
59384+{
59385+ return 0;
59386+}
59387+
59388+void
59389+gr_acl_handle_psacct(struct task_struct *task, const long code)
59390+{
59391+ return;
59392+}
59393+
59394+int
59395+gr_handle_ptrace(struct task_struct *task, const long request)
59396+{
59397+ return 0;
59398+}
59399+
59400+int
59401+gr_handle_proc_ptrace(struct task_struct *task)
59402+{
59403+ return 0;
59404+}
59405+
59406+int
59407+gr_set_acls(const int type)
59408+{
59409+ return 0;
59410+}
59411+
59412+int
59413+gr_check_hidden_task(const struct task_struct *tsk)
59414+{
59415+ return 0;
59416+}
59417+
59418+int
59419+gr_check_protected_task(const struct task_struct *task)
59420+{
59421+ return 0;
59422+}
59423+
59424+int
59425+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59426+{
59427+ return 0;
59428+}
59429+
59430+void
59431+gr_copy_label(struct task_struct *tsk)
59432+{
59433+ return;
59434+}
59435+
59436+void
59437+gr_set_pax_flags(struct task_struct *task)
59438+{
59439+ return;
59440+}
59441+
59442+int
59443+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59444+ const int unsafe_share)
59445+{
59446+ return 0;
59447+}
59448+
59449+void
59450+gr_handle_delete(const ino_t ino, const dev_t dev)
59451+{
59452+ return;
59453+}
59454+
59455+void
59456+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59457+{
59458+ return;
59459+}
59460+
59461+void
59462+gr_handle_crash(struct task_struct *task, const int sig)
59463+{
59464+ return;
59465+}
59466+
59467+int
59468+gr_check_crash_exec(const struct file *filp)
59469+{
59470+ return 0;
59471+}
59472+
59473+int
59474+gr_check_crash_uid(const uid_t uid)
59475+{
59476+ return 0;
59477+}
59478+
59479+void
59480+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59481+ struct dentry *old_dentry,
59482+ struct dentry *new_dentry,
59483+ struct vfsmount *mnt, const __u8 replace)
59484+{
59485+ return;
59486+}
59487+
59488+int
59489+gr_search_socket(const int family, const int type, const int protocol)
59490+{
59491+ return 1;
59492+}
59493+
59494+int
59495+gr_search_connectbind(const int mode, const struct socket *sock,
59496+ const struct sockaddr_in *addr)
59497+{
59498+ return 0;
59499+}
59500+
59501+void
59502+gr_handle_alertkill(struct task_struct *task)
59503+{
59504+ return;
59505+}
59506+
59507+__u32
59508+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59509+{
59510+ return 1;
59511+}
59512+
59513+__u32
59514+gr_acl_handle_hidden_file(const struct dentry * dentry,
59515+ const struct vfsmount * mnt)
59516+{
59517+ return 1;
59518+}
59519+
59520+__u32
59521+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59522+ int acc_mode)
59523+{
59524+ return 1;
59525+}
59526+
59527+__u32
59528+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59529+{
59530+ return 1;
59531+}
59532+
59533+__u32
59534+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59535+{
59536+ return 1;
59537+}
59538+
59539+int
59540+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59541+ unsigned int *vm_flags)
59542+{
59543+ return 1;
59544+}
59545+
59546+__u32
59547+gr_acl_handle_truncate(const struct dentry * dentry,
59548+ const struct vfsmount * mnt)
59549+{
59550+ return 1;
59551+}
59552+
59553+__u32
59554+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59555+{
59556+ return 1;
59557+}
59558+
59559+__u32
59560+gr_acl_handle_access(const struct dentry * dentry,
59561+ const struct vfsmount * mnt, const int fmode)
59562+{
59563+ return 1;
59564+}
59565+
59566+__u32
59567+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59568+ umode_t *mode)
59569+{
59570+ return 1;
59571+}
59572+
59573+__u32
59574+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59575+{
59576+ return 1;
59577+}
59578+
59579+__u32
59580+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59581+{
59582+ return 1;
59583+}
59584+
59585+void
59586+grsecurity_init(void)
59587+{
59588+ return;
59589+}
59590+
59591+umode_t gr_acl_umask(void)
59592+{
59593+ return 0;
59594+}
59595+
59596+__u32
59597+gr_acl_handle_mknod(const struct dentry * new_dentry,
59598+ const struct dentry * parent_dentry,
59599+ const struct vfsmount * parent_mnt,
59600+ const int mode)
59601+{
59602+ return 1;
59603+}
59604+
59605+__u32
59606+gr_acl_handle_mkdir(const struct dentry * new_dentry,
59607+ const struct dentry * parent_dentry,
59608+ const struct vfsmount * parent_mnt)
59609+{
59610+ return 1;
59611+}
59612+
59613+__u32
59614+gr_acl_handle_symlink(const struct dentry * new_dentry,
59615+ const struct dentry * parent_dentry,
59616+ const struct vfsmount * parent_mnt, const struct filename *from)
59617+{
59618+ return 1;
59619+}
59620+
59621+__u32
59622+gr_acl_handle_link(const struct dentry * new_dentry,
59623+ const struct dentry * parent_dentry,
59624+ const struct vfsmount * parent_mnt,
59625+ const struct dentry * old_dentry,
59626+ const struct vfsmount * old_mnt, const struct filename *to)
59627+{
59628+ return 1;
59629+}
59630+
59631+int
59632+gr_acl_handle_rename(const struct dentry *new_dentry,
59633+ const struct dentry *parent_dentry,
59634+ const struct vfsmount *parent_mnt,
59635+ const struct dentry *old_dentry,
59636+ const struct inode *old_parent_inode,
59637+ const struct vfsmount *old_mnt, const struct filename *newname)
59638+{
59639+ return 0;
59640+}
59641+
59642+int
59643+gr_acl_handle_filldir(const struct file *file, const char *name,
59644+ const int namelen, const ino_t ino)
59645+{
59646+ return 1;
59647+}
59648+
59649+int
59650+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59651+ const time_t shm_createtime, const uid_t cuid, const int shmid)
59652+{
59653+ return 1;
59654+}
59655+
59656+int
59657+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59658+{
59659+ return 0;
59660+}
59661+
59662+int
59663+gr_search_accept(const struct socket *sock)
59664+{
59665+ return 0;
59666+}
59667+
59668+int
59669+gr_search_listen(const struct socket *sock)
59670+{
59671+ return 0;
59672+}
59673+
59674+int
59675+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59676+{
59677+ return 0;
59678+}
59679+
59680+__u32
59681+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59682+{
59683+ return 1;
59684+}
59685+
59686+__u32
59687+gr_acl_handle_creat(const struct dentry * dentry,
59688+ const struct dentry * p_dentry,
59689+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59690+ const int imode)
59691+{
59692+ return 1;
59693+}
59694+
59695+void
59696+gr_acl_handle_exit(void)
59697+{
59698+ return;
59699+}
59700+
59701+int
59702+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59703+{
59704+ return 1;
59705+}
59706+
59707+void
59708+gr_set_role_label(const uid_t uid, const gid_t gid)
59709+{
59710+ return;
59711+}
59712+
59713+int
59714+gr_acl_handle_procpidmem(const struct task_struct *task)
59715+{
59716+ return 0;
59717+}
59718+
59719+int
59720+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59721+{
59722+ return 0;
59723+}
59724+
59725+int
59726+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59727+{
59728+ return 0;
59729+}
59730+
59731+void
59732+gr_set_kernel_label(struct task_struct *task)
59733+{
59734+ return;
59735+}
59736+
59737+int
59738+gr_check_user_change(int real, int effective, int fs)
59739+{
59740+ return 0;
59741+}
59742+
59743+int
59744+gr_check_group_change(int real, int effective, int fs)
59745+{
59746+ return 0;
59747+}
59748+
59749+int gr_acl_enable_at_secure(void)
59750+{
59751+ return 0;
59752+}
59753+
59754+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59755+{
59756+ return dentry->d_inode->i_sb->s_dev;
59757+}
59758+
59759+void gr_put_exec_file(struct task_struct *task)
59760+{
59761+ return;
59762+}
59763+
59764+EXPORT_SYMBOL(gr_set_kernel_label);
59765+#ifdef CONFIG_SECURITY
59766+EXPORT_SYMBOL(gr_check_user_change);
59767+EXPORT_SYMBOL(gr_check_group_change);
59768+#endif
59769diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59770new file mode 100644
59771index 0000000..abfa971
59772--- /dev/null
59773+++ b/grsecurity/grsec_exec.c
59774@@ -0,0 +1,174 @@
59775+#include <linux/kernel.h>
59776+#include <linux/sched.h>
59777+#include <linux/file.h>
59778+#include <linux/binfmts.h>
59779+#include <linux/fs.h>
59780+#include <linux/types.h>
59781+#include <linux/grdefs.h>
59782+#include <linux/grsecurity.h>
59783+#include <linux/grinternal.h>
59784+#include <linux/capability.h>
59785+#include <linux/module.h>
59786+
59787+#include <asm/uaccess.h>
59788+
59789+#ifdef CONFIG_GRKERNSEC_EXECLOG
59790+static char gr_exec_arg_buf[132];
59791+static DEFINE_MUTEX(gr_exec_arg_mutex);
59792+#endif
59793+
59794+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
59795+
59796+void
59797+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
59798+{
59799+#ifdef CONFIG_GRKERNSEC_EXECLOG
59800+ char *grarg = gr_exec_arg_buf;
59801+ unsigned int i, x, execlen = 0;
59802+ char c;
59803+
59804+ if (!((grsec_enable_execlog && grsec_enable_group &&
59805+ in_group_p(grsec_audit_gid))
59806+ || (grsec_enable_execlog && !grsec_enable_group)))
59807+ return;
59808+
59809+ mutex_lock(&gr_exec_arg_mutex);
59810+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
59811+
59812+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
59813+ const char __user *p;
59814+ unsigned int len;
59815+
59816+ p = get_user_arg_ptr(argv, i);
59817+ if (IS_ERR(p))
59818+ goto log;
59819+
59820+ len = strnlen_user(p, 128 - execlen);
59821+ if (len > 128 - execlen)
59822+ len = 128 - execlen;
59823+ else if (len > 0)
59824+ len--;
59825+ if (copy_from_user(grarg + execlen, p, len))
59826+ goto log;
59827+
59828+ /* rewrite unprintable characters */
59829+ for (x = 0; x < len; x++) {
59830+ c = *(grarg + execlen + x);
59831+ if (c < 32 || c > 126)
59832+ *(grarg + execlen + x) = ' ';
59833+ }
59834+
59835+ execlen += len;
59836+ *(grarg + execlen) = ' ';
59837+ *(grarg + execlen + 1) = '\0';
59838+ execlen++;
59839+ }
59840+
59841+ log:
59842+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
59843+ bprm->file->f_path.mnt, grarg);
59844+ mutex_unlock(&gr_exec_arg_mutex);
59845+#endif
59846+ return;
59847+}
59848+
59849+#ifdef CONFIG_GRKERNSEC
59850+extern int gr_acl_is_capable(const int cap);
59851+extern int gr_acl_is_capable_nolog(const int cap);
59852+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59853+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
59854+extern int gr_chroot_is_capable(const int cap);
59855+extern int gr_chroot_is_capable_nolog(const int cap);
59856+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59857+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
59858+#endif
59859+
59860+const char *captab_log[] = {
59861+ "CAP_CHOWN",
59862+ "CAP_DAC_OVERRIDE",
59863+ "CAP_DAC_READ_SEARCH",
59864+ "CAP_FOWNER",
59865+ "CAP_FSETID",
59866+ "CAP_KILL",
59867+ "CAP_SETGID",
59868+ "CAP_SETUID",
59869+ "CAP_SETPCAP",
59870+ "CAP_LINUX_IMMUTABLE",
59871+ "CAP_NET_BIND_SERVICE",
59872+ "CAP_NET_BROADCAST",
59873+ "CAP_NET_ADMIN",
59874+ "CAP_NET_RAW",
59875+ "CAP_IPC_LOCK",
59876+ "CAP_IPC_OWNER",
59877+ "CAP_SYS_MODULE",
59878+ "CAP_SYS_RAWIO",
59879+ "CAP_SYS_CHROOT",
59880+ "CAP_SYS_PTRACE",
59881+ "CAP_SYS_PACCT",
59882+ "CAP_SYS_ADMIN",
59883+ "CAP_SYS_BOOT",
59884+ "CAP_SYS_NICE",
59885+ "CAP_SYS_RESOURCE",
59886+ "CAP_SYS_TIME",
59887+ "CAP_SYS_TTY_CONFIG",
59888+ "CAP_MKNOD",
59889+ "CAP_LEASE",
59890+ "CAP_AUDIT_WRITE",
59891+ "CAP_AUDIT_CONTROL",
59892+ "CAP_SETFCAP",
59893+ "CAP_MAC_OVERRIDE",
59894+ "CAP_MAC_ADMIN",
59895+ "CAP_SYSLOG",
59896+ "CAP_WAKE_ALARM"
59897+};
59898+
59899+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
59900+
59901+int gr_is_capable(const int cap)
59902+{
59903+#ifdef CONFIG_GRKERNSEC
59904+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
59905+ return 1;
59906+ return 0;
59907+#else
59908+ return 1;
59909+#endif
59910+}
59911+
59912+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59913+{
59914+#ifdef CONFIG_GRKERNSEC
59915+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
59916+ return 1;
59917+ return 0;
59918+#else
59919+ return 1;
59920+#endif
59921+}
59922+
59923+int gr_is_capable_nolog(const int cap)
59924+{
59925+#ifdef CONFIG_GRKERNSEC
59926+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
59927+ return 1;
59928+ return 0;
59929+#else
59930+ return 1;
59931+#endif
59932+}
59933+
59934+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
59935+{
59936+#ifdef CONFIG_GRKERNSEC
59937+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
59938+ return 1;
59939+ return 0;
59940+#else
59941+ return 1;
59942+#endif
59943+}
59944+
59945+EXPORT_SYMBOL(gr_is_capable);
59946+EXPORT_SYMBOL(gr_is_capable_nolog);
59947+EXPORT_SYMBOL(gr_task_is_capable);
59948+EXPORT_SYMBOL(gr_task_is_capable_nolog);
59949diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
59950new file mode 100644
59951index 0000000..d3ee748
59952--- /dev/null
59953+++ b/grsecurity/grsec_fifo.c
59954@@ -0,0 +1,24 @@
59955+#include <linux/kernel.h>
59956+#include <linux/sched.h>
59957+#include <linux/fs.h>
59958+#include <linux/file.h>
59959+#include <linux/grinternal.h>
59960+
59961+int
59962+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
59963+ const struct dentry *dir, const int flag, const int acc_mode)
59964+{
59965+#ifdef CONFIG_GRKERNSEC_FIFO
59966+ const struct cred *cred = current_cred();
59967+
59968+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
59969+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
59970+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
59971+ (cred->fsuid != dentry->d_inode->i_uid)) {
59972+ if (!inode_permission(dentry->d_inode, acc_mode))
59973+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
59974+ return -EACCES;
59975+ }
59976+#endif
59977+ return 0;
59978+}
59979diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
59980new file mode 100644
59981index 0000000..8ca18bf
59982--- /dev/null
59983+++ b/grsecurity/grsec_fork.c
59984@@ -0,0 +1,23 @@
59985+#include <linux/kernel.h>
59986+#include <linux/sched.h>
59987+#include <linux/grsecurity.h>
59988+#include <linux/grinternal.h>
59989+#include <linux/errno.h>
59990+
59991+void
59992+gr_log_forkfail(const int retval)
59993+{
59994+#ifdef CONFIG_GRKERNSEC_FORKFAIL
59995+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
59996+ switch (retval) {
59997+ case -EAGAIN:
59998+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
59999+ break;
60000+ case -ENOMEM:
60001+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60002+ break;
60003+ }
60004+ }
60005+#endif
60006+ return;
60007+}
60008diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60009new file mode 100644
60010index 0000000..05a6015
60011--- /dev/null
60012+++ b/grsecurity/grsec_init.c
60013@@ -0,0 +1,283 @@
60014+#include <linux/kernel.h>
60015+#include <linux/sched.h>
60016+#include <linux/mm.h>
60017+#include <linux/gracl.h>
60018+#include <linux/slab.h>
60019+#include <linux/vmalloc.h>
60020+#include <linux/percpu.h>
60021+#include <linux/module.h>
60022+
60023+int grsec_enable_ptrace_readexec;
60024+int grsec_enable_setxid;
60025+int grsec_enable_symlinkown;
60026+int grsec_symlinkown_gid;
60027+int grsec_enable_brute;
60028+int grsec_enable_link;
60029+int grsec_enable_dmesg;
60030+int grsec_enable_harden_ptrace;
60031+int grsec_enable_fifo;
60032+int grsec_enable_execlog;
60033+int grsec_enable_signal;
60034+int grsec_enable_forkfail;
60035+int grsec_enable_audit_ptrace;
60036+int grsec_enable_time;
60037+int grsec_enable_audit_textrel;
60038+int grsec_enable_group;
60039+int grsec_audit_gid;
60040+int grsec_enable_chdir;
60041+int grsec_enable_mount;
60042+int grsec_enable_rofs;
60043+int grsec_enable_chroot_findtask;
60044+int grsec_enable_chroot_mount;
60045+int grsec_enable_chroot_shmat;
60046+int grsec_enable_chroot_fchdir;
60047+int grsec_enable_chroot_double;
60048+int grsec_enable_chroot_pivot;
60049+int grsec_enable_chroot_chdir;
60050+int grsec_enable_chroot_chmod;
60051+int grsec_enable_chroot_mknod;
60052+int grsec_enable_chroot_nice;
60053+int grsec_enable_chroot_execlog;
60054+int grsec_enable_chroot_caps;
60055+int grsec_enable_chroot_sysctl;
60056+int grsec_enable_chroot_unix;
60057+int grsec_enable_tpe;
60058+int grsec_tpe_gid;
60059+int grsec_enable_blackhole;
60060+#ifdef CONFIG_IPV6_MODULE
60061+EXPORT_SYMBOL(grsec_enable_blackhole);
60062+#endif
60063+int grsec_lastack_retries;
60064+int grsec_enable_tpe_all;
60065+int grsec_enable_tpe_invert;
60066+int grsec_enable_socket_all;
60067+int grsec_socket_all_gid;
60068+int grsec_enable_socket_client;
60069+int grsec_socket_client_gid;
60070+int grsec_enable_socket_server;
60071+int grsec_socket_server_gid;
60072+int grsec_resource_logging;
60073+int grsec_disable_privio;
60074+int grsec_enable_log_rwxmaps;
60075+int grsec_lock;
60076+
60077+DEFINE_SPINLOCK(grsec_alert_lock);
60078+unsigned long grsec_alert_wtime = 0;
60079+unsigned long grsec_alert_fyet = 0;
60080+
60081+DEFINE_SPINLOCK(grsec_audit_lock);
60082+
60083+DEFINE_RWLOCK(grsec_exec_file_lock);
60084+
60085+char *gr_shared_page[4];
60086+
60087+char *gr_alert_log_fmt;
60088+char *gr_audit_log_fmt;
60089+char *gr_alert_log_buf;
60090+char *gr_audit_log_buf;
60091+
60092+extern struct gr_arg *gr_usermode;
60093+extern unsigned char *gr_system_salt;
60094+extern unsigned char *gr_system_sum;
60095+
60096+void __init
60097+grsecurity_init(void)
60098+{
60099+ int j;
60100+ /* create the per-cpu shared pages */
60101+
60102+#ifdef CONFIG_X86
60103+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60104+#endif
60105+
60106+ for (j = 0; j < 4; j++) {
60107+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60108+ if (gr_shared_page[j] == NULL) {
60109+ panic("Unable to allocate grsecurity shared page");
60110+ return;
60111+ }
60112+ }
60113+
60114+ /* allocate log buffers */
60115+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60116+ if (!gr_alert_log_fmt) {
60117+ panic("Unable to allocate grsecurity alert log format buffer");
60118+ return;
60119+ }
60120+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60121+ if (!gr_audit_log_fmt) {
60122+ panic("Unable to allocate grsecurity audit log format buffer");
60123+ return;
60124+ }
60125+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60126+ if (!gr_alert_log_buf) {
60127+ panic("Unable to allocate grsecurity alert log buffer");
60128+ return;
60129+ }
60130+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60131+ if (!gr_audit_log_buf) {
60132+ panic("Unable to allocate grsecurity audit log buffer");
60133+ return;
60134+ }
60135+
60136+ /* allocate memory for authentication structure */
60137+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60138+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60139+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60140+
60141+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60142+ panic("Unable to allocate grsecurity authentication structure");
60143+ return;
60144+ }
60145+
60146+
60147+#ifdef CONFIG_GRKERNSEC_IO
60148+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60149+ grsec_disable_privio = 1;
60150+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60151+ grsec_disable_privio = 1;
60152+#else
60153+ grsec_disable_privio = 0;
60154+#endif
60155+#endif
60156+
60157+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60158+ /* for backward compatibility, tpe_invert always defaults to on if
60159+ enabled in the kernel
60160+ */
60161+ grsec_enable_tpe_invert = 1;
60162+#endif
60163+
60164+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60165+#ifndef CONFIG_GRKERNSEC_SYSCTL
60166+ grsec_lock = 1;
60167+#endif
60168+
60169+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60170+ grsec_enable_audit_textrel = 1;
60171+#endif
60172+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60173+ grsec_enable_log_rwxmaps = 1;
60174+#endif
60175+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60176+ grsec_enable_group = 1;
60177+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60178+#endif
60179+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60180+ grsec_enable_ptrace_readexec = 1;
60181+#endif
60182+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60183+ grsec_enable_chdir = 1;
60184+#endif
60185+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60186+ grsec_enable_harden_ptrace = 1;
60187+#endif
60188+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60189+ grsec_enable_mount = 1;
60190+#endif
60191+#ifdef CONFIG_GRKERNSEC_LINK
60192+ grsec_enable_link = 1;
60193+#endif
60194+#ifdef CONFIG_GRKERNSEC_BRUTE
60195+ grsec_enable_brute = 1;
60196+#endif
60197+#ifdef CONFIG_GRKERNSEC_DMESG
60198+ grsec_enable_dmesg = 1;
60199+#endif
60200+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60201+ grsec_enable_blackhole = 1;
60202+ grsec_lastack_retries = 4;
60203+#endif
60204+#ifdef CONFIG_GRKERNSEC_FIFO
60205+ grsec_enable_fifo = 1;
60206+#endif
60207+#ifdef CONFIG_GRKERNSEC_EXECLOG
60208+ grsec_enable_execlog = 1;
60209+#endif
60210+#ifdef CONFIG_GRKERNSEC_SETXID
60211+ grsec_enable_setxid = 1;
60212+#endif
60213+#ifdef CONFIG_GRKERNSEC_SIGNAL
60214+ grsec_enable_signal = 1;
60215+#endif
60216+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60217+ grsec_enable_forkfail = 1;
60218+#endif
60219+#ifdef CONFIG_GRKERNSEC_TIME
60220+ grsec_enable_time = 1;
60221+#endif
60222+#ifdef CONFIG_GRKERNSEC_RESLOG
60223+ grsec_resource_logging = 1;
60224+#endif
60225+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60226+ grsec_enable_chroot_findtask = 1;
60227+#endif
60228+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60229+ grsec_enable_chroot_unix = 1;
60230+#endif
60231+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60232+ grsec_enable_chroot_mount = 1;
60233+#endif
60234+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60235+ grsec_enable_chroot_fchdir = 1;
60236+#endif
60237+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60238+ grsec_enable_chroot_shmat = 1;
60239+#endif
60240+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60241+ grsec_enable_audit_ptrace = 1;
60242+#endif
60243+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60244+ grsec_enable_chroot_double = 1;
60245+#endif
60246+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60247+ grsec_enable_chroot_pivot = 1;
60248+#endif
60249+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60250+ grsec_enable_chroot_chdir = 1;
60251+#endif
60252+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60253+ grsec_enable_chroot_chmod = 1;
60254+#endif
60255+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60256+ grsec_enable_chroot_mknod = 1;
60257+#endif
60258+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60259+ grsec_enable_chroot_nice = 1;
60260+#endif
60261+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60262+ grsec_enable_chroot_execlog = 1;
60263+#endif
60264+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60265+ grsec_enable_chroot_caps = 1;
60266+#endif
60267+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60268+ grsec_enable_chroot_sysctl = 1;
60269+#endif
60270+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60271+ grsec_enable_symlinkown = 1;
60272+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60273+#endif
60274+#ifdef CONFIG_GRKERNSEC_TPE
60275+ grsec_enable_tpe = 1;
60276+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60277+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60278+ grsec_enable_tpe_all = 1;
60279+#endif
60280+#endif
60281+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60282+ grsec_enable_socket_all = 1;
60283+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60284+#endif
60285+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60286+ grsec_enable_socket_client = 1;
60287+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60288+#endif
60289+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60290+ grsec_enable_socket_server = 1;
60291+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60292+#endif
60293+#endif
60294+
60295+ return;
60296+}
60297diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60298new file mode 100644
60299index 0000000..6095407
60300--- /dev/null
60301+++ b/grsecurity/grsec_link.c
60302@@ -0,0 +1,58 @@
60303+#include <linux/kernel.h>
60304+#include <linux/sched.h>
60305+#include <linux/fs.h>
60306+#include <linux/file.h>
60307+#include <linux/grinternal.h>
60308+
60309+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60310+{
60311+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60312+ const struct inode *link_inode = link->dentry->d_inode;
60313+
60314+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60315+ /* ignore root-owned links, e.g. /proc/self */
60316+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60317+ !uid_eq(link_inode->i_uid, target->i_uid)) {
60318+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60319+ return 1;
60320+ }
60321+#endif
60322+ return 0;
60323+}
60324+
60325+int
60326+gr_handle_follow_link(const struct inode *parent,
60327+ const struct inode *inode,
60328+ const struct dentry *dentry, const struct vfsmount *mnt)
60329+{
60330+#ifdef CONFIG_GRKERNSEC_LINK
60331+ const struct cred *cred = current_cred();
60332+
60333+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60334+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60335+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60336+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60337+ return -EACCES;
60338+ }
60339+#endif
60340+ return 0;
60341+}
60342+
60343+int
60344+gr_handle_hardlink(const struct dentry *dentry,
60345+ const struct vfsmount *mnt,
60346+ struct inode *inode, const int mode, const struct filename *to)
60347+{
60348+#ifdef CONFIG_GRKERNSEC_LINK
60349+ const struct cred *cred = current_cred();
60350+
60351+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60352+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60353+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60354+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60355+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60356+ return -EPERM;
60357+ }
60358+#endif
60359+ return 0;
60360+}
60361diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60362new file mode 100644
60363index 0000000..7bd6c2b
60364--- /dev/null
60365+++ b/grsecurity/grsec_log.c
60366@@ -0,0 +1,329 @@
60367+#include <linux/kernel.h>
60368+#include <linux/sched.h>
60369+#include <linux/file.h>
60370+#include <linux/tty.h>
60371+#include <linux/fs.h>
60372+#include <linux/grinternal.h>
60373+
60374+#ifdef CONFIG_TREE_PREEMPT_RCU
60375+#define DISABLE_PREEMPT() preempt_disable()
60376+#define ENABLE_PREEMPT() preempt_enable()
60377+#else
60378+#define DISABLE_PREEMPT()
60379+#define ENABLE_PREEMPT()
60380+#endif
60381+
60382+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
60383+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
60384+
60385+#define BEGIN_LOCKS(x) \
60386+ DISABLE_PREEMPT(); \
60387+ rcu_read_lock(); \
60388+ read_lock(&tasklist_lock); \
60389+ read_lock(&grsec_exec_file_lock); \
60390+ if (x != GR_DO_AUDIT) \
60391+ spin_lock(&grsec_alert_lock); \
60392+ else \
60393+ spin_lock(&grsec_audit_lock)
60394+
60395+#define END_LOCKS(x) \
60396+ if (x != GR_DO_AUDIT) \
60397+ spin_unlock(&grsec_alert_lock); \
60398+ else \
60399+ spin_unlock(&grsec_audit_lock); \
60400+ read_unlock(&grsec_exec_file_lock); \
60401+ read_unlock(&tasklist_lock); \
60402+ rcu_read_unlock(); \
60403+ ENABLE_PREEMPT(); \
60404+ if (x == GR_DONT_AUDIT) \
60405+ gr_handle_alertkill(current)
60406+
60407+enum {
60408+ FLOODING,
60409+ NO_FLOODING
60410+};
60411+
60412+extern char *gr_alert_log_fmt;
60413+extern char *gr_audit_log_fmt;
60414+extern char *gr_alert_log_buf;
60415+extern char *gr_audit_log_buf;
60416+
60417+static int gr_log_start(int audit)
60418+{
60419+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60420+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60421+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60422+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60423+ unsigned long curr_secs = get_seconds();
60424+
60425+ if (audit == GR_DO_AUDIT)
60426+ goto set_fmt;
60427+
60428+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60429+ grsec_alert_wtime = curr_secs;
60430+ grsec_alert_fyet = 0;
60431+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60432+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60433+ grsec_alert_fyet++;
60434+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60435+ grsec_alert_wtime = curr_secs;
60436+ grsec_alert_fyet++;
60437+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60438+ return FLOODING;
60439+ }
60440+ else return FLOODING;
60441+
60442+set_fmt:
60443+#endif
60444+ memset(buf, 0, PAGE_SIZE);
60445+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
60446+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60447+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60448+ } else if (current->signal->curr_ip) {
60449+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60450+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60451+ } else if (gr_acl_is_enabled()) {
60452+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60453+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60454+ } else {
60455+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
60456+ strcpy(buf, fmt);
60457+ }
60458+
60459+ return NO_FLOODING;
60460+}
60461+
60462+static void gr_log_middle(int audit, const char *msg, va_list ap)
60463+ __attribute__ ((format (printf, 2, 0)));
60464+
60465+static void gr_log_middle(int audit, const char *msg, va_list ap)
60466+{
60467+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60468+ unsigned int len = strlen(buf);
60469+
60470+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60471+
60472+ return;
60473+}
60474+
60475+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60476+ __attribute__ ((format (printf, 2, 3)));
60477+
60478+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60479+{
60480+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60481+ unsigned int len = strlen(buf);
60482+ va_list ap;
60483+
60484+ va_start(ap, msg);
60485+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60486+ va_end(ap);
60487+
60488+ return;
60489+}
60490+
60491+static void gr_log_end(int audit, int append_default)
60492+{
60493+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60494+ if (append_default) {
60495+ struct task_struct *task = current;
60496+ struct task_struct *parent = task->real_parent;
60497+ const struct cred *cred = __task_cred(task);
60498+ const struct cred *pcred = __task_cred(parent);
60499+ unsigned int len = strlen(buf);
60500+
60501+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60502+ }
60503+
60504+ printk("%s\n", buf);
60505+
60506+ return;
60507+}
60508+
60509+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60510+{
60511+ int logtype;
60512+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60513+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60514+ void *voidptr = NULL;
60515+ int num1 = 0, num2 = 0;
60516+ unsigned long ulong1 = 0, ulong2 = 0;
60517+ struct dentry *dentry = NULL;
60518+ struct vfsmount *mnt = NULL;
60519+ struct file *file = NULL;
60520+ struct task_struct *task = NULL;
60521+ const struct cred *cred, *pcred;
60522+ va_list ap;
60523+
60524+ BEGIN_LOCKS(audit);
60525+ logtype = gr_log_start(audit);
60526+ if (logtype == FLOODING) {
60527+ END_LOCKS(audit);
60528+ return;
60529+ }
60530+ va_start(ap, argtypes);
60531+ switch (argtypes) {
60532+ case GR_TTYSNIFF:
60533+ task = va_arg(ap, struct task_struct *);
60534+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task_pid_nr(task), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent));
60535+ break;
60536+ case GR_SYSCTL_HIDDEN:
60537+ str1 = va_arg(ap, char *);
60538+ gr_log_middle_varargs(audit, msg, result, str1);
60539+ break;
60540+ case GR_RBAC:
60541+ dentry = va_arg(ap, struct dentry *);
60542+ mnt = va_arg(ap, struct vfsmount *);
60543+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60544+ break;
60545+ case GR_RBAC_STR:
60546+ dentry = va_arg(ap, struct dentry *);
60547+ mnt = va_arg(ap, struct vfsmount *);
60548+ str1 = va_arg(ap, char *);
60549+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60550+ break;
60551+ case GR_STR_RBAC:
60552+ str1 = va_arg(ap, char *);
60553+ dentry = va_arg(ap, struct dentry *);
60554+ mnt = va_arg(ap, struct vfsmount *);
60555+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60556+ break;
60557+ case GR_RBAC_MODE2:
60558+ dentry = va_arg(ap, struct dentry *);
60559+ mnt = va_arg(ap, struct vfsmount *);
60560+ str1 = va_arg(ap, char *);
60561+ str2 = va_arg(ap, char *);
60562+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60563+ break;
60564+ case GR_RBAC_MODE3:
60565+ dentry = va_arg(ap, struct dentry *);
60566+ mnt = va_arg(ap, struct vfsmount *);
60567+ str1 = va_arg(ap, char *);
60568+ str2 = va_arg(ap, char *);
60569+ str3 = va_arg(ap, char *);
60570+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60571+ break;
60572+ case GR_FILENAME:
60573+ dentry = va_arg(ap, struct dentry *);
60574+ mnt = va_arg(ap, struct vfsmount *);
60575+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60576+ break;
60577+ case GR_STR_FILENAME:
60578+ str1 = va_arg(ap, char *);
60579+ dentry = va_arg(ap, struct dentry *);
60580+ mnt = va_arg(ap, struct vfsmount *);
60581+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60582+ break;
60583+ case GR_FILENAME_STR:
60584+ dentry = va_arg(ap, struct dentry *);
60585+ mnt = va_arg(ap, struct vfsmount *);
60586+ str1 = va_arg(ap, char *);
60587+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60588+ break;
60589+ case GR_FILENAME_TWO_INT:
60590+ dentry = va_arg(ap, struct dentry *);
60591+ mnt = va_arg(ap, struct vfsmount *);
60592+ num1 = va_arg(ap, int);
60593+ num2 = va_arg(ap, int);
60594+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60595+ break;
60596+ case GR_FILENAME_TWO_INT_STR:
60597+ dentry = va_arg(ap, struct dentry *);
60598+ mnt = va_arg(ap, struct vfsmount *);
60599+ num1 = va_arg(ap, int);
60600+ num2 = va_arg(ap, int);
60601+ str1 = va_arg(ap, char *);
60602+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60603+ break;
60604+ case GR_TEXTREL:
60605+ file = va_arg(ap, struct file *);
60606+ ulong1 = va_arg(ap, unsigned long);
60607+ ulong2 = va_arg(ap, unsigned long);
60608+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60609+ break;
60610+ case GR_PTRACE:
60611+ task = va_arg(ap, struct task_struct *);
60612+ 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_nr(task));
60613+ break;
60614+ case GR_RESOURCE:
60615+ task = va_arg(ap, struct task_struct *);
60616+ cred = __task_cred(task);
60617+ pcred = __task_cred(task->real_parent);
60618+ ulong1 = va_arg(ap, unsigned long);
60619+ str1 = va_arg(ap, char *);
60620+ ulong2 = va_arg(ap, unsigned long);
60621+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60622+ break;
60623+ case GR_CAP:
60624+ task = va_arg(ap, struct task_struct *);
60625+ cred = __task_cred(task);
60626+ pcred = __task_cred(task->real_parent);
60627+ str1 = va_arg(ap, char *);
60628+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60629+ break;
60630+ case GR_SIG:
60631+ str1 = va_arg(ap, char *);
60632+ voidptr = va_arg(ap, void *);
60633+ gr_log_middle_varargs(audit, msg, str1, voidptr);
60634+ break;
60635+ case GR_SIG2:
60636+ task = va_arg(ap, struct task_struct *);
60637+ cred = __task_cred(task);
60638+ pcred = __task_cred(task->real_parent);
60639+ num1 = va_arg(ap, int);
60640+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath0(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60641+ break;
60642+ case GR_CRASH1:
60643+ task = va_arg(ap, struct task_struct *);
60644+ cred = __task_cred(task);
60645+ pcred = __task_cred(task->real_parent);
60646+ ulong1 = va_arg(ap, unsigned long);
60647+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), GR_GLOBAL_UID(cred->uid), ulong1);
60648+ break;
60649+ case GR_CRASH2:
60650+ task = va_arg(ap, struct task_struct *);
60651+ cred = __task_cred(task);
60652+ pcred = __task_cred(task->real_parent);
60653+ ulong1 = va_arg(ap, unsigned long);
60654+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_GID(cred->egid), gr_parent_task_fullpath(task), task->real_parent->comm, task_pid_nr(task->real_parent), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid), ulong1);
60655+ break;
60656+ case GR_RWXMAP:
60657+ file = va_arg(ap, struct file *);
60658+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60659+ break;
60660+ case GR_PSACCT:
60661+ {
60662+ unsigned int wday, cday;
60663+ __u8 whr, chr;
60664+ __u8 wmin, cmin;
60665+ __u8 wsec, csec;
60666+ char cur_tty[64] = { 0 };
60667+ char parent_tty[64] = { 0 };
60668+
60669+ task = va_arg(ap, struct task_struct *);
60670+ wday = va_arg(ap, unsigned int);
60671+ cday = va_arg(ap, unsigned int);
60672+ whr = va_arg(ap, int);
60673+ chr = va_arg(ap, int);
60674+ wmin = va_arg(ap, int);
60675+ cmin = va_arg(ap, int);
60676+ wsec = va_arg(ap, int);
60677+ csec = va_arg(ap, int);
60678+ ulong1 = va_arg(ap, unsigned long);
60679+ cred = __task_cred(task);
60680+ pcred = __task_cred(task->real_parent);
60681+
60682+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task_pid_nr(task), &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), GR_GLOBAL_UID(cred->uid), GR_GLOBAL_UID(cred->euid), GR_GLOBAL_GID(cred->gid), GR_GLOBAL_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_pid_nr(task->real_parent), &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), GR_GLOBAL_UID(pcred->uid), GR_GLOBAL_UID(pcred->euid), GR_GLOBAL_GID(pcred->gid), GR_GLOBAL_GID(pcred->egid));
60683+ }
60684+ break;
60685+ default:
60686+ gr_log_middle(audit, msg, ap);
60687+ }
60688+ va_end(ap);
60689+ // these don't need DEFAULTSECARGS printed on the end
60690+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60691+ gr_log_end(audit, 0);
60692+ else
60693+ gr_log_end(audit, 1);
60694+ END_LOCKS(audit);
60695+}
60696diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60697new file mode 100644
60698index 0000000..f536303
60699--- /dev/null
60700+++ b/grsecurity/grsec_mem.c
60701@@ -0,0 +1,40 @@
60702+#include <linux/kernel.h>
60703+#include <linux/sched.h>
60704+#include <linux/mm.h>
60705+#include <linux/mman.h>
60706+#include <linux/grinternal.h>
60707+
60708+void
60709+gr_handle_ioperm(void)
60710+{
60711+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60712+ return;
60713+}
60714+
60715+void
60716+gr_handle_iopl(void)
60717+{
60718+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60719+ return;
60720+}
60721+
60722+void
60723+gr_handle_mem_readwrite(u64 from, u64 to)
60724+{
60725+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60726+ return;
60727+}
60728+
60729+void
60730+gr_handle_vm86(void)
60731+{
60732+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60733+ return;
60734+}
60735+
60736+void
60737+gr_log_badprocpid(const char *entry)
60738+{
60739+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60740+ return;
60741+}
60742diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60743new file mode 100644
60744index 0000000..2131422
60745--- /dev/null
60746+++ b/grsecurity/grsec_mount.c
60747@@ -0,0 +1,62 @@
60748+#include <linux/kernel.h>
60749+#include <linux/sched.h>
60750+#include <linux/mount.h>
60751+#include <linux/grsecurity.h>
60752+#include <linux/grinternal.h>
60753+
60754+void
60755+gr_log_remount(const char *devname, const int retval)
60756+{
60757+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60758+ if (grsec_enable_mount && (retval >= 0))
60759+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60760+#endif
60761+ return;
60762+}
60763+
60764+void
60765+gr_log_unmount(const char *devname, const int retval)
60766+{
60767+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60768+ if (grsec_enable_mount && (retval >= 0))
60769+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60770+#endif
60771+ return;
60772+}
60773+
60774+void
60775+gr_log_mount(const char *from, const char *to, const int retval)
60776+{
60777+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60778+ if (grsec_enable_mount && (retval >= 0))
60779+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60780+#endif
60781+ return;
60782+}
60783+
60784+int
60785+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60786+{
60787+#ifdef CONFIG_GRKERNSEC_ROFS
60788+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60789+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
60790+ return -EPERM;
60791+ } else
60792+ return 0;
60793+#endif
60794+ return 0;
60795+}
60796+
60797+int
60798+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
60799+{
60800+#ifdef CONFIG_GRKERNSEC_ROFS
60801+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
60802+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
60803+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
60804+ return -EPERM;
60805+ } else
60806+ return 0;
60807+#endif
60808+ return 0;
60809+}
60810diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
60811new file mode 100644
60812index 0000000..a3b12a0
60813--- /dev/null
60814+++ b/grsecurity/grsec_pax.c
60815@@ -0,0 +1,36 @@
60816+#include <linux/kernel.h>
60817+#include <linux/sched.h>
60818+#include <linux/mm.h>
60819+#include <linux/file.h>
60820+#include <linux/grinternal.h>
60821+#include <linux/grsecurity.h>
60822+
60823+void
60824+gr_log_textrel(struct vm_area_struct * vma)
60825+{
60826+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60827+ if (grsec_enable_audit_textrel)
60828+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
60829+#endif
60830+ return;
60831+}
60832+
60833+void
60834+gr_log_rwxmmap(struct file *file)
60835+{
60836+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60837+ if (grsec_enable_log_rwxmaps)
60838+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
60839+#endif
60840+ return;
60841+}
60842+
60843+void
60844+gr_log_rwxmprotect(struct file *file)
60845+{
60846+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60847+ if (grsec_enable_log_rwxmaps)
60848+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
60849+#endif
60850+ return;
60851+}
60852diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
60853new file mode 100644
60854index 0000000..f7f29aa
60855--- /dev/null
60856+++ b/grsecurity/grsec_ptrace.c
60857@@ -0,0 +1,30 @@
60858+#include <linux/kernel.h>
60859+#include <linux/sched.h>
60860+#include <linux/grinternal.h>
60861+#include <linux/security.h>
60862+
60863+void
60864+gr_audit_ptrace(struct task_struct *task)
60865+{
60866+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60867+ if (grsec_enable_audit_ptrace)
60868+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
60869+#endif
60870+ return;
60871+}
60872+
60873+int
60874+gr_ptrace_readexec(struct file *file, int unsafe_flags)
60875+{
60876+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60877+ const struct dentry *dentry = file->f_path.dentry;
60878+ const struct vfsmount *mnt = file->f_path.mnt;
60879+
60880+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
60881+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
60882+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
60883+ return -EACCES;
60884+ }
60885+#endif
60886+ return 0;
60887+}
60888diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
60889new file mode 100644
60890index 0000000..5c00416
60891--- /dev/null
60892+++ b/grsecurity/grsec_sig.c
60893@@ -0,0 +1,222 @@
60894+#include <linux/kernel.h>
60895+#include <linux/sched.h>
60896+#include <linux/delay.h>
60897+#include <linux/grsecurity.h>
60898+#include <linux/grinternal.h>
60899+#include <linux/hardirq.h>
60900+
60901+char *signames[] = {
60902+ [SIGSEGV] = "Segmentation fault",
60903+ [SIGILL] = "Illegal instruction",
60904+ [SIGABRT] = "Abort",
60905+ [SIGBUS] = "Invalid alignment/Bus error"
60906+};
60907+
60908+void
60909+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
60910+{
60911+#ifdef CONFIG_GRKERNSEC_SIGNAL
60912+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
60913+ (sig == SIGABRT) || (sig == SIGBUS))) {
60914+ if (t->pid == current->pid) {
60915+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
60916+ } else {
60917+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
60918+ }
60919+ }
60920+#endif
60921+ return;
60922+}
60923+
60924+int
60925+gr_handle_signal(const struct task_struct *p, const int sig)
60926+{
60927+#ifdef CONFIG_GRKERNSEC
60928+ /* ignore the 0 signal for protected task checks */
60929+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
60930+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
60931+ return -EPERM;
60932+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
60933+ return -EPERM;
60934+ }
60935+#endif
60936+ return 0;
60937+}
60938+
60939+#ifdef CONFIG_GRKERNSEC
60940+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
60941+
60942+int gr_fake_force_sig(int sig, struct task_struct *t)
60943+{
60944+ unsigned long int flags;
60945+ int ret, blocked, ignored;
60946+ struct k_sigaction *action;
60947+
60948+ spin_lock_irqsave(&t->sighand->siglock, flags);
60949+ action = &t->sighand->action[sig-1];
60950+ ignored = action->sa.sa_handler == SIG_IGN;
60951+ blocked = sigismember(&t->blocked, sig);
60952+ if (blocked || ignored) {
60953+ action->sa.sa_handler = SIG_DFL;
60954+ if (blocked) {
60955+ sigdelset(&t->blocked, sig);
60956+ recalc_sigpending_and_wake(t);
60957+ }
60958+ }
60959+ if (action->sa.sa_handler == SIG_DFL)
60960+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
60961+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
60962+
60963+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
60964+
60965+ return ret;
60966+}
60967+#endif
60968+
60969+#ifdef CONFIG_GRKERNSEC_BRUTE
60970+#define GR_USER_BAN_TIME (15 * 60)
60971+#define GR_DAEMON_BRUTE_TIME (30 * 60)
60972+
60973+static int __get_dumpable(unsigned long mm_flags)
60974+{
60975+ int ret;
60976+
60977+ ret = mm_flags & MMF_DUMPABLE_MASK;
60978+ return (ret >= 2) ? 2 : ret;
60979+}
60980+#endif
60981+
60982+void gr_handle_brute_attach(unsigned long mm_flags)
60983+{
60984+#ifdef CONFIG_GRKERNSEC_BRUTE
60985+ struct task_struct *p = current;
60986+ kuid_t uid = GLOBAL_ROOT_UID;
60987+ int daemon = 0;
60988+
60989+ if (!grsec_enable_brute)
60990+ return;
60991+
60992+ rcu_read_lock();
60993+ read_lock(&tasklist_lock);
60994+ read_lock(&grsec_exec_file_lock);
60995+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
60996+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
60997+ p->real_parent->brute = 1;
60998+ daemon = 1;
60999+ } else {
61000+ const struct cred *cred = __task_cred(p), *cred2;
61001+ struct task_struct *tsk, *tsk2;
61002+
61003+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61004+ struct user_struct *user;
61005+
61006+ uid = cred->uid;
61007+
61008+ /* this is put upon execution past expiration */
61009+ user = find_user(uid);
61010+ if (user == NULL)
61011+ goto unlock;
61012+ user->banned = 1;
61013+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61014+ if (user->ban_expires == ~0UL)
61015+ user->ban_expires--;
61016+
61017+ do_each_thread(tsk2, tsk) {
61018+ cred2 = __task_cred(tsk);
61019+ if (tsk != p && uid_eq(cred2->uid, uid))
61020+ gr_fake_force_sig(SIGKILL, tsk);
61021+ } while_each_thread(tsk2, tsk);
61022+ }
61023+ }
61024+unlock:
61025+ read_unlock(&grsec_exec_file_lock);
61026+ read_unlock(&tasklist_lock);
61027+ rcu_read_unlock();
61028+
61029+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
61030+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61031+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61032+ else if (daemon)
61033+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61034+
61035+#endif
61036+ return;
61037+}
61038+
61039+void gr_handle_brute_check(void)
61040+{
61041+#ifdef CONFIG_GRKERNSEC_BRUTE
61042+ struct task_struct *p = current;
61043+
61044+ if (unlikely(p->brute)) {
61045+ if (!grsec_enable_brute)
61046+ p->brute = 0;
61047+ else if (time_before(get_seconds(), p->brute_expires))
61048+ msleep(30 * 1000);
61049+ }
61050+#endif
61051+ return;
61052+}
61053+
61054+void gr_handle_kernel_exploit(void)
61055+{
61056+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61057+ const struct cred *cred;
61058+ struct task_struct *tsk, *tsk2;
61059+ struct user_struct *user;
61060+ kuid_t uid;
61061+
61062+ if (in_irq() || in_serving_softirq() || in_nmi())
61063+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61064+
61065+ uid = current_uid();
61066+
61067+ if (uid_eq(uid, GLOBAL_ROOT_UID))
61068+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
61069+ else {
61070+ /* kill all the processes of this user, hold a reference
61071+ to their creds struct, and prevent them from creating
61072+ another process until system reset
61073+ */
61074+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61075+ from_kuid_munged(&init_user_ns, uid));
61076+ /* we intentionally leak this ref */
61077+ user = get_uid(current->cred->user);
61078+ if (user) {
61079+ user->banned = 1;
61080+ user->ban_expires = ~0UL;
61081+ }
61082+
61083+ read_lock(&tasklist_lock);
61084+ do_each_thread(tsk2, tsk) {
61085+ cred = __task_cred(tsk);
61086+ if (uid_eq(cred->uid, uid))
61087+ gr_fake_force_sig(SIGKILL, tsk);
61088+ } while_each_thread(tsk2, tsk);
61089+ read_unlock(&tasklist_lock);
61090+ }
61091+#endif
61092+}
61093+
61094+int __gr_process_user_ban(struct user_struct *user)
61095+{
61096+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61097+ if (unlikely(user->banned)) {
61098+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61099+ user->banned = 0;
61100+ user->ban_expires = 0;
61101+ free_uid(user);
61102+ } else
61103+ return -EPERM;
61104+ }
61105+#endif
61106+ return 0;
61107+}
61108+
61109+int gr_process_user_ban(void)
61110+{
61111+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61112+ return __gr_process_user_ban(current->cred->user);
61113+#endif
61114+ return 0;
61115+}
61116diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61117new file mode 100644
61118index 0000000..4030d57
61119--- /dev/null
61120+++ b/grsecurity/grsec_sock.c
61121@@ -0,0 +1,244 @@
61122+#include <linux/kernel.h>
61123+#include <linux/module.h>
61124+#include <linux/sched.h>
61125+#include <linux/file.h>
61126+#include <linux/net.h>
61127+#include <linux/in.h>
61128+#include <linux/ip.h>
61129+#include <net/sock.h>
61130+#include <net/inet_sock.h>
61131+#include <linux/grsecurity.h>
61132+#include <linux/grinternal.h>
61133+#include <linux/gracl.h>
61134+
61135+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61136+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61137+
61138+EXPORT_SYMBOL(gr_search_udp_recvmsg);
61139+EXPORT_SYMBOL(gr_search_udp_sendmsg);
61140+
61141+#ifdef CONFIG_UNIX_MODULE
61142+EXPORT_SYMBOL(gr_acl_handle_unix);
61143+EXPORT_SYMBOL(gr_acl_handle_mknod);
61144+EXPORT_SYMBOL(gr_handle_chroot_unix);
61145+EXPORT_SYMBOL(gr_handle_create);
61146+#endif
61147+
61148+#ifdef CONFIG_GRKERNSEC
61149+#define gr_conn_table_size 32749
61150+struct conn_table_entry {
61151+ struct conn_table_entry *next;
61152+ struct signal_struct *sig;
61153+};
61154+
61155+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61156+DEFINE_SPINLOCK(gr_conn_table_lock);
61157+
61158+extern const char * gr_socktype_to_name(unsigned char type);
61159+extern const char * gr_proto_to_name(unsigned char proto);
61160+extern const char * gr_sockfamily_to_name(unsigned char family);
61161+
61162+static __inline__ int
61163+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61164+{
61165+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61166+}
61167+
61168+static __inline__ int
61169+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61170+ __u16 sport, __u16 dport)
61171+{
61172+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61173+ sig->gr_sport == sport && sig->gr_dport == dport))
61174+ return 1;
61175+ else
61176+ return 0;
61177+}
61178+
61179+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61180+{
61181+ struct conn_table_entry **match;
61182+ unsigned int index;
61183+
61184+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61185+ sig->gr_sport, sig->gr_dport,
61186+ gr_conn_table_size);
61187+
61188+ newent->sig = sig;
61189+
61190+ match = &gr_conn_table[index];
61191+ newent->next = *match;
61192+ *match = newent;
61193+
61194+ return;
61195+}
61196+
61197+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61198+{
61199+ struct conn_table_entry *match, *last = NULL;
61200+ unsigned int index;
61201+
61202+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61203+ sig->gr_sport, sig->gr_dport,
61204+ gr_conn_table_size);
61205+
61206+ match = gr_conn_table[index];
61207+ while (match && !conn_match(match->sig,
61208+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61209+ sig->gr_dport)) {
61210+ last = match;
61211+ match = match->next;
61212+ }
61213+
61214+ if (match) {
61215+ if (last)
61216+ last->next = match->next;
61217+ else
61218+ gr_conn_table[index] = NULL;
61219+ kfree(match);
61220+ }
61221+
61222+ return;
61223+}
61224+
61225+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61226+ __u16 sport, __u16 dport)
61227+{
61228+ struct conn_table_entry *match;
61229+ unsigned int index;
61230+
61231+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61232+
61233+ match = gr_conn_table[index];
61234+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61235+ match = match->next;
61236+
61237+ if (match)
61238+ return match->sig;
61239+ else
61240+ return NULL;
61241+}
61242+
61243+#endif
61244+
61245+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61246+{
61247+#ifdef CONFIG_GRKERNSEC
61248+ struct signal_struct *sig = task->signal;
61249+ struct conn_table_entry *newent;
61250+
61251+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61252+ if (newent == NULL)
61253+ return;
61254+ /* no bh lock needed since we are called with bh disabled */
61255+ spin_lock(&gr_conn_table_lock);
61256+ gr_del_task_from_ip_table_nolock(sig);
61257+ sig->gr_saddr = inet->inet_rcv_saddr;
61258+ sig->gr_daddr = inet->inet_daddr;
61259+ sig->gr_sport = inet->inet_sport;
61260+ sig->gr_dport = inet->inet_dport;
61261+ gr_add_to_task_ip_table_nolock(sig, newent);
61262+ spin_unlock(&gr_conn_table_lock);
61263+#endif
61264+ return;
61265+}
61266+
61267+void gr_del_task_from_ip_table(struct task_struct *task)
61268+{
61269+#ifdef CONFIG_GRKERNSEC
61270+ spin_lock_bh(&gr_conn_table_lock);
61271+ gr_del_task_from_ip_table_nolock(task->signal);
61272+ spin_unlock_bh(&gr_conn_table_lock);
61273+#endif
61274+ return;
61275+}
61276+
61277+void
61278+gr_attach_curr_ip(const struct sock *sk)
61279+{
61280+#ifdef CONFIG_GRKERNSEC
61281+ struct signal_struct *p, *set;
61282+ const struct inet_sock *inet = inet_sk(sk);
61283+
61284+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61285+ return;
61286+
61287+ set = current->signal;
61288+
61289+ spin_lock_bh(&gr_conn_table_lock);
61290+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61291+ inet->inet_dport, inet->inet_sport);
61292+ if (unlikely(p != NULL)) {
61293+ set->curr_ip = p->curr_ip;
61294+ set->used_accept = 1;
61295+ gr_del_task_from_ip_table_nolock(p);
61296+ spin_unlock_bh(&gr_conn_table_lock);
61297+ return;
61298+ }
61299+ spin_unlock_bh(&gr_conn_table_lock);
61300+
61301+ set->curr_ip = inet->inet_daddr;
61302+ set->used_accept = 1;
61303+#endif
61304+ return;
61305+}
61306+
61307+int
61308+gr_handle_sock_all(const int family, const int type, const int protocol)
61309+{
61310+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61311+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61312+ (family != AF_UNIX)) {
61313+ if (family == AF_INET)
61314+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61315+ else
61316+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61317+ return -EACCES;
61318+ }
61319+#endif
61320+ return 0;
61321+}
61322+
61323+int
61324+gr_handle_sock_server(const struct sockaddr *sck)
61325+{
61326+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61327+ if (grsec_enable_socket_server &&
61328+ in_group_p(grsec_socket_server_gid) &&
61329+ sck && (sck->sa_family != AF_UNIX) &&
61330+ (sck->sa_family != AF_LOCAL)) {
61331+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61332+ return -EACCES;
61333+ }
61334+#endif
61335+ return 0;
61336+}
61337+
61338+int
61339+gr_handle_sock_server_other(const struct sock *sck)
61340+{
61341+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61342+ if (grsec_enable_socket_server &&
61343+ in_group_p(grsec_socket_server_gid) &&
61344+ sck && (sck->sk_family != AF_UNIX) &&
61345+ (sck->sk_family != AF_LOCAL)) {
61346+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61347+ return -EACCES;
61348+ }
61349+#endif
61350+ return 0;
61351+}
61352+
61353+int
61354+gr_handle_sock_client(const struct sockaddr *sck)
61355+{
61356+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61357+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61358+ sck && (sck->sa_family != AF_UNIX) &&
61359+ (sck->sa_family != AF_LOCAL)) {
61360+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61361+ return -EACCES;
61362+ }
61363+#endif
61364+ return 0;
61365+}
61366diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61367new file mode 100644
61368index 0000000..f55ef0f
61369--- /dev/null
61370+++ b/grsecurity/grsec_sysctl.c
61371@@ -0,0 +1,469 @@
61372+#include <linux/kernel.h>
61373+#include <linux/sched.h>
61374+#include <linux/sysctl.h>
61375+#include <linux/grsecurity.h>
61376+#include <linux/grinternal.h>
61377+
61378+int
61379+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61380+{
61381+#ifdef CONFIG_GRKERNSEC_SYSCTL
61382+ if (dirname == NULL || name == NULL)
61383+ return 0;
61384+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61385+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61386+ return -EACCES;
61387+ }
61388+#endif
61389+ return 0;
61390+}
61391+
61392+#ifdef CONFIG_GRKERNSEC_ROFS
61393+static int __maybe_unused one = 1;
61394+#endif
61395+
61396+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61397+struct ctl_table grsecurity_table[] = {
61398+#ifdef CONFIG_GRKERNSEC_SYSCTL
61399+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61400+#ifdef CONFIG_GRKERNSEC_IO
61401+ {
61402+ .procname = "disable_priv_io",
61403+ .data = &grsec_disable_privio,
61404+ .maxlen = sizeof(int),
61405+ .mode = 0600,
61406+ .proc_handler = &proc_dointvec,
61407+ },
61408+#endif
61409+#endif
61410+#ifdef CONFIG_GRKERNSEC_LINK
61411+ {
61412+ .procname = "linking_restrictions",
61413+ .data = &grsec_enable_link,
61414+ .maxlen = sizeof(int),
61415+ .mode = 0600,
61416+ .proc_handler = &proc_dointvec,
61417+ },
61418+#endif
61419+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61420+ {
61421+ .procname = "enforce_symlinksifowner",
61422+ .data = &grsec_enable_symlinkown,
61423+ .maxlen = sizeof(int),
61424+ .mode = 0600,
61425+ .proc_handler = &proc_dointvec,
61426+ },
61427+ {
61428+ .procname = "symlinkown_gid",
61429+ .data = &grsec_symlinkown_gid,
61430+ .maxlen = sizeof(int),
61431+ .mode = 0600,
61432+ .proc_handler = &proc_dointvec,
61433+ },
61434+#endif
61435+#ifdef CONFIG_GRKERNSEC_BRUTE
61436+ {
61437+ .procname = "deter_bruteforce",
61438+ .data = &grsec_enable_brute,
61439+ .maxlen = sizeof(int),
61440+ .mode = 0600,
61441+ .proc_handler = &proc_dointvec,
61442+ },
61443+#endif
61444+#ifdef CONFIG_GRKERNSEC_FIFO
61445+ {
61446+ .procname = "fifo_restrictions",
61447+ .data = &grsec_enable_fifo,
61448+ .maxlen = sizeof(int),
61449+ .mode = 0600,
61450+ .proc_handler = &proc_dointvec,
61451+ },
61452+#endif
61453+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61454+ {
61455+ .procname = "ptrace_readexec",
61456+ .data = &grsec_enable_ptrace_readexec,
61457+ .maxlen = sizeof(int),
61458+ .mode = 0600,
61459+ .proc_handler = &proc_dointvec,
61460+ },
61461+#endif
61462+#ifdef CONFIG_GRKERNSEC_SETXID
61463+ {
61464+ .procname = "consistent_setxid",
61465+ .data = &grsec_enable_setxid,
61466+ .maxlen = sizeof(int),
61467+ .mode = 0600,
61468+ .proc_handler = &proc_dointvec,
61469+ },
61470+#endif
61471+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61472+ {
61473+ .procname = "ip_blackhole",
61474+ .data = &grsec_enable_blackhole,
61475+ .maxlen = sizeof(int),
61476+ .mode = 0600,
61477+ .proc_handler = &proc_dointvec,
61478+ },
61479+ {
61480+ .procname = "lastack_retries",
61481+ .data = &grsec_lastack_retries,
61482+ .maxlen = sizeof(int),
61483+ .mode = 0600,
61484+ .proc_handler = &proc_dointvec,
61485+ },
61486+#endif
61487+#ifdef CONFIG_GRKERNSEC_EXECLOG
61488+ {
61489+ .procname = "exec_logging",
61490+ .data = &grsec_enable_execlog,
61491+ .maxlen = sizeof(int),
61492+ .mode = 0600,
61493+ .proc_handler = &proc_dointvec,
61494+ },
61495+#endif
61496+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61497+ {
61498+ .procname = "rwxmap_logging",
61499+ .data = &grsec_enable_log_rwxmaps,
61500+ .maxlen = sizeof(int),
61501+ .mode = 0600,
61502+ .proc_handler = &proc_dointvec,
61503+ },
61504+#endif
61505+#ifdef CONFIG_GRKERNSEC_SIGNAL
61506+ {
61507+ .procname = "signal_logging",
61508+ .data = &grsec_enable_signal,
61509+ .maxlen = sizeof(int),
61510+ .mode = 0600,
61511+ .proc_handler = &proc_dointvec,
61512+ },
61513+#endif
61514+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61515+ {
61516+ .procname = "forkfail_logging",
61517+ .data = &grsec_enable_forkfail,
61518+ .maxlen = sizeof(int),
61519+ .mode = 0600,
61520+ .proc_handler = &proc_dointvec,
61521+ },
61522+#endif
61523+#ifdef CONFIG_GRKERNSEC_TIME
61524+ {
61525+ .procname = "timechange_logging",
61526+ .data = &grsec_enable_time,
61527+ .maxlen = sizeof(int),
61528+ .mode = 0600,
61529+ .proc_handler = &proc_dointvec,
61530+ },
61531+#endif
61532+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61533+ {
61534+ .procname = "chroot_deny_shmat",
61535+ .data = &grsec_enable_chroot_shmat,
61536+ .maxlen = sizeof(int),
61537+ .mode = 0600,
61538+ .proc_handler = &proc_dointvec,
61539+ },
61540+#endif
61541+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61542+ {
61543+ .procname = "chroot_deny_unix",
61544+ .data = &grsec_enable_chroot_unix,
61545+ .maxlen = sizeof(int),
61546+ .mode = 0600,
61547+ .proc_handler = &proc_dointvec,
61548+ },
61549+#endif
61550+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61551+ {
61552+ .procname = "chroot_deny_mount",
61553+ .data = &grsec_enable_chroot_mount,
61554+ .maxlen = sizeof(int),
61555+ .mode = 0600,
61556+ .proc_handler = &proc_dointvec,
61557+ },
61558+#endif
61559+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61560+ {
61561+ .procname = "chroot_deny_fchdir",
61562+ .data = &grsec_enable_chroot_fchdir,
61563+ .maxlen = sizeof(int),
61564+ .mode = 0600,
61565+ .proc_handler = &proc_dointvec,
61566+ },
61567+#endif
61568+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61569+ {
61570+ .procname = "chroot_deny_chroot",
61571+ .data = &grsec_enable_chroot_double,
61572+ .maxlen = sizeof(int),
61573+ .mode = 0600,
61574+ .proc_handler = &proc_dointvec,
61575+ },
61576+#endif
61577+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61578+ {
61579+ .procname = "chroot_deny_pivot",
61580+ .data = &grsec_enable_chroot_pivot,
61581+ .maxlen = sizeof(int),
61582+ .mode = 0600,
61583+ .proc_handler = &proc_dointvec,
61584+ },
61585+#endif
61586+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61587+ {
61588+ .procname = "chroot_enforce_chdir",
61589+ .data = &grsec_enable_chroot_chdir,
61590+ .maxlen = sizeof(int),
61591+ .mode = 0600,
61592+ .proc_handler = &proc_dointvec,
61593+ },
61594+#endif
61595+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61596+ {
61597+ .procname = "chroot_deny_chmod",
61598+ .data = &grsec_enable_chroot_chmod,
61599+ .maxlen = sizeof(int),
61600+ .mode = 0600,
61601+ .proc_handler = &proc_dointvec,
61602+ },
61603+#endif
61604+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61605+ {
61606+ .procname = "chroot_deny_mknod",
61607+ .data = &grsec_enable_chroot_mknod,
61608+ .maxlen = sizeof(int),
61609+ .mode = 0600,
61610+ .proc_handler = &proc_dointvec,
61611+ },
61612+#endif
61613+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61614+ {
61615+ .procname = "chroot_restrict_nice",
61616+ .data = &grsec_enable_chroot_nice,
61617+ .maxlen = sizeof(int),
61618+ .mode = 0600,
61619+ .proc_handler = &proc_dointvec,
61620+ },
61621+#endif
61622+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61623+ {
61624+ .procname = "chroot_execlog",
61625+ .data = &grsec_enable_chroot_execlog,
61626+ .maxlen = sizeof(int),
61627+ .mode = 0600,
61628+ .proc_handler = &proc_dointvec,
61629+ },
61630+#endif
61631+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61632+ {
61633+ .procname = "chroot_caps",
61634+ .data = &grsec_enable_chroot_caps,
61635+ .maxlen = sizeof(int),
61636+ .mode = 0600,
61637+ .proc_handler = &proc_dointvec,
61638+ },
61639+#endif
61640+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61641+ {
61642+ .procname = "chroot_deny_sysctl",
61643+ .data = &grsec_enable_chroot_sysctl,
61644+ .maxlen = sizeof(int),
61645+ .mode = 0600,
61646+ .proc_handler = &proc_dointvec,
61647+ },
61648+#endif
61649+#ifdef CONFIG_GRKERNSEC_TPE
61650+ {
61651+ .procname = "tpe",
61652+ .data = &grsec_enable_tpe,
61653+ .maxlen = sizeof(int),
61654+ .mode = 0600,
61655+ .proc_handler = &proc_dointvec,
61656+ },
61657+ {
61658+ .procname = "tpe_gid",
61659+ .data = &grsec_tpe_gid,
61660+ .maxlen = sizeof(int),
61661+ .mode = 0600,
61662+ .proc_handler = &proc_dointvec,
61663+ },
61664+#endif
61665+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61666+ {
61667+ .procname = "tpe_invert",
61668+ .data = &grsec_enable_tpe_invert,
61669+ .maxlen = sizeof(int),
61670+ .mode = 0600,
61671+ .proc_handler = &proc_dointvec,
61672+ },
61673+#endif
61674+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61675+ {
61676+ .procname = "tpe_restrict_all",
61677+ .data = &grsec_enable_tpe_all,
61678+ .maxlen = sizeof(int),
61679+ .mode = 0600,
61680+ .proc_handler = &proc_dointvec,
61681+ },
61682+#endif
61683+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61684+ {
61685+ .procname = "socket_all",
61686+ .data = &grsec_enable_socket_all,
61687+ .maxlen = sizeof(int),
61688+ .mode = 0600,
61689+ .proc_handler = &proc_dointvec,
61690+ },
61691+ {
61692+ .procname = "socket_all_gid",
61693+ .data = &grsec_socket_all_gid,
61694+ .maxlen = sizeof(int),
61695+ .mode = 0600,
61696+ .proc_handler = &proc_dointvec,
61697+ },
61698+#endif
61699+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61700+ {
61701+ .procname = "socket_client",
61702+ .data = &grsec_enable_socket_client,
61703+ .maxlen = sizeof(int),
61704+ .mode = 0600,
61705+ .proc_handler = &proc_dointvec,
61706+ },
61707+ {
61708+ .procname = "socket_client_gid",
61709+ .data = &grsec_socket_client_gid,
61710+ .maxlen = sizeof(int),
61711+ .mode = 0600,
61712+ .proc_handler = &proc_dointvec,
61713+ },
61714+#endif
61715+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61716+ {
61717+ .procname = "socket_server",
61718+ .data = &grsec_enable_socket_server,
61719+ .maxlen = sizeof(int),
61720+ .mode = 0600,
61721+ .proc_handler = &proc_dointvec,
61722+ },
61723+ {
61724+ .procname = "socket_server_gid",
61725+ .data = &grsec_socket_server_gid,
61726+ .maxlen = sizeof(int),
61727+ .mode = 0600,
61728+ .proc_handler = &proc_dointvec,
61729+ },
61730+#endif
61731+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61732+ {
61733+ .procname = "audit_group",
61734+ .data = &grsec_enable_group,
61735+ .maxlen = sizeof(int),
61736+ .mode = 0600,
61737+ .proc_handler = &proc_dointvec,
61738+ },
61739+ {
61740+ .procname = "audit_gid",
61741+ .data = &grsec_audit_gid,
61742+ .maxlen = sizeof(int),
61743+ .mode = 0600,
61744+ .proc_handler = &proc_dointvec,
61745+ },
61746+#endif
61747+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61748+ {
61749+ .procname = "audit_chdir",
61750+ .data = &grsec_enable_chdir,
61751+ .maxlen = sizeof(int),
61752+ .mode = 0600,
61753+ .proc_handler = &proc_dointvec,
61754+ },
61755+#endif
61756+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61757+ {
61758+ .procname = "audit_mount",
61759+ .data = &grsec_enable_mount,
61760+ .maxlen = sizeof(int),
61761+ .mode = 0600,
61762+ .proc_handler = &proc_dointvec,
61763+ },
61764+#endif
61765+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61766+ {
61767+ .procname = "audit_textrel",
61768+ .data = &grsec_enable_audit_textrel,
61769+ .maxlen = sizeof(int),
61770+ .mode = 0600,
61771+ .proc_handler = &proc_dointvec,
61772+ },
61773+#endif
61774+#ifdef CONFIG_GRKERNSEC_DMESG
61775+ {
61776+ .procname = "dmesg",
61777+ .data = &grsec_enable_dmesg,
61778+ .maxlen = sizeof(int),
61779+ .mode = 0600,
61780+ .proc_handler = &proc_dointvec,
61781+ },
61782+#endif
61783+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61784+ {
61785+ .procname = "chroot_findtask",
61786+ .data = &grsec_enable_chroot_findtask,
61787+ .maxlen = sizeof(int),
61788+ .mode = 0600,
61789+ .proc_handler = &proc_dointvec,
61790+ },
61791+#endif
61792+#ifdef CONFIG_GRKERNSEC_RESLOG
61793+ {
61794+ .procname = "resource_logging",
61795+ .data = &grsec_resource_logging,
61796+ .maxlen = sizeof(int),
61797+ .mode = 0600,
61798+ .proc_handler = &proc_dointvec,
61799+ },
61800+#endif
61801+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61802+ {
61803+ .procname = "audit_ptrace",
61804+ .data = &grsec_enable_audit_ptrace,
61805+ .maxlen = sizeof(int),
61806+ .mode = 0600,
61807+ .proc_handler = &proc_dointvec,
61808+ },
61809+#endif
61810+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61811+ {
61812+ .procname = "harden_ptrace",
61813+ .data = &grsec_enable_harden_ptrace,
61814+ .maxlen = sizeof(int),
61815+ .mode = 0600,
61816+ .proc_handler = &proc_dointvec,
61817+ },
61818+#endif
61819+ {
61820+ .procname = "grsec_lock",
61821+ .data = &grsec_lock,
61822+ .maxlen = sizeof(int),
61823+ .mode = 0600,
61824+ .proc_handler = &proc_dointvec,
61825+ },
61826+#endif
61827+#ifdef CONFIG_GRKERNSEC_ROFS
61828+ {
61829+ .procname = "romount_protect",
61830+ .data = &grsec_enable_rofs,
61831+ .maxlen = sizeof(int),
61832+ .mode = 0600,
61833+ .proc_handler = &proc_dointvec_minmax,
61834+ .extra1 = &one,
61835+ .extra2 = &one,
61836+ },
61837+#endif
61838+ { }
61839+};
61840+#endif
61841diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
61842new file mode 100644
61843index 0000000..0dc13c3
61844--- /dev/null
61845+++ b/grsecurity/grsec_time.c
61846@@ -0,0 +1,16 @@
61847+#include <linux/kernel.h>
61848+#include <linux/sched.h>
61849+#include <linux/grinternal.h>
61850+#include <linux/module.h>
61851+
61852+void
61853+gr_log_timechange(void)
61854+{
61855+#ifdef CONFIG_GRKERNSEC_TIME
61856+ if (grsec_enable_time)
61857+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
61858+#endif
61859+ return;
61860+}
61861+
61862+EXPORT_SYMBOL(gr_log_timechange);
61863diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
61864new file mode 100644
61865index 0000000..07e0dc0
61866--- /dev/null
61867+++ b/grsecurity/grsec_tpe.c
61868@@ -0,0 +1,73 @@
61869+#include <linux/kernel.h>
61870+#include <linux/sched.h>
61871+#include <linux/file.h>
61872+#include <linux/fs.h>
61873+#include <linux/grinternal.h>
61874+
61875+extern int gr_acl_tpe_check(void);
61876+
61877+int
61878+gr_tpe_allow(const struct file *file)
61879+{
61880+#ifdef CONFIG_GRKERNSEC
61881+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
61882+ const struct cred *cred = current_cred();
61883+ char *msg = NULL;
61884+ char *msg2 = NULL;
61885+
61886+ // never restrict root
61887+ if (!cred->uid)
61888+ return 1;
61889+
61890+ if (grsec_enable_tpe) {
61891+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61892+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
61893+ msg = "not being in trusted group";
61894+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
61895+ msg = "being in untrusted group";
61896+#else
61897+ if (in_group_p(grsec_tpe_gid))
61898+ msg = "being in untrusted group";
61899+#endif
61900+ }
61901+ if (!msg && gr_acl_tpe_check())
61902+ msg = "being in untrusted role";
61903+
61904+ // not in any affected group/role
61905+ if (!msg)
61906+ goto next_check;
61907+
61908+ if (inode->i_uid)
61909+ msg2 = "file in non-root-owned directory";
61910+ else if (inode->i_mode & S_IWOTH)
61911+ msg2 = "file in world-writable directory";
61912+ else if (inode->i_mode & S_IWGRP)
61913+ msg2 = "file in group-writable directory";
61914+
61915+ if (msg && msg2) {
61916+ char fullmsg[70] = {0};
61917+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
61918+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
61919+ return 0;
61920+ }
61921+ msg = NULL;
61922+next_check:
61923+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61924+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
61925+ return 1;
61926+
61927+ if (inode->i_uid && (inode->i_uid != cred->uid))
61928+ msg = "directory not owned by user";
61929+ else if (inode->i_mode & S_IWOTH)
61930+ msg = "file in world-writable directory";
61931+ else if (inode->i_mode & S_IWGRP)
61932+ msg = "file in group-writable directory";
61933+
61934+ if (msg) {
61935+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
61936+ return 0;
61937+ }
61938+#endif
61939+#endif
61940+ return 1;
61941+}
61942diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
61943new file mode 100644
61944index 0000000..9f7b1ac
61945--- /dev/null
61946+++ b/grsecurity/grsum.c
61947@@ -0,0 +1,61 @@
61948+#include <linux/err.h>
61949+#include <linux/kernel.h>
61950+#include <linux/sched.h>
61951+#include <linux/mm.h>
61952+#include <linux/scatterlist.h>
61953+#include <linux/crypto.h>
61954+#include <linux/gracl.h>
61955+
61956+
61957+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
61958+#error "crypto and sha256 must be built into the kernel"
61959+#endif
61960+
61961+int
61962+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
61963+{
61964+ char *p;
61965+ struct crypto_hash *tfm;
61966+ struct hash_desc desc;
61967+ struct scatterlist sg;
61968+ unsigned char temp_sum[GR_SHA_LEN];
61969+ volatile int retval = 0;
61970+ volatile int dummy = 0;
61971+ unsigned int i;
61972+
61973+ sg_init_table(&sg, 1);
61974+
61975+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
61976+ if (IS_ERR(tfm)) {
61977+ /* should never happen, since sha256 should be built in */
61978+ return 1;
61979+ }
61980+
61981+ desc.tfm = tfm;
61982+ desc.flags = 0;
61983+
61984+ crypto_hash_init(&desc);
61985+
61986+ p = salt;
61987+ sg_set_buf(&sg, p, GR_SALT_LEN);
61988+ crypto_hash_update(&desc, &sg, sg.length);
61989+
61990+ p = entry->pw;
61991+ sg_set_buf(&sg, p, strlen(p));
61992+
61993+ crypto_hash_update(&desc, &sg, sg.length);
61994+
61995+ crypto_hash_final(&desc, temp_sum);
61996+
61997+ memset(entry->pw, 0, GR_PW_LEN);
61998+
61999+ for (i = 0; i < GR_SHA_LEN; i++)
62000+ if (sum[i] != temp_sum[i])
62001+ retval = 1;
62002+ else
62003+ dummy = 1; // waste a cycle
62004+
62005+ crypto_free_hash(tfm);
62006+
62007+ return retval;
62008+}
62009diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62010index 77ff547..181834f 100644
62011--- a/include/asm-generic/4level-fixup.h
62012+++ b/include/asm-generic/4level-fixup.h
62013@@ -13,8 +13,10 @@
62014 #define pmd_alloc(mm, pud, address) \
62015 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62016 NULL: pmd_offset(pud, address))
62017+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62018
62019 #define pud_alloc(mm, pgd, address) (pgd)
62020+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62021 #define pud_offset(pgd, start) (pgd)
62022 #define pud_none(pud) 0
62023 #define pud_bad(pud) 0
62024diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62025index b7babf0..04ad282 100644
62026--- a/include/asm-generic/atomic-long.h
62027+++ b/include/asm-generic/atomic-long.h
62028@@ -22,6 +22,12 @@
62029
62030 typedef atomic64_t atomic_long_t;
62031
62032+#ifdef CONFIG_PAX_REFCOUNT
62033+typedef atomic64_unchecked_t atomic_long_unchecked_t;
62034+#else
62035+typedef atomic64_t atomic_long_unchecked_t;
62036+#endif
62037+
62038 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62039
62040 static inline long atomic_long_read(atomic_long_t *l)
62041@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62042 return (long)atomic64_read(v);
62043 }
62044
62045+#ifdef CONFIG_PAX_REFCOUNT
62046+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62047+{
62048+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62049+
62050+ return (long)atomic64_read_unchecked(v);
62051+}
62052+#endif
62053+
62054 static inline void atomic_long_set(atomic_long_t *l, long i)
62055 {
62056 atomic64_t *v = (atomic64_t *)l;
62057@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62058 atomic64_set(v, i);
62059 }
62060
62061+#ifdef CONFIG_PAX_REFCOUNT
62062+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62063+{
62064+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62065+
62066+ atomic64_set_unchecked(v, i);
62067+}
62068+#endif
62069+
62070 static inline void atomic_long_inc(atomic_long_t *l)
62071 {
62072 atomic64_t *v = (atomic64_t *)l;
62073@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62074 atomic64_inc(v);
62075 }
62076
62077+#ifdef CONFIG_PAX_REFCOUNT
62078+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62079+{
62080+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62081+
62082+ atomic64_inc_unchecked(v);
62083+}
62084+#endif
62085+
62086 static inline void atomic_long_dec(atomic_long_t *l)
62087 {
62088 atomic64_t *v = (atomic64_t *)l;
62089@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62090 atomic64_dec(v);
62091 }
62092
62093+#ifdef CONFIG_PAX_REFCOUNT
62094+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62095+{
62096+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62097+
62098+ atomic64_dec_unchecked(v);
62099+}
62100+#endif
62101+
62102 static inline void atomic_long_add(long i, atomic_long_t *l)
62103 {
62104 atomic64_t *v = (atomic64_t *)l;
62105@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62106 atomic64_add(i, v);
62107 }
62108
62109+#ifdef CONFIG_PAX_REFCOUNT
62110+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62111+{
62112+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62113+
62114+ atomic64_add_unchecked(i, v);
62115+}
62116+#endif
62117+
62118 static inline void atomic_long_sub(long i, atomic_long_t *l)
62119 {
62120 atomic64_t *v = (atomic64_t *)l;
62121@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62122 atomic64_sub(i, v);
62123 }
62124
62125+#ifdef CONFIG_PAX_REFCOUNT
62126+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62127+{
62128+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62129+
62130+ atomic64_sub_unchecked(i, v);
62131+}
62132+#endif
62133+
62134 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62135 {
62136 atomic64_t *v = (atomic64_t *)l;
62137@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62138 return (long)atomic64_add_return(i, v);
62139 }
62140
62141+#ifdef CONFIG_PAX_REFCOUNT
62142+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62143+{
62144+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62145+
62146+ return (long)atomic64_add_return_unchecked(i, v);
62147+}
62148+#endif
62149+
62150 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62151 {
62152 atomic64_t *v = (atomic64_t *)l;
62153@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62154 return (long)atomic64_inc_return(v);
62155 }
62156
62157+#ifdef CONFIG_PAX_REFCOUNT
62158+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62159+{
62160+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62161+
62162+ return (long)atomic64_inc_return_unchecked(v);
62163+}
62164+#endif
62165+
62166 static inline long atomic_long_dec_return(atomic_long_t *l)
62167 {
62168 atomic64_t *v = (atomic64_t *)l;
62169@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62170
62171 typedef atomic_t atomic_long_t;
62172
62173+#ifdef CONFIG_PAX_REFCOUNT
62174+typedef atomic_unchecked_t atomic_long_unchecked_t;
62175+#else
62176+typedef atomic_t atomic_long_unchecked_t;
62177+#endif
62178+
62179 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62180 static inline long atomic_long_read(atomic_long_t *l)
62181 {
62182@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62183 return (long)atomic_read(v);
62184 }
62185
62186+#ifdef CONFIG_PAX_REFCOUNT
62187+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62188+{
62189+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62190+
62191+ return (long)atomic_read_unchecked(v);
62192+}
62193+#endif
62194+
62195 static inline void atomic_long_set(atomic_long_t *l, long i)
62196 {
62197 atomic_t *v = (atomic_t *)l;
62198@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62199 atomic_set(v, i);
62200 }
62201
62202+#ifdef CONFIG_PAX_REFCOUNT
62203+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62204+{
62205+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62206+
62207+ atomic_set_unchecked(v, i);
62208+}
62209+#endif
62210+
62211 static inline void atomic_long_inc(atomic_long_t *l)
62212 {
62213 atomic_t *v = (atomic_t *)l;
62214@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62215 atomic_inc(v);
62216 }
62217
62218+#ifdef CONFIG_PAX_REFCOUNT
62219+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62220+{
62221+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62222+
62223+ atomic_inc_unchecked(v);
62224+}
62225+#endif
62226+
62227 static inline void atomic_long_dec(atomic_long_t *l)
62228 {
62229 atomic_t *v = (atomic_t *)l;
62230@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62231 atomic_dec(v);
62232 }
62233
62234+#ifdef CONFIG_PAX_REFCOUNT
62235+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62236+{
62237+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62238+
62239+ atomic_dec_unchecked(v);
62240+}
62241+#endif
62242+
62243 static inline void atomic_long_add(long i, atomic_long_t *l)
62244 {
62245 atomic_t *v = (atomic_t *)l;
62246@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62247 atomic_add(i, v);
62248 }
62249
62250+#ifdef CONFIG_PAX_REFCOUNT
62251+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62252+{
62253+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62254+
62255+ atomic_add_unchecked(i, v);
62256+}
62257+#endif
62258+
62259 static inline void atomic_long_sub(long i, atomic_long_t *l)
62260 {
62261 atomic_t *v = (atomic_t *)l;
62262@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62263 atomic_sub(i, v);
62264 }
62265
62266+#ifdef CONFIG_PAX_REFCOUNT
62267+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62268+{
62269+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62270+
62271+ atomic_sub_unchecked(i, v);
62272+}
62273+#endif
62274+
62275 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62276 {
62277 atomic_t *v = (atomic_t *)l;
62278@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62279 return (long)atomic_add_return(i, v);
62280 }
62281
62282+#ifdef CONFIG_PAX_REFCOUNT
62283+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62284+{
62285+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62286+
62287+ return (long)atomic_add_return_unchecked(i, v);
62288+}
62289+
62290+#endif
62291+
62292 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62293 {
62294 atomic_t *v = (atomic_t *)l;
62295@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62296 return (long)atomic_inc_return(v);
62297 }
62298
62299+#ifdef CONFIG_PAX_REFCOUNT
62300+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62301+{
62302+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62303+
62304+ return (long)atomic_inc_return_unchecked(v);
62305+}
62306+#endif
62307+
62308 static inline long atomic_long_dec_return(atomic_long_t *l)
62309 {
62310 atomic_t *v = (atomic_t *)l;
62311@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62312
62313 #endif /* BITS_PER_LONG == 64 */
62314
62315+#ifdef CONFIG_PAX_REFCOUNT
62316+static inline void pax_refcount_needs_these_functions(void)
62317+{
62318+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
62319+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62320+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62321+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62322+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62323+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62324+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62325+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62326+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62327+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62328+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62329+#ifdef CONFIG_X86
62330+ atomic_clear_mask_unchecked(0, NULL);
62331+ atomic_set_mask_unchecked(0, NULL);
62332+#endif
62333+
62334+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62335+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62336+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62337+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62338+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62339+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62340+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62341+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62342+}
62343+#else
62344+#define atomic_read_unchecked(v) atomic_read(v)
62345+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62346+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62347+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62348+#define atomic_inc_unchecked(v) atomic_inc(v)
62349+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62350+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62351+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62352+#define atomic_dec_unchecked(v) atomic_dec(v)
62353+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62354+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62355+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62356+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62357+
62358+#define atomic_long_read_unchecked(v) atomic_long_read(v)
62359+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62360+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62361+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62362+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62363+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62364+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62365+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62366+#endif
62367+
62368 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62369diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62370index 1ced641..c896ee8 100644
62371--- a/include/asm-generic/atomic.h
62372+++ b/include/asm-generic/atomic.h
62373@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62374 * Atomically clears the bits set in @mask from @v
62375 */
62376 #ifndef atomic_clear_mask
62377-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62378+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62379 {
62380 unsigned long flags;
62381
62382diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62383index b18ce4f..2ee2843 100644
62384--- a/include/asm-generic/atomic64.h
62385+++ b/include/asm-generic/atomic64.h
62386@@ -16,6 +16,8 @@ typedef struct {
62387 long long counter;
62388 } atomic64_t;
62389
62390+typedef atomic64_t atomic64_unchecked_t;
62391+
62392 #define ATOMIC64_INIT(i) { (i) }
62393
62394 extern long long atomic64_read(const atomic64_t *v);
62395@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62396 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62397 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62398
62399+#define atomic64_read_unchecked(v) atomic64_read(v)
62400+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62401+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62402+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62403+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62404+#define atomic64_inc_unchecked(v) atomic64_inc(v)
62405+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62406+#define atomic64_dec_unchecked(v) atomic64_dec(v)
62407+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62408+
62409 #endif /* _ASM_GENERIC_ATOMIC64_H */
62410diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62411index 1bfcfe5..e04c5c9 100644
62412--- a/include/asm-generic/cache.h
62413+++ b/include/asm-generic/cache.h
62414@@ -6,7 +6,7 @@
62415 * cache lines need to provide their own cache.h.
62416 */
62417
62418-#define L1_CACHE_SHIFT 5
62419-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62420+#define L1_CACHE_SHIFT 5UL
62421+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62422
62423 #endif /* __ASM_GENERIC_CACHE_H */
62424diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62425index 0d68a1e..b74a761 100644
62426--- a/include/asm-generic/emergency-restart.h
62427+++ b/include/asm-generic/emergency-restart.h
62428@@ -1,7 +1,7 @@
62429 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62430 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62431
62432-static inline void machine_emergency_restart(void)
62433+static inline __noreturn void machine_emergency_restart(void)
62434 {
62435 machine_restart(NULL);
62436 }
62437diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62438index 90f99c7..00ce236 100644
62439--- a/include/asm-generic/kmap_types.h
62440+++ b/include/asm-generic/kmap_types.h
62441@@ -2,9 +2,9 @@
62442 #define _ASM_GENERIC_KMAP_TYPES_H
62443
62444 #ifdef __WITH_KM_FENCE
62445-# define KM_TYPE_NR 41
62446+# define KM_TYPE_NR 42
62447 #else
62448-# define KM_TYPE_NR 20
62449+# define KM_TYPE_NR 21
62450 #endif
62451
62452 #endif
62453diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62454index 9ceb03b..62b0b8f 100644
62455--- a/include/asm-generic/local.h
62456+++ b/include/asm-generic/local.h
62457@@ -23,24 +23,37 @@ typedef struct
62458 atomic_long_t a;
62459 } local_t;
62460
62461+typedef struct {
62462+ atomic_long_unchecked_t a;
62463+} local_unchecked_t;
62464+
62465 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62466
62467 #define local_read(l) atomic_long_read(&(l)->a)
62468+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62469 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62470+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62471 #define local_inc(l) atomic_long_inc(&(l)->a)
62472+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62473 #define local_dec(l) atomic_long_dec(&(l)->a)
62474+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62475 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62476+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62477 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62478+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62479
62480 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62481 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62482 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62483 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62484 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62485+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62486 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62487 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62488+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62489
62490 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62491+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62492 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62493 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62494 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62495diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62496index 725612b..9cc513a 100644
62497--- a/include/asm-generic/pgtable-nopmd.h
62498+++ b/include/asm-generic/pgtable-nopmd.h
62499@@ -1,14 +1,19 @@
62500 #ifndef _PGTABLE_NOPMD_H
62501 #define _PGTABLE_NOPMD_H
62502
62503-#ifndef __ASSEMBLY__
62504-
62505 #include <asm-generic/pgtable-nopud.h>
62506
62507-struct mm_struct;
62508-
62509 #define __PAGETABLE_PMD_FOLDED
62510
62511+#define PMD_SHIFT PUD_SHIFT
62512+#define PTRS_PER_PMD 1
62513+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62514+#define PMD_MASK (~(PMD_SIZE-1))
62515+
62516+#ifndef __ASSEMBLY__
62517+
62518+struct mm_struct;
62519+
62520 /*
62521 * Having the pmd type consist of a pud gets the size right, and allows
62522 * us to conceptually access the pud entry that this pmd is folded into
62523@@ -16,11 +21,6 @@ struct mm_struct;
62524 */
62525 typedef struct { pud_t pud; } pmd_t;
62526
62527-#define PMD_SHIFT PUD_SHIFT
62528-#define PTRS_PER_PMD 1
62529-#define PMD_SIZE (1UL << PMD_SHIFT)
62530-#define PMD_MASK (~(PMD_SIZE-1))
62531-
62532 /*
62533 * The "pud_xxx()" functions here are trivial for a folded two-level
62534 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62535diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62536index 810431d..0ec4804f 100644
62537--- a/include/asm-generic/pgtable-nopud.h
62538+++ b/include/asm-generic/pgtable-nopud.h
62539@@ -1,10 +1,15 @@
62540 #ifndef _PGTABLE_NOPUD_H
62541 #define _PGTABLE_NOPUD_H
62542
62543-#ifndef __ASSEMBLY__
62544-
62545 #define __PAGETABLE_PUD_FOLDED
62546
62547+#define PUD_SHIFT PGDIR_SHIFT
62548+#define PTRS_PER_PUD 1
62549+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62550+#define PUD_MASK (~(PUD_SIZE-1))
62551+
62552+#ifndef __ASSEMBLY__
62553+
62554 /*
62555 * Having the pud type consist of a pgd gets the size right, and allows
62556 * us to conceptually access the pgd entry that this pud is folded into
62557@@ -12,11 +17,6 @@
62558 */
62559 typedef struct { pgd_t pgd; } pud_t;
62560
62561-#define PUD_SHIFT PGDIR_SHIFT
62562-#define PTRS_PER_PUD 1
62563-#define PUD_SIZE (1UL << PUD_SHIFT)
62564-#define PUD_MASK (~(PUD_SIZE-1))
62565-
62566 /*
62567 * The "pgd_xxx()" functions here are trivial for a folded two-level
62568 * setup: the pud is never bad, and a pud always exists (as it's folded
62569@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62570 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62571
62572 #define pgd_populate(mm, pgd, pud) do { } while (0)
62573+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62574 /*
62575 * (puds are folded into pgds so this doesn't get actually called,
62576 * but the define is needed for a generic inline function.)
62577diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62578index b36ce40..019426d 100644
62579--- a/include/asm-generic/pgtable.h
62580+++ b/include/asm-generic/pgtable.h
62581@@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62582 #endif
62583 }
62584
62585+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62586+static inline unsigned long pax_open_kernel(void) { return 0; }
62587+#endif
62588+
62589+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62590+static inline unsigned long pax_close_kernel(void) { return 0; }
62591+#endif
62592+
62593 #endif /* CONFIG_MMU */
62594
62595 #endif /* !__ASSEMBLY__ */
62596diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62597index d1ea7ce..b1ebf2a 100644
62598--- a/include/asm-generic/vmlinux.lds.h
62599+++ b/include/asm-generic/vmlinux.lds.h
62600@@ -218,6 +218,7 @@
62601 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62602 VMLINUX_SYMBOL(__start_rodata) = .; \
62603 *(.rodata) *(.rodata.*) \
62604+ *(.data..read_only) \
62605 *(__vermagic) /* Kernel version magic */ \
62606 . = ALIGN(8); \
62607 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62608@@ -725,17 +726,18 @@
62609 * section in the linker script will go there too. @phdr should have
62610 * a leading colon.
62611 *
62612- * Note that this macros defines __per_cpu_load as an absolute symbol.
62613+ * Note that this macros defines per_cpu_load as an absolute symbol.
62614 * If there is no need to put the percpu section at a predetermined
62615 * address, use PERCPU_SECTION.
62616 */
62617 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62618- VMLINUX_SYMBOL(__per_cpu_load) = .; \
62619- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62620+ per_cpu_load = .; \
62621+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62622 - LOAD_OFFSET) { \
62623+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62624 PERCPU_INPUT(cacheline) \
62625 } phdr \
62626- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62627+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62628
62629 /**
62630 * PERCPU_SECTION - define output section for percpu area, simple version
62631diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62632index 418d270..bfd2794 100644
62633--- a/include/crypto/algapi.h
62634+++ b/include/crypto/algapi.h
62635@@ -34,7 +34,7 @@ struct crypto_type {
62636 unsigned int maskclear;
62637 unsigned int maskset;
62638 unsigned int tfmsize;
62639-};
62640+} __do_const;
62641
62642 struct crypto_instance {
62643 struct crypto_alg alg;
62644diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62645index 3fd8280..2b3c415 100644
62646--- a/include/drm/drmP.h
62647+++ b/include/drm/drmP.h
62648@@ -72,6 +72,7 @@
62649 #include <linux/workqueue.h>
62650 #include <linux/poll.h>
62651 #include <asm/pgalloc.h>
62652+#include <asm/local.h>
62653 #include <drm/drm.h>
62654 #include <drm/drm_sarea.h>
62655
62656@@ -1068,7 +1069,7 @@ struct drm_device {
62657
62658 /** \name Usage Counters */
62659 /*@{ */
62660- int open_count; /**< Outstanding files open */
62661+ local_t open_count; /**< Outstanding files open */
62662 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62663 atomic_t vma_count; /**< Outstanding vma areas open */
62664 int buf_use; /**< Buffers in use -- cannot alloc */
62665@@ -1079,7 +1080,7 @@ struct drm_device {
62666 /*@{ */
62667 unsigned long counters;
62668 enum drm_stat_type types[15];
62669- atomic_t counts[15];
62670+ atomic_unchecked_t counts[15];
62671 /*@} */
62672
62673 struct list_head filelist;
62674diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62675index e01cc80..6fb6f25 100644
62676--- a/include/drm/drm_crtc_helper.h
62677+++ b/include/drm/drm_crtc_helper.h
62678@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62679 struct drm_connector *connector);
62680 /* disable encoder when not in use - more explicit than dpms off */
62681 void (*disable)(struct drm_encoder *encoder);
62682-};
62683+} __no_const;
62684
62685 /**
62686 * drm_connector_helper_funcs - helper operations for connectors
62687diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62688index d6d1da4..fdd1ac5 100644
62689--- a/include/drm/ttm/ttm_memory.h
62690+++ b/include/drm/ttm/ttm_memory.h
62691@@ -48,7 +48,7 @@
62692
62693 struct ttm_mem_shrink {
62694 int (*do_shrink) (struct ttm_mem_shrink *);
62695-};
62696+} __no_const;
62697
62698 /**
62699 * struct ttm_mem_global - Global memory accounting structure.
62700diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62701index 22ef21c..75904ba 100644
62702--- a/include/linux/atmdev.h
62703+++ b/include/linux/atmdev.h
62704@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62705 #endif
62706
62707 struct k_atm_aal_stats {
62708-#define __HANDLE_ITEM(i) atomic_t i
62709+#define __HANDLE_ITEM(i) atomic_unchecked_t i
62710 __AAL_STAT_ITEMS
62711 #undef __HANDLE_ITEM
62712 };
62713diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62714index de0628e..38f42eb 100644
62715--- a/include/linux/binfmts.h
62716+++ b/include/linux/binfmts.h
62717@@ -75,6 +75,7 @@ struct linux_binfmt {
62718 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62719 int (*load_shlib)(struct file *);
62720 int (*core_dump)(struct coredump_params *cprm);
62721+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62722 unsigned long min_coredump; /* minimal dump size */
62723 };
62724
62725diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62726index 1756001..ab117ec 100644
62727--- a/include/linux/blkdev.h
62728+++ b/include/linux/blkdev.h
62729@@ -1478,7 +1478,7 @@ struct block_device_operations {
62730 /* this callback is with swap_lock and sometimes page table lock held */
62731 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62732 struct module *owner;
62733-};
62734+} __do_const;
62735
62736 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62737 unsigned long);
62738diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62739index 7c2e030..b72475d 100644
62740--- a/include/linux/blktrace_api.h
62741+++ b/include/linux/blktrace_api.h
62742@@ -23,7 +23,7 @@ struct blk_trace {
62743 struct dentry *dir;
62744 struct dentry *dropped_file;
62745 struct dentry *msg_file;
62746- atomic_t dropped;
62747+ atomic_unchecked_t dropped;
62748 };
62749
62750 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62751diff --git a/include/linux/cache.h b/include/linux/cache.h
62752index 4c57065..4307975 100644
62753--- a/include/linux/cache.h
62754+++ b/include/linux/cache.h
62755@@ -16,6 +16,10 @@
62756 #define __read_mostly
62757 #endif
62758
62759+#ifndef __read_only
62760+#define __read_only __read_mostly
62761+#endif
62762+
62763 #ifndef ____cacheline_aligned
62764 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62765 #endif
62766diff --git a/include/linux/capability.h b/include/linux/capability.h
62767index 98503b7..cc36d18 100644
62768--- a/include/linux/capability.h
62769+++ b/include/linux/capability.h
62770@@ -211,8 +211,13 @@ extern bool capable(int cap);
62771 extern bool ns_capable(struct user_namespace *ns, int cap);
62772 extern bool nsown_capable(int cap);
62773 extern bool inode_capable(const struct inode *inode, int cap);
62774+extern bool capable_nolog(int cap);
62775+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62776+extern bool inode_capable_nolog(const struct inode *inode, int cap);
62777
62778 /* audit system wants to get cap info from files as well */
62779 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62780
62781+extern int is_privileged_binary(const struct dentry *dentry);
62782+
62783 #endif /* !_LINUX_CAPABILITY_H */
62784diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62785index 8609d57..86e4d79 100644
62786--- a/include/linux/cdrom.h
62787+++ b/include/linux/cdrom.h
62788@@ -87,7 +87,6 @@ struct cdrom_device_ops {
62789
62790 /* driver specifications */
62791 const int capability; /* capability flags */
62792- int n_minors; /* number of active minor devices */
62793 /* handle uniform packets for scsi type devices (scsi,atapi) */
62794 int (*generic_packet) (struct cdrom_device_info *,
62795 struct packet_command *);
62796diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
62797index 42e55de..1cd0e66 100644
62798--- a/include/linux/cleancache.h
62799+++ b/include/linux/cleancache.h
62800@@ -31,7 +31,7 @@ struct cleancache_ops {
62801 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
62802 void (*invalidate_inode)(int, struct cleancache_filekey);
62803 void (*invalidate_fs)(int);
62804-};
62805+} __no_const;
62806
62807 extern struct cleancache_ops
62808 cleancache_register_ops(struct cleancache_ops *ops);
62809diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
62810index 412bc6c..c31666e 100644
62811--- a/include/linux/compiler-gcc4.h
62812+++ b/include/linux/compiler-gcc4.h
62813@@ -32,6 +32,21 @@
62814 #define __linktime_error(message) __attribute__((__error__(message)))
62815
62816 #if __GNUC_MINOR__ >= 5
62817+
62818+#ifdef CONSTIFY_PLUGIN
62819+#define __no_const __attribute__((no_const))
62820+#define __do_const __attribute__((do_const))
62821+#endif
62822+
62823+#ifdef SIZE_OVERFLOW_PLUGIN
62824+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
62825+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
62826+#endif
62827+
62828+#ifdef LATENT_ENTROPY_PLUGIN
62829+#define __latent_entropy __attribute__((latent_entropy))
62830+#endif
62831+
62832 /*
62833 * Mark a position in code as unreachable. This can be used to
62834 * suppress control flow warnings after asm blocks that transfer
62835@@ -47,6 +62,11 @@
62836 #define __noclone __attribute__((__noclone__))
62837
62838 #endif
62839+
62840+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
62841+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
62842+#define __bos0(ptr) __bos((ptr), 0)
62843+#define __bos1(ptr) __bos((ptr), 1)
62844 #endif
62845
62846 #if __GNUC_MINOR__ >= 6
62847diff --git a/include/linux/compiler.h b/include/linux/compiler.h
62848index f430e41..38be90f 100644
62849--- a/include/linux/compiler.h
62850+++ b/include/linux/compiler.h
62851@@ -5,31 +5,62 @@
62852
62853 #ifdef __CHECKER__
62854 # define __user __attribute__((noderef, address_space(1)))
62855+# define __force_user __force __user
62856 # define __kernel __attribute__((address_space(0)))
62857+# define __force_kernel __force __kernel
62858 # define __safe __attribute__((safe))
62859 # define __force __attribute__((force))
62860 # define __nocast __attribute__((nocast))
62861 # define __iomem __attribute__((noderef, address_space(2)))
62862+# define __force_iomem __force __iomem
62863 # define __acquires(x) __attribute__((context(x,0,1)))
62864 # define __releases(x) __attribute__((context(x,1,0)))
62865 # define __acquire(x) __context__(x,1)
62866 # define __release(x) __context__(x,-1)
62867 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
62868 # define __percpu __attribute__((noderef, address_space(3)))
62869+# define __force_percpu __force __percpu
62870 #ifdef CONFIG_SPARSE_RCU_POINTER
62871 # define __rcu __attribute__((noderef, address_space(4)))
62872+# define __force_rcu __force __rcu
62873 #else
62874 # define __rcu
62875+# define __force_rcu
62876 #endif
62877 extern void __chk_user_ptr(const volatile void __user *);
62878 extern void __chk_io_ptr(const volatile void __iomem *);
62879+#elif defined(CHECKER_PLUGIN)
62880+//# define __user
62881+//# define __force_user
62882+//# define __kernel
62883+//# define __force_kernel
62884+# define __safe
62885+# define __force
62886+# define __nocast
62887+# define __iomem
62888+# define __force_iomem
62889+# define __chk_user_ptr(x) (void)0
62890+# define __chk_io_ptr(x) (void)0
62891+# define __builtin_warning(x, y...) (1)
62892+# define __acquires(x)
62893+# define __releases(x)
62894+# define __acquire(x) (void)0
62895+# define __release(x) (void)0
62896+# define __cond_lock(x,c) (c)
62897+# define __percpu
62898+# define __force_percpu
62899+# define __rcu
62900+# define __force_rcu
62901 #else
62902 # define __user
62903+# define __force_user
62904 # define __kernel
62905+# define __force_kernel
62906 # define __safe
62907 # define __force
62908 # define __nocast
62909 # define __iomem
62910+# define __force_iomem
62911 # define __chk_user_ptr(x) (void)0
62912 # define __chk_io_ptr(x) (void)0
62913 # define __builtin_warning(x, y...) (1)
62914@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
62915 # define __release(x) (void)0
62916 # define __cond_lock(x,c) (c)
62917 # define __percpu
62918+# define __force_percpu
62919 # define __rcu
62920+# define __force_rcu
62921 #endif
62922
62923 #ifdef __KERNEL__
62924@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62925 # define __attribute_const__ /* unimplemented */
62926 #endif
62927
62928+#ifndef __no_const
62929+# define __no_const
62930+#endif
62931+
62932+#ifndef __do_const
62933+# define __do_const
62934+#endif
62935+
62936+#ifndef __size_overflow
62937+# define __size_overflow(...)
62938+#endif
62939+
62940+#ifndef __intentional_overflow
62941+# define __intentional_overflow(...)
62942+#endif
62943+
62944+#ifndef __latent_entropy
62945+# define __latent_entropy
62946+#endif
62947+
62948 /*
62949 * Tell gcc if a function is cold. The compiler will assume any path
62950 * directly leading to the call is unlikely.
62951@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62952 #define __cold
62953 #endif
62954
62955+#ifndef __alloc_size
62956+#define __alloc_size(...)
62957+#endif
62958+
62959+#ifndef __bos
62960+#define __bos(ptr, arg)
62961+#endif
62962+
62963+#ifndef __bos0
62964+#define __bos0(ptr)
62965+#endif
62966+
62967+#ifndef __bos1
62968+#define __bos1(ptr)
62969+#endif
62970+
62971 /* Simple shorthand for a section definition */
62972 #ifndef __section
62973 # define __section(S) __attribute__ ((__section__(#S)))
62974@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
62975 * use is to mediate communication between process-level code and irq/NMI
62976 * handlers, all running on the same CPU.
62977 */
62978-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
62979+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
62980+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
62981
62982 #endif /* __LINUX_COMPILER_H */
62983diff --git a/include/linux/cred.h b/include/linux/cred.h
62984index ebbed2c..908cc2c 100644
62985--- a/include/linux/cred.h
62986+++ b/include/linux/cred.h
62987@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
62988 static inline void validate_process_creds(void)
62989 {
62990 }
62991+static inline void validate_task_creds(struct task_struct *task)
62992+{
62993+}
62994 #endif
62995
62996 /**
62997diff --git a/include/linux/crypto.h b/include/linux/crypto.h
62998index b92eadf..b4ecdc1 100644
62999--- a/include/linux/crypto.h
63000+++ b/include/linux/crypto.h
63001@@ -373,7 +373,7 @@ struct cipher_tfm {
63002 const u8 *key, unsigned int keylen);
63003 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63004 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63005-};
63006+} __no_const;
63007
63008 struct hash_tfm {
63009 int (*init)(struct hash_desc *desc);
63010@@ -394,13 +394,13 @@ struct compress_tfm {
63011 int (*cot_decompress)(struct crypto_tfm *tfm,
63012 const u8 *src, unsigned int slen,
63013 u8 *dst, unsigned int *dlen);
63014-};
63015+} __no_const;
63016
63017 struct rng_tfm {
63018 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63019 unsigned int dlen);
63020 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63021-};
63022+} __no_const;
63023
63024 #define crt_ablkcipher crt_u.ablkcipher
63025 #define crt_aead crt_u.aead
63026diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63027index 7925bf0..d5143d2 100644
63028--- a/include/linux/decompress/mm.h
63029+++ b/include/linux/decompress/mm.h
63030@@ -77,7 +77,7 @@ static void free(void *where)
63031 * warnings when not needed (indeed large_malloc / large_free are not
63032 * needed by inflate */
63033
63034-#define malloc(a) kmalloc(a, GFP_KERNEL)
63035+#define malloc(a) kmalloc((a), GFP_KERNEL)
63036 #define free(a) kfree(a)
63037
63038 #define large_malloc(a) vmalloc(a)
63039diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63040index 94af418..b1ca7a2 100644
63041--- a/include/linux/dma-mapping.h
63042+++ b/include/linux/dma-mapping.h
63043@@ -54,7 +54,7 @@ struct dma_map_ops {
63044 u64 (*get_required_mask)(struct device *dev);
63045 #endif
63046 int is_phys;
63047-};
63048+} __do_const;
63049
63050 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63051
63052diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63053index d3201e4..8281e63 100644
63054--- a/include/linux/dmaengine.h
63055+++ b/include/linux/dmaengine.h
63056@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63057 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63058 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63059
63060-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63061+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63062 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63063-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63064+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63065 struct dma_pinned_list *pinned_list, struct page *page,
63066 unsigned int offset, size_t len);
63067
63068diff --git a/include/linux/efi.h b/include/linux/efi.h
63069index b424f64..fd36c1b 100644
63070--- a/include/linux/efi.h
63071+++ b/include/linux/efi.h
63072@@ -656,6 +656,7 @@ struct efivar_operations {
63073 efi_get_next_variable_t *get_next_variable;
63074 efi_set_variable_t *set_variable;
63075 };
63076+typedef struct efivar_operations __no_const efivar_operations_no_const;
63077
63078 struct efivars {
63079 /*
63080diff --git a/include/linux/elf.h b/include/linux/elf.h
63081index 8c9048e..16a4665 100644
63082--- a/include/linux/elf.h
63083+++ b/include/linux/elf.h
63084@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63085 #define elf_note elf32_note
63086 #define elf_addr_t Elf32_Off
63087 #define Elf_Half Elf32_Half
63088+#define elf_dyn Elf32_Dyn
63089
63090 #else
63091
63092@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63093 #define elf_note elf64_note
63094 #define elf_addr_t Elf64_Off
63095 #define Elf_Half Elf64_Half
63096+#define elf_dyn Elf64_Dyn
63097
63098 #endif
63099
63100diff --git a/include/linux/filter.h b/include/linux/filter.h
63101index 24d251f..7afb83d 100644
63102--- a/include/linux/filter.h
63103+++ b/include/linux/filter.h
63104@@ -20,6 +20,7 @@ struct compat_sock_fprog {
63105
63106 struct sk_buff;
63107 struct sock;
63108+struct bpf_jit_work;
63109
63110 struct sk_filter
63111 {
63112@@ -27,6 +28,9 @@ struct sk_filter
63113 unsigned int len; /* Number of filter blocks */
63114 unsigned int (*bpf_func)(const struct sk_buff *skb,
63115 const struct sock_filter *filter);
63116+#ifdef CONFIG_BPF_JIT
63117+ struct bpf_jit_work *work;
63118+#endif
63119 struct rcu_head rcu;
63120 struct sock_filter insns[0];
63121 };
63122diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63123index 3044254..9767f41 100644
63124--- a/include/linux/frontswap.h
63125+++ b/include/linux/frontswap.h
63126@@ -11,7 +11,7 @@ struct frontswap_ops {
63127 int (*load)(unsigned, pgoff_t, struct page *);
63128 void (*invalidate_page)(unsigned, pgoff_t);
63129 void (*invalidate_area)(unsigned);
63130-};
63131+} __no_const;
63132
63133 extern bool frontswap_enabled;
63134 extern struct frontswap_ops
63135diff --git a/include/linux/fs.h b/include/linux/fs.h
63136index 75fe9a1..8417cac 100644
63137--- a/include/linux/fs.h
63138+++ b/include/linux/fs.h
63139@@ -1543,7 +1543,8 @@ struct file_operations {
63140 int (*setlease)(struct file *, long, struct file_lock **);
63141 long (*fallocate)(struct file *file, int mode, loff_t offset,
63142 loff_t len);
63143-};
63144+} __do_const;
63145+typedef struct file_operations __no_const file_operations_no_const;
63146
63147 struct inode_operations {
63148 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63149@@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63150 inode->i_flags |= S_NOSEC;
63151 }
63152
63153+static inline bool is_sidechannel_device(const struct inode *inode)
63154+{
63155+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63156+ umode_t mode = inode->i_mode;
63157+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63158+#else
63159+ return false;
63160+#endif
63161+}
63162+
63163 #endif /* _LINUX_FS_H */
63164diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63165index 003dc0f..3c4ea97 100644
63166--- a/include/linux/fs_struct.h
63167+++ b/include/linux/fs_struct.h
63168@@ -6,7 +6,7 @@
63169 #include <linux/seqlock.h>
63170
63171 struct fs_struct {
63172- int users;
63173+ atomic_t users;
63174 spinlock_t lock;
63175 seqcount_t seq;
63176 int umask;
63177diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63178index ce31408..b1ad003 100644
63179--- a/include/linux/fscache-cache.h
63180+++ b/include/linux/fscache-cache.h
63181@@ -102,7 +102,7 @@ struct fscache_operation {
63182 fscache_operation_release_t release;
63183 };
63184
63185-extern atomic_t fscache_op_debug_id;
63186+extern atomic_unchecked_t fscache_op_debug_id;
63187 extern void fscache_op_work_func(struct work_struct *work);
63188
63189 extern void fscache_enqueue_operation(struct fscache_operation *);
63190@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63191 {
63192 INIT_WORK(&op->work, fscache_op_work_func);
63193 atomic_set(&op->usage, 1);
63194- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63195+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63196 op->processor = processor;
63197 op->release = release;
63198 INIT_LIST_HEAD(&op->pend_link);
63199diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63200index 0fbfb46..508eb0d 100644
63201--- a/include/linux/fsnotify.h
63202+++ b/include/linux/fsnotify.h
63203@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63204 struct inode *inode = path->dentry->d_inode;
63205 __u32 mask = FS_ACCESS;
63206
63207+ if (is_sidechannel_device(inode))
63208+ return;
63209+
63210 if (S_ISDIR(inode->i_mode))
63211 mask |= FS_ISDIR;
63212
63213@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63214 struct inode *inode = path->dentry->d_inode;
63215 __u32 mask = FS_MODIFY;
63216
63217+ if (is_sidechannel_device(inode))
63218+ return;
63219+
63220 if (S_ISDIR(inode->i_mode))
63221 mask |= FS_ISDIR;
63222
63223@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63224 */
63225 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63226 {
63227- return kstrdup(name, GFP_KERNEL);
63228+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63229 }
63230
63231 /*
63232diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63233index 642928c..93afe6a 100644
63234--- a/include/linux/ftrace_event.h
63235+++ b/include/linux/ftrace_event.h
63236@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63237 extern int trace_add_event_call(struct ftrace_event_call *call);
63238 extern void trace_remove_event_call(struct ftrace_event_call *call);
63239
63240-#define is_signed_type(type) (((type)(-1)) < 0)
63241+#define is_signed_type(type) (((type)(-1)) < (type)1)
63242
63243 int trace_set_clr_event(const char *system, const char *event, int set);
63244
63245diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63246index 4f440b3..342233a 100644
63247--- a/include/linux/genhd.h
63248+++ b/include/linux/genhd.h
63249@@ -190,7 +190,7 @@ struct gendisk {
63250 struct kobject *slave_dir;
63251
63252 struct timer_rand_state *random;
63253- atomic_t sync_io; /* RAID */
63254+ atomic_unchecked_t sync_io; /* RAID */
63255 struct disk_events *ev;
63256 #ifdef CONFIG_BLK_DEV_INTEGRITY
63257 struct blk_integrity *integrity;
63258diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63259index d0a7967..63c4c47 100644
63260--- a/include/linux/gfp.h
63261+++ b/include/linux/gfp.h
63262@@ -35,6 +35,12 @@ struct vm_area_struct;
63263 #define ___GFP_OTHER_NODE 0x800000u
63264 #define ___GFP_WRITE 0x1000000u
63265
63266+#ifdef CONFIG_PAX_USERCOPY_SLABS
63267+#define ___GFP_USERCOPY 0x2000000u
63268+#else
63269+#define ___GFP_USERCOPY 0
63270+#endif
63271+
63272 /*
63273 * GFP bitmasks..
63274 *
63275@@ -89,6 +95,7 @@ struct vm_area_struct;
63276 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63277 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63278 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63279+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63280
63281 /*
63282 * This may seem redundant, but it's a way of annotating false positives vs.
63283@@ -96,7 +103,7 @@ struct vm_area_struct;
63284 */
63285 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63286
63287-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63288+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63289 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63290
63291 /* This equals 0, but use constants in case they ever change */
63292@@ -150,6 +157,8 @@ struct vm_area_struct;
63293 /* 4GB DMA on some platforms */
63294 #define GFP_DMA32 __GFP_DMA32
63295
63296+#define GFP_USERCOPY __GFP_USERCOPY
63297+
63298 /* Convert GFP flags to their corresponding migrate type */
63299 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63300 {
63301diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63302new file mode 100644
63303index 0000000..ebe6d72
63304--- /dev/null
63305+++ b/include/linux/gracl.h
63306@@ -0,0 +1,319 @@
63307+#ifndef GR_ACL_H
63308+#define GR_ACL_H
63309+
63310+#include <linux/grdefs.h>
63311+#include <linux/resource.h>
63312+#include <linux/capability.h>
63313+#include <linux/dcache.h>
63314+#include <asm/resource.h>
63315+
63316+/* Major status information */
63317+
63318+#define GR_VERSION "grsecurity 2.9.1"
63319+#define GRSECURITY_VERSION 0x2901
63320+
63321+enum {
63322+ GR_SHUTDOWN = 0,
63323+ GR_ENABLE = 1,
63324+ GR_SPROLE = 2,
63325+ GR_RELOAD = 3,
63326+ GR_SEGVMOD = 4,
63327+ GR_STATUS = 5,
63328+ GR_UNSPROLE = 6,
63329+ GR_PASSSET = 7,
63330+ GR_SPROLEPAM = 8,
63331+};
63332+
63333+/* Password setup definitions
63334+ * kernel/grhash.c */
63335+enum {
63336+ GR_PW_LEN = 128,
63337+ GR_SALT_LEN = 16,
63338+ GR_SHA_LEN = 32,
63339+};
63340+
63341+enum {
63342+ GR_SPROLE_LEN = 64,
63343+};
63344+
63345+enum {
63346+ GR_NO_GLOB = 0,
63347+ GR_REG_GLOB,
63348+ GR_CREATE_GLOB
63349+};
63350+
63351+#define GR_NLIMITS 32
63352+
63353+/* Begin Data Structures */
63354+
63355+struct sprole_pw {
63356+ unsigned char *rolename;
63357+ unsigned char salt[GR_SALT_LEN];
63358+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63359+};
63360+
63361+struct name_entry {
63362+ __u32 key;
63363+ ino_t inode;
63364+ dev_t device;
63365+ char *name;
63366+ __u16 len;
63367+ __u8 deleted;
63368+ struct name_entry *prev;
63369+ struct name_entry *next;
63370+};
63371+
63372+struct inodev_entry {
63373+ struct name_entry *nentry;
63374+ struct inodev_entry *prev;
63375+ struct inodev_entry *next;
63376+};
63377+
63378+struct acl_role_db {
63379+ struct acl_role_label **r_hash;
63380+ __u32 r_size;
63381+};
63382+
63383+struct inodev_db {
63384+ struct inodev_entry **i_hash;
63385+ __u32 i_size;
63386+};
63387+
63388+struct name_db {
63389+ struct name_entry **n_hash;
63390+ __u32 n_size;
63391+};
63392+
63393+struct crash_uid {
63394+ uid_t uid;
63395+ unsigned long expires;
63396+};
63397+
63398+struct gr_hash_struct {
63399+ void **table;
63400+ void **nametable;
63401+ void *first;
63402+ __u32 table_size;
63403+ __u32 used_size;
63404+ int type;
63405+};
63406+
63407+/* Userspace Grsecurity ACL data structures */
63408+
63409+struct acl_subject_label {
63410+ char *filename;
63411+ ino_t inode;
63412+ dev_t device;
63413+ __u32 mode;
63414+ kernel_cap_t cap_mask;
63415+ kernel_cap_t cap_lower;
63416+ kernel_cap_t cap_invert_audit;
63417+
63418+ struct rlimit res[GR_NLIMITS];
63419+ __u32 resmask;
63420+
63421+ __u8 user_trans_type;
63422+ __u8 group_trans_type;
63423+ uid_t *user_transitions;
63424+ gid_t *group_transitions;
63425+ __u16 user_trans_num;
63426+ __u16 group_trans_num;
63427+
63428+ __u32 sock_families[2];
63429+ __u32 ip_proto[8];
63430+ __u32 ip_type;
63431+ struct acl_ip_label **ips;
63432+ __u32 ip_num;
63433+ __u32 inaddr_any_override;
63434+
63435+ __u32 crashes;
63436+ unsigned long expires;
63437+
63438+ struct acl_subject_label *parent_subject;
63439+ struct gr_hash_struct *hash;
63440+ struct acl_subject_label *prev;
63441+ struct acl_subject_label *next;
63442+
63443+ struct acl_object_label **obj_hash;
63444+ __u32 obj_hash_size;
63445+ __u16 pax_flags;
63446+};
63447+
63448+struct role_allowed_ip {
63449+ __u32 addr;
63450+ __u32 netmask;
63451+
63452+ struct role_allowed_ip *prev;
63453+ struct role_allowed_ip *next;
63454+};
63455+
63456+struct role_transition {
63457+ char *rolename;
63458+
63459+ struct role_transition *prev;
63460+ struct role_transition *next;
63461+};
63462+
63463+struct acl_role_label {
63464+ char *rolename;
63465+ uid_t uidgid;
63466+ __u16 roletype;
63467+
63468+ __u16 auth_attempts;
63469+ unsigned long expires;
63470+
63471+ struct acl_subject_label *root_label;
63472+ struct gr_hash_struct *hash;
63473+
63474+ struct acl_role_label *prev;
63475+ struct acl_role_label *next;
63476+
63477+ struct role_transition *transitions;
63478+ struct role_allowed_ip *allowed_ips;
63479+ uid_t *domain_children;
63480+ __u16 domain_child_num;
63481+
63482+ umode_t umask;
63483+
63484+ struct acl_subject_label **subj_hash;
63485+ __u32 subj_hash_size;
63486+};
63487+
63488+struct user_acl_role_db {
63489+ struct acl_role_label **r_table;
63490+ __u32 num_pointers; /* Number of allocations to track */
63491+ __u32 num_roles; /* Number of roles */
63492+ __u32 num_domain_children; /* Number of domain children */
63493+ __u32 num_subjects; /* Number of subjects */
63494+ __u32 num_objects; /* Number of objects */
63495+};
63496+
63497+struct acl_object_label {
63498+ char *filename;
63499+ ino_t inode;
63500+ dev_t device;
63501+ __u32 mode;
63502+
63503+ struct acl_subject_label *nested;
63504+ struct acl_object_label *globbed;
63505+
63506+ /* next two structures not used */
63507+
63508+ struct acl_object_label *prev;
63509+ struct acl_object_label *next;
63510+};
63511+
63512+struct acl_ip_label {
63513+ char *iface;
63514+ __u32 addr;
63515+ __u32 netmask;
63516+ __u16 low, high;
63517+ __u8 mode;
63518+ __u32 type;
63519+ __u32 proto[8];
63520+
63521+ /* next two structures not used */
63522+
63523+ struct acl_ip_label *prev;
63524+ struct acl_ip_label *next;
63525+};
63526+
63527+struct gr_arg {
63528+ struct user_acl_role_db role_db;
63529+ unsigned char pw[GR_PW_LEN];
63530+ unsigned char salt[GR_SALT_LEN];
63531+ unsigned char sum[GR_SHA_LEN];
63532+ unsigned char sp_role[GR_SPROLE_LEN];
63533+ struct sprole_pw *sprole_pws;
63534+ dev_t segv_device;
63535+ ino_t segv_inode;
63536+ uid_t segv_uid;
63537+ __u16 num_sprole_pws;
63538+ __u16 mode;
63539+};
63540+
63541+struct gr_arg_wrapper {
63542+ struct gr_arg *arg;
63543+ __u32 version;
63544+ __u32 size;
63545+};
63546+
63547+struct subject_map {
63548+ struct acl_subject_label *user;
63549+ struct acl_subject_label *kernel;
63550+ struct subject_map *prev;
63551+ struct subject_map *next;
63552+};
63553+
63554+struct acl_subj_map_db {
63555+ struct subject_map **s_hash;
63556+ __u32 s_size;
63557+};
63558+
63559+/* End Data Structures Section */
63560+
63561+/* Hash functions generated by empirical testing by Brad Spengler
63562+ Makes good use of the low bits of the inode. Generally 0-1 times
63563+ in loop for successful match. 0-3 for unsuccessful match.
63564+ Shift/add algorithm with modulus of table size and an XOR*/
63565+
63566+static __inline__ unsigned int
63567+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63568+{
63569+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
63570+}
63571+
63572+ static __inline__ unsigned int
63573+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63574+{
63575+ return ((const unsigned long)userp % sz);
63576+}
63577+
63578+static __inline__ unsigned int
63579+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63580+{
63581+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63582+}
63583+
63584+static __inline__ unsigned int
63585+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63586+{
63587+ return full_name_hash((const unsigned char *)name, len) % sz;
63588+}
63589+
63590+#define FOR_EACH_ROLE_START(role) \
63591+ role = role_list; \
63592+ while (role) {
63593+
63594+#define FOR_EACH_ROLE_END(role) \
63595+ role = role->prev; \
63596+ }
63597+
63598+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63599+ subj = NULL; \
63600+ iter = 0; \
63601+ while (iter < role->subj_hash_size) { \
63602+ if (subj == NULL) \
63603+ subj = role->subj_hash[iter]; \
63604+ if (subj == NULL) { \
63605+ iter++; \
63606+ continue; \
63607+ }
63608+
63609+#define FOR_EACH_SUBJECT_END(subj,iter) \
63610+ subj = subj->next; \
63611+ if (subj == NULL) \
63612+ iter++; \
63613+ }
63614+
63615+
63616+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63617+ subj = role->hash->first; \
63618+ while (subj != NULL) {
63619+
63620+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63621+ subj = subj->next; \
63622+ }
63623+
63624+#endif
63625+
63626diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63627new file mode 100644
63628index 0000000..323ecf2
63629--- /dev/null
63630+++ b/include/linux/gralloc.h
63631@@ -0,0 +1,9 @@
63632+#ifndef __GRALLOC_H
63633+#define __GRALLOC_H
63634+
63635+void acl_free_all(void);
63636+int acl_alloc_stack_init(unsigned long size);
63637+void *acl_alloc(unsigned long len);
63638+void *acl_alloc_num(unsigned long num, unsigned long len);
63639+
63640+#endif
63641diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63642new file mode 100644
63643index 0000000..be66033
63644--- /dev/null
63645+++ b/include/linux/grdefs.h
63646@@ -0,0 +1,140 @@
63647+#ifndef GRDEFS_H
63648+#define GRDEFS_H
63649+
63650+/* Begin grsecurity status declarations */
63651+
63652+enum {
63653+ GR_READY = 0x01,
63654+ GR_STATUS_INIT = 0x00 // disabled state
63655+};
63656+
63657+/* Begin ACL declarations */
63658+
63659+/* Role flags */
63660+
63661+enum {
63662+ GR_ROLE_USER = 0x0001,
63663+ GR_ROLE_GROUP = 0x0002,
63664+ GR_ROLE_DEFAULT = 0x0004,
63665+ GR_ROLE_SPECIAL = 0x0008,
63666+ GR_ROLE_AUTH = 0x0010,
63667+ GR_ROLE_NOPW = 0x0020,
63668+ GR_ROLE_GOD = 0x0040,
63669+ GR_ROLE_LEARN = 0x0080,
63670+ GR_ROLE_TPE = 0x0100,
63671+ GR_ROLE_DOMAIN = 0x0200,
63672+ GR_ROLE_PAM = 0x0400,
63673+ GR_ROLE_PERSIST = 0x0800
63674+};
63675+
63676+/* ACL Subject and Object mode flags */
63677+enum {
63678+ GR_DELETED = 0x80000000
63679+};
63680+
63681+/* ACL Object-only mode flags */
63682+enum {
63683+ GR_READ = 0x00000001,
63684+ GR_APPEND = 0x00000002,
63685+ GR_WRITE = 0x00000004,
63686+ GR_EXEC = 0x00000008,
63687+ GR_FIND = 0x00000010,
63688+ GR_INHERIT = 0x00000020,
63689+ GR_SETID = 0x00000040,
63690+ GR_CREATE = 0x00000080,
63691+ GR_DELETE = 0x00000100,
63692+ GR_LINK = 0x00000200,
63693+ GR_AUDIT_READ = 0x00000400,
63694+ GR_AUDIT_APPEND = 0x00000800,
63695+ GR_AUDIT_WRITE = 0x00001000,
63696+ GR_AUDIT_EXEC = 0x00002000,
63697+ GR_AUDIT_FIND = 0x00004000,
63698+ GR_AUDIT_INHERIT= 0x00008000,
63699+ GR_AUDIT_SETID = 0x00010000,
63700+ GR_AUDIT_CREATE = 0x00020000,
63701+ GR_AUDIT_DELETE = 0x00040000,
63702+ GR_AUDIT_LINK = 0x00080000,
63703+ GR_PTRACERD = 0x00100000,
63704+ GR_NOPTRACE = 0x00200000,
63705+ GR_SUPPRESS = 0x00400000,
63706+ GR_NOLEARN = 0x00800000,
63707+ GR_INIT_TRANSFER= 0x01000000
63708+};
63709+
63710+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63711+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63712+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63713+
63714+/* ACL subject-only mode flags */
63715+enum {
63716+ GR_KILL = 0x00000001,
63717+ GR_VIEW = 0x00000002,
63718+ GR_PROTECTED = 0x00000004,
63719+ GR_LEARN = 0x00000008,
63720+ GR_OVERRIDE = 0x00000010,
63721+ /* just a placeholder, this mode is only used in userspace */
63722+ GR_DUMMY = 0x00000020,
63723+ GR_PROTSHM = 0x00000040,
63724+ GR_KILLPROC = 0x00000080,
63725+ GR_KILLIPPROC = 0x00000100,
63726+ /* just a placeholder, this mode is only used in userspace */
63727+ GR_NOTROJAN = 0x00000200,
63728+ GR_PROTPROCFD = 0x00000400,
63729+ GR_PROCACCT = 0x00000800,
63730+ GR_RELAXPTRACE = 0x00001000,
63731+ //GR_NESTED = 0x00002000,
63732+ GR_INHERITLEARN = 0x00004000,
63733+ GR_PROCFIND = 0x00008000,
63734+ GR_POVERRIDE = 0x00010000,
63735+ GR_KERNELAUTH = 0x00020000,
63736+ GR_ATSECURE = 0x00040000,
63737+ GR_SHMEXEC = 0x00080000
63738+};
63739+
63740+enum {
63741+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63742+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63743+ GR_PAX_ENABLE_MPROTECT = 0x0004,
63744+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
63745+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63746+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63747+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63748+ GR_PAX_DISABLE_MPROTECT = 0x0400,
63749+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
63750+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63751+};
63752+
63753+enum {
63754+ GR_ID_USER = 0x01,
63755+ GR_ID_GROUP = 0x02,
63756+};
63757+
63758+enum {
63759+ GR_ID_ALLOW = 0x01,
63760+ GR_ID_DENY = 0x02,
63761+};
63762+
63763+#define GR_CRASH_RES 31
63764+#define GR_UIDTABLE_MAX 500
63765+
63766+/* begin resource learning section */
63767+enum {
63768+ GR_RLIM_CPU_BUMP = 60,
63769+ GR_RLIM_FSIZE_BUMP = 50000,
63770+ GR_RLIM_DATA_BUMP = 10000,
63771+ GR_RLIM_STACK_BUMP = 1000,
63772+ GR_RLIM_CORE_BUMP = 10000,
63773+ GR_RLIM_RSS_BUMP = 500000,
63774+ GR_RLIM_NPROC_BUMP = 1,
63775+ GR_RLIM_NOFILE_BUMP = 5,
63776+ GR_RLIM_MEMLOCK_BUMP = 50000,
63777+ GR_RLIM_AS_BUMP = 500000,
63778+ GR_RLIM_LOCKS_BUMP = 2,
63779+ GR_RLIM_SIGPENDING_BUMP = 5,
63780+ GR_RLIM_MSGQUEUE_BUMP = 10000,
63781+ GR_RLIM_NICE_BUMP = 1,
63782+ GR_RLIM_RTPRIO_BUMP = 1,
63783+ GR_RLIM_RTTIME_BUMP = 1000000
63784+};
63785+
63786+#endif
63787diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63788new file mode 100644
63789index 0000000..baa6e96
63790--- /dev/null
63791+++ b/include/linux/grinternal.h
63792@@ -0,0 +1,215 @@
63793+#ifndef __GRINTERNAL_H
63794+#define __GRINTERNAL_H
63795+
63796+#ifdef CONFIG_GRKERNSEC
63797+
63798+#include <linux/fs.h>
63799+#include <linux/mnt_namespace.h>
63800+#include <linux/nsproxy.h>
63801+#include <linux/gracl.h>
63802+#include <linux/grdefs.h>
63803+#include <linux/grmsg.h>
63804+
63805+void gr_add_learn_entry(const char *fmt, ...)
63806+ __attribute__ ((format (printf, 1, 2)));
63807+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
63808+ const struct vfsmount *mnt);
63809+__u32 gr_check_create(const struct dentry *new_dentry,
63810+ const struct dentry *parent,
63811+ const struct vfsmount *mnt, const __u32 mode);
63812+int gr_check_protected_task(const struct task_struct *task);
63813+__u32 to_gr_audit(const __u32 reqmode);
63814+int gr_set_acls(const int type);
63815+int gr_apply_subject_to_task(struct task_struct *task);
63816+int gr_acl_is_enabled(void);
63817+char gr_roletype_to_char(void);
63818+
63819+void gr_handle_alertkill(struct task_struct *task);
63820+char *gr_to_filename(const struct dentry *dentry,
63821+ const struct vfsmount *mnt);
63822+char *gr_to_filename1(const struct dentry *dentry,
63823+ const struct vfsmount *mnt);
63824+char *gr_to_filename2(const struct dentry *dentry,
63825+ const struct vfsmount *mnt);
63826+char *gr_to_filename3(const struct dentry *dentry,
63827+ const struct vfsmount *mnt);
63828+
63829+extern int grsec_enable_ptrace_readexec;
63830+extern int grsec_enable_harden_ptrace;
63831+extern int grsec_enable_link;
63832+extern int grsec_enable_fifo;
63833+extern int grsec_enable_execve;
63834+extern int grsec_enable_shm;
63835+extern int grsec_enable_execlog;
63836+extern int grsec_enable_signal;
63837+extern int grsec_enable_audit_ptrace;
63838+extern int grsec_enable_forkfail;
63839+extern int grsec_enable_time;
63840+extern int grsec_enable_rofs;
63841+extern int grsec_enable_chroot_shmat;
63842+extern int grsec_enable_chroot_mount;
63843+extern int grsec_enable_chroot_double;
63844+extern int grsec_enable_chroot_pivot;
63845+extern int grsec_enable_chroot_chdir;
63846+extern int grsec_enable_chroot_chmod;
63847+extern int grsec_enable_chroot_mknod;
63848+extern int grsec_enable_chroot_fchdir;
63849+extern int grsec_enable_chroot_nice;
63850+extern int grsec_enable_chroot_execlog;
63851+extern int grsec_enable_chroot_caps;
63852+extern int grsec_enable_chroot_sysctl;
63853+extern int grsec_enable_chroot_unix;
63854+extern int grsec_enable_symlinkown;
63855+extern int grsec_symlinkown_gid;
63856+extern int grsec_enable_tpe;
63857+extern int grsec_tpe_gid;
63858+extern int grsec_enable_tpe_all;
63859+extern int grsec_enable_tpe_invert;
63860+extern int grsec_enable_socket_all;
63861+extern int grsec_socket_all_gid;
63862+extern int grsec_enable_socket_client;
63863+extern int grsec_socket_client_gid;
63864+extern int grsec_enable_socket_server;
63865+extern int grsec_socket_server_gid;
63866+extern int grsec_audit_gid;
63867+extern int grsec_enable_group;
63868+extern int grsec_enable_audit_textrel;
63869+extern int grsec_enable_log_rwxmaps;
63870+extern int grsec_enable_mount;
63871+extern int grsec_enable_chdir;
63872+extern int grsec_resource_logging;
63873+extern int grsec_enable_blackhole;
63874+extern int grsec_lastack_retries;
63875+extern int grsec_enable_brute;
63876+extern int grsec_lock;
63877+
63878+extern spinlock_t grsec_alert_lock;
63879+extern unsigned long grsec_alert_wtime;
63880+extern unsigned long grsec_alert_fyet;
63881+
63882+extern spinlock_t grsec_audit_lock;
63883+
63884+extern rwlock_t grsec_exec_file_lock;
63885+
63886+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
63887+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
63888+ (tsk)->exec_file->f_vfsmnt) : "/")
63889+
63890+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
63891+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
63892+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63893+
63894+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
63895+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
63896+ (tsk)->exec_file->f_vfsmnt) : "/")
63897+
63898+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
63899+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
63900+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63901+
63902+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
63903+
63904+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
63905+
63906+#define GR_CHROOT_CAPS {{ \
63907+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
63908+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
63909+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
63910+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
63911+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
63912+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
63913+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
63914+
63915+#define security_learn(normal_msg,args...) \
63916+({ \
63917+ read_lock(&grsec_exec_file_lock); \
63918+ gr_add_learn_entry(normal_msg "\n", ## args); \
63919+ read_unlock(&grsec_exec_file_lock); \
63920+})
63921+
63922+enum {
63923+ GR_DO_AUDIT,
63924+ GR_DONT_AUDIT,
63925+ /* used for non-audit messages that we shouldn't kill the task on */
63926+ GR_DONT_AUDIT_GOOD
63927+};
63928+
63929+enum {
63930+ GR_TTYSNIFF,
63931+ GR_RBAC,
63932+ GR_RBAC_STR,
63933+ GR_STR_RBAC,
63934+ GR_RBAC_MODE2,
63935+ GR_RBAC_MODE3,
63936+ GR_FILENAME,
63937+ GR_SYSCTL_HIDDEN,
63938+ GR_NOARGS,
63939+ GR_ONE_INT,
63940+ GR_ONE_INT_TWO_STR,
63941+ GR_ONE_STR,
63942+ GR_STR_INT,
63943+ GR_TWO_STR_INT,
63944+ GR_TWO_INT,
63945+ GR_TWO_U64,
63946+ GR_THREE_INT,
63947+ GR_FIVE_INT_TWO_STR,
63948+ GR_TWO_STR,
63949+ GR_THREE_STR,
63950+ GR_FOUR_STR,
63951+ GR_STR_FILENAME,
63952+ GR_FILENAME_STR,
63953+ GR_FILENAME_TWO_INT,
63954+ GR_FILENAME_TWO_INT_STR,
63955+ GR_TEXTREL,
63956+ GR_PTRACE,
63957+ GR_RESOURCE,
63958+ GR_CAP,
63959+ GR_SIG,
63960+ GR_SIG2,
63961+ GR_CRASH1,
63962+ GR_CRASH2,
63963+ GR_PSACCT,
63964+ GR_RWXMAP
63965+};
63966+
63967+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
63968+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
63969+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
63970+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
63971+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
63972+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
63973+#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)
63974+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
63975+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
63976+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
63977+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
63978+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
63979+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
63980+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
63981+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
63982+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
63983+#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)
63984+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
63985+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
63986+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
63987+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
63988+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
63989+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
63990+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
63991+#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)
63992+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
63993+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
63994+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
63995+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
63996+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
63997+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
63998+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
63999+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64000+#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)
64001+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64002+
64003+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64004+
64005+#endif
64006+
64007+#endif
64008diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64009new file mode 100644
64010index 0000000..2bd4c8d
64011--- /dev/null
64012+++ b/include/linux/grmsg.h
64013@@ -0,0 +1,111 @@
64014+#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"
64015+#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"
64016+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64017+#define GR_STOPMOD_MSG "denied modification of module state by "
64018+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64019+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64020+#define GR_IOPERM_MSG "denied use of ioperm() by "
64021+#define GR_IOPL_MSG "denied use of iopl() by "
64022+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64023+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64024+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64025+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64026+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64027+#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"
64028+#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"
64029+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64030+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64031+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64032+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64033+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64034+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64035+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64036+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64037+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64038+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64039+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64040+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64041+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64042+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64043+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64044+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64045+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64046+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64047+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64048+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64049+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64050+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64051+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64052+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64053+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64054+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64055+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64056+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64057+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64058+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64059+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64060+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64061+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64062+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64063+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64064+#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"
64065+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64066+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64067+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64068+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64069+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64070+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64071+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64072+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64073+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64074+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64075+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64076+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64077+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64078+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64079+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64080+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64081+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64082+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64083+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64084+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64085+#define GR_FAILFORK_MSG "failed fork with errno %s by "
64086+#define GR_NICE_CHROOT_MSG "denied priority change by "
64087+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64088+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64089+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64090+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64091+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64092+#define GR_TIME_MSG "time set by "
64093+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64094+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64095+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64096+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64097+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64098+#define GR_BIND_MSG "denied bind() by "
64099+#define GR_CONNECT_MSG "denied connect() by "
64100+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64101+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64102+#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"
64103+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64104+#define GR_CAP_ACL_MSG "use of %s denied for "
64105+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64106+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64107+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64108+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64109+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64110+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64111+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64112+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64113+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64114+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64115+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64116+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64117+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64118+#define GR_VM86_MSG "denied use of vm86 by "
64119+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64120+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64121+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64122+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64123+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64124+#define GR_BRUTE_DAEMON_MSG "bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. Please investigate the crash report for "
64125diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64126new file mode 100644
64127index 0000000..c5e5913
64128--- /dev/null
64129+++ b/include/linux/grsecurity.h
64130@@ -0,0 +1,257 @@
64131+#ifndef GR_SECURITY_H
64132+#define GR_SECURITY_H
64133+#include <linux/fs.h>
64134+#include <linux/fs_struct.h>
64135+#include <linux/binfmts.h>
64136+#include <linux/gracl.h>
64137+
64138+/* notify of brain-dead configs */
64139+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64140+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64141+#endif
64142+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64143+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64144+#endif
64145+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64146+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64147+#endif
64148+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64149+#error "CONFIG_PAX enabled, but no PaX options are enabled."
64150+#endif
64151+
64152+#include <linux/compat.h>
64153+
64154+struct user_arg_ptr {
64155+#ifdef CONFIG_COMPAT
64156+ bool is_compat;
64157+#endif
64158+ union {
64159+ const char __user *const __user *native;
64160+#ifdef CONFIG_COMPAT
64161+ const compat_uptr_t __user *compat;
64162+#endif
64163+ } ptr;
64164+};
64165+
64166+void gr_handle_brute_attach(unsigned long mm_flags);
64167+void gr_handle_brute_check(void);
64168+void gr_handle_kernel_exploit(void);
64169+int gr_process_user_ban(void);
64170+
64171+char gr_roletype_to_char(void);
64172+
64173+int gr_acl_enable_at_secure(void);
64174+
64175+int gr_check_user_change(int real, int effective, int fs);
64176+int gr_check_group_change(int real, int effective, int fs);
64177+
64178+void gr_del_task_from_ip_table(struct task_struct *p);
64179+
64180+int gr_pid_is_chrooted(struct task_struct *p);
64181+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64182+int gr_handle_chroot_nice(void);
64183+int gr_handle_chroot_sysctl(const int op);
64184+int gr_handle_chroot_setpriority(struct task_struct *p,
64185+ const int niceval);
64186+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64187+int gr_handle_chroot_chroot(const struct dentry *dentry,
64188+ const struct vfsmount *mnt);
64189+void gr_handle_chroot_chdir(struct path *path);
64190+int gr_handle_chroot_chmod(const struct dentry *dentry,
64191+ const struct vfsmount *mnt, const int mode);
64192+int gr_handle_chroot_mknod(const struct dentry *dentry,
64193+ const struct vfsmount *mnt, const int mode);
64194+int gr_handle_chroot_mount(const struct dentry *dentry,
64195+ const struct vfsmount *mnt,
64196+ const char *dev_name);
64197+int gr_handle_chroot_pivot(void);
64198+int gr_handle_chroot_unix(const pid_t pid);
64199+
64200+int gr_handle_rawio(const struct inode *inode);
64201+
64202+void gr_handle_ioperm(void);
64203+void gr_handle_iopl(void);
64204+
64205+umode_t gr_acl_umask(void);
64206+
64207+int gr_tpe_allow(const struct file *file);
64208+
64209+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64210+void gr_clear_chroot_entries(struct task_struct *task);
64211+
64212+void gr_log_forkfail(const int retval);
64213+void gr_log_timechange(void);
64214+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64215+void gr_log_chdir(const struct dentry *dentry,
64216+ const struct vfsmount *mnt);
64217+void gr_log_chroot_exec(const struct dentry *dentry,
64218+ const struct vfsmount *mnt);
64219+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64220+void gr_log_remount(const char *devname, const int retval);
64221+void gr_log_unmount(const char *devname, const int retval);
64222+void gr_log_mount(const char *from, const char *to, const int retval);
64223+void gr_log_textrel(struct vm_area_struct *vma);
64224+void gr_log_rwxmmap(struct file *file);
64225+void gr_log_rwxmprotect(struct file *file);
64226+
64227+int gr_handle_follow_link(const struct inode *parent,
64228+ const struct inode *inode,
64229+ const struct dentry *dentry,
64230+ const struct vfsmount *mnt);
64231+int gr_handle_fifo(const struct dentry *dentry,
64232+ const struct vfsmount *mnt,
64233+ const struct dentry *dir, const int flag,
64234+ const int acc_mode);
64235+int gr_handle_hardlink(const struct dentry *dentry,
64236+ const struct vfsmount *mnt,
64237+ struct inode *inode,
64238+ const int mode, const struct filename *to);
64239+
64240+int gr_is_capable(const int cap);
64241+int gr_is_capable_nolog(const int cap);
64242+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64243+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64244+
64245+void gr_copy_label(struct task_struct *tsk);
64246+void gr_handle_crash(struct task_struct *task, const int sig);
64247+int gr_handle_signal(const struct task_struct *p, const int sig);
64248+int gr_check_crash_uid(const uid_t uid);
64249+int gr_check_protected_task(const struct task_struct *task);
64250+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64251+int gr_acl_handle_mmap(const struct file *file,
64252+ const unsigned long prot);
64253+int gr_acl_handle_mprotect(const struct file *file,
64254+ const unsigned long prot);
64255+int gr_check_hidden_task(const struct task_struct *tsk);
64256+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64257+ const struct vfsmount *mnt);
64258+__u32 gr_acl_handle_utime(const struct dentry *dentry,
64259+ const struct vfsmount *mnt);
64260+__u32 gr_acl_handle_access(const struct dentry *dentry,
64261+ const struct vfsmount *mnt, const int fmode);
64262+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64263+ const struct vfsmount *mnt, umode_t *mode);
64264+__u32 gr_acl_handle_chown(const struct dentry *dentry,
64265+ const struct vfsmount *mnt);
64266+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64267+ const struct vfsmount *mnt);
64268+int gr_handle_ptrace(struct task_struct *task, const long request);
64269+int gr_handle_proc_ptrace(struct task_struct *task);
64270+__u32 gr_acl_handle_execve(const struct dentry *dentry,
64271+ const struct vfsmount *mnt);
64272+int gr_check_crash_exec(const struct file *filp);
64273+int gr_acl_is_enabled(void);
64274+void gr_set_kernel_label(struct task_struct *task);
64275+void gr_set_role_label(struct task_struct *task, const uid_t uid,
64276+ const gid_t gid);
64277+int gr_set_proc_label(const struct dentry *dentry,
64278+ const struct vfsmount *mnt,
64279+ const int unsafe_flags);
64280+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64281+ const struct vfsmount *mnt);
64282+__u32 gr_acl_handle_open(const struct dentry *dentry,
64283+ const struct vfsmount *mnt, int acc_mode);
64284+__u32 gr_acl_handle_creat(const struct dentry *dentry,
64285+ const struct dentry *p_dentry,
64286+ const struct vfsmount *p_mnt,
64287+ int open_flags, int acc_mode, const int imode);
64288+void gr_handle_create(const struct dentry *dentry,
64289+ const struct vfsmount *mnt);
64290+void gr_handle_proc_create(const struct dentry *dentry,
64291+ const struct inode *inode);
64292+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64293+ const struct dentry *parent_dentry,
64294+ const struct vfsmount *parent_mnt,
64295+ const int mode);
64296+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64297+ const struct dentry *parent_dentry,
64298+ const struct vfsmount *parent_mnt);
64299+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64300+ const struct vfsmount *mnt);
64301+void gr_handle_delete(const ino_t ino, const dev_t dev);
64302+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64303+ const struct vfsmount *mnt);
64304+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64305+ const struct dentry *parent_dentry,
64306+ const struct vfsmount *parent_mnt,
64307+ const struct filename *from);
64308+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64309+ const struct dentry *parent_dentry,
64310+ const struct vfsmount *parent_mnt,
64311+ const struct dentry *old_dentry,
64312+ const struct vfsmount *old_mnt, const struct filename *to);
64313+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64314+int gr_acl_handle_rename(struct dentry *new_dentry,
64315+ struct dentry *parent_dentry,
64316+ const struct vfsmount *parent_mnt,
64317+ struct dentry *old_dentry,
64318+ struct inode *old_parent_inode,
64319+ struct vfsmount *old_mnt, const struct filename *newname);
64320+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64321+ struct dentry *old_dentry,
64322+ struct dentry *new_dentry,
64323+ struct vfsmount *mnt, const __u8 replace);
64324+__u32 gr_check_link(const struct dentry *new_dentry,
64325+ const struct dentry *parent_dentry,
64326+ const struct vfsmount *parent_mnt,
64327+ const struct dentry *old_dentry,
64328+ const struct vfsmount *old_mnt);
64329+int gr_acl_handle_filldir(const struct file *file, const char *name,
64330+ const unsigned int namelen, const ino_t ino);
64331+
64332+__u32 gr_acl_handle_unix(const struct dentry *dentry,
64333+ const struct vfsmount *mnt);
64334+void gr_acl_handle_exit(void);
64335+void gr_acl_handle_psacct(struct task_struct *task, const long code);
64336+int gr_acl_handle_procpidmem(const struct task_struct *task);
64337+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64338+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64339+void gr_audit_ptrace(struct task_struct *task);
64340+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64341+void gr_put_exec_file(struct task_struct *task);
64342+
64343+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64344+
64345+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
64346+extern void gr_learn_resource(const struct task_struct *task, const int res,
64347+ const unsigned long wanted, const int gt);
64348+#else
64349+static inline void gr_learn_resource(const struct task_struct *task, const int res,
64350+ const unsigned long wanted, const int gt)
64351+{
64352+}
64353+#endif
64354+
64355+#ifdef CONFIG_GRKERNSEC_RESLOG
64356+extern void gr_log_resource(const struct task_struct *task, const int res,
64357+ const unsigned long wanted, const int gt);
64358+#else
64359+static inline void gr_log_resource(const struct task_struct *task, const int res,
64360+ const unsigned long wanted, const int gt)
64361+{
64362+}
64363+#endif
64364+
64365+#ifdef CONFIG_GRKERNSEC
64366+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64367+void gr_handle_vm86(void);
64368+void gr_handle_mem_readwrite(u64 from, u64 to);
64369+
64370+void gr_log_badprocpid(const char *entry);
64371+
64372+extern int grsec_enable_dmesg;
64373+extern int grsec_disable_privio;
64374+
64375+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64376+extern int grsec_proc_gid;
64377+#endif
64378+
64379+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64380+extern int grsec_enable_chroot_findtask;
64381+#endif
64382+#ifdef CONFIG_GRKERNSEC_SETXID
64383+extern int grsec_enable_setxid;
64384+#endif
64385+#endif
64386+
64387+#endif
64388diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64389new file mode 100644
64390index 0000000..e7ffaaf
64391--- /dev/null
64392+++ b/include/linux/grsock.h
64393@@ -0,0 +1,19 @@
64394+#ifndef __GRSOCK_H
64395+#define __GRSOCK_H
64396+
64397+extern void gr_attach_curr_ip(const struct sock *sk);
64398+extern int gr_handle_sock_all(const int family, const int type,
64399+ const int protocol);
64400+extern int gr_handle_sock_server(const struct sockaddr *sck);
64401+extern int gr_handle_sock_server_other(const struct sock *sck);
64402+extern int gr_handle_sock_client(const struct sockaddr *sck);
64403+extern int gr_search_connect(struct socket * sock,
64404+ struct sockaddr_in * addr);
64405+extern int gr_search_bind(struct socket * sock,
64406+ struct sockaddr_in * addr);
64407+extern int gr_search_listen(struct socket * sock);
64408+extern int gr_search_accept(struct socket * sock);
64409+extern int gr_search_socket(const int domain, const int type,
64410+ const int protocol);
64411+
64412+#endif
64413diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64414index ef788b5..ac41b7b 100644
64415--- a/include/linux/highmem.h
64416+++ b/include/linux/highmem.h
64417@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64418 kunmap_atomic(kaddr);
64419 }
64420
64421+static inline void sanitize_highpage(struct page *page)
64422+{
64423+ void *kaddr;
64424+ unsigned long flags;
64425+
64426+ local_irq_save(flags);
64427+ kaddr = kmap_atomic(page);
64428+ clear_page(kaddr);
64429+ kunmap_atomic(kaddr);
64430+ local_irq_restore(flags);
64431+}
64432+
64433 static inline void zero_user_segments(struct page *page,
64434 unsigned start1, unsigned end1,
64435 unsigned start2, unsigned end2)
64436diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64437index 800de22..7a2fa46 100644
64438--- a/include/linux/i2c.h
64439+++ b/include/linux/i2c.h
64440@@ -367,6 +367,7 @@ struct i2c_algorithm {
64441 /* To determine what the adapter supports */
64442 u32 (*functionality) (struct i2c_adapter *);
64443 };
64444+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64445
64446 /*
64447 * i2c_adapter is the structure used to identify a physical i2c bus along
64448diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64449index d23c3c2..eb63c81 100644
64450--- a/include/linux/i2o.h
64451+++ b/include/linux/i2o.h
64452@@ -565,7 +565,7 @@ struct i2o_controller {
64453 struct i2o_device *exec; /* Executive */
64454 #if BITS_PER_LONG == 64
64455 spinlock_t context_list_lock; /* lock for context_list */
64456- atomic_t context_list_counter; /* needed for unique contexts */
64457+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64458 struct list_head context_list; /* list of context id's
64459 and pointers */
64460 #endif
64461diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64462index aff7ad8..3942bbd 100644
64463--- a/include/linux/if_pppox.h
64464+++ b/include/linux/if_pppox.h
64465@@ -76,7 +76,7 @@ struct pppox_proto {
64466 int (*ioctl)(struct socket *sock, unsigned int cmd,
64467 unsigned long arg);
64468 struct module *owner;
64469-};
64470+} __do_const;
64471
64472 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64473 extern void unregister_pppox_proto(int proto_num);
64474diff --git a/include/linux/init.h b/include/linux/init.h
64475index e59041e..df0a975 100644
64476--- a/include/linux/init.h
64477+++ b/include/linux/init.h
64478@@ -39,9 +39,36 @@
64479 * Also note, that this data cannot be "const".
64480 */
64481
64482+#ifdef MODULE
64483+#define add_init_latent_entropy
64484+#define add_devinit_latent_entropy
64485+#define add_cpuinit_latent_entropy
64486+#define add_meminit_latent_entropy
64487+#else
64488+#define add_init_latent_entropy __latent_entropy
64489+
64490+#ifdef CONFIG_HOTPLUG
64491+#define add_devinit_latent_entropy
64492+#else
64493+#define add_devinit_latent_entropy __latent_entropy
64494+#endif
64495+
64496+#ifdef CONFIG_HOTPLUG_CPU
64497+#define add_cpuinit_latent_entropy
64498+#else
64499+#define add_cpuinit_latent_entropy __latent_entropy
64500+#endif
64501+
64502+#ifdef CONFIG_MEMORY_HOTPLUG
64503+#define add_meminit_latent_entropy
64504+#else
64505+#define add_meminit_latent_entropy __latent_entropy
64506+#endif
64507+#endif
64508+
64509 /* These are for everybody (although not all archs will actually
64510 discard it in modules) */
64511-#define __init __section(.init.text) __cold notrace
64512+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64513 #define __initdata __section(.init.data)
64514 #define __initconst __constsection(.init.rodata)
64515 #define __exitdata __section(.exit.data)
64516@@ -94,7 +121,7 @@
64517 #define __exit __section(.exit.text) __exitused __cold notrace
64518
64519 /* Used for HOTPLUG */
64520-#define __devinit __section(.devinit.text) __cold notrace
64521+#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64522 #define __devinitdata __section(.devinit.data)
64523 #define __devinitconst __constsection(.devinit.rodata)
64524 #define __devexit __section(.devexit.text) __exitused __cold notrace
64525@@ -102,7 +129,7 @@
64526 #define __devexitconst __constsection(.devexit.rodata)
64527
64528 /* Used for HOTPLUG_CPU */
64529-#define __cpuinit __section(.cpuinit.text) __cold notrace
64530+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64531 #define __cpuinitdata __section(.cpuinit.data)
64532 #define __cpuinitconst __constsection(.cpuinit.rodata)
64533 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64534@@ -110,7 +137,7 @@
64535 #define __cpuexitconst __constsection(.cpuexit.rodata)
64536
64537 /* Used for MEMORY_HOTPLUG */
64538-#define __meminit __section(.meminit.text) __cold notrace
64539+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64540 #define __meminitdata __section(.meminit.data)
64541 #define __meminitconst __constsection(.meminit.rodata)
64542 #define __memexit __section(.memexit.text) __exitused __cold notrace
64543diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64544index 6d087c5..401cab8 100644
64545--- a/include/linux/init_task.h
64546+++ b/include/linux/init_task.h
64547@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64548
64549 #define INIT_TASK_COMM "swapper"
64550
64551+#ifdef CONFIG_X86
64552+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64553+#else
64554+#define INIT_TASK_THREAD_INFO
64555+#endif
64556+
64557 /*
64558 * INIT_TASK is used to set up the first task table, touch at
64559 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64560@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64561 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64562 .comm = INIT_TASK_COMM, \
64563 .thread = INIT_THREAD, \
64564+ INIT_TASK_THREAD_INFO \
64565 .fs = &init_fs, \
64566 .files = &init_files, \
64567 .signal = &init_signals, \
64568diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64569index 5e4e617..073b866 100644
64570--- a/include/linux/interrupt.h
64571+++ b/include/linux/interrupt.h
64572@@ -435,7 +435,7 @@ enum
64573 /* map softirq index to softirq name. update 'softirq_to_name' in
64574 * kernel/softirq.c when adding a new softirq.
64575 */
64576-extern char *softirq_to_name[NR_SOFTIRQS];
64577+extern const char * const softirq_to_name[NR_SOFTIRQS];
64578
64579 /* softirq mask and active fields moved to irq_cpustat_t in
64580 * asm/hardirq.h to get better cache usage. KAO
64581@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64582
64583 struct softirq_action
64584 {
64585- void (*action)(struct softirq_action *);
64586-};
64587+ void (*action)(void);
64588+} __no_const;
64589
64590 asmlinkage void do_softirq(void);
64591 asmlinkage void __do_softirq(void);
64592-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64593+extern void open_softirq(int nr, void (*action)(void));
64594 extern void softirq_init(void);
64595 extern void __raise_softirq_irqoff(unsigned int nr);
64596
64597diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64598index 6883e19..06992b1 100644
64599--- a/include/linux/kallsyms.h
64600+++ b/include/linux/kallsyms.h
64601@@ -15,7 +15,8 @@
64602
64603 struct module;
64604
64605-#ifdef CONFIG_KALLSYMS
64606+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64607+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64608 /* Lookup the address for a symbol. Returns 0 if not found. */
64609 unsigned long kallsyms_lookup_name(const char *name);
64610
64611@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64612 /* Stupid that this does nothing, but I didn't create this mess. */
64613 #define __print_symbol(fmt, addr)
64614 #endif /*CONFIG_KALLSYMS*/
64615+#else /* when included by kallsyms.c, vsnprintf.c, or
64616+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64617+extern void __print_symbol(const char *fmt, unsigned long address);
64618+extern int sprint_backtrace(char *buffer, unsigned long address);
64619+extern int sprint_symbol(char *buffer, unsigned long address);
64620+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64621+const char *kallsyms_lookup(unsigned long addr,
64622+ unsigned long *symbolsize,
64623+ unsigned long *offset,
64624+ char **modname, char *namebuf);
64625+#endif
64626
64627 /* This macro allows us to keep printk typechecking */
64628 static __printf(1, 2)
64629diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64630index 4dff0c6..1ca9b72 100644
64631--- a/include/linux/kgdb.h
64632+++ b/include/linux/kgdb.h
64633@@ -53,7 +53,7 @@ extern int kgdb_connected;
64634 extern int kgdb_io_module_registered;
64635
64636 extern atomic_t kgdb_setting_breakpoint;
64637-extern atomic_t kgdb_cpu_doing_single_step;
64638+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64639
64640 extern struct task_struct *kgdb_usethread;
64641 extern struct task_struct *kgdb_contthread;
64642@@ -255,7 +255,7 @@ struct kgdb_arch {
64643 void (*correct_hw_break)(void);
64644
64645 void (*enable_nmi)(bool on);
64646-};
64647+} __do_const;
64648
64649 /**
64650 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64651@@ -280,7 +280,7 @@ struct kgdb_io {
64652 void (*pre_exception) (void);
64653 void (*post_exception) (void);
64654 int is_console;
64655-};
64656+} __do_const;
64657
64658 extern struct kgdb_arch arch_kgdb_ops;
64659
64660diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64661index 5398d58..5883a34 100644
64662--- a/include/linux/kmod.h
64663+++ b/include/linux/kmod.h
64664@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64665 * usually useless though. */
64666 extern __printf(2, 3)
64667 int __request_module(bool wait, const char *name, ...);
64668+extern __printf(3, 4)
64669+int ___request_module(bool wait, char *param_name, const char *name, ...);
64670 #define request_module(mod...) __request_module(true, mod)
64671 #define request_module_nowait(mod...) __request_module(false, mod)
64672 #define try_then_request_module(x, mod...) \
64673diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64674index 1e57449..4fede7b 100644
64675--- a/include/linux/kobject.h
64676+++ b/include/linux/kobject.h
64677@@ -111,7 +111,7 @@ struct kobj_type {
64678 struct attribute **default_attrs;
64679 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64680 const void *(*namespace)(struct kobject *kobj);
64681-};
64682+} __do_const;
64683
64684 struct kobj_uevent_env {
64685 char *envp[UEVENT_NUM_ENVP];
64686diff --git a/include/linux/kref.h b/include/linux/kref.h
64687index 65af688..0592677 100644
64688--- a/include/linux/kref.h
64689+++ b/include/linux/kref.h
64690@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64691 static inline int kref_sub(struct kref *kref, unsigned int count,
64692 void (*release)(struct kref *kref))
64693 {
64694- WARN_ON(release == NULL);
64695+ BUG_ON(release == NULL);
64696
64697 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64698 release(kref);
64699diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64700index ecc5543..0e96bcc 100644
64701--- a/include/linux/kvm_host.h
64702+++ b/include/linux/kvm_host.h
64703@@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64704 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64705 void vcpu_put(struct kvm_vcpu *vcpu);
64706
64707-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64708+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64709 struct module *module);
64710 void kvm_exit(void);
64711
64712@@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64713 struct kvm_guest_debug *dbg);
64714 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64715
64716-int kvm_arch_init(void *opaque);
64717+int kvm_arch_init(const void *opaque);
64718 void kvm_arch_exit(void);
64719
64720 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64721diff --git a/include/linux/libata.h b/include/linux/libata.h
64722index 1e36c63..0c5046e 100644
64723--- a/include/linux/libata.h
64724+++ b/include/linux/libata.h
64725@@ -915,7 +915,7 @@ struct ata_port_operations {
64726 * fields must be pointers.
64727 */
64728 const struct ata_port_operations *inherits;
64729-};
64730+} __do_const;
64731
64732 struct ata_port_info {
64733 unsigned long flags;
64734diff --git a/include/linux/list.h b/include/linux/list.h
64735index cc6d2aa..71febca 100644
64736--- a/include/linux/list.h
64737+++ b/include/linux/list.h
64738@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64739 extern void list_del(struct list_head *entry);
64740 #endif
64741
64742+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64743+extern void pax_list_del(struct list_head *entry);
64744+
64745 /**
64746 * list_replace - replace old entry by new one
64747 * @old : the element to be replaced
64748diff --git a/include/linux/mm.h b/include/linux/mm.h
64749index 280dae5..baea6c8 100644
64750--- a/include/linux/mm.h
64751+++ b/include/linux/mm.h
64752@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64753 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64754 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64755 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64756+
64757+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64758+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64759+#endif
64760+
64761 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64762
64763 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64764@@ -231,6 +236,7 @@ struct vm_operations_struct {
64765 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
64766 unsigned long size, pgoff_t pgoff);
64767 };
64768+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
64769
64770 struct mmu_gather;
64771 struct inode;
64772@@ -1039,34 +1045,6 @@ int set_page_dirty(struct page *page);
64773 int set_page_dirty_lock(struct page *page);
64774 int clear_page_dirty_for_io(struct page *page);
64775
64776-/* Is the vma a continuation of the stack vma above it? */
64777-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64778-{
64779- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64780-}
64781-
64782-static inline int stack_guard_page_start(struct vm_area_struct *vma,
64783- unsigned long addr)
64784-{
64785- return (vma->vm_flags & VM_GROWSDOWN) &&
64786- (vma->vm_start == addr) &&
64787- !vma_growsdown(vma->vm_prev, addr);
64788-}
64789-
64790-/* Is the vma a continuation of the stack vma below it? */
64791-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
64792-{
64793- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
64794-}
64795-
64796-static inline int stack_guard_page_end(struct vm_area_struct *vma,
64797- unsigned long addr)
64798-{
64799- return (vma->vm_flags & VM_GROWSUP) &&
64800- (vma->vm_end == addr) &&
64801- !vma_growsup(vma->vm_next, addr);
64802-}
64803-
64804 extern pid_t
64805 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
64806
64807@@ -1166,6 +1144,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
64808 }
64809 #endif
64810
64811+#ifdef CONFIG_MMU
64812+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
64813+#else
64814+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64815+{
64816+ return __pgprot(0);
64817+}
64818+#endif
64819+
64820 int vma_wants_writenotify(struct vm_area_struct *vma);
64821
64822 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
64823@@ -1184,8 +1171,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
64824 {
64825 return 0;
64826 }
64827+
64828+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
64829+ unsigned long address)
64830+{
64831+ return 0;
64832+}
64833 #else
64834 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64835+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64836 #endif
64837
64838 #ifdef __PAGETABLE_PMD_FOLDED
64839@@ -1194,8 +1188,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
64840 {
64841 return 0;
64842 }
64843+
64844+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
64845+ unsigned long address)
64846+{
64847+ return 0;
64848+}
64849 #else
64850 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
64851+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
64852 #endif
64853
64854 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
64855@@ -1213,11 +1214,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
64856 NULL: pud_offset(pgd, address);
64857 }
64858
64859+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
64860+{
64861+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
64862+ NULL: pud_offset(pgd, address);
64863+}
64864+
64865 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
64866 {
64867 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
64868 NULL: pmd_offset(pud, address);
64869 }
64870+
64871+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
64872+{
64873+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
64874+ NULL: pmd_offset(pud, address);
64875+}
64876 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
64877
64878 #if USE_SPLIT_PTLOCKS
64879@@ -1447,6 +1460,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
64880 unsigned long, unsigned long,
64881 unsigned long, unsigned long);
64882 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
64883+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
64884
64885 /* These take the mm semaphore themselves */
64886 extern unsigned long vm_brk(unsigned long, unsigned long);
64887@@ -1510,6 +1524,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
64888 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
64889 struct vm_area_struct **pprev);
64890
64891+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
64892+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
64893+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
64894+
64895 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64896 NULL if none. Assume start_addr < end_addr. */
64897 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64898@@ -1538,15 +1556,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64899 return vma;
64900 }
64901
64902-#ifdef CONFIG_MMU
64903-pgprot_t vm_get_page_prot(unsigned long vm_flags);
64904-#else
64905-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
64906-{
64907- return __pgprot(0);
64908-}
64909-#endif
64910-
64911 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
64912 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
64913 unsigned long pfn, unsigned long size, pgprot_t);
64914@@ -1652,7 +1661,7 @@ extern int unpoison_memory(unsigned long pfn);
64915 extern int sysctl_memory_failure_early_kill;
64916 extern int sysctl_memory_failure_recovery;
64917 extern void shake_page(struct page *p, int access);
64918-extern atomic_long_t mce_bad_pages;
64919+extern atomic_long_unchecked_t mce_bad_pages;
64920 extern int soft_offline_page(struct page *page, int flags);
64921
64922 extern void dump_page(struct page *page);
64923@@ -1683,5 +1692,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64924 static inline bool page_is_guard(struct page *page) { return false; }
64925 #endif /* CONFIG_DEBUG_PAGEALLOC */
64926
64927+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64928+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64929+#else
64930+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64931+#endif
64932+
64933 #endif /* __KERNEL__ */
64934 #endif /* _LINUX_MM_H */
64935diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
64936index 31f8a3a..499f1db 100644
64937--- a/include/linux/mm_types.h
64938+++ b/include/linux/mm_types.h
64939@@ -275,6 +275,8 @@ struct vm_area_struct {
64940 #ifdef CONFIG_NUMA
64941 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
64942 #endif
64943+
64944+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
64945 };
64946
64947 struct core_thread {
64948@@ -348,7 +350,7 @@ struct mm_struct {
64949 unsigned long def_flags;
64950 unsigned long nr_ptes; /* Page table pages */
64951 unsigned long start_code, end_code, start_data, end_data;
64952- unsigned long start_brk, brk, start_stack;
64953+ unsigned long brk_gap, start_brk, brk, start_stack;
64954 unsigned long arg_start, arg_end, env_start, env_end;
64955
64956 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
64957@@ -399,6 +401,24 @@ struct mm_struct {
64958 struct cpumask cpumask_allocation;
64959 #endif
64960 struct uprobes_state uprobes_state;
64961+
64962+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64963+ unsigned long pax_flags;
64964+#endif
64965+
64966+#ifdef CONFIG_PAX_DLRESOLVE
64967+ unsigned long call_dl_resolve;
64968+#endif
64969+
64970+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
64971+ unsigned long call_syscall;
64972+#endif
64973+
64974+#ifdef CONFIG_PAX_ASLR
64975+ unsigned long delta_mmap; /* randomized offset */
64976+ unsigned long delta_stack; /* randomized offset */
64977+#endif
64978+
64979 };
64980
64981 static inline void mm_init_cpumask(struct mm_struct *mm)
64982diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
64983index c5d5278..f0b68c8 100644
64984--- a/include/linux/mmiotrace.h
64985+++ b/include/linux/mmiotrace.h
64986@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
64987 /* Called from ioremap.c */
64988 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
64989 void __iomem *addr);
64990-extern void mmiotrace_iounmap(volatile void __iomem *addr);
64991+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
64992
64993 /* For anyone to insert markers. Remember trailing newline. */
64994 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
64995@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
64996 {
64997 }
64998
64999-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65000+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65001 {
65002 }
65003
65004diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65005index a23923b..073fee4 100644
65006--- a/include/linux/mmzone.h
65007+++ b/include/linux/mmzone.h
65008@@ -421,7 +421,7 @@ struct zone {
65009 unsigned long flags; /* zone flags, see below */
65010
65011 /* Zone statistics */
65012- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65013+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65014
65015 /*
65016 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65017diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65018index fed3def..7cc3f93 100644
65019--- a/include/linux/mod_devicetable.h
65020+++ b/include/linux/mod_devicetable.h
65021@@ -12,7 +12,7 @@
65022 typedef unsigned long kernel_ulong_t;
65023 #endif
65024
65025-#define PCI_ANY_ID (~0)
65026+#define PCI_ANY_ID ((__u16)~0)
65027
65028 struct pci_device_id {
65029 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65030@@ -139,7 +139,7 @@ struct usb_device_id {
65031 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65032 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65033
65034-#define HID_ANY_ID (~0)
65035+#define HID_ANY_ID (~0U)
65036 #define HID_BUS_ANY 0xffff
65037 #define HID_GROUP_ANY 0x0000
65038
65039diff --git a/include/linux/module.h b/include/linux/module.h
65040index 1375ee3..d631af0 100644
65041--- a/include/linux/module.h
65042+++ b/include/linux/module.h
65043@@ -17,9 +17,11 @@
65044 #include <linux/moduleparam.h>
65045 #include <linux/tracepoint.h>
65046 #include <linux/export.h>
65047+#include <linux/fs.h>
65048
65049 #include <linux/percpu.h>
65050 #include <asm/module.h>
65051+#include <asm/pgtable.h>
65052
65053 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65054 #define MODULE_SIG_STRING "~Module signature appended~\n"
65055@@ -281,19 +283,16 @@ struct module
65056 int (*init)(void);
65057
65058 /* If this is non-NULL, vfree after init() returns */
65059- void *module_init;
65060+ void *module_init_rx, *module_init_rw;
65061
65062 /* Here is the actual code + data, vfree'd on unload. */
65063- void *module_core;
65064+ void *module_core_rx, *module_core_rw;
65065
65066 /* Here are the sizes of the init and core sections */
65067- unsigned int init_size, core_size;
65068+ unsigned int init_size_rw, core_size_rw;
65069
65070 /* The size of the executable code in each section. */
65071- unsigned int init_text_size, core_text_size;
65072-
65073- /* Size of RO sections of the module (text+rodata) */
65074- unsigned int init_ro_size, core_ro_size;
65075+ unsigned int init_size_rx, core_size_rx;
65076
65077 /* Arch-specific module values */
65078 struct mod_arch_specific arch;
65079@@ -349,6 +348,10 @@ struct module
65080 #ifdef CONFIG_EVENT_TRACING
65081 struct ftrace_event_call **trace_events;
65082 unsigned int num_trace_events;
65083+ struct file_operations trace_id;
65084+ struct file_operations trace_enable;
65085+ struct file_operations trace_format;
65086+ struct file_operations trace_filter;
65087 #endif
65088 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65089 unsigned int num_ftrace_callsites;
65090@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65091 bool is_module_percpu_address(unsigned long addr);
65092 bool is_module_text_address(unsigned long addr);
65093
65094+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65095+{
65096+
65097+#ifdef CONFIG_PAX_KERNEXEC
65098+ if (ktla_ktva(addr) >= (unsigned long)start &&
65099+ ktla_ktva(addr) < (unsigned long)start + size)
65100+ return 1;
65101+#endif
65102+
65103+ return ((void *)addr >= start && (void *)addr < start + size);
65104+}
65105+
65106+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65107+{
65108+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65109+}
65110+
65111+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65112+{
65113+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65114+}
65115+
65116+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65117+{
65118+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65119+}
65120+
65121+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65122+{
65123+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65124+}
65125+
65126 static inline int within_module_core(unsigned long addr, struct module *mod)
65127 {
65128- return (unsigned long)mod->module_core <= addr &&
65129- addr < (unsigned long)mod->module_core + mod->core_size;
65130+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65131 }
65132
65133 static inline int within_module_init(unsigned long addr, struct module *mod)
65134 {
65135- return (unsigned long)mod->module_init <= addr &&
65136- addr < (unsigned long)mod->module_init + mod->init_size;
65137+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65138 }
65139
65140 /* Search for module by name: must hold module_mutex. */
65141diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65142index 560ca53..5ee8d73 100644
65143--- a/include/linux/moduleloader.h
65144+++ b/include/linux/moduleloader.h
65145@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65146
65147 /* Allocator used for allocating struct module, core sections and init
65148 sections. Returns NULL on failure. */
65149-void *module_alloc(unsigned long size);
65150+void *module_alloc(unsigned long size) __size_overflow(1);
65151+
65152+#ifdef CONFIG_PAX_KERNEXEC
65153+void *module_alloc_exec(unsigned long size) __size_overflow(1);
65154+#else
65155+#define module_alloc_exec(x) module_alloc(x)
65156+#endif
65157
65158 /* Free memory returned from module_alloc. */
65159 void module_free(struct module *mod, void *module_region);
65160
65161+#ifdef CONFIG_PAX_KERNEXEC
65162+void module_free_exec(struct module *mod, void *module_region);
65163+#else
65164+#define module_free_exec(x, y) module_free((x), (y))
65165+#endif
65166+
65167 /*
65168 * Apply the given relocation to the (simplified) ELF. Return -error
65169 * or 0.
65170@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65171 unsigned int relsec,
65172 struct module *me)
65173 {
65174+#ifdef CONFIG_MODULES
65175 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65176+#endif
65177 return -ENOEXEC;
65178 }
65179 #endif
65180@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65181 unsigned int relsec,
65182 struct module *me)
65183 {
65184+#ifdef CONFIG_MODULES
65185 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65186+#endif
65187 return -ENOEXEC;
65188 }
65189 #endif
65190diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65191index d6a5806..7c13347 100644
65192--- a/include/linux/moduleparam.h
65193+++ b/include/linux/moduleparam.h
65194@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65195 * @len is usually just sizeof(string).
65196 */
65197 #define module_param_string(name, string, len, perm) \
65198- static const struct kparam_string __param_string_##name \
65199+ static const struct kparam_string __param_string_##name __used \
65200 = { len, string }; \
65201 __module_param_call(MODULE_PARAM_PREFIX, name, \
65202 &param_ops_string, \
65203@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65204 */
65205 #define module_param_array_named(name, array, type, nump, perm) \
65206 param_check_##type(name, &(array)[0]); \
65207- static const struct kparam_array __param_arr_##name \
65208+ static const struct kparam_array __param_arr_##name __used \
65209 = { .max = ARRAY_SIZE(array), .num = nump, \
65210 .ops = &param_ops_##type, \
65211 .elemsize = sizeof(array[0]), .elem = array }; \
65212diff --git a/include/linux/namei.h b/include/linux/namei.h
65213index 4bf19d8..5268cea 100644
65214--- a/include/linux/namei.h
65215+++ b/include/linux/namei.h
65216@@ -18,7 +18,7 @@ struct nameidata {
65217 unsigned seq;
65218 int last_type;
65219 unsigned depth;
65220- char *saved_names[MAX_NESTED_LINKS + 1];
65221+ const char *saved_names[MAX_NESTED_LINKS + 1];
65222 };
65223
65224 /*
65225@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65226
65227 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65228
65229-static inline void nd_set_link(struct nameidata *nd, char *path)
65230+static inline void nd_set_link(struct nameidata *nd, const char *path)
65231 {
65232 nd->saved_names[nd->depth] = path;
65233 }
65234
65235-static inline char *nd_get_link(struct nameidata *nd)
65236+static inline const char *nd_get_link(const struct nameidata *nd)
65237 {
65238 return nd->saved_names[nd->depth];
65239 }
65240diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65241index 825fb7e..24cdd41 100644
65242--- a/include/linux/netdevice.h
65243+++ b/include/linux/netdevice.h
65244@@ -1002,6 +1002,7 @@ struct net_device_ops {
65245 struct net_device *dev,
65246 int idx);
65247 };
65248+typedef struct net_device_ops __no_const net_device_ops_no_const;
65249
65250 /*
65251 * The DEVICE structure.
65252@@ -1062,7 +1063,7 @@ struct net_device {
65253 int iflink;
65254
65255 struct net_device_stats stats;
65256- atomic_long_t rx_dropped; /* dropped packets by core network
65257+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65258 * Do not use this in drivers.
65259 */
65260
65261diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65262index 7958e84..ed74d7a 100644
65263--- a/include/linux/netfilter/ipset/ip_set.h
65264+++ b/include/linux/netfilter/ipset/ip_set.h
65265@@ -98,7 +98,7 @@ struct ip_set_type_variant {
65266 /* Return true if "b" set is the same as "a"
65267 * according to the create set parameters */
65268 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65269-};
65270+} __do_const;
65271
65272 /* The core set type structure */
65273 struct ip_set_type {
65274diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65275index 4966dde..7d8ce06 100644
65276--- a/include/linux/netfilter/nfnetlink.h
65277+++ b/include/linux/netfilter/nfnetlink.h
65278@@ -16,7 +16,7 @@ struct nfnl_callback {
65279 const struct nlattr * const cda[]);
65280 const struct nla_policy *policy; /* netlink attribute policy */
65281 const u_int16_t attr_count; /* number of nlattr's */
65282-};
65283+} __do_const;
65284
65285 struct nfnetlink_subsystem {
65286 const char *name;
65287diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65288new file mode 100644
65289index 0000000..33f4af8
65290--- /dev/null
65291+++ b/include/linux/netfilter/xt_gradm.h
65292@@ -0,0 +1,9 @@
65293+#ifndef _LINUX_NETFILTER_XT_GRADM_H
65294+#define _LINUX_NETFILTER_XT_GRADM_H 1
65295+
65296+struct xt_gradm_mtinfo {
65297+ __u16 flags;
65298+ __u16 invflags;
65299+};
65300+
65301+#endif
65302diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65303index d65746e..62e72c2 100644
65304--- a/include/linux/notifier.h
65305+++ b/include/linux/notifier.h
65306@@ -51,7 +51,8 @@ struct notifier_block {
65307 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65308 struct notifier_block __rcu *next;
65309 int priority;
65310-};
65311+} __do_const;
65312+typedef struct notifier_block __no_const notifier_block_no_const;
65313
65314 struct atomic_notifier_head {
65315 spinlock_t lock;
65316diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65317index a4c5624..79d6d88 100644
65318--- a/include/linux/oprofile.h
65319+++ b/include/linux/oprofile.h
65320@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65321 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65322 char const * name, ulong * val);
65323
65324-/** Create a file for read-only access to an atomic_t. */
65325+/** Create a file for read-only access to an atomic_unchecked_t. */
65326 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65327- char const * name, atomic_t * val);
65328+ char const * name, atomic_unchecked_t * val);
65329
65330 /** create a directory */
65331 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65332diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65333index 6bfb2faa..1204767 100644
65334--- a/include/linux/perf_event.h
65335+++ b/include/linux/perf_event.h
65336@@ -328,8 +328,8 @@ struct perf_event {
65337
65338 enum perf_event_active_state state;
65339 unsigned int attach_state;
65340- local64_t count;
65341- atomic64_t child_count;
65342+ local64_t count; /* PaX: fix it one day */
65343+ atomic64_unchecked_t child_count;
65344
65345 /*
65346 * These are the total time in nanoseconds that the event
65347@@ -380,8 +380,8 @@ struct perf_event {
65348 * These accumulate total time (in nanoseconds) that children
65349 * events have been enabled and running, respectively.
65350 */
65351- atomic64_t child_total_time_enabled;
65352- atomic64_t child_total_time_running;
65353+ atomic64_unchecked_t child_total_time_enabled;
65354+ atomic64_unchecked_t child_total_time_running;
65355
65356 /*
65357 * Protect attach/detach and child_list:
65358diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65359index ad1a427..6419649 100644
65360--- a/include/linux/pipe_fs_i.h
65361+++ b/include/linux/pipe_fs_i.h
65362@@ -45,9 +45,9 @@ struct pipe_buffer {
65363 struct pipe_inode_info {
65364 wait_queue_head_t wait;
65365 unsigned int nrbufs, curbuf, buffers;
65366- unsigned int readers;
65367- unsigned int writers;
65368- unsigned int waiting_writers;
65369+ atomic_t readers;
65370+ atomic_t writers;
65371+ atomic_t waiting_writers;
65372 unsigned int r_counter;
65373 unsigned int w_counter;
65374 struct page *tmp_page;
65375diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65376index 5f28cae..3d23723 100644
65377--- a/include/linux/platform_data/usb-ehci-s5p.h
65378+++ b/include/linux/platform_data/usb-ehci-s5p.h
65379@@ -14,7 +14,7 @@
65380 struct s5p_ehci_platdata {
65381 int (*phy_init)(struct platform_device *pdev, int type);
65382 int (*phy_exit)(struct platform_device *pdev, int type);
65383-};
65384+} __no_const;
65385
65386 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65387
65388diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65389index f271860..6b3bec5 100644
65390--- a/include/linux/pm_runtime.h
65391+++ b/include/linux/pm_runtime.h
65392@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65393
65394 static inline void pm_runtime_mark_last_busy(struct device *dev)
65395 {
65396- ACCESS_ONCE(dev->power.last_busy) = jiffies;
65397+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65398 }
65399
65400 #else /* !CONFIG_PM_RUNTIME */
65401diff --git a/include/linux/poison.h b/include/linux/poison.h
65402index 2110a81..13a11bb 100644
65403--- a/include/linux/poison.h
65404+++ b/include/linux/poison.h
65405@@ -19,8 +19,8 @@
65406 * under normal circumstances, used to verify that nobody uses
65407 * non-initialized list entries.
65408 */
65409-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65410-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65411+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65412+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65413
65414 /********** include/linux/timer.h **********/
65415 /*
65416diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65417index 4a496eb..d9c5659 100644
65418--- a/include/linux/power/smartreflex.h
65419+++ b/include/linux/power/smartreflex.h
65420@@ -238,7 +238,7 @@ struct omap_sr_class_data {
65421 int (*notify)(struct omap_sr *sr, u32 status);
65422 u8 notify_flags;
65423 u8 class_type;
65424-};
65425+} __do_const;
65426
65427 /**
65428 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65429diff --git a/include/linux/printk.h b/include/linux/printk.h
65430index 9afc01e..92c32e8 100644
65431--- a/include/linux/printk.h
65432+++ b/include/linux/printk.h
65433@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65434 extern int printk_needs_cpu(int cpu);
65435 extern void printk_tick(void);
65436
65437+extern int kptr_restrict;
65438+
65439 #ifdef CONFIG_PRINTK
65440 asmlinkage __printf(5, 0)
65441 int vprintk_emit(int facility, int level,
65442@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65443
65444 extern int printk_delay_msec;
65445 extern int dmesg_restrict;
65446-extern int kptr_restrict;
65447
65448 void log_buf_kexec_setup(void);
65449 void __init setup_log_buf(int early);
65450diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65451index 3fd2e87..75db910 100644
65452--- a/include/linux/proc_fs.h
65453+++ b/include/linux/proc_fs.h
65454@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65455 return proc_create_data(name, mode, parent, proc_fops, NULL);
65456 }
65457
65458+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65459+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65460+{
65461+#ifdef CONFIG_GRKERNSEC_PROC_USER
65462+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65463+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65464+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65465+#else
65466+ return proc_create_data(name, mode, parent, proc_fops, NULL);
65467+#endif
65468+}
65469+
65470 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65471 umode_t mode, struct proc_dir_entry *base,
65472 read_proc_t *read_proc, void * data)
65473diff --git a/include/linux/random.h b/include/linux/random.h
65474index 6330ed4..419c6c3 100644
65475--- a/include/linux/random.h
65476+++ b/include/linux/random.h
65477@@ -30,12 +30,17 @@ void srandom32(u32 seed);
65478
65479 u32 prandom32(struct rnd_state *);
65480
65481+static inline unsigned long pax_get_random_long(void)
65482+{
65483+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65484+}
65485+
65486 /*
65487 * Handle minimum values for seeds
65488 */
65489 static inline u32 __seed(u32 x, u32 m)
65490 {
65491- return (x < m) ? x + m : x;
65492+ return (x <= m) ? x + m + 1 : x;
65493 }
65494
65495 /**
65496diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65497index 23b3630..e1bc12b 100644
65498--- a/include/linux/reboot.h
65499+++ b/include/linux/reboot.h
65500@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65501 * Architecture-specific implementations of sys_reboot commands.
65502 */
65503
65504-extern void machine_restart(char *cmd);
65505-extern void machine_halt(void);
65506-extern void machine_power_off(void);
65507+extern void machine_restart(char *cmd) __noreturn;
65508+extern void machine_halt(void) __noreturn;
65509+extern void machine_power_off(void) __noreturn;
65510
65511 extern void machine_shutdown(void);
65512 struct pt_regs;
65513@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65514 */
65515
65516 extern void kernel_restart_prepare(char *cmd);
65517-extern void kernel_restart(char *cmd);
65518-extern void kernel_halt(void);
65519-extern void kernel_power_off(void);
65520+extern void kernel_restart(char *cmd) __noreturn;
65521+extern void kernel_halt(void) __noreturn;
65522+extern void kernel_power_off(void) __noreturn;
65523
65524 extern int C_A_D; /* for sysctl */
65525 void ctrl_alt_del(void);
65526@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65527 * Emergency restart, callable from an interrupt handler.
65528 */
65529
65530-extern void emergency_restart(void);
65531+extern void emergency_restart(void) __noreturn;
65532 #include <asm/emergency-restart.h>
65533
65534 #endif /* _LINUX_REBOOT_H */
65535diff --git a/include/linux/regset.h b/include/linux/regset.h
65536index 8e0c9fe..ac4d221 100644
65537--- a/include/linux/regset.h
65538+++ b/include/linux/regset.h
65539@@ -161,7 +161,8 @@ struct user_regset {
65540 unsigned int align;
65541 unsigned int bias;
65542 unsigned int core_note_type;
65543-};
65544+} __do_const;
65545+typedef struct user_regset __no_const user_regset_no_const;
65546
65547 /**
65548 * struct user_regset_view - available regsets
65549diff --git a/include/linux/relay.h b/include/linux/relay.h
65550index 91cacc3..b55ff74 100644
65551--- a/include/linux/relay.h
65552+++ b/include/linux/relay.h
65553@@ -160,7 +160,7 @@ struct rchan_callbacks
65554 * The callback should return 0 if successful, negative if not.
65555 */
65556 int (*remove_buf_file)(struct dentry *dentry);
65557-};
65558+} __no_const;
65559
65560 /*
65561 * CONFIG_RELAY kernel API, kernel/relay.c
65562diff --git a/include/linux/rio.h b/include/linux/rio.h
65563index a3e7842..d973ca6 100644
65564--- a/include/linux/rio.h
65565+++ b/include/linux/rio.h
65566@@ -339,7 +339,7 @@ struct rio_ops {
65567 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65568 u64 rstart, u32 size, u32 flags);
65569 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65570-};
65571+} __no_const;
65572
65573 #define RIO_RESOURCE_MEM 0x00000100
65574 #define RIO_RESOURCE_DOORBELL 0x00000200
65575diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65576index bfe1f47..6a33ee3 100644
65577--- a/include/linux/rmap.h
65578+++ b/include/linux/rmap.h
65579@@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65580 void anon_vma_init(void); /* create anon_vma_cachep */
65581 int anon_vma_prepare(struct vm_area_struct *);
65582 void unlink_anon_vmas(struct vm_area_struct *);
65583-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65584-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65585+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65586+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65587
65588 static inline void anon_vma_merge(struct vm_area_struct *vma,
65589 struct vm_area_struct *next)
65590diff --git a/include/linux/sched.h b/include/linux/sched.h
65591index 3e63925..6c93b17 100644
65592--- a/include/linux/sched.h
65593+++ b/include/linux/sched.h
65594@@ -61,6 +61,7 @@ struct bio_list;
65595 struct fs_struct;
65596 struct perf_event_context;
65597 struct blk_plug;
65598+struct linux_binprm;
65599
65600 /*
65601 * List of flags we want to share for kernel threads,
65602@@ -344,10 +345,23 @@ struct user_namespace;
65603 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65604
65605 extern int sysctl_max_map_count;
65606+extern unsigned long sysctl_heap_stack_gap;
65607
65608 #include <linux/aio.h>
65609
65610 #ifdef CONFIG_MMU
65611+
65612+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65613+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65614+#else
65615+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65616+{
65617+ return 0;
65618+}
65619+#endif
65620+
65621+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65622+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65623 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65624 extern unsigned long
65625 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65626@@ -614,6 +628,17 @@ struct signal_struct {
65627 #ifdef CONFIG_TASKSTATS
65628 struct taskstats *stats;
65629 #endif
65630+
65631+#ifdef CONFIG_GRKERNSEC
65632+ u32 curr_ip;
65633+ u32 saved_ip;
65634+ u32 gr_saddr;
65635+ u32 gr_daddr;
65636+ u16 gr_sport;
65637+ u16 gr_dport;
65638+ u8 used_accept:1;
65639+#endif
65640+
65641 #ifdef CONFIG_AUDIT
65642 unsigned audit_tty;
65643 struct tty_audit_buf *tty_audit_buf;
65644@@ -691,6 +716,11 @@ struct user_struct {
65645 struct key *session_keyring; /* UID's default session keyring */
65646 #endif
65647
65648+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65649+ unsigned int banned;
65650+ unsigned long ban_expires;
65651+#endif
65652+
65653 /* Hash table maintenance information */
65654 struct hlist_node uidhash_node;
65655 kuid_t uid;
65656@@ -1312,8 +1342,8 @@ struct task_struct {
65657 struct list_head thread_group;
65658
65659 struct completion *vfork_done; /* for vfork() */
65660- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65661- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65662+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65663+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65664
65665 cputime_t utime, stime, utimescaled, stimescaled;
65666 cputime_t gtime;
65667@@ -1329,11 +1359,6 @@ struct task_struct {
65668 struct task_cputime cputime_expires;
65669 struct list_head cpu_timers[3];
65670
65671-/* process credentials */
65672- const struct cred __rcu *real_cred; /* objective and real subjective task
65673- * credentials (COW) */
65674- const struct cred __rcu *cred; /* effective (overridable) subjective task
65675- * credentials (COW) */
65676 char comm[TASK_COMM_LEN]; /* executable name excluding path
65677 - access with [gs]et_task_comm (which lock
65678 it with task_lock())
65679@@ -1350,6 +1375,10 @@ struct task_struct {
65680 #endif
65681 /* CPU-specific state of this task */
65682 struct thread_struct thread;
65683+/* thread_info moved to task_struct */
65684+#ifdef CONFIG_X86
65685+ struct thread_info tinfo;
65686+#endif
65687 /* filesystem information */
65688 struct fs_struct *fs;
65689 /* open file information */
65690@@ -1423,6 +1452,10 @@ struct task_struct {
65691 gfp_t lockdep_reclaim_gfp;
65692 #endif
65693
65694+/* process credentials */
65695+ const struct cred __rcu *real_cred; /* objective and real subjective task
65696+ * credentials (COW) */
65697+
65698 /* journalling filesystem info */
65699 void *journal_info;
65700
65701@@ -1461,6 +1494,10 @@ struct task_struct {
65702 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65703 struct list_head cg_list;
65704 #endif
65705+
65706+ const struct cred __rcu *cred; /* effective (overridable) subjective task
65707+ * credentials (COW) */
65708+
65709 #ifdef CONFIG_FUTEX
65710 struct robust_list_head __user *robust_list;
65711 #ifdef CONFIG_COMPAT
65712@@ -1548,8 +1585,74 @@ struct task_struct {
65713 #ifdef CONFIG_UPROBES
65714 struct uprobe_task *utask;
65715 #endif
65716+
65717+#ifdef CONFIG_GRKERNSEC
65718+ /* grsecurity */
65719+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65720+ u64 exec_id;
65721+#endif
65722+#ifdef CONFIG_GRKERNSEC_SETXID
65723+ const struct cred *delayed_cred;
65724+#endif
65725+ struct dentry *gr_chroot_dentry;
65726+ struct acl_subject_label *acl;
65727+ struct acl_role_label *role;
65728+ struct file *exec_file;
65729+ unsigned long brute_expires;
65730+ u16 acl_role_id;
65731+ /* is this the task that authenticated to the special role */
65732+ u8 acl_sp_role;
65733+ u8 is_writable;
65734+ u8 brute;
65735+ u8 gr_is_chrooted;
65736+#endif
65737+
65738 };
65739
65740+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
65741+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
65742+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
65743+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
65744+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
65745+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
65746+
65747+#ifdef CONFIG_PAX_SOFTMODE
65748+extern int pax_softmode;
65749+#endif
65750+
65751+extern int pax_check_flags(unsigned long *);
65752+
65753+/* if tsk != current then task_lock must be held on it */
65754+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65755+static inline unsigned long pax_get_flags(struct task_struct *tsk)
65756+{
65757+ if (likely(tsk->mm))
65758+ return tsk->mm->pax_flags;
65759+ else
65760+ return 0UL;
65761+}
65762+
65763+/* if tsk != current then task_lock must be held on it */
65764+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
65765+{
65766+ if (likely(tsk->mm)) {
65767+ tsk->mm->pax_flags = flags;
65768+ return 0;
65769+ }
65770+ return -EINVAL;
65771+}
65772+#endif
65773+
65774+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65775+extern void pax_set_initial_flags(struct linux_binprm *bprm);
65776+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
65777+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
65778+#endif
65779+
65780+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
65781+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
65782+extern void pax_report_refcount_overflow(struct pt_regs *regs);
65783+
65784 /* Future-safe accessor for struct task_struct's cpus_allowed. */
65785 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
65786
65787@@ -2092,7 +2195,9 @@ void yield(void);
65788 extern struct exec_domain default_exec_domain;
65789
65790 union thread_union {
65791+#ifndef CONFIG_X86
65792 struct thread_info thread_info;
65793+#endif
65794 unsigned long stack[THREAD_SIZE/sizeof(long)];
65795 };
65796
65797@@ -2125,6 +2230,7 @@ extern struct pid_namespace init_pid_ns;
65798 */
65799
65800 extern struct task_struct *find_task_by_vpid(pid_t nr);
65801+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
65802 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
65803 struct pid_namespace *ns);
65804
65805@@ -2281,7 +2387,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
65806 extern void exit_itimers(struct signal_struct *);
65807 extern void flush_itimer_signals(void);
65808
65809-extern void do_group_exit(int);
65810+extern __noreturn void do_group_exit(int);
65811
65812 extern void daemonize(const char *, ...);
65813 extern int allow_signal(int);
65814@@ -2485,9 +2591,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
65815
65816 #endif
65817
65818-static inline int object_is_on_stack(void *obj)
65819+static inline int object_starts_on_stack(void *obj)
65820 {
65821- void *stack = task_stack_page(current);
65822+ const void *stack = task_stack_page(current);
65823
65824 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
65825 }
65826diff --git a/include/linux/security.h b/include/linux/security.h
65827index 05e88bd..5cda002 100644
65828--- a/include/linux/security.h
65829+++ b/include/linux/security.h
65830@@ -26,6 +26,7 @@
65831 #include <linux/capability.h>
65832 #include <linux/slab.h>
65833 #include <linux/err.h>
65834+#include <linux/grsecurity.h>
65835
65836 struct linux_binprm;
65837 struct cred;
65838diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
65839index 68a04a3..866e6a1 100644
65840--- a/include/linux/seq_file.h
65841+++ b/include/linux/seq_file.h
65842@@ -26,6 +26,9 @@ struct seq_file {
65843 struct mutex lock;
65844 const struct seq_operations *op;
65845 int poll_event;
65846+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65847+ u64 exec_id;
65848+#endif
65849 #ifdef CONFIG_USER_NS
65850 struct user_namespace *user_ns;
65851 #endif
65852@@ -38,6 +41,7 @@ struct seq_operations {
65853 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
65854 int (*show) (struct seq_file *m, void *v);
65855 };
65856+typedef struct seq_operations __no_const seq_operations_no_const;
65857
65858 #define SEQ_SKIP 1
65859
65860diff --git a/include/linux/shm.h b/include/linux/shm.h
65861index bcf8a6a..4d0af77 100644
65862--- a/include/linux/shm.h
65863+++ b/include/linux/shm.h
65864@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
65865
65866 /* The task created the shm object. NULL if the task is dead. */
65867 struct task_struct *shm_creator;
65868+#ifdef CONFIG_GRKERNSEC
65869+ time_t shm_createtime;
65870+ pid_t shm_lapid;
65871+#endif
65872 };
65873
65874 /* shm_mode upper byte flags */
65875diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
65876index 6a2c34e..a1f320f 100644
65877--- a/include/linux/skbuff.h
65878+++ b/include/linux/skbuff.h
65879@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
65880 extern struct sk_buff *__alloc_skb(unsigned int size,
65881 gfp_t priority, int flags, int node);
65882 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
65883-static inline struct sk_buff *alloc_skb(unsigned int size,
65884+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
65885 gfp_t priority)
65886 {
65887 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
65888@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
65889 */
65890 static inline int skb_queue_empty(const struct sk_buff_head *list)
65891 {
65892- return list->next == (struct sk_buff *)list;
65893+ return list->next == (const struct sk_buff *)list;
65894 }
65895
65896 /**
65897@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
65898 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65899 const struct sk_buff *skb)
65900 {
65901- return skb->next == (struct sk_buff *)list;
65902+ return skb->next == (const struct sk_buff *)list;
65903 }
65904
65905 /**
65906@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65907 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
65908 const struct sk_buff *skb)
65909 {
65910- return skb->prev == (struct sk_buff *)list;
65911+ return skb->prev == (const struct sk_buff *)list;
65912 }
65913
65914 /**
65915@@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
65916 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
65917 */
65918 #ifndef NET_SKB_PAD
65919-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
65920+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
65921 #endif
65922
65923 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
65924@@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
65925 int noblock, int *err);
65926 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
65927 struct poll_table_struct *wait);
65928-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
65929+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
65930 int offset, struct iovec *to,
65931 int size);
65932 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
65933diff --git a/include/linux/slab.h b/include/linux/slab.h
65934index 83d1a14..e23d723 100644
65935--- a/include/linux/slab.h
65936+++ b/include/linux/slab.h
65937@@ -11,12 +11,20 @@
65938
65939 #include <linux/gfp.h>
65940 #include <linux/types.h>
65941+#include <linux/err.h>
65942
65943 /*
65944 * Flags to pass to kmem_cache_create().
65945 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
65946 */
65947 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
65948+
65949+#ifdef CONFIG_PAX_USERCOPY_SLABS
65950+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
65951+#else
65952+#define SLAB_USERCOPY 0x00000000UL
65953+#endif
65954+
65955 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
65956 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
65957 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
65958@@ -87,10 +95,13 @@
65959 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
65960 * Both make kfree a no-op.
65961 */
65962-#define ZERO_SIZE_PTR ((void *)16)
65963+#define ZERO_SIZE_PTR \
65964+({ \
65965+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
65966+ (void *)(-MAX_ERRNO-1L); \
65967+})
65968
65969-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
65970- (unsigned long)ZERO_SIZE_PTR)
65971+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
65972
65973 /*
65974 * Common fields provided in kmem_cache by all slab allocators
65975@@ -110,7 +121,7 @@ struct kmem_cache {
65976 unsigned int align; /* Alignment as calculated */
65977 unsigned long flags; /* Active flags on the slab */
65978 const char *name; /* Slab name for sysfs */
65979- int refcount; /* Use counter */
65980+ atomic_t refcount; /* Use counter */
65981 void (*ctor)(void *); /* Called on object slot creation */
65982 struct list_head list; /* List of all slab caches on the system */
65983 };
65984@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
65985 void kfree(const void *);
65986 void kzfree(const void *);
65987 size_t ksize(const void *);
65988+const char *check_heap_object(const void *ptr, unsigned long n);
65989+bool is_usercopy_object(const void *ptr);
65990
65991 /*
65992 * Allocator specific definitions. These are mainly used to establish optimized
65993@@ -264,8 +277,18 @@ size_t ksize(const void *);
65994 * for general use, and so are not documented here. For a full list of
65995 * potential flags, always refer to linux/gfp.h.
65996 */
65997+
65998+extern void kmalloc_array_error(void)
65999+#if defined(CONFIG_GCOV_KERNEL) && defined(CONFIG_PAX_SIZE_OVERFLOW)
66000+__compiletime_warning("kmalloc_array called with swapped arguments?");
66001+#else
66002+__compiletime_error("kmalloc_array called with swapped arguments?");
66003+#endif
66004+
66005 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
66006 {
66007+ if (__builtin_constant_p(n) && !__builtin_constant_p(size))
66008+ kmalloc_array_error();
66009 if (size != 0 && n > SIZE_MAX / size)
66010 return NULL;
66011 return __kmalloc(n * size, flags);
66012@@ -323,7 +346,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66013 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66014 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66015 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66016-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66017+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66018 #define kmalloc_track_caller(size, flags) \
66019 __kmalloc_track_caller(size, flags, _RET_IP_)
66020 #else
66021@@ -343,7 +366,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66022 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66023 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66024 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66025-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66026+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66027 #define kmalloc_node_track_caller(size, flags, node) \
66028 __kmalloc_node_track_caller(size, flags, node, \
66029 _RET_IP_)
66030diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66031index cc290f0..0ba60931 100644
66032--- a/include/linux/slab_def.h
66033+++ b/include/linux/slab_def.h
66034@@ -52,7 +52,7 @@ struct kmem_cache {
66035 /* 4) cache creation/removal */
66036 const char *name;
66037 struct list_head list;
66038- int refcount;
66039+ atomic_t refcount;
66040 int object_size;
66041 int align;
66042
66043@@ -68,10 +68,10 @@ struct kmem_cache {
66044 unsigned long node_allocs;
66045 unsigned long node_frees;
66046 unsigned long node_overflow;
66047- atomic_t allochit;
66048- atomic_t allocmiss;
66049- atomic_t freehit;
66050- atomic_t freemiss;
66051+ atomic_unchecked_t allochit;
66052+ atomic_unchecked_t allocmiss;
66053+ atomic_unchecked_t freehit;
66054+ atomic_unchecked_t freemiss;
66055
66056 /*
66057 * If debugging is enabled, then the allocator can add additional
66058@@ -104,11 +104,16 @@ struct cache_sizes {
66059 #ifdef CONFIG_ZONE_DMA
66060 struct kmem_cache *cs_dmacachep;
66061 #endif
66062+
66063+#ifdef CONFIG_PAX_USERCOPY_SLABS
66064+ struct kmem_cache *cs_usercopycachep;
66065+#endif
66066+
66067 };
66068 extern struct cache_sizes malloc_sizes[];
66069
66070 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66071-void *__kmalloc(size_t size, gfp_t flags);
66072+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66073
66074 #ifdef CONFIG_TRACING
66075 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66076@@ -145,6 +150,13 @@ found:
66077 cachep = malloc_sizes[i].cs_dmacachep;
66078 else
66079 #endif
66080+
66081+#ifdef CONFIG_PAX_USERCOPY_SLABS
66082+ if (flags & GFP_USERCOPY)
66083+ cachep = malloc_sizes[i].cs_usercopycachep;
66084+ else
66085+#endif
66086+
66087 cachep = malloc_sizes[i].cs_cachep;
66088
66089 ret = kmem_cache_alloc_trace(cachep, flags, size);
66090@@ -155,7 +167,7 @@ found:
66091 }
66092
66093 #ifdef CONFIG_NUMA
66094-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66095+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66096 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66097
66098 #ifdef CONFIG_TRACING
66099@@ -198,6 +210,13 @@ found:
66100 cachep = malloc_sizes[i].cs_dmacachep;
66101 else
66102 #endif
66103+
66104+#ifdef CONFIG_PAX_USERCOPY_SLABS
66105+ if (flags & GFP_USERCOPY)
66106+ cachep = malloc_sizes[i].cs_usercopycachep;
66107+ else
66108+#endif
66109+
66110 cachep = malloc_sizes[i].cs_cachep;
66111
66112 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66113diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66114index f28e14a..7831211 100644
66115--- a/include/linux/slob_def.h
66116+++ b/include/linux/slob_def.h
66117@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66118 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66119 }
66120
66121-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66122+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66123
66124 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66125 {
66126@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66127 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66128 }
66129
66130-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66131+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66132 {
66133 return kmalloc(size, flags);
66134 }
66135diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66136index df448ad..b99e7f6 100644
66137--- a/include/linux/slub_def.h
66138+++ b/include/linux/slub_def.h
66139@@ -91,7 +91,7 @@ struct kmem_cache {
66140 struct kmem_cache_order_objects max;
66141 struct kmem_cache_order_objects min;
66142 gfp_t allocflags; /* gfp flags to use on each alloc */
66143- int refcount; /* Refcount for slab cache destroy */
66144+ atomic_t refcount; /* Refcount for slab cache destroy */
66145 void (*ctor)(void *);
66146 int inuse; /* Offset to metadata */
66147 int align; /* Alignment */
66148@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66149 * Sorry that the following has to be that ugly but some versions of GCC
66150 * have trouble with constant propagation and loops.
66151 */
66152-static __always_inline int kmalloc_index(size_t size)
66153+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66154 {
66155 if (!size)
66156 return 0;
66157@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66158 }
66159
66160 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66161-void *__kmalloc(size_t size, gfp_t flags);
66162+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66163
66164 static __always_inline void *
66165 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66166@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66167 }
66168 #endif
66169
66170-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66171+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66172 {
66173 unsigned int order = get_order(size);
66174 return kmalloc_order_trace(size, flags, order);
66175@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66176 }
66177
66178 #ifdef CONFIG_NUMA
66179-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66180+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66181 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66182
66183 #ifdef CONFIG_TRACING
66184diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66185index 680f9a3..f13aeb0 100644
66186--- a/include/linux/sonet.h
66187+++ b/include/linux/sonet.h
66188@@ -7,7 +7,7 @@
66189 #include <uapi/linux/sonet.h>
66190
66191 struct k_sonet_stats {
66192-#define __HANDLE_ITEM(i) atomic_t i
66193+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66194 __SONET_ITEMS
66195 #undef __HANDLE_ITEM
66196 };
66197diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66198index 34206b8..f019e06 100644
66199--- a/include/linux/sunrpc/clnt.h
66200+++ b/include/linux/sunrpc/clnt.h
66201@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66202 {
66203 switch (sap->sa_family) {
66204 case AF_INET:
66205- return ntohs(((struct sockaddr_in *)sap)->sin_port);
66206+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66207 case AF_INET6:
66208- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66209+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66210 }
66211 return 0;
66212 }
66213@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66214 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66215 const struct sockaddr *src)
66216 {
66217- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66218+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66219 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66220
66221 dsin->sin_family = ssin->sin_family;
66222@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66223 if (sa->sa_family != AF_INET6)
66224 return 0;
66225
66226- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66227+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66228 }
66229
66230 #endif /* __KERNEL__ */
66231diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66232index 0b8e3e6..33e0a01 100644
66233--- a/include/linux/sunrpc/svc_rdma.h
66234+++ b/include/linux/sunrpc/svc_rdma.h
66235@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66236 extern unsigned int svcrdma_max_requests;
66237 extern unsigned int svcrdma_max_req_size;
66238
66239-extern atomic_t rdma_stat_recv;
66240-extern atomic_t rdma_stat_read;
66241-extern atomic_t rdma_stat_write;
66242-extern atomic_t rdma_stat_sq_starve;
66243-extern atomic_t rdma_stat_rq_starve;
66244-extern atomic_t rdma_stat_rq_poll;
66245-extern atomic_t rdma_stat_rq_prod;
66246-extern atomic_t rdma_stat_sq_poll;
66247-extern atomic_t rdma_stat_sq_prod;
66248+extern atomic_unchecked_t rdma_stat_recv;
66249+extern atomic_unchecked_t rdma_stat_read;
66250+extern atomic_unchecked_t rdma_stat_write;
66251+extern atomic_unchecked_t rdma_stat_sq_starve;
66252+extern atomic_unchecked_t rdma_stat_rq_starve;
66253+extern atomic_unchecked_t rdma_stat_rq_poll;
66254+extern atomic_unchecked_t rdma_stat_rq_prod;
66255+extern atomic_unchecked_t rdma_stat_sq_poll;
66256+extern atomic_unchecked_t rdma_stat_sq_prod;
66257
66258 #define RPCRDMA_VERSION 1
66259
66260diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66261index cd844a6..3ca3592 100644
66262--- a/include/linux/sysctl.h
66263+++ b/include/linux/sysctl.h
66264@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66265
66266 extern int proc_dostring(struct ctl_table *, int,
66267 void __user *, size_t *, loff_t *);
66268+extern int proc_dostring_modpriv(struct ctl_table *, int,
66269+ void __user *, size_t *, loff_t *);
66270 extern int proc_dointvec(struct ctl_table *, int,
66271 void __user *, size_t *, loff_t *);
66272 extern int proc_dointvec_minmax(struct ctl_table *, int,
66273diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66274index 7faf933..eb6f5e3 100644
66275--- a/include/linux/sysrq.h
66276+++ b/include/linux/sysrq.h
66277@@ -36,7 +36,7 @@ struct sysrq_key_op {
66278 char *help_msg;
66279 char *action_msg;
66280 int enable_mask;
66281-};
66282+} __do_const;
66283
66284 #ifdef CONFIG_MAGIC_SYSRQ
66285
66286diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
66287index ccc1899..b1aaceb 100644
66288--- a/include/linux/thread_info.h
66289+++ b/include/linux/thread_info.h
66290@@ -146,6 +146,15 @@ static inline bool test_and_clear_restore_sigmask(void)
66291 #error "no set_restore_sigmask() provided and default one won't work"
66292 #endif
66293
66294+extern void __check_object_size(const void *ptr, unsigned long n, bool to);
66295+static inline void check_object_size(const void *ptr, unsigned long n, bool to)
66296+{
66297+#ifndef CONFIG_PAX_USERCOPY_DEBUG
66298+ if (!__builtin_constant_p(n))
66299+#endif
66300+ __check_object_size(ptr, n, to);
66301+}
66302+
66303 #endif /* __KERNEL__ */
66304
66305 #endif /* _LINUX_THREAD_INFO_H */
66306diff --git a/include/linux/tty.h b/include/linux/tty.h
66307index f0b4eb4..1c4854e 100644
66308--- a/include/linux/tty.h
66309+++ b/include/linux/tty.h
66310@@ -192,7 +192,7 @@ struct tty_port {
66311 const struct tty_port_operations *ops; /* Port operations */
66312 spinlock_t lock; /* Lock protecting tty field */
66313 int blocked_open; /* Waiting to open */
66314- int count; /* Usage count */
66315+ atomic_t count; /* Usage count */
66316 wait_queue_head_t open_wait; /* Open waiters */
66317 wait_queue_head_t close_wait; /* Close waiters */
66318 wait_queue_head_t delta_msr_wait; /* Modem status change */
66319@@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66320 struct tty_struct *tty, struct file *filp);
66321 static inline int tty_port_users(struct tty_port *port)
66322 {
66323- return port->count + port->blocked_open;
66324+ return atomic_read(&port->count) + port->blocked_open;
66325 }
66326
66327 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66328diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66329index dd976cf..e272742 100644
66330--- a/include/linux/tty_driver.h
66331+++ b/include/linux/tty_driver.h
66332@@ -284,7 +284,7 @@ struct tty_operations {
66333 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66334 #endif
66335 const struct file_operations *proc_fops;
66336-};
66337+} __do_const;
66338
66339 struct tty_driver {
66340 int magic; /* magic number for this structure */
66341diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66342index fb79dd8d..07d4773 100644
66343--- a/include/linux/tty_ldisc.h
66344+++ b/include/linux/tty_ldisc.h
66345@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66346
66347 struct module *owner;
66348
66349- int refcount;
66350+ atomic_t refcount;
66351 };
66352
66353 struct tty_ldisc {
66354diff --git a/include/linux/types.h b/include/linux/types.h
66355index 1cc0e4b..0d50edf 100644
66356--- a/include/linux/types.h
66357+++ b/include/linux/types.h
66358@@ -175,10 +175,26 @@ typedef struct {
66359 int counter;
66360 } atomic_t;
66361
66362+#ifdef CONFIG_PAX_REFCOUNT
66363+typedef struct {
66364+ int counter;
66365+} atomic_unchecked_t;
66366+#else
66367+typedef atomic_t atomic_unchecked_t;
66368+#endif
66369+
66370 #ifdef CONFIG_64BIT
66371 typedef struct {
66372 long counter;
66373 } atomic64_t;
66374+
66375+#ifdef CONFIG_PAX_REFCOUNT
66376+typedef struct {
66377+ long counter;
66378+} atomic64_unchecked_t;
66379+#else
66380+typedef atomic64_t atomic64_unchecked_t;
66381+#endif
66382 #endif
66383
66384 struct list_head {
66385diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66386index 5ca0951..ab496a5 100644
66387--- a/include/linux/uaccess.h
66388+++ b/include/linux/uaccess.h
66389@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66390 long ret; \
66391 mm_segment_t old_fs = get_fs(); \
66392 \
66393- set_fs(KERNEL_DS); \
66394 pagefault_disable(); \
66395- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66396- pagefault_enable(); \
66397+ set_fs(KERNEL_DS); \
66398+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66399 set_fs(old_fs); \
66400+ pagefault_enable(); \
66401 ret; \
66402 })
66403
66404diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66405index 99c1b4d..bb94261 100644
66406--- a/include/linux/unaligned/access_ok.h
66407+++ b/include/linux/unaligned/access_ok.h
66408@@ -6,32 +6,32 @@
66409
66410 static inline u16 get_unaligned_le16(const void *p)
66411 {
66412- return le16_to_cpup((__le16 *)p);
66413+ return le16_to_cpup((const __le16 *)p);
66414 }
66415
66416 static inline u32 get_unaligned_le32(const void *p)
66417 {
66418- return le32_to_cpup((__le32 *)p);
66419+ return le32_to_cpup((const __le32 *)p);
66420 }
66421
66422 static inline u64 get_unaligned_le64(const void *p)
66423 {
66424- return le64_to_cpup((__le64 *)p);
66425+ return le64_to_cpup((const __le64 *)p);
66426 }
66427
66428 static inline u16 get_unaligned_be16(const void *p)
66429 {
66430- return be16_to_cpup((__be16 *)p);
66431+ return be16_to_cpup((const __be16 *)p);
66432 }
66433
66434 static inline u32 get_unaligned_be32(const void *p)
66435 {
66436- return be32_to_cpup((__be32 *)p);
66437+ return be32_to_cpup((const __be32 *)p);
66438 }
66439
66440 static inline u64 get_unaligned_be64(const void *p)
66441 {
66442- return be64_to_cpup((__be64 *)p);
66443+ return be64_to_cpup((const __be64 *)p);
66444 }
66445
66446 static inline void put_unaligned_le16(u16 val, void *p)
66447diff --git a/include/linux/usb.h b/include/linux/usb.h
66448index 10278d1..e21ec3c 100644
66449--- a/include/linux/usb.h
66450+++ b/include/linux/usb.h
66451@@ -551,7 +551,7 @@ struct usb_device {
66452 int maxchild;
66453
66454 u32 quirks;
66455- atomic_t urbnum;
66456+ atomic_unchecked_t urbnum;
66457
66458 unsigned long active_duration;
66459
66460diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66461index c5d36c6..108f4f9 100644
66462--- a/include/linux/usb/renesas_usbhs.h
66463+++ b/include/linux/usb/renesas_usbhs.h
66464@@ -39,7 +39,7 @@ enum {
66465 */
66466 struct renesas_usbhs_driver_callback {
66467 int (*notify_hotplug)(struct platform_device *pdev);
66468-};
66469+} __no_const;
66470
66471 /*
66472 * callback functions for platform
66473diff --git a/include/linux/usb/usbnet.h b/include/linux/usb/usbnet.h
66474index ddbbb7d..9134611 100644
66475--- a/include/linux/usb/usbnet.h
66476+++ b/include/linux/usb/usbnet.h
66477@@ -33,6 +33,7 @@ struct usbnet {
66478 wait_queue_head_t *wait;
66479 struct mutex phy_mutex;
66480 unsigned char suspend_count;
66481+ unsigned char pkt_cnt, pkt_err;
66482
66483 /* i/o info: pipes etc */
66484 unsigned in, out;
66485@@ -69,6 +70,8 @@ struct usbnet {
66486 # define EVENT_DEV_ASLEEP 6
66487 # define EVENT_DEV_OPEN 7
66488 # define EVENT_DEVICE_REPORT_IDLE 8
66489+# define EVENT_NO_RUNTIME_PM 9
66490+# define EVENT_RX_KILL 10
66491 };
66492
66493 static inline struct usb_driver *driver_of(struct usb_interface *intf)
66494diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66495index 6f8fbcf..8259001 100644
66496--- a/include/linux/vermagic.h
66497+++ b/include/linux/vermagic.h
66498@@ -25,9 +25,35 @@
66499 #define MODULE_ARCH_VERMAGIC ""
66500 #endif
66501
66502+#ifdef CONFIG_PAX_REFCOUNT
66503+#define MODULE_PAX_REFCOUNT "REFCOUNT "
66504+#else
66505+#define MODULE_PAX_REFCOUNT ""
66506+#endif
66507+
66508+#ifdef CONSTIFY_PLUGIN
66509+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66510+#else
66511+#define MODULE_CONSTIFY_PLUGIN ""
66512+#endif
66513+
66514+#ifdef STACKLEAK_PLUGIN
66515+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66516+#else
66517+#define MODULE_STACKLEAK_PLUGIN ""
66518+#endif
66519+
66520+#ifdef CONFIG_GRKERNSEC
66521+#define MODULE_GRSEC "GRSEC "
66522+#else
66523+#define MODULE_GRSEC ""
66524+#endif
66525+
66526 #define VERMAGIC_STRING \
66527 UTS_RELEASE " " \
66528 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66529 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66530- MODULE_ARCH_VERMAGIC
66531+ MODULE_ARCH_VERMAGIC \
66532+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66533+ MODULE_GRSEC
66534
66535diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66536index 6071e91..ca6a489 100644
66537--- a/include/linux/vmalloc.h
66538+++ b/include/linux/vmalloc.h
66539@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66540 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66541 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66542 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66543+
66544+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66545+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66546+#endif
66547+
66548 /* bits [20..32] reserved for arch specific ioremap internals */
66549
66550 /*
66551@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66552 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66553 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66554 unsigned long start, unsigned long end, gfp_t gfp_mask,
66555- pgprot_t prot, int node, const void *caller);
66556+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
66557 extern void vfree(const void *addr);
66558
66559 extern void *vmap(struct page **pages, unsigned int count,
66560@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66561 extern void free_vm_area(struct vm_struct *area);
66562
66563 /* for /dev/kmem */
66564-extern long vread(char *buf, char *addr, unsigned long count);
66565-extern long vwrite(char *buf, char *addr, unsigned long count);
66566+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66567+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66568
66569 /*
66570 * Internals. Dont't use..
66571diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66572index 92a86b2..1d9eb3c 100644
66573--- a/include/linux/vmstat.h
66574+++ b/include/linux/vmstat.h
66575@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66576 /*
66577 * Zone based page accounting with per cpu differentials.
66578 */
66579-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66580+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66581
66582 static inline void zone_page_state_add(long x, struct zone *zone,
66583 enum zone_stat_item item)
66584 {
66585- atomic_long_add(x, &zone->vm_stat[item]);
66586- atomic_long_add(x, &vm_stat[item]);
66587+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66588+ atomic_long_add_unchecked(x, &vm_stat[item]);
66589 }
66590
66591 static inline unsigned long global_page_state(enum zone_stat_item item)
66592 {
66593- long x = atomic_long_read(&vm_stat[item]);
66594+ long x = atomic_long_read_unchecked(&vm_stat[item]);
66595 #ifdef CONFIG_SMP
66596 if (x < 0)
66597 x = 0;
66598@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66599 static inline unsigned long zone_page_state(struct zone *zone,
66600 enum zone_stat_item item)
66601 {
66602- long x = atomic_long_read(&zone->vm_stat[item]);
66603+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66604 #ifdef CONFIG_SMP
66605 if (x < 0)
66606 x = 0;
66607@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66608 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66609 enum zone_stat_item item)
66610 {
66611- long x = atomic_long_read(&zone->vm_stat[item]);
66612+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66613
66614 #ifdef CONFIG_SMP
66615 int cpu;
66616@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66617
66618 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66619 {
66620- atomic_long_inc(&zone->vm_stat[item]);
66621- atomic_long_inc(&vm_stat[item]);
66622+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
66623+ atomic_long_inc_unchecked(&vm_stat[item]);
66624 }
66625
66626 static inline void __inc_zone_page_state(struct page *page,
66627@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66628
66629 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66630 {
66631- atomic_long_dec(&zone->vm_stat[item]);
66632- atomic_long_dec(&vm_stat[item]);
66633+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
66634+ atomic_long_dec_unchecked(&vm_stat[item]);
66635 }
66636
66637 static inline void __dec_zone_page_state(struct page *page,
66638diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66639index 95d1c91..6798cca 100644
66640--- a/include/media/v4l2-dev.h
66641+++ b/include/media/v4l2-dev.h
66642@@ -76,7 +76,7 @@ struct v4l2_file_operations {
66643 int (*mmap) (struct file *, struct vm_area_struct *);
66644 int (*open) (struct file *);
66645 int (*release) (struct file *);
66646-};
66647+} __do_const;
66648
66649 /*
66650 * Newer version of video_device, handled by videodev2.c
66651diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66652index e48b571..7e40de4 100644
66653--- a/include/media/v4l2-ioctl.h
66654+++ b/include/media/v4l2-ioctl.h
66655@@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66656 bool valid_prio, int cmd, void *arg);
66657 };
66658
66659-
66660 /* v4l debugging and diagnostics */
66661
66662 /* Debug bitmask flags to be used on V4L2 */
66663diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66664index 9e5425b..8136ffc 100644
66665--- a/include/net/caif/cfctrl.h
66666+++ b/include/net/caif/cfctrl.h
66667@@ -52,7 +52,7 @@ struct cfctrl_rsp {
66668 void (*radioset_rsp)(void);
66669 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66670 struct cflayer *client_layer);
66671-};
66672+} __no_const;
66673
66674 /* Link Setup Parameters for CAIF-Links. */
66675 struct cfctrl_link_param {
66676@@ -101,8 +101,8 @@ struct cfctrl_request_info {
66677 struct cfctrl {
66678 struct cfsrvl serv;
66679 struct cfctrl_rsp res;
66680- atomic_t req_seq_no;
66681- atomic_t rsp_seq_no;
66682+ atomic_unchecked_t req_seq_no;
66683+ atomic_unchecked_t rsp_seq_no;
66684 struct list_head list;
66685 /* Protects from simultaneous access to first_req list */
66686 spinlock_t info_list_lock;
66687diff --git a/include/net/flow.h b/include/net/flow.h
66688index 628e11b..4c475df 100644
66689--- a/include/net/flow.h
66690+++ b/include/net/flow.h
66691@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66692
66693 extern void flow_cache_flush(void);
66694 extern void flow_cache_flush_deferred(void);
66695-extern atomic_t flow_cache_genid;
66696+extern atomic_unchecked_t flow_cache_genid;
66697
66698 #endif
66699diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66700index e5062c9..48a9a4b 100644
66701--- a/include/net/gro_cells.h
66702+++ b/include/net/gro_cells.h
66703@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66704 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66705
66706 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66707- atomic_long_inc(&dev->rx_dropped);
66708+ atomic_long_inc_unchecked(&dev->rx_dropped);
66709 kfree_skb(skb);
66710 return;
66711 }
66712@@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
66713 int i;
66714
66715 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
66716- gcells->cells = kcalloc(sizeof(struct gro_cell),
66717- gcells->gro_cells_mask + 1,
66718+ gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
66719+ sizeof(struct gro_cell),
66720 GFP_KERNEL);
66721 if (!gcells->cells)
66722 return -ENOMEM;
66723diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66724index 1832927..ce39aea 100644
66725--- a/include/net/inet_connection_sock.h
66726+++ b/include/net/inet_connection_sock.h
66727@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66728 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66729 int (*bind_conflict)(const struct sock *sk,
66730 const struct inet_bind_bucket *tb, bool relax);
66731-};
66732+} __do_const;
66733
66734 /** inet_connection_sock - INET connection oriented sock
66735 *
66736diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66737index 53f464d..ba76aaa 100644
66738--- a/include/net/inetpeer.h
66739+++ b/include/net/inetpeer.h
66740@@ -47,8 +47,8 @@ struct inet_peer {
66741 */
66742 union {
66743 struct {
66744- atomic_t rid; /* Frag reception counter */
66745- atomic_t ip_id_count; /* IP ID for the next packet */
66746+ atomic_unchecked_t rid; /* Frag reception counter */
66747+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
66748 };
66749 struct rcu_head rcu;
66750 struct inet_peer *gc_next;
66751@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
66752 more++;
66753 inet_peer_refcheck(p);
66754 do {
66755- old = atomic_read(&p->ip_id_count);
66756+ old = atomic_read_unchecked(&p->ip_id_count);
66757 new = old + more;
66758 if (!new)
66759 new = 1;
66760- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
66761+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
66762 return new;
66763 }
66764
66765diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
66766index 9497be1..5a4fafe 100644
66767--- a/include/net/ip_fib.h
66768+++ b/include/net/ip_fib.h
66769@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
66770
66771 #define FIB_RES_SADDR(net, res) \
66772 ((FIB_RES_NH(res).nh_saddr_genid == \
66773- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
66774+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
66775 FIB_RES_NH(res).nh_saddr : \
66776 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
66777 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
66778diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
66779index ee75ccd..2cc2b95 100644
66780--- a/include/net/ip_vs.h
66781+++ b/include/net/ip_vs.h
66782@@ -510,7 +510,7 @@ struct ip_vs_conn {
66783 struct ip_vs_conn *control; /* Master control connection */
66784 atomic_t n_control; /* Number of controlled ones */
66785 struct ip_vs_dest *dest; /* real server */
66786- atomic_t in_pkts; /* incoming packet counter */
66787+ atomic_unchecked_t in_pkts; /* incoming packet counter */
66788
66789 /* packet transmitter for different forwarding methods. If it
66790 mangles the packet, it must return NF_DROP or better NF_STOLEN,
66791@@ -648,7 +648,7 @@ struct ip_vs_dest {
66792 __be16 port; /* port number of the server */
66793 union nf_inet_addr addr; /* IP address of the server */
66794 volatile unsigned int flags; /* dest status flags */
66795- atomic_t conn_flags; /* flags to copy to conn */
66796+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
66797 atomic_t weight; /* server weight */
66798
66799 atomic_t refcnt; /* reference counter */
66800diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
66801index 80ffde3..968b0f4 100644
66802--- a/include/net/irda/ircomm_tty.h
66803+++ b/include/net/irda/ircomm_tty.h
66804@@ -35,6 +35,7 @@
66805 #include <linux/termios.h>
66806 #include <linux/timer.h>
66807 #include <linux/tty.h> /* struct tty_struct */
66808+#include <asm/local.h>
66809
66810 #include <net/irda/irias_object.h>
66811 #include <net/irda/ircomm_core.h>
66812diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
66813index cc7c197..9f2da2a 100644
66814--- a/include/net/iucv/af_iucv.h
66815+++ b/include/net/iucv/af_iucv.h
66816@@ -141,7 +141,7 @@ struct iucv_sock {
66817 struct iucv_sock_list {
66818 struct hlist_head head;
66819 rwlock_t lock;
66820- atomic_t autobind_name;
66821+ atomic_unchecked_t autobind_name;
66822 };
66823
66824 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
66825diff --git a/include/net/neighbour.h b/include/net/neighbour.h
66826index 0dab173..1b76af0 100644
66827--- a/include/net/neighbour.h
66828+++ b/include/net/neighbour.h
66829@@ -123,7 +123,7 @@ struct neigh_ops {
66830 void (*error_report)(struct neighbour *, struct sk_buff *);
66831 int (*output)(struct neighbour *, struct sk_buff *);
66832 int (*connected_output)(struct neighbour *, struct sk_buff *);
66833-};
66834+} __do_const;
66835
66836 struct pneigh_entry {
66837 struct pneigh_entry *next;
66838diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
66839index 95e6466..251016d 100644
66840--- a/include/net/net_namespace.h
66841+++ b/include/net/net_namespace.h
66842@@ -110,7 +110,7 @@ struct net {
66843 #endif
66844 struct netns_ipvs *ipvs;
66845 struct sock *diag_nlsk;
66846- atomic_t rt_genid;
66847+ atomic_unchecked_t rt_genid;
66848 };
66849
66850 /*
66851@@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
66852
66853 static inline int rt_genid(struct net *net)
66854 {
66855- return atomic_read(&net->rt_genid);
66856+ return atomic_read_unchecked(&net->rt_genid);
66857 }
66858
66859 static inline void rt_genid_bump(struct net *net)
66860 {
66861- atomic_inc(&net->rt_genid);
66862+ atomic_inc_unchecked(&net->rt_genid);
66863 }
66864
66865 #endif /* __NET_NET_NAMESPACE_H */
66866diff --git a/include/net/netdma.h b/include/net/netdma.h
66867index 8ba8ce2..99b7fff 100644
66868--- a/include/net/netdma.h
66869+++ b/include/net/netdma.h
66870@@ -24,7 +24,7 @@
66871 #include <linux/dmaengine.h>
66872 #include <linux/skbuff.h>
66873
66874-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66875+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66876 struct sk_buff *skb, int offset, struct iovec *to,
66877 size_t len, struct dma_pinned_list *pinned_list);
66878
66879diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
66880index 252fd10..aa1421f 100644
66881--- a/include/net/netfilter/nf_queue.h
66882+++ b/include/net/netfilter/nf_queue.h
66883@@ -22,7 +22,7 @@ struct nf_queue_handler {
66884 int (*outfn)(struct nf_queue_entry *entry,
66885 unsigned int queuenum);
66886 char *name;
66887-};
66888+} __do_const;
66889
66890 extern int nf_register_queue_handler(u_int8_t pf,
66891 const struct nf_queue_handler *qh);
66892diff --git a/include/net/netlink.h b/include/net/netlink.h
66893index 9690b0f..87aded7 100644
66894--- a/include/net/netlink.h
66895+++ b/include/net/netlink.h
66896@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
66897 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
66898 {
66899 if (mark)
66900- skb_trim(skb, (unsigned char *) mark - skb->data);
66901+ skb_trim(skb, (const unsigned char *) mark - skb->data);
66902 }
66903
66904 /**
66905diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
66906index 2ae2b83..dbdc85e 100644
66907--- a/include/net/netns/ipv4.h
66908+++ b/include/net/netns/ipv4.h
66909@@ -64,7 +64,7 @@ struct netns_ipv4 {
66910 kgid_t sysctl_ping_group_range[2];
66911 long sysctl_tcp_mem[3];
66912
66913- atomic_t dev_addr_genid;
66914+ atomic_unchecked_t dev_addr_genid;
66915
66916 #ifdef CONFIG_IP_MROUTE
66917 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
66918diff --git a/include/net/protocol.h b/include/net/protocol.h
66919index 929528c..c84d4f6 100644
66920--- a/include/net/protocol.h
66921+++ b/include/net/protocol.h
66922@@ -48,7 +48,7 @@ struct net_protocol {
66923 int (*gro_complete)(struct sk_buff *skb);
66924 unsigned int no_policy:1,
66925 netns_ok:1;
66926-};
66927+} __do_const;
66928
66929 #if IS_ENABLED(CONFIG_IPV6)
66930 struct inet6_protocol {
66931@@ -69,7 +69,7 @@ struct inet6_protocol {
66932 int (*gro_complete)(struct sk_buff *skb);
66933
66934 unsigned int flags; /* INET6_PROTO_xxx */
66935-};
66936+} __do_const;
66937
66938 #define INET6_PROTO_NOPOLICY 0x1
66939 #define INET6_PROTO_FINAL 0x2
66940diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
66941index 9c6414f..fbd0524 100644
66942--- a/include/net/sctp/sctp.h
66943+++ b/include/net/sctp/sctp.h
66944@@ -318,9 +318,9 @@ do { \
66945
66946 #else /* SCTP_DEBUG */
66947
66948-#define SCTP_DEBUG_PRINTK(whatever...)
66949-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
66950-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
66951+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
66952+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
66953+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
66954 #define SCTP_ENABLE_DEBUG
66955 #define SCTP_DISABLE_DEBUG
66956 #define SCTP_ASSERT(expr, str, func)
66957diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
66958index 64158aa..b65533c 100644
66959--- a/include/net/sctp/structs.h
66960+++ b/include/net/sctp/structs.h
66961@@ -496,7 +496,7 @@ struct sctp_af {
66962 int sockaddr_len;
66963 sa_family_t sa_family;
66964 struct list_head list;
66965-};
66966+} __do_const;
66967
66968 struct sctp_af *sctp_get_af_specific(sa_family_t);
66969 int sctp_register_af(struct sctp_af *);
66970@@ -516,7 +516,7 @@ struct sctp_pf {
66971 struct sctp_association *asoc);
66972 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
66973 struct sctp_af *af;
66974-};
66975+} __do_const;
66976
66977
66978 /* Structure to track chunk fragments that have been acked, but peer
66979diff --git a/include/net/sock.h b/include/net/sock.h
66980index c945fba..e162e56 100644
66981--- a/include/net/sock.h
66982+++ b/include/net/sock.h
66983@@ -304,7 +304,7 @@ struct sock {
66984 #ifdef CONFIG_RPS
66985 __u32 sk_rxhash;
66986 #endif
66987- atomic_t sk_drops;
66988+ atomic_unchecked_t sk_drops;
66989 int sk_rcvbuf;
66990
66991 struct sk_filter __rcu *sk_filter;
66992@@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
66993 }
66994
66995 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
66996- char __user *from, char *to,
66997+ char __user *from, unsigned char *to,
66998 int copy, int offset)
66999 {
67000 if (skb->ip_summed == CHECKSUM_NONE) {
67001@@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
67002 }
67003 }
67004
67005-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67006+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67007
67008 /**
67009 * sk_page_frag - return an appropriate page_frag
67010diff --git a/include/net/tcp.h b/include/net/tcp.h
67011index 4af45e3..af97861 100644
67012--- a/include/net/tcp.h
67013+++ b/include/net/tcp.h
67014@@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67015 extern void tcp_xmit_retransmit_queue(struct sock *);
67016 extern void tcp_simple_retransmit(struct sock *);
67017 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67018-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67019+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67020
67021 extern void tcp_send_probe0(struct sock *);
67022 extern void tcp_send_partial(struct sock *);
67023@@ -702,8 +702,8 @@ struct tcp_skb_cb {
67024 struct inet6_skb_parm h6;
67025 #endif
67026 } header; /* For incoming frames */
67027- __u32 seq; /* Starting sequence number */
67028- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67029+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
67030+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67031 __u32 when; /* used to compute rtt's */
67032 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67033
67034@@ -717,7 +717,7 @@ struct tcp_skb_cb {
67035
67036 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67037 /* 1 byte hole */
67038- __u32 ack_seq; /* Sequence number ACK'd */
67039+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67040 };
67041
67042 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67043diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67044index 63445ed..74ef61d 100644
67045--- a/include/net/xfrm.h
67046+++ b/include/net/xfrm.h
67047@@ -423,7 +423,7 @@ struct xfrm_mode {
67048 struct module *owner;
67049 unsigned int encap;
67050 int flags;
67051-};
67052+} __do_const;
67053
67054 /* Flags for xfrm_mode. */
67055 enum {
67056@@ -514,7 +514,7 @@ struct xfrm_policy {
67057 struct timer_list timer;
67058
67059 struct flow_cache_object flo;
67060- atomic_t genid;
67061+ atomic_unchecked_t genid;
67062 u32 priority;
67063 u32 index;
67064 struct xfrm_mark mark;
67065diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67066index 1a046b1..ee0bef0 100644
67067--- a/include/rdma/iw_cm.h
67068+++ b/include/rdma/iw_cm.h
67069@@ -122,7 +122,7 @@ struct iw_cm_verbs {
67070 int backlog);
67071
67072 int (*destroy_listen)(struct iw_cm_id *cm_id);
67073-};
67074+} __no_const;
67075
67076 /**
67077 * iw_create_cm_id - Create an IW CM identifier.
67078diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67079index 399162b..b337f1a 100644
67080--- a/include/scsi/libfc.h
67081+++ b/include/scsi/libfc.h
67082@@ -762,6 +762,7 @@ struct libfc_function_template {
67083 */
67084 void (*disc_stop_final) (struct fc_lport *);
67085 };
67086+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67087
67088 /**
67089 * struct fc_disc - Discovery context
67090@@ -866,7 +867,7 @@ struct fc_lport {
67091 struct fc_vport *vport;
67092
67093 /* Operational Information */
67094- struct libfc_function_template tt;
67095+ libfc_function_template_no_const tt;
67096 u8 link_up;
67097 u8 qfull;
67098 enum fc_lport_state state;
67099diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67100index 55367b0..d97bd2a 100644
67101--- a/include/scsi/scsi_device.h
67102+++ b/include/scsi/scsi_device.h
67103@@ -169,9 +169,9 @@ struct scsi_device {
67104 unsigned int max_device_blocked; /* what device_blocked counts down from */
67105 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67106
67107- atomic_t iorequest_cnt;
67108- atomic_t iodone_cnt;
67109- atomic_t ioerr_cnt;
67110+ atomic_unchecked_t iorequest_cnt;
67111+ atomic_unchecked_t iodone_cnt;
67112+ atomic_unchecked_t ioerr_cnt;
67113
67114 struct device sdev_gendev,
67115 sdev_dev;
67116diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67117index b797e8f..8e2c3aa 100644
67118--- a/include/scsi/scsi_transport_fc.h
67119+++ b/include/scsi/scsi_transport_fc.h
67120@@ -751,7 +751,8 @@ struct fc_function_template {
67121 unsigned long show_host_system_hostname:1;
67122
67123 unsigned long disable_target_scan:1;
67124-};
67125+} __do_const;
67126+typedef struct fc_function_template __no_const fc_function_template_no_const;
67127
67128
67129 /**
67130diff --git a/include/sound/soc.h b/include/sound/soc.h
67131index 91244a0..89ca1a7 100644
67132--- a/include/sound/soc.h
67133+++ b/include/sound/soc.h
67134@@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67135 /* probe ordering - for components with runtime dependencies */
67136 int probe_order;
67137 int remove_order;
67138-};
67139+} __do_const;
67140
67141 /* SoC platform interface */
67142 struct snd_soc_platform_driver {
67143@@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67144 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67145 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67146 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67147-};
67148+} __do_const;
67149
67150 struct snd_soc_platform {
67151 const char *name;
67152diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67153index fca8bbe..c0242ea 100644
67154--- a/include/target/target_core_base.h
67155+++ b/include/target/target_core_base.h
67156@@ -760,7 +760,7 @@ struct se_device {
67157 spinlock_t stats_lock;
67158 /* Active commands on this virtual SE device */
67159 atomic_t simple_cmds;
67160- atomic_t dev_ordered_id;
67161+ atomic_unchecked_t dev_ordered_id;
67162 atomic_t dev_ordered_sync;
67163 atomic_t dev_qf_count;
67164 struct se_obj dev_obj;
67165diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67166new file mode 100644
67167index 0000000..fb634b7
67168--- /dev/null
67169+++ b/include/trace/events/fs.h
67170@@ -0,0 +1,53 @@
67171+#undef TRACE_SYSTEM
67172+#define TRACE_SYSTEM fs
67173+
67174+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67175+#define _TRACE_FS_H
67176+
67177+#include <linux/fs.h>
67178+#include <linux/tracepoint.h>
67179+
67180+TRACE_EVENT(do_sys_open,
67181+
67182+ TP_PROTO(const char *filename, int flags, int mode),
67183+
67184+ TP_ARGS(filename, flags, mode),
67185+
67186+ TP_STRUCT__entry(
67187+ __string( filename, filename )
67188+ __field( int, flags )
67189+ __field( int, mode )
67190+ ),
67191+
67192+ TP_fast_assign(
67193+ __assign_str(filename, filename);
67194+ __entry->flags = flags;
67195+ __entry->mode = mode;
67196+ ),
67197+
67198+ TP_printk("\"%s\" %x %o",
67199+ __get_str(filename), __entry->flags, __entry->mode)
67200+);
67201+
67202+TRACE_EVENT(open_exec,
67203+
67204+ TP_PROTO(const char *filename),
67205+
67206+ TP_ARGS(filename),
67207+
67208+ TP_STRUCT__entry(
67209+ __string( filename, filename )
67210+ ),
67211+
67212+ TP_fast_assign(
67213+ __assign_str(filename, filename);
67214+ ),
67215+
67216+ TP_printk("\"%s\"",
67217+ __get_str(filename))
67218+);
67219+
67220+#endif /* _TRACE_FS_H */
67221+
67222+/* This part must be outside protection */
67223+#include <trace/define_trace.h>
67224diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67225index 1c09820..7f5ec79 100644
67226--- a/include/trace/events/irq.h
67227+++ b/include/trace/events/irq.h
67228@@ -36,7 +36,7 @@ struct softirq_action;
67229 */
67230 TRACE_EVENT(irq_handler_entry,
67231
67232- TP_PROTO(int irq, struct irqaction *action),
67233+ TP_PROTO(int irq, const struct irqaction *action),
67234
67235 TP_ARGS(irq, action),
67236
67237@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67238 */
67239 TRACE_EVENT(irq_handler_exit,
67240
67241- TP_PROTO(int irq, struct irqaction *action, int ret),
67242+ TP_PROTO(int irq, const struct irqaction *action, int ret),
67243
67244 TP_ARGS(irq, action, ret),
67245
67246diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67247index 7caf44c..23c6f27 100644
67248--- a/include/uapi/linux/a.out.h
67249+++ b/include/uapi/linux/a.out.h
67250@@ -39,6 +39,14 @@ enum machine_type {
67251 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67252 };
67253
67254+/* Constants for the N_FLAGS field */
67255+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67256+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67257+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67258+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67259+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67260+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67261+
67262 #if !defined (N_MAGIC)
67263 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67264 #endif
67265diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67266index d876736..b36014e 100644
67267--- a/include/uapi/linux/byteorder/little_endian.h
67268+++ b/include/uapi/linux/byteorder/little_endian.h
67269@@ -42,51 +42,51 @@
67270
67271 static inline __le64 __cpu_to_le64p(const __u64 *p)
67272 {
67273- return (__force __le64)*p;
67274+ return (__force const __le64)*p;
67275 }
67276 static inline __u64 __le64_to_cpup(const __le64 *p)
67277 {
67278- return (__force __u64)*p;
67279+ return (__force const __u64)*p;
67280 }
67281 static inline __le32 __cpu_to_le32p(const __u32 *p)
67282 {
67283- return (__force __le32)*p;
67284+ return (__force const __le32)*p;
67285 }
67286 static inline __u32 __le32_to_cpup(const __le32 *p)
67287 {
67288- return (__force __u32)*p;
67289+ return (__force const __u32)*p;
67290 }
67291 static inline __le16 __cpu_to_le16p(const __u16 *p)
67292 {
67293- return (__force __le16)*p;
67294+ return (__force const __le16)*p;
67295 }
67296 static inline __u16 __le16_to_cpup(const __le16 *p)
67297 {
67298- return (__force __u16)*p;
67299+ return (__force const __u16)*p;
67300 }
67301 static inline __be64 __cpu_to_be64p(const __u64 *p)
67302 {
67303- return (__force __be64)__swab64p(p);
67304+ return (__force const __be64)__swab64p(p);
67305 }
67306 static inline __u64 __be64_to_cpup(const __be64 *p)
67307 {
67308- return __swab64p((__u64 *)p);
67309+ return __swab64p((const __u64 *)p);
67310 }
67311 static inline __be32 __cpu_to_be32p(const __u32 *p)
67312 {
67313- return (__force __be32)__swab32p(p);
67314+ return (__force const __be32)__swab32p(p);
67315 }
67316 static inline __u32 __be32_to_cpup(const __be32 *p)
67317 {
67318- return __swab32p((__u32 *)p);
67319+ return __swab32p((const __u32 *)p);
67320 }
67321 static inline __be16 __cpu_to_be16p(const __u16 *p)
67322 {
67323- return (__force __be16)__swab16p(p);
67324+ return (__force const __be16)__swab16p(p);
67325 }
67326 static inline __u16 __be16_to_cpup(const __be16 *p)
67327 {
67328- return __swab16p((__u16 *)p);
67329+ return __swab16p((const __u16 *)p);
67330 }
67331 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67332 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67333diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67334index 126a817..d522bd1 100644
67335--- a/include/uapi/linux/elf.h
67336+++ b/include/uapi/linux/elf.h
67337@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67338 #define PT_GNU_EH_FRAME 0x6474e550
67339
67340 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67341+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67342+
67343+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67344+
67345+/* Constants for the e_flags field */
67346+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67347+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67348+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67349+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67350+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67351+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67352
67353 /*
67354 * Extended Numbering
67355@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67356 #define DT_DEBUG 21
67357 #define DT_TEXTREL 22
67358 #define DT_JMPREL 23
67359+#define DT_FLAGS 30
67360+ #define DF_TEXTREL 0x00000004
67361 #define DT_ENCODING 32
67362 #define OLD_DT_LOOS 0x60000000
67363 #define DT_LOOS 0x6000000d
67364@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67365 #define PF_W 0x2
67366 #define PF_X 0x1
67367
67368+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67369+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67370+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67371+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67372+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67373+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67374+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67375+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67376+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67377+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67378+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67379+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67380+
67381 typedef struct elf32_phdr{
67382 Elf32_Word p_type;
67383 Elf32_Off p_offset;
67384@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67385 #define EI_OSABI 7
67386 #define EI_PAD 8
67387
67388+#define EI_PAX 14
67389+
67390 #define ELFMAG0 0x7f /* EI_MAG */
67391 #define ELFMAG1 'E'
67392 #define ELFMAG2 'L'
67393diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67394index aa169c4..6a2771d 100644
67395--- a/include/uapi/linux/personality.h
67396+++ b/include/uapi/linux/personality.h
67397@@ -30,6 +30,7 @@ enum {
67398 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67399 ADDR_NO_RANDOMIZE | \
67400 ADDR_COMPAT_LAYOUT | \
67401+ ADDR_LIMIT_3GB | \
67402 MMAP_PAGE_ZERO)
67403
67404 /*
67405diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67406index 7530e74..e714828 100644
67407--- a/include/uapi/linux/screen_info.h
67408+++ b/include/uapi/linux/screen_info.h
67409@@ -43,7 +43,8 @@ struct screen_info {
67410 __u16 pages; /* 0x32 */
67411 __u16 vesa_attributes; /* 0x34 */
67412 __u32 capabilities; /* 0x36 */
67413- __u8 _reserved[6]; /* 0x3a */
67414+ __u16 vesapm_size; /* 0x3a */
67415+ __u8 _reserved[4]; /* 0x3c */
67416 } __attribute__((packed));
67417
67418 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67419diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67420index 6d67213..8dab561 100644
67421--- a/include/uapi/linux/sysctl.h
67422+++ b/include/uapi/linux/sysctl.h
67423@@ -155,7 +155,11 @@ enum
67424 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67425 };
67426
67427-
67428+#ifdef CONFIG_PAX_SOFTMODE
67429+enum {
67430+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67431+};
67432+#endif
67433
67434 /* CTL_VM names: */
67435 enum
67436diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67437index 26607bd..588b65f 100644
67438--- a/include/uapi/linux/xattr.h
67439+++ b/include/uapi/linux/xattr.h
67440@@ -60,5 +60,9 @@
67441 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67442 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67443
67444+/* User namespace */
67445+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67446+#define XATTR_PAX_FLAGS_SUFFIX "flags"
67447+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67448
67449 #endif /* _UAPI_LINUX_XATTR_H */
67450diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67451index f9466fa..f4e2b81 100644
67452--- a/include/video/udlfb.h
67453+++ b/include/video/udlfb.h
67454@@ -53,10 +53,10 @@ struct dlfb_data {
67455 u32 pseudo_palette[256];
67456 int blank_mode; /*one of FB_BLANK_ */
67457 /* blit-only rendering path metrics, exposed through sysfs */
67458- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67459- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67460- atomic_t bytes_sent; /* to usb, after compression including overhead */
67461- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67462+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67463+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67464+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67465+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67466 };
67467
67468 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67469diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67470index 0993a22..32ba2fe 100644
67471--- a/include/video/uvesafb.h
67472+++ b/include/video/uvesafb.h
67473@@ -177,6 +177,7 @@ struct uvesafb_par {
67474 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67475 u8 pmi_setpal; /* PMI for palette changes */
67476 u16 *pmi_base; /* protected mode interface location */
67477+ u8 *pmi_code; /* protected mode code location */
67478 void *pmi_start;
67479 void *pmi_pal;
67480 u8 *vbe_state_orig; /*
67481diff --git a/init/Kconfig b/init/Kconfig
67482index 6fdd6e3..5b01610 100644
67483--- a/init/Kconfig
67484+++ b/init/Kconfig
67485@@ -925,6 +925,7 @@ endif # CGROUPS
67486
67487 config CHECKPOINT_RESTORE
67488 bool "Checkpoint/restore support" if EXPERT
67489+ depends on !GRKERNSEC
67490 default n
67491 help
67492 Enables additional kernel features in a sake of checkpoint/restore.
67493@@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67494 depends on OCFS2_FS = n
67495 depends on XFS_FS = n
67496
67497+ depends on GRKERNSEC = n
67498+
67499 config UIDGID_STRICT_TYPE_CHECKS
67500 bool "Require conversions between uid/gids and their internal representation"
67501 depends on UIDGID_CONVERTED
67502@@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67503
67504 config COMPAT_BRK
67505 bool "Disable heap randomization"
67506- default y
67507+ default n
67508 help
67509 Randomizing heap placement makes heap exploits harder, but it
67510 also breaks ancient binaries (including anything libc5 based).
67511@@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67512 config STOP_MACHINE
67513 bool
67514 default y
67515- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67516+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67517 help
67518 Need stop_machine() primitive.
67519
67520diff --git a/init/Makefile b/init/Makefile
67521index 7bc47ee..6da2dc7 100644
67522--- a/init/Makefile
67523+++ b/init/Makefile
67524@@ -2,6 +2,9 @@
67525 # Makefile for the linux kernel.
67526 #
67527
67528+ccflags-y := $(GCC_PLUGINS_CFLAGS)
67529+asflags-y := $(GCC_PLUGINS_AFLAGS)
67530+
67531 obj-y := main.o version.o mounts.o
67532 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67533 obj-y += noinitramfs.o
67534diff --git a/init/do_mounts.c b/init/do_mounts.c
67535index f8a6642..4e5ee1b 100644
67536--- a/init/do_mounts.c
67537+++ b/init/do_mounts.c
67538@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67539 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67540 {
67541 struct super_block *s;
67542- int err = sys_mount(name, "/root", fs, flags, data);
67543+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67544 if (err)
67545 return err;
67546
67547- sys_chdir("/root");
67548+ sys_chdir((const char __force_user *)"/root");
67549 s = current->fs->pwd.dentry->d_sb;
67550 ROOT_DEV = s->s_dev;
67551 printk(KERN_INFO
67552@@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67553 va_start(args, fmt);
67554 vsprintf(buf, fmt, args);
67555 va_end(args);
67556- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67557+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67558 if (fd >= 0) {
67559 sys_ioctl(fd, FDEJECT, 0);
67560 sys_close(fd);
67561 }
67562 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67563- fd = sys_open("/dev/console", O_RDWR, 0);
67564+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67565 if (fd >= 0) {
67566 sys_ioctl(fd, TCGETS, (long)&termios);
67567 termios.c_lflag &= ~ICANON;
67568 sys_ioctl(fd, TCSETSF, (long)&termios);
67569- sys_read(fd, &c, 1);
67570+ sys_read(fd, (char __user *)&c, 1);
67571 termios.c_lflag |= ICANON;
67572 sys_ioctl(fd, TCSETSF, (long)&termios);
67573 sys_close(fd);
67574@@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67575 mount_root();
67576 out:
67577 devtmpfs_mount("dev");
67578- sys_mount(".", "/", NULL, MS_MOVE, NULL);
67579- sys_chroot(".");
67580+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67581+ sys_chroot((const char __force_user *)".");
67582 }
67583diff --git a/init/do_mounts.h b/init/do_mounts.h
67584index f5b978a..69dbfe8 100644
67585--- a/init/do_mounts.h
67586+++ b/init/do_mounts.h
67587@@ -15,15 +15,15 @@ extern int root_mountflags;
67588
67589 static inline int create_dev(char *name, dev_t dev)
67590 {
67591- sys_unlink(name);
67592- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67593+ sys_unlink((char __force_user *)name);
67594+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67595 }
67596
67597 #if BITS_PER_LONG == 32
67598 static inline u32 bstat(char *name)
67599 {
67600 struct stat64 stat;
67601- if (sys_stat64(name, &stat) != 0)
67602+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67603 return 0;
67604 if (!S_ISBLK(stat.st_mode))
67605 return 0;
67606@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67607 static inline u32 bstat(char *name)
67608 {
67609 struct stat stat;
67610- if (sys_newstat(name, &stat) != 0)
67611+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67612 return 0;
67613 if (!S_ISBLK(stat.st_mode))
67614 return 0;
67615diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67616index f9acf71..1e19144 100644
67617--- a/init/do_mounts_initrd.c
67618+++ b/init/do_mounts_initrd.c
67619@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67620 create_dev("/dev/root.old", Root_RAM0);
67621 /* mount initrd on rootfs' /root */
67622 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67623- sys_mkdir("/old", 0700);
67624- sys_chdir("/old");
67625+ sys_mkdir((const char __force_user *)"/old", 0700);
67626+ sys_chdir((const char __force_user *)"/old");
67627
67628 /*
67629 * In case that a resume from disk is carried out by linuxrc or one of
67630@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67631 current->flags &= ~PF_FREEZER_SKIP;
67632
67633 /* move initrd to rootfs' /old */
67634- sys_mount("..", ".", NULL, MS_MOVE, NULL);
67635+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67636 /* switch root and cwd back to / of rootfs */
67637- sys_chroot("..");
67638+ sys_chroot((const char __force_user *)"..");
67639
67640 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67641- sys_chdir("/old");
67642+ sys_chdir((const char __force_user *)"/old");
67643 return;
67644 }
67645
67646- sys_chdir("/");
67647+ sys_chdir((const char __force_user *)"/");
67648 ROOT_DEV = new_decode_dev(real_root_dev);
67649 mount_root();
67650
67651 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67652- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67653+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67654 if (!error)
67655 printk("okay\n");
67656 else {
67657- int fd = sys_open("/dev/root.old", O_RDWR, 0);
67658+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67659 if (error == -ENOENT)
67660 printk("/initrd does not exist. Ignored.\n");
67661 else
67662 printk("failed\n");
67663 printk(KERN_NOTICE "Unmounting old root\n");
67664- sys_umount("/old", MNT_DETACH);
67665+ sys_umount((char __force_user *)"/old", MNT_DETACH);
67666 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67667 if (fd < 0) {
67668 error = fd;
67669@@ -120,11 +120,11 @@ int __init initrd_load(void)
67670 * mounted in the normal path.
67671 */
67672 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67673- sys_unlink("/initrd.image");
67674+ sys_unlink((const char __force_user *)"/initrd.image");
67675 handle_initrd();
67676 return 1;
67677 }
67678 }
67679- sys_unlink("/initrd.image");
67680+ sys_unlink((const char __force_user *)"/initrd.image");
67681 return 0;
67682 }
67683diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67684index 8cb6db5..d729f50 100644
67685--- a/init/do_mounts_md.c
67686+++ b/init/do_mounts_md.c
67687@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67688 partitioned ? "_d" : "", minor,
67689 md_setup_args[ent].device_names);
67690
67691- fd = sys_open(name, 0, 0);
67692+ fd = sys_open((char __force_user *)name, 0, 0);
67693 if (fd < 0) {
67694 printk(KERN_ERR "md: open failed - cannot start "
67695 "array %s\n", name);
67696@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67697 * array without it
67698 */
67699 sys_close(fd);
67700- fd = sys_open(name, 0, 0);
67701+ fd = sys_open((char __force_user *)name, 0, 0);
67702 sys_ioctl(fd, BLKRRPART, 0);
67703 }
67704 sys_close(fd);
67705@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67706
67707 wait_for_device_probe();
67708
67709- fd = sys_open("/dev/md0", 0, 0);
67710+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67711 if (fd >= 0) {
67712 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67713 sys_close(fd);
67714diff --git a/init/init_task.c b/init/init_task.c
67715index 8b2f399..f0797c9 100644
67716--- a/init/init_task.c
67717+++ b/init/init_task.c
67718@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67719 * Initial thread structure. Alignment of this is handled by a special
67720 * linker map entry.
67721 */
67722+#ifdef CONFIG_X86
67723+union thread_union init_thread_union __init_task_data;
67724+#else
67725 union thread_union init_thread_union __init_task_data =
67726 { INIT_THREAD_INFO(init_task) };
67727+#endif
67728diff --git a/init/initramfs.c b/init/initramfs.c
67729index 84c6bf1..8899338 100644
67730--- a/init/initramfs.c
67731+++ b/init/initramfs.c
67732@@ -84,7 +84,7 @@ static void __init free_hash(void)
67733 }
67734 }
67735
67736-static long __init do_utime(char *filename, time_t mtime)
67737+static long __init do_utime(char __force_user *filename, time_t mtime)
67738 {
67739 struct timespec t[2];
67740
67741@@ -119,7 +119,7 @@ static void __init dir_utime(void)
67742 struct dir_entry *de, *tmp;
67743 list_for_each_entry_safe(de, tmp, &dir_list, list) {
67744 list_del(&de->list);
67745- do_utime(de->name, de->mtime);
67746+ do_utime((char __force_user *)de->name, de->mtime);
67747 kfree(de->name);
67748 kfree(de);
67749 }
67750@@ -281,7 +281,7 @@ static int __init maybe_link(void)
67751 if (nlink >= 2) {
67752 char *old = find_link(major, minor, ino, mode, collected);
67753 if (old)
67754- return (sys_link(old, collected) < 0) ? -1 : 1;
67755+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
67756 }
67757 return 0;
67758 }
67759@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
67760 {
67761 struct stat st;
67762
67763- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
67764+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
67765 if (S_ISDIR(st.st_mode))
67766- sys_rmdir(path);
67767+ sys_rmdir((char __force_user *)path);
67768 else
67769- sys_unlink(path);
67770+ sys_unlink((char __force_user *)path);
67771 }
67772 }
67773
67774@@ -315,7 +315,7 @@ static int __init do_name(void)
67775 int openflags = O_WRONLY|O_CREAT;
67776 if (ml != 1)
67777 openflags |= O_TRUNC;
67778- wfd = sys_open(collected, openflags, mode);
67779+ wfd = sys_open((char __force_user *)collected, openflags, mode);
67780
67781 if (wfd >= 0) {
67782 sys_fchown(wfd, uid, gid);
67783@@ -327,17 +327,17 @@ static int __init do_name(void)
67784 }
67785 }
67786 } else if (S_ISDIR(mode)) {
67787- sys_mkdir(collected, mode);
67788- sys_chown(collected, uid, gid);
67789- sys_chmod(collected, mode);
67790+ sys_mkdir((char __force_user *)collected, mode);
67791+ sys_chown((char __force_user *)collected, uid, gid);
67792+ sys_chmod((char __force_user *)collected, mode);
67793 dir_add(collected, mtime);
67794 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
67795 S_ISFIFO(mode) || S_ISSOCK(mode)) {
67796 if (maybe_link() == 0) {
67797- sys_mknod(collected, mode, rdev);
67798- sys_chown(collected, uid, gid);
67799- sys_chmod(collected, mode);
67800- do_utime(collected, mtime);
67801+ sys_mknod((char __force_user *)collected, mode, rdev);
67802+ sys_chown((char __force_user *)collected, uid, gid);
67803+ sys_chmod((char __force_user *)collected, mode);
67804+ do_utime((char __force_user *)collected, mtime);
67805 }
67806 }
67807 return 0;
67808@@ -346,15 +346,15 @@ static int __init do_name(void)
67809 static int __init do_copy(void)
67810 {
67811 if (count >= body_len) {
67812- sys_write(wfd, victim, body_len);
67813+ sys_write(wfd, (char __force_user *)victim, body_len);
67814 sys_close(wfd);
67815- do_utime(vcollected, mtime);
67816+ do_utime((char __force_user *)vcollected, mtime);
67817 kfree(vcollected);
67818 eat(body_len);
67819 state = SkipIt;
67820 return 0;
67821 } else {
67822- sys_write(wfd, victim, count);
67823+ sys_write(wfd, (char __force_user *)victim, count);
67824 body_len -= count;
67825 eat(count);
67826 return 1;
67827@@ -365,9 +365,9 @@ static int __init do_symlink(void)
67828 {
67829 collected[N_ALIGN(name_len) + body_len] = '\0';
67830 clean_path(collected, 0);
67831- sys_symlink(collected + N_ALIGN(name_len), collected);
67832- sys_lchown(collected, uid, gid);
67833- do_utime(collected, mtime);
67834+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
67835+ sys_lchown((char __force_user *)collected, uid, gid);
67836+ do_utime((char __force_user *)collected, mtime);
67837 state = SkipIt;
67838 next_state = Reset;
67839 return 0;
67840diff --git a/init/main.c b/init/main.c
67841index 857166f..9df1d8e 100644
67842--- a/init/main.c
67843+++ b/init/main.c
67844@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
67845 extern void tc_init(void);
67846 #endif
67847
67848+extern void grsecurity_init(void);
67849+
67850 /*
67851 * Debug helper: via this flag we know that we are in 'early bootup code'
67852 * where only the boot processor is running with IRQ disabled. This means
67853@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
67854
67855 __setup("reset_devices", set_reset_devices);
67856
67857+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67858+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
67859+static int __init setup_grsec_proc_gid(char *str)
67860+{
67861+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
67862+ return 1;
67863+}
67864+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
67865+#endif
67866+
67867+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
67868+extern char pax_enter_kernel_user[];
67869+extern char pax_exit_kernel_user[];
67870+extern pgdval_t clone_pgd_mask;
67871+#endif
67872+
67873+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
67874+static int __init setup_pax_nouderef(char *str)
67875+{
67876+#ifdef CONFIG_X86_32
67877+ unsigned int cpu;
67878+ struct desc_struct *gdt;
67879+
67880+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
67881+ gdt = get_cpu_gdt_table(cpu);
67882+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
67883+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
67884+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
67885+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
67886+ }
67887+ loadsegment(ds, __KERNEL_DS);
67888+ loadsegment(es, __KERNEL_DS);
67889+ loadsegment(ss, __KERNEL_DS);
67890+#else
67891+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
67892+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
67893+ clone_pgd_mask = ~(pgdval_t)0UL;
67894+#endif
67895+
67896+ return 0;
67897+}
67898+early_param("pax_nouderef", setup_pax_nouderef);
67899+#endif
67900+
67901+#ifdef CONFIG_PAX_SOFTMODE
67902+int pax_softmode;
67903+
67904+static int __init setup_pax_softmode(char *str)
67905+{
67906+ get_option(&str, &pax_softmode);
67907+ return 1;
67908+}
67909+__setup("pax_softmode=", setup_pax_softmode);
67910+#endif
67911+
67912 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
67913 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
67914 static const char *panic_later, *panic_param;
67915@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
67916 {
67917 int count = preempt_count();
67918 int ret;
67919+ const char *msg1 = "", *msg2 = "";
67920
67921 if (initcall_debug)
67922 ret = do_one_initcall_debug(fn);
67923@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
67924 sprintf(msgbuf, "error code %d ", ret);
67925
67926 if (preempt_count() != count) {
67927- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
67928+ msg1 = " preemption imbalance";
67929 preempt_count() = count;
67930 }
67931 if (irqs_disabled()) {
67932- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
67933+ msg2 = " disabled interrupts";
67934 local_irq_enable();
67935 }
67936- if (msgbuf[0]) {
67937- printk("initcall %pF returned with %s\n", fn, msgbuf);
67938+ if (msgbuf[0] || *msg1 || *msg2) {
67939+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
67940 }
67941
67942 return ret;
67943@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
67944 "late",
67945 };
67946
67947+#ifdef CONFIG_PAX_LATENT_ENTROPY
67948+u64 latent_entropy;
67949+#endif
67950+
67951 static void __init do_initcall_level(int level)
67952 {
67953 extern const struct kernel_param __start___param[], __stop___param[];
67954@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
67955 level, level,
67956 &repair_env_string);
67957
67958- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
67959+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
67960 do_one_initcall(*fn);
67961+
67962+#ifdef CONFIG_PAX_LATENT_ENTROPY
67963+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67964+#endif
67965+
67966+ }
67967 }
67968
67969 static void __init do_initcalls(void)
67970@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
67971 {
67972 initcall_t *fn;
67973
67974- for (fn = __initcall_start; fn < __initcall0_start; fn++)
67975+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
67976 do_one_initcall(*fn);
67977+
67978+#ifdef CONFIG_PAX_LATENT_ENTROPY
67979+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67980+#endif
67981+
67982+ }
67983 }
67984
67985 static int run_init_process(const char *init_filename)
67986@@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
67987 do_basic_setup();
67988
67989 /* Open the /dev/console on the rootfs, this should never fail */
67990- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
67991+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
67992 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
67993
67994 (void) sys_dup(0);
67995@@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
67996 if (!ramdisk_execute_command)
67997 ramdisk_execute_command = "/init";
67998
67999- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68000+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68001 ramdisk_execute_command = NULL;
68002 prepare_namespace();
68003 }
68004
68005+ grsecurity_init();
68006+
68007 /*
68008 * Ok, we have completed the initial bootup, and
68009 * we're essentially up and running. Get rid of the
68010diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68011index 71a3ca1..cc330ee 100644
68012--- a/ipc/mqueue.c
68013+++ b/ipc/mqueue.c
68014@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68015 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68016 info->attr.mq_msgsize);
68017
68018+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68019 spin_lock(&mq_lock);
68020 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68021 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68022diff --git a/ipc/msg.c b/ipc/msg.c
68023index a71af5a..a90a110 100644
68024--- a/ipc/msg.c
68025+++ b/ipc/msg.c
68026@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68027 return security_msg_queue_associate(msq, msgflg);
68028 }
68029
68030+static struct ipc_ops msg_ops = {
68031+ .getnew = newque,
68032+ .associate = msg_security,
68033+ .more_checks = NULL
68034+};
68035+
68036 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68037 {
68038 struct ipc_namespace *ns;
68039- struct ipc_ops msg_ops;
68040 struct ipc_params msg_params;
68041
68042 ns = current->nsproxy->ipc_ns;
68043
68044- msg_ops.getnew = newque;
68045- msg_ops.associate = msg_security;
68046- msg_ops.more_checks = NULL;
68047-
68048 msg_params.key = key;
68049 msg_params.flg = msgflg;
68050
68051diff --git a/ipc/sem.c b/ipc/sem.c
68052index 58d31f1..cce7a55 100644
68053--- a/ipc/sem.c
68054+++ b/ipc/sem.c
68055@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68056 return 0;
68057 }
68058
68059+static struct ipc_ops sem_ops = {
68060+ .getnew = newary,
68061+ .associate = sem_security,
68062+ .more_checks = sem_more_checks
68063+};
68064+
68065 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68066 {
68067 struct ipc_namespace *ns;
68068- struct ipc_ops sem_ops;
68069 struct ipc_params sem_params;
68070
68071 ns = current->nsproxy->ipc_ns;
68072@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68073 if (nsems < 0 || nsems > ns->sc_semmsl)
68074 return -EINVAL;
68075
68076- sem_ops.getnew = newary;
68077- sem_ops.associate = sem_security;
68078- sem_ops.more_checks = sem_more_checks;
68079-
68080 sem_params.key = key;
68081 sem_params.flg = semflg;
68082 sem_params.u.nsems = nsems;
68083diff --git a/ipc/shm.c b/ipc/shm.c
68084index dff40c9..9450e27 100644
68085--- a/ipc/shm.c
68086+++ b/ipc/shm.c
68087@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68088 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68089 #endif
68090
68091+#ifdef CONFIG_GRKERNSEC
68092+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68093+ const time_t shm_createtime, const uid_t cuid,
68094+ const int shmid);
68095+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68096+ const time_t shm_createtime);
68097+#endif
68098+
68099 void shm_init_ns(struct ipc_namespace *ns)
68100 {
68101 ns->shm_ctlmax = SHMMAX;
68102@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68103 shp->shm_lprid = 0;
68104 shp->shm_atim = shp->shm_dtim = 0;
68105 shp->shm_ctim = get_seconds();
68106+#ifdef CONFIG_GRKERNSEC
68107+ {
68108+ struct timespec timeval;
68109+ do_posix_clock_monotonic_gettime(&timeval);
68110+
68111+ shp->shm_createtime = timeval.tv_sec;
68112+ }
68113+#endif
68114 shp->shm_segsz = size;
68115 shp->shm_nattch = 0;
68116 shp->shm_file = file;
68117@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68118 return 0;
68119 }
68120
68121+static struct ipc_ops shm_ops = {
68122+ .getnew = newseg,
68123+ .associate = shm_security,
68124+ .more_checks = shm_more_checks
68125+};
68126+
68127 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68128 {
68129 struct ipc_namespace *ns;
68130- struct ipc_ops shm_ops;
68131 struct ipc_params shm_params;
68132
68133 ns = current->nsproxy->ipc_ns;
68134
68135- shm_ops.getnew = newseg;
68136- shm_ops.associate = shm_security;
68137- shm_ops.more_checks = shm_more_checks;
68138-
68139 shm_params.key = key;
68140 shm_params.flg = shmflg;
68141 shm_params.u.size = size;
68142@@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68143 f_mode = FMODE_READ | FMODE_WRITE;
68144 }
68145 if (shmflg & SHM_EXEC) {
68146+
68147+#ifdef CONFIG_PAX_MPROTECT
68148+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
68149+ goto out;
68150+#endif
68151+
68152 prot |= PROT_EXEC;
68153 acc_mode |= S_IXUGO;
68154 }
68155@@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68156 if (err)
68157 goto out_unlock;
68158
68159+#ifdef CONFIG_GRKERNSEC
68160+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68161+ shp->shm_perm.cuid, shmid) ||
68162+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68163+ err = -EACCES;
68164+ goto out_unlock;
68165+ }
68166+#endif
68167+
68168 path = shp->shm_file->f_path;
68169 path_get(&path);
68170 shp->shm_nattch++;
68171+#ifdef CONFIG_GRKERNSEC
68172+ shp->shm_lapid = current->pid;
68173+#endif
68174 size = i_size_read(path.dentry->d_inode);
68175 shm_unlock(shp);
68176
68177diff --git a/kernel/acct.c b/kernel/acct.c
68178index 051e071..15e0920 100644
68179--- a/kernel/acct.c
68180+++ b/kernel/acct.c
68181@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68182 */
68183 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68184 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68185- file->f_op->write(file, (char *)&ac,
68186+ file->f_op->write(file, (char __force_user *)&ac,
68187 sizeof(acct_t), &file->f_pos);
68188 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68189 set_fs(fs);
68190diff --git a/kernel/audit.c b/kernel/audit.c
68191index 40414e9..c920b72 100644
68192--- a/kernel/audit.c
68193+++ b/kernel/audit.c
68194@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68195 3) suppressed due to audit_rate_limit
68196 4) suppressed due to audit_backlog_limit
68197 */
68198-static atomic_t audit_lost = ATOMIC_INIT(0);
68199+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68200
68201 /* The netlink socket. */
68202 static struct sock *audit_sock;
68203@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68204 unsigned long now;
68205 int print;
68206
68207- atomic_inc(&audit_lost);
68208+ atomic_inc_unchecked(&audit_lost);
68209
68210 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68211
68212@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68213 printk(KERN_WARNING
68214 "audit: audit_lost=%d audit_rate_limit=%d "
68215 "audit_backlog_limit=%d\n",
68216- atomic_read(&audit_lost),
68217+ atomic_read_unchecked(&audit_lost),
68218 audit_rate_limit,
68219 audit_backlog_limit);
68220 audit_panic(message);
68221@@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68222 status_set.pid = audit_pid;
68223 status_set.rate_limit = audit_rate_limit;
68224 status_set.backlog_limit = audit_backlog_limit;
68225- status_set.lost = atomic_read(&audit_lost);
68226+ status_set.lost = atomic_read_unchecked(&audit_lost);
68227 status_set.backlog = skb_queue_len(&audit_skb_queue);
68228 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68229 &status_set, sizeof(status_set));
68230diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68231index 157e989..b28b365 100644
68232--- a/kernel/auditsc.c
68233+++ b/kernel/auditsc.c
68234@@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68235 }
68236
68237 /* global counter which is incremented every time something logs in */
68238-static atomic_t session_id = ATOMIC_INIT(0);
68239+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68240
68241 /**
68242 * audit_set_loginuid - set current task's audit_context loginuid
68243@@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68244 return -EPERM;
68245 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68246
68247- sessionid = atomic_inc_return(&session_id);
68248+ sessionid = atomic_inc_return_unchecked(&session_id);
68249 if (context && context->in_syscall) {
68250 struct audit_buffer *ab;
68251
68252diff --git a/kernel/capability.c b/kernel/capability.c
68253index 493d972..ea17248 100644
68254--- a/kernel/capability.c
68255+++ b/kernel/capability.c
68256@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68257 * before modification is attempted and the application
68258 * fails.
68259 */
68260+ if (tocopy > ARRAY_SIZE(kdata))
68261+ return -EFAULT;
68262+
68263 if (copy_to_user(dataptr, kdata, tocopy
68264 * sizeof(struct __user_cap_data_struct))) {
68265 return -EFAULT;
68266@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68267 int ret;
68268
68269 rcu_read_lock();
68270- ret = security_capable(__task_cred(t), ns, cap);
68271+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68272+ gr_task_is_capable(t, __task_cred(t), cap);
68273 rcu_read_unlock();
68274
68275- return (ret == 0);
68276+ return ret;
68277 }
68278
68279 /**
68280@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68281 int ret;
68282
68283 rcu_read_lock();
68284- ret = security_capable_noaudit(__task_cred(t), ns, cap);
68285+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68286 rcu_read_unlock();
68287
68288- return (ret == 0);
68289+ return ret;
68290 }
68291
68292 /**
68293@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68294 BUG();
68295 }
68296
68297- if (security_capable(current_cred(), ns, cap) == 0) {
68298+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68299 current->flags |= PF_SUPERPRIV;
68300 return true;
68301 }
68302@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68303 }
68304 EXPORT_SYMBOL(ns_capable);
68305
68306+bool ns_capable_nolog(struct user_namespace *ns, int cap)
68307+{
68308+ if (unlikely(!cap_valid(cap))) {
68309+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68310+ BUG();
68311+ }
68312+
68313+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68314+ current->flags |= PF_SUPERPRIV;
68315+ return true;
68316+ }
68317+ return false;
68318+}
68319+EXPORT_SYMBOL(ns_capable_nolog);
68320+
68321 /**
68322 * capable - Determine if the current task has a superior capability in effect
68323 * @cap: The capability to be tested for
68324@@ -408,6 +427,12 @@ bool capable(int cap)
68325 }
68326 EXPORT_SYMBOL(capable);
68327
68328+bool capable_nolog(int cap)
68329+{
68330+ return ns_capable_nolog(&init_user_ns, cap);
68331+}
68332+EXPORT_SYMBOL(capable_nolog);
68333+
68334 /**
68335 * nsown_capable - Check superior capability to one's own user_ns
68336 * @cap: The capability in question
68337@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68338
68339 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68340 }
68341+
68342+bool inode_capable_nolog(const struct inode *inode, int cap)
68343+{
68344+ struct user_namespace *ns = current_user_ns();
68345+
68346+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68347+}
68348diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68349index ad99830..992d8a7 100644
68350--- a/kernel/cgroup.c
68351+++ b/kernel/cgroup.c
68352@@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68353 struct css_set *cg = link->cg;
68354 struct task_struct *task;
68355 int count = 0;
68356- seq_printf(seq, "css_set %p\n", cg);
68357+ seq_printf(seq, "css_set %pK\n", cg);
68358 list_for_each_entry(task, &cg->tasks, cg_list) {
68359 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68360 seq_puts(seq, " ...\n");
68361diff --git a/kernel/compat.c b/kernel/compat.c
68362index c28a306..b4d0cf3 100644
68363--- a/kernel/compat.c
68364+++ b/kernel/compat.c
68365@@ -13,6 +13,7 @@
68366
68367 #include <linux/linkage.h>
68368 #include <linux/compat.h>
68369+#include <linux/module.h>
68370 #include <linux/errno.h>
68371 #include <linux/time.h>
68372 #include <linux/signal.h>
68373@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68374 mm_segment_t oldfs;
68375 long ret;
68376
68377- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68378+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68379 oldfs = get_fs();
68380 set_fs(KERNEL_DS);
68381 ret = hrtimer_nanosleep_restart(restart);
68382@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68383 oldfs = get_fs();
68384 set_fs(KERNEL_DS);
68385 ret = hrtimer_nanosleep(&tu,
68386- rmtp ? (struct timespec __user *)&rmt : NULL,
68387+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
68388 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68389 set_fs(oldfs);
68390
68391@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68392 mm_segment_t old_fs = get_fs();
68393
68394 set_fs(KERNEL_DS);
68395- ret = sys_sigpending((old_sigset_t __user *) &s);
68396+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
68397 set_fs(old_fs);
68398 if (ret == 0)
68399 ret = put_user(s, set);
68400@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68401 mm_segment_t old_fs = get_fs();
68402
68403 set_fs(KERNEL_DS);
68404- ret = sys_old_getrlimit(resource, &r);
68405+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68406 set_fs(old_fs);
68407
68408 if (!ret) {
68409@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68410 mm_segment_t old_fs = get_fs();
68411
68412 set_fs(KERNEL_DS);
68413- ret = sys_getrusage(who, (struct rusage __user *) &r);
68414+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68415 set_fs(old_fs);
68416
68417 if (ret)
68418@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68419 set_fs (KERNEL_DS);
68420 ret = sys_wait4(pid,
68421 (stat_addr ?
68422- (unsigned int __user *) &status : NULL),
68423- options, (struct rusage __user *) &r);
68424+ (unsigned int __force_user *) &status : NULL),
68425+ options, (struct rusage __force_user *) &r);
68426 set_fs (old_fs);
68427
68428 if (ret > 0) {
68429@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68430 memset(&info, 0, sizeof(info));
68431
68432 set_fs(KERNEL_DS);
68433- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68434- uru ? (struct rusage __user *)&ru : NULL);
68435+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68436+ uru ? (struct rusage __force_user *)&ru : NULL);
68437 set_fs(old_fs);
68438
68439 if ((ret < 0) || (info.si_signo == 0))
68440@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68441 oldfs = get_fs();
68442 set_fs(KERNEL_DS);
68443 err = sys_timer_settime(timer_id, flags,
68444- (struct itimerspec __user *) &newts,
68445- (struct itimerspec __user *) &oldts);
68446+ (struct itimerspec __force_user *) &newts,
68447+ (struct itimerspec __force_user *) &oldts);
68448 set_fs(oldfs);
68449 if (!err && old && put_compat_itimerspec(old, &oldts))
68450 return -EFAULT;
68451@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68452 oldfs = get_fs();
68453 set_fs(KERNEL_DS);
68454 err = sys_timer_gettime(timer_id,
68455- (struct itimerspec __user *) &ts);
68456+ (struct itimerspec __force_user *) &ts);
68457 set_fs(oldfs);
68458 if (!err && put_compat_itimerspec(setting, &ts))
68459 return -EFAULT;
68460@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68461 oldfs = get_fs();
68462 set_fs(KERNEL_DS);
68463 err = sys_clock_settime(which_clock,
68464- (struct timespec __user *) &ts);
68465+ (struct timespec __force_user *) &ts);
68466 set_fs(oldfs);
68467 return err;
68468 }
68469@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68470 oldfs = get_fs();
68471 set_fs(KERNEL_DS);
68472 err = sys_clock_gettime(which_clock,
68473- (struct timespec __user *) &ts);
68474+ (struct timespec __force_user *) &ts);
68475 set_fs(oldfs);
68476 if (!err && put_compat_timespec(&ts, tp))
68477 return -EFAULT;
68478@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68479
68480 oldfs = get_fs();
68481 set_fs(KERNEL_DS);
68482- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68483+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68484 set_fs(oldfs);
68485
68486 err = compat_put_timex(utp, &txc);
68487@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68488 oldfs = get_fs();
68489 set_fs(KERNEL_DS);
68490 err = sys_clock_getres(which_clock,
68491- (struct timespec __user *) &ts);
68492+ (struct timespec __force_user *) &ts);
68493 set_fs(oldfs);
68494 if (!err && tp && put_compat_timespec(&ts, tp))
68495 return -EFAULT;
68496@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68497 long err;
68498 mm_segment_t oldfs;
68499 struct timespec tu;
68500- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68501+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68502
68503- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68504+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68505 oldfs = get_fs();
68506 set_fs(KERNEL_DS);
68507 err = clock_nanosleep_restart(restart);
68508@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68509 oldfs = get_fs();
68510 set_fs(KERNEL_DS);
68511 err = sys_clock_nanosleep(which_clock, flags,
68512- (struct timespec __user *) &in,
68513- (struct timespec __user *) &out);
68514+ (struct timespec __force_user *) &in,
68515+ (struct timespec __force_user *) &out);
68516 set_fs(oldfs);
68517
68518 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68519diff --git a/kernel/configs.c b/kernel/configs.c
68520index 42e8fa0..9e7406b 100644
68521--- a/kernel/configs.c
68522+++ b/kernel/configs.c
68523@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68524 struct proc_dir_entry *entry;
68525
68526 /* create the current config file */
68527+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68528+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68529+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68530+ &ikconfig_file_ops);
68531+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68532+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68533+ &ikconfig_file_ops);
68534+#endif
68535+#else
68536 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68537 &ikconfig_file_ops);
68538+#endif
68539+
68540 if (!entry)
68541 return -ENOMEM;
68542
68543diff --git a/kernel/cred.c b/kernel/cred.c
68544index 48cea3d..3476734 100644
68545--- a/kernel/cred.c
68546+++ b/kernel/cred.c
68547@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68548 validate_creds(cred);
68549 alter_cred_subscribers(cred, -1);
68550 put_cred(cred);
68551+
68552+#ifdef CONFIG_GRKERNSEC_SETXID
68553+ cred = (struct cred *) tsk->delayed_cred;
68554+ if (cred != NULL) {
68555+ tsk->delayed_cred = NULL;
68556+ validate_creds(cred);
68557+ alter_cred_subscribers(cred, -1);
68558+ put_cred(cred);
68559+ }
68560+#endif
68561 }
68562
68563 /**
68564@@ -469,7 +479,7 @@ error_put:
68565 * Always returns 0 thus allowing this function to be tail-called at the end
68566 * of, say, sys_setgid().
68567 */
68568-int commit_creds(struct cred *new)
68569+static int __commit_creds(struct cred *new)
68570 {
68571 struct task_struct *task = current;
68572 const struct cred *old = task->real_cred;
68573@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68574
68575 get_cred(new); /* we will require a ref for the subj creds too */
68576
68577+ gr_set_role_label(task, new->uid, new->gid);
68578+
68579 /* dumpability changes */
68580 if (!uid_eq(old->euid, new->euid) ||
68581 !gid_eq(old->egid, new->egid) ||
68582@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68583 put_cred(old);
68584 return 0;
68585 }
68586+#ifdef CONFIG_GRKERNSEC_SETXID
68587+extern int set_user(struct cred *new);
68588+
68589+void gr_delayed_cred_worker(void)
68590+{
68591+ const struct cred *new = current->delayed_cred;
68592+ struct cred *ncred;
68593+
68594+ current->delayed_cred = NULL;
68595+
68596+ if (current_uid() && new != NULL) {
68597+ // from doing get_cred on it when queueing this
68598+ put_cred(new);
68599+ return;
68600+ } else if (new == NULL)
68601+ return;
68602+
68603+ ncred = prepare_creds();
68604+ if (!ncred)
68605+ goto die;
68606+ // uids
68607+ ncred->uid = new->uid;
68608+ ncred->euid = new->euid;
68609+ ncred->suid = new->suid;
68610+ ncred->fsuid = new->fsuid;
68611+ // gids
68612+ ncred->gid = new->gid;
68613+ ncred->egid = new->egid;
68614+ ncred->sgid = new->sgid;
68615+ ncred->fsgid = new->fsgid;
68616+ // groups
68617+ if (set_groups(ncred, new->group_info) < 0) {
68618+ abort_creds(ncred);
68619+ goto die;
68620+ }
68621+ // caps
68622+ ncred->securebits = new->securebits;
68623+ ncred->cap_inheritable = new->cap_inheritable;
68624+ ncred->cap_permitted = new->cap_permitted;
68625+ ncred->cap_effective = new->cap_effective;
68626+ ncred->cap_bset = new->cap_bset;
68627+
68628+ if (set_user(ncred)) {
68629+ abort_creds(ncred);
68630+ goto die;
68631+ }
68632+
68633+ // from doing get_cred on it when queueing this
68634+ put_cred(new);
68635+
68636+ __commit_creds(ncred);
68637+ return;
68638+die:
68639+ // from doing get_cred on it when queueing this
68640+ put_cred(new);
68641+ do_group_exit(SIGKILL);
68642+}
68643+#endif
68644+
68645+int commit_creds(struct cred *new)
68646+{
68647+#ifdef CONFIG_GRKERNSEC_SETXID
68648+ int ret;
68649+ int schedule_it = 0;
68650+ struct task_struct *t;
68651+
68652+ /* we won't get called with tasklist_lock held for writing
68653+ and interrupts disabled as the cred struct in that case is
68654+ init_cred
68655+ */
68656+ if (grsec_enable_setxid && !current_is_single_threaded() &&
68657+ !current_uid() && new->uid) {
68658+ schedule_it = 1;
68659+ }
68660+ ret = __commit_creds(new);
68661+ if (schedule_it) {
68662+ rcu_read_lock();
68663+ read_lock(&tasklist_lock);
68664+ for (t = next_thread(current); t != current;
68665+ t = next_thread(t)) {
68666+ if (t->delayed_cred == NULL) {
68667+ t->delayed_cred = get_cred(new);
68668+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68669+ set_tsk_need_resched(t);
68670+ }
68671+ }
68672+ read_unlock(&tasklist_lock);
68673+ rcu_read_unlock();
68674+ }
68675+ return ret;
68676+#else
68677+ return __commit_creds(new);
68678+#endif
68679+}
68680+
68681 EXPORT_SYMBOL(commit_creds);
68682
68683 /**
68684diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68685index 9a61738..c5c8f3a 100644
68686--- a/kernel/debug/debug_core.c
68687+++ b/kernel/debug/debug_core.c
68688@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68689 */
68690 static atomic_t masters_in_kgdb;
68691 static atomic_t slaves_in_kgdb;
68692-static atomic_t kgdb_break_tasklet_var;
68693+static atomic_unchecked_t kgdb_break_tasklet_var;
68694 atomic_t kgdb_setting_breakpoint;
68695
68696 struct task_struct *kgdb_usethread;
68697@@ -132,7 +132,7 @@ int kgdb_single_step;
68698 static pid_t kgdb_sstep_pid;
68699
68700 /* to keep track of the CPU which is doing the single stepping*/
68701-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68702+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68703
68704 /*
68705 * If you are debugging a problem where roundup (the collection of
68706@@ -540,7 +540,7 @@ return_normal:
68707 * kernel will only try for the value of sstep_tries before
68708 * giving up and continuing on.
68709 */
68710- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68711+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68712 (kgdb_info[cpu].task &&
68713 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68714 atomic_set(&kgdb_active, -1);
68715@@ -634,8 +634,8 @@ cpu_master_loop:
68716 }
68717
68718 kgdb_restore:
68719- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68720- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68721+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68722+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68723 if (kgdb_info[sstep_cpu].task)
68724 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68725 else
68726@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
68727 static void kgdb_tasklet_bpt(unsigned long ing)
68728 {
68729 kgdb_breakpoint();
68730- atomic_set(&kgdb_break_tasklet_var, 0);
68731+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
68732 }
68733
68734 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
68735
68736 void kgdb_schedule_breakpoint(void)
68737 {
68738- if (atomic_read(&kgdb_break_tasklet_var) ||
68739+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
68740 atomic_read(&kgdb_active) != -1 ||
68741 atomic_read(&kgdb_setting_breakpoint))
68742 return;
68743- atomic_inc(&kgdb_break_tasklet_var);
68744+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
68745 tasklet_schedule(&kgdb_tasklet_breakpoint);
68746 }
68747 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
68748diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
68749index 8875254..7cf4928 100644
68750--- a/kernel/debug/kdb/kdb_main.c
68751+++ b/kernel/debug/kdb/kdb_main.c
68752@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
68753 continue;
68754
68755 kdb_printf("%-20s%8u 0x%p ", mod->name,
68756- mod->core_size, (void *)mod);
68757+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
68758 #ifdef CONFIG_MODULE_UNLOAD
68759 kdb_printf("%4ld ", module_refcount(mod));
68760 #endif
68761@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
68762 kdb_printf(" (Loading)");
68763 else
68764 kdb_printf(" (Live)");
68765- kdb_printf(" 0x%p", mod->module_core);
68766+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68767
68768 #ifdef CONFIG_MODULE_UNLOAD
68769 {
68770diff --git a/kernel/events/core.c b/kernel/events/core.c
68771index dbccf83..8c66482 100644
68772--- a/kernel/events/core.c
68773+++ b/kernel/events/core.c
68774@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
68775 return 0;
68776 }
68777
68778-static atomic64_t perf_event_id;
68779+static atomic64_unchecked_t perf_event_id;
68780
68781 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68782 enum event_type_t event_type);
68783@@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
68784
68785 static inline u64 perf_event_count(struct perf_event *event)
68786 {
68787- return local64_read(&event->count) + atomic64_read(&event->child_count);
68788+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68789 }
68790
68791 static u64 perf_event_read(struct perf_event *event)
68792@@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
68793 mutex_lock(&event->child_mutex);
68794 total += perf_event_read(event);
68795 *enabled += event->total_time_enabled +
68796- atomic64_read(&event->child_total_time_enabled);
68797+ atomic64_read_unchecked(&event->child_total_time_enabled);
68798 *running += event->total_time_running +
68799- atomic64_read(&event->child_total_time_running);
68800+ atomic64_read_unchecked(&event->child_total_time_running);
68801
68802 list_for_each_entry(child, &event->child_list, child_list) {
68803 total += perf_event_read(child);
68804@@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
68805 userpg->offset -= local64_read(&event->hw.prev_count);
68806
68807 userpg->time_enabled = enabled +
68808- atomic64_read(&event->child_total_time_enabled);
68809+ atomic64_read_unchecked(&event->child_total_time_enabled);
68810
68811 userpg->time_running = running +
68812- atomic64_read(&event->child_total_time_running);
68813+ atomic64_read_unchecked(&event->child_total_time_running);
68814
68815 arch_perf_update_userpage(userpg, now);
68816
68817@@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
68818 values[n++] = perf_event_count(event);
68819 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68820 values[n++] = enabled +
68821- atomic64_read(&event->child_total_time_enabled);
68822+ atomic64_read_unchecked(&event->child_total_time_enabled);
68823 }
68824 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68825 values[n++] = running +
68826- atomic64_read(&event->child_total_time_running);
68827+ atomic64_read_unchecked(&event->child_total_time_running);
68828 }
68829 if (read_format & PERF_FORMAT_ID)
68830 values[n++] = primary_event_id(event);
68831@@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
68832 * need to add enough zero bytes after the string to handle
68833 * the 64bit alignment we do later.
68834 */
68835- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
68836+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
68837 if (!buf) {
68838 name = strncpy(tmp, "//enomem", sizeof(tmp));
68839 goto got_name;
68840 }
68841- name = d_path(&file->f_path, buf, PATH_MAX);
68842+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
68843 if (IS_ERR(name)) {
68844 name = strncpy(tmp, "//toolong", sizeof(tmp));
68845 goto got_name;
68846@@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
68847 event->parent = parent_event;
68848
68849 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68850- event->id = atomic64_inc_return(&perf_event_id);
68851+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
68852
68853 event->state = PERF_EVENT_STATE_INACTIVE;
68854
68855@@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
68856 /*
68857 * Add back the child's count to the parent's count:
68858 */
68859- atomic64_add(child_val, &parent_event->child_count);
68860- atomic64_add(child_event->total_time_enabled,
68861+ atomic64_add_unchecked(child_val, &parent_event->child_count);
68862+ atomic64_add_unchecked(child_event->total_time_enabled,
68863 &parent_event->child_total_time_enabled);
68864- atomic64_add(child_event->total_time_running,
68865+ atomic64_add_unchecked(child_event->total_time_running,
68866 &parent_event->child_total_time_running);
68867
68868 /*
68869diff --git a/kernel/exit.c b/kernel/exit.c
68870index 346616c..f103b28 100644
68871--- a/kernel/exit.c
68872+++ b/kernel/exit.c
68873@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
68874 struct task_struct *leader;
68875 int zap_leader;
68876 repeat:
68877+#ifdef CONFIG_NET
68878+ gr_del_task_from_ip_table(p);
68879+#endif
68880+
68881 /* don't need to get the RCU readlock here - the process is dead and
68882 * can't be modifying its own credentials. But shut RCU-lockdep up */
68883 rcu_read_lock();
68884@@ -394,7 +398,7 @@ int allow_signal(int sig)
68885 * know it'll be handled, so that they don't get converted to
68886 * SIGKILL or just silently dropped.
68887 */
68888- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
68889+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
68890 recalc_sigpending();
68891 spin_unlock_irq(&current->sighand->siglock);
68892 return 0;
68893@@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
68894 vsnprintf(current->comm, sizeof(current->comm), name, args);
68895 va_end(args);
68896
68897+ gr_put_exec_file(current);
68898+ gr_set_kernel_label(current);
68899+
68900 /*
68901 * If we were started as result of loading a module, close all of the
68902 * user space pages. We don't need them, and if we didn't close them
68903@@ -812,6 +819,8 @@ void do_exit(long code)
68904 struct task_struct *tsk = current;
68905 int group_dead;
68906
68907+ set_fs(USER_DS);
68908+
68909 profile_task_exit(tsk);
68910
68911 WARN_ON(blk_needs_flush_plug(tsk));
68912@@ -828,7 +837,6 @@ void do_exit(long code)
68913 * mm_release()->clear_child_tid() from writing to a user-controlled
68914 * kernel address.
68915 */
68916- set_fs(USER_DS);
68917
68918 ptrace_event(PTRACE_EVENT_EXIT, code);
68919
68920@@ -887,6 +895,9 @@ void do_exit(long code)
68921 tsk->exit_code = code;
68922 taskstats_exit(tsk, group_dead);
68923
68924+ gr_acl_handle_psacct(tsk, code);
68925+ gr_acl_handle_exit();
68926+
68927 exit_mm(tsk);
68928
68929 if (group_dead)
68930@@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
68931 * Take down every thread in the group. This is called by fatal signals
68932 * as well as by sys_exit_group (below).
68933 */
68934-void
68935+__noreturn void
68936 do_group_exit(int exit_code)
68937 {
68938 struct signal_struct *sig = current->signal;
68939diff --git a/kernel/fork.c b/kernel/fork.c
68940index acc4cb6..b524cb5 100644
68941--- a/kernel/fork.c
68942+++ b/kernel/fork.c
68943@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
68944 *stackend = STACK_END_MAGIC; /* for overflow detection */
68945
68946 #ifdef CONFIG_CC_STACKPROTECTOR
68947- tsk->stack_canary = get_random_int();
68948+ tsk->stack_canary = pax_get_random_long();
68949 #endif
68950
68951 /*
68952@@ -344,13 +344,81 @@ free_tsk:
68953 }
68954
68955 #ifdef CONFIG_MMU
68956+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
68957+{
68958+ struct vm_area_struct *tmp;
68959+ unsigned long charge;
68960+ struct mempolicy *pol;
68961+ struct file *file;
68962+
68963+ charge = 0;
68964+ if (mpnt->vm_flags & VM_ACCOUNT) {
68965+ unsigned long len = vma_pages(mpnt);
68966+
68967+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
68968+ goto fail_nomem;
68969+ charge = len;
68970+ }
68971+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
68972+ if (!tmp)
68973+ goto fail_nomem;
68974+ *tmp = *mpnt;
68975+ tmp->vm_mm = mm;
68976+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
68977+ pol = mpol_dup(vma_policy(mpnt));
68978+ if (IS_ERR(pol))
68979+ goto fail_nomem_policy;
68980+ vma_set_policy(tmp, pol);
68981+ if (anon_vma_fork(tmp, mpnt))
68982+ goto fail_nomem_anon_vma_fork;
68983+ tmp->vm_flags &= ~VM_LOCKED;
68984+ tmp->vm_next = tmp->vm_prev = NULL;
68985+ tmp->vm_mirror = NULL;
68986+ file = tmp->vm_file;
68987+ if (file) {
68988+ struct inode *inode = file->f_path.dentry->d_inode;
68989+ struct address_space *mapping = file->f_mapping;
68990+
68991+ get_file(file);
68992+ if (tmp->vm_flags & VM_DENYWRITE)
68993+ atomic_dec(&inode->i_writecount);
68994+ mutex_lock(&mapping->i_mmap_mutex);
68995+ if (tmp->vm_flags & VM_SHARED)
68996+ mapping->i_mmap_writable++;
68997+ flush_dcache_mmap_lock(mapping);
68998+ /* insert tmp into the share list, just after mpnt */
68999+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69000+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69001+ else
69002+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69003+ flush_dcache_mmap_unlock(mapping);
69004+ mutex_unlock(&mapping->i_mmap_mutex);
69005+ }
69006+
69007+ /*
69008+ * Clear hugetlb-related page reserves for children. This only
69009+ * affects MAP_PRIVATE mappings. Faults generated by the child
69010+ * are not guaranteed to succeed, even if read-only
69011+ */
69012+ if (is_vm_hugetlb_page(tmp))
69013+ reset_vma_resv_huge_pages(tmp);
69014+
69015+ return tmp;
69016+
69017+fail_nomem_anon_vma_fork:
69018+ mpol_put(pol);
69019+fail_nomem_policy:
69020+ kmem_cache_free(vm_area_cachep, tmp);
69021+fail_nomem:
69022+ vm_unacct_memory(charge);
69023+ return NULL;
69024+}
69025+
69026 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69027 {
69028 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69029 struct rb_node **rb_link, *rb_parent;
69030 int retval;
69031- unsigned long charge;
69032- struct mempolicy *pol;
69033
69034 down_write(&oldmm->mmap_sem);
69035 flush_cache_dup_mm(oldmm);
69036@@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69037 mm->locked_vm = 0;
69038 mm->mmap = NULL;
69039 mm->mmap_cache = NULL;
69040- mm->free_area_cache = oldmm->mmap_base;
69041- mm->cached_hole_size = ~0UL;
69042+ mm->free_area_cache = oldmm->free_area_cache;
69043+ mm->cached_hole_size = oldmm->cached_hole_size;
69044 mm->map_count = 0;
69045 cpumask_clear(mm_cpumask(mm));
69046 mm->mm_rb = RB_ROOT;
69047@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69048
69049 prev = NULL;
69050 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69051- struct file *file;
69052-
69053 if (mpnt->vm_flags & VM_DONTCOPY) {
69054 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69055 -vma_pages(mpnt));
69056 continue;
69057 }
69058- charge = 0;
69059- if (mpnt->vm_flags & VM_ACCOUNT) {
69060- unsigned long len = vma_pages(mpnt);
69061-
69062- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69063- goto fail_nomem;
69064- charge = len;
69065- }
69066- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69067- if (!tmp)
69068- goto fail_nomem;
69069- *tmp = *mpnt;
69070- INIT_LIST_HEAD(&tmp->anon_vma_chain);
69071- pol = mpol_dup(vma_policy(mpnt));
69072- retval = PTR_ERR(pol);
69073- if (IS_ERR(pol))
69074- goto fail_nomem_policy;
69075- vma_set_policy(tmp, pol);
69076- tmp->vm_mm = mm;
69077- if (anon_vma_fork(tmp, mpnt))
69078- goto fail_nomem_anon_vma_fork;
69079- tmp->vm_flags &= ~VM_LOCKED;
69080- tmp->vm_next = tmp->vm_prev = NULL;
69081- file = tmp->vm_file;
69082- if (file) {
69083- struct inode *inode = file->f_path.dentry->d_inode;
69084- struct address_space *mapping = file->f_mapping;
69085-
69086- get_file(file);
69087- if (tmp->vm_flags & VM_DENYWRITE)
69088- atomic_dec(&inode->i_writecount);
69089- mutex_lock(&mapping->i_mmap_mutex);
69090- if (tmp->vm_flags & VM_SHARED)
69091- mapping->i_mmap_writable++;
69092- flush_dcache_mmap_lock(mapping);
69093- /* insert tmp into the share list, just after mpnt */
69094- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69095- vma_nonlinear_insert(tmp,
69096- &mapping->i_mmap_nonlinear);
69097- else
69098- vma_interval_tree_insert_after(tmp, mpnt,
69099- &mapping->i_mmap);
69100- flush_dcache_mmap_unlock(mapping);
69101- mutex_unlock(&mapping->i_mmap_mutex);
69102+ tmp = dup_vma(mm, oldmm, mpnt);
69103+ if (!tmp) {
69104+ retval = -ENOMEM;
69105+ goto out;
69106 }
69107
69108 /*
69109@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69110 if (retval)
69111 goto out;
69112 }
69113+
69114+#ifdef CONFIG_PAX_SEGMEXEC
69115+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69116+ struct vm_area_struct *mpnt_m;
69117+
69118+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69119+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69120+
69121+ if (!mpnt->vm_mirror)
69122+ continue;
69123+
69124+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69125+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69126+ mpnt->vm_mirror = mpnt_m;
69127+ } else {
69128+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69129+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69130+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69131+ mpnt->vm_mirror->vm_mirror = mpnt;
69132+ }
69133+ }
69134+ BUG_ON(mpnt_m);
69135+ }
69136+#endif
69137+
69138 /* a new mm has just been created */
69139 arch_dup_mmap(oldmm, mm);
69140 retval = 0;
69141@@ -470,14 +521,6 @@ out:
69142 flush_tlb_mm(oldmm);
69143 up_write(&oldmm->mmap_sem);
69144 return retval;
69145-fail_nomem_anon_vma_fork:
69146- mpol_put(pol);
69147-fail_nomem_policy:
69148- kmem_cache_free(vm_area_cachep, tmp);
69149-fail_nomem:
69150- retval = -ENOMEM;
69151- vm_unacct_memory(charge);
69152- goto out;
69153 }
69154
69155 static inline int mm_alloc_pgd(struct mm_struct *mm)
69156@@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69157 return ERR_PTR(err);
69158
69159 mm = get_task_mm(task);
69160- if (mm && mm != current->mm &&
69161- !ptrace_may_access(task, mode)) {
69162+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69163+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69164 mmput(mm);
69165 mm = ERR_PTR(-EACCES);
69166 }
69167@@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69168 spin_unlock(&fs->lock);
69169 return -EAGAIN;
69170 }
69171- fs->users++;
69172+ atomic_inc(&fs->users);
69173 spin_unlock(&fs->lock);
69174 return 0;
69175 }
69176 tsk->fs = copy_fs_struct(fs);
69177 if (!tsk->fs)
69178 return -ENOMEM;
69179+ /* Carry through gr_chroot_dentry and is_chrooted instead
69180+ of recomputing it here. Already copied when the task struct
69181+ is duplicated. This allows pivot_root to not be treated as
69182+ a chroot
69183+ */
69184+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
69185+
69186 return 0;
69187 }
69188
69189@@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69190 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69191 #endif
69192 retval = -EAGAIN;
69193+
69194+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69195+
69196 if (atomic_read(&p->real_cred->user->processes) >=
69197 task_rlimit(p, RLIMIT_NPROC)) {
69198 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69199@@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69200 goto bad_fork_free_pid;
69201 }
69202
69203+ /* synchronizes with gr_set_acls()
69204+ we need to call this past the point of no return for fork()
69205+ */
69206+ gr_copy_label(p);
69207+
69208 if (clone_flags & CLONE_THREAD) {
69209 current->signal->nr_threads++;
69210 atomic_inc(&current->signal->live);
69211@@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69212 bad_fork_free:
69213 free_task(p);
69214 fork_out:
69215+ gr_log_forkfail(retval);
69216+
69217 return ERR_PTR(retval);
69218 }
69219
69220@@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69221 if (clone_flags & CLONE_PARENT_SETTID)
69222 put_user(nr, parent_tidptr);
69223
69224+ gr_handle_brute_check();
69225+
69226 if (clone_flags & CLONE_VFORK) {
69227 p->vfork_done = &vfork;
69228 init_completion(&vfork);
69229@@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69230 return 0;
69231
69232 /* don't need lock here; in the worst case we'll do useless copy */
69233- if (fs->users == 1)
69234+ if (atomic_read(&fs->users) == 1)
69235 return 0;
69236
69237 *new_fsp = copy_fs_struct(fs);
69238@@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69239 fs = current->fs;
69240 spin_lock(&fs->lock);
69241 current->fs = new_fs;
69242- if (--fs->users)
69243+ gr_set_chroot_entries(current, &current->fs->root);
69244+ if (atomic_dec_return(&fs->users))
69245 new_fs = NULL;
69246 else
69247 new_fs = fs;
69248diff --git a/kernel/futex.c b/kernel/futex.c
69249index 19eb089..b8c65ea 100644
69250--- a/kernel/futex.c
69251+++ b/kernel/futex.c
69252@@ -54,6 +54,7 @@
69253 #include <linux/mount.h>
69254 #include <linux/pagemap.h>
69255 #include <linux/syscalls.h>
69256+#include <linux/ptrace.h>
69257 #include <linux/signal.h>
69258 #include <linux/export.h>
69259 #include <linux/magic.h>
69260@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69261 struct page *page, *page_head;
69262 int err, ro = 0;
69263
69264+#ifdef CONFIG_PAX_SEGMEXEC
69265+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69266+ return -EFAULT;
69267+#endif
69268+
69269 /*
69270 * The futex address must be "naturally" aligned.
69271 */
69272@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69273 {
69274 u32 curval;
69275 int i;
69276+ mm_segment_t oldfs;
69277
69278 /*
69279 * This will fail and we want it. Some arch implementations do
69280@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69281 * implementation, the non-functional ones will return
69282 * -ENOSYS.
69283 */
69284+ oldfs = get_fs();
69285+ set_fs(USER_DS);
69286 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69287 futex_cmpxchg_enabled = 1;
69288+ set_fs(oldfs);
69289
69290 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69291 plist_head_init(&futex_queues[i].chain);
69292diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69293index 9b22d03..6295b62 100644
69294--- a/kernel/gcov/base.c
69295+++ b/kernel/gcov/base.c
69296@@ -102,11 +102,6 @@ void gcov_enable_events(void)
69297 }
69298
69299 #ifdef CONFIG_MODULES
69300-static inline int within(void *addr, void *start, unsigned long size)
69301-{
69302- return ((addr >= start) && (addr < start + size));
69303-}
69304-
69305 /* Update list and generate events when modules are unloaded. */
69306 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69307 void *data)
69308@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69309 prev = NULL;
69310 /* Remove entries located in module from linked list. */
69311 for (info = gcov_info_head; info; info = info->next) {
69312- if (within(info, mod->module_core, mod->core_size)) {
69313+ if (within_module_core_rw((unsigned long)info, mod)) {
69314 if (prev)
69315 prev->next = info->next;
69316 else
69317diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69318index 6db7a5e..25b6648 100644
69319--- a/kernel/hrtimer.c
69320+++ b/kernel/hrtimer.c
69321@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69322 local_irq_restore(flags);
69323 }
69324
69325-static void run_hrtimer_softirq(struct softirq_action *h)
69326+static void run_hrtimer_softirq(void)
69327 {
69328 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69329
69330diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69331index 60f48fa..7f3a770 100644
69332--- a/kernel/jump_label.c
69333+++ b/kernel/jump_label.c
69334@@ -13,6 +13,7 @@
69335 #include <linux/sort.h>
69336 #include <linux/err.h>
69337 #include <linux/static_key.h>
69338+#include <linux/mm.h>
69339
69340 #ifdef HAVE_JUMP_LABEL
69341
69342@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69343
69344 size = (((unsigned long)stop - (unsigned long)start)
69345 / sizeof(struct jump_entry));
69346+ pax_open_kernel();
69347 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69348+ pax_close_kernel();
69349 }
69350
69351 static void jump_label_update(struct static_key *key, int enable);
69352@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69353 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69354 struct jump_entry *iter;
69355
69356+ pax_open_kernel();
69357 for (iter = iter_start; iter < iter_stop; iter++) {
69358 if (within_module_init(iter->code, mod))
69359 iter->code = 0;
69360 }
69361+ pax_close_kernel();
69362 }
69363
69364 static int
69365diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69366index 2169fee..45c017a 100644
69367--- a/kernel/kallsyms.c
69368+++ b/kernel/kallsyms.c
69369@@ -11,6 +11,9 @@
69370 * Changed the compression method from stem compression to "table lookup"
69371 * compression (see scripts/kallsyms.c for a more complete description)
69372 */
69373+#ifdef CONFIG_GRKERNSEC_HIDESYM
69374+#define __INCLUDED_BY_HIDESYM 1
69375+#endif
69376 #include <linux/kallsyms.h>
69377 #include <linux/module.h>
69378 #include <linux/init.h>
69379@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69380
69381 static inline int is_kernel_inittext(unsigned long addr)
69382 {
69383+ if (system_state != SYSTEM_BOOTING)
69384+ return 0;
69385+
69386 if (addr >= (unsigned long)_sinittext
69387 && addr <= (unsigned long)_einittext)
69388 return 1;
69389 return 0;
69390 }
69391
69392+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69393+#ifdef CONFIG_MODULES
69394+static inline int is_module_text(unsigned long addr)
69395+{
69396+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69397+ return 1;
69398+
69399+ addr = ktla_ktva(addr);
69400+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69401+}
69402+#else
69403+static inline int is_module_text(unsigned long addr)
69404+{
69405+ return 0;
69406+}
69407+#endif
69408+#endif
69409+
69410 static inline int is_kernel_text(unsigned long addr)
69411 {
69412 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69413@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69414
69415 static inline int is_kernel(unsigned long addr)
69416 {
69417+
69418+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69419+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
69420+ return 1;
69421+
69422+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69423+#else
69424 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69425+#endif
69426+
69427 return 1;
69428 return in_gate_area_no_mm(addr);
69429 }
69430
69431 static int is_ksym_addr(unsigned long addr)
69432 {
69433+
69434+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69435+ if (is_module_text(addr))
69436+ return 0;
69437+#endif
69438+
69439 if (all_var)
69440 return is_kernel(addr);
69441
69442@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69443
69444 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69445 {
69446- iter->name[0] = '\0';
69447 iter->nameoff = get_symbol_offset(new_pos);
69448 iter->pos = new_pos;
69449 }
69450@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69451 {
69452 struct kallsym_iter *iter = m->private;
69453
69454+#ifdef CONFIG_GRKERNSEC_HIDESYM
69455+ if (current_uid())
69456+ return 0;
69457+#endif
69458+
69459 /* Some debugging symbols have no name. Ignore them. */
69460 if (!iter->name[0])
69461 return 0;
69462@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69463 */
69464 type = iter->exported ? toupper(iter->type) :
69465 tolower(iter->type);
69466+
69467 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69468 type, iter->name, iter->module_name);
69469 } else
69470@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69471 struct kallsym_iter *iter;
69472 int ret;
69473
69474- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69475+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69476 if (!iter)
69477 return -ENOMEM;
69478 reset_iter(iter, 0);
69479diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69480index 30b7b22..c726387 100644
69481--- a/kernel/kcmp.c
69482+++ b/kernel/kcmp.c
69483@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69484 struct task_struct *task1, *task2;
69485 int ret;
69486
69487+#ifdef CONFIG_GRKERNSEC
69488+ return -ENOSYS;
69489+#endif
69490+
69491 rcu_read_lock();
69492
69493 /*
69494diff --git a/kernel/kexec.c b/kernel/kexec.c
69495index 5e4bd78..00c5b91 100644
69496--- a/kernel/kexec.c
69497+++ b/kernel/kexec.c
69498@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69499 unsigned long flags)
69500 {
69501 struct compat_kexec_segment in;
69502- struct kexec_segment out, __user *ksegments;
69503+ struct kexec_segment out;
69504+ struct kexec_segment __user *ksegments;
69505 unsigned long i, result;
69506
69507 /* Don't allow clients that don't understand the native
69508diff --git a/kernel/kmod.c b/kernel/kmod.c
69509index 1c317e3..4a92a55 100644
69510--- a/kernel/kmod.c
69511+++ b/kernel/kmod.c
69512@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69513 kfree(info->argv);
69514 }
69515
69516-static int call_modprobe(char *module_name, int wait)
69517+static int call_modprobe(char *module_name, char *module_param, int wait)
69518 {
69519 static char *envp[] = {
69520 "HOME=/",
69521@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69522 NULL
69523 };
69524
69525- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69526+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69527 if (!argv)
69528 goto out;
69529
69530@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69531 argv[1] = "-q";
69532 argv[2] = "--";
69533 argv[3] = module_name; /* check free_modprobe_argv() */
69534- argv[4] = NULL;
69535+ argv[4] = module_param;
69536+ argv[5] = NULL;
69537
69538 return call_usermodehelper_fns(modprobe_path, argv, envp,
69539 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69540@@ -120,9 +121,8 @@ out:
69541 * If module auto-loading support is disabled then this function
69542 * becomes a no-operation.
69543 */
69544-int __request_module(bool wait, const char *fmt, ...)
69545+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69546 {
69547- va_list args;
69548 char module_name[MODULE_NAME_LEN];
69549 unsigned int max_modprobes;
69550 int ret;
69551@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69552 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69553 static int kmod_loop_msg;
69554
69555- va_start(args, fmt);
69556- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69557- va_end(args);
69558+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69559 if (ret >= MODULE_NAME_LEN)
69560 return -ENAMETOOLONG;
69561
69562@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69563 if (ret)
69564 return ret;
69565
69566+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69567+ if (!current_uid()) {
69568+ /* hack to workaround consolekit/udisks stupidity */
69569+ read_lock(&tasklist_lock);
69570+ if (!strcmp(current->comm, "mount") &&
69571+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69572+ read_unlock(&tasklist_lock);
69573+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69574+ return -EPERM;
69575+ }
69576+ read_unlock(&tasklist_lock);
69577+ }
69578+#endif
69579+
69580 /* If modprobe needs a service that is in a module, we get a recursive
69581 * loop. Limit the number of running kmod threads to max_threads/2 or
69582 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69583@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69584
69585 trace_module_request(module_name, wait, _RET_IP_);
69586
69587- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69588+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69589
69590 atomic_dec(&kmod_concurrent);
69591 return ret;
69592 }
69593+
69594+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69595+{
69596+ va_list args;
69597+ int ret;
69598+
69599+ va_start(args, fmt);
69600+ ret = ____request_module(wait, module_param, fmt, args);
69601+ va_end(args);
69602+
69603+ return ret;
69604+}
69605+
69606+int __request_module(bool wait, const char *fmt, ...)
69607+{
69608+ va_list args;
69609+ int ret;
69610+
69611+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69612+ if (current_uid()) {
69613+ char module_param[MODULE_NAME_LEN];
69614+
69615+ memset(module_param, 0, sizeof(module_param));
69616+
69617+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69618+
69619+ va_start(args, fmt);
69620+ ret = ____request_module(wait, module_param, fmt, args);
69621+ va_end(args);
69622+
69623+ return ret;
69624+ }
69625+#endif
69626+
69627+ va_start(args, fmt);
69628+ ret = ____request_module(wait, NULL, fmt, args);
69629+ va_end(args);
69630+
69631+ return ret;
69632+}
69633+
69634 EXPORT_SYMBOL(__request_module);
69635 #endif /* CONFIG_MODULES */
69636
69637@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69638 *
69639 * Thus the __user pointer cast is valid here.
69640 */
69641- sys_wait4(pid, (int __user *)&ret, 0, NULL);
69642+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69643
69644 /*
69645 * If ret is 0, either ____call_usermodehelper failed and the
69646diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69647index 098f396..fe85ff1 100644
69648--- a/kernel/kprobes.c
69649+++ b/kernel/kprobes.c
69650@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69651 * kernel image and loaded module images reside. This is required
69652 * so x86_64 can correctly handle the %rip-relative fixups.
69653 */
69654- kip->insns = module_alloc(PAGE_SIZE);
69655+ kip->insns = module_alloc_exec(PAGE_SIZE);
69656 if (!kip->insns) {
69657 kfree(kip);
69658 return NULL;
69659@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69660 */
69661 if (!list_is_singular(&kip->list)) {
69662 list_del(&kip->list);
69663- module_free(NULL, kip->insns);
69664+ module_free_exec(NULL, kip->insns);
69665 kfree(kip);
69666 }
69667 return 1;
69668@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69669 {
69670 int i, err = 0;
69671 unsigned long offset = 0, size = 0;
69672- char *modname, namebuf[128];
69673+ char *modname, namebuf[KSYM_NAME_LEN];
69674 const char *symbol_name;
69675 void *addr;
69676 struct kprobe_blackpoint *kb;
69677@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69678 kprobe_type = "k";
69679
69680 if (sym)
69681- seq_printf(pi, "%p %s %s+0x%x %s ",
69682+ seq_printf(pi, "%pK %s %s+0x%x %s ",
69683 p->addr, kprobe_type, sym, offset,
69684 (modname ? modname : " "));
69685 else
69686- seq_printf(pi, "%p %s %p ",
69687+ seq_printf(pi, "%pK %s %pK ",
69688 p->addr, kprobe_type, p->addr);
69689
69690 if (!pp)
69691@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69692 const char *sym = NULL;
69693 unsigned int i = *(loff_t *) v;
69694 unsigned long offset = 0;
69695- char *modname, namebuf[128];
69696+ char *modname, namebuf[KSYM_NAME_LEN];
69697
69698 head = &kprobe_table[i];
69699 preempt_disable();
69700diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69701index 4e316e1..5501eef 100644
69702--- a/kernel/ksysfs.c
69703+++ b/kernel/ksysfs.c
69704@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69705 {
69706 if (count+1 > UEVENT_HELPER_PATH_LEN)
69707 return -ENOENT;
69708+ if (!capable(CAP_SYS_ADMIN))
69709+ return -EPERM;
69710 memcpy(uevent_helper, buf, count);
69711 uevent_helper[count] = '\0';
69712 if (count && uevent_helper[count-1] == '\n')
69713diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69714index 7981e5b..7f2105c 100644
69715--- a/kernel/lockdep.c
69716+++ b/kernel/lockdep.c
69717@@ -590,6 +590,10 @@ static int static_obj(void *obj)
69718 end = (unsigned long) &_end,
69719 addr = (unsigned long) obj;
69720
69721+#ifdef CONFIG_PAX_KERNEXEC
69722+ start = ktla_ktva(start);
69723+#endif
69724+
69725 /*
69726 * static variable?
69727 */
69728@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
69729 if (!static_obj(lock->key)) {
69730 debug_locks_off();
69731 printk("INFO: trying to register non-static key.\n");
69732+ printk("lock:%pS key:%pS.\n", lock, lock->key);
69733 printk("the code is fine but needs lockdep annotation.\n");
69734 printk("turning off the locking correctness validator.\n");
69735 dump_stack();
69736@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
69737 if (!class)
69738 return 0;
69739 }
69740- atomic_inc((atomic_t *)&class->ops);
69741+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
69742 if (very_verbose(class)) {
69743 printk("\nacquire class [%p] %s", class->key, class->name);
69744 if (class->name_version > 1)
69745diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
69746index 91c32a0..7b88d63 100644
69747--- a/kernel/lockdep_proc.c
69748+++ b/kernel/lockdep_proc.c
69749@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
69750
69751 static void print_name(struct seq_file *m, struct lock_class *class)
69752 {
69753- char str[128];
69754+ char str[KSYM_NAME_LEN];
69755 const char *name = class->name;
69756
69757 if (!name) {
69758@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
69759 return 0;
69760 }
69761
69762- seq_printf(m, "%p", class->key);
69763+ seq_printf(m, "%pK", class->key);
69764 #ifdef CONFIG_DEBUG_LOCKDEP
69765 seq_printf(m, " OPS:%8ld", class->ops);
69766 #endif
69767@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
69768
69769 list_for_each_entry(entry, &class->locks_after, entry) {
69770 if (entry->distance == 1) {
69771- seq_printf(m, " -> [%p] ", entry->class->key);
69772+ seq_printf(m, " -> [%pK] ", entry->class->key);
69773 print_name(m, entry->class);
69774 seq_puts(m, "\n");
69775 }
69776@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
69777 if (!class->key)
69778 continue;
69779
69780- seq_printf(m, "[%p] ", class->key);
69781+ seq_printf(m, "[%pK] ", class->key);
69782 print_name(m, class);
69783 seq_puts(m, "\n");
69784 }
69785@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69786 if (!i)
69787 seq_line(m, '-', 40-namelen, namelen);
69788
69789- snprintf(ip, sizeof(ip), "[<%p>]",
69790+ snprintf(ip, sizeof(ip), "[<%pK>]",
69791 (void *)class->contention_point[i]);
69792 seq_printf(m, "%40s %14lu %29s %pS\n",
69793 name, stats->contention_point[i],
69794@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69795 if (!i)
69796 seq_line(m, '-', 40-namelen, namelen);
69797
69798- snprintf(ip, sizeof(ip), "[<%p>]",
69799+ snprintf(ip, sizeof(ip), "[<%pK>]",
69800 (void *)class->contending_point[i]);
69801 seq_printf(m, "%40s %14lu %29s %pS\n",
69802 name, stats->contending_point[i],
69803diff --git a/kernel/module.c b/kernel/module.c
69804index 3e544f4..34c3008 100644
69805--- a/kernel/module.c
69806+++ b/kernel/module.c
69807@@ -59,6 +59,7 @@
69808 #include <linux/pfn.h>
69809 #include <linux/bsearch.h>
69810 #include <linux/fips.h>
69811+#include <linux/grsecurity.h>
69812 #include "module-internal.h"
69813
69814 #define CREATE_TRACE_POINTS
69815@@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
69816
69817 /* Bounds of module allocation, for speeding __module_address.
69818 * Protected by module_mutex. */
69819-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
69820+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
69821+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
69822
69823 int register_module_notifier(struct notifier_block * nb)
69824 {
69825@@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69826 return true;
69827
69828 list_for_each_entry_rcu(mod, &modules, list) {
69829- struct symsearch arr[] = {
69830+ struct symsearch modarr[] = {
69831 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
69832 NOT_GPL_ONLY, false },
69833 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
69834@@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69835 if (mod->state == MODULE_STATE_UNFORMED)
69836 continue;
69837
69838- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
69839+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
69840 return true;
69841 }
69842 return false;
69843@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
69844 static int percpu_modalloc(struct module *mod,
69845 unsigned long size, unsigned long align)
69846 {
69847- if (align > PAGE_SIZE) {
69848+ if (align-1 >= PAGE_SIZE) {
69849 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
69850 mod->name, align, PAGE_SIZE);
69851 align = PAGE_SIZE;
69852@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
69853 static ssize_t show_coresize(struct module_attribute *mattr,
69854 struct module_kobject *mk, char *buffer)
69855 {
69856- return sprintf(buffer, "%u\n", mk->mod->core_size);
69857+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
69858 }
69859
69860 static struct module_attribute modinfo_coresize =
69861@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
69862 static ssize_t show_initsize(struct module_attribute *mattr,
69863 struct module_kobject *mk, char *buffer)
69864 {
69865- return sprintf(buffer, "%u\n", mk->mod->init_size);
69866+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
69867 }
69868
69869 static struct module_attribute modinfo_initsize =
69870@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
69871 */
69872 #ifdef CONFIG_SYSFS
69873
69874-#ifdef CONFIG_KALLSYMS
69875+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69876 static inline bool sect_empty(const Elf_Shdr *sect)
69877 {
69878 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
69879@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
69880
69881 static void unset_module_core_ro_nx(struct module *mod)
69882 {
69883- set_page_attributes(mod->module_core + mod->core_text_size,
69884- mod->module_core + mod->core_size,
69885+ set_page_attributes(mod->module_core_rw,
69886+ mod->module_core_rw + mod->core_size_rw,
69887 set_memory_x);
69888- set_page_attributes(mod->module_core,
69889- mod->module_core + mod->core_ro_size,
69890+ set_page_attributes(mod->module_core_rx,
69891+ mod->module_core_rx + mod->core_size_rx,
69892 set_memory_rw);
69893 }
69894
69895 static void unset_module_init_ro_nx(struct module *mod)
69896 {
69897- set_page_attributes(mod->module_init + mod->init_text_size,
69898- mod->module_init + mod->init_size,
69899+ set_page_attributes(mod->module_init_rw,
69900+ mod->module_init_rw + mod->init_size_rw,
69901 set_memory_x);
69902- set_page_attributes(mod->module_init,
69903- mod->module_init + mod->init_ro_size,
69904+ set_page_attributes(mod->module_init_rx,
69905+ mod->module_init_rx + mod->init_size_rx,
69906 set_memory_rw);
69907 }
69908
69909@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
69910 list_for_each_entry_rcu(mod, &modules, list) {
69911 if (mod->state == MODULE_STATE_UNFORMED)
69912 continue;
69913- if ((mod->module_core) && (mod->core_text_size)) {
69914- set_page_attributes(mod->module_core,
69915- mod->module_core + mod->core_text_size,
69916+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
69917+ set_page_attributes(mod->module_core_rx,
69918+ mod->module_core_rx + mod->core_size_rx,
69919 set_memory_rw);
69920 }
69921- if ((mod->module_init) && (mod->init_text_size)) {
69922- set_page_attributes(mod->module_init,
69923- mod->module_init + mod->init_text_size,
69924+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
69925+ set_page_attributes(mod->module_init_rx,
69926+ mod->module_init_rx + mod->init_size_rx,
69927 set_memory_rw);
69928 }
69929 }
69930@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
69931 list_for_each_entry_rcu(mod, &modules, list) {
69932 if (mod->state == MODULE_STATE_UNFORMED)
69933 continue;
69934- if ((mod->module_core) && (mod->core_text_size)) {
69935- set_page_attributes(mod->module_core,
69936- mod->module_core + mod->core_text_size,
69937+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
69938+ set_page_attributes(mod->module_core_rx,
69939+ mod->module_core_rx + mod->core_size_rx,
69940 set_memory_ro);
69941 }
69942- if ((mod->module_init) && (mod->init_text_size)) {
69943- set_page_attributes(mod->module_init,
69944- mod->module_init + mod->init_text_size,
69945+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
69946+ set_page_attributes(mod->module_init_rx,
69947+ mod->module_init_rx + mod->init_size_rx,
69948 set_memory_ro);
69949 }
69950 }
69951@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
69952
69953 /* This may be NULL, but that's OK */
69954 unset_module_init_ro_nx(mod);
69955- module_free(mod, mod->module_init);
69956+ module_free(mod, mod->module_init_rw);
69957+ module_free_exec(mod, mod->module_init_rx);
69958 kfree(mod->args);
69959 percpu_modfree(mod);
69960
69961 /* Free lock-classes: */
69962- lockdep_free_key_range(mod->module_core, mod->core_size);
69963+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
69964+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
69965
69966 /* Finally, free the core (containing the module structure) */
69967 unset_module_core_ro_nx(mod);
69968- module_free(mod, mod->module_core);
69969+ module_free_exec(mod, mod->module_core_rx);
69970+ module_free(mod, mod->module_core_rw);
69971
69972 #ifdef CONFIG_MPU
69973 update_protections(current->mm);
69974@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
69975 int ret = 0;
69976 const struct kernel_symbol *ksym;
69977
69978+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69979+ int is_fs_load = 0;
69980+ int register_filesystem_found = 0;
69981+ char *p;
69982+
69983+ p = strstr(mod->args, "grsec_modharden_fs");
69984+ if (p) {
69985+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
69986+ /* copy \0 as well */
69987+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
69988+ is_fs_load = 1;
69989+ }
69990+#endif
69991+
69992 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
69993 const char *name = info->strtab + sym[i].st_name;
69994
69995+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69996+ /* it's a real shame this will never get ripped and copied
69997+ upstream! ;(
69998+ */
69999+ if (is_fs_load && !strcmp(name, "register_filesystem"))
70000+ register_filesystem_found = 1;
70001+#endif
70002+
70003 switch (sym[i].st_shndx) {
70004 case SHN_COMMON:
70005 /* We compiled with -fno-common. These are not
70006@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70007 ksym = resolve_symbol_wait(mod, info, name);
70008 /* Ok if resolved. */
70009 if (ksym && !IS_ERR(ksym)) {
70010+ pax_open_kernel();
70011 sym[i].st_value = ksym->value;
70012+ pax_close_kernel();
70013 break;
70014 }
70015
70016@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70017 secbase = (unsigned long)mod_percpu(mod);
70018 else
70019 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70020+ pax_open_kernel();
70021 sym[i].st_value += secbase;
70022+ pax_close_kernel();
70023 break;
70024 }
70025 }
70026
70027+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70028+ if (is_fs_load && !register_filesystem_found) {
70029+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70030+ ret = -EPERM;
70031+ }
70032+#endif
70033+
70034 return ret;
70035 }
70036
70037@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70038 || s->sh_entsize != ~0UL
70039 || strstarts(sname, ".init"))
70040 continue;
70041- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70042+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70043+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70044+ else
70045+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70046 pr_debug("\t%s\n", sname);
70047 }
70048- switch (m) {
70049- case 0: /* executable */
70050- mod->core_size = debug_align(mod->core_size);
70051- mod->core_text_size = mod->core_size;
70052- break;
70053- case 1: /* RO: text and ro-data */
70054- mod->core_size = debug_align(mod->core_size);
70055- mod->core_ro_size = mod->core_size;
70056- break;
70057- case 3: /* whole core */
70058- mod->core_size = debug_align(mod->core_size);
70059- break;
70060- }
70061 }
70062
70063 pr_debug("Init section allocation order:\n");
70064@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70065 || s->sh_entsize != ~0UL
70066 || !strstarts(sname, ".init"))
70067 continue;
70068- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70069- | INIT_OFFSET_MASK);
70070+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70071+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70072+ else
70073+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70074+ s->sh_entsize |= INIT_OFFSET_MASK;
70075 pr_debug("\t%s\n", sname);
70076 }
70077- switch (m) {
70078- case 0: /* executable */
70079- mod->init_size = debug_align(mod->init_size);
70080- mod->init_text_size = mod->init_size;
70081- break;
70082- case 1: /* RO: text and ro-data */
70083- mod->init_size = debug_align(mod->init_size);
70084- mod->init_ro_size = mod->init_size;
70085- break;
70086- case 3: /* whole init */
70087- mod->init_size = debug_align(mod->init_size);
70088- break;
70089- }
70090 }
70091 }
70092
70093@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70094
70095 /* Put symbol section at end of init part of module. */
70096 symsect->sh_flags |= SHF_ALLOC;
70097- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70098+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70099 info->index.sym) | INIT_OFFSET_MASK;
70100 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70101
70102@@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70103 }
70104
70105 /* Append room for core symbols at end of core part. */
70106- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70107- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70108- mod->core_size += strtab_size;
70109+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70110+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70111+ mod->core_size_rx += strtab_size;
70112
70113 /* Put string table section at end of init part of module. */
70114 strsect->sh_flags |= SHF_ALLOC;
70115- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70116+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70117 info->index.str) | INIT_OFFSET_MASK;
70118 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70119 }
70120@@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70121 /* Make sure we get permanent strtab: don't use info->strtab. */
70122 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70123
70124+ pax_open_kernel();
70125+
70126 /* Set types up while we still have access to sections. */
70127 for (i = 0; i < mod->num_symtab; i++)
70128 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70129
70130- mod->core_symtab = dst = mod->module_core + info->symoffs;
70131- mod->core_strtab = s = mod->module_core + info->stroffs;
70132+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70133+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70134 src = mod->symtab;
70135 *s++ = 0;
70136 for (ndst = i = 0; i < mod->num_symtab; i++) {
70137@@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70138 }
70139 }
70140 mod->core_num_syms = ndst;
70141+
70142+ pax_close_kernel();
70143 }
70144 #else
70145 static inline void layout_symtab(struct module *mod, struct load_info *info)
70146@@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70147 return size == 0 ? NULL : vmalloc_exec(size);
70148 }
70149
70150-static void *module_alloc_update_bounds(unsigned long size)
70151+static void *module_alloc_update_bounds_rw(unsigned long size)
70152 {
70153 void *ret = module_alloc(size);
70154
70155 if (ret) {
70156 mutex_lock(&module_mutex);
70157 /* Update module bounds. */
70158- if ((unsigned long)ret < module_addr_min)
70159- module_addr_min = (unsigned long)ret;
70160- if ((unsigned long)ret + size > module_addr_max)
70161- module_addr_max = (unsigned long)ret + size;
70162+ if ((unsigned long)ret < module_addr_min_rw)
70163+ module_addr_min_rw = (unsigned long)ret;
70164+ if ((unsigned long)ret + size > module_addr_max_rw)
70165+ module_addr_max_rw = (unsigned long)ret + size;
70166+ mutex_unlock(&module_mutex);
70167+ }
70168+ return ret;
70169+}
70170+
70171+static void *module_alloc_update_bounds_rx(unsigned long size)
70172+{
70173+ void *ret = module_alloc_exec(size);
70174+
70175+ if (ret) {
70176+ mutex_lock(&module_mutex);
70177+ /* Update module bounds. */
70178+ if ((unsigned long)ret < module_addr_min_rx)
70179+ module_addr_min_rx = (unsigned long)ret;
70180+ if ((unsigned long)ret + size > module_addr_max_rx)
70181+ module_addr_max_rx = (unsigned long)ret + size;
70182 mutex_unlock(&module_mutex);
70183 }
70184 return ret;
70185@@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70186 static int check_modinfo(struct module *mod, struct load_info *info)
70187 {
70188 const char *modmagic = get_modinfo(info, "vermagic");
70189+ const char *license = get_modinfo(info, "license");
70190 int err;
70191
70192+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70193+ if (!license || !license_is_gpl_compatible(license))
70194+ return -ENOEXEC;
70195+#endif
70196+
70197 /* This is allowed: modprobe --force will invalidate it. */
70198 if (!modmagic) {
70199 err = try_to_force_load(mod, "bad vermagic");
70200@@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70201 }
70202
70203 /* Set up license info based on the info section */
70204- set_license(mod, get_modinfo(info, "license"));
70205+ set_license(mod, license);
70206
70207 return 0;
70208 }
70209@@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70210 void *ptr;
70211
70212 /* Do the allocs. */
70213- ptr = module_alloc_update_bounds(mod->core_size);
70214+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70215 /*
70216 * The pointer to this block is stored in the module structure
70217 * which is inside the block. Just mark it as not being a
70218@@ -2758,10 +2802,10 @@ static int move_module(struct module *mod, struct load_info *info)
70219 if (!ptr)
70220 return -ENOMEM;
70221
70222- memset(ptr, 0, mod->core_size);
70223- mod->module_core = ptr;
70224+ memset(ptr, 0, mod->core_size_rw);
70225+ mod->module_core_rw = ptr;
70226
70227- ptr = module_alloc_update_bounds(mod->init_size);
70228+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70229 /*
70230 * The pointer to this block is stored in the module structure
70231 * which is inside the block. This block doesn't need to be
70232@@ -2769,12 +2813,39 @@ static int move_module(struct module *mod, struct load_info *info)
70233 * after the module is initialized.
70234 */
70235 kmemleak_ignore(ptr);
70236- if (!ptr && mod->init_size) {
70237- module_free(mod, mod->module_core);
70238+ if (!ptr && mod->init_size_rw) {
70239+ module_free(mod, mod->module_core_rw);
70240 return -ENOMEM;
70241 }
70242- memset(ptr, 0, mod->init_size);
70243- mod->module_init = ptr;
70244+ memset(ptr, 0, mod->init_size_rw);
70245+ mod->module_init_rw = ptr;
70246+
70247+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70248+ kmemleak_not_leak(ptr);
70249+ if (!ptr) {
70250+ module_free(mod, mod->module_init_rw);
70251+ module_free(mod, mod->module_core_rw);
70252+ return -ENOMEM;
70253+ }
70254+
70255+ pax_open_kernel();
70256+ memset(ptr, 0, mod->core_size_rx);
70257+ pax_close_kernel();
70258+ mod->module_core_rx = ptr;
70259+
70260+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70261+ kmemleak_ignore(ptr);
70262+ if (!ptr && mod->init_size_rx) {
70263+ module_free_exec(mod, mod->module_core_rx);
70264+ module_free(mod, mod->module_init_rw);
70265+ module_free(mod, mod->module_core_rw);
70266+ return -ENOMEM;
70267+ }
70268+
70269+ pax_open_kernel();
70270+ memset(ptr, 0, mod->init_size_rx);
70271+ pax_close_kernel();
70272+ mod->module_init_rx = ptr;
70273
70274 /* Transfer each section which specifies SHF_ALLOC */
70275 pr_debug("final section addresses:\n");
70276@@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70277 if (!(shdr->sh_flags & SHF_ALLOC))
70278 continue;
70279
70280- if (shdr->sh_entsize & INIT_OFFSET_MASK)
70281- dest = mod->module_init
70282- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70283- else
70284- dest = mod->module_core + shdr->sh_entsize;
70285+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70286+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70287+ dest = mod->module_init_rw
70288+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70289+ else
70290+ dest = mod->module_init_rx
70291+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70292+ } else {
70293+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70294+ dest = mod->module_core_rw + shdr->sh_entsize;
70295+ else
70296+ dest = mod->module_core_rx + shdr->sh_entsize;
70297+ }
70298+
70299+ if (shdr->sh_type != SHT_NOBITS) {
70300+
70301+#ifdef CONFIG_PAX_KERNEXEC
70302+#ifdef CONFIG_X86_64
70303+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70304+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70305+#endif
70306+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70307+ pax_open_kernel();
70308+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70309+ pax_close_kernel();
70310+ } else
70311+#endif
70312
70313- if (shdr->sh_type != SHT_NOBITS)
70314 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70315+ }
70316 /* Update sh_addr to point to copy in image. */
70317- shdr->sh_addr = (unsigned long)dest;
70318+
70319+#ifdef CONFIG_PAX_KERNEXEC
70320+ if (shdr->sh_flags & SHF_EXECINSTR)
70321+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
70322+ else
70323+#endif
70324+
70325+ shdr->sh_addr = (unsigned long)dest;
70326 pr_debug("\t0x%lx %s\n",
70327 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70328 }
70329@@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70330 * Do it before processing of module parameters, so the module
70331 * can provide parameter accessor functions of its own.
70332 */
70333- if (mod->module_init)
70334- flush_icache_range((unsigned long)mod->module_init,
70335- (unsigned long)mod->module_init
70336- + mod->init_size);
70337- flush_icache_range((unsigned long)mod->module_core,
70338- (unsigned long)mod->module_core + mod->core_size);
70339+ if (mod->module_init_rx)
70340+ flush_icache_range((unsigned long)mod->module_init_rx,
70341+ (unsigned long)mod->module_init_rx
70342+ + mod->init_size_rx);
70343+ flush_icache_range((unsigned long)mod->module_core_rx,
70344+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
70345
70346 set_fs(old_fs);
70347 }
70348@@ -2924,8 +3024,10 @@ out:
70349 static void module_deallocate(struct module *mod, struct load_info *info)
70350 {
70351 percpu_modfree(mod);
70352- module_free(mod, mod->module_init);
70353- module_free(mod, mod->module_core);
70354+ module_free_exec(mod, mod->module_init_rx);
70355+ module_free_exec(mod, mod->module_core_rx);
70356+ module_free(mod, mod->module_init_rw);
70357+ module_free(mod, mod->module_core_rw);
70358 }
70359
70360 int __weak module_finalize(const Elf_Ehdr *hdr,
70361@@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70362 static int post_relocation(struct module *mod, const struct load_info *info)
70363 {
70364 /* Sort exception table now relocations are done. */
70365+ pax_open_kernel();
70366 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70367+ pax_close_kernel();
70368
70369 /* Copy relocated percpu area over. */
70370 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70371@@ -3036,9 +3140,38 @@ again:
70372 if (err)
70373 goto free_unload;
70374
70375+ /* Now copy in args */
70376+ mod->args = strndup_user(uargs, ~0UL >> 1);
70377+ if (IS_ERR(mod->args)) {
70378+ err = PTR_ERR(mod->args);
70379+ goto free_unload;
70380+ }
70381+
70382 /* Set up MODINFO_ATTR fields */
70383 setup_modinfo(mod, &info);
70384
70385+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70386+ {
70387+ char *p, *p2;
70388+
70389+ if (strstr(mod->args, "grsec_modharden_netdev")) {
70390+ 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);
70391+ err = -EPERM;
70392+ goto free_modinfo;
70393+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70394+ p += sizeof("grsec_modharden_normal") - 1;
70395+ p2 = strstr(p, "_");
70396+ if (p2) {
70397+ *p2 = '\0';
70398+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70399+ *p2 = '_';
70400+ }
70401+ err = -EPERM;
70402+ goto free_modinfo;
70403+ }
70404+ }
70405+#endif
70406+
70407 /* Fix up syms, so that st_value is a pointer to location. */
70408 err = simplify_symbols(mod, &info);
70409 if (err < 0)
70410@@ -3104,11 +3237,11 @@ again:
70411 mutex_unlock(&module_mutex);
70412 dynamic_debug_remove(info.debug);
70413 synchronize_sched();
70414- kfree(mod->args);
70415 free_arch_cleanup:
70416 module_arch_cleanup(mod);
70417 free_modinfo:
70418 free_modinfo(mod);
70419+ kfree(mod->args);
70420 free_unload:
70421 module_unload_free(mod);
70422 unlink_mod:
70423@@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70424 MODULE_STATE_COMING, mod);
70425
70426 /* Set RO and NX regions for core */
70427- set_section_ro_nx(mod->module_core,
70428- mod->core_text_size,
70429- mod->core_ro_size,
70430- mod->core_size);
70431+ set_section_ro_nx(mod->module_core_rx,
70432+ mod->core_size_rx,
70433+ mod->core_size_rx,
70434+ mod->core_size_rx);
70435
70436 /* Set RO and NX regions for init */
70437- set_section_ro_nx(mod->module_init,
70438- mod->init_text_size,
70439- mod->init_ro_size,
70440- mod->init_size);
70441+ set_section_ro_nx(mod->module_init_rx,
70442+ mod->init_size_rx,
70443+ mod->init_size_rx,
70444+ mod->init_size_rx);
70445
70446 do_mod_ctors(mod);
70447 /* Start the module */
70448@@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70449 mod->strtab = mod->core_strtab;
70450 #endif
70451 unset_module_init_ro_nx(mod);
70452- module_free(mod, mod->module_init);
70453- mod->module_init = NULL;
70454- mod->init_size = 0;
70455- mod->init_ro_size = 0;
70456- mod->init_text_size = 0;
70457+ module_free(mod, mod->module_init_rw);
70458+ module_free_exec(mod, mod->module_init_rx);
70459+ mod->module_init_rw = NULL;
70460+ mod->module_init_rx = NULL;
70461+ mod->init_size_rw = 0;
70462+ mod->init_size_rx = 0;
70463 mutex_unlock(&module_mutex);
70464 wake_up_all(&module_wq);
70465
70466@@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70467 unsigned long nextval;
70468
70469 /* At worse, next value is at end of module */
70470- if (within_module_init(addr, mod))
70471- nextval = (unsigned long)mod->module_init+mod->init_text_size;
70472+ if (within_module_init_rx(addr, mod))
70473+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70474+ else if (within_module_init_rw(addr, mod))
70475+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70476+ else if (within_module_core_rx(addr, mod))
70477+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70478+ else if (within_module_core_rw(addr, mod))
70479+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70480 else
70481- nextval = (unsigned long)mod->module_core+mod->core_text_size;
70482+ return NULL;
70483
70484 /* Scan for closest preceding symbol, and next symbol. (ELF
70485 starts real symbols at 1). */
70486@@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70487 return 0;
70488
70489 seq_printf(m, "%s %u",
70490- mod->name, mod->init_size + mod->core_size);
70491+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70492 print_unload_info(m, mod);
70493
70494 /* Informative for users. */
70495@@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70496 mod->state == MODULE_STATE_COMING ? "Loading":
70497 "Live");
70498 /* Used by oprofile and other similar tools. */
70499- seq_printf(m, " 0x%pK", mod->module_core);
70500+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70501
70502 /* Taints info */
70503 if (mod->taints)
70504@@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70505
70506 static int __init proc_modules_init(void)
70507 {
70508+#ifndef CONFIG_GRKERNSEC_HIDESYM
70509+#ifdef CONFIG_GRKERNSEC_PROC_USER
70510+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70511+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70512+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70513+#else
70514 proc_create("modules", 0, NULL, &proc_modules_operations);
70515+#endif
70516+#else
70517+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70518+#endif
70519 return 0;
70520 }
70521 module_init(proc_modules_init);
70522@@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70523 {
70524 struct module *mod;
70525
70526- if (addr < module_addr_min || addr > module_addr_max)
70527+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70528+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
70529 return NULL;
70530
70531 list_for_each_entry_rcu(mod, &modules, list) {
70532 if (mod->state == MODULE_STATE_UNFORMED)
70533 continue;
70534- if (within_module_core(addr, mod)
70535- || within_module_init(addr, mod))
70536+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
70537 return mod;
70538 }
70539 return NULL;
70540@@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70541 */
70542 struct module *__module_text_address(unsigned long addr)
70543 {
70544- struct module *mod = __module_address(addr);
70545+ struct module *mod;
70546+
70547+#ifdef CONFIG_X86_32
70548+ addr = ktla_ktva(addr);
70549+#endif
70550+
70551+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70552+ return NULL;
70553+
70554+ mod = __module_address(addr);
70555+
70556 if (mod) {
70557 /* Make sure it's within the text section. */
70558- if (!within(addr, mod->module_init, mod->init_text_size)
70559- && !within(addr, mod->module_core, mod->core_text_size))
70560+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70561 mod = NULL;
70562 }
70563 return mod;
70564diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70565index 7e3443f..b2a1e6b 100644
70566--- a/kernel/mutex-debug.c
70567+++ b/kernel/mutex-debug.c
70568@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70569 }
70570
70571 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70572- struct thread_info *ti)
70573+ struct task_struct *task)
70574 {
70575 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70576
70577 /* Mark the current thread as blocked on the lock: */
70578- ti->task->blocked_on = waiter;
70579+ task->blocked_on = waiter;
70580 }
70581
70582 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70583- struct thread_info *ti)
70584+ struct task_struct *task)
70585 {
70586 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70587- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70588- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70589- ti->task->blocked_on = NULL;
70590+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
70591+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70592+ task->blocked_on = NULL;
70593
70594 list_del_init(&waiter->list);
70595 waiter->task = NULL;
70596diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70597index 0799fd3..d06ae3b 100644
70598--- a/kernel/mutex-debug.h
70599+++ b/kernel/mutex-debug.h
70600@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70601 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70602 extern void debug_mutex_add_waiter(struct mutex *lock,
70603 struct mutex_waiter *waiter,
70604- struct thread_info *ti);
70605+ struct task_struct *task);
70606 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70607- struct thread_info *ti);
70608+ struct task_struct *task);
70609 extern void debug_mutex_unlock(struct mutex *lock);
70610 extern void debug_mutex_init(struct mutex *lock, const char *name,
70611 struct lock_class_key *key);
70612diff --git a/kernel/mutex.c b/kernel/mutex.c
70613index a307cc9..27fd2e9 100644
70614--- a/kernel/mutex.c
70615+++ b/kernel/mutex.c
70616@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70617 spin_lock_mutex(&lock->wait_lock, flags);
70618
70619 debug_mutex_lock_common(lock, &waiter);
70620- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70621+ debug_mutex_add_waiter(lock, &waiter, task);
70622
70623 /* add waiting tasks to the end of the waitqueue (FIFO): */
70624 list_add_tail(&waiter.list, &lock->wait_list);
70625@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70626 * TASK_UNINTERRUPTIBLE case.)
70627 */
70628 if (unlikely(signal_pending_state(state, task))) {
70629- mutex_remove_waiter(lock, &waiter,
70630- task_thread_info(task));
70631+ mutex_remove_waiter(lock, &waiter, task);
70632 mutex_release(&lock->dep_map, 1, ip);
70633 spin_unlock_mutex(&lock->wait_lock, flags);
70634
70635@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70636 done:
70637 lock_acquired(&lock->dep_map, ip);
70638 /* got the lock - rejoice! */
70639- mutex_remove_waiter(lock, &waiter, current_thread_info());
70640+ mutex_remove_waiter(lock, &waiter, task);
70641 mutex_set_owner(lock);
70642
70643 /* set it to 0 if there are no waiters left: */
70644diff --git a/kernel/notifier.c b/kernel/notifier.c
70645index 2d5cc4c..d9ea600 100644
70646--- a/kernel/notifier.c
70647+++ b/kernel/notifier.c
70648@@ -5,6 +5,7 @@
70649 #include <linux/rcupdate.h>
70650 #include <linux/vmalloc.h>
70651 #include <linux/reboot.h>
70652+#include <linux/mm.h>
70653
70654 /*
70655 * Notifier list for kernel code which wants to be called
70656@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70657 while ((*nl) != NULL) {
70658 if (n->priority > (*nl)->priority)
70659 break;
70660- nl = &((*nl)->next);
70661+ nl = (struct notifier_block **)&((*nl)->next);
70662 }
70663- n->next = *nl;
70664+ pax_open_kernel();
70665+ *(const void **)&n->next = *nl;
70666 rcu_assign_pointer(*nl, n);
70667+ pax_close_kernel();
70668 return 0;
70669 }
70670
70671@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70672 return 0;
70673 if (n->priority > (*nl)->priority)
70674 break;
70675- nl = &((*nl)->next);
70676+ nl = (struct notifier_block **)&((*nl)->next);
70677 }
70678- n->next = *nl;
70679+ pax_open_kernel();
70680+ *(const void **)&n->next = *nl;
70681 rcu_assign_pointer(*nl, n);
70682+ pax_close_kernel();
70683 return 0;
70684 }
70685
70686@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70687 {
70688 while ((*nl) != NULL) {
70689 if ((*nl) == n) {
70690+ pax_open_kernel();
70691 rcu_assign_pointer(*nl, n->next);
70692+ pax_close_kernel();
70693 return 0;
70694 }
70695- nl = &((*nl)->next);
70696+ nl = (struct notifier_block **)&((*nl)->next);
70697 }
70698 return -ENOENT;
70699 }
70700diff --git a/kernel/panic.c b/kernel/panic.c
70701index e1b2822..5edc1d9 100644
70702--- a/kernel/panic.c
70703+++ b/kernel/panic.c
70704@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70705 const char *board;
70706
70707 printk(KERN_WARNING "------------[ cut here ]------------\n");
70708- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70709+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70710 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70711 if (board)
70712 printk(KERN_WARNING "Hardware name: %s\n", board);
70713@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70714 */
70715 void __stack_chk_fail(void)
70716 {
70717- panic("stack-protector: Kernel stack is corrupted in: %p\n",
70718+ dump_stack();
70719+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70720 __builtin_return_address(0));
70721 }
70722 EXPORT_SYMBOL(__stack_chk_fail);
70723diff --git a/kernel/pid.c b/kernel/pid.c
70724index aebd4f5..1693c13 100644
70725--- a/kernel/pid.c
70726+++ b/kernel/pid.c
70727@@ -33,6 +33,7 @@
70728 #include <linux/rculist.h>
70729 #include <linux/bootmem.h>
70730 #include <linux/hash.h>
70731+#include <linux/security.h>
70732 #include <linux/pid_namespace.h>
70733 #include <linux/init_task.h>
70734 #include <linux/syscalls.h>
70735@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
70736
70737 int pid_max = PID_MAX_DEFAULT;
70738
70739-#define RESERVED_PIDS 300
70740+#define RESERVED_PIDS 500
70741
70742 int pid_max_min = RESERVED_PIDS + 1;
70743 int pid_max_max = PID_MAX_LIMIT;
70744@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
70745 */
70746 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
70747 {
70748+ struct task_struct *task;
70749+
70750 rcu_lockdep_assert(rcu_read_lock_held(),
70751 "find_task_by_pid_ns() needs rcu_read_lock()"
70752 " protection");
70753- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70754+
70755+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70756+
70757+ if (gr_pid_is_chrooted(task))
70758+ return NULL;
70759+
70760+ return task;
70761 }
70762
70763 struct task_struct *find_task_by_vpid(pid_t vnr)
70764@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
70765 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
70766 }
70767
70768+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
70769+{
70770+ rcu_lockdep_assert(rcu_read_lock_held(),
70771+ "find_task_by_pid_ns() needs rcu_read_lock()"
70772+ " protection");
70773+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
70774+}
70775+
70776 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
70777 {
70778 struct pid *pid;
70779diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
70780index 125cb67..2e5c8ad 100644
70781--- a/kernel/posix-cpu-timers.c
70782+++ b/kernel/posix-cpu-timers.c
70783@@ -6,9 +6,11 @@
70784 #include <linux/posix-timers.h>
70785 #include <linux/errno.h>
70786 #include <linux/math64.h>
70787+#include <linux/security.h>
70788 #include <asm/uaccess.h>
70789 #include <linux/kernel_stat.h>
70790 #include <trace/events/timer.h>
70791+#include <linux/random.h>
70792
70793 /*
70794 * Called after updating RLIMIT_CPU to run cpu timer and update
70795@@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
70796 */
70797 void posix_cpu_timers_exit(struct task_struct *tsk)
70798 {
70799+ add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
70800+ sizeof(unsigned long long));
70801 cleanup_timers(tsk->cpu_timers,
70802 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
70803
70804@@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
70805
70806 static __init int init_posix_cpu_timers(void)
70807 {
70808- struct k_clock process = {
70809+ static struct k_clock process = {
70810 .clock_getres = process_cpu_clock_getres,
70811 .clock_get = process_cpu_clock_get,
70812 .timer_create = process_cpu_timer_create,
70813 .nsleep = process_cpu_nsleep,
70814 .nsleep_restart = process_cpu_nsleep_restart,
70815 };
70816- struct k_clock thread = {
70817+ static struct k_clock thread = {
70818 .clock_getres = thread_cpu_clock_getres,
70819 .clock_get = thread_cpu_clock_get,
70820 .timer_create = thread_cpu_timer_create,
70821diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
70822index 69185ae..cc2847a 100644
70823--- a/kernel/posix-timers.c
70824+++ b/kernel/posix-timers.c
70825@@ -43,6 +43,7 @@
70826 #include <linux/idr.h>
70827 #include <linux/posix-clock.h>
70828 #include <linux/posix-timers.h>
70829+#include <linux/grsecurity.h>
70830 #include <linux/syscalls.h>
70831 #include <linux/wait.h>
70832 #include <linux/workqueue.h>
70833@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
70834 * which we beg off on and pass to do_sys_settimeofday().
70835 */
70836
70837-static struct k_clock posix_clocks[MAX_CLOCKS];
70838+static struct k_clock *posix_clocks[MAX_CLOCKS];
70839
70840 /*
70841 * These ones are defined below.
70842@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
70843 */
70844 static __init int init_posix_timers(void)
70845 {
70846- struct k_clock clock_realtime = {
70847+ static struct k_clock clock_realtime = {
70848 .clock_getres = hrtimer_get_res,
70849 .clock_get = posix_clock_realtime_get,
70850 .clock_set = posix_clock_realtime_set,
70851@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
70852 .timer_get = common_timer_get,
70853 .timer_del = common_timer_del,
70854 };
70855- struct k_clock clock_monotonic = {
70856+ static struct k_clock clock_monotonic = {
70857 .clock_getres = hrtimer_get_res,
70858 .clock_get = posix_ktime_get_ts,
70859 .nsleep = common_nsleep,
70860@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
70861 .timer_get = common_timer_get,
70862 .timer_del = common_timer_del,
70863 };
70864- struct k_clock clock_monotonic_raw = {
70865+ static struct k_clock clock_monotonic_raw = {
70866 .clock_getres = hrtimer_get_res,
70867 .clock_get = posix_get_monotonic_raw,
70868 };
70869- struct k_clock clock_realtime_coarse = {
70870+ static struct k_clock clock_realtime_coarse = {
70871 .clock_getres = posix_get_coarse_res,
70872 .clock_get = posix_get_realtime_coarse,
70873 };
70874- struct k_clock clock_monotonic_coarse = {
70875+ static struct k_clock clock_monotonic_coarse = {
70876 .clock_getres = posix_get_coarse_res,
70877 .clock_get = posix_get_monotonic_coarse,
70878 };
70879- struct k_clock clock_boottime = {
70880+ static struct k_clock clock_boottime = {
70881 .clock_getres = hrtimer_get_res,
70882 .clock_get = posix_get_boottime,
70883 .nsleep = common_nsleep,
70884@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
70885 return;
70886 }
70887
70888- posix_clocks[clock_id] = *new_clock;
70889+ posix_clocks[clock_id] = new_clock;
70890 }
70891 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
70892
70893@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
70894 return (id & CLOCKFD_MASK) == CLOCKFD ?
70895 &clock_posix_dynamic : &clock_posix_cpu;
70896
70897- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
70898+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
70899 return NULL;
70900- return &posix_clocks[id];
70901+ return posix_clocks[id];
70902 }
70903
70904 static int common_timer_create(struct k_itimer *new_timer)
70905@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
70906 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
70907 return -EFAULT;
70908
70909+ /* only the CLOCK_REALTIME clock can be set, all other clocks
70910+ have their clock_set fptr set to a nosettime dummy function
70911+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
70912+ call common_clock_set, which calls do_sys_settimeofday, which
70913+ we hook
70914+ */
70915+
70916 return kc->clock_set(which_clock, &new_tp);
70917 }
70918
70919diff --git a/kernel/power/process.c b/kernel/power/process.c
70920index 87da817..30ddd13 100644
70921--- a/kernel/power/process.c
70922+++ b/kernel/power/process.c
70923@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
70924 u64 elapsed_csecs64;
70925 unsigned int elapsed_csecs;
70926 bool wakeup = false;
70927+ bool timedout = false;
70928
70929 do_gettimeofday(&start);
70930
70931@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
70932
70933 while (true) {
70934 todo = 0;
70935+ if (time_after(jiffies, end_time))
70936+ timedout = true;
70937 read_lock(&tasklist_lock);
70938 do_each_thread(g, p) {
70939 if (p == current || !freeze_task(p))
70940@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
70941 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
70942 * transition can't race with task state testing here.
70943 */
70944- if (!task_is_stopped_or_traced(p) &&
70945- !freezer_should_skip(p))
70946+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
70947 todo++;
70948+ if (timedout) {
70949+ printk(KERN_ERR "Task refusing to freeze:\n");
70950+ sched_show_task(p);
70951+ }
70952+ }
70953 } while_each_thread(g, p);
70954 read_unlock(&tasklist_lock);
70955
70956@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
70957 todo += wq_busy;
70958 }
70959
70960- if (!todo || time_after(jiffies, end_time))
70961+ if (!todo || timedout)
70962 break;
70963
70964 if (pm_wakeup_pending()) {
70965diff --git a/kernel/printk.c b/kernel/printk.c
70966index f8e0b5a..dda2a5c 100644
70967--- a/kernel/printk.c
70968+++ b/kernel/printk.c
70969@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
70970 if (from_file && type != SYSLOG_ACTION_OPEN)
70971 return 0;
70972
70973+#ifdef CONFIG_GRKERNSEC_DMESG
70974+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
70975+ return -EPERM;
70976+#endif
70977+
70978 if (syslog_action_restricted(type)) {
70979 if (capable(CAP_SYSLOG))
70980 return 0;
70981diff --git a/kernel/profile.c b/kernel/profile.c
70982index 76b8e77..a2930e8 100644
70983--- a/kernel/profile.c
70984+++ b/kernel/profile.c
70985@@ -39,7 +39,7 @@ struct profile_hit {
70986 /* Oprofile timer tick hook */
70987 static int (*timer_hook)(struct pt_regs *) __read_mostly;
70988
70989-static atomic_t *prof_buffer;
70990+static atomic_unchecked_t *prof_buffer;
70991 static unsigned long prof_len, prof_shift;
70992
70993 int prof_on __read_mostly;
70994@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
70995 hits[i].pc = 0;
70996 continue;
70997 }
70998- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
70999+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71000 hits[i].hits = hits[i].pc = 0;
71001 }
71002 }
71003@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71004 * Add the current hit(s) and flush the write-queue out
71005 * to the global buffer:
71006 */
71007- atomic_add(nr_hits, &prof_buffer[pc]);
71008+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71009 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71010- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71011+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71012 hits[i].pc = hits[i].hits = 0;
71013 }
71014 out:
71015@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71016 {
71017 unsigned long pc;
71018 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71019- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71020+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71021 }
71022 #endif /* !CONFIG_SMP */
71023
71024@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71025 return -EFAULT;
71026 buf++; p++; count--; read++;
71027 }
71028- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71029+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71030 if (copy_to_user(buf, (void *)pnt, count))
71031 return -EFAULT;
71032 read += count;
71033@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71034 }
71035 #endif
71036 profile_discard_flip_buffers();
71037- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71038+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71039 return count;
71040 }
71041
71042diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71043index fbea91d..9bf15e8 100644
71044--- a/kernel/ptrace.c
71045+++ b/kernel/ptrace.c
71046@@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71047
71048 if (seize)
71049 flags |= PT_SEIZED;
71050- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71051+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71052 flags |= PT_PTRACE_CAP;
71053 task->ptrace = flags;
71054
71055@@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71056 break;
71057 return -EIO;
71058 }
71059- if (copy_to_user(dst, buf, retval))
71060+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71061 return -EFAULT;
71062 copied += retval;
71063 src += retval;
71064@@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71065 bool seized = child->ptrace & PT_SEIZED;
71066 int ret = -EIO;
71067 siginfo_t siginfo, *si;
71068- void __user *datavp = (void __user *) data;
71069+ void __user *datavp = (__force void __user *) data;
71070 unsigned long __user *datalp = datavp;
71071 unsigned long flags;
71072
71073@@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71074 goto out;
71075 }
71076
71077+ if (gr_handle_ptrace(child, request)) {
71078+ ret = -EPERM;
71079+ goto out_put_task_struct;
71080+ }
71081+
71082 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71083 ret = ptrace_attach(child, request, addr, data);
71084 /*
71085 * Some architectures need to do book-keeping after
71086 * a ptrace attach.
71087 */
71088- if (!ret)
71089+ if (!ret) {
71090 arch_ptrace_attach(child);
71091+ gr_audit_ptrace(child);
71092+ }
71093 goto out_put_task_struct;
71094 }
71095
71096@@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71097 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71098 if (copied != sizeof(tmp))
71099 return -EIO;
71100- return put_user(tmp, (unsigned long __user *)data);
71101+ return put_user(tmp, (__force unsigned long __user *)data);
71102 }
71103
71104 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71105@@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71106 goto out;
71107 }
71108
71109+ if (gr_handle_ptrace(child, request)) {
71110+ ret = -EPERM;
71111+ goto out_put_task_struct;
71112+ }
71113+
71114 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71115 ret = ptrace_attach(child, request, addr, data);
71116 /*
71117 * Some architectures need to do book-keeping after
71118 * a ptrace attach.
71119 */
71120- if (!ret)
71121+ if (!ret) {
71122 arch_ptrace_attach(child);
71123+ gr_audit_ptrace(child);
71124+ }
71125 goto out_put_task_struct;
71126 }
71127
71128diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71129index e4c6a59..c86621a 100644
71130--- a/kernel/rcutiny.c
71131+++ b/kernel/rcutiny.c
71132@@ -46,7 +46,7 @@
71133 struct rcu_ctrlblk;
71134 static void invoke_rcu_callbacks(void);
71135 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71136-static void rcu_process_callbacks(struct softirq_action *unused);
71137+static void rcu_process_callbacks(void);
71138 static void __call_rcu(struct rcu_head *head,
71139 void (*func)(struct rcu_head *rcu),
71140 struct rcu_ctrlblk *rcp);
71141@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71142 rcu_is_callbacks_kthread()));
71143 }
71144
71145-static void rcu_process_callbacks(struct softirq_action *unused)
71146+static void rcu_process_callbacks(void)
71147 {
71148 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71149 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71150diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71151index 3d01902..afbf46e 100644
71152--- a/kernel/rcutiny_plugin.h
71153+++ b/kernel/rcutiny_plugin.h
71154@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71155 have_rcu_kthread_work = morework;
71156 local_irq_restore(flags);
71157 if (work)
71158- rcu_process_callbacks(NULL);
71159+ rcu_process_callbacks();
71160 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71161 }
71162
71163diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71164index aaa7b9f..055ff1e 100644
71165--- a/kernel/rcutorture.c
71166+++ b/kernel/rcutorture.c
71167@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71168 { 0 };
71169 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71170 { 0 };
71171-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71172-static atomic_t n_rcu_torture_alloc;
71173-static atomic_t n_rcu_torture_alloc_fail;
71174-static atomic_t n_rcu_torture_free;
71175-static atomic_t n_rcu_torture_mberror;
71176-static atomic_t n_rcu_torture_error;
71177+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71178+static atomic_unchecked_t n_rcu_torture_alloc;
71179+static atomic_unchecked_t n_rcu_torture_alloc_fail;
71180+static atomic_unchecked_t n_rcu_torture_free;
71181+static atomic_unchecked_t n_rcu_torture_mberror;
71182+static atomic_unchecked_t n_rcu_torture_error;
71183 static long n_rcu_torture_barrier_error;
71184 static long n_rcu_torture_boost_ktrerror;
71185 static long n_rcu_torture_boost_rterror;
71186@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71187
71188 spin_lock_bh(&rcu_torture_lock);
71189 if (list_empty(&rcu_torture_freelist)) {
71190- atomic_inc(&n_rcu_torture_alloc_fail);
71191+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71192 spin_unlock_bh(&rcu_torture_lock);
71193 return NULL;
71194 }
71195- atomic_inc(&n_rcu_torture_alloc);
71196+ atomic_inc_unchecked(&n_rcu_torture_alloc);
71197 p = rcu_torture_freelist.next;
71198 list_del_init(p);
71199 spin_unlock_bh(&rcu_torture_lock);
71200@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71201 static void
71202 rcu_torture_free(struct rcu_torture *p)
71203 {
71204- atomic_inc(&n_rcu_torture_free);
71205+ atomic_inc_unchecked(&n_rcu_torture_free);
71206 spin_lock_bh(&rcu_torture_lock);
71207 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71208 spin_unlock_bh(&rcu_torture_lock);
71209@@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *p)
71210 i = rp->rtort_pipe_count;
71211 if (i > RCU_TORTURE_PIPE_LEN)
71212 i = RCU_TORTURE_PIPE_LEN;
71213- atomic_inc(&rcu_torture_wcount[i]);
71214+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71215 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71216 rp->rtort_mbtest = 0;
71217 rcu_torture_free(rp);
71218@@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71219 i = rp->rtort_pipe_count;
71220 if (i > RCU_TORTURE_PIPE_LEN)
71221 i = RCU_TORTURE_PIPE_LEN;
71222- atomic_inc(&rcu_torture_wcount[i]);
71223+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71224 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71225 rp->rtort_mbtest = 0;
71226 list_del(&rp->rtort_free);
71227@@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71228 i = old_rp->rtort_pipe_count;
71229 if (i > RCU_TORTURE_PIPE_LEN)
71230 i = RCU_TORTURE_PIPE_LEN;
71231- atomic_inc(&rcu_torture_wcount[i]);
71232+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71233 old_rp->rtort_pipe_count++;
71234 cur_ops->deferred_free(old_rp);
71235 }
71236@@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
71237 }
71238 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71239 if (p->rtort_mbtest == 0)
71240- atomic_inc(&n_rcu_torture_mberror);
71241+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71242 spin_lock(&rand_lock);
71243 cur_ops->read_delay(&rand);
71244 n_rcu_torture_timers++;
71245@@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71246 }
71247 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71248 if (p->rtort_mbtest == 0)
71249- atomic_inc(&n_rcu_torture_mberror);
71250+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71251 cur_ops->read_delay(&rand);
71252 preempt_disable();
71253 pipe_count = p->rtort_pipe_count;
71254@@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71255 rcu_torture_current,
71256 rcu_torture_current_version,
71257 list_empty(&rcu_torture_freelist),
71258- atomic_read(&n_rcu_torture_alloc),
71259- atomic_read(&n_rcu_torture_alloc_fail),
71260- atomic_read(&n_rcu_torture_free));
71261+ atomic_read_unchecked(&n_rcu_torture_alloc),
71262+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71263+ atomic_read_unchecked(&n_rcu_torture_free));
71264 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71265- atomic_read(&n_rcu_torture_mberror),
71266+ atomic_read_unchecked(&n_rcu_torture_mberror),
71267 n_rcu_torture_boost_ktrerror,
71268 n_rcu_torture_boost_rterror);
71269 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71270@@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71271 n_barrier_attempts,
71272 n_rcu_torture_barrier_error);
71273 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71274- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71275+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71276 n_rcu_torture_barrier_error != 0 ||
71277 n_rcu_torture_boost_ktrerror != 0 ||
71278 n_rcu_torture_boost_rterror != 0 ||
71279 n_rcu_torture_boost_failure != 0 ||
71280 i > 1) {
71281 cnt += sprintf(&page[cnt], "!!! ");
71282- atomic_inc(&n_rcu_torture_error);
71283+ atomic_inc_unchecked(&n_rcu_torture_error);
71284 WARN_ON_ONCE(1);
71285 }
71286 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71287@@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71288 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71289 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71290 cnt += sprintf(&page[cnt], " %d",
71291- atomic_read(&rcu_torture_wcount[i]));
71292+ atomic_read_unchecked(&rcu_torture_wcount[i]));
71293 }
71294 cnt += sprintf(&page[cnt], "\n");
71295 if (cur_ops->stats)
71296@@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71297
71298 if (cur_ops->cleanup)
71299 cur_ops->cleanup();
71300- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71301+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71302 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71303 else if (n_online_successes != n_online_attempts ||
71304 n_offline_successes != n_offline_attempts)
71305@@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71306
71307 rcu_torture_current = NULL;
71308 rcu_torture_current_version = 0;
71309- atomic_set(&n_rcu_torture_alloc, 0);
71310- atomic_set(&n_rcu_torture_alloc_fail, 0);
71311- atomic_set(&n_rcu_torture_free, 0);
71312- atomic_set(&n_rcu_torture_mberror, 0);
71313- atomic_set(&n_rcu_torture_error, 0);
71314+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71315+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71316+ atomic_set_unchecked(&n_rcu_torture_free, 0);
71317+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71318+ atomic_set_unchecked(&n_rcu_torture_error, 0);
71319 n_rcu_torture_barrier_error = 0;
71320 n_rcu_torture_boost_ktrerror = 0;
71321 n_rcu_torture_boost_rterror = 0;
71322 n_rcu_torture_boost_failure = 0;
71323 n_rcu_torture_boosts = 0;
71324 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71325- atomic_set(&rcu_torture_wcount[i], 0);
71326+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71327 for_each_possible_cpu(cpu) {
71328 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71329 per_cpu(rcu_torture_count, cpu)[i] = 0;
71330diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71331index 2682295..0f2297e 100644
71332--- a/kernel/rcutree.c
71333+++ b/kernel/rcutree.c
71334@@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71335 rcu_prepare_for_idle(smp_processor_id());
71336 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71337 smp_mb__before_atomic_inc(); /* See above. */
71338- atomic_inc(&rdtp->dynticks);
71339+ atomic_inc_unchecked(&rdtp->dynticks);
71340 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71341- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71342+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71343
71344 /*
71345 * It is illegal to enter an extended quiescent state while
71346@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71347 int user)
71348 {
71349 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71350- atomic_inc(&rdtp->dynticks);
71351+ atomic_inc_unchecked(&rdtp->dynticks);
71352 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71353 smp_mb__after_atomic_inc(); /* See above. */
71354- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71355+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71356 rcu_cleanup_after_idle(smp_processor_id());
71357 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71358 if (!user && !is_idle_task(current)) {
71359@@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71360 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71361
71362 if (rdtp->dynticks_nmi_nesting == 0 &&
71363- (atomic_read(&rdtp->dynticks) & 0x1))
71364+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71365 return;
71366 rdtp->dynticks_nmi_nesting++;
71367 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71368- atomic_inc(&rdtp->dynticks);
71369+ atomic_inc_unchecked(&rdtp->dynticks);
71370 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71371 smp_mb__after_atomic_inc(); /* See above. */
71372- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71373+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71374 }
71375
71376 /**
71377@@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71378 return;
71379 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71380 smp_mb__before_atomic_inc(); /* See above. */
71381- atomic_inc(&rdtp->dynticks);
71382+ atomic_inc_unchecked(&rdtp->dynticks);
71383 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71384- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71385+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71386 }
71387
71388 /**
71389@@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71390 int ret;
71391
71392 preempt_disable();
71393- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71394+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71395 preempt_enable();
71396 return ret;
71397 }
71398@@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71399 */
71400 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71401 {
71402- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71403+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71404 return (rdp->dynticks_snap & 0x1) == 0;
71405 }
71406
71407@@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71408 unsigned int curr;
71409 unsigned int snap;
71410
71411- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71412+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71413 snap = (unsigned int)rdp->dynticks_snap;
71414
71415 /*
71416@@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71417 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71418 */
71419 if (till_stall_check < 3) {
71420- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71421+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71422 till_stall_check = 3;
71423 } else if (till_stall_check > 300) {
71424- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71425+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71426 till_stall_check = 300;
71427 }
71428 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71429@@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71430 rsp->qlen += rdp->qlen;
71431 rdp->n_cbs_orphaned += rdp->qlen;
71432 rdp->qlen_lazy = 0;
71433- ACCESS_ONCE(rdp->qlen) = 0;
71434+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71435 }
71436
71437 /*
71438@@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71439 }
71440 smp_mb(); /* List handling before counting for rcu_barrier(). */
71441 rdp->qlen_lazy -= count_lazy;
71442- ACCESS_ONCE(rdp->qlen) -= count;
71443+ ACCESS_ONCE_RW(rdp->qlen) -= count;
71444 rdp->n_cbs_invoked += count;
71445
71446 /* Reinstate batch limit if we have worked down the excess. */
71447@@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71448 /*
71449 * Do RCU core processing for the current CPU.
71450 */
71451-static void rcu_process_callbacks(struct softirq_action *unused)
71452+static void rcu_process_callbacks(void)
71453 {
71454 struct rcu_state *rsp;
71455
71456@@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71457 local_irq_restore(flags);
71458 return;
71459 }
71460- ACCESS_ONCE(rdp->qlen)++;
71461+ ACCESS_ONCE_RW(rdp->qlen)++;
71462 if (lazy)
71463 rdp->qlen_lazy++;
71464 else
71465@@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71466 }
71467 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71468
71469-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71470-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71471+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71472+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71473
71474 static int synchronize_sched_expedited_cpu_stop(void *data)
71475 {
71476@@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71477 int firstsnap, s, snap, trycount = 0;
71478
71479 /* Note that atomic_inc_return() implies full memory barrier. */
71480- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71481+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71482 get_online_cpus();
71483 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71484
71485@@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71486 }
71487
71488 /* Check to see if someone else did our work for us. */
71489- s = atomic_read(&sync_sched_expedited_done);
71490+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71491 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71492 smp_mb(); /* ensure test happens before caller kfree */
71493 return;
71494@@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71495 * grace period works for us.
71496 */
71497 get_online_cpus();
71498- snap = atomic_read(&sync_sched_expedited_started);
71499+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
71500 smp_mb(); /* ensure read is before try_stop_cpus(). */
71501 }
71502
71503@@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71504 * than we did beat us to the punch.
71505 */
71506 do {
71507- s = atomic_read(&sync_sched_expedited_done);
71508+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71509 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71510 smp_mb(); /* ensure test happens before caller kfree */
71511 break;
71512 }
71513- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71514+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71515
71516 put_online_cpus();
71517 }
71518@@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71519 * ACCESS_ONCE() to prevent the compiler from speculating
71520 * the increment to precede the early-exit check.
71521 */
71522- ACCESS_ONCE(rsp->n_barrier_done)++;
71523+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71524 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71525 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71526 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71527@@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71528
71529 /* Increment ->n_barrier_done to prevent duplicate work. */
71530 smp_mb(); /* Keep increment after above mechanism. */
71531- ACCESS_ONCE(rsp->n_barrier_done)++;
71532+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71533 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71534 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71535 smp_mb(); /* Keep increment before caller's subsequent code. */
71536@@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71537 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71538 init_callback_list(rdp);
71539 rdp->qlen_lazy = 0;
71540- ACCESS_ONCE(rdp->qlen) = 0;
71541+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71542 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71543 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71544- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71545+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71546 #ifdef CONFIG_RCU_USER_QS
71547 WARN_ON_ONCE(rdp->dynticks->in_user);
71548 #endif
71549@@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71550 rdp->blimit = blimit;
71551 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71552 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71553- atomic_set(&rdp->dynticks->dynticks,
71554- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71555+ atomic_set_unchecked(&rdp->dynticks->dynticks,
71556+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71557 rcu_prepare_for_idle_init(cpu);
71558 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71559
71560diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71561index a240f03..d469618 100644
71562--- a/kernel/rcutree.h
71563+++ b/kernel/rcutree.h
71564@@ -86,7 +86,7 @@ struct rcu_dynticks {
71565 long long dynticks_nesting; /* Track irq/process nesting level. */
71566 /* Process level is worth LLONG_MAX/2. */
71567 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71568- atomic_t dynticks; /* Even value for idle, else odd. */
71569+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71570 #ifdef CONFIG_RCU_FAST_NO_HZ
71571 int dyntick_drain; /* Prepare-for-idle state variable. */
71572 unsigned long dyntick_holdoff;
71573diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71574index f921154..34c4873 100644
71575--- a/kernel/rcutree_plugin.h
71576+++ b/kernel/rcutree_plugin.h
71577@@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71578
71579 /* Clean up and exit. */
71580 smp_mb(); /* ensure expedited GP seen before counter increment. */
71581- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71582+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71583 unlock_mb_ret:
71584 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71585 mb_ret:
71586@@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71587 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71588 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71589 cpu, ticks_value, ticks_title,
71590- atomic_read(&rdtp->dynticks) & 0xfff,
71591+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71592 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71593 fast_no_hz);
71594 }
71595diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71596index 693513b..b9f1d63 100644
71597--- a/kernel/rcutree_trace.c
71598+++ b/kernel/rcutree_trace.c
71599@@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71600 rdp->completed, rdp->gpnum,
71601 rdp->passed_quiesce, rdp->qs_pending);
71602 seq_printf(m, " dt=%d/%llx/%d df=%lu",
71603- atomic_read(&rdp->dynticks->dynticks),
71604+ atomic_read_unchecked(&rdp->dynticks->dynticks),
71605 rdp->dynticks->dynticks_nesting,
71606 rdp->dynticks->dynticks_nmi_nesting,
71607 rdp->dynticks_fqs);
71608@@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71609 rdp->completed, rdp->gpnum,
71610 rdp->passed_quiesce, rdp->qs_pending);
71611 seq_printf(m, ",%d,%llx,%d,%lu",
71612- atomic_read(&rdp->dynticks->dynticks),
71613+ atomic_read_unchecked(&rdp->dynticks->dynticks),
71614 rdp->dynticks->dynticks_nesting,
71615 rdp->dynticks->dynticks_nmi_nesting,
71616 rdp->dynticks_fqs);
71617diff --git a/kernel/resource.c b/kernel/resource.c
71618index 73f35d4..4684fc4 100644
71619--- a/kernel/resource.c
71620+++ b/kernel/resource.c
71621@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71622
71623 static int __init ioresources_init(void)
71624 {
71625+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71626+#ifdef CONFIG_GRKERNSEC_PROC_USER
71627+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71628+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71629+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71630+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71631+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71632+#endif
71633+#else
71634 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71635 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71636+#endif
71637 return 0;
71638 }
71639 __initcall(ioresources_init);
71640diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71641index 98ec494..4241d6d 100644
71642--- a/kernel/rtmutex-tester.c
71643+++ b/kernel/rtmutex-tester.c
71644@@ -20,7 +20,7 @@
71645 #define MAX_RT_TEST_MUTEXES 8
71646
71647 static spinlock_t rttest_lock;
71648-static atomic_t rttest_event;
71649+static atomic_unchecked_t rttest_event;
71650
71651 struct test_thread_data {
71652 int opcode;
71653@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71654
71655 case RTTEST_LOCKCONT:
71656 td->mutexes[td->opdata] = 1;
71657- td->event = atomic_add_return(1, &rttest_event);
71658+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71659 return 0;
71660
71661 case RTTEST_RESET:
71662@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71663 return 0;
71664
71665 case RTTEST_RESETEVENT:
71666- atomic_set(&rttest_event, 0);
71667+ atomic_set_unchecked(&rttest_event, 0);
71668 return 0;
71669
71670 default:
71671@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71672 return ret;
71673
71674 td->mutexes[id] = 1;
71675- td->event = atomic_add_return(1, &rttest_event);
71676+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71677 rt_mutex_lock(&mutexes[id]);
71678- td->event = atomic_add_return(1, &rttest_event);
71679+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71680 td->mutexes[id] = 4;
71681 return 0;
71682
71683@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71684 return ret;
71685
71686 td->mutexes[id] = 1;
71687- td->event = atomic_add_return(1, &rttest_event);
71688+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71689 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71690- td->event = atomic_add_return(1, &rttest_event);
71691+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71692 td->mutexes[id] = ret ? 0 : 4;
71693 return ret ? -EINTR : 0;
71694
71695@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71696 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71697 return ret;
71698
71699- td->event = atomic_add_return(1, &rttest_event);
71700+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71701 rt_mutex_unlock(&mutexes[id]);
71702- td->event = atomic_add_return(1, &rttest_event);
71703+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71704 td->mutexes[id] = 0;
71705 return 0;
71706
71707@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71708 break;
71709
71710 td->mutexes[dat] = 2;
71711- td->event = atomic_add_return(1, &rttest_event);
71712+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71713 break;
71714
71715 default:
71716@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71717 return;
71718
71719 td->mutexes[dat] = 3;
71720- td->event = atomic_add_return(1, &rttest_event);
71721+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71722 break;
71723
71724 case RTTEST_LOCKNOWAIT:
71725@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71726 return;
71727
71728 td->mutexes[dat] = 1;
71729- td->event = atomic_add_return(1, &rttest_event);
71730+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71731 return;
71732
71733 default:
71734diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
71735index 15f60d0..7e50319 100644
71736--- a/kernel/sched/auto_group.c
71737+++ b/kernel/sched/auto_group.c
71738@@ -11,7 +11,7 @@
71739
71740 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
71741 static struct autogroup autogroup_default;
71742-static atomic_t autogroup_seq_nr;
71743+static atomic_unchecked_t autogroup_seq_nr;
71744
71745 void __init autogroup_init(struct task_struct *init_task)
71746 {
71747@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
71748
71749 kref_init(&ag->kref);
71750 init_rwsem(&ag->lock);
71751- ag->id = atomic_inc_return(&autogroup_seq_nr);
71752+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
71753 ag->tg = tg;
71754 #ifdef CONFIG_RT_GROUP_SCHED
71755 /*
71756diff --git a/kernel/sched/core.c b/kernel/sched/core.c
71757index c529d00..d00b4f3 100644
71758--- a/kernel/sched/core.c
71759+++ b/kernel/sched/core.c
71760@@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
71761 /* convert nice value [19,-20] to rlimit style value [1,40] */
71762 int nice_rlim = 20 - nice;
71763
71764+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
71765+
71766 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
71767 capable(CAP_SYS_NICE));
71768 }
71769@@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
71770 if (nice > 19)
71771 nice = 19;
71772
71773- if (increment < 0 && !can_nice(current, nice))
71774+ if (increment < 0 && (!can_nice(current, nice) ||
71775+ gr_handle_chroot_nice()))
71776 return -EPERM;
71777
71778 retval = security_task_setnice(current, nice);
71779@@ -3750,6 +3753,7 @@ recheck:
71780 unsigned long rlim_rtprio =
71781 task_rlimit(p, RLIMIT_RTPRIO);
71782
71783+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
71784 /* can't set/change the rt policy */
71785 if (policy != p->policy && !rlim_rtprio)
71786 return -EPERM;
71787diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
71788index 6b800a1..0c36227 100644
71789--- a/kernel/sched/fair.c
71790+++ b/kernel/sched/fair.c
71791@@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
71792 * run_rebalance_domains is triggered when needed from the scheduler tick.
71793 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
71794 */
71795-static void run_rebalance_domains(struct softirq_action *h)
71796+static void run_rebalance_domains(void)
71797 {
71798 int this_cpu = smp_processor_id();
71799 struct rq *this_rq = cpu_rq(this_cpu);
71800diff --git a/kernel/signal.c b/kernel/signal.c
71801index 57dde52..2c561f0 100644
71802--- a/kernel/signal.c
71803+++ b/kernel/signal.c
71804@@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
71805
71806 int print_fatal_signals __read_mostly;
71807
71808-static void __user *sig_handler(struct task_struct *t, int sig)
71809+static __sighandler_t sig_handler(struct task_struct *t, int sig)
71810 {
71811 return t->sighand->action[sig - 1].sa.sa_handler;
71812 }
71813
71814-static int sig_handler_ignored(void __user *handler, int sig)
71815+static int sig_handler_ignored(__sighandler_t handler, int sig)
71816 {
71817 /* Is it explicitly or implicitly ignored? */
71818 return handler == SIG_IGN ||
71819@@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
71820
71821 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
71822 {
71823- void __user *handler;
71824+ __sighandler_t handler;
71825
71826 handler = sig_handler(t, sig);
71827
71828@@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
71829 atomic_inc(&user->sigpending);
71830 rcu_read_unlock();
71831
71832+ if (!override_rlimit)
71833+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
71834+
71835 if (override_rlimit ||
71836 atomic_read(&user->sigpending) <=
71837 task_rlimit(t, RLIMIT_SIGPENDING)) {
71838@@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
71839
71840 int unhandled_signal(struct task_struct *tsk, int sig)
71841 {
71842- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
71843+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
71844 if (is_global_init(tsk))
71845 return 1;
71846 if (handler != SIG_IGN && handler != SIG_DFL)
71847@@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
71848 }
71849 }
71850
71851+ /* allow glibc communication via tgkill to other threads in our
71852+ thread group */
71853+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
71854+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
71855+ && gr_handle_signal(t, sig))
71856+ return -EPERM;
71857+
71858 return security_task_kill(t, info, sig, 0);
71859 }
71860
71861@@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71862 return send_signal(sig, info, p, 1);
71863 }
71864
71865-static int
71866+int
71867 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71868 {
71869 return send_signal(sig, info, t, 0);
71870@@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71871 unsigned long int flags;
71872 int ret, blocked, ignored;
71873 struct k_sigaction *action;
71874+ int is_unhandled = 0;
71875
71876 spin_lock_irqsave(&t->sighand->siglock, flags);
71877 action = &t->sighand->action[sig-1];
71878@@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71879 }
71880 if (action->sa.sa_handler == SIG_DFL)
71881 t->signal->flags &= ~SIGNAL_UNKILLABLE;
71882+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
71883+ is_unhandled = 1;
71884 ret = specific_send_sig_info(sig, info, t);
71885 spin_unlock_irqrestore(&t->sighand->siglock, flags);
71886
71887+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
71888+ normal operation */
71889+ if (is_unhandled) {
71890+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
71891+ gr_handle_crash(t, sig);
71892+ }
71893+
71894 return ret;
71895 }
71896
71897@@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71898 ret = check_kill_permission(sig, info, p);
71899 rcu_read_unlock();
71900
71901- if (!ret && sig)
71902+ if (!ret && sig) {
71903 ret = do_send_sig_info(sig, info, p, true);
71904+ if (!ret)
71905+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
71906+ }
71907
71908 return ret;
71909 }
71910@@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
71911 int error = -ESRCH;
71912
71913 rcu_read_lock();
71914- p = find_task_by_vpid(pid);
71915+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71916+ /* allow glibc communication via tgkill to other threads in our
71917+ thread group */
71918+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
71919+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
71920+ p = find_task_by_vpid_unrestricted(pid);
71921+ else
71922+#endif
71923+ p = find_task_by_vpid(pid);
71924 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
71925 error = check_kill_permission(sig, info, p);
71926 /*
71927diff --git a/kernel/softirq.c b/kernel/softirq.c
71928index cc96bdc..6a96894 100644
71929--- a/kernel/softirq.c
71930+++ b/kernel/softirq.c
71931@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
71932 EXPORT_SYMBOL(irq_stat);
71933 #endif
71934
71935-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
71936+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
71937
71938 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
71939
71940-char *softirq_to_name[NR_SOFTIRQS] = {
71941+const char * const softirq_to_name[NR_SOFTIRQS] = {
71942 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
71943 "TASKLET", "SCHED", "HRTIMER", "RCU"
71944 };
71945@@ -244,7 +244,7 @@ restart:
71946 kstat_incr_softirqs_this_cpu(vec_nr);
71947
71948 trace_softirq_entry(vec_nr);
71949- h->action(h);
71950+ h->action();
71951 trace_softirq_exit(vec_nr);
71952 if (unlikely(prev_count != preempt_count())) {
71953 printk(KERN_ERR "huh, entered softirq %u %s %p"
71954@@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
71955 or_softirq_pending(1UL << nr);
71956 }
71957
71958-void open_softirq(int nr, void (*action)(struct softirq_action *))
71959+void __init open_softirq(int nr, void (*action)(void))
71960 {
71961 softirq_vec[nr].action = action;
71962 }
71963@@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
71964
71965 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
71966
71967-static void tasklet_action(struct softirq_action *a)
71968+static void tasklet_action(void)
71969 {
71970 struct tasklet_struct *list;
71971
71972@@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
71973 }
71974 }
71975
71976-static void tasklet_hi_action(struct softirq_action *a)
71977+static void tasklet_hi_action(void)
71978 {
71979 struct tasklet_struct *list;
71980
71981diff --git a/kernel/srcu.c b/kernel/srcu.c
71982index 97c465e..d83f3bb 100644
71983--- a/kernel/srcu.c
71984+++ b/kernel/srcu.c
71985@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
71986 preempt_disable();
71987 idx = rcu_dereference_index_check(sp->completed,
71988 rcu_read_lock_sched_held()) & 0x1;
71989- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
71990+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
71991 smp_mb(); /* B */ /* Avoid leaking the critical section. */
71992- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
71993+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
71994 preempt_enable();
71995 return idx;
71996 }
71997@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
71998 {
71999 preempt_disable();
72000 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72001- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72002+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72003 preempt_enable();
72004 }
72005 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72006diff --git a/kernel/sys.c b/kernel/sys.c
72007index e6e0ece..1f2e413 100644
72008--- a/kernel/sys.c
72009+++ b/kernel/sys.c
72010@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72011 error = -EACCES;
72012 goto out;
72013 }
72014+
72015+ if (gr_handle_chroot_setpriority(p, niceval)) {
72016+ error = -EACCES;
72017+ goto out;
72018+ }
72019+
72020 no_nice = security_task_setnice(p, niceval);
72021 if (no_nice) {
72022 error = no_nice;
72023@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72024 goto error;
72025 }
72026
72027+ if (gr_check_group_change(new->gid, new->egid, -1))
72028+ goto error;
72029+
72030 if (rgid != (gid_t) -1 ||
72031 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72032 new->sgid = new->egid;
72033@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72034 old = current_cred();
72035
72036 retval = -EPERM;
72037+
72038+ if (gr_check_group_change(kgid, kgid, kgid))
72039+ goto error;
72040+
72041 if (nsown_capable(CAP_SETGID))
72042 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72043 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72044@@ -647,7 +660,7 @@ error:
72045 /*
72046 * change the user struct in a credentials set to match the new UID
72047 */
72048-static int set_user(struct cred *new)
72049+int set_user(struct cred *new)
72050 {
72051 struct user_struct *new_user;
72052
72053@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72054 goto error;
72055 }
72056
72057+ if (gr_check_user_change(new->uid, new->euid, -1))
72058+ goto error;
72059+
72060 if (!uid_eq(new->uid, old->uid)) {
72061 retval = set_user(new);
72062 if (retval < 0)
72063@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72064 old = current_cred();
72065
72066 retval = -EPERM;
72067+
72068+ if (gr_check_crash_uid(kuid))
72069+ goto error;
72070+ if (gr_check_user_change(kuid, kuid, kuid))
72071+ goto error;
72072+
72073 if (nsown_capable(CAP_SETUID)) {
72074 new->suid = new->uid = kuid;
72075 if (!uid_eq(kuid, old->uid)) {
72076@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72077 goto error;
72078 }
72079
72080+ if (gr_check_user_change(kruid, keuid, -1))
72081+ goto error;
72082+
72083 if (ruid != (uid_t) -1) {
72084 new->uid = kruid;
72085 if (!uid_eq(kruid, old->uid)) {
72086@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72087 goto error;
72088 }
72089
72090+ if (gr_check_group_change(krgid, kegid, -1))
72091+ goto error;
72092+
72093 if (rgid != (gid_t) -1)
72094 new->gid = krgid;
72095 if (egid != (gid_t) -1)
72096@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72097 if (!uid_valid(kuid))
72098 return old_fsuid;
72099
72100+ if (gr_check_user_change(-1, -1, kuid))
72101+ goto error;
72102+
72103 new = prepare_creds();
72104 if (!new)
72105 return old_fsuid;
72106@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72107 }
72108 }
72109
72110+error:
72111 abort_creds(new);
72112 return old_fsuid;
72113
72114@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72115 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72116 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72117 nsown_capable(CAP_SETGID)) {
72118+ if (gr_check_group_change(-1, -1, kgid))
72119+ goto error;
72120+
72121 if (!gid_eq(kgid, old->fsgid)) {
72122 new->fsgid = kgid;
72123 goto change_okay;
72124 }
72125 }
72126
72127+error:
72128 abort_creds(new);
72129 return old_fsgid;
72130
72131@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72132 return -EFAULT;
72133
72134 down_read(&uts_sem);
72135- error = __copy_to_user(&name->sysname, &utsname()->sysname,
72136+ error = __copy_to_user(name->sysname, &utsname()->sysname,
72137 __OLD_UTS_LEN);
72138 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72139- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72140+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
72141 __OLD_UTS_LEN);
72142 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72143- error |= __copy_to_user(&name->release, &utsname()->release,
72144+ error |= __copy_to_user(name->release, &utsname()->release,
72145 __OLD_UTS_LEN);
72146 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72147- error |= __copy_to_user(&name->version, &utsname()->version,
72148+ error |= __copy_to_user(name->version, &utsname()->version,
72149 __OLD_UTS_LEN);
72150 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72151- error |= __copy_to_user(&name->machine, &utsname()->machine,
72152+ error |= __copy_to_user(name->machine, &utsname()->machine,
72153 __OLD_UTS_LEN);
72154 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72155 up_read(&uts_sem);
72156@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72157 error = get_dumpable(me->mm);
72158 break;
72159 case PR_SET_DUMPABLE:
72160- if (arg2 < 0 || arg2 > 1) {
72161+ if (arg2 > 1) {
72162 error = -EINVAL;
72163 break;
72164 }
72165diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72166index 26f65ea..df8e5ad 100644
72167--- a/kernel/sysctl.c
72168+++ b/kernel/sysctl.c
72169@@ -92,7 +92,6 @@
72170
72171
72172 #if defined(CONFIG_SYSCTL)
72173-
72174 /* External variables not in a header file. */
72175 extern int sysctl_overcommit_memory;
72176 extern int sysctl_overcommit_ratio;
72177@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72178 void __user *buffer, size_t *lenp, loff_t *ppos);
72179 #endif
72180
72181-#ifdef CONFIG_PRINTK
72182 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72183 void __user *buffer, size_t *lenp, loff_t *ppos);
72184-#endif
72185
72186 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72187 void __user *buffer, size_t *lenp, loff_t *ppos);
72188@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72189
72190 #endif
72191
72192+extern struct ctl_table grsecurity_table[];
72193+
72194 static struct ctl_table kern_table[];
72195 static struct ctl_table vm_table[];
72196 static struct ctl_table fs_table[];
72197@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72198 int sysctl_legacy_va_layout;
72199 #endif
72200
72201+#ifdef CONFIG_PAX_SOFTMODE
72202+static ctl_table pax_table[] = {
72203+ {
72204+ .procname = "softmode",
72205+ .data = &pax_softmode,
72206+ .maxlen = sizeof(unsigned int),
72207+ .mode = 0600,
72208+ .proc_handler = &proc_dointvec,
72209+ },
72210+
72211+ { }
72212+};
72213+#endif
72214+
72215 /* The default sysctl tables: */
72216
72217 static struct ctl_table sysctl_base_table[] = {
72218@@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72219 #endif
72220
72221 static struct ctl_table kern_table[] = {
72222+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72223+ {
72224+ .procname = "grsecurity",
72225+ .mode = 0500,
72226+ .child = grsecurity_table,
72227+ },
72228+#endif
72229+
72230+#ifdef CONFIG_PAX_SOFTMODE
72231+ {
72232+ .procname = "pax",
72233+ .mode = 0500,
72234+ .child = pax_table,
72235+ },
72236+#endif
72237+
72238 {
72239 .procname = "sched_child_runs_first",
72240 .data = &sysctl_sched_child_runs_first,
72241@@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72242 .data = &modprobe_path,
72243 .maxlen = KMOD_PATH_LEN,
72244 .mode = 0644,
72245- .proc_handler = proc_dostring,
72246+ .proc_handler = proc_dostring_modpriv,
72247 },
72248 {
72249 .procname = "modules_disabled",
72250@@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72251 .extra1 = &zero,
72252 .extra2 = &one,
72253 },
72254+#endif
72255 {
72256 .procname = "kptr_restrict",
72257 .data = &kptr_restrict,
72258 .maxlen = sizeof(int),
72259 .mode = 0644,
72260 .proc_handler = proc_dointvec_minmax_sysadmin,
72261+#ifdef CONFIG_GRKERNSEC_HIDESYM
72262+ .extra1 = &two,
72263+#else
72264 .extra1 = &zero,
72265+#endif
72266 .extra2 = &two,
72267 },
72268-#endif
72269 {
72270 .procname = "ngroups_max",
72271 .data = &ngroups_max,
72272@@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72273 .proc_handler = proc_dointvec_minmax,
72274 .extra1 = &zero,
72275 },
72276+ {
72277+ .procname = "heap_stack_gap",
72278+ .data = &sysctl_heap_stack_gap,
72279+ .maxlen = sizeof(sysctl_heap_stack_gap),
72280+ .mode = 0644,
72281+ .proc_handler = proc_doulongvec_minmax,
72282+ },
72283 #else
72284 {
72285 .procname = "nr_trim_pages",
72286@@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72287 buffer, lenp, ppos);
72288 }
72289
72290+int proc_dostring_modpriv(struct ctl_table *table, int write,
72291+ void __user *buffer, size_t *lenp, loff_t *ppos)
72292+{
72293+ if (write && !capable(CAP_SYS_MODULE))
72294+ return -EPERM;
72295+
72296+ return _proc_do_string(table->data, table->maxlen, write,
72297+ buffer, lenp, ppos);
72298+}
72299+
72300 static size_t proc_skip_spaces(char **buf)
72301 {
72302 size_t ret;
72303@@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72304 len = strlen(tmp);
72305 if (len > *size)
72306 len = *size;
72307+ if (len > sizeof(tmp))
72308+ len = sizeof(tmp);
72309 if (copy_to_user(*buf, tmp, len))
72310 return -EFAULT;
72311 *size -= len;
72312@@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72313 return err;
72314 }
72315
72316-#ifdef CONFIG_PRINTK
72317 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72318 void __user *buffer, size_t *lenp, loff_t *ppos)
72319 {
72320@@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72321
72322 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72323 }
72324-#endif
72325
72326 struct do_proc_dointvec_minmax_conv_param {
72327 int *min;
72328@@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72329 *i = val;
72330 } else {
72331 val = convdiv * (*i) / convmul;
72332- if (!first)
72333+ if (!first) {
72334 err = proc_put_char(&buffer, &left, '\t');
72335+ if (err)
72336+ break;
72337+ }
72338 err = proc_put_long(&buffer, &left, val, false);
72339 if (err)
72340 break;
72341@@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72342 return -ENOSYS;
72343 }
72344
72345+int proc_dostring_modpriv(struct ctl_table *table, int write,
72346+ void __user *buffer, size_t *lenp, loff_t *ppos)
72347+{
72348+ return -ENOSYS;
72349+}
72350+
72351 int proc_dointvec(struct ctl_table *table, int write,
72352 void __user *buffer, size_t *lenp, loff_t *ppos)
72353 {
72354@@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72355 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72356 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72357 EXPORT_SYMBOL(proc_dostring);
72358+EXPORT_SYMBOL(proc_dostring_modpriv);
72359 EXPORT_SYMBOL(proc_doulongvec_minmax);
72360 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72361diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72362index 65bdcf1..21eb831 100644
72363--- a/kernel/sysctl_binary.c
72364+++ b/kernel/sysctl_binary.c
72365@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72366 int i;
72367
72368 set_fs(KERNEL_DS);
72369- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72370+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72371 set_fs(old_fs);
72372 if (result < 0)
72373 goto out_kfree;
72374@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72375 }
72376
72377 set_fs(KERNEL_DS);
72378- result = vfs_write(file, buffer, str - buffer, &pos);
72379+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72380 set_fs(old_fs);
72381 if (result < 0)
72382 goto out_kfree;
72383@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72384 int i;
72385
72386 set_fs(KERNEL_DS);
72387- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72388+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72389 set_fs(old_fs);
72390 if (result < 0)
72391 goto out_kfree;
72392@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72393 }
72394
72395 set_fs(KERNEL_DS);
72396- result = vfs_write(file, buffer, str - buffer, &pos);
72397+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72398 set_fs(old_fs);
72399 if (result < 0)
72400 goto out_kfree;
72401@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72402 int i;
72403
72404 set_fs(KERNEL_DS);
72405- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72406+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72407 set_fs(old_fs);
72408 if (result < 0)
72409 goto out;
72410@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72411 __le16 dnaddr;
72412
72413 set_fs(KERNEL_DS);
72414- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72415+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72416 set_fs(old_fs);
72417 if (result < 0)
72418 goto out;
72419@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72420 le16_to_cpu(dnaddr) & 0x3ff);
72421
72422 set_fs(KERNEL_DS);
72423- result = vfs_write(file, buf, len, &pos);
72424+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72425 set_fs(old_fs);
72426 if (result < 0)
72427 goto out;
72428diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72429index 145bb4d..b2aa969 100644
72430--- a/kernel/taskstats.c
72431+++ b/kernel/taskstats.c
72432@@ -28,9 +28,12 @@
72433 #include <linux/fs.h>
72434 #include <linux/file.h>
72435 #include <linux/pid_namespace.h>
72436+#include <linux/grsecurity.h>
72437 #include <net/genetlink.h>
72438 #include <linux/atomic.h>
72439
72440+extern int gr_is_taskstats_denied(int pid);
72441+
72442 /*
72443 * Maximum length of a cpumask that can be specified in
72444 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72445@@ -570,6 +573,9 @@ err:
72446
72447 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72448 {
72449+ if (gr_is_taskstats_denied(current->pid))
72450+ return -EACCES;
72451+
72452 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72453 return cmd_attr_register_cpumask(info);
72454 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72455diff --git a/kernel/time.c b/kernel/time.c
72456index d226c6a..c7c0960 100644
72457--- a/kernel/time.c
72458+++ b/kernel/time.c
72459@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72460 return error;
72461
72462 if (tz) {
72463+ /* we log in do_settimeofday called below, so don't log twice
72464+ */
72465+ if (!tv)
72466+ gr_log_timechange();
72467+
72468 sys_tz = *tz;
72469 update_vsyscall_tz();
72470 if (firsttime) {
72471diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72472index f11d83b..d016d91 100644
72473--- a/kernel/time/alarmtimer.c
72474+++ b/kernel/time/alarmtimer.c
72475@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72476 struct platform_device *pdev;
72477 int error = 0;
72478 int i;
72479- struct k_clock alarm_clock = {
72480+ static struct k_clock alarm_clock = {
72481 .clock_getres = alarm_clock_getres,
72482 .clock_get = alarm_clock_get,
72483 .timer_create = alarm_timer_create,
72484diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72485index f113755..ec24223 100644
72486--- a/kernel/time/tick-broadcast.c
72487+++ b/kernel/time/tick-broadcast.c
72488@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72489 * then clear the broadcast bit.
72490 */
72491 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72492- int cpu = smp_processor_id();
72493+ cpu = smp_processor_id();
72494
72495 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72496 tick_broadcast_clear_oneshot(cpu);
72497diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72498index e424970..4c7962b 100644
72499--- a/kernel/time/timekeeping.c
72500+++ b/kernel/time/timekeeping.c
72501@@ -15,6 +15,7 @@
72502 #include <linux/init.h>
72503 #include <linux/mm.h>
72504 #include <linux/sched.h>
72505+#include <linux/grsecurity.h>
72506 #include <linux/syscore_ops.h>
72507 #include <linux/clocksource.h>
72508 #include <linux/jiffies.h>
72509@@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72510 if (!timespec_valid_strict(tv))
72511 return -EINVAL;
72512
72513+ gr_log_timechange();
72514+
72515 write_seqlock_irqsave(&tk->lock, flags);
72516
72517 timekeeping_forward_now(tk);
72518diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72519index af5a7e9..715611a 100644
72520--- a/kernel/time/timer_list.c
72521+++ b/kernel/time/timer_list.c
72522@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72523
72524 static void print_name_offset(struct seq_file *m, void *sym)
72525 {
72526+#ifdef CONFIG_GRKERNSEC_HIDESYM
72527+ SEQ_printf(m, "<%p>", NULL);
72528+#else
72529 char symname[KSYM_NAME_LEN];
72530
72531 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72532 SEQ_printf(m, "<%pK>", sym);
72533 else
72534 SEQ_printf(m, "%s", symname);
72535+#endif
72536 }
72537
72538 static void
72539@@ -112,7 +116,11 @@ next_one:
72540 static void
72541 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72542 {
72543+#ifdef CONFIG_GRKERNSEC_HIDESYM
72544+ SEQ_printf(m, " .base: %p\n", NULL);
72545+#else
72546 SEQ_printf(m, " .base: %pK\n", base);
72547+#endif
72548 SEQ_printf(m, " .index: %d\n",
72549 base->index);
72550 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72551@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72552 {
72553 struct proc_dir_entry *pe;
72554
72555+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72556+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72557+#else
72558 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72559+#endif
72560 if (!pe)
72561 return -ENOMEM;
72562 return 0;
72563diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72564index 0b537f2..40d6c20 100644
72565--- a/kernel/time/timer_stats.c
72566+++ b/kernel/time/timer_stats.c
72567@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72568 static unsigned long nr_entries;
72569 static struct entry entries[MAX_ENTRIES];
72570
72571-static atomic_t overflow_count;
72572+static atomic_unchecked_t overflow_count;
72573
72574 /*
72575 * The entries are in a hash-table, for fast lookup:
72576@@ -140,7 +140,7 @@ static void reset_entries(void)
72577 nr_entries = 0;
72578 memset(entries, 0, sizeof(entries));
72579 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72580- atomic_set(&overflow_count, 0);
72581+ atomic_set_unchecked(&overflow_count, 0);
72582 }
72583
72584 static struct entry *alloc_entry(void)
72585@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72586 if (likely(entry))
72587 entry->count++;
72588 else
72589- atomic_inc(&overflow_count);
72590+ atomic_inc_unchecked(&overflow_count);
72591
72592 out_unlock:
72593 raw_spin_unlock_irqrestore(lock, flags);
72594@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72595
72596 static void print_name_offset(struct seq_file *m, unsigned long addr)
72597 {
72598+#ifdef CONFIG_GRKERNSEC_HIDESYM
72599+ seq_printf(m, "<%p>", NULL);
72600+#else
72601 char symname[KSYM_NAME_LEN];
72602
72603 if (lookup_symbol_name(addr, symname) < 0)
72604- seq_printf(m, "<%p>", (void *)addr);
72605+ seq_printf(m, "<%pK>", (void *)addr);
72606 else
72607 seq_printf(m, "%s", symname);
72608+#endif
72609 }
72610
72611 static int tstats_show(struct seq_file *m, void *v)
72612@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72613
72614 seq_puts(m, "Timer Stats Version: v0.2\n");
72615 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72616- if (atomic_read(&overflow_count))
72617+ if (atomic_read_unchecked(&overflow_count))
72618 seq_printf(m, "Overflow: %d entries\n",
72619- atomic_read(&overflow_count));
72620+ atomic_read_unchecked(&overflow_count));
72621
72622 for (i = 0; i < nr_entries; i++) {
72623 entry = entries + i;
72624@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72625 {
72626 struct proc_dir_entry *pe;
72627
72628+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72629+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72630+#else
72631 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72632+#endif
72633 if (!pe)
72634 return -ENOMEM;
72635 return 0;
72636diff --git a/kernel/timer.c b/kernel/timer.c
72637index 367d008..46857a0 100644
72638--- a/kernel/timer.c
72639+++ b/kernel/timer.c
72640@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72641 /*
72642 * This function runs timers and the timer-tq in bottom half context.
72643 */
72644-static void run_timer_softirq(struct softirq_action *h)
72645+static void run_timer_softirq(void)
72646 {
72647 struct tvec_base *base = __this_cpu_read(tvec_bases);
72648
72649@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72650 return NOTIFY_OK;
72651 }
72652
72653-static struct notifier_block __cpuinitdata timers_nb = {
72654+static struct notifier_block __cpuinitconst timers_nb = {
72655 .notifier_call = timer_cpu_notify,
72656 };
72657
72658diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72659index c0bd030..62a1927 100644
72660--- a/kernel/trace/blktrace.c
72661+++ b/kernel/trace/blktrace.c
72662@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72663 struct blk_trace *bt = filp->private_data;
72664 char buf[16];
72665
72666- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72667+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72668
72669 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72670 }
72671@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72672 return 1;
72673
72674 bt = buf->chan->private_data;
72675- atomic_inc(&bt->dropped);
72676+ atomic_inc_unchecked(&bt->dropped);
72677 return 0;
72678 }
72679
72680@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72681
72682 bt->dir = dir;
72683 bt->dev = dev;
72684- atomic_set(&bt->dropped, 0);
72685+ atomic_set_unchecked(&bt->dropped, 0);
72686
72687 ret = -EIO;
72688 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72689diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72690index 356bc2f..7c94fc0 100644
72691--- a/kernel/trace/ftrace.c
72692+++ b/kernel/trace/ftrace.c
72693@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72694 if (unlikely(ftrace_disabled))
72695 return 0;
72696
72697+ ret = ftrace_arch_code_modify_prepare();
72698+ FTRACE_WARN_ON(ret);
72699+ if (ret)
72700+ return 0;
72701+
72702 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72703+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72704 if (ret) {
72705 ftrace_bug(ret, ip);
72706- return 0;
72707 }
72708- return 1;
72709+ return ret ? 0 : 1;
72710 }
72711
72712 /*
72713@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72714
72715 int
72716 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72717- void *data)
72718+ void *data)
72719 {
72720 struct ftrace_func_probe *entry;
72721 struct ftrace_page *pg;
72722@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72723 if (!count)
72724 return 0;
72725
72726+ pax_open_kernel();
72727 sort(start, count, sizeof(*start),
72728 ftrace_cmp_ips, ftrace_swap_ips);
72729+ pax_close_kernel();
72730
72731 start_pg = ftrace_allocate_pages(count);
72732 if (!start_pg)
72733@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
72734 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
72735
72736 static int ftrace_graph_active;
72737-static struct notifier_block ftrace_suspend_notifier;
72738-
72739 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
72740 {
72741 return 0;
72742@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
72743 return NOTIFY_DONE;
72744 }
72745
72746+static struct notifier_block ftrace_suspend_notifier = {
72747+ .notifier_call = ftrace_suspend_notifier_call
72748+};
72749+
72750 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72751 trace_func_graph_ent_t entryfunc)
72752 {
72753@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72754 goto out;
72755 }
72756
72757- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
72758 register_pm_notifier(&ftrace_suspend_notifier);
72759
72760 ftrace_graph_active++;
72761diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
72762index 4cb5e51..e7e05d9 100644
72763--- a/kernel/trace/ring_buffer.c
72764+++ b/kernel/trace/ring_buffer.c
72765@@ -346,9 +346,9 @@ struct buffer_data_page {
72766 */
72767 struct buffer_page {
72768 struct list_head list; /* list of buffer pages */
72769- local_t write; /* index for next write */
72770+ local_unchecked_t write; /* index for next write */
72771 unsigned read; /* index for next read */
72772- local_t entries; /* entries on this page */
72773+ local_unchecked_t entries; /* entries on this page */
72774 unsigned long real_end; /* real end of data */
72775 struct buffer_data_page *page; /* Actual data page */
72776 };
72777@@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
72778 unsigned long lost_events;
72779 unsigned long last_overrun;
72780 local_t entries_bytes;
72781- local_t commit_overrun;
72782- local_t overrun;
72783+ local_unchecked_t commit_overrun;
72784+ local_unchecked_t overrun;
72785 local_t entries;
72786 local_t committing;
72787 local_t commits;
72788@@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72789 *
72790 * We add a counter to the write field to denote this.
72791 */
72792- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
72793- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
72794+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
72795+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
72796
72797 /*
72798 * Just make sure we have seen our old_write and synchronize
72799@@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72800 * cmpxchg to only update if an interrupt did not already
72801 * do it for us. If the cmpxchg fails, we don't care.
72802 */
72803- (void)local_cmpxchg(&next_page->write, old_write, val);
72804- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
72805+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
72806+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
72807
72808 /*
72809 * No need to worry about races with clearing out the commit.
72810@@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
72811
72812 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
72813 {
72814- return local_read(&bpage->entries) & RB_WRITE_MASK;
72815+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
72816 }
72817
72818 static inline unsigned long rb_page_write(struct buffer_page *bpage)
72819 {
72820- return local_read(&bpage->write) & RB_WRITE_MASK;
72821+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
72822 }
72823
72824 static int
72825@@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
72826 * bytes consumed in ring buffer from here.
72827 * Increment overrun to account for the lost events.
72828 */
72829- local_add(page_entries, &cpu_buffer->overrun);
72830+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
72831 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72832 }
72833
72834@@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
72835 * it is our responsibility to update
72836 * the counters.
72837 */
72838- local_add(entries, &cpu_buffer->overrun);
72839+ local_add_unchecked(entries, &cpu_buffer->overrun);
72840 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72841
72842 /*
72843@@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72844 if (tail == BUF_PAGE_SIZE)
72845 tail_page->real_end = 0;
72846
72847- local_sub(length, &tail_page->write);
72848+ local_sub_unchecked(length, &tail_page->write);
72849 return;
72850 }
72851
72852@@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72853 rb_event_set_padding(event);
72854
72855 /* Set the write back to the previous setting */
72856- local_sub(length, &tail_page->write);
72857+ local_sub_unchecked(length, &tail_page->write);
72858 return;
72859 }
72860
72861@@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72862
72863 /* Set write to end of buffer */
72864 length = (tail + length) - BUF_PAGE_SIZE;
72865- local_sub(length, &tail_page->write);
72866+ local_sub_unchecked(length, &tail_page->write);
72867 }
72868
72869 /*
72870@@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72871 * about it.
72872 */
72873 if (unlikely(next_page == commit_page)) {
72874- local_inc(&cpu_buffer->commit_overrun);
72875+ local_inc_unchecked(&cpu_buffer->commit_overrun);
72876 goto out_reset;
72877 }
72878
72879@@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72880 cpu_buffer->tail_page) &&
72881 (cpu_buffer->commit_page ==
72882 cpu_buffer->reader_page))) {
72883- local_inc(&cpu_buffer->commit_overrun);
72884+ local_inc_unchecked(&cpu_buffer->commit_overrun);
72885 goto out_reset;
72886 }
72887 }
72888@@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72889 length += RB_LEN_TIME_EXTEND;
72890
72891 tail_page = cpu_buffer->tail_page;
72892- write = local_add_return(length, &tail_page->write);
72893+ write = local_add_return_unchecked(length, &tail_page->write);
72894
72895 /* set write to only the index of the write */
72896 write &= RB_WRITE_MASK;
72897@@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72898 kmemcheck_annotate_bitfield(event, bitfield);
72899 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
72900
72901- local_inc(&tail_page->entries);
72902+ local_inc_unchecked(&tail_page->entries);
72903
72904 /*
72905 * If this is the first commit on the page, then update
72906@@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72907
72908 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
72909 unsigned long write_mask =
72910- local_read(&bpage->write) & ~RB_WRITE_MASK;
72911+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
72912 unsigned long event_length = rb_event_length(event);
72913 /*
72914 * This is on the tail page. It is possible that
72915@@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72916 */
72917 old_index += write_mask;
72918 new_index += write_mask;
72919- index = local_cmpxchg(&bpage->write, old_index, new_index);
72920+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
72921 if (index == old_index) {
72922 /* update counters */
72923 local_sub(event_length, &cpu_buffer->entries_bytes);
72924@@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72925
72926 /* Do the likely case first */
72927 if (likely(bpage->page == (void *)addr)) {
72928- local_dec(&bpage->entries);
72929+ local_dec_unchecked(&bpage->entries);
72930 return;
72931 }
72932
72933@@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72934 start = bpage;
72935 do {
72936 if (bpage->page == (void *)addr) {
72937- local_dec(&bpage->entries);
72938+ local_dec_unchecked(&bpage->entries);
72939 return;
72940 }
72941 rb_inc_page(cpu_buffer, &bpage);
72942@@ -2923,7 +2923,7 @@ static inline unsigned long
72943 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
72944 {
72945 return local_read(&cpu_buffer->entries) -
72946- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
72947+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
72948 }
72949
72950 /**
72951@@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
72952 return 0;
72953
72954 cpu_buffer = buffer->buffers[cpu];
72955- ret = local_read(&cpu_buffer->overrun);
72956+ ret = local_read_unchecked(&cpu_buffer->overrun);
72957
72958 return ret;
72959 }
72960@@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
72961 return 0;
72962
72963 cpu_buffer = buffer->buffers[cpu];
72964- ret = local_read(&cpu_buffer->commit_overrun);
72965+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
72966
72967 return ret;
72968 }
72969@@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
72970 /* if you care about this being correct, lock the buffer */
72971 for_each_buffer_cpu(buffer, cpu) {
72972 cpu_buffer = buffer->buffers[cpu];
72973- overruns += local_read(&cpu_buffer->overrun);
72974+ overruns += local_read_unchecked(&cpu_buffer->overrun);
72975 }
72976
72977 return overruns;
72978@@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72979 /*
72980 * Reset the reader page to size zero.
72981 */
72982- local_set(&cpu_buffer->reader_page->write, 0);
72983- local_set(&cpu_buffer->reader_page->entries, 0);
72984+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
72985+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
72986 local_set(&cpu_buffer->reader_page->page->commit, 0);
72987 cpu_buffer->reader_page->real_end = 0;
72988
72989@@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72990 * want to compare with the last_overrun.
72991 */
72992 smp_mb();
72993- overwrite = local_read(&(cpu_buffer->overrun));
72994+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
72995
72996 /*
72997 * Here's the tricky part.
72998@@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
72999
73000 cpu_buffer->head_page
73001 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73002- local_set(&cpu_buffer->head_page->write, 0);
73003- local_set(&cpu_buffer->head_page->entries, 0);
73004+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
73005+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73006 local_set(&cpu_buffer->head_page->page->commit, 0);
73007
73008 cpu_buffer->head_page->read = 0;
73009@@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73010
73011 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73012 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73013- local_set(&cpu_buffer->reader_page->write, 0);
73014- local_set(&cpu_buffer->reader_page->entries, 0);
73015+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73016+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73017 local_set(&cpu_buffer->reader_page->page->commit, 0);
73018 cpu_buffer->reader_page->read = 0;
73019
73020- local_set(&cpu_buffer->commit_overrun, 0);
73021+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73022 local_set(&cpu_buffer->entries_bytes, 0);
73023- local_set(&cpu_buffer->overrun, 0);
73024+ local_set_unchecked(&cpu_buffer->overrun, 0);
73025 local_set(&cpu_buffer->entries, 0);
73026 local_set(&cpu_buffer->committing, 0);
73027 local_set(&cpu_buffer->commits, 0);
73028@@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73029 rb_init_page(bpage);
73030 bpage = reader->page;
73031 reader->page = *data_page;
73032- local_set(&reader->write, 0);
73033- local_set(&reader->entries, 0);
73034+ local_set_unchecked(&reader->write, 0);
73035+ local_set_unchecked(&reader->entries, 0);
73036 reader->read = 0;
73037 *data_page = bpage;
73038
73039diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73040index 31e4f55..62da00f 100644
73041--- a/kernel/trace/trace.c
73042+++ b/kernel/trace/trace.c
73043@@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73044 };
73045 #endif
73046
73047-static struct dentry *d_tracer;
73048-
73049 struct dentry *tracing_init_dentry(void)
73050 {
73051+ static struct dentry *d_tracer;
73052 static int once;
73053
73054 if (d_tracer)
73055@@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73056 return d_tracer;
73057 }
73058
73059-static struct dentry *d_percpu;
73060-
73061 struct dentry *tracing_dentry_percpu(void)
73062 {
73063+ static struct dentry *d_percpu;
73064 static int once;
73065 struct dentry *d_tracer;
73066
73067diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73068index d608d09..bd3801f 100644
73069--- a/kernel/trace/trace_events.c
73070+++ b/kernel/trace/trace_events.c
73071@@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73072 struct ftrace_module_file_ops {
73073 struct list_head list;
73074 struct module *mod;
73075- struct file_operations id;
73076- struct file_operations enable;
73077- struct file_operations format;
73078- struct file_operations filter;
73079 };
73080
73081 static struct ftrace_module_file_ops *
73082@@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73083
73084 file_ops->mod = mod;
73085
73086- file_ops->id = ftrace_event_id_fops;
73087- file_ops->id.owner = mod;
73088-
73089- file_ops->enable = ftrace_enable_fops;
73090- file_ops->enable.owner = mod;
73091-
73092- file_ops->filter = ftrace_event_filter_fops;
73093- file_ops->filter.owner = mod;
73094-
73095- file_ops->format = ftrace_event_format_fops;
73096- file_ops->format.owner = mod;
73097+ pax_open_kernel();
73098+ mod->trace_id.owner = mod;
73099+ mod->trace_enable.owner = mod;
73100+ mod->trace_filter.owner = mod;
73101+ mod->trace_format.owner = mod;
73102+ pax_close_kernel();
73103
73104 list_add(&file_ops->list, &ftrace_module_file_list);
73105
73106@@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73107
73108 for_each_event(call, start, end) {
73109 __trace_add_event_call(*call, mod,
73110- &file_ops->id, &file_ops->enable,
73111- &file_ops->filter, &file_ops->format);
73112+ &mod->trace_id, &mod->trace_enable,
73113+ &mod->trace_filter, &mod->trace_format);
73114 }
73115 }
73116
73117diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73118index fd3c8aa..5f324a6 100644
73119--- a/kernel/trace/trace_mmiotrace.c
73120+++ b/kernel/trace/trace_mmiotrace.c
73121@@ -24,7 +24,7 @@ struct header_iter {
73122 static struct trace_array *mmio_trace_array;
73123 static bool overrun_detected;
73124 static unsigned long prev_overruns;
73125-static atomic_t dropped_count;
73126+static atomic_unchecked_t dropped_count;
73127
73128 static void mmio_reset_data(struct trace_array *tr)
73129 {
73130@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73131
73132 static unsigned long count_overruns(struct trace_iterator *iter)
73133 {
73134- unsigned long cnt = atomic_xchg(&dropped_count, 0);
73135+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73136 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73137
73138 if (over > prev_overruns)
73139@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73140 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
73141 sizeof(*entry), 0, pc);
73142 if (!event) {
73143- atomic_inc(&dropped_count);
73144+ atomic_inc_unchecked(&dropped_count);
73145 return;
73146 }
73147 entry = ring_buffer_event_data(event);
73148@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73149 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73150 sizeof(*entry), 0, pc);
73151 if (!event) {
73152- atomic_inc(&dropped_count);
73153+ atomic_inc_unchecked(&dropped_count);
73154 return;
73155 }
73156 entry = ring_buffer_event_data(event);
73157diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73158index 123b189..1e9e2a6 100644
73159--- a/kernel/trace/trace_output.c
73160+++ b/kernel/trace/trace_output.c
73161@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73162
73163 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73164 if (!IS_ERR(p)) {
73165- p = mangle_path(s->buffer + s->len, p, "\n");
73166+ p = mangle_path(s->buffer + s->len, p, "\n\\");
73167 if (p) {
73168 s->len = p - s->buffer;
73169 return 1;
73170@@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73171 goto out;
73172 }
73173
73174+ pax_open_kernel();
73175 if (event->funcs->trace == NULL)
73176- event->funcs->trace = trace_nop_print;
73177+ *(void **)&event->funcs->trace = trace_nop_print;
73178 if (event->funcs->raw == NULL)
73179- event->funcs->raw = trace_nop_print;
73180+ *(void **)&event->funcs->raw = trace_nop_print;
73181 if (event->funcs->hex == NULL)
73182- event->funcs->hex = trace_nop_print;
73183+ *(void **)&event->funcs->hex = trace_nop_print;
73184 if (event->funcs->binary == NULL)
73185- event->funcs->binary = trace_nop_print;
73186+ *(void **)&event->funcs->binary = trace_nop_print;
73187+ pax_close_kernel();
73188
73189 key = event->type & (EVENT_HASHSIZE - 1);
73190
73191diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73192index 0c1b1657..95337e9 100644
73193--- a/kernel/trace/trace_stack.c
73194+++ b/kernel/trace/trace_stack.c
73195@@ -53,7 +53,7 @@ static inline void check_stack(void)
73196 return;
73197
73198 /* we do not handle interrupt stacks yet */
73199- if (!object_is_on_stack(&this_size))
73200+ if (!object_starts_on_stack(&this_size))
73201 return;
73202
73203 local_irq_save(flags);
73204diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73205index 28e9d6c9..50381bd 100644
73206--- a/lib/Kconfig.debug
73207+++ b/lib/Kconfig.debug
73208@@ -1278,6 +1278,7 @@ config LATENCYTOP
73209 depends on DEBUG_KERNEL
73210 depends on STACKTRACE_SUPPORT
73211 depends on PROC_FS
73212+ depends on !GRKERNSEC_HIDESYM
73213 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73214 select KALLSYMS
73215 select KALLSYMS_ALL
73216@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73217
73218 config PROVIDE_OHCI1394_DMA_INIT
73219 bool "Remote debugging over FireWire early on boot"
73220- depends on PCI && X86
73221+ depends on PCI && X86 && !GRKERNSEC
73222 help
73223 If you want to debug problems which hang or crash the kernel early
73224 on boot and the crashing machine has a FireWire port, you can use
73225@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73226
73227 config FIREWIRE_OHCI_REMOTE_DMA
73228 bool "Remote debugging over FireWire with firewire-ohci"
73229- depends on FIREWIRE_OHCI
73230+ depends on FIREWIRE_OHCI && !GRKERNSEC
73231 help
73232 This option lets you use the FireWire bus for remote debugging
73233 with help of the firewire-ohci driver. It enables unfiltered
73234diff --git a/lib/Makefile b/lib/Makefile
73235index a08b791..a3ff1eb 100644
73236--- a/lib/Makefile
73237+++ b/lib/Makefile
73238@@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73239
73240 obj-$(CONFIG_BTREE) += btree.o
73241 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73242-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73243+obj-y += list_debug.o
73244 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73245
73246 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73247diff --git a/lib/bitmap.c b/lib/bitmap.c
73248index 06fdfa1..97c5c7d 100644
73249--- a/lib/bitmap.c
73250+++ b/lib/bitmap.c
73251@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73252 {
73253 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73254 u32 chunk;
73255- const char __user __force *ubuf = (const char __user __force *)buf;
73256+ const char __user *ubuf = (const char __force_user *)buf;
73257
73258 bitmap_zero(maskp, nmaskbits);
73259
73260@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73261 {
73262 if (!access_ok(VERIFY_READ, ubuf, ulen))
73263 return -EFAULT;
73264- return __bitmap_parse((const char __force *)ubuf,
73265+ return __bitmap_parse((const char __force_kernel *)ubuf,
73266 ulen, 1, maskp, nmaskbits);
73267
73268 }
73269@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73270 {
73271 unsigned a, b;
73272 int c, old_c, totaldigits;
73273- const char __user __force *ubuf = (const char __user __force *)buf;
73274+ const char __user *ubuf = (const char __force_user *)buf;
73275 int exp_digit, in_range;
73276
73277 totaldigits = c = 0;
73278@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73279 {
73280 if (!access_ok(VERIFY_READ, ubuf, ulen))
73281 return -EFAULT;
73282- return __bitmap_parselist((const char __force *)ubuf,
73283+ return __bitmap_parselist((const char __force_kernel *)ubuf,
73284 ulen, 1, maskp, nmaskbits);
73285 }
73286 EXPORT_SYMBOL(bitmap_parselist_user);
73287diff --git a/lib/bug.c b/lib/bug.c
73288index d0cdf14..4d07bd2 100644
73289--- a/lib/bug.c
73290+++ b/lib/bug.c
73291@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73292 return BUG_TRAP_TYPE_NONE;
73293
73294 bug = find_bug(bugaddr);
73295+ if (!bug)
73296+ return BUG_TRAP_TYPE_NONE;
73297
73298 file = NULL;
73299 line = 0;
73300diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73301index d11808c..dc2d6f8 100644
73302--- a/lib/debugobjects.c
73303+++ b/lib/debugobjects.c
73304@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73305 if (limit > 4)
73306 return;
73307
73308- is_on_stack = object_is_on_stack(addr);
73309+ is_on_stack = object_starts_on_stack(addr);
73310 if (is_on_stack == onstack)
73311 return;
73312
73313diff --git a/lib/devres.c b/lib/devres.c
73314index 80b9c76..9e32279 100644
73315--- a/lib/devres.c
73316+++ b/lib/devres.c
73317@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73318 void devm_iounmap(struct device *dev, void __iomem *addr)
73319 {
73320 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73321- (void *)addr));
73322+ (void __force *)addr));
73323 iounmap(addr);
73324 }
73325 EXPORT_SYMBOL(devm_iounmap);
73326@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73327 {
73328 ioport_unmap(addr);
73329 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73330- devm_ioport_map_match, (void *)addr));
73331+ devm_ioport_map_match, (void __force *)addr));
73332 }
73333 EXPORT_SYMBOL(devm_ioport_unmap);
73334
73335diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73336index d84beb9..da44791 100644
73337--- a/lib/dma-debug.c
73338+++ b/lib/dma-debug.c
73339@@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73340
73341 void dma_debug_add_bus(struct bus_type *bus)
73342 {
73343- struct notifier_block *nb;
73344+ notifier_block_no_const *nb;
73345
73346 if (global_disable)
73347 return;
73348@@ -919,7 +919,7 @@ out:
73349
73350 static void check_for_stack(struct device *dev, void *addr)
73351 {
73352- if (object_is_on_stack(addr))
73353+ if (object_starts_on_stack(addr))
73354 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73355 "stack [addr=%p]\n", addr);
73356 }
73357diff --git a/lib/inflate.c b/lib/inflate.c
73358index 013a761..c28f3fc 100644
73359--- a/lib/inflate.c
73360+++ b/lib/inflate.c
73361@@ -269,7 +269,7 @@ static void free(void *where)
73362 malloc_ptr = free_mem_ptr;
73363 }
73364 #else
73365-#define malloc(a) kmalloc(a, GFP_KERNEL)
73366+#define malloc(a) kmalloc((a), GFP_KERNEL)
73367 #define free(a) kfree(a)
73368 #endif
73369
73370diff --git a/lib/ioremap.c b/lib/ioremap.c
73371index 0c9216c..863bd89 100644
73372--- a/lib/ioremap.c
73373+++ b/lib/ioremap.c
73374@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73375 unsigned long next;
73376
73377 phys_addr -= addr;
73378- pmd = pmd_alloc(&init_mm, pud, addr);
73379+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73380 if (!pmd)
73381 return -ENOMEM;
73382 do {
73383@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73384 unsigned long next;
73385
73386 phys_addr -= addr;
73387- pud = pud_alloc(&init_mm, pgd, addr);
73388+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73389 if (!pud)
73390 return -ENOMEM;
73391 do {
73392diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73393index bd2bea9..6b3c95e 100644
73394--- a/lib/is_single_threaded.c
73395+++ b/lib/is_single_threaded.c
73396@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73397 struct task_struct *p, *t;
73398 bool ret;
73399
73400+ if (!mm)
73401+ return true;
73402+
73403 if (atomic_read(&task->signal->live) != 1)
73404 return false;
73405
73406diff --git a/lib/list_debug.c b/lib/list_debug.c
73407index c24c2f7..3fc5da0 100644
73408--- a/lib/list_debug.c
73409+++ b/lib/list_debug.c
73410@@ -11,7 +11,9 @@
73411 #include <linux/bug.h>
73412 #include <linux/kernel.h>
73413 #include <linux/rculist.h>
73414+#include <linux/mm.h>
73415
73416+#ifdef CONFIG_DEBUG_LIST
73417 /*
73418 * Insert a new entry between two known consecutive entries.
73419 *
73420@@ -19,21 +21,32 @@
73421 * the prev/next entries already!
73422 */
73423
73424-void __list_add(struct list_head *new,
73425- struct list_head *prev,
73426- struct list_head *next)
73427+static bool __list_add_debug(struct list_head *new,
73428+ struct list_head *prev,
73429+ struct list_head *next)
73430 {
73431- WARN(next->prev != prev,
73432+ if (WARN(next->prev != prev,
73433 "list_add corruption. next->prev should be "
73434 "prev (%p), but was %p. (next=%p).\n",
73435- prev, next->prev, next);
73436- WARN(prev->next != next,
73437+ prev, next->prev, next) ||
73438+ WARN(prev->next != next,
73439 "list_add corruption. prev->next should be "
73440 "next (%p), but was %p. (prev=%p).\n",
73441- next, prev->next, prev);
73442- WARN(new == prev || new == next,
73443+ next, prev->next, prev) ||
73444+ WARN(new == prev || new == next,
73445 "list_add double add: new=%p, prev=%p, next=%p.\n",
73446- new, prev, next);
73447+ new, prev, next))
73448+ return false;
73449+ return true;
73450+}
73451+
73452+void __list_add(struct list_head *new,
73453+ struct list_head *prev,
73454+ struct list_head *next)
73455+{
73456+ if (!__list_add_debug(new, prev, next))
73457+ return;
73458+
73459 next->prev = new;
73460 new->next = next;
73461 new->prev = prev;
73462@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73463 }
73464 EXPORT_SYMBOL(__list_add);
73465
73466-void __list_del_entry(struct list_head *entry)
73467+static bool __list_del_entry_debug(struct list_head *entry)
73468 {
73469 struct list_head *prev, *next;
73470
73471@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73472 WARN(next->prev != entry,
73473 "list_del corruption. next->prev should be %p, "
73474 "but was %p\n", entry, next->prev))
73475+ return false;
73476+ return true;
73477+}
73478+
73479+void __list_del_entry(struct list_head *entry)
73480+{
73481+ if (!__list_del_entry_debug(entry))
73482 return;
73483
73484- __list_del(prev, next);
73485+ __list_del(entry->prev, entry->next);
73486 }
73487 EXPORT_SYMBOL(__list_del_entry);
73488
73489@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73490 void __list_add_rcu(struct list_head *new,
73491 struct list_head *prev, struct list_head *next)
73492 {
73493- WARN(next->prev != prev,
73494+ if (WARN(next->prev != prev,
73495 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73496- prev, next->prev, next);
73497- WARN(prev->next != next,
73498+ prev, next->prev, next) ||
73499+ WARN(prev->next != next,
73500 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73501- next, prev->next, prev);
73502+ next, prev->next, prev))
73503+ return;
73504+
73505 new->next = next;
73506 new->prev = prev;
73507 rcu_assign_pointer(list_next_rcu(prev), new);
73508 next->prev = new;
73509 }
73510 EXPORT_SYMBOL(__list_add_rcu);
73511+#endif
73512+
73513+void pax_list_add_tail(struct list_head *new, struct list_head *head)
73514+{
73515+ struct list_head *prev, *next;
73516+
73517+ prev = head->prev;
73518+ next = head;
73519+
73520+#ifdef CONFIG_DEBUG_LIST
73521+ if (!__list_add_debug(new, prev, next))
73522+ return;
73523+#endif
73524+
73525+ pax_open_kernel();
73526+ next->prev = new;
73527+ new->next = next;
73528+ new->prev = prev;
73529+ prev->next = new;
73530+ pax_close_kernel();
73531+}
73532+EXPORT_SYMBOL(pax_list_add_tail);
73533+
73534+void pax_list_del(struct list_head *entry)
73535+{
73536+#ifdef CONFIG_DEBUG_LIST
73537+ if (!__list_del_entry_debug(entry))
73538+ return;
73539+#endif
73540+
73541+ pax_open_kernel();
73542+ __list_del(entry->prev, entry->next);
73543+ entry->next = LIST_POISON1;
73544+ entry->prev = LIST_POISON2;
73545+ pax_close_kernel();
73546+}
73547+EXPORT_SYMBOL(pax_list_del);
73548diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73549index e796429..6e38f9f 100644
73550--- a/lib/radix-tree.c
73551+++ b/lib/radix-tree.c
73552@@ -92,7 +92,7 @@ struct radix_tree_preload {
73553 int nr;
73554 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73555 };
73556-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73557+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73558
73559 static inline void *ptr_to_indirect(void *ptr)
73560 {
73561diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73562index bb2b201..46abaf9 100644
73563--- a/lib/strncpy_from_user.c
73564+++ b/lib/strncpy_from_user.c
73565@@ -21,7 +21,7 @@
73566 */
73567 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73568 {
73569- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73570+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73571 long res = 0;
73572
73573 /*
73574diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73575index a28df52..3d55877 100644
73576--- a/lib/strnlen_user.c
73577+++ b/lib/strnlen_user.c
73578@@ -26,7 +26,7 @@
73579 */
73580 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73581 {
73582- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73583+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73584 long align, res = 0;
73585 unsigned long c;
73586
73587diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73588index 39c99fe..18f060b 100644
73589--- a/lib/vsprintf.c
73590+++ b/lib/vsprintf.c
73591@@ -16,6 +16,9 @@
73592 * - scnprintf and vscnprintf
73593 */
73594
73595+#ifdef CONFIG_GRKERNSEC_HIDESYM
73596+#define __INCLUDED_BY_HIDESYM 1
73597+#endif
73598 #include <stdarg.h>
73599 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73600 #include <linux/types.h>
73601@@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73602 char sym[KSYM_SYMBOL_LEN];
73603 if (ext == 'B')
73604 sprint_backtrace(sym, value);
73605- else if (ext != 'f' && ext != 's')
73606+ else if (ext != 'f' && ext != 's' && ext != 'a')
73607 sprint_symbol(sym, value);
73608 else
73609 sprint_symbol_no_offset(sym, value);
73610@@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73611 return number(buf, end, *(const netdev_features_t *)addr, spec);
73612 }
73613
73614+#ifdef CONFIG_GRKERNSEC_HIDESYM
73615+int kptr_restrict __read_mostly = 2;
73616+#else
73617 int kptr_restrict __read_mostly;
73618+#endif
73619
73620 /*
73621 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73622@@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73623 * - 'S' For symbolic direct pointers with offset
73624 * - 's' For symbolic direct pointers without offset
73625 * - 'B' For backtraced symbolic direct pointers with offset
73626+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73627+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73628 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73629 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73630 * - 'M' For a 6-byte MAC address, it prints the address in the
73631@@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73632
73633 if (!ptr && *fmt != 'K') {
73634 /*
73635- * Print (null) with the same width as a pointer so it makes
73636+ * Print (nil) with the same width as a pointer so it makes
73637 * tabular output look nice.
73638 */
73639 if (spec.field_width == -1)
73640 spec.field_width = default_width;
73641- return string(buf, end, "(null)", spec);
73642+ return string(buf, end, "(nil)", spec);
73643 }
73644
73645 switch (*fmt) {
73646@@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73647 /* Fallthrough */
73648 case 'S':
73649 case 's':
73650+#ifdef CONFIG_GRKERNSEC_HIDESYM
73651+ break;
73652+#else
73653+ return symbol_string(buf, end, ptr, spec, *fmt);
73654+#endif
73655+ case 'A':
73656+ case 'a':
73657 case 'B':
73658 return symbol_string(buf, end, ptr, spec, *fmt);
73659 case 'R':
73660@@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73661 va_end(va);
73662 return buf;
73663 }
73664+ case 'P':
73665+ break;
73666 case 'K':
73667 /*
73668 * %pK cannot be used in IRQ context because its test
73669@@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73670 }
73671 break;
73672 }
73673+
73674+#ifdef CONFIG_GRKERNSEC_HIDESYM
73675+ /* 'P' = approved pointers to copy to userland,
73676+ as in the /proc/kallsyms case, as we make it display nothing
73677+ for non-root users, and the real contents for root users
73678+ Also ignore 'K' pointers, since we force their NULLing for non-root users
73679+ above
73680+ */
73681+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73682+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73683+ dump_stack();
73684+ ptr = NULL;
73685+ }
73686+#endif
73687+
73688 spec.flags |= SMALL;
73689 if (spec.field_width == -1) {
73690 spec.field_width = default_width;
73691@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73692 typeof(type) value; \
73693 if (sizeof(type) == 8) { \
73694 args = PTR_ALIGN(args, sizeof(u32)); \
73695- *(u32 *)&value = *(u32 *)args; \
73696- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73697+ *(u32 *)&value = *(const u32 *)args; \
73698+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73699 } else { \
73700 args = PTR_ALIGN(args, sizeof(type)); \
73701- value = *(typeof(type) *)args; \
73702+ value = *(const typeof(type) *)args; \
73703 } \
73704 args += sizeof(type); \
73705 value; \
73706@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73707 case FORMAT_TYPE_STR: {
73708 const char *str_arg = args;
73709 args += strlen(str_arg) + 1;
73710- str = string(str, end, (char *)str_arg, spec);
73711+ str = string(str, end, str_arg, spec);
73712 break;
73713 }
73714
73715diff --git a/localversion-grsec b/localversion-grsec
73716new file mode 100644
73717index 0000000..7cd6065
73718--- /dev/null
73719+++ b/localversion-grsec
73720@@ -0,0 +1 @@
73721+-grsec
73722diff --git a/mm/Kconfig b/mm/Kconfig
73723index a3f8ddd..f31e92e 100644
73724--- a/mm/Kconfig
73725+++ b/mm/Kconfig
73726@@ -252,10 +252,10 @@ config KSM
73727 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
73728
73729 config DEFAULT_MMAP_MIN_ADDR
73730- int "Low address space to protect from user allocation"
73731+ int "Low address space to protect from user allocation"
73732 depends on MMU
73733- default 4096
73734- help
73735+ default 65536
73736+ help
73737 This is the portion of low virtual memory which should be protected
73738 from userspace allocation. Keeping a user from writing to low pages
73739 can help reduce the impact of kernel NULL pointer bugs.
73740@@ -286,7 +286,7 @@ config MEMORY_FAILURE
73741
73742 config HWPOISON_INJECT
73743 tristate "HWPoison pages injector"
73744- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
73745+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
73746 select PROC_PAGE_MONITOR
73747
73748 config NOMMU_INITIAL_TRIM_EXCESS
73749diff --git a/mm/filemap.c b/mm/filemap.c
73750index 83efee7..3f99381 100644
73751--- a/mm/filemap.c
73752+++ b/mm/filemap.c
73753@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
73754 struct address_space *mapping = file->f_mapping;
73755
73756 if (!mapping->a_ops->readpage)
73757- return -ENOEXEC;
73758+ return -ENODEV;
73759 file_accessed(file);
73760 vma->vm_ops = &generic_file_vm_ops;
73761 return 0;
73762@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
73763 *pos = i_size_read(inode);
73764
73765 if (limit != RLIM_INFINITY) {
73766+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
73767 if (*pos >= limit) {
73768 send_sig(SIGXFSZ, current, 0);
73769 return -EFBIG;
73770diff --git a/mm/fremap.c b/mm/fremap.c
73771index a0aaf0e..20325c3 100644
73772--- a/mm/fremap.c
73773+++ b/mm/fremap.c
73774@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
73775 retry:
73776 vma = find_vma(mm, start);
73777
73778+#ifdef CONFIG_PAX_SEGMEXEC
73779+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
73780+ goto out;
73781+#endif
73782+
73783 /*
73784 * Make sure the vma is shared, that it supports prefaulting,
73785 * and that the remapped range is valid and fully within
73786diff --git a/mm/highmem.c b/mm/highmem.c
73787index 09fc744..3936897 100644
73788--- a/mm/highmem.c
73789+++ b/mm/highmem.c
73790@@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
73791 * So no dangers, even with speculative execution.
73792 */
73793 page = pte_page(pkmap_page_table[i]);
73794+ pax_open_kernel();
73795 pte_clear(&init_mm, (unsigned long)page_address(page),
73796 &pkmap_page_table[i]);
73797-
73798+ pax_close_kernel();
73799 set_page_address(page, NULL);
73800 need_flush = 1;
73801 }
73802@@ -199,9 +200,11 @@ start:
73803 }
73804 }
73805 vaddr = PKMAP_ADDR(last_pkmap_nr);
73806+
73807+ pax_open_kernel();
73808 set_pte_at(&init_mm, vaddr,
73809 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
73810-
73811+ pax_close_kernel();
73812 pkmap_count[last_pkmap_nr] = 1;
73813 set_page_address(page, (void *)vaddr);
73814
73815diff --git a/mm/huge_memory.c b/mm/huge_memory.c
73816index 40f17c3..c1cc011 100644
73817--- a/mm/huge_memory.c
73818+++ b/mm/huge_memory.c
73819@@ -710,7 +710,7 @@ out:
73820 * run pte_offset_map on the pmd, if an huge pmd could
73821 * materialize from under us from a different thread.
73822 */
73823- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
73824+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73825 return VM_FAULT_OOM;
73826 /* if an huge pmd materialized from under us just retry later */
73827 if (unlikely(pmd_trans_huge(*pmd)))
73828diff --git a/mm/hugetlb.c b/mm/hugetlb.c
73829index b969ed4..10e3e37 100644
73830--- a/mm/hugetlb.c
73831+++ b/mm/hugetlb.c
73832@@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
73833 return 1;
73834 }
73835
73836+#ifdef CONFIG_PAX_SEGMEXEC
73837+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
73838+{
73839+ struct mm_struct *mm = vma->vm_mm;
73840+ struct vm_area_struct *vma_m;
73841+ unsigned long address_m;
73842+ pte_t *ptep_m;
73843+
73844+ vma_m = pax_find_mirror_vma(vma);
73845+ if (!vma_m)
73846+ return;
73847+
73848+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73849+ address_m = address + SEGMEXEC_TASK_SIZE;
73850+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
73851+ get_page(page_m);
73852+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
73853+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
73854+}
73855+#endif
73856+
73857 /*
73858 * Hugetlb_cow() should be called with page lock of the original hugepage held.
73859 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
73860@@ -2627,6 +2648,11 @@ retry_avoidcopy:
73861 make_huge_pte(vma, new_page, 1));
73862 page_remove_rmap(old_page);
73863 hugepage_add_new_anon_rmap(new_page, vma, address);
73864+
73865+#ifdef CONFIG_PAX_SEGMEXEC
73866+ pax_mirror_huge_pte(vma, address, new_page);
73867+#endif
73868+
73869 /* Make the old page be freed below */
73870 new_page = old_page;
73871 }
73872@@ -2786,6 +2812,10 @@ retry:
73873 && (vma->vm_flags & VM_SHARED)));
73874 set_huge_pte_at(mm, address, ptep, new_pte);
73875
73876+#ifdef CONFIG_PAX_SEGMEXEC
73877+ pax_mirror_huge_pte(vma, address, page);
73878+#endif
73879+
73880 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
73881 /* Optimization, do the COW without a second fault */
73882 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
73883@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73884 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
73885 struct hstate *h = hstate_vma(vma);
73886
73887+#ifdef CONFIG_PAX_SEGMEXEC
73888+ struct vm_area_struct *vma_m;
73889+#endif
73890+
73891 address &= huge_page_mask(h);
73892
73893 ptep = huge_pte_offset(mm, address);
73894@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73895 VM_FAULT_SET_HINDEX(hstate_index(h));
73896 }
73897
73898+#ifdef CONFIG_PAX_SEGMEXEC
73899+ vma_m = pax_find_mirror_vma(vma);
73900+ if (vma_m) {
73901+ unsigned long address_m;
73902+
73903+ if (vma->vm_start > vma_m->vm_start) {
73904+ address_m = address;
73905+ address -= SEGMEXEC_TASK_SIZE;
73906+ vma = vma_m;
73907+ h = hstate_vma(vma);
73908+ } else
73909+ address_m = address + SEGMEXEC_TASK_SIZE;
73910+
73911+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
73912+ return VM_FAULT_OOM;
73913+ address_m &= HPAGE_MASK;
73914+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
73915+ }
73916+#endif
73917+
73918 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
73919 if (!ptep)
73920 return VM_FAULT_OOM;
73921diff --git a/mm/internal.h b/mm/internal.h
73922index 3c5197d..08d0065 100644
73923--- a/mm/internal.h
73924+++ b/mm/internal.h
73925@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
73926 * in mm/page_alloc.c
73927 */
73928 extern void __free_pages_bootmem(struct page *page, unsigned int order);
73929+extern void free_compound_page(struct page *page);
73930 extern void prep_compound_page(struct page *page, unsigned long order);
73931 #ifdef CONFIG_MEMORY_FAILURE
73932 extern bool is_free_buddy_page(struct page *page);
73933diff --git a/mm/kmemleak.c b/mm/kmemleak.c
73934index a217cc5..44b2b35 100644
73935--- a/mm/kmemleak.c
73936+++ b/mm/kmemleak.c
73937@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
73938
73939 for (i = 0; i < object->trace_len; i++) {
73940 void *ptr = (void *)object->trace[i];
73941- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
73942+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
73943 }
73944 }
73945
73946@@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
73947 return -ENOMEM;
73948 }
73949
73950- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
73951+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
73952 &kmemleak_fops);
73953 if (!dentry)
73954 pr_warning("Failed to create the debugfs kmemleak file\n");
73955diff --git a/mm/maccess.c b/mm/maccess.c
73956index d53adf9..03a24bf 100644
73957--- a/mm/maccess.c
73958+++ b/mm/maccess.c
73959@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
73960 set_fs(KERNEL_DS);
73961 pagefault_disable();
73962 ret = __copy_from_user_inatomic(dst,
73963- (__force const void __user *)src, size);
73964+ (const void __force_user *)src, size);
73965 pagefault_enable();
73966 set_fs(old_fs);
73967
73968@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
73969
73970 set_fs(KERNEL_DS);
73971 pagefault_disable();
73972- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
73973+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
73974 pagefault_enable();
73975 set_fs(old_fs);
73976
73977diff --git a/mm/madvise.c b/mm/madvise.c
73978index 03dfa5c..b032917 100644
73979--- a/mm/madvise.c
73980+++ b/mm/madvise.c
73981@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
73982 pgoff_t pgoff;
73983 unsigned long new_flags = vma->vm_flags;
73984
73985+#ifdef CONFIG_PAX_SEGMEXEC
73986+ struct vm_area_struct *vma_m;
73987+#endif
73988+
73989 switch (behavior) {
73990 case MADV_NORMAL:
73991 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
73992@@ -123,6 +127,13 @@ success:
73993 /*
73994 * vm_flags is protected by the mmap_sem held in write mode.
73995 */
73996+
73997+#ifdef CONFIG_PAX_SEGMEXEC
73998+ vma_m = pax_find_mirror_vma(vma);
73999+ if (vma_m)
74000+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74001+#endif
74002+
74003 vma->vm_flags = new_flags;
74004
74005 out:
74006@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74007 struct vm_area_struct ** prev,
74008 unsigned long start, unsigned long end)
74009 {
74010+
74011+#ifdef CONFIG_PAX_SEGMEXEC
74012+ struct vm_area_struct *vma_m;
74013+#endif
74014+
74015 *prev = vma;
74016 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74017 return -EINVAL;
74018@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74019 zap_page_range(vma, start, end - start, &details);
74020 } else
74021 zap_page_range(vma, start, end - start, NULL);
74022+
74023+#ifdef CONFIG_PAX_SEGMEXEC
74024+ vma_m = pax_find_mirror_vma(vma);
74025+ if (vma_m) {
74026+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74027+ struct zap_details details = {
74028+ .nonlinear_vma = vma_m,
74029+ .last_index = ULONG_MAX,
74030+ };
74031+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74032+ } else
74033+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74034+ }
74035+#endif
74036+
74037 return 0;
74038 }
74039
74040@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74041 if (end < start)
74042 goto out;
74043
74044+#ifdef CONFIG_PAX_SEGMEXEC
74045+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74046+ if (end > SEGMEXEC_TASK_SIZE)
74047+ goto out;
74048+ } else
74049+#endif
74050+
74051+ if (end > TASK_SIZE)
74052+ goto out;
74053+
74054 error = 0;
74055 if (end == start)
74056 goto out;
74057diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74058index 8b20278..05dac18 100644
74059--- a/mm/memory-failure.c
74060+++ b/mm/memory-failure.c
74061@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74062
74063 int sysctl_memory_failure_recovery __read_mostly = 1;
74064
74065-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74066+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74067
74068 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74069
74070@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74071 pfn, t->comm, t->pid);
74072 si.si_signo = SIGBUS;
74073 si.si_errno = 0;
74074- si.si_addr = (void *)addr;
74075+ si.si_addr = (void __user *)addr;
74076 #ifdef __ARCH_SI_TRAPNO
74077 si.si_trapno = trapno;
74078 #endif
74079@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74080 }
74081
74082 nr_pages = 1 << compound_trans_order(hpage);
74083- atomic_long_add(nr_pages, &mce_bad_pages);
74084+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74085
74086 /*
74087 * We need/can do nothing about count=0 pages.
74088@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74089 if (!PageHWPoison(hpage)
74090 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74091 || (p != hpage && TestSetPageHWPoison(hpage))) {
74092- atomic_long_sub(nr_pages, &mce_bad_pages);
74093+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74094 return 0;
74095 }
74096 set_page_hwpoison_huge_page(hpage);
74097@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74098 }
74099 if (hwpoison_filter(p)) {
74100 if (TestClearPageHWPoison(p))
74101- atomic_long_sub(nr_pages, &mce_bad_pages);
74102+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74103 unlock_page(hpage);
74104 put_page(hpage);
74105 return 0;
74106@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74107 return 0;
74108 }
74109 if (TestClearPageHWPoison(p))
74110- atomic_long_sub(nr_pages, &mce_bad_pages);
74111+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74112 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74113 return 0;
74114 }
74115@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74116 */
74117 if (TestClearPageHWPoison(page)) {
74118 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74119- atomic_long_sub(nr_pages, &mce_bad_pages);
74120+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74121 freeit = 1;
74122 if (PageHuge(page))
74123 clear_page_hwpoison_huge_page(page);
74124@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74125 }
74126 done:
74127 if (!PageHWPoison(hpage))
74128- atomic_long_add(1 << compound_trans_order(hpage),
74129+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74130 &mce_bad_pages);
74131 set_page_hwpoison_huge_page(hpage);
74132 dequeue_hwpoisoned_huge_page(hpage);
74133@@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74134 return ret;
74135
74136 done:
74137- atomic_long_add(1, &mce_bad_pages);
74138+ atomic_long_add_unchecked(1, &mce_bad_pages);
74139 SetPageHWPoison(page);
74140 /* keep elevated page count for bad page */
74141 return ret;
74142diff --git a/mm/memory.c b/mm/memory.c
74143index f2973b2..fd020a7 100644
74144--- a/mm/memory.c
74145+++ b/mm/memory.c
74146@@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74147 free_pte_range(tlb, pmd, addr);
74148 } while (pmd++, addr = next, addr != end);
74149
74150+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74151 start &= PUD_MASK;
74152 if (start < floor)
74153 return;
74154@@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74155 pmd = pmd_offset(pud, start);
74156 pud_clear(pud);
74157 pmd_free_tlb(tlb, pmd, start);
74158+#endif
74159+
74160 }
74161
74162 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74163@@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74164 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74165 } while (pud++, addr = next, addr != end);
74166
74167+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74168 start &= PGDIR_MASK;
74169 if (start < floor)
74170 return;
74171@@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74172 pud = pud_offset(pgd, start);
74173 pgd_clear(pgd);
74174 pud_free_tlb(tlb, pud, start);
74175+#endif
74176+
74177 }
74178
74179 /*
74180@@ -1626,12 +1632,6 @@ no_page_table:
74181 return page;
74182 }
74183
74184-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74185-{
74186- return stack_guard_page_start(vma, addr) ||
74187- stack_guard_page_end(vma, addr+PAGE_SIZE);
74188-}
74189-
74190 /**
74191 * __get_user_pages() - pin user pages in memory
74192 * @tsk: task_struct of target task
74193@@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74194 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74195 i = 0;
74196
74197- do {
74198+ while (nr_pages) {
74199 struct vm_area_struct *vma;
74200
74201- vma = find_extend_vma(mm, start);
74202+ vma = find_vma(mm, start);
74203 if (!vma && in_gate_area(mm, start)) {
74204 unsigned long pg = start & PAGE_MASK;
74205 pgd_t *pgd;
74206@@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74207 goto next_page;
74208 }
74209
74210- if (!vma ||
74211+ if (!vma || start < vma->vm_start ||
74212 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74213 !(vm_flags & vma->vm_flags))
74214 return i ? : -EFAULT;
74215@@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74216 int ret;
74217 unsigned int fault_flags = 0;
74218
74219- /* For mlock, just skip the stack guard page. */
74220- if (foll_flags & FOLL_MLOCK) {
74221- if (stack_guard_page(vma, start))
74222- goto next_page;
74223- }
74224 if (foll_flags & FOLL_WRITE)
74225 fault_flags |= FAULT_FLAG_WRITE;
74226 if (nonblocking)
74227@@ -1860,7 +1855,7 @@ next_page:
74228 start += PAGE_SIZE;
74229 nr_pages--;
74230 } while (nr_pages && start < vma->vm_end);
74231- } while (nr_pages);
74232+ }
74233 return i;
74234 }
74235 EXPORT_SYMBOL(__get_user_pages);
74236@@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74237 page_add_file_rmap(page);
74238 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74239
74240+#ifdef CONFIG_PAX_SEGMEXEC
74241+ pax_mirror_file_pte(vma, addr, page, ptl);
74242+#endif
74243+
74244 retval = 0;
74245 pte_unmap_unlock(pte, ptl);
74246 return retval;
74247@@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74248 if (!page_count(page))
74249 return -EINVAL;
74250 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74251+
74252+#ifdef CONFIG_PAX_SEGMEXEC
74253+ struct vm_area_struct *vma_m;
74254+#endif
74255+
74256 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74257 BUG_ON(vma->vm_flags & VM_PFNMAP);
74258 vma->vm_flags |= VM_MIXEDMAP;
74259+
74260+#ifdef CONFIG_PAX_SEGMEXEC
74261+ vma_m = pax_find_mirror_vma(vma);
74262+ if (vma_m)
74263+ vma_m->vm_flags |= VM_MIXEDMAP;
74264+#endif
74265+
74266 }
74267 return insert_page(vma, addr, page, vma->vm_page_prot);
74268 }
74269@@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74270 unsigned long pfn)
74271 {
74272 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74273+ BUG_ON(vma->vm_mirror);
74274
74275 if (addr < vma->vm_start || addr >= vma->vm_end)
74276 return -EFAULT;
74277@@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74278
74279 BUG_ON(pud_huge(*pud));
74280
74281- pmd = pmd_alloc(mm, pud, addr);
74282+ pmd = (mm == &init_mm) ?
74283+ pmd_alloc_kernel(mm, pud, addr) :
74284+ pmd_alloc(mm, pud, addr);
74285 if (!pmd)
74286 return -ENOMEM;
74287 do {
74288@@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74289 unsigned long next;
74290 int err;
74291
74292- pud = pud_alloc(mm, pgd, addr);
74293+ pud = (mm == &init_mm) ?
74294+ pud_alloc_kernel(mm, pgd, addr) :
74295+ pud_alloc(mm, pgd, addr);
74296 if (!pud)
74297 return -ENOMEM;
74298 do {
74299@@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74300 copy_user_highpage(dst, src, va, vma);
74301 }
74302
74303+#ifdef CONFIG_PAX_SEGMEXEC
74304+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74305+{
74306+ struct mm_struct *mm = vma->vm_mm;
74307+ spinlock_t *ptl;
74308+ pte_t *pte, entry;
74309+
74310+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74311+ entry = *pte;
74312+ if (!pte_present(entry)) {
74313+ if (!pte_none(entry)) {
74314+ BUG_ON(pte_file(entry));
74315+ free_swap_and_cache(pte_to_swp_entry(entry));
74316+ pte_clear_not_present_full(mm, address, pte, 0);
74317+ }
74318+ } else {
74319+ struct page *page;
74320+
74321+ flush_cache_page(vma, address, pte_pfn(entry));
74322+ entry = ptep_clear_flush(vma, address, pte);
74323+ BUG_ON(pte_dirty(entry));
74324+ page = vm_normal_page(vma, address, entry);
74325+ if (page) {
74326+ update_hiwater_rss(mm);
74327+ if (PageAnon(page))
74328+ dec_mm_counter_fast(mm, MM_ANONPAGES);
74329+ else
74330+ dec_mm_counter_fast(mm, MM_FILEPAGES);
74331+ page_remove_rmap(page);
74332+ page_cache_release(page);
74333+ }
74334+ }
74335+ pte_unmap_unlock(pte, ptl);
74336+}
74337+
74338+/* PaX: if vma is mirrored, synchronize the mirror's PTE
74339+ *
74340+ * the ptl of the lower mapped page is held on entry and is not released on exit
74341+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74342+ */
74343+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74344+{
74345+ struct mm_struct *mm = vma->vm_mm;
74346+ unsigned long address_m;
74347+ spinlock_t *ptl_m;
74348+ struct vm_area_struct *vma_m;
74349+ pmd_t *pmd_m;
74350+ pte_t *pte_m, entry_m;
74351+
74352+ BUG_ON(!page_m || !PageAnon(page_m));
74353+
74354+ vma_m = pax_find_mirror_vma(vma);
74355+ if (!vma_m)
74356+ return;
74357+
74358+ BUG_ON(!PageLocked(page_m));
74359+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74360+ address_m = address + SEGMEXEC_TASK_SIZE;
74361+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74362+ pte_m = pte_offset_map(pmd_m, address_m);
74363+ ptl_m = pte_lockptr(mm, pmd_m);
74364+ if (ptl != ptl_m) {
74365+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74366+ if (!pte_none(*pte_m))
74367+ goto out;
74368+ }
74369+
74370+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74371+ page_cache_get(page_m);
74372+ page_add_anon_rmap(page_m, vma_m, address_m);
74373+ inc_mm_counter_fast(mm, MM_ANONPAGES);
74374+ set_pte_at(mm, address_m, pte_m, entry_m);
74375+ update_mmu_cache(vma_m, address_m, entry_m);
74376+out:
74377+ if (ptl != ptl_m)
74378+ spin_unlock(ptl_m);
74379+ pte_unmap(pte_m);
74380+ unlock_page(page_m);
74381+}
74382+
74383+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74384+{
74385+ struct mm_struct *mm = vma->vm_mm;
74386+ unsigned long address_m;
74387+ spinlock_t *ptl_m;
74388+ struct vm_area_struct *vma_m;
74389+ pmd_t *pmd_m;
74390+ pte_t *pte_m, entry_m;
74391+
74392+ BUG_ON(!page_m || PageAnon(page_m));
74393+
74394+ vma_m = pax_find_mirror_vma(vma);
74395+ if (!vma_m)
74396+ return;
74397+
74398+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74399+ address_m = address + SEGMEXEC_TASK_SIZE;
74400+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74401+ pte_m = pte_offset_map(pmd_m, address_m);
74402+ ptl_m = pte_lockptr(mm, pmd_m);
74403+ if (ptl != ptl_m) {
74404+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74405+ if (!pte_none(*pte_m))
74406+ goto out;
74407+ }
74408+
74409+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74410+ page_cache_get(page_m);
74411+ page_add_file_rmap(page_m);
74412+ inc_mm_counter_fast(mm, MM_FILEPAGES);
74413+ set_pte_at(mm, address_m, pte_m, entry_m);
74414+ update_mmu_cache(vma_m, address_m, entry_m);
74415+out:
74416+ if (ptl != ptl_m)
74417+ spin_unlock(ptl_m);
74418+ pte_unmap(pte_m);
74419+}
74420+
74421+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74422+{
74423+ struct mm_struct *mm = vma->vm_mm;
74424+ unsigned long address_m;
74425+ spinlock_t *ptl_m;
74426+ struct vm_area_struct *vma_m;
74427+ pmd_t *pmd_m;
74428+ pte_t *pte_m, entry_m;
74429+
74430+ vma_m = pax_find_mirror_vma(vma);
74431+ if (!vma_m)
74432+ return;
74433+
74434+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74435+ address_m = address + SEGMEXEC_TASK_SIZE;
74436+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74437+ pte_m = pte_offset_map(pmd_m, address_m);
74438+ ptl_m = pte_lockptr(mm, pmd_m);
74439+ if (ptl != ptl_m) {
74440+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74441+ if (!pte_none(*pte_m))
74442+ goto out;
74443+ }
74444+
74445+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74446+ set_pte_at(mm, address_m, pte_m, entry_m);
74447+out:
74448+ if (ptl != ptl_m)
74449+ spin_unlock(ptl_m);
74450+ pte_unmap(pte_m);
74451+}
74452+
74453+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74454+{
74455+ struct page *page_m;
74456+ pte_t entry;
74457+
74458+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74459+ goto out;
74460+
74461+ entry = *pte;
74462+ page_m = vm_normal_page(vma, address, entry);
74463+ if (!page_m)
74464+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74465+ else if (PageAnon(page_m)) {
74466+ if (pax_find_mirror_vma(vma)) {
74467+ pte_unmap_unlock(pte, ptl);
74468+ lock_page(page_m);
74469+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74470+ if (pte_same(entry, *pte))
74471+ pax_mirror_anon_pte(vma, address, page_m, ptl);
74472+ else
74473+ unlock_page(page_m);
74474+ }
74475+ } else
74476+ pax_mirror_file_pte(vma, address, page_m, ptl);
74477+
74478+out:
74479+ pte_unmap_unlock(pte, ptl);
74480+}
74481+#endif
74482+
74483 /*
74484 * This routine handles present pages, when users try to write
74485 * to a shared page. It is done by copying the page to a new address
74486@@ -2720,6 +2916,12 @@ gotten:
74487 */
74488 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74489 if (likely(pte_same(*page_table, orig_pte))) {
74490+
74491+#ifdef CONFIG_PAX_SEGMEXEC
74492+ if (pax_find_mirror_vma(vma))
74493+ BUG_ON(!trylock_page(new_page));
74494+#endif
74495+
74496 if (old_page) {
74497 if (!PageAnon(old_page)) {
74498 dec_mm_counter_fast(mm, MM_FILEPAGES);
74499@@ -2771,6 +2973,10 @@ gotten:
74500 page_remove_rmap(old_page);
74501 }
74502
74503+#ifdef CONFIG_PAX_SEGMEXEC
74504+ pax_mirror_anon_pte(vma, address, new_page, ptl);
74505+#endif
74506+
74507 /* Free the old page.. */
74508 new_page = old_page;
74509 ret |= VM_FAULT_WRITE;
74510@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74511 swap_free(entry);
74512 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74513 try_to_free_swap(page);
74514+
74515+#ifdef CONFIG_PAX_SEGMEXEC
74516+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74517+#endif
74518+
74519 unlock_page(page);
74520 if (swapcache) {
74521 /*
74522@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74523
74524 /* No need to invalidate - it was non-present before */
74525 update_mmu_cache(vma, address, page_table);
74526+
74527+#ifdef CONFIG_PAX_SEGMEXEC
74528+ pax_mirror_anon_pte(vma, address, page, ptl);
74529+#endif
74530+
74531 unlock:
74532 pte_unmap_unlock(page_table, ptl);
74533 out:
74534@@ -3093,40 +3309,6 @@ out_release:
74535 }
74536
74537 /*
74538- * This is like a special single-page "expand_{down|up}wards()",
74539- * except we must first make sure that 'address{-|+}PAGE_SIZE'
74540- * doesn't hit another vma.
74541- */
74542-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74543-{
74544- address &= PAGE_MASK;
74545- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74546- struct vm_area_struct *prev = vma->vm_prev;
74547-
74548- /*
74549- * Is there a mapping abutting this one below?
74550- *
74551- * That's only ok if it's the same stack mapping
74552- * that has gotten split..
74553- */
74554- if (prev && prev->vm_end == address)
74555- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74556-
74557- expand_downwards(vma, address - PAGE_SIZE);
74558- }
74559- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74560- struct vm_area_struct *next = vma->vm_next;
74561-
74562- /* As VM_GROWSDOWN but s/below/above/ */
74563- if (next && next->vm_start == address + PAGE_SIZE)
74564- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74565-
74566- expand_upwards(vma, address + PAGE_SIZE);
74567- }
74568- return 0;
74569-}
74570-
74571-/*
74572 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74573 * but allow concurrent faults), and pte mapped but not yet locked.
74574 * We return with mmap_sem still held, but pte unmapped and unlocked.
74575@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74576 unsigned long address, pte_t *page_table, pmd_t *pmd,
74577 unsigned int flags)
74578 {
74579- struct page *page;
74580+ struct page *page = NULL;
74581 spinlock_t *ptl;
74582 pte_t entry;
74583
74584- pte_unmap(page_table);
74585-
74586- /* Check if we need to add a guard page to the stack */
74587- if (check_stack_guard_page(vma, address) < 0)
74588- return VM_FAULT_SIGBUS;
74589-
74590- /* Use the zero-page for reads */
74591 if (!(flags & FAULT_FLAG_WRITE)) {
74592 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74593 vma->vm_page_prot));
74594- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74595+ ptl = pte_lockptr(mm, pmd);
74596+ spin_lock(ptl);
74597 if (!pte_none(*page_table))
74598 goto unlock;
74599 goto setpte;
74600 }
74601
74602 /* Allocate our own private page. */
74603+ pte_unmap(page_table);
74604+
74605 if (unlikely(anon_vma_prepare(vma)))
74606 goto oom;
74607 page = alloc_zeroed_user_highpage_movable(vma, address);
74608@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74609 if (!pte_none(*page_table))
74610 goto release;
74611
74612+#ifdef CONFIG_PAX_SEGMEXEC
74613+ if (pax_find_mirror_vma(vma))
74614+ BUG_ON(!trylock_page(page));
74615+#endif
74616+
74617 inc_mm_counter_fast(mm, MM_ANONPAGES);
74618 page_add_new_anon_rmap(page, vma, address);
74619 setpte:
74620@@ -3181,6 +3364,12 @@ setpte:
74621
74622 /* No need to invalidate - it was non-present before */
74623 update_mmu_cache(vma, address, page_table);
74624+
74625+#ifdef CONFIG_PAX_SEGMEXEC
74626+ if (page)
74627+ pax_mirror_anon_pte(vma, address, page, ptl);
74628+#endif
74629+
74630 unlock:
74631 pte_unmap_unlock(page_table, ptl);
74632 return 0;
74633@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74634 */
74635 /* Only go through if we didn't race with anybody else... */
74636 if (likely(pte_same(*page_table, orig_pte))) {
74637+
74638+#ifdef CONFIG_PAX_SEGMEXEC
74639+ if (anon && pax_find_mirror_vma(vma))
74640+ BUG_ON(!trylock_page(page));
74641+#endif
74642+
74643 flush_icache_page(vma, page);
74644 entry = mk_pte(page, vma->vm_page_prot);
74645 if (flags & FAULT_FLAG_WRITE)
74646@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74647
74648 /* no need to invalidate: a not-present page won't be cached */
74649 update_mmu_cache(vma, address, page_table);
74650+
74651+#ifdef CONFIG_PAX_SEGMEXEC
74652+ if (anon)
74653+ pax_mirror_anon_pte(vma, address, page, ptl);
74654+ else
74655+ pax_mirror_file_pte(vma, address, page, ptl);
74656+#endif
74657+
74658 } else {
74659 if (cow_page)
74660 mem_cgroup_uncharge_page(cow_page);
74661@@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74662 if (flags & FAULT_FLAG_WRITE)
74663 flush_tlb_fix_spurious_fault(vma, address);
74664 }
74665+
74666+#ifdef CONFIG_PAX_SEGMEXEC
74667+ pax_mirror_pte(vma, address, pte, pmd, ptl);
74668+ return 0;
74669+#endif
74670+
74671 unlock:
74672 pte_unmap_unlock(pte, ptl);
74673 return 0;
74674@@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74675 pmd_t *pmd;
74676 pte_t *pte;
74677
74678+#ifdef CONFIG_PAX_SEGMEXEC
74679+ struct vm_area_struct *vma_m;
74680+#endif
74681+
74682 __set_current_state(TASK_RUNNING);
74683
74684 count_vm_event(PGFAULT);
74685@@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74686 if (unlikely(is_vm_hugetlb_page(vma)))
74687 return hugetlb_fault(mm, vma, address, flags);
74688
74689+#ifdef CONFIG_PAX_SEGMEXEC
74690+ vma_m = pax_find_mirror_vma(vma);
74691+ if (vma_m) {
74692+ unsigned long address_m;
74693+ pgd_t *pgd_m;
74694+ pud_t *pud_m;
74695+ pmd_t *pmd_m;
74696+
74697+ if (vma->vm_start > vma_m->vm_start) {
74698+ address_m = address;
74699+ address -= SEGMEXEC_TASK_SIZE;
74700+ vma = vma_m;
74701+ } else
74702+ address_m = address + SEGMEXEC_TASK_SIZE;
74703+
74704+ pgd_m = pgd_offset(mm, address_m);
74705+ pud_m = pud_alloc(mm, pgd_m, address_m);
74706+ if (!pud_m)
74707+ return VM_FAULT_OOM;
74708+ pmd_m = pmd_alloc(mm, pud_m, address_m);
74709+ if (!pmd_m)
74710+ return VM_FAULT_OOM;
74711+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74712+ return VM_FAULT_OOM;
74713+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74714+ }
74715+#endif
74716+
74717 retry:
74718 pgd = pgd_offset(mm, address);
74719 pud = pud_alloc(mm, pgd, address);
74720@@ -3565,7 +3806,7 @@ retry:
74721 * run pte_offset_map on the pmd, if an huge pmd could
74722 * materialize from under us from a different thread.
74723 */
74724- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
74725+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74726 return VM_FAULT_OOM;
74727 /* if an huge pmd materialized from under us just retry later */
74728 if (unlikely(pmd_trans_huge(*pmd)))
74729@@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74730 spin_unlock(&mm->page_table_lock);
74731 return 0;
74732 }
74733+
74734+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74735+{
74736+ pud_t *new = pud_alloc_one(mm, address);
74737+ if (!new)
74738+ return -ENOMEM;
74739+
74740+ smp_wmb(); /* See comment in __pte_alloc */
74741+
74742+ spin_lock(&mm->page_table_lock);
74743+ if (pgd_present(*pgd)) /* Another has populated it */
74744+ pud_free(mm, new);
74745+ else
74746+ pgd_populate_kernel(mm, pgd, new);
74747+ spin_unlock(&mm->page_table_lock);
74748+ return 0;
74749+}
74750 #endif /* __PAGETABLE_PUD_FOLDED */
74751
74752 #ifndef __PAGETABLE_PMD_FOLDED
74753@@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74754 spin_unlock(&mm->page_table_lock);
74755 return 0;
74756 }
74757+
74758+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74759+{
74760+ pmd_t *new = pmd_alloc_one(mm, address);
74761+ if (!new)
74762+ return -ENOMEM;
74763+
74764+ smp_wmb(); /* See comment in __pte_alloc */
74765+
74766+ spin_lock(&mm->page_table_lock);
74767+#ifndef __ARCH_HAS_4LEVEL_HACK
74768+ if (pud_present(*pud)) /* Another has populated it */
74769+ pmd_free(mm, new);
74770+ else
74771+ pud_populate_kernel(mm, pud, new);
74772+#else
74773+ if (pgd_present(*pud)) /* Another has populated it */
74774+ pmd_free(mm, new);
74775+ else
74776+ pgd_populate_kernel(mm, pud, new);
74777+#endif /* __ARCH_HAS_4LEVEL_HACK */
74778+ spin_unlock(&mm->page_table_lock);
74779+ return 0;
74780+}
74781 #endif /* __PAGETABLE_PMD_FOLDED */
74782
74783 int make_pages_present(unsigned long addr, unsigned long end)
74784@@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
74785 gate_vma.vm_start = FIXADDR_USER_START;
74786 gate_vma.vm_end = FIXADDR_USER_END;
74787 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
74788- gate_vma.vm_page_prot = __P101;
74789+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
74790
74791 return 0;
74792 }
74793diff --git a/mm/mempolicy.c b/mm/mempolicy.c
74794index 002c281..9429765 100644
74795--- a/mm/mempolicy.c
74796+++ b/mm/mempolicy.c
74797@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74798 unsigned long vmstart;
74799 unsigned long vmend;
74800
74801+#ifdef CONFIG_PAX_SEGMEXEC
74802+ struct vm_area_struct *vma_m;
74803+#endif
74804+
74805 vma = find_vma(mm, start);
74806 if (!vma || vma->vm_start > start)
74807 return -EFAULT;
74808@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74809 if (err)
74810 goto out;
74811 }
74812+
74813 err = vma_replace_policy(vma, new_pol);
74814 if (err)
74815 goto out;
74816+
74817+#ifdef CONFIG_PAX_SEGMEXEC
74818+ vma_m = pax_find_mirror_vma(vma);
74819+ if (vma_m) {
74820+ err = vma_replace_policy(vma_m, new_pol);
74821+ if (err)
74822+ goto out;
74823+ }
74824+#endif
74825+
74826 }
74827
74828 out:
74829@@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
74830
74831 if (end < start)
74832 return -EINVAL;
74833+
74834+#ifdef CONFIG_PAX_SEGMEXEC
74835+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74836+ if (end > SEGMEXEC_TASK_SIZE)
74837+ return -EINVAL;
74838+ } else
74839+#endif
74840+
74841+ if (end > TASK_SIZE)
74842+ return -EINVAL;
74843+
74844 if (end == start)
74845 return 0;
74846
74847@@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74848 */
74849 tcred = __task_cred(task);
74850 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74851- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74852- !capable(CAP_SYS_NICE)) {
74853+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74854 rcu_read_unlock();
74855 err = -EPERM;
74856 goto out_put;
74857@@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74858 goto out;
74859 }
74860
74861+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74862+ if (mm != current->mm &&
74863+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
74864+ mmput(mm);
74865+ err = -EPERM;
74866+ goto out;
74867+ }
74868+#endif
74869+
74870 err = do_migrate_pages(mm, old, new,
74871 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
74872
74873diff --git a/mm/migrate.c b/mm/migrate.c
74874index 346d32d..d7adff2 100644
74875--- a/mm/migrate.c
74876+++ b/mm/migrate.c
74877@@ -1352,8 +1352,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
74878 */
74879 tcred = __task_cred(task);
74880 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74881- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74882- !capable(CAP_SYS_NICE)) {
74883+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74884 rcu_read_unlock();
74885 err = -EPERM;
74886 goto out;
74887diff --git a/mm/mlock.c b/mm/mlock.c
74888index f0b9ce5..da8d069 100644
74889--- a/mm/mlock.c
74890+++ b/mm/mlock.c
74891@@ -13,6 +13,7 @@
74892 #include <linux/pagemap.h>
74893 #include <linux/mempolicy.h>
74894 #include <linux/syscalls.h>
74895+#include <linux/security.h>
74896 #include <linux/sched.h>
74897 #include <linux/export.h>
74898 #include <linux/rmap.h>
74899@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
74900 {
74901 unsigned long nstart, end, tmp;
74902 struct vm_area_struct * vma, * prev;
74903- int error;
74904+ int error = 0;
74905
74906 VM_BUG_ON(start & ~PAGE_MASK);
74907 VM_BUG_ON(len != PAGE_ALIGN(len));
74908@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
74909 return -EINVAL;
74910 if (end == start)
74911 return 0;
74912+ if (end > TASK_SIZE)
74913+ return -EINVAL;
74914+
74915 vma = find_vma(current->mm, start);
74916 if (!vma || vma->vm_start > start)
74917 return -ENOMEM;
74918@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
74919 for (nstart = start ; ; ) {
74920 vm_flags_t newflags;
74921
74922+#ifdef CONFIG_PAX_SEGMEXEC
74923+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74924+ break;
74925+#endif
74926+
74927 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
74928
74929 newflags = vma->vm_flags | VM_LOCKED;
74930@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
74931 lock_limit >>= PAGE_SHIFT;
74932
74933 /* check against resource limits */
74934+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
74935 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
74936 error = do_mlock(start, len, 1);
74937 up_write(&current->mm->mmap_sem);
74938@@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
74939 static int do_mlockall(int flags)
74940 {
74941 struct vm_area_struct * vma, * prev = NULL;
74942- unsigned int def_flags = 0;
74943
74944 if (flags & MCL_FUTURE)
74945- def_flags = VM_LOCKED;
74946- current->mm->def_flags = def_flags;
74947+ current->mm->def_flags |= VM_LOCKED;
74948+ else
74949+ current->mm->def_flags &= ~VM_LOCKED;
74950 if (flags == MCL_FUTURE)
74951 goto out;
74952
74953 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
74954 vm_flags_t newflags;
74955
74956+#ifdef CONFIG_PAX_SEGMEXEC
74957+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74958+ break;
74959+#endif
74960+
74961+ BUG_ON(vma->vm_end > TASK_SIZE);
74962 newflags = vma->vm_flags | VM_LOCKED;
74963 if (!(flags & MCL_CURRENT))
74964 newflags &= ~VM_LOCKED;
74965@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
74966 lock_limit >>= PAGE_SHIFT;
74967
74968 ret = -ENOMEM;
74969+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
74970 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
74971 capable(CAP_IPC_LOCK))
74972 ret = do_mlockall(flags);
74973diff --git a/mm/mmap.c b/mm/mmap.c
74974index 9a796c4..e2c9724 100644
74975--- a/mm/mmap.c
74976+++ b/mm/mmap.c
74977@@ -31,6 +31,7 @@
74978 #include <linux/audit.h>
74979 #include <linux/khugepaged.h>
74980 #include <linux/uprobes.h>
74981+#include <linux/random.h>
74982
74983 #include <asm/uaccess.h>
74984 #include <asm/cacheflush.h>
74985@@ -47,6 +48,16 @@
74986 #define arch_rebalance_pgtables(addr, len) (addr)
74987 #endif
74988
74989+static inline void verify_mm_writelocked(struct mm_struct *mm)
74990+{
74991+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
74992+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
74993+ up_read(&mm->mmap_sem);
74994+ BUG();
74995+ }
74996+#endif
74997+}
74998+
74999 static void unmap_region(struct mm_struct *mm,
75000 struct vm_area_struct *vma, struct vm_area_struct *prev,
75001 unsigned long start, unsigned long end);
75002@@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75003 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75004 *
75005 */
75006-pgprot_t protection_map[16] = {
75007+pgprot_t protection_map[16] __read_only = {
75008 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75009 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75010 };
75011
75012-pgprot_t vm_get_page_prot(unsigned long vm_flags)
75013+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75014 {
75015- return __pgprot(pgprot_val(protection_map[vm_flags &
75016+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75017 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75018 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75019+
75020+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75021+ if (!(__supported_pte_mask & _PAGE_NX) &&
75022+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75023+ (vm_flags & (VM_READ | VM_WRITE)))
75024+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75025+#endif
75026+
75027+ return prot;
75028 }
75029 EXPORT_SYMBOL(vm_get_page_prot);
75030
75031 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75032 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75033 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75034+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75035 /*
75036 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75037 * other variables. It can be updated by several CPUs frequently.
75038@@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75039 struct vm_area_struct *next = vma->vm_next;
75040
75041 might_sleep();
75042+ BUG_ON(vma->vm_mirror);
75043 if (vma->vm_ops && vma->vm_ops->close)
75044 vma->vm_ops->close(vma);
75045 if (vma->vm_file)
75046@@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75047 * not page aligned -Ram Gupta
75048 */
75049 rlim = rlimit(RLIMIT_DATA);
75050+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75051 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75052 (mm->end_data - mm->start_data) > rlim)
75053 goto out;
75054@@ -736,6 +759,12 @@ static int
75055 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75056 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75057 {
75058+
75059+#ifdef CONFIG_PAX_SEGMEXEC
75060+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75061+ return 0;
75062+#endif
75063+
75064 if (is_mergeable_vma(vma, file, vm_flags) &&
75065 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75066 if (vma->vm_pgoff == vm_pgoff)
75067@@ -755,6 +784,12 @@ static int
75068 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75069 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75070 {
75071+
75072+#ifdef CONFIG_PAX_SEGMEXEC
75073+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75074+ return 0;
75075+#endif
75076+
75077 if (is_mergeable_vma(vma, file, vm_flags) &&
75078 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75079 pgoff_t vm_pglen;
75080@@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75081 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75082 struct vm_area_struct *prev, unsigned long addr,
75083 unsigned long end, unsigned long vm_flags,
75084- struct anon_vma *anon_vma, struct file *file,
75085+ struct anon_vma *anon_vma, struct file *file,
75086 pgoff_t pgoff, struct mempolicy *policy)
75087 {
75088 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75089 struct vm_area_struct *area, *next;
75090 int err;
75091
75092+#ifdef CONFIG_PAX_SEGMEXEC
75093+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75094+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75095+
75096+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75097+#endif
75098+
75099 /*
75100 * We later require that vma->vm_flags == vm_flags,
75101 * so this tests vma->vm_flags & VM_SPECIAL, too.
75102@@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75103 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75104 next = next->vm_next;
75105
75106+#ifdef CONFIG_PAX_SEGMEXEC
75107+ if (prev)
75108+ prev_m = pax_find_mirror_vma(prev);
75109+ if (area)
75110+ area_m = pax_find_mirror_vma(area);
75111+ if (next)
75112+ next_m = pax_find_mirror_vma(next);
75113+#endif
75114+
75115 /*
75116 * Can it merge with the predecessor?
75117 */
75118@@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75119 /* cases 1, 6 */
75120 err = vma_adjust(prev, prev->vm_start,
75121 next->vm_end, prev->vm_pgoff, NULL);
75122- } else /* cases 2, 5, 7 */
75123+
75124+#ifdef CONFIG_PAX_SEGMEXEC
75125+ if (!err && prev_m)
75126+ err = vma_adjust(prev_m, prev_m->vm_start,
75127+ next_m->vm_end, prev_m->vm_pgoff, NULL);
75128+#endif
75129+
75130+ } else { /* cases 2, 5, 7 */
75131 err = vma_adjust(prev, prev->vm_start,
75132 end, prev->vm_pgoff, NULL);
75133+
75134+#ifdef CONFIG_PAX_SEGMEXEC
75135+ if (!err && prev_m)
75136+ err = vma_adjust(prev_m, prev_m->vm_start,
75137+ end_m, prev_m->vm_pgoff, NULL);
75138+#endif
75139+
75140+ }
75141 if (err)
75142 return NULL;
75143 khugepaged_enter_vma_merge(prev);
75144@@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75145 mpol_equal(policy, vma_policy(next)) &&
75146 can_vma_merge_before(next, vm_flags,
75147 anon_vma, file, pgoff+pglen)) {
75148- if (prev && addr < prev->vm_end) /* case 4 */
75149+ if (prev && addr < prev->vm_end) { /* case 4 */
75150 err = vma_adjust(prev, prev->vm_start,
75151 addr, prev->vm_pgoff, NULL);
75152- else /* cases 3, 8 */
75153+
75154+#ifdef CONFIG_PAX_SEGMEXEC
75155+ if (!err && prev_m)
75156+ err = vma_adjust(prev_m, prev_m->vm_start,
75157+ addr_m, prev_m->vm_pgoff, NULL);
75158+#endif
75159+
75160+ } else { /* cases 3, 8 */
75161 err = vma_adjust(area, addr, next->vm_end,
75162 next->vm_pgoff - pglen, NULL);
75163+
75164+#ifdef CONFIG_PAX_SEGMEXEC
75165+ if (!err && area_m)
75166+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
75167+ next_m->vm_pgoff - pglen, NULL);
75168+#endif
75169+
75170+ }
75171 if (err)
75172 return NULL;
75173 khugepaged_enter_vma_merge(area);
75174@@ -968,16 +1049,13 @@ none:
75175 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75176 struct file *file, long pages)
75177 {
75178- const unsigned long stack_flags
75179- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75180-
75181 mm->total_vm += pages;
75182
75183 if (file) {
75184 mm->shared_vm += pages;
75185 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75186 mm->exec_vm += pages;
75187- } else if (flags & stack_flags)
75188+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75189 mm->stack_vm += pages;
75190 }
75191 #endif /* CONFIG_PROC_FS */
75192@@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75193 * (the exception is when the underlying filesystem is noexec
75194 * mounted, in which case we dont add PROT_EXEC.)
75195 */
75196- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75197+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75198 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75199 prot |= PROT_EXEC;
75200
75201@@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75202 /* Obtain the address to map to. we verify (or select) it and ensure
75203 * that it represents a valid section of the address space.
75204 */
75205- addr = get_unmapped_area(file, addr, len, pgoff, flags);
75206+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75207 if (addr & ~PAGE_MASK)
75208 return addr;
75209
75210@@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75211 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75212 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75213
75214+#ifdef CONFIG_PAX_MPROTECT
75215+ if (mm->pax_flags & MF_PAX_MPROTECT) {
75216+#ifndef CONFIG_PAX_MPROTECT_COMPAT
75217+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75218+ gr_log_rwxmmap(file);
75219+
75220+#ifdef CONFIG_PAX_EMUPLT
75221+ vm_flags &= ~VM_EXEC;
75222+#else
75223+ return -EPERM;
75224+#endif
75225+
75226+ }
75227+
75228+ if (!(vm_flags & VM_EXEC))
75229+ vm_flags &= ~VM_MAYEXEC;
75230+#else
75231+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75232+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75233+#endif
75234+ else
75235+ vm_flags &= ~VM_MAYWRITE;
75236+ }
75237+#endif
75238+
75239+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75240+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75241+ vm_flags &= ~VM_PAGEEXEC;
75242+#endif
75243+
75244 if (flags & MAP_LOCKED)
75245 if (!can_do_mlock())
75246 return -EPERM;
75247@@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75248 locked += mm->locked_vm;
75249 lock_limit = rlimit(RLIMIT_MEMLOCK);
75250 lock_limit >>= PAGE_SHIFT;
75251+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75252 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75253 return -EAGAIN;
75254 }
75255@@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75256 }
75257 }
75258
75259+ if (!gr_acl_handle_mmap(file, prot))
75260+ return -EACCES;
75261+
75262 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75263 }
75264
75265@@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75266 vm_flags_t vm_flags = vma->vm_flags;
75267
75268 /* If it was private or non-writable, the write bit is already clear */
75269- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75270+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75271 return 0;
75272
75273 /* The backer wishes to know when pages are first written to? */
75274@@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75275 unsigned long charged = 0;
75276 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75277
75278+#ifdef CONFIG_PAX_SEGMEXEC
75279+ struct vm_area_struct *vma_m = NULL;
75280+#endif
75281+
75282+ /*
75283+ * mm->mmap_sem is required to protect against another thread
75284+ * changing the mappings in case we sleep.
75285+ */
75286+ verify_mm_writelocked(mm);
75287+
75288 /* Clear old maps */
75289 error = -ENOMEM;
75290-munmap_back:
75291 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75292 if (do_munmap(mm, addr, len))
75293 return -ENOMEM;
75294- goto munmap_back;
75295+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75296 }
75297
75298 /* Check against address space limit. */
75299@@ -1307,6 +1428,16 @@ munmap_back:
75300 goto unacct_error;
75301 }
75302
75303+#ifdef CONFIG_PAX_SEGMEXEC
75304+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75305+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75306+ if (!vma_m) {
75307+ error = -ENOMEM;
75308+ goto free_vma;
75309+ }
75310+ }
75311+#endif
75312+
75313 vma->vm_mm = mm;
75314 vma->vm_start = addr;
75315 vma->vm_end = addr + len;
75316@@ -1331,6 +1462,13 @@ munmap_back:
75317 if (error)
75318 goto unmap_and_free_vma;
75319
75320+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75321+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75322+ vma->vm_flags |= VM_PAGEEXEC;
75323+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75324+ }
75325+#endif
75326+
75327 /* Can addr have changed??
75328 *
75329 * Answer: Yes, several device drivers can do it in their
75330@@ -1365,6 +1503,11 @@ munmap_back:
75331 vma_link(mm, vma, prev, rb_link, rb_parent);
75332 file = vma->vm_file;
75333
75334+#ifdef CONFIG_PAX_SEGMEXEC
75335+ if (vma_m)
75336+ BUG_ON(pax_mirror_vma(vma_m, vma));
75337+#endif
75338+
75339 /* Once vma denies write, undo our temporary denial count */
75340 if (correct_wcount)
75341 atomic_inc(&inode->i_writecount);
75342@@ -1372,6 +1515,7 @@ out:
75343 perf_event_mmap(vma);
75344
75345 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75346+ track_exec_limit(mm, addr, addr + len, vm_flags);
75347 if (vm_flags & VM_LOCKED) {
75348 if (!mlock_vma_pages_range(vma, addr, addr + len))
75349 mm->locked_vm += (len >> PAGE_SHIFT);
75350@@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75351 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75352 charged = 0;
75353 free_vma:
75354+
75355+#ifdef CONFIG_PAX_SEGMEXEC
75356+ if (vma_m)
75357+ kmem_cache_free(vm_area_cachep, vma_m);
75358+#endif
75359+
75360 kmem_cache_free(vm_area_cachep, vma);
75361 unacct_error:
75362 if (charged)
75363@@ -1400,6 +1550,62 @@ unacct_error:
75364 return error;
75365 }
75366
75367+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75368+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75369+{
75370+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75371+ return (random32() & 0xFF) << PAGE_SHIFT;
75372+
75373+ return 0;
75374+}
75375+#endif
75376+
75377+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75378+{
75379+ if (!vma) {
75380+#ifdef CONFIG_STACK_GROWSUP
75381+ if (addr > sysctl_heap_stack_gap)
75382+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75383+ else
75384+ vma = find_vma(current->mm, 0);
75385+ if (vma && (vma->vm_flags & VM_GROWSUP))
75386+ return false;
75387+#endif
75388+ return true;
75389+ }
75390+
75391+ if (addr + len > vma->vm_start)
75392+ return false;
75393+
75394+ if (vma->vm_flags & VM_GROWSDOWN)
75395+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75396+#ifdef CONFIG_STACK_GROWSUP
75397+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75398+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75399+#endif
75400+ else if (offset)
75401+ return offset <= vma->vm_start - addr - len;
75402+
75403+ return true;
75404+}
75405+
75406+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75407+{
75408+ if (vma->vm_start < len)
75409+ return -ENOMEM;
75410+
75411+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
75412+ if (offset <= vma->vm_start - len)
75413+ return vma->vm_start - len - offset;
75414+ else
75415+ return -ENOMEM;
75416+ }
75417+
75418+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
75419+ return vma->vm_start - len - sysctl_heap_stack_gap;
75420+ return -ENOMEM;
75421+}
75422+
75423 /* Get an address range which is currently unmapped.
75424 * For shmat() with addr=0.
75425 *
75426@@ -1419,6 +1625,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75427 struct mm_struct *mm = current->mm;
75428 struct vm_area_struct *vma;
75429 unsigned long start_addr;
75430+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75431
75432 if (len > TASK_SIZE)
75433 return -ENOMEM;
75434@@ -1426,18 +1633,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75435 if (flags & MAP_FIXED)
75436 return addr;
75437
75438+#ifdef CONFIG_PAX_RANDMMAP
75439+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75440+#endif
75441+
75442 if (addr) {
75443 addr = PAGE_ALIGN(addr);
75444- vma = find_vma(mm, addr);
75445- if (TASK_SIZE - len >= addr &&
75446- (!vma || addr + len <= vma->vm_start))
75447- return addr;
75448+ if (TASK_SIZE - len >= addr) {
75449+ vma = find_vma(mm, addr);
75450+ if (check_heap_stack_gap(vma, addr, len, offset))
75451+ return addr;
75452+ }
75453 }
75454 if (len > mm->cached_hole_size) {
75455- start_addr = addr = mm->free_area_cache;
75456+ start_addr = addr = mm->free_area_cache;
75457 } else {
75458- start_addr = addr = TASK_UNMAPPED_BASE;
75459- mm->cached_hole_size = 0;
75460+ start_addr = addr = mm->mmap_base;
75461+ mm->cached_hole_size = 0;
75462 }
75463
75464 full_search:
75465@@ -1448,34 +1660,40 @@ full_search:
75466 * Start a new search - just in case we missed
75467 * some holes.
75468 */
75469- if (start_addr != TASK_UNMAPPED_BASE) {
75470- addr = TASK_UNMAPPED_BASE;
75471- start_addr = addr;
75472+ if (start_addr != mm->mmap_base) {
75473+ start_addr = addr = mm->mmap_base;
75474 mm->cached_hole_size = 0;
75475 goto full_search;
75476 }
75477 return -ENOMEM;
75478 }
75479- if (!vma || addr + len <= vma->vm_start) {
75480- /*
75481- * Remember the place where we stopped the search:
75482- */
75483- mm->free_area_cache = addr + len;
75484- return addr;
75485- }
75486+ if (check_heap_stack_gap(vma, addr, len, offset))
75487+ break;
75488 if (addr + mm->cached_hole_size < vma->vm_start)
75489 mm->cached_hole_size = vma->vm_start - addr;
75490 addr = vma->vm_end;
75491 }
75492+
75493+ /*
75494+ * Remember the place where we stopped the search:
75495+ */
75496+ mm->free_area_cache = addr + len;
75497+ return addr;
75498 }
75499 #endif
75500
75501 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75502 {
75503+
75504+#ifdef CONFIG_PAX_SEGMEXEC
75505+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75506+ return;
75507+#endif
75508+
75509 /*
75510 * Is this a new hole at the lowest possible address?
75511 */
75512- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75513+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75514 mm->free_area_cache = addr;
75515 }
75516
75517@@ -1491,7 +1709,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75518 {
75519 struct vm_area_struct *vma;
75520 struct mm_struct *mm = current->mm;
75521- unsigned long addr = addr0, start_addr;
75522+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75523+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
75524
75525 /* requested length too big for entire address space */
75526 if (len > TASK_SIZE)
75527@@ -1500,13 +1719,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75528 if (flags & MAP_FIXED)
75529 return addr;
75530
75531+#ifdef CONFIG_PAX_RANDMMAP
75532+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75533+#endif
75534+
75535 /* requesting a specific address */
75536 if (addr) {
75537 addr = PAGE_ALIGN(addr);
75538- vma = find_vma(mm, addr);
75539- if (TASK_SIZE - len >= addr &&
75540- (!vma || addr + len <= vma->vm_start))
75541- return addr;
75542+ if (TASK_SIZE - len >= addr) {
75543+ vma = find_vma(mm, addr);
75544+ if (check_heap_stack_gap(vma, addr, len, offset))
75545+ return addr;
75546+ }
75547 }
75548
75549 /* check if free_area_cache is useful for us */
75550@@ -1530,7 +1754,7 @@ try_again:
75551 * return with success:
75552 */
75553 vma = find_vma(mm, addr);
75554- if (!vma || addr+len <= vma->vm_start)
75555+ if (check_heap_stack_gap(vma, addr, len, offset))
75556 /* remember the address as a hint for next time */
75557 return (mm->free_area_cache = addr);
75558
75559@@ -1539,8 +1763,8 @@ try_again:
75560 mm->cached_hole_size = vma->vm_start - addr;
75561
75562 /* try just below the current vma->vm_start */
75563- addr = vma->vm_start-len;
75564- } while (len < vma->vm_start);
75565+ addr = skip_heap_stack_gap(vma, len, offset);
75566+ } while (!IS_ERR_VALUE(addr));
75567
75568 fail:
75569 /*
75570@@ -1563,13 +1787,21 @@ fail:
75571 * can happen with large stack limits and large mmap()
75572 * allocations.
75573 */
75574+ mm->mmap_base = TASK_UNMAPPED_BASE;
75575+
75576+#ifdef CONFIG_PAX_RANDMMAP
75577+ if (mm->pax_flags & MF_PAX_RANDMMAP)
75578+ mm->mmap_base += mm->delta_mmap;
75579+#endif
75580+
75581+ mm->free_area_cache = mm->mmap_base;
75582 mm->cached_hole_size = ~0UL;
75583- mm->free_area_cache = TASK_UNMAPPED_BASE;
75584 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
75585 /*
75586 * Restore the topdown base:
75587 */
75588- mm->free_area_cache = mm->mmap_base;
75589+ mm->mmap_base = base;
75590+ mm->free_area_cache = base;
75591 mm->cached_hole_size = ~0UL;
75592
75593 return addr;
75594@@ -1578,6 +1810,12 @@ fail:
75595
75596 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75597 {
75598+
75599+#ifdef CONFIG_PAX_SEGMEXEC
75600+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75601+ return;
75602+#endif
75603+
75604 /*
75605 * Is this a new hole at the highest possible address?
75606 */
75607@@ -1585,8 +1823,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
75608 mm->free_area_cache = addr;
75609
75610 /* dont allow allocations above current base */
75611- if (mm->free_area_cache > mm->mmap_base)
75612+ if (mm->free_area_cache > mm->mmap_base) {
75613 mm->free_area_cache = mm->mmap_base;
75614+ mm->cached_hole_size = ~0UL;
75615+ }
75616 }
75617
75618 unsigned long
75619@@ -1685,6 +1925,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
75620 return vma;
75621 }
75622
75623+#ifdef CONFIG_PAX_SEGMEXEC
75624+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
75625+{
75626+ struct vm_area_struct *vma_m;
75627+
75628+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
75629+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
75630+ BUG_ON(vma->vm_mirror);
75631+ return NULL;
75632+ }
75633+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
75634+ vma_m = vma->vm_mirror;
75635+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
75636+ BUG_ON(vma->vm_file != vma_m->vm_file);
75637+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
75638+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
75639+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
75640+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
75641+ return vma_m;
75642+}
75643+#endif
75644+
75645 /*
75646 * Verify that the stack growth is acceptable and
75647 * update accounting. This is shared with both the
75648@@ -1701,6 +1963,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75649 return -ENOMEM;
75650
75651 /* Stack limit test */
75652+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
75653 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
75654 return -ENOMEM;
75655
75656@@ -1711,6 +1974,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75657 locked = mm->locked_vm + grow;
75658 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
75659 limit >>= PAGE_SHIFT;
75660+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75661 if (locked > limit && !capable(CAP_IPC_LOCK))
75662 return -ENOMEM;
75663 }
75664@@ -1740,37 +2004,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
75665 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
75666 * vma is the last one with address > vma->vm_end. Have to extend vma.
75667 */
75668+#ifndef CONFIG_IA64
75669+static
75670+#endif
75671 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75672 {
75673 int error;
75674+ bool locknext;
75675
75676 if (!(vma->vm_flags & VM_GROWSUP))
75677 return -EFAULT;
75678
75679+ /* Also guard against wrapping around to address 0. */
75680+ if (address < PAGE_ALIGN(address+1))
75681+ address = PAGE_ALIGN(address+1);
75682+ else
75683+ return -ENOMEM;
75684+
75685 /*
75686 * We must make sure the anon_vma is allocated
75687 * so that the anon_vma locking is not a noop.
75688 */
75689 if (unlikely(anon_vma_prepare(vma)))
75690 return -ENOMEM;
75691+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
75692+ if (locknext && anon_vma_prepare(vma->vm_next))
75693+ return -ENOMEM;
75694 vma_lock_anon_vma(vma);
75695+ if (locknext)
75696+ vma_lock_anon_vma(vma->vm_next);
75697
75698 /*
75699 * vma->vm_start/vm_end cannot change under us because the caller
75700 * is required to hold the mmap_sem in read mode. We need the
75701- * anon_vma lock to serialize against concurrent expand_stacks.
75702- * Also guard against wrapping around to address 0.
75703+ * anon_vma locks to serialize against concurrent expand_stacks
75704+ * and expand_upwards.
75705 */
75706- if (address < PAGE_ALIGN(address+4))
75707- address = PAGE_ALIGN(address+4);
75708- else {
75709- vma_unlock_anon_vma(vma);
75710- return -ENOMEM;
75711- }
75712 error = 0;
75713
75714 /* Somebody else might have raced and expanded it already */
75715- if (address > vma->vm_end) {
75716+ 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)
75717+ error = -ENOMEM;
75718+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
75719 unsigned long size, grow;
75720
75721 size = address - vma->vm_start;
75722@@ -1787,6 +2062,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
75723 }
75724 }
75725 }
75726+ if (locknext)
75727+ vma_unlock_anon_vma(vma->vm_next);
75728 vma_unlock_anon_vma(vma);
75729 khugepaged_enter_vma_merge(vma);
75730 validate_mm(vma->vm_mm);
75731@@ -1801,6 +2078,8 @@ int expand_downwards(struct vm_area_struct *vma,
75732 unsigned long address)
75733 {
75734 int error;
75735+ bool lockprev = false;
75736+ struct vm_area_struct *prev;
75737
75738 /*
75739 * We must make sure the anon_vma is allocated
75740@@ -1814,6 +2093,15 @@ int expand_downwards(struct vm_area_struct *vma,
75741 if (error)
75742 return error;
75743
75744+ prev = vma->vm_prev;
75745+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
75746+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
75747+#endif
75748+ if (lockprev && anon_vma_prepare(prev))
75749+ return -ENOMEM;
75750+ if (lockprev)
75751+ vma_lock_anon_vma(prev);
75752+
75753 vma_lock_anon_vma(vma);
75754
75755 /*
75756@@ -1823,9 +2111,17 @@ int expand_downwards(struct vm_area_struct *vma,
75757 */
75758
75759 /* Somebody else might have raced and expanded it already */
75760- if (address < vma->vm_start) {
75761+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
75762+ error = -ENOMEM;
75763+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
75764 unsigned long size, grow;
75765
75766+#ifdef CONFIG_PAX_SEGMEXEC
75767+ struct vm_area_struct *vma_m;
75768+
75769+ vma_m = pax_find_mirror_vma(vma);
75770+#endif
75771+
75772 size = vma->vm_end - address;
75773 grow = (vma->vm_start - address) >> PAGE_SHIFT;
75774
75775@@ -1837,6 +2133,17 @@ int expand_downwards(struct vm_area_struct *vma,
75776 vma->vm_start = address;
75777 vma->vm_pgoff -= grow;
75778 anon_vma_interval_tree_post_update_vma(vma);
75779+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
75780+
75781+#ifdef CONFIG_PAX_SEGMEXEC
75782+ if (vma_m) {
75783+ anon_vma_interval_tree_pre_update_vma(vma_m);
75784+ vma_m->vm_start -= grow << PAGE_SHIFT;
75785+ vma_m->vm_pgoff -= grow;
75786+ anon_vma_interval_tree_post_update_vma(vma_m);
75787+ }
75788+#endif
75789+
75790 perf_event_mmap(vma);
75791 }
75792 }
75793@@ -1914,6 +2221,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
75794 do {
75795 long nrpages = vma_pages(vma);
75796
75797+#ifdef CONFIG_PAX_SEGMEXEC
75798+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
75799+ vma = remove_vma(vma);
75800+ continue;
75801+ }
75802+#endif
75803+
75804 if (vma->vm_flags & VM_ACCOUNT)
75805 nr_accounted += nrpages;
75806 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
75807@@ -1959,6 +2273,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
75808 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
75809 vma->vm_prev = NULL;
75810 do {
75811+
75812+#ifdef CONFIG_PAX_SEGMEXEC
75813+ if (vma->vm_mirror) {
75814+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
75815+ vma->vm_mirror->vm_mirror = NULL;
75816+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
75817+ vma->vm_mirror = NULL;
75818+ }
75819+#endif
75820+
75821 rb_erase(&vma->vm_rb, &mm->mm_rb);
75822 mm->map_count--;
75823 tail_vma = vma;
75824@@ -1987,14 +2311,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75825 struct vm_area_struct *new;
75826 int err = -ENOMEM;
75827
75828+#ifdef CONFIG_PAX_SEGMEXEC
75829+ struct vm_area_struct *vma_m, *new_m = NULL;
75830+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
75831+#endif
75832+
75833 if (is_vm_hugetlb_page(vma) && (addr &
75834 ~(huge_page_mask(hstate_vma(vma)))))
75835 return -EINVAL;
75836
75837+#ifdef CONFIG_PAX_SEGMEXEC
75838+ vma_m = pax_find_mirror_vma(vma);
75839+#endif
75840+
75841 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75842 if (!new)
75843 goto out_err;
75844
75845+#ifdef CONFIG_PAX_SEGMEXEC
75846+ if (vma_m) {
75847+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75848+ if (!new_m) {
75849+ kmem_cache_free(vm_area_cachep, new);
75850+ goto out_err;
75851+ }
75852+ }
75853+#endif
75854+
75855 /* most fields are the same, copy all, and then fixup */
75856 *new = *vma;
75857
75858@@ -2007,6 +2350,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75859 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
75860 }
75861
75862+#ifdef CONFIG_PAX_SEGMEXEC
75863+ if (vma_m) {
75864+ *new_m = *vma_m;
75865+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
75866+ new_m->vm_mirror = new;
75867+ new->vm_mirror = new_m;
75868+
75869+ if (new_below)
75870+ new_m->vm_end = addr_m;
75871+ else {
75872+ new_m->vm_start = addr_m;
75873+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
75874+ }
75875+ }
75876+#endif
75877+
75878 pol = mpol_dup(vma_policy(vma));
75879 if (IS_ERR(pol)) {
75880 err = PTR_ERR(pol);
75881@@ -2029,6 +2388,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75882 else
75883 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
75884
75885+#ifdef CONFIG_PAX_SEGMEXEC
75886+ if (!err && vma_m) {
75887+ if (anon_vma_clone(new_m, vma_m))
75888+ goto out_free_mpol;
75889+
75890+ mpol_get(pol);
75891+ vma_set_policy(new_m, pol);
75892+
75893+ if (new_m->vm_file)
75894+ get_file(new_m->vm_file);
75895+
75896+ if (new_m->vm_ops && new_m->vm_ops->open)
75897+ new_m->vm_ops->open(new_m);
75898+
75899+ if (new_below)
75900+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
75901+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
75902+ else
75903+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
75904+
75905+ if (err) {
75906+ if (new_m->vm_ops && new_m->vm_ops->close)
75907+ new_m->vm_ops->close(new_m);
75908+ if (new_m->vm_file)
75909+ fput(new_m->vm_file);
75910+ mpol_put(pol);
75911+ }
75912+ }
75913+#endif
75914+
75915 /* Success. */
75916 if (!err)
75917 return 0;
75918@@ -2038,10 +2427,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75919 new->vm_ops->close(new);
75920 if (new->vm_file)
75921 fput(new->vm_file);
75922- unlink_anon_vmas(new);
75923 out_free_mpol:
75924 mpol_put(pol);
75925 out_free_vma:
75926+
75927+#ifdef CONFIG_PAX_SEGMEXEC
75928+ if (new_m) {
75929+ unlink_anon_vmas(new_m);
75930+ kmem_cache_free(vm_area_cachep, new_m);
75931+ }
75932+#endif
75933+
75934+ unlink_anon_vmas(new);
75935 kmem_cache_free(vm_area_cachep, new);
75936 out_err:
75937 return err;
75938@@ -2054,6 +2451,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
75939 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75940 unsigned long addr, int new_below)
75941 {
75942+
75943+#ifdef CONFIG_PAX_SEGMEXEC
75944+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
75945+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
75946+ if (mm->map_count >= sysctl_max_map_count-1)
75947+ return -ENOMEM;
75948+ } else
75949+#endif
75950+
75951 if (mm->map_count >= sysctl_max_map_count)
75952 return -ENOMEM;
75953
75954@@ -2065,11 +2471,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
75955 * work. This now handles partial unmappings.
75956 * Jeremy Fitzhardinge <jeremy@goop.org>
75957 */
75958+#ifdef CONFIG_PAX_SEGMEXEC
75959 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75960 {
75961+ int ret = __do_munmap(mm, start, len);
75962+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
75963+ return ret;
75964+
75965+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
75966+}
75967+
75968+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75969+#else
75970+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75971+#endif
75972+{
75973 unsigned long end;
75974 struct vm_area_struct *vma, *prev, *last;
75975
75976+ /*
75977+ * mm->mmap_sem is required to protect against another thread
75978+ * changing the mappings in case we sleep.
75979+ */
75980+ verify_mm_writelocked(mm);
75981+
75982 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
75983 return -EINVAL;
75984
75985@@ -2144,6 +2569,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
75986 /* Fix up all other VM information */
75987 remove_vma_list(mm, vma);
75988
75989+ track_exec_limit(mm, start, end, 0UL);
75990+
75991 return 0;
75992 }
75993
75994@@ -2152,6 +2579,13 @@ int vm_munmap(unsigned long start, size_t len)
75995 int ret;
75996 struct mm_struct *mm = current->mm;
75997
75998+
75999+#ifdef CONFIG_PAX_SEGMEXEC
76000+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
76001+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
76002+ return -EINVAL;
76003+#endif
76004+
76005 down_write(&mm->mmap_sem);
76006 ret = do_munmap(mm, start, len);
76007 up_write(&mm->mmap_sem);
76008@@ -2165,16 +2599,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
76009 return vm_munmap(addr, len);
76010 }
76011
76012-static inline void verify_mm_writelocked(struct mm_struct *mm)
76013-{
76014-#ifdef CONFIG_DEBUG_VM
76015- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
76016- WARN_ON(1);
76017- up_read(&mm->mmap_sem);
76018- }
76019-#endif
76020-}
76021-
76022 /*
76023 * this is really a simplified "do_mmap". it only handles
76024 * anonymous maps. eventually we may be able to do some
76025@@ -2188,6 +2612,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76026 struct rb_node ** rb_link, * rb_parent;
76027 pgoff_t pgoff = addr >> PAGE_SHIFT;
76028 int error;
76029+ unsigned long charged;
76030
76031 len = PAGE_ALIGN(len);
76032 if (!len)
76033@@ -2195,16 +2620,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76034
76035 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
76036
76037+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
76038+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
76039+ flags &= ~VM_EXEC;
76040+
76041+#ifdef CONFIG_PAX_MPROTECT
76042+ if (mm->pax_flags & MF_PAX_MPROTECT)
76043+ flags &= ~VM_MAYEXEC;
76044+#endif
76045+
76046+ }
76047+#endif
76048+
76049 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
76050 if (error & ~PAGE_MASK)
76051 return error;
76052
76053+ charged = len >> PAGE_SHIFT;
76054+
76055 /*
76056 * mlock MCL_FUTURE?
76057 */
76058 if (mm->def_flags & VM_LOCKED) {
76059 unsigned long locked, lock_limit;
76060- locked = len >> PAGE_SHIFT;
76061+ locked = charged;
76062 locked += mm->locked_vm;
76063 lock_limit = rlimit(RLIMIT_MEMLOCK);
76064 lock_limit >>= PAGE_SHIFT;
76065@@ -2221,21 +2660,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76066 /*
76067 * Clear old maps. this also does some error checking for us
76068 */
76069- munmap_back:
76070 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
76071 if (do_munmap(mm, addr, len))
76072 return -ENOMEM;
76073- goto munmap_back;
76074+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
76075 }
76076
76077 /* Check against address space limits *after* clearing old maps... */
76078- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
76079+ if (!may_expand_vm(mm, charged))
76080 return -ENOMEM;
76081
76082 if (mm->map_count > sysctl_max_map_count)
76083 return -ENOMEM;
76084
76085- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
76086+ if (security_vm_enough_memory_mm(mm, charged))
76087 return -ENOMEM;
76088
76089 /* Can we just expand an old private anonymous mapping? */
76090@@ -2249,7 +2687,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76091 */
76092 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76093 if (!vma) {
76094- vm_unacct_memory(len >> PAGE_SHIFT);
76095+ vm_unacct_memory(charged);
76096 return -ENOMEM;
76097 }
76098
76099@@ -2263,11 +2701,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
76100 vma_link(mm, vma, prev, rb_link, rb_parent);
76101 out:
76102 perf_event_mmap(vma);
76103- mm->total_vm += len >> PAGE_SHIFT;
76104+ mm->total_vm += charged;
76105 if (flags & VM_LOCKED) {
76106 if (!mlock_vma_pages_range(vma, addr, addr + len))
76107- mm->locked_vm += (len >> PAGE_SHIFT);
76108+ mm->locked_vm += charged;
76109 }
76110+ track_exec_limit(mm, addr, addr + len, flags);
76111 return addr;
76112 }
76113
76114@@ -2325,6 +2764,7 @@ void exit_mmap(struct mm_struct *mm)
76115 while (vma) {
76116 if (vma->vm_flags & VM_ACCOUNT)
76117 nr_accounted += vma_pages(vma);
76118+ vma->vm_mirror = NULL;
76119 vma = remove_vma(vma);
76120 }
76121 vm_unacct_memory(nr_accounted);
76122@@ -2341,6 +2781,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76123 struct vm_area_struct *prev;
76124 struct rb_node **rb_link, *rb_parent;
76125
76126+#ifdef CONFIG_PAX_SEGMEXEC
76127+ struct vm_area_struct *vma_m = NULL;
76128+#endif
76129+
76130+ if (security_mmap_addr(vma->vm_start))
76131+ return -EPERM;
76132+
76133 /*
76134 * The vm_pgoff of a purely anonymous vma should be irrelevant
76135 * until its first write fault, when page's anon_vma and index
76136@@ -2364,7 +2811,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
76137 security_vm_enough_memory_mm(mm, vma_pages(vma)))
76138 return -ENOMEM;
76139
76140+#ifdef CONFIG_PAX_SEGMEXEC
76141+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
76142+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76143+ if (!vma_m)
76144+ return -ENOMEM;
76145+ }
76146+#endif
76147+
76148 vma_link(mm, vma, prev, rb_link, rb_parent);
76149+
76150+#ifdef CONFIG_PAX_SEGMEXEC
76151+ if (vma_m)
76152+ BUG_ON(pax_mirror_vma(vma_m, vma));
76153+#endif
76154+
76155 return 0;
76156 }
76157
76158@@ -2384,6 +2845,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76159 struct mempolicy *pol;
76160 bool faulted_in_anon_vma = true;
76161
76162+ BUG_ON(vma->vm_mirror);
76163+
76164 /*
76165 * If anonymous vma has not yet been faulted, update new pgoff
76166 * to match new location, to increase its chance of merging.
76167@@ -2450,6 +2913,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
76168 return NULL;
76169 }
76170
76171+#ifdef CONFIG_PAX_SEGMEXEC
76172+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
76173+{
76174+ struct vm_area_struct *prev_m;
76175+ struct rb_node **rb_link_m, *rb_parent_m;
76176+ struct mempolicy *pol_m;
76177+
76178+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
76179+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
76180+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
76181+ *vma_m = *vma;
76182+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
76183+ if (anon_vma_clone(vma_m, vma))
76184+ return -ENOMEM;
76185+ pol_m = vma_policy(vma_m);
76186+ mpol_get(pol_m);
76187+ vma_set_policy(vma_m, pol_m);
76188+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
76189+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
76190+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
76191+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
76192+ if (vma_m->vm_file)
76193+ get_file(vma_m->vm_file);
76194+ if (vma_m->vm_ops && vma_m->vm_ops->open)
76195+ vma_m->vm_ops->open(vma_m);
76196+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
76197+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
76198+ vma_m->vm_mirror = vma;
76199+ vma->vm_mirror = vma_m;
76200+ return 0;
76201+}
76202+#endif
76203+
76204 /*
76205 * Return true if the calling process may expand its vm space by the passed
76206 * number of pages
76207@@ -2461,6 +2957,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
76208
76209 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
76210
76211+#ifdef CONFIG_PAX_RANDMMAP
76212+ if (mm->pax_flags & MF_PAX_RANDMMAP)
76213+ cur -= mm->brk_gap;
76214+#endif
76215+
76216+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
76217 if (cur + npages > lim)
76218 return 0;
76219 return 1;
76220@@ -2531,6 +3033,22 @@ int install_special_mapping(struct mm_struct *mm,
76221 vma->vm_start = addr;
76222 vma->vm_end = addr + len;
76223
76224+#ifdef CONFIG_PAX_MPROTECT
76225+ if (mm->pax_flags & MF_PAX_MPROTECT) {
76226+#ifndef CONFIG_PAX_MPROTECT_COMPAT
76227+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
76228+ return -EPERM;
76229+ if (!(vm_flags & VM_EXEC))
76230+ vm_flags &= ~VM_MAYEXEC;
76231+#else
76232+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
76233+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
76234+#endif
76235+ else
76236+ vm_flags &= ~VM_MAYWRITE;
76237+ }
76238+#endif
76239+
76240 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
76241 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
76242
76243diff --git a/mm/mprotect.c b/mm/mprotect.c
76244index a409926..8b32e6d 100644
76245--- a/mm/mprotect.c
76246+++ b/mm/mprotect.c
76247@@ -23,10 +23,17 @@
76248 #include <linux/mmu_notifier.h>
76249 #include <linux/migrate.h>
76250 #include <linux/perf_event.h>
76251+
76252+#ifdef CONFIG_PAX_MPROTECT
76253+#include <linux/elf.h>
76254+#include <linux/binfmts.h>
76255+#endif
76256+
76257 #include <asm/uaccess.h>
76258 #include <asm/pgtable.h>
76259 #include <asm/cacheflush.h>
76260 #include <asm/tlbflush.h>
76261+#include <asm/mmu_context.h>
76262
76263 #ifndef pgprot_modify
76264 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
76265@@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
76266 flush_tlb_range(vma, start, end);
76267 }
76268
76269+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76270+/* called while holding the mmap semaphor for writing except stack expansion */
76271+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
76272+{
76273+ unsigned long oldlimit, newlimit = 0UL;
76274+
76275+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
76276+ return;
76277+
76278+ spin_lock(&mm->page_table_lock);
76279+ oldlimit = mm->context.user_cs_limit;
76280+ if ((prot & VM_EXEC) && oldlimit < end)
76281+ /* USER_CS limit moved up */
76282+ newlimit = end;
76283+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
76284+ /* USER_CS limit moved down */
76285+ newlimit = start;
76286+
76287+ if (newlimit) {
76288+ mm->context.user_cs_limit = newlimit;
76289+
76290+#ifdef CONFIG_SMP
76291+ wmb();
76292+ cpus_clear(mm->context.cpu_user_cs_mask);
76293+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
76294+#endif
76295+
76296+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
76297+ }
76298+ spin_unlock(&mm->page_table_lock);
76299+ if (newlimit == end) {
76300+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
76301+
76302+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
76303+ if (is_vm_hugetlb_page(vma))
76304+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
76305+ else
76306+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
76307+ }
76308+}
76309+#endif
76310+
76311 int
76312 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76313 unsigned long start, unsigned long end, unsigned long newflags)
76314@@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76315 int error;
76316 int dirty_accountable = 0;
76317
76318+#ifdef CONFIG_PAX_SEGMEXEC
76319+ struct vm_area_struct *vma_m = NULL;
76320+ unsigned long start_m, end_m;
76321+
76322+ start_m = start + SEGMEXEC_TASK_SIZE;
76323+ end_m = end + SEGMEXEC_TASK_SIZE;
76324+#endif
76325+
76326 if (newflags == oldflags) {
76327 *pprev = vma;
76328 return 0;
76329 }
76330
76331+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
76332+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
76333+
76334+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
76335+ return -ENOMEM;
76336+
76337+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
76338+ return -ENOMEM;
76339+ }
76340+
76341 /*
76342 * If we make a private mapping writable we increase our commit;
76343 * but (without finer accounting) cannot reduce our commit if we
76344@@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
76345 }
76346 }
76347
76348+#ifdef CONFIG_PAX_SEGMEXEC
76349+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
76350+ if (start != vma->vm_start) {
76351+ error = split_vma(mm, vma, start, 1);
76352+ if (error)
76353+ goto fail;
76354+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
76355+ *pprev = (*pprev)->vm_next;
76356+ }
76357+
76358+ if (end != vma->vm_end) {
76359+ error = split_vma(mm, vma, end, 0);
76360+ if (error)
76361+ goto fail;
76362+ }
76363+
76364+ if (pax_find_mirror_vma(vma)) {
76365+ error = __do_munmap(mm, start_m, end_m - start_m);
76366+ if (error)
76367+ goto fail;
76368+ } else {
76369+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
76370+ if (!vma_m) {
76371+ error = -ENOMEM;
76372+ goto fail;
76373+ }
76374+ vma->vm_flags = newflags;
76375+ error = pax_mirror_vma(vma_m, vma);
76376+ if (error) {
76377+ vma->vm_flags = oldflags;
76378+ goto fail;
76379+ }
76380+ }
76381+ }
76382+#endif
76383+
76384 /*
76385 * First try to merge with previous and/or next vma.
76386 */
76387@@ -204,9 +307,21 @@ success:
76388 * vm_flags and vm_page_prot are protected by the mmap_sem
76389 * held in write mode.
76390 */
76391+
76392+#ifdef CONFIG_PAX_SEGMEXEC
76393+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
76394+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
76395+#endif
76396+
76397 vma->vm_flags = newflags;
76398+
76399+#ifdef CONFIG_PAX_MPROTECT
76400+ if (mm->binfmt && mm->binfmt->handle_mprotect)
76401+ mm->binfmt->handle_mprotect(vma, newflags);
76402+#endif
76403+
76404 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
76405- vm_get_page_prot(newflags));
76406+ vm_get_page_prot(vma->vm_flags));
76407
76408 if (vma_wants_writenotify(vma)) {
76409 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
76410@@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76411 end = start + len;
76412 if (end <= start)
76413 return -ENOMEM;
76414+
76415+#ifdef CONFIG_PAX_SEGMEXEC
76416+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
76417+ if (end > SEGMEXEC_TASK_SIZE)
76418+ return -EINVAL;
76419+ } else
76420+#endif
76421+
76422+ if (end > TASK_SIZE)
76423+ return -EINVAL;
76424+
76425 if (!arch_validate_prot(prot))
76426 return -EINVAL;
76427
76428@@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76429 /*
76430 * Does the application expect PROT_READ to imply PROT_EXEC:
76431 */
76432- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
76433+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
76434 prot |= PROT_EXEC;
76435
76436 vm_flags = calc_vm_prot_bits(prot);
76437@@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76438 if (start > vma->vm_start)
76439 prev = vma;
76440
76441+#ifdef CONFIG_PAX_MPROTECT
76442+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
76443+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
76444+#endif
76445+
76446 for (nstart = start ; ; ) {
76447 unsigned long newflags;
76448
76449@@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76450
76451 /* newflags >> 4 shift VM_MAY% in place of VM_% */
76452 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
76453+ if (prot & (PROT_WRITE | PROT_EXEC))
76454+ gr_log_rwxmprotect(vma->vm_file);
76455+
76456+ error = -EACCES;
76457+ goto out;
76458+ }
76459+
76460+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
76461 error = -EACCES;
76462 goto out;
76463 }
76464@@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
76465 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
76466 if (error)
76467 goto out;
76468+
76469+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
76470+
76471 nstart = tmp;
76472
76473 if (nstart < prev->vm_end)
76474diff --git a/mm/mremap.c b/mm/mremap.c
76475index 1b61c2d..1cc0e3c 100644
76476--- a/mm/mremap.c
76477+++ b/mm/mremap.c
76478@@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
76479 continue;
76480 pte = ptep_get_and_clear(mm, old_addr, old_pte);
76481 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
76482+
76483+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
76484+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
76485+ pte = pte_exprotect(pte);
76486+#endif
76487+
76488 set_pte_at(mm, new_addr, new_pte, pte);
76489 }
76490
76491@@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
76492 if (is_vm_hugetlb_page(vma))
76493 goto Einval;
76494
76495+#ifdef CONFIG_PAX_SEGMEXEC
76496+ if (pax_find_mirror_vma(vma))
76497+ goto Einval;
76498+#endif
76499+
76500 /* We can't remap across vm area boundaries */
76501 if (old_len > vma->vm_end - addr)
76502 goto Efault;
76503@@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
76504 unsigned long ret = -EINVAL;
76505 unsigned long charged = 0;
76506 unsigned long map_flags;
76507+ unsigned long pax_task_size = TASK_SIZE;
76508
76509 if (new_addr & ~PAGE_MASK)
76510 goto out;
76511
76512- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
76513+#ifdef CONFIG_PAX_SEGMEXEC
76514+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
76515+ pax_task_size = SEGMEXEC_TASK_SIZE;
76516+#endif
76517+
76518+ pax_task_size -= PAGE_SIZE;
76519+
76520+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
76521 goto out;
76522
76523 /* Check if the location we're moving into overlaps the
76524 * old location at all, and fail if it does.
76525 */
76526- if ((new_addr <= addr) && (new_addr+new_len) > addr)
76527- goto out;
76528-
76529- if ((addr <= new_addr) && (addr+old_len) > new_addr)
76530+ if (addr + old_len > new_addr && new_addr + new_len > addr)
76531 goto out;
76532
76533 ret = do_munmap(mm, new_addr, new_len);
76534@@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76535 struct vm_area_struct *vma;
76536 unsigned long ret = -EINVAL;
76537 unsigned long charged = 0;
76538+ unsigned long pax_task_size = TASK_SIZE;
76539
76540 down_write(&current->mm->mmap_sem);
76541
76542@@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76543 if (!new_len)
76544 goto out;
76545
76546+#ifdef CONFIG_PAX_SEGMEXEC
76547+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
76548+ pax_task_size = SEGMEXEC_TASK_SIZE;
76549+#endif
76550+
76551+ pax_task_size -= PAGE_SIZE;
76552+
76553+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
76554+ old_len > pax_task_size || addr > pax_task_size-old_len)
76555+ goto out;
76556+
76557 if (flags & MREMAP_FIXED) {
76558 if (flags & MREMAP_MAYMOVE)
76559 ret = mremap_to(addr, old_len, new_addr, new_len);
76560@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76561 addr + new_len);
76562 }
76563 ret = addr;
76564+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
76565 goto out;
76566 }
76567 }
76568@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
76569 goto out;
76570 }
76571
76572+ map_flags = vma->vm_flags;
76573 ret = move_vma(vma, addr, old_len, new_len, new_addr);
76574+ if (!(ret & ~PAGE_MASK)) {
76575+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
76576+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
76577+ }
76578 }
76579 out:
76580 if (ret & ~PAGE_MASK)
76581diff --git a/mm/nommu.c b/mm/nommu.c
76582index 45131b4..c521665 100644
76583--- a/mm/nommu.c
76584+++ b/mm/nommu.c
76585@@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
76586 int sysctl_overcommit_ratio = 50; /* default is 50% */
76587 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
76588 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
76589-int heap_stack_gap = 0;
76590
76591 atomic_long_t mmap_pages_allocated;
76592
76593@@ -824,15 +823,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
76594 EXPORT_SYMBOL(find_vma);
76595
76596 /*
76597- * find a VMA
76598- * - we don't extend stack VMAs under NOMMU conditions
76599- */
76600-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
76601-{
76602- return find_vma(mm, addr);
76603-}
76604-
76605-/*
76606 * expand a stack to a given address
76607 * - not supported under NOMMU conditions
76608 */
76609@@ -1540,6 +1530,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
76610
76611 /* most fields are the same, copy all, and then fixup */
76612 *new = *vma;
76613+ INIT_LIST_HEAD(&new->anon_vma_chain);
76614 *region = *vma->vm_region;
76615 new->vm_region = region;
76616
76617diff --git a/mm/page_alloc.c b/mm/page_alloc.c
76618index ceb4168..d7774f2 100644
76619--- a/mm/page_alloc.c
76620+++ b/mm/page_alloc.c
76621@@ -340,7 +340,7 @@ out:
76622 * This usage means that zero-order pages may not be compound.
76623 */
76624
76625-static void free_compound_page(struct page *page)
76626+void free_compound_page(struct page *page)
76627 {
76628 __free_pages_ok(page, compound_order(page));
76629 }
76630@@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76631 int i;
76632 int bad = 0;
76633
76634+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76635+ unsigned long index = 1UL << order;
76636+#endif
76637+
76638 trace_mm_page_free(page, order);
76639 kmemcheck_free_shadow(page, order);
76640
76641@@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
76642 debug_check_no_obj_freed(page_address(page),
76643 PAGE_SIZE << order);
76644 }
76645+
76646+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76647+ for (; index; --index)
76648+ sanitize_highpage(page + index - 1);
76649+#endif
76650+
76651 arch_free_page(page, order);
76652 kernel_map_pages(page, 1 << order, 0);
76653
76654@@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
76655 arch_alloc_page(page, order);
76656 kernel_map_pages(page, 1 << order, 1);
76657
76658+#ifndef CONFIG_PAX_MEMORY_SANITIZE
76659 if (gfp_flags & __GFP_ZERO)
76660 prep_zero_page(page, order, gfp_flags);
76661+#endif
76662
76663 if (order && (gfp_flags & __GFP_COMP))
76664 prep_compound_page(page, order);
76665@@ -3684,7 +3696,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
76666 unsigned long pfn;
76667
76668 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
76669+#ifdef CONFIG_X86_32
76670+ /* boot failures in VMware 8 on 32bit vanilla since
76671+ this change */
76672+ if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
76673+#else
76674 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
76675+#endif
76676 return 1;
76677 }
76678 return 0;
76679diff --git a/mm/percpu.c b/mm/percpu.c
76680index ddc5efb..f632d2c 100644
76681--- a/mm/percpu.c
76682+++ b/mm/percpu.c
76683@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
76684 static unsigned int pcpu_high_unit_cpu __read_mostly;
76685
76686 /* the address of the first chunk which starts with the kernel static area */
76687-void *pcpu_base_addr __read_mostly;
76688+void *pcpu_base_addr __read_only;
76689 EXPORT_SYMBOL_GPL(pcpu_base_addr);
76690
76691 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
76692diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
76693index 926b466..b23df53 100644
76694--- a/mm/process_vm_access.c
76695+++ b/mm/process_vm_access.c
76696@@ -13,6 +13,7 @@
76697 #include <linux/uio.h>
76698 #include <linux/sched.h>
76699 #include <linux/highmem.h>
76700+#include <linux/security.h>
76701 #include <linux/ptrace.h>
76702 #include <linux/slab.h>
76703 #include <linux/syscalls.h>
76704@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76705 size_t iov_l_curr_offset = 0;
76706 ssize_t iov_len;
76707
76708+ return -ENOSYS; // PaX: until properly audited
76709+
76710 /*
76711 * Work out how many pages of struct pages we're going to need
76712 * when eventually calling get_user_pages
76713 */
76714 for (i = 0; i < riovcnt; i++) {
76715 iov_len = rvec[i].iov_len;
76716- if (iov_len > 0) {
76717- nr_pages_iov = ((unsigned long)rvec[i].iov_base
76718- + iov_len)
76719- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
76720- / PAGE_SIZE + 1;
76721- nr_pages = max(nr_pages, nr_pages_iov);
76722- }
76723+ if (iov_len <= 0)
76724+ continue;
76725+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
76726+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
76727+ nr_pages = max(nr_pages, nr_pages_iov);
76728 }
76729
76730 if (nr_pages == 0)
76731@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
76732 goto free_proc_pages;
76733 }
76734
76735+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
76736+ rc = -EPERM;
76737+ goto put_task_struct;
76738+ }
76739+
76740 mm = mm_access(task, PTRACE_MODE_ATTACH);
76741 if (!mm || IS_ERR(mm)) {
76742 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
76743diff --git a/mm/rmap.c b/mm/rmap.c
76744index 2ee1ef0..2e175ba 100644
76745--- a/mm/rmap.c
76746+++ b/mm/rmap.c
76747@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76748 struct anon_vma *anon_vma = vma->anon_vma;
76749 struct anon_vma_chain *avc;
76750
76751+#ifdef CONFIG_PAX_SEGMEXEC
76752+ struct anon_vma_chain *avc_m = NULL;
76753+#endif
76754+
76755 might_sleep();
76756 if (unlikely(!anon_vma)) {
76757 struct mm_struct *mm = vma->vm_mm;
76758@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76759 if (!avc)
76760 goto out_enomem;
76761
76762+#ifdef CONFIG_PAX_SEGMEXEC
76763+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
76764+ if (!avc_m)
76765+ goto out_enomem_free_avc;
76766+#endif
76767+
76768 anon_vma = find_mergeable_anon_vma(vma);
76769 allocated = NULL;
76770 if (!anon_vma) {
76771@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76772 /* page_table_lock to protect against threads */
76773 spin_lock(&mm->page_table_lock);
76774 if (likely(!vma->anon_vma)) {
76775+
76776+#ifdef CONFIG_PAX_SEGMEXEC
76777+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
76778+
76779+ if (vma_m) {
76780+ BUG_ON(vma_m->anon_vma);
76781+ vma_m->anon_vma = anon_vma;
76782+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
76783+ avc_m = NULL;
76784+ }
76785+#endif
76786+
76787 vma->anon_vma = anon_vma;
76788 anon_vma_chain_link(vma, avc, anon_vma);
76789 allocated = NULL;
76790@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
76791
76792 if (unlikely(allocated))
76793 put_anon_vma(allocated);
76794+
76795+#ifdef CONFIG_PAX_SEGMEXEC
76796+ if (unlikely(avc_m))
76797+ anon_vma_chain_free(avc_m);
76798+#endif
76799+
76800 if (unlikely(avc))
76801 anon_vma_chain_free(avc);
76802 }
76803 return 0;
76804
76805 out_enomem_free_avc:
76806+
76807+#ifdef CONFIG_PAX_SEGMEXEC
76808+ if (avc_m)
76809+ anon_vma_chain_free(avc_m);
76810+#endif
76811+
76812 anon_vma_chain_free(avc);
76813 out_enomem:
76814 return -ENOMEM;
76815@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
76816 * Attach the anon_vmas from src to dst.
76817 * Returns 0 on success, -ENOMEM on failure.
76818 */
76819-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76820+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
76821 {
76822 struct anon_vma_chain *avc, *pavc;
76823 struct anon_vma *root = NULL;
76824@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
76825 * the corresponding VMA in the parent process is attached to.
76826 * Returns 0 on success, non-zero on failure.
76827 */
76828-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
76829+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
76830 {
76831 struct anon_vma_chain *avc;
76832 struct anon_vma *anon_vma;
76833diff --git a/mm/shmem.c b/mm/shmem.c
76834index 50c5b8f..0bc87f7 100644
76835--- a/mm/shmem.c
76836+++ b/mm/shmem.c
76837@@ -31,7 +31,7 @@
76838 #include <linux/export.h>
76839 #include <linux/swap.h>
76840
76841-static struct vfsmount *shm_mnt;
76842+struct vfsmount *shm_mnt;
76843
76844 #ifdef CONFIG_SHMEM
76845 /*
76846@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
76847 #define BOGO_DIRENT_SIZE 20
76848
76849 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
76850-#define SHORT_SYMLINK_LEN 128
76851+#define SHORT_SYMLINK_LEN 64
76852
76853 /*
76854 * shmem_fallocate and shmem_writepage communicate via inode->i_private
76855@@ -2112,6 +2112,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
76856 static int shmem_xattr_validate(const char *name)
76857 {
76858 struct { const char *prefix; size_t len; } arr[] = {
76859+
76860+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76861+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
76862+#endif
76863+
76864 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
76865 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
76866 };
76867@@ -2167,6 +2172,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
76868 if (err)
76869 return err;
76870
76871+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
76872+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
76873+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
76874+ return -EOPNOTSUPP;
76875+ if (size > 8)
76876+ return -EINVAL;
76877+ }
76878+#endif
76879+
76880 return simple_xattr_set(&info->xattrs, name, value, size, flags);
76881 }
76882
76883@@ -2466,8 +2480,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
76884 int err = -ENOMEM;
76885
76886 /* Round up to L1_CACHE_BYTES to resist false sharing */
76887- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
76888- L1_CACHE_BYTES), GFP_KERNEL);
76889+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
76890 if (!sbinfo)
76891 return -ENOMEM;
76892
76893diff --git a/mm/slab.c b/mm/slab.c
76894index 33d3363..3851c61 100644
76895--- a/mm/slab.c
76896+++ b/mm/slab.c
76897@@ -164,7 +164,7 @@ static bool pfmemalloc_active __read_mostly;
76898
76899 /* Legal flag mask for kmem_cache_create(). */
76900 #if DEBUG
76901-# define CREATE_MASK (SLAB_RED_ZONE | \
76902+# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
76903 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
76904 SLAB_CACHE_DMA | \
76905 SLAB_STORE_USER | \
76906@@ -172,7 +172,7 @@ static bool pfmemalloc_active __read_mostly;
76907 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76908 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
76909 #else
76910-# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
76911+# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
76912 SLAB_CACHE_DMA | \
76913 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
76914 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
76915@@ -322,7 +322,7 @@ struct kmem_list3 {
76916 * Need this for bootstrapping a per node allocator.
76917 */
76918 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
76919-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
76920+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
76921 #define CACHE_CACHE 0
76922 #define SIZE_AC MAX_NUMNODES
76923 #define SIZE_L3 (2 * MAX_NUMNODES)
76924@@ -423,10 +423,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
76925 if ((x)->max_freeable < i) \
76926 (x)->max_freeable = i; \
76927 } while (0)
76928-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
76929-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
76930-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
76931-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
76932+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
76933+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
76934+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
76935+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
76936 #else
76937 #define STATS_INC_ACTIVE(x) do { } while (0)
76938 #define STATS_DEC_ACTIVE(x) do { } while (0)
76939@@ -534,7 +534,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
76940 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
76941 */
76942 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
76943- const struct slab *slab, void *obj)
76944+ const struct slab *slab, const void *obj)
76945 {
76946 u32 offset = (obj - slab->s_mem);
76947 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
76948@@ -555,12 +555,13 @@ EXPORT_SYMBOL(malloc_sizes);
76949 struct cache_names {
76950 char *name;
76951 char *name_dma;
76952+ char *name_usercopy;
76953 };
76954
76955 static struct cache_names __initdata cache_names[] = {
76956-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
76957+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
76958 #include <linux/kmalloc_sizes.h>
76959- {NULL,}
76960+ {NULL}
76961 #undef CACHE
76962 };
76963
76964@@ -721,6 +722,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
76965 if (unlikely(gfpflags & GFP_DMA))
76966 return csizep->cs_dmacachep;
76967 #endif
76968+
76969+#ifdef CONFIG_PAX_USERCOPY_SLABS
76970+ if (unlikely(gfpflags & GFP_USERCOPY))
76971+ return csizep->cs_usercopycachep;
76972+#endif
76973+
76974 return csizep->cs_cachep;
76975 }
76976
76977@@ -1676,7 +1683,7 @@ void __init kmem_cache_init(void)
76978 sizes[INDEX_AC].cs_cachep->size = sizes[INDEX_AC].cs_size;
76979 sizes[INDEX_AC].cs_cachep->object_size = sizes[INDEX_AC].cs_size;
76980 sizes[INDEX_AC].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76981- __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
76982+ __kmem_cache_create(sizes[INDEX_AC].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
76983 list_add(&sizes[INDEX_AC].cs_cachep->list, &slab_caches);
76984
76985 if (INDEX_AC != INDEX_L3) {
76986@@ -1685,7 +1692,7 @@ void __init kmem_cache_init(void)
76987 sizes[INDEX_L3].cs_cachep->size = sizes[INDEX_L3].cs_size;
76988 sizes[INDEX_L3].cs_cachep->object_size = sizes[INDEX_L3].cs_size;
76989 sizes[INDEX_L3].cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76990- __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
76991+ __kmem_cache_create(sizes[INDEX_L3].cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
76992 list_add(&sizes[INDEX_L3].cs_cachep->list, &slab_caches);
76993 }
76994
76995@@ -1705,7 +1712,7 @@ void __init kmem_cache_init(void)
76996 sizes->cs_cachep->size = sizes->cs_size;
76997 sizes->cs_cachep->object_size = sizes->cs_size;
76998 sizes->cs_cachep->align = ARCH_KMALLOC_MINALIGN;
76999- __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC);
77000+ __kmem_cache_create(sizes->cs_cachep, ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY);
77001 list_add(&sizes->cs_cachep->list, &slab_caches);
77002 }
77003 #ifdef CONFIG_ZONE_DMA
77004@@ -1718,6 +1725,17 @@ void __init kmem_cache_init(void)
77005 ARCH_KMALLOC_FLAGS|SLAB_CACHE_DMA| SLAB_PANIC);
77006 list_add(&sizes->cs_dmacachep->list, &slab_caches);
77007 #endif
77008+
77009+#ifdef CONFIG_PAX_USERCOPY_SLABS
77010+ sizes->cs_usercopycachep = kmem_cache_zalloc(kmem_cache, GFP_NOWAIT);
77011+ sizes->cs_usercopycachep->name = names->name_usercopy;
77012+ sizes->cs_usercopycachep->size = sizes->cs_size;
77013+ sizes->cs_usercopycachep->object_size = sizes->cs_size;
77014+ sizes->cs_usercopycachep->align = ARCH_KMALLOC_MINALIGN;
77015+ __kmem_cache_create(sizes->cs_usercopycachep, ARCH_KMALLOC_FLAGS| SLAB_PANIC|SLAB_USERCOPY);
77016+ list_add(&sizes->cs_usercopycachep->list, &slab_caches);
77017+#endif
77018+
77019 sizes++;
77020 names++;
77021 }
77022@@ -4405,10 +4423,10 @@ static int s_show(struct seq_file *m, void *p)
77023 }
77024 /* cpu stats */
77025 {
77026- unsigned long allochit = atomic_read(&cachep->allochit);
77027- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
77028- unsigned long freehit = atomic_read(&cachep->freehit);
77029- unsigned long freemiss = atomic_read(&cachep->freemiss);
77030+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
77031+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
77032+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
77033+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
77034
77035 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
77036 allochit, allocmiss, freehit, freemiss);
77037@@ -4667,13 +4685,71 @@ static int __init slab_proc_init(void)
77038 {
77039 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
77040 #ifdef CONFIG_DEBUG_SLAB_LEAK
77041- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
77042+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
77043 #endif
77044 return 0;
77045 }
77046 module_init(slab_proc_init);
77047 #endif
77048
77049+bool is_usercopy_object(const void *ptr)
77050+{
77051+ struct page *page;
77052+ struct kmem_cache *cachep;
77053+
77054+ if (ZERO_OR_NULL_PTR(ptr))
77055+ return false;
77056+
77057+ if (!slab_is_available())
77058+ return false;
77059+
77060+ if (!virt_addr_valid(ptr))
77061+ return false;
77062+
77063+ page = virt_to_head_page(ptr);
77064+
77065+ if (!PageSlab(page))
77066+ return false;
77067+
77068+ cachep = page->slab_cache;
77069+ return cachep->flags & SLAB_USERCOPY;
77070+}
77071+
77072+#ifdef CONFIG_PAX_USERCOPY
77073+const char *check_heap_object(const void *ptr, unsigned long n)
77074+{
77075+ struct page *page;
77076+ struct kmem_cache *cachep;
77077+ struct slab *slabp;
77078+ unsigned int objnr;
77079+ unsigned long offset;
77080+
77081+ if (ZERO_OR_NULL_PTR(ptr))
77082+ return "<null>";
77083+
77084+ if (!virt_addr_valid(ptr))
77085+ return NULL;
77086+
77087+ page = virt_to_head_page(ptr);
77088+
77089+ if (!PageSlab(page))
77090+ return NULL;
77091+
77092+ cachep = page->slab_cache;
77093+ if (!(cachep->flags & SLAB_USERCOPY))
77094+ return cachep->name;
77095+
77096+ slabp = page->slab_page;
77097+ objnr = obj_to_index(cachep, slabp, ptr);
77098+ BUG_ON(objnr >= cachep->num);
77099+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
77100+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
77101+ return NULL;
77102+
77103+ return cachep->name;
77104+}
77105+#endif
77106+
77107 /**
77108 * ksize - get the actual amount of memory allocated for a given object
77109 * @objp: Pointer to the object
77110diff --git a/mm/slab_common.c b/mm/slab_common.c
77111index 069a24e6..226a310 100644
77112--- a/mm/slab_common.c
77113+++ b/mm/slab_common.c
77114@@ -127,7 +127,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size, size_t align
77115 err = __kmem_cache_create(s, flags);
77116 if (!err) {
77117
77118- s->refcount = 1;
77119+ atomic_set(&s->refcount, 1);
77120 list_add(&s->list, &slab_caches);
77121
77122 } else {
77123@@ -163,8 +163,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
77124 {
77125 get_online_cpus();
77126 mutex_lock(&slab_mutex);
77127- s->refcount--;
77128- if (!s->refcount) {
77129+ if (atomic_dec_and_test(&s->refcount)) {
77130 list_del(&s->list);
77131
77132 if (!__kmem_cache_shutdown(s)) {
77133diff --git a/mm/slob.c b/mm/slob.c
77134index 1e921c5..1ce12c2 100644
77135--- a/mm/slob.c
77136+++ b/mm/slob.c
77137@@ -159,7 +159,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
77138 /*
77139 * Return the size of a slob block.
77140 */
77141-static slobidx_t slob_units(slob_t *s)
77142+static slobidx_t slob_units(const slob_t *s)
77143 {
77144 if (s->units > 0)
77145 return s->units;
77146@@ -169,7 +169,7 @@ static slobidx_t slob_units(slob_t *s)
77147 /*
77148 * Return the next free slob block pointer after this one.
77149 */
77150-static slob_t *slob_next(slob_t *s)
77151+static slob_t *slob_next(const slob_t *s)
77152 {
77153 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
77154 slobidx_t next;
77155@@ -184,14 +184,14 @@ static slob_t *slob_next(slob_t *s)
77156 /*
77157 * Returns true if s is the last free block in its page.
77158 */
77159-static int slob_last(slob_t *s)
77160+static int slob_last(const slob_t *s)
77161 {
77162 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
77163 }
77164
77165-static void *slob_new_pages(gfp_t gfp, int order, int node)
77166+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
77167 {
77168- void *page;
77169+ struct page *page;
77170
77171 #ifdef CONFIG_NUMA
77172 if (node != NUMA_NO_NODE)
77173@@ -203,14 +203,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
77174 if (!page)
77175 return NULL;
77176
77177- return page_address(page);
77178+ __SetPageSlab(page);
77179+ return page;
77180 }
77181
77182-static void slob_free_pages(void *b, int order)
77183+static void slob_free_pages(struct page *sp, int order)
77184 {
77185 if (current->reclaim_state)
77186 current->reclaim_state->reclaimed_slab += 1 << order;
77187- free_pages((unsigned long)b, order);
77188+ __ClearPageSlab(sp);
77189+ reset_page_mapcount(sp);
77190+ sp->private = 0;
77191+ __free_pages(sp, order);
77192 }
77193
77194 /*
77195@@ -315,15 +319,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
77196
77197 /* Not enough space: must allocate a new page */
77198 if (!b) {
77199- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77200- if (!b)
77201+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
77202+ if (!sp)
77203 return NULL;
77204- sp = virt_to_page(b);
77205- __SetPageSlab(sp);
77206+ b = page_address(sp);
77207
77208 spin_lock_irqsave(&slob_lock, flags);
77209 sp->units = SLOB_UNITS(PAGE_SIZE);
77210 sp->freelist = b;
77211+ sp->private = 0;
77212 INIT_LIST_HEAD(&sp->list);
77213 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
77214 set_slob_page_free(sp, slob_list);
77215@@ -361,9 +365,7 @@ static void slob_free(void *block, int size)
77216 if (slob_page_free(sp))
77217 clear_slob_page_free(sp);
77218 spin_unlock_irqrestore(&slob_lock, flags);
77219- __ClearPageSlab(sp);
77220- reset_page_mapcount(sp);
77221- slob_free_pages(b, 0);
77222+ slob_free_pages(sp, 0);
77223 return;
77224 }
77225
77226@@ -426,11 +428,10 @@ out:
77227 */
77228
77229 static __always_inline void *
77230-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77231+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
77232 {
77233- unsigned int *m;
77234- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77235- void *ret;
77236+ slob_t *m;
77237+ void *ret = NULL;
77238
77239 gfp &= gfp_allowed_mask;
77240
77241@@ -444,20 +445,23 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77242
77243 if (!m)
77244 return NULL;
77245- *m = size;
77246+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
77247+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
77248+ m[0].units = size;
77249+ m[1].units = align;
77250 ret = (void *)m + align;
77251
77252 trace_kmalloc_node(caller, ret,
77253 size, size + align, gfp, node);
77254 } else {
77255 unsigned int order = get_order(size);
77256+ struct page *page;
77257
77258 if (likely(order))
77259 gfp |= __GFP_COMP;
77260- ret = slob_new_pages(gfp, order, node);
77261- if (ret) {
77262- struct page *page;
77263- page = virt_to_page(ret);
77264+ page = slob_new_pages(gfp, order, node);
77265+ if (page) {
77266+ ret = page_address(page);
77267 page->private = size;
77268 }
77269
77270@@ -465,7 +469,17 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77271 size, PAGE_SIZE << order, gfp, node);
77272 }
77273
77274- kmemleak_alloc(ret, size, 1, gfp);
77275+ return ret;
77276+}
77277+
77278+static __always_inline void *
77279+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
77280+{
77281+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77282+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
77283+
77284+ if (!ZERO_OR_NULL_PTR(ret))
77285+ kmemleak_alloc(ret, size, 1, gfp);
77286 return ret;
77287 }
77288
77289@@ -501,15 +515,91 @@ void kfree(const void *block)
77290 kmemleak_free(block);
77291
77292 sp = virt_to_page(block);
77293- if (PageSlab(sp)) {
77294+ VM_BUG_ON(!PageSlab(sp));
77295+ if (!sp->private) {
77296 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77297- unsigned int *m = (unsigned int *)(block - align);
77298- slob_free(m, *m + align);
77299- } else
77300+ slob_t *m = (slob_t *)(block - align);
77301+ slob_free(m, m[0].units + align);
77302+ } else {
77303+ __ClearPageSlab(sp);
77304+ reset_page_mapcount(sp);
77305+ sp->private = 0;
77306 put_page(sp);
77307+ }
77308 }
77309 EXPORT_SYMBOL(kfree);
77310
77311+bool is_usercopy_object(const void *ptr)
77312+{
77313+ if (!slab_is_available())
77314+ return false;
77315+
77316+ // PAX: TODO
77317+
77318+ return false;
77319+}
77320+
77321+#ifdef CONFIG_PAX_USERCOPY
77322+const char *check_heap_object(const void *ptr, unsigned long n)
77323+{
77324+ struct page *page;
77325+ const slob_t *free;
77326+ const void *base;
77327+ unsigned long flags;
77328+
77329+ if (ZERO_OR_NULL_PTR(ptr))
77330+ return "<null>";
77331+
77332+ if (!virt_addr_valid(ptr))
77333+ return NULL;
77334+
77335+ page = virt_to_head_page(ptr);
77336+ if (!PageSlab(page))
77337+ return NULL;
77338+
77339+ if (page->private) {
77340+ base = page;
77341+ if (base <= ptr && n <= page->private - (ptr - base))
77342+ return NULL;
77343+ return "<slob>";
77344+ }
77345+
77346+ /* some tricky double walking to find the chunk */
77347+ spin_lock_irqsave(&slob_lock, flags);
77348+ base = (void *)((unsigned long)ptr & PAGE_MASK);
77349+ free = page->freelist;
77350+
77351+ while (!slob_last(free) && (void *)free <= ptr) {
77352+ base = free + slob_units(free);
77353+ free = slob_next(free);
77354+ }
77355+
77356+ while (base < (void *)free) {
77357+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
77358+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
77359+ int offset;
77360+
77361+ if (ptr < base + align)
77362+ break;
77363+
77364+ offset = ptr - base - align;
77365+ if (offset >= m) {
77366+ base += size;
77367+ continue;
77368+ }
77369+
77370+ if (n > m - offset)
77371+ break;
77372+
77373+ spin_unlock_irqrestore(&slob_lock, flags);
77374+ return NULL;
77375+ }
77376+
77377+ spin_unlock_irqrestore(&slob_lock, flags);
77378+ return "<slob>";
77379+}
77380+#endif
77381+
77382 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
77383 size_t ksize(const void *block)
77384 {
77385@@ -520,10 +610,11 @@ size_t ksize(const void *block)
77386 return 0;
77387
77388 sp = virt_to_page(block);
77389- if (PageSlab(sp)) {
77390+ VM_BUG_ON(!PageSlab(sp));
77391+ if (!sp->private) {
77392 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
77393- unsigned int *m = (unsigned int *)(block - align);
77394- return SLOB_UNITS(*m) * SLOB_UNIT;
77395+ slob_t *m = (slob_t *)(block - align);
77396+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
77397 } else
77398 return sp->private;
77399 }
77400@@ -550,23 +641,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
77401
77402 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
77403 {
77404- void *b;
77405+ void *b = NULL;
77406
77407 flags &= gfp_allowed_mask;
77408
77409 lockdep_trace_alloc(flags);
77410
77411+#ifdef CONFIG_PAX_USERCOPY_SLABS
77412+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
77413+#else
77414 if (c->size < PAGE_SIZE) {
77415 b = slob_alloc(c->size, flags, c->align, node);
77416 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77417 SLOB_UNITS(c->size) * SLOB_UNIT,
77418 flags, node);
77419 } else {
77420- b = slob_new_pages(flags, get_order(c->size), node);
77421+ struct page *sp;
77422+
77423+ sp = slob_new_pages(flags, get_order(c->size), node);
77424+ if (sp) {
77425+ b = page_address(sp);
77426+ sp->private = c->size;
77427+ }
77428 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
77429 PAGE_SIZE << get_order(c->size),
77430 flags, node);
77431 }
77432+#endif
77433
77434 if (c->ctor)
77435 c->ctor(b);
77436@@ -578,10 +679,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
77437
77438 static void __kmem_cache_free(void *b, int size)
77439 {
77440- if (size < PAGE_SIZE)
77441+ struct page *sp;
77442+
77443+ sp = virt_to_page(b);
77444+ BUG_ON(!PageSlab(sp));
77445+ if (!sp->private)
77446 slob_free(b, size);
77447 else
77448- slob_free_pages(b, get_order(size));
77449+ slob_free_pages(sp, get_order(size));
77450 }
77451
77452 static void kmem_rcu_free(struct rcu_head *head)
77453@@ -594,17 +699,31 @@ static void kmem_rcu_free(struct rcu_head *head)
77454
77455 void kmem_cache_free(struct kmem_cache *c, void *b)
77456 {
77457+ int size = c->size;
77458+
77459+#ifdef CONFIG_PAX_USERCOPY_SLABS
77460+ if (size + c->align < PAGE_SIZE) {
77461+ size += c->align;
77462+ b -= c->align;
77463+ }
77464+#endif
77465+
77466 kmemleak_free_recursive(b, c->flags);
77467 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
77468 struct slob_rcu *slob_rcu;
77469- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
77470- slob_rcu->size = c->size;
77471+ slob_rcu = b + (size - sizeof(struct slob_rcu));
77472+ slob_rcu->size = size;
77473 call_rcu(&slob_rcu->head, kmem_rcu_free);
77474 } else {
77475- __kmem_cache_free(b, c->size);
77476+ __kmem_cache_free(b, size);
77477 }
77478
77479+#ifdef CONFIG_PAX_USERCOPY_SLABS
77480+ trace_kfree(_RET_IP_, b);
77481+#else
77482 trace_kmem_cache_free(_RET_IP_, b);
77483+#endif
77484+
77485 }
77486 EXPORT_SYMBOL(kmem_cache_free);
77487
77488diff --git a/mm/slub.c b/mm/slub.c
77489index 321afab..9595170 100644
77490--- a/mm/slub.c
77491+++ b/mm/slub.c
77492@@ -201,7 +201,7 @@ struct track {
77493
77494 enum track_item { TRACK_ALLOC, TRACK_FREE };
77495
77496-#ifdef CONFIG_SYSFS
77497+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77498 static int sysfs_slab_add(struct kmem_cache *);
77499 static int sysfs_slab_alias(struct kmem_cache *, const char *);
77500 static void sysfs_slab_remove(struct kmem_cache *);
77501@@ -521,7 +521,7 @@ static void print_track(const char *s, struct track *t)
77502 if (!t->addr)
77503 return;
77504
77505- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
77506+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
77507 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
77508 #ifdef CONFIG_STACKTRACE
77509 {
77510@@ -2623,6 +2623,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
77511
77512 page = virt_to_head_page(x);
77513
77514+ BUG_ON(!PageSlab(page));
77515+
77516 if (kmem_cache_debug(s) && page->slab != s) {
77517 pr_err("kmem_cache_free: Wrong slab cache. %s but object"
77518 " is from %s\n", page->slab->name, s->name);
77519@@ -2663,7 +2665,7 @@ static int slub_min_objects;
77520 * Merge control. If this is set then no merging of slab caches will occur.
77521 * (Could be removed. This was introduced to pacify the merge skeptics.)
77522 */
77523-static int slub_nomerge;
77524+static int slub_nomerge = 1;
77525
77526 /*
77527 * Calculate the order of allocation given an slab object size.
77528@@ -3225,6 +3227,10 @@ EXPORT_SYMBOL(kmalloc_caches);
77529 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
77530 #endif
77531
77532+#ifdef CONFIG_PAX_USERCOPY_SLABS
77533+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
77534+#endif
77535+
77536 static int __init setup_slub_min_order(char *str)
77537 {
77538 get_option(&str, &slub_min_order);
77539@@ -3279,7 +3285,7 @@ static struct kmem_cache *__init create_kmalloc_cache(const char *name,
77540 if (kmem_cache_open(s, flags))
77541 goto panic;
77542
77543- s->refcount = 1;
77544+ atomic_set(&s->refcount, 1);
77545 list_add(&s->list, &slab_caches);
77546 return s;
77547
77548@@ -3343,6 +3349,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77549 return kmalloc_dma_caches[index];
77550
77551 #endif
77552+
77553+#ifdef CONFIG_PAX_USERCOPY_SLABS
77554+ if (flags & SLAB_USERCOPY)
77555+ return kmalloc_usercopy_caches[index];
77556+
77557+#endif
77558+
77559 return kmalloc_caches[index];
77560 }
77561
77562@@ -3411,6 +3424,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77563 EXPORT_SYMBOL(__kmalloc_node);
77564 #endif
77565
77566+bool is_usercopy_object(const void *ptr)
77567+{
77568+ struct page *page;
77569+ struct kmem_cache *s;
77570+
77571+ if (ZERO_OR_NULL_PTR(ptr))
77572+ return false;
77573+
77574+ if (!slab_is_available())
77575+ return false;
77576+
77577+ if (!virt_addr_valid(ptr))
77578+ return false;
77579+
77580+ page = virt_to_head_page(ptr);
77581+
77582+ if (!PageSlab(page))
77583+ return false;
77584+
77585+ s = page->slab;
77586+ return s->flags & SLAB_USERCOPY;
77587+}
77588+
77589+#ifdef CONFIG_PAX_USERCOPY
77590+const char *check_heap_object(const void *ptr, unsigned long n)
77591+{
77592+ struct page *page;
77593+ struct kmem_cache *s;
77594+ unsigned long offset;
77595+
77596+ if (ZERO_OR_NULL_PTR(ptr))
77597+ return "<null>";
77598+
77599+ if (!virt_addr_valid(ptr))
77600+ return NULL;
77601+
77602+ page = virt_to_head_page(ptr);
77603+
77604+ if (!PageSlab(page))
77605+ return NULL;
77606+
77607+ s = page->slab;
77608+ if (!(s->flags & SLAB_USERCOPY))
77609+ return s->name;
77610+
77611+ offset = (ptr - page_address(page)) % s->size;
77612+ if (offset <= s->object_size && n <= s->object_size - offset)
77613+ return NULL;
77614+
77615+ return s->name;
77616+}
77617+#endif
77618+
77619 size_t ksize(const void *object)
77620 {
77621 struct page *page;
77622@@ -3685,7 +3751,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77623 int node;
77624
77625 list_add(&s->list, &slab_caches);
77626- s->refcount = -1;
77627+ atomic_set(&s->refcount, -1);
77628
77629 for_each_node_state(node, N_NORMAL_MEMORY) {
77630 struct kmem_cache_node *n = get_node(s, node);
77631@@ -3808,17 +3874,17 @@ void __init kmem_cache_init(void)
77632
77633 /* Caches that are not of the two-to-the-power-of size */
77634 if (KMALLOC_MIN_SIZE <= 32) {
77635- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77636+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77637 caches++;
77638 }
77639
77640 if (KMALLOC_MIN_SIZE <= 64) {
77641- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77642+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77643 caches++;
77644 }
77645
77646 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77647- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77648+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77649 caches++;
77650 }
77651
77652@@ -3860,6 +3926,22 @@ void __init kmem_cache_init(void)
77653 }
77654 }
77655 #endif
77656+
77657+#ifdef CONFIG_PAX_USERCOPY_SLABS
77658+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77659+ struct kmem_cache *s = kmalloc_caches[i];
77660+
77661+ if (s && s->size) {
77662+ char *name = kasprintf(GFP_NOWAIT,
77663+ "usercopy-kmalloc-%d", s->object_size);
77664+
77665+ BUG_ON(!name);
77666+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77667+ s->object_size, SLAB_USERCOPY);
77668+ }
77669+ }
77670+#endif
77671+
77672 printk(KERN_INFO
77673 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77674 " CPUs=%d, Nodes=%d\n",
77675@@ -3886,7 +3968,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77676 /*
77677 * We may have set a slab to be unmergeable during bootstrap.
77678 */
77679- if (s->refcount < 0)
77680+ if (atomic_read(&s->refcount) < 0)
77681 return 1;
77682
77683 return 0;
77684@@ -3940,7 +4022,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77685
77686 s = find_mergeable(size, align, flags, name, ctor);
77687 if (s) {
77688- s->refcount++;
77689+ atomic_inc(&s->refcount);
77690 /*
77691 * Adjust the object sizes so that we clear
77692 * the complete object on kzalloc.
77693@@ -3949,7 +4031,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77694 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77695
77696 if (sysfs_slab_alias(s, name)) {
77697- s->refcount--;
77698+ atomic_dec(&s->refcount);
77699 s = NULL;
77700 }
77701 }
77702@@ -4064,7 +4146,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77703 }
77704 #endif
77705
77706-#ifdef CONFIG_SYSFS
77707+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77708 static int count_inuse(struct page *page)
77709 {
77710 return page->inuse;
77711@@ -4451,12 +4533,12 @@ static void resiliency_test(void)
77712 validate_slab_cache(kmalloc_caches[9]);
77713 }
77714 #else
77715-#ifdef CONFIG_SYSFS
77716+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77717 static void resiliency_test(void) {};
77718 #endif
77719 #endif
77720
77721-#ifdef CONFIG_SYSFS
77722+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77723 enum slab_stat_type {
77724 SL_ALL, /* All slabs */
77725 SL_PARTIAL, /* Only partially allocated slabs */
77726@@ -4700,7 +4782,7 @@ SLAB_ATTR_RO(ctor);
77727
77728 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77729 {
77730- return sprintf(buf, "%d\n", s->refcount - 1);
77731+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77732 }
77733 SLAB_ATTR_RO(aliases);
77734
77735@@ -5262,6 +5344,7 @@ static char *create_unique_id(struct kmem_cache *s)
77736 return name;
77737 }
77738
77739+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77740 static int sysfs_slab_add(struct kmem_cache *s)
77741 {
77742 int err;
77743@@ -5324,6 +5407,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
77744 kobject_del(&s->kobj);
77745 kobject_put(&s->kobj);
77746 }
77747+#endif
77748
77749 /*
77750 * Need to buffer aliases during bootup until sysfs becomes
77751@@ -5337,6 +5421,7 @@ struct saved_alias {
77752
77753 static struct saved_alias *alias_list;
77754
77755+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77756 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77757 {
77758 struct saved_alias *al;
77759@@ -5359,6 +5444,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77760 alias_list = al;
77761 return 0;
77762 }
77763+#endif
77764
77765 static int __init slab_sysfs_init(void)
77766 {
77767diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
77768index 1b7e22a..3fcd4f3 100644
77769--- a/mm/sparse-vmemmap.c
77770+++ b/mm/sparse-vmemmap.c
77771@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
77772 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77773 if (!p)
77774 return NULL;
77775- pud_populate(&init_mm, pud, p);
77776+ pud_populate_kernel(&init_mm, pud, p);
77777 }
77778 return pud;
77779 }
77780@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
77781 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77782 if (!p)
77783 return NULL;
77784- pgd_populate(&init_mm, pgd, p);
77785+ pgd_populate_kernel(&init_mm, pgd, p);
77786 }
77787 return pgd;
77788 }
77789diff --git a/mm/swap.c b/mm/swap.c
77790index 6310dc2..3662b3f 100644
77791--- a/mm/swap.c
77792+++ b/mm/swap.c
77793@@ -30,6 +30,7 @@
77794 #include <linux/backing-dev.h>
77795 #include <linux/memcontrol.h>
77796 #include <linux/gfp.h>
77797+#include <linux/hugetlb.h>
77798
77799 #include "internal.h"
77800
77801@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
77802
77803 __page_cache_release(page);
77804 dtor = get_compound_page_dtor(page);
77805+ if (!PageHuge(page))
77806+ BUG_ON(dtor != free_compound_page);
77807 (*dtor)(page);
77808 }
77809
77810diff --git a/mm/swapfile.c b/mm/swapfile.c
77811index f91a255..9dcac21 100644
77812--- a/mm/swapfile.c
77813+++ b/mm/swapfile.c
77814@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
77815
77816 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
77817 /* Activity counter to indicate that a swapon or swapoff has occurred */
77818-static atomic_t proc_poll_event = ATOMIC_INIT(0);
77819+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
77820
77821 static inline unsigned char swap_count(unsigned char ent)
77822 {
77823@@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
77824 }
77825 filp_close(swap_file, NULL);
77826 err = 0;
77827- atomic_inc(&proc_poll_event);
77828+ atomic_inc_unchecked(&proc_poll_event);
77829 wake_up_interruptible(&proc_poll_wait);
77830
77831 out_dput:
77832@@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
77833
77834 poll_wait(file, &proc_poll_wait, wait);
77835
77836- if (seq->poll_event != atomic_read(&proc_poll_event)) {
77837- seq->poll_event = atomic_read(&proc_poll_event);
77838+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
77839+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77840 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
77841 }
77842
77843@@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
77844 return ret;
77845
77846 seq = file->private_data;
77847- seq->poll_event = atomic_read(&proc_poll_event);
77848+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77849 return 0;
77850 }
77851
77852@@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
77853 (frontswap_map) ? "FS" : "");
77854
77855 mutex_unlock(&swapon_mutex);
77856- atomic_inc(&proc_poll_event);
77857+ atomic_inc_unchecked(&proc_poll_event);
77858 wake_up_interruptible(&proc_poll_wait);
77859
77860 if (S_ISREG(inode->i_mode))
77861diff --git a/mm/util.c b/mm/util.c
77862index dc3036c..b6c7c9d 100644
77863--- a/mm/util.c
77864+++ b/mm/util.c
77865@@ -292,6 +292,12 @@ done:
77866 void arch_pick_mmap_layout(struct mm_struct *mm)
77867 {
77868 mm->mmap_base = TASK_UNMAPPED_BASE;
77869+
77870+#ifdef CONFIG_PAX_RANDMMAP
77871+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77872+ mm->mmap_base += mm->delta_mmap;
77873+#endif
77874+
77875 mm->get_unmapped_area = arch_get_unmapped_area;
77876 mm->unmap_area = arch_unmap_area;
77877 }
77878diff --git a/mm/vmalloc.c b/mm/vmalloc.c
77879index 78e0830..bc6bbd8 100644
77880--- a/mm/vmalloc.c
77881+++ b/mm/vmalloc.c
77882@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
77883
77884 pte = pte_offset_kernel(pmd, addr);
77885 do {
77886- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77887- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77888+
77889+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77890+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
77891+ BUG_ON(!pte_exec(*pte));
77892+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
77893+ continue;
77894+ }
77895+#endif
77896+
77897+ {
77898+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77899+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77900+ }
77901 } while (pte++, addr += PAGE_SIZE, addr != end);
77902 }
77903
77904@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
77905 pte = pte_alloc_kernel(pmd, addr);
77906 if (!pte)
77907 return -ENOMEM;
77908+
77909+ pax_open_kernel();
77910 do {
77911 struct page *page = pages[*nr];
77912
77913- if (WARN_ON(!pte_none(*pte)))
77914+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77915+ if (pgprot_val(prot) & _PAGE_NX)
77916+#endif
77917+
77918+ if (!pte_none(*pte)) {
77919+ pax_close_kernel();
77920+ WARN_ON(1);
77921 return -EBUSY;
77922- if (WARN_ON(!page))
77923+ }
77924+ if (!page) {
77925+ pax_close_kernel();
77926+ WARN_ON(1);
77927 return -ENOMEM;
77928+ }
77929 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
77930 (*nr)++;
77931 } while (pte++, addr += PAGE_SIZE, addr != end);
77932+ pax_close_kernel();
77933 return 0;
77934 }
77935
77936@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
77937 pmd_t *pmd;
77938 unsigned long next;
77939
77940- pmd = pmd_alloc(&init_mm, pud, addr);
77941+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
77942 if (!pmd)
77943 return -ENOMEM;
77944 do {
77945@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
77946 pud_t *pud;
77947 unsigned long next;
77948
77949- pud = pud_alloc(&init_mm, pgd, addr);
77950+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
77951 if (!pud)
77952 return -ENOMEM;
77953 do {
77954@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
77955 * and fall back on vmalloc() if that fails. Others
77956 * just put it in the vmalloc space.
77957 */
77958-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
77959+#ifdef CONFIG_MODULES
77960+#ifdef MODULES_VADDR
77961 unsigned long addr = (unsigned long)x;
77962 if (addr >= MODULES_VADDR && addr < MODULES_END)
77963 return 1;
77964 #endif
77965+
77966+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77967+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
77968+ return 1;
77969+#endif
77970+
77971+#endif
77972+
77973 return is_vmalloc_addr(x);
77974 }
77975
77976@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
77977
77978 if (!pgd_none(*pgd)) {
77979 pud_t *pud = pud_offset(pgd, addr);
77980+#ifdef CONFIG_X86
77981+ if (!pud_large(*pud))
77982+#endif
77983 if (!pud_none(*pud)) {
77984 pmd_t *pmd = pmd_offset(pud, addr);
77985+#ifdef CONFIG_X86
77986+ if (!pmd_large(*pmd))
77987+#endif
77988 if (!pmd_none(*pmd)) {
77989 pte_t *ptep, pte;
77990
77991@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
77992 * Allocate a region of KVA of the specified size and alignment, within the
77993 * vstart and vend.
77994 */
77995-static struct vmap_area *alloc_vmap_area(unsigned long size,
77996+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
77997 unsigned long align,
77998 unsigned long vstart, unsigned long vend,
77999 int node, gfp_t gfp_mask)
78000@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
78001 struct vm_struct *area;
78002
78003 BUG_ON(in_interrupt());
78004+
78005+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78006+ if (flags & VM_KERNEXEC) {
78007+ if (start != VMALLOC_START || end != VMALLOC_END)
78008+ return NULL;
78009+ start = (unsigned long)MODULES_EXEC_VADDR;
78010+ end = (unsigned long)MODULES_EXEC_END;
78011+ }
78012+#endif
78013+
78014 if (flags & VM_IOREMAP) {
78015 int bit = fls(size);
78016
78017@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78018 if (count > totalram_pages)
78019 return NULL;
78020
78021+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78022+ if (!(pgprot_val(prot) & _PAGE_NX))
78023+ flags |= VM_KERNEXEC;
78024+#endif
78025+
78026 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78027 __builtin_return_address(0));
78028 if (!area)
78029@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78030 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78031 goto fail;
78032
78033+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78034+ if (!(pgprot_val(prot) & _PAGE_NX))
78035+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78036+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78037+ else
78038+#endif
78039+
78040 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78041 start, end, node, gfp_mask, caller);
78042 if (!area)
78043@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78044 * For tight control over page level allocator and protection flags
78045 * use __vmalloc() instead.
78046 */
78047-
78048 void *vmalloc_exec(unsigned long size)
78049 {
78050- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78051+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78052 -1, __builtin_return_address(0));
78053 }
78054
78055@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78056 unsigned long uaddr = vma->vm_start;
78057 unsigned long usize = vma->vm_end - vma->vm_start;
78058
78059+ BUG_ON(vma->vm_mirror);
78060+
78061 if ((PAGE_SIZE-1) & (unsigned long)addr)
78062 return -EINVAL;
78063
78064@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78065 v->addr, v->addr + v->size, v->size);
78066
78067 if (v->caller)
78068+#ifdef CONFIG_GRKERNSEC_HIDESYM
78069+ seq_printf(m, " %pK", v->caller);
78070+#else
78071 seq_printf(m, " %pS", v->caller);
78072+#endif
78073
78074 if (v->nr_pages)
78075 seq_printf(m, " pages=%d", v->nr_pages);
78076diff --git a/mm/vmstat.c b/mm/vmstat.c
78077index c737057..a49753a 100644
78078--- a/mm/vmstat.c
78079+++ b/mm/vmstat.c
78080@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78081 *
78082 * vm_stat contains the global counters
78083 */
78084-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78085+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78086 EXPORT_SYMBOL(vm_stat);
78087
78088 #ifdef CONFIG_SMP
78089@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78090 v = p->vm_stat_diff[i];
78091 p->vm_stat_diff[i] = 0;
78092 local_irq_restore(flags);
78093- atomic_long_add(v, &zone->vm_stat[i]);
78094+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78095 global_diff[i] += v;
78096 #ifdef CONFIG_NUMA
78097 /* 3 seconds idle till flush */
78098@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78099
78100 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78101 if (global_diff[i])
78102- atomic_long_add(global_diff[i], &vm_stat[i]);
78103+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78104 }
78105
78106 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78107@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78108 if (pset->vm_stat_diff[i]) {
78109 int v = pset->vm_stat_diff[i];
78110 pset->vm_stat_diff[i] = 0;
78111- atomic_long_add(v, &zone->vm_stat[i]);
78112- atomic_long_add(v, &vm_stat[i]);
78113+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78114+ atomic_long_add_unchecked(v, &vm_stat[i]);
78115 }
78116 }
78117 #endif
78118@@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78119 start_cpu_timer(cpu);
78120 #endif
78121 #ifdef CONFIG_PROC_FS
78122- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78123- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78124- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78125- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78126+ {
78127+ mode_t gr_mode = S_IRUGO;
78128+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78129+ gr_mode = S_IRUSR;
78130+#endif
78131+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78132+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78133+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78134+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78135+#else
78136+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78137+#endif
78138+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78139+ }
78140 #endif
78141 return 0;
78142 }
78143diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78144index ee07072..593e3fd 100644
78145--- a/net/8021q/vlan.c
78146+++ b/net/8021q/vlan.c
78147@@ -484,7 +484,7 @@ out:
78148 return NOTIFY_DONE;
78149 }
78150
78151-static struct notifier_block vlan_notifier_block __read_mostly = {
78152+static struct notifier_block vlan_notifier_block = {
78153 .notifier_call = vlan_device_event,
78154 };
78155
78156@@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78157 err = -EPERM;
78158 if (!capable(CAP_NET_ADMIN))
78159 break;
78160- if ((args.u.name_type >= 0) &&
78161- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78162+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78163 struct vlan_net *vn;
78164
78165 vn = net_generic(net, vlan_net_id);
78166diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78167index 02efb25..41541a9 100644
78168--- a/net/9p/trans_fd.c
78169+++ b/net/9p/trans_fd.c
78170@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78171 oldfs = get_fs();
78172 set_fs(get_ds());
78173 /* The cast to a user pointer is valid due to the set_fs() */
78174- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78175+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78176 set_fs(oldfs);
78177
78178 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78179diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78180index 876fbe8..8bbea9f 100644
78181--- a/net/atm/atm_misc.c
78182+++ b/net/atm/atm_misc.c
78183@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78184 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78185 return 1;
78186 atm_return(vcc, truesize);
78187- atomic_inc(&vcc->stats->rx_drop);
78188+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78189 return 0;
78190 }
78191 EXPORT_SYMBOL(atm_charge);
78192@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78193 }
78194 }
78195 atm_return(vcc, guess);
78196- atomic_inc(&vcc->stats->rx_drop);
78197+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78198 return NULL;
78199 }
78200 EXPORT_SYMBOL(atm_alloc_charge);
78201@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78202
78203 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78204 {
78205-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78206+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78207 __SONET_ITEMS
78208 #undef __HANDLE_ITEM
78209 }
78210@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78211
78212 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78213 {
78214-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78215+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78216 __SONET_ITEMS
78217 #undef __HANDLE_ITEM
78218 }
78219diff --git a/net/atm/lec.h b/net/atm/lec.h
78220index a86aff9..3a0d6f6 100644
78221--- a/net/atm/lec.h
78222+++ b/net/atm/lec.h
78223@@ -48,7 +48,7 @@ struct lane2_ops {
78224 const u8 *tlvs, u32 sizeoftlvs);
78225 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78226 const u8 *tlvs, u32 sizeoftlvs);
78227-};
78228+} __no_const;
78229
78230 /*
78231 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78232diff --git a/net/atm/proc.c b/net/atm/proc.c
78233index 0d020de..011c7bb 100644
78234--- a/net/atm/proc.c
78235+++ b/net/atm/proc.c
78236@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78237 const struct k_atm_aal_stats *stats)
78238 {
78239 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78240- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78241- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78242- atomic_read(&stats->rx_drop));
78243+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78244+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78245+ atomic_read_unchecked(&stats->rx_drop));
78246 }
78247
78248 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78249diff --git a/net/atm/resources.c b/net/atm/resources.c
78250index 0447d5d..3cf4728 100644
78251--- a/net/atm/resources.c
78252+++ b/net/atm/resources.c
78253@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78254 static void copy_aal_stats(struct k_atm_aal_stats *from,
78255 struct atm_aal_stats *to)
78256 {
78257-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78258+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78259 __AAL_STAT_ITEMS
78260 #undef __HANDLE_ITEM
78261 }
78262@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78263 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78264 struct atm_aal_stats *to)
78265 {
78266-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78267+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78268 __AAL_STAT_ITEMS
78269 #undef __HANDLE_ITEM
78270 }
78271diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78272index c6fcc76..1270d14 100644
78273--- a/net/batman-adv/bat_iv_ogm.c
78274+++ b/net/batman-adv/bat_iv_ogm.c
78275@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78276
78277 /* randomize initial seqno to avoid collision */
78278 get_random_bytes(&random_seqno, sizeof(random_seqno));
78279- atomic_set(&hard_iface->seqno, random_seqno);
78280+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78281
78282 hard_iface->packet_len = BATADV_OGM_HLEN;
78283 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78284@@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78285 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78286
78287 /* change sequence number to network order */
78288- seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78289+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78290 batadv_ogm_packet->seqno = htonl(seqno);
78291- atomic_inc(&hard_iface->seqno);
78292+ atomic_inc_unchecked(&hard_iface->seqno);
78293
78294 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78295 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78296@@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78297 return;
78298
78299 /* could be changed by schedule_own_packet() */
78300- if_incoming_seqno = atomic_read(&if_incoming->seqno);
78301+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78302
78303 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78304 has_directlink_flag = 1;
78305diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78306index d112fd6..686a447 100644
78307--- a/net/batman-adv/hard-interface.c
78308+++ b/net/batman-adv/hard-interface.c
78309@@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78310 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78311 dev_add_pack(&hard_iface->batman_adv_ptype);
78312
78313- atomic_set(&hard_iface->frag_seqno, 1);
78314+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78315 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78316 hard_iface->net_dev->name);
78317
78318@@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78319 /* This can't be called via a bat_priv callback because
78320 * we have no bat_priv yet.
78321 */
78322- atomic_set(&hard_iface->seqno, 1);
78323+ atomic_set_unchecked(&hard_iface->seqno, 1);
78324 hard_iface->packet_buff = NULL;
78325
78326 return hard_iface;
78327diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78328index ce0684a..4a0cbf1 100644
78329--- a/net/batman-adv/soft-interface.c
78330+++ b/net/batman-adv/soft-interface.c
78331@@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78332 primary_if->net_dev->dev_addr, ETH_ALEN);
78333
78334 /* set broadcast sequence number */
78335- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78336+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78337 bcast_packet->seqno = htonl(seqno);
78338
78339 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78340@@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78341 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78342
78343 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78344- atomic_set(&bat_priv->bcast_seqno, 1);
78345+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78346 atomic_set(&bat_priv->tt.vn, 0);
78347 atomic_set(&bat_priv->tt.local_changes, 0);
78348 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78349diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78350index ac1e07a..4c846e2 100644
78351--- a/net/batman-adv/types.h
78352+++ b/net/batman-adv/types.h
78353@@ -33,8 +33,8 @@ struct batadv_hard_iface {
78354 int16_t if_num;
78355 char if_status;
78356 struct net_device *net_dev;
78357- atomic_t seqno;
78358- atomic_t frag_seqno;
78359+ atomic_unchecked_t seqno;
78360+ atomic_unchecked_t frag_seqno;
78361 unsigned char *packet_buff;
78362 int packet_len;
78363 struct kobject *hardif_obj;
78364@@ -244,7 +244,7 @@ struct batadv_priv {
78365 atomic_t orig_interval; /* uint */
78366 atomic_t hop_penalty; /* uint */
78367 atomic_t log_level; /* uint */
78368- atomic_t bcast_seqno;
78369+ atomic_unchecked_t bcast_seqno;
78370 atomic_t bcast_queue_left;
78371 atomic_t batman_queue_left;
78372 char num_ifaces;
78373diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78374index f397232..3206a33 100644
78375--- a/net/batman-adv/unicast.c
78376+++ b/net/batman-adv/unicast.c
78377@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78378 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78379 frag2->flags = large_tail;
78380
78381- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78382+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78383 frag1->seqno = htons(seqno - 1);
78384 frag2->seqno = htons(seqno);
78385
78386diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78387index 07f0739..3c42e34 100644
78388--- a/net/bluetooth/hci_sock.c
78389+++ b/net/bluetooth/hci_sock.c
78390@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78391 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78392 }
78393
78394- len = min_t(unsigned int, len, sizeof(uf));
78395+ len = min((size_t)len, sizeof(uf));
78396 if (copy_from_user(&uf, optval, len)) {
78397 err = -EFAULT;
78398 break;
78399diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78400index a91239d..d7ed533 100644
78401--- a/net/bluetooth/l2cap_core.c
78402+++ b/net/bluetooth/l2cap_core.c
78403@@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78404 break;
78405
78406 case L2CAP_CONF_RFC:
78407- if (olen == sizeof(rfc))
78408- memcpy(&rfc, (void *)val, olen);
78409+ if (olen != sizeof(rfc))
78410+ break;
78411+
78412+ memcpy(&rfc, (void *)val, olen);
78413
78414 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78415 rfc.mode != chan->mode)
78416diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78417index 083f2bf..799f9448 100644
78418--- a/net/bluetooth/l2cap_sock.c
78419+++ b/net/bluetooth/l2cap_sock.c
78420@@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78421 struct sock *sk = sock->sk;
78422 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78423 struct l2cap_options opts;
78424- int len, err = 0;
78425+ int err = 0;
78426+ size_t len = optlen;
78427 u32 opt;
78428
78429 BT_DBG("sk %p", sk);
78430@@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78431 opts.max_tx = chan->max_tx;
78432 opts.txwin_size = chan->tx_win;
78433
78434- len = min_t(unsigned int, sizeof(opts), optlen);
78435+ len = min(sizeof(opts), len);
78436 if (copy_from_user((char *) &opts, optval, len)) {
78437 err = -EFAULT;
78438 break;
78439@@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78440 struct bt_security sec;
78441 struct bt_power pwr;
78442 struct l2cap_conn *conn;
78443- int len, err = 0;
78444+ int err = 0;
78445+ size_t len = optlen;
78446 u32 opt;
78447
78448 BT_DBG("sk %p", sk);
78449@@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78450
78451 sec.level = BT_SECURITY_LOW;
78452
78453- len = min_t(unsigned int, sizeof(sec), optlen);
78454+ len = min(sizeof(sec), len);
78455 if (copy_from_user((char *) &sec, optval, len)) {
78456 err = -EFAULT;
78457 break;
78458@@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78459
78460 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78461
78462- len = min_t(unsigned int, sizeof(pwr), optlen);
78463+ len = min(sizeof(pwr), len);
78464 if (copy_from_user((char *) &pwr, optval, len)) {
78465 err = -EFAULT;
78466 break;
78467diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78468index 868a909..d044bc3 100644
78469--- a/net/bluetooth/rfcomm/sock.c
78470+++ b/net/bluetooth/rfcomm/sock.c
78471@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78472 struct sock *sk = sock->sk;
78473 struct bt_security sec;
78474 int err = 0;
78475- size_t len;
78476+ size_t len = optlen;
78477 u32 opt;
78478
78479 BT_DBG("sk %p", sk);
78480@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78481
78482 sec.level = BT_SECURITY_LOW;
78483
78484- len = min_t(unsigned int, sizeof(sec), optlen);
78485+ len = min(sizeof(sec), len);
78486 if (copy_from_user((char *) &sec, optval, len)) {
78487 err = -EFAULT;
78488 break;
78489diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78490index ccc2487..921073d 100644
78491--- a/net/bluetooth/rfcomm/tty.c
78492+++ b/net/bluetooth/rfcomm/tty.c
78493@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78494 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78495
78496 spin_lock_irqsave(&dev->port.lock, flags);
78497- if (dev->port.count > 0) {
78498+ if (atomic_read(&dev->port.count) > 0) {
78499 spin_unlock_irqrestore(&dev->port.lock, flags);
78500 return;
78501 }
78502@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78503 return -ENODEV;
78504
78505 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78506- dev->channel, dev->port.count);
78507+ dev->channel, atomic_read(&dev->port.count));
78508
78509 spin_lock_irqsave(&dev->port.lock, flags);
78510- if (++dev->port.count > 1) {
78511+ if (atomic_inc_return(&dev->port.count) > 1) {
78512 spin_unlock_irqrestore(&dev->port.lock, flags);
78513 return 0;
78514 }
78515@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78516 return;
78517
78518 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78519- dev->port.count);
78520+ atomic_read(&dev->port.count));
78521
78522 spin_lock_irqsave(&dev->port.lock, flags);
78523- if (!--dev->port.count) {
78524+ if (!atomic_dec_return(&dev->port.count)) {
78525 spin_unlock_irqrestore(&dev->port.lock, flags);
78526 if (dev->tty_dev->parent)
78527 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78528diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78529index 5fe2ff3..121d696 100644
78530--- a/net/bridge/netfilter/ebtables.c
78531+++ b/net/bridge/netfilter/ebtables.c
78532@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78533 tmp.valid_hooks = t->table->valid_hooks;
78534 }
78535 mutex_unlock(&ebt_mutex);
78536- if (copy_to_user(user, &tmp, *len) != 0){
78537+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78538 BUGPRINT("c2u Didn't work\n");
78539 ret = -EFAULT;
78540 break;
78541@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78542 goto out;
78543 tmp.valid_hooks = t->valid_hooks;
78544
78545- if (copy_to_user(user, &tmp, *len) != 0) {
78546+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78547 ret = -EFAULT;
78548 break;
78549 }
78550@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78551 tmp.entries_size = t->table->entries_size;
78552 tmp.valid_hooks = t->table->valid_hooks;
78553
78554- if (copy_to_user(user, &tmp, *len) != 0) {
78555+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78556 ret = -EFAULT;
78557 break;
78558 }
78559diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78560index 44f270f..1f5602d 100644
78561--- a/net/caif/cfctrl.c
78562+++ b/net/caif/cfctrl.c
78563@@ -10,6 +10,7 @@
78564 #include <linux/spinlock.h>
78565 #include <linux/slab.h>
78566 #include <linux/pkt_sched.h>
78567+#include <linux/sched.h>
78568 #include <net/caif/caif_layer.h>
78569 #include <net/caif/cfpkt.h>
78570 #include <net/caif/cfctrl.h>
78571@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78572 memset(&dev_info, 0, sizeof(dev_info));
78573 dev_info.id = 0xff;
78574 cfsrvl_init(&this->serv, 0, &dev_info, false);
78575- atomic_set(&this->req_seq_no, 1);
78576- atomic_set(&this->rsp_seq_no, 1);
78577+ atomic_set_unchecked(&this->req_seq_no, 1);
78578+ atomic_set_unchecked(&this->rsp_seq_no, 1);
78579 this->serv.layer.receive = cfctrl_recv;
78580 sprintf(this->serv.layer.name, "ctrl");
78581 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78582@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78583 struct cfctrl_request_info *req)
78584 {
78585 spin_lock_bh(&ctrl->info_list_lock);
78586- atomic_inc(&ctrl->req_seq_no);
78587- req->sequence_no = atomic_read(&ctrl->req_seq_no);
78588+ atomic_inc_unchecked(&ctrl->req_seq_no);
78589+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78590 list_add_tail(&req->list, &ctrl->list);
78591 spin_unlock_bh(&ctrl->info_list_lock);
78592 }
78593@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78594 if (p != first)
78595 pr_warn("Requests are not received in order\n");
78596
78597- atomic_set(&ctrl->rsp_seq_no,
78598+ atomic_set_unchecked(&ctrl->rsp_seq_no,
78599 p->sequence_no);
78600 list_del(&p->list);
78601 goto out;
78602diff --git a/net/can/af_can.c b/net/can/af_can.c
78603index ddac1ee..3ee0a78 100644
78604--- a/net/can/af_can.c
78605+++ b/net/can/af_can.c
78606@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78607 };
78608
78609 /* notifier block for netdevice event */
78610-static struct notifier_block can_netdev_notifier __read_mostly = {
78611+static struct notifier_block can_netdev_notifier = {
78612 .notifier_call = can_notifier,
78613 };
78614
78615diff --git a/net/can/gw.c b/net/can/gw.c
78616index 1f5c978..ef714c7 100644
78617--- a/net/can/gw.c
78618+++ b/net/can/gw.c
78619@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78620 MODULE_ALIAS("can-gw");
78621
78622 static HLIST_HEAD(cgw_list);
78623-static struct notifier_block notifier;
78624
78625 static struct kmem_cache *cgw_cache __read_mostly;
78626
78627@@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78628 return err;
78629 }
78630
78631+static struct notifier_block notifier = {
78632+ .notifier_call = cgw_notifier
78633+};
78634+
78635 static __init int cgw_module_init(void)
78636 {
78637 printk(banner);
78638@@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78639 return -ENOMEM;
78640
78641 /* set notifier */
78642- notifier.notifier_call = cgw_notifier;
78643 register_netdevice_notifier(&notifier);
78644
78645 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78646diff --git a/net/compat.c b/net/compat.c
78647index 79ae884..17c5c09 100644
78648--- a/net/compat.c
78649+++ b/net/compat.c
78650@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78651 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78652 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78653 return -EFAULT;
78654- kmsg->msg_name = compat_ptr(tmp1);
78655- kmsg->msg_iov = compat_ptr(tmp2);
78656- kmsg->msg_control = compat_ptr(tmp3);
78657+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78658+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78659+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78660 return 0;
78661 }
78662
78663@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78664
78665 if (kern_msg->msg_namelen) {
78666 if (mode == VERIFY_READ) {
78667- int err = move_addr_to_kernel(kern_msg->msg_name,
78668+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78669 kern_msg->msg_namelen,
78670 kern_address);
78671 if (err < 0)
78672@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78673 kern_msg->msg_name = NULL;
78674
78675 tot_len = iov_from_user_compat_to_kern(kern_iov,
78676- (struct compat_iovec __user *)kern_msg->msg_iov,
78677+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
78678 kern_msg->msg_iovlen);
78679 if (tot_len >= 0)
78680 kern_msg->msg_iov = kern_iov;
78681@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78682
78683 #define CMSG_COMPAT_FIRSTHDR(msg) \
78684 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78685- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78686+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78687 (struct compat_cmsghdr __user *)NULL)
78688
78689 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78690 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78691 (ucmlen) <= (unsigned long) \
78692 ((mhdr)->msg_controllen - \
78693- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78694+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78695
78696 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78697 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78698 {
78699 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78700- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78701+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78702 msg->msg_controllen)
78703 return NULL;
78704 return (struct compat_cmsghdr __user *)ptr;
78705@@ -219,7 +219,7 @@ Efault:
78706
78707 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78708 {
78709- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78710+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78711 struct compat_cmsghdr cmhdr;
78712 struct compat_timeval ctv;
78713 struct compat_timespec cts[3];
78714@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78715
78716 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
78717 {
78718- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78719+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78720 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78721 int fdnum = scm->fp->count;
78722 struct file **fp = scm->fp->fp;
78723@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78724 return -EFAULT;
78725 old_fs = get_fs();
78726 set_fs(KERNEL_DS);
78727- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78728+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78729 set_fs(old_fs);
78730
78731 return err;
78732@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78733 len = sizeof(ktime);
78734 old_fs = get_fs();
78735 set_fs(KERNEL_DS);
78736- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
78737+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
78738 set_fs(old_fs);
78739
78740 if (!err) {
78741@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78742 case MCAST_JOIN_GROUP:
78743 case MCAST_LEAVE_GROUP:
78744 {
78745- struct compat_group_req __user *gr32 = (void *)optval;
78746+ struct compat_group_req __user *gr32 = (void __user *)optval;
78747 struct group_req __user *kgr =
78748 compat_alloc_user_space(sizeof(struct group_req));
78749 u32 interface;
78750@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78751 case MCAST_BLOCK_SOURCE:
78752 case MCAST_UNBLOCK_SOURCE:
78753 {
78754- struct compat_group_source_req __user *gsr32 = (void *)optval;
78755+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
78756 struct group_source_req __user *kgsr = compat_alloc_user_space(
78757 sizeof(struct group_source_req));
78758 u32 interface;
78759@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78760 }
78761 case MCAST_MSFILTER:
78762 {
78763- struct compat_group_filter __user *gf32 = (void *)optval;
78764+ struct compat_group_filter __user *gf32 = (void __user *)optval;
78765 struct group_filter __user *kgf;
78766 u32 interface, fmode, numsrc;
78767
78768@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
78769 char __user *optval, int __user *optlen,
78770 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
78771 {
78772- struct compat_group_filter __user *gf32 = (void *)optval;
78773+ struct compat_group_filter __user *gf32 = (void __user *)optval;
78774 struct group_filter __user *kgf;
78775 int __user *koptlen;
78776 u32 interface, fmode, numsrc;
78777@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
78778
78779 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
78780 return -EINVAL;
78781- if (copy_from_user(a, args, nas[call]))
78782+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
78783 return -EFAULT;
78784 a0 = a[0];
78785 a1 = a[1];
78786diff --git a/net/core/datagram.c b/net/core/datagram.c
78787index 0337e2b..f82d4a3 100644
78788--- a/net/core/datagram.c
78789+++ b/net/core/datagram.c
78790@@ -187,7 +187,7 @@ struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned int flags,
78791 skb_queue_walk(queue, skb) {
78792 *peeked = skb->peeked;
78793 if (flags & MSG_PEEK) {
78794- if (*off >= skb->len) {
78795+ if (*off >= skb->len && skb->len) {
78796 *off -= skb->len;
78797 continue;
78798 }
78799@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
78800 }
78801
78802 kfree_skb(skb);
78803- atomic_inc(&sk->sk_drops);
78804+ atomic_inc_unchecked(&sk->sk_drops);
78805 sk_mem_reclaim_partial(sk);
78806
78807 return err;
78808diff --git a/net/core/dev.c b/net/core/dev.c
78809index 3470794..eb5008c 100644
78810--- a/net/core/dev.c
78811+++ b/net/core/dev.c
78812@@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
78813 if (no_module && capable(CAP_NET_ADMIN))
78814 no_module = request_module("netdev-%s", name);
78815 if (no_module && capable(CAP_SYS_MODULE)) {
78816+#ifdef CONFIG_GRKERNSEC_MODHARDEN
78817+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
78818+#else
78819 if (!request_module("%s", name))
78820 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
78821 name);
78822+#endif
78823 }
78824 }
78825 EXPORT_SYMBOL(dev_load);
78826@@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78827 {
78828 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
78829 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
78830- atomic_long_inc(&dev->rx_dropped);
78831+ atomic_long_inc_unchecked(&dev->rx_dropped);
78832 kfree_skb(skb);
78833 return NET_RX_DROP;
78834 }
78835@@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78836 nf_reset(skb);
78837
78838 if (unlikely(!is_skb_forwardable(dev, skb))) {
78839- atomic_long_inc(&dev->rx_dropped);
78840+ atomic_long_inc_unchecked(&dev->rx_dropped);
78841 kfree_skb(skb);
78842 return NET_RX_DROP;
78843 }
78844@@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
78845
78846 struct dev_gso_cb {
78847 void (*destructor)(struct sk_buff *skb);
78848-};
78849+} __no_const;
78850
78851 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
78852
78853@@ -2955,7 +2959,7 @@ enqueue:
78854
78855 local_irq_restore(flags);
78856
78857- atomic_long_inc(&skb->dev->rx_dropped);
78858+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78859 kfree_skb(skb);
78860 return NET_RX_DROP;
78861 }
78862@@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
78863 }
78864 EXPORT_SYMBOL(netif_rx_ni);
78865
78866-static void net_tx_action(struct softirq_action *h)
78867+static void net_tx_action(void)
78868 {
78869 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78870
78871@@ -3358,7 +3362,7 @@ ncls:
78872 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
78873 } else {
78874 drop:
78875- atomic_long_inc(&skb->dev->rx_dropped);
78876+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78877 kfree_skb(skb);
78878 /* Jamal, now you will not able to escape explaining
78879 * me how you were going to use this. :-)
78880@@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
78881 }
78882 EXPORT_SYMBOL(netif_napi_del);
78883
78884-static void net_rx_action(struct softirq_action *h)
78885+static void net_rx_action(void)
78886 {
78887 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78888 unsigned long time_limit = jiffies + 2;
78889@@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
78890 else
78891 seq_printf(seq, "%04x", ntohs(pt->type));
78892
78893+#ifdef CONFIG_GRKERNSEC_HIDESYM
78894+ seq_printf(seq, " %-8s %p\n",
78895+ pt->dev ? pt->dev->name : "", NULL);
78896+#else
78897 seq_printf(seq, " %-8s %pF\n",
78898 pt->dev ? pt->dev->name : "", pt->func);
78899+#endif
78900 }
78901
78902 return 0;
78903@@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
78904 } else {
78905 netdev_stats_to_stats64(storage, &dev->stats);
78906 }
78907- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
78908+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
78909 return storage;
78910 }
78911 EXPORT_SYMBOL(dev_get_stats);
78912diff --git a/net/core/flow.c b/net/core/flow.c
78913index e318c7e..168b1d0 100644
78914--- a/net/core/flow.c
78915+++ b/net/core/flow.c
78916@@ -61,7 +61,7 @@ struct flow_cache {
78917 struct timer_list rnd_timer;
78918 };
78919
78920-atomic_t flow_cache_genid = ATOMIC_INIT(0);
78921+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
78922 EXPORT_SYMBOL(flow_cache_genid);
78923 static struct flow_cache flow_cache_global;
78924 static struct kmem_cache *flow_cachep __read_mostly;
78925@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
78926
78927 static int flow_entry_valid(struct flow_cache_entry *fle)
78928 {
78929- if (atomic_read(&flow_cache_genid) != fle->genid)
78930+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
78931 return 0;
78932 if (fle->object && !fle->object->ops->check(fle->object))
78933 return 0;
78934@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
78935 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
78936 fcp->hash_count++;
78937 }
78938- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
78939+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
78940 flo = fle->object;
78941 if (!flo)
78942 goto ret_object;
78943@@ -280,7 +280,7 @@ nocache:
78944 }
78945 flo = resolver(net, key, family, dir, flo, ctx);
78946 if (fle) {
78947- fle->genid = atomic_read(&flow_cache_genid);
78948+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
78949 if (!IS_ERR(flo))
78950 fle->object = flo;
78951 else
78952diff --git a/net/core/iovec.c b/net/core/iovec.c
78953index 7e7aeb0..2a998cb 100644
78954--- a/net/core/iovec.c
78955+++ b/net/core/iovec.c
78956@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78957 if (m->msg_namelen) {
78958 if (mode == VERIFY_READ) {
78959 void __user *namep;
78960- namep = (void __user __force *) m->msg_name;
78961+ namep = (void __force_user *) m->msg_name;
78962 err = move_addr_to_kernel(namep, m->msg_namelen,
78963 address);
78964 if (err < 0)
78965@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78966 }
78967
78968 size = m->msg_iovlen * sizeof(struct iovec);
78969- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
78970+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
78971 return -EFAULT;
78972
78973 m->msg_iov = iov;
78974diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
78975index fad649a..df5891e 100644
78976--- a/net/core/rtnetlink.c
78977+++ b/net/core/rtnetlink.c
78978@@ -58,7 +58,7 @@ struct rtnl_link {
78979 rtnl_doit_func doit;
78980 rtnl_dumpit_func dumpit;
78981 rtnl_calcit_func calcit;
78982-};
78983+} __no_const;
78984
78985 static DEFINE_MUTEX(rtnl_mutex);
78986
78987diff --git a/net/core/scm.c b/net/core/scm.c
78988index ab57084..0190c8f 100644
78989--- a/net/core/scm.c
78990+++ b/net/core/scm.c
78991@@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
78992 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
78993 {
78994 struct cmsghdr __user *cm
78995- = (__force struct cmsghdr __user *)msg->msg_control;
78996+ = (struct cmsghdr __force_user *)msg->msg_control;
78997 struct cmsghdr cmhdr;
78998 int cmlen = CMSG_LEN(len);
78999 int err;
79000@@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79001 err = -EFAULT;
79002 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79003 goto out;
79004- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79005+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79006 goto out;
79007 cmlen = CMSG_SPACE(len);
79008 if (msg->msg_controllen < cmlen)
79009@@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79010 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79011 {
79012 struct cmsghdr __user *cm
79013- = (__force struct cmsghdr __user*)msg->msg_control;
79014+ = (struct cmsghdr __force_user *)msg->msg_control;
79015
79016 int fdmax = 0;
79017 int fdnum = scm->fp->count;
79018@@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79019 if (fdnum < fdmax)
79020 fdmax = fdnum;
79021
79022- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79023+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79024 i++, cmfptr++)
79025 {
79026 struct socket *sock;
79027diff --git a/net/core/sock.c b/net/core/sock.c
79028index 8a146cf..ee08914d 100644
79029--- a/net/core/sock.c
79030+++ b/net/core/sock.c
79031@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79032 struct sk_buff_head *list = &sk->sk_receive_queue;
79033
79034 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79035- atomic_inc(&sk->sk_drops);
79036+ atomic_inc_unchecked(&sk->sk_drops);
79037 trace_sock_rcvqueue_full(sk, skb);
79038 return -ENOMEM;
79039 }
79040@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79041 return err;
79042
79043 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79044- atomic_inc(&sk->sk_drops);
79045+ atomic_inc_unchecked(&sk->sk_drops);
79046 return -ENOBUFS;
79047 }
79048
79049@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79050 skb_dst_force(skb);
79051
79052 spin_lock_irqsave(&list->lock, flags);
79053- skb->dropcount = atomic_read(&sk->sk_drops);
79054+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79055 __skb_queue_tail(list, skb);
79056 spin_unlock_irqrestore(&list->lock, flags);
79057
79058@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79059 skb->dev = NULL;
79060
79061 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79062- atomic_inc(&sk->sk_drops);
79063+ atomic_inc_unchecked(&sk->sk_drops);
79064 goto discard_and_relse;
79065 }
79066 if (nested)
79067@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79068 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79069 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79070 bh_unlock_sock(sk);
79071- atomic_inc(&sk->sk_drops);
79072+ atomic_inc_unchecked(&sk->sk_drops);
79073 goto discard_and_relse;
79074 }
79075
79076@@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79077 struct timeval tm;
79078 } v;
79079
79080- int lv = sizeof(int);
79081- int len;
79082+ unsigned int lv = sizeof(int);
79083+ unsigned int len;
79084
79085 if (get_user(len, optlen))
79086 return -EFAULT;
79087- if (len < 0)
79088+ if (len > INT_MAX)
79089 return -EINVAL;
79090
79091 memset(&v, 0, sizeof(v));
79092@@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79093
79094 case SO_PEERNAME:
79095 {
79096- char address[128];
79097+ char address[_K_SS_MAXSIZE];
79098
79099 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79100 return -ENOTCONN;
79101- if (lv < len)
79102+ if (lv < len || sizeof address < len)
79103 return -EINVAL;
79104 if (copy_to_user(optval, address, len))
79105 return -EFAULT;
79106@@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79107
79108 if (len > lv)
79109 len = lv;
79110- if (copy_to_user(optval, &v, len))
79111+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
79112 return -EFAULT;
79113 lenout:
79114 if (put_user(len, optlen))
79115@@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79116 */
79117 smp_wmb();
79118 atomic_set(&sk->sk_refcnt, 1);
79119- atomic_set(&sk->sk_drops, 0);
79120+ atomic_set_unchecked(&sk->sk_drops, 0);
79121 }
79122 EXPORT_SYMBOL(sock_init_data);
79123
79124diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79125index 602cd63..05c6c60 100644
79126--- a/net/core/sock_diag.c
79127+++ b/net/core/sock_diag.c
79128@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79129
79130 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79131 {
79132+#ifndef CONFIG_GRKERNSEC_HIDESYM
79133 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79134 cookie[1] != INET_DIAG_NOCOOKIE) &&
79135 ((u32)(unsigned long)sk != cookie[0] ||
79136 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79137 return -ESTALE;
79138 else
79139+#endif
79140 return 0;
79141 }
79142 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79143
79144 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79145 {
79146+#ifdef CONFIG_GRKERNSEC_HIDESYM
79147+ cookie[0] = 0;
79148+ cookie[1] = 0;
79149+#else
79150 cookie[0] = (u32)(unsigned long)sk;
79151 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79152+#endif
79153 }
79154 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79155
79156diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79157index a55eecc..dd8428c 100644
79158--- a/net/decnet/sysctl_net_decnet.c
79159+++ b/net/decnet/sysctl_net_decnet.c
79160@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79161
79162 if (len > *lenp) len = *lenp;
79163
79164- if (copy_to_user(buffer, addr, len))
79165+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79166 return -EFAULT;
79167
79168 *lenp = len;
79169@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79170
79171 if (len > *lenp) len = *lenp;
79172
79173- if (copy_to_user(buffer, devname, len))
79174+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79175 return -EFAULT;
79176
79177 *lenp = len;
79178diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79179index 2a6abc1..c379ba7 100644
79180--- a/net/ipv4/devinet.c
79181+++ b/net/ipv4/devinet.c
79182@@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79183 if (!ifa) {
79184 ret = -ENOBUFS;
79185 ifa = inet_alloc_ifa();
79186+ if (!ifa)
79187+ break;
79188 INIT_HLIST_NODE(&ifa->hash);
79189- if (!ifa)
79190- break;
79191 if (colon)
79192 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79193 else
79194diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79195index 825c608..750ff29 100644
79196--- a/net/ipv4/fib_frontend.c
79197+++ b/net/ipv4/fib_frontend.c
79198@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79199 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79200 fib_sync_up(dev);
79201 #endif
79202- atomic_inc(&net->ipv4.dev_addr_genid);
79203+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79204 rt_cache_flush(dev_net(dev));
79205 break;
79206 case NETDEV_DOWN:
79207 fib_del_ifaddr(ifa, NULL);
79208- atomic_inc(&net->ipv4.dev_addr_genid);
79209+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79210 if (ifa->ifa_dev->ifa_list == NULL) {
79211 /* Last address was deleted from this interface.
79212 * Disable IP.
79213@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79214 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79215 fib_sync_up(dev);
79216 #endif
79217- atomic_inc(&net->ipv4.dev_addr_genid);
79218+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79219 rt_cache_flush(net);
79220 break;
79221 case NETDEV_DOWN:
79222diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79223index 71b125c..f4c70b0 100644
79224--- a/net/ipv4/fib_semantics.c
79225+++ b/net/ipv4/fib_semantics.c
79226@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79227 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79228 nh->nh_gw,
79229 nh->nh_parent->fib_scope);
79230- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79231+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79232
79233 return nh->nh_saddr;
79234 }
79235diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79236index 7880af9..70f92a3 100644
79237--- a/net/ipv4/inet_hashtables.c
79238+++ b/net/ipv4/inet_hashtables.c
79239@@ -18,12 +18,15 @@
79240 #include <linux/sched.h>
79241 #include <linux/slab.h>
79242 #include <linux/wait.h>
79243+#include <linux/security.h>
79244
79245 #include <net/inet_connection_sock.h>
79246 #include <net/inet_hashtables.h>
79247 #include <net/secure_seq.h>
79248 #include <net/ip.h>
79249
79250+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79251+
79252 /*
79253 * Allocate and initialize a new local port bind bucket.
79254 * The bindhash mutex for snum's hash chain must be held here.
79255@@ -530,6 +533,8 @@ ok:
79256 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79257 spin_unlock(&head->lock);
79258
79259+ gr_update_task_in_ip_table(current, inet_sk(sk));
79260+
79261 if (tw) {
79262 inet_twsk_deschedule(tw, death_row);
79263 while (twrefcnt) {
79264diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79265index 000e3d2..5472da3 100644
79266--- a/net/ipv4/inetpeer.c
79267+++ b/net/ipv4/inetpeer.c
79268@@ -503,8 +503,8 @@ relookup:
79269 if (p) {
79270 p->daddr = *daddr;
79271 atomic_set(&p->refcnt, 1);
79272- atomic_set(&p->rid, 0);
79273- atomic_set(&p->ip_id_count,
79274+ atomic_set_unchecked(&p->rid, 0);
79275+ atomic_set_unchecked(&p->ip_id_count,
79276 (daddr->family == AF_INET) ?
79277 secure_ip_id(daddr->addr.a4) :
79278 secure_ipv6_id(daddr->addr.a6));
79279diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79280index 8d5cc75..821fd11 100644
79281--- a/net/ipv4/ip_fragment.c
79282+++ b/net/ipv4/ip_fragment.c
79283@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79284 return 0;
79285
79286 start = qp->rid;
79287- end = atomic_inc_return(&peer->rid);
79288+ end = atomic_inc_return_unchecked(&peer->rid);
79289 qp->rid = end;
79290
79291 rc = qp->q.fragments && (end - start) > max;
79292diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79293index e95d72b..5268ac0 100644
79294--- a/net/ipv4/ip_sockglue.c
79295+++ b/net/ipv4/ip_sockglue.c
79296@@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79297 len = min_t(unsigned int, len, opt->optlen);
79298 if (put_user(len, optlen))
79299 return -EFAULT;
79300- if (copy_to_user(optval, opt->__data, len))
79301+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79302+ copy_to_user(optval, opt->__data, len))
79303 return -EFAULT;
79304 return 0;
79305 }
79306@@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79307 if (sk->sk_type != SOCK_STREAM)
79308 return -ENOPROTOOPT;
79309
79310- msg.msg_control = optval;
79311+ msg.msg_control = (void __force_kernel *)optval;
79312 msg.msg_controllen = len;
79313 msg.msg_flags = flags;
79314
79315diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79316index 798358b..73570b7 100644
79317--- a/net/ipv4/ipconfig.c
79318+++ b/net/ipv4/ipconfig.c
79319@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79320
79321 mm_segment_t oldfs = get_fs();
79322 set_fs(get_ds());
79323- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79324+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79325 set_fs(oldfs);
79326 return res;
79327 }
79328@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79329
79330 mm_segment_t oldfs = get_fs();
79331 set_fs(get_ds());
79332- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79333+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79334 set_fs(oldfs);
79335 return res;
79336 }
79337@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79338
79339 mm_segment_t oldfs = get_fs();
79340 set_fs(get_ds());
79341- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79342+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79343 set_fs(oldfs);
79344 return res;
79345 }
79346diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79347index 97e61ea..cac1bbb 100644
79348--- a/net/ipv4/netfilter/arp_tables.c
79349+++ b/net/ipv4/netfilter/arp_tables.c
79350@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79351 #endif
79352
79353 static int get_info(struct net *net, void __user *user,
79354- const int *len, int compat)
79355+ int len, int compat)
79356 {
79357 char name[XT_TABLE_MAXNAMELEN];
79358 struct xt_table *t;
79359 int ret;
79360
79361- if (*len != sizeof(struct arpt_getinfo)) {
79362- duprintf("length %u != %Zu\n", *len,
79363+ if (len != sizeof(struct arpt_getinfo)) {
79364+ duprintf("length %u != %Zu\n", len,
79365 sizeof(struct arpt_getinfo));
79366 return -EINVAL;
79367 }
79368@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79369 info.size = private->size;
79370 strcpy(info.name, name);
79371
79372- if (copy_to_user(user, &info, *len) != 0)
79373+ if (copy_to_user(user, &info, len) != 0)
79374 ret = -EFAULT;
79375 else
79376 ret = 0;
79377@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79378
79379 switch (cmd) {
79380 case ARPT_SO_GET_INFO:
79381- ret = get_info(sock_net(sk), user, len, 1);
79382+ ret = get_info(sock_net(sk), user, *len, 1);
79383 break;
79384 case ARPT_SO_GET_ENTRIES:
79385 ret = compat_get_entries(sock_net(sk), user, len);
79386@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79387
79388 switch (cmd) {
79389 case ARPT_SO_GET_INFO:
79390- ret = get_info(sock_net(sk), user, len, 0);
79391+ ret = get_info(sock_net(sk), user, *len, 0);
79392 break;
79393
79394 case ARPT_SO_GET_ENTRIES:
79395diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79396index 170b1fd..6105b91 100644
79397--- a/net/ipv4/netfilter/ip_tables.c
79398+++ b/net/ipv4/netfilter/ip_tables.c
79399@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79400 #endif
79401
79402 static int get_info(struct net *net, void __user *user,
79403- const int *len, int compat)
79404+ int len, int compat)
79405 {
79406 char name[XT_TABLE_MAXNAMELEN];
79407 struct xt_table *t;
79408 int ret;
79409
79410- if (*len != sizeof(struct ipt_getinfo)) {
79411- duprintf("length %u != %zu\n", *len,
79412+ if (len != sizeof(struct ipt_getinfo)) {
79413+ duprintf("length %u != %zu\n", len,
79414 sizeof(struct ipt_getinfo));
79415 return -EINVAL;
79416 }
79417@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79418 info.size = private->size;
79419 strcpy(info.name, name);
79420
79421- if (copy_to_user(user, &info, *len) != 0)
79422+ if (copy_to_user(user, &info, len) != 0)
79423 ret = -EFAULT;
79424 else
79425 ret = 0;
79426@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79427
79428 switch (cmd) {
79429 case IPT_SO_GET_INFO:
79430- ret = get_info(sock_net(sk), user, len, 1);
79431+ ret = get_info(sock_net(sk), user, *len, 1);
79432 break;
79433 case IPT_SO_GET_ENTRIES:
79434 ret = compat_get_entries(sock_net(sk), user, len);
79435@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79436
79437 switch (cmd) {
79438 case IPT_SO_GET_INFO:
79439- ret = get_info(sock_net(sk), user, len, 0);
79440+ ret = get_info(sock_net(sk), user, *len, 0);
79441 break;
79442
79443 case IPT_SO_GET_ENTRIES:
79444diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79445index 6f9c072..38ea6c6 100644
79446--- a/net/ipv4/ping.c
79447+++ b/net/ipv4/ping.c
79448@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79449 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79450 0, sock_i_ino(sp),
79451 atomic_read(&sp->sk_refcnt), sp,
79452- atomic_read(&sp->sk_drops), len);
79453+ atomic_read_unchecked(&sp->sk_drops), len);
79454 }
79455
79456 static int ping_seq_show(struct seq_file *seq, void *v)
79457diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79458index 6f08991..55867ad 100644
79459--- a/net/ipv4/raw.c
79460+++ b/net/ipv4/raw.c
79461@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79462 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79463 {
79464 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79465- atomic_inc(&sk->sk_drops);
79466+ atomic_inc_unchecked(&sk->sk_drops);
79467 kfree_skb(skb);
79468 return NET_RX_DROP;
79469 }
79470@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79471
79472 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79473 {
79474+ struct icmp_filter filter;
79475+
79476 if (optlen > sizeof(struct icmp_filter))
79477 optlen = sizeof(struct icmp_filter);
79478- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79479+ if (copy_from_user(&filter, optval, optlen))
79480 return -EFAULT;
79481+ raw_sk(sk)->filter = filter;
79482 return 0;
79483 }
79484
79485 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79486 {
79487 int len, ret = -EFAULT;
79488+ struct icmp_filter filter;
79489
79490 if (get_user(len, optlen))
79491 goto out;
79492@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79493 if (len > sizeof(struct icmp_filter))
79494 len = sizeof(struct icmp_filter);
79495 ret = -EFAULT;
79496- if (put_user(len, optlen) ||
79497- copy_to_user(optval, &raw_sk(sk)->filter, len))
79498+ filter = raw_sk(sk)->filter;
79499+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79500 goto out;
79501 ret = 0;
79502 out: return ret;
79503@@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79504 0, 0L, 0,
79505 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79506 0, sock_i_ino(sp),
79507- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79508+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79509 }
79510
79511 static int raw_seq_show(struct seq_file *seq, void *v)
79512diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79513index 0fdfe4c..e7ea542 100644
79514--- a/net/ipv4/route.c
79515+++ b/net/ipv4/route.c
79516@@ -2579,7 +2579,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79517
79518 static __net_init int rt_genid_init(struct net *net)
79519 {
79520- atomic_set(&net->rt_genid, 0);
79521+ atomic_set_unchecked(&net->rt_genid, 0);
79522 get_random_bytes(&net->ipv4.dev_addr_genid,
79523 sizeof(net->ipv4.dev_addr_genid));
79524 return 0;
79525diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79526index beabc80..48a6a10 100644
79527--- a/net/ipv4/tcp_input.c
79528+++ b/net/ipv4/tcp_input.c
79529@@ -4709,7 +4709,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79530 * simplifies code)
79531 */
79532 static void
79533-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79534+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79535 struct sk_buff *head, struct sk_buff *tail,
79536 u32 start, u32 end)
79537 {
79538@@ -5541,6 +5541,9 @@ slow_path:
79539 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79540 goto csum_error;
79541
79542+ if (!th->ack)
79543+ goto discard;
79544+
79545 /*
79546 * Standard slow path.
79547 */
79548@@ -5549,7 +5552,7 @@ slow_path:
79549 return 0;
79550
79551 step5:
79552- if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79553+ if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79554 goto discard;
79555
79556 /* ts_recent update must be made after we are sure that the packet
79557@@ -5840,6 +5843,7 @@ discard:
79558 tcp_paws_reject(&tp->rx_opt, 0))
79559 goto discard_and_undo;
79560
79561+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79562 if (th->syn) {
79563 /* We see SYN without ACK. It is attempt of
79564 * simultaneous connect with crossed SYNs.
79565@@ -5890,6 +5894,7 @@ discard:
79566 goto discard;
79567 #endif
79568 }
79569+#endif
79570 /* "fifth, if neither of the SYN or RST bits is set then
79571 * drop the segment and return."
79572 */
79573@@ -5934,7 +5939,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79574 goto discard;
79575
79576 if (th->syn) {
79577- if (th->fin)
79578+ if (th->fin || th->urg || th->psh)
79579 goto discard;
79580 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79581 return 1;
79582@@ -5981,11 +5986,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79583 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79584 goto discard;
79585 }
79586+
79587+ if (!th->ack)
79588+ goto discard;
79589+
79590 if (!tcp_validate_incoming(sk, skb, th, 0))
79591 return 0;
79592
79593 /* step 5: check the ACK field */
79594- if (th->ack) {
79595+ if (true) {
79596 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79597
79598 switch (sk->sk_state) {
79599@@ -6135,8 +6144,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79600 }
79601 break;
79602 }
79603- } else
79604- goto discard;
79605+ }
79606
79607 /* ts_recent update must be made after we are sure that the packet
79608 * is in window.
79609diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79610index e637770..364ff02 100644
79611--- a/net/ipv4/tcp_ipv4.c
79612+++ b/net/ipv4/tcp_ipv4.c
79613@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79614 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79615
79616
79617+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79618+extern int grsec_enable_blackhole;
79619+#endif
79620+
79621 #ifdef CONFIG_TCP_MD5SIG
79622 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79623 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79624@@ -1898,6 +1902,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79625 return 0;
79626
79627 reset:
79628+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79629+ if (!grsec_enable_blackhole)
79630+#endif
79631 tcp_v4_send_reset(rsk, skb);
79632 discard:
79633 kfree_skb(skb);
79634@@ -1998,12 +2005,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79635 TCP_SKB_CB(skb)->sacked = 0;
79636
79637 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79638- if (!sk)
79639+ if (!sk) {
79640+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79641+ ret = 1;
79642+#endif
79643 goto no_tcp_socket;
79644-
79645+ }
79646 process:
79647- if (sk->sk_state == TCP_TIME_WAIT)
79648+ if (sk->sk_state == TCP_TIME_WAIT) {
79649+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79650+ ret = 2;
79651+#endif
79652 goto do_time_wait;
79653+ }
79654
79655 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79656 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79657@@ -2054,6 +2068,10 @@ no_tcp_socket:
79658 bad_packet:
79659 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79660 } else {
79661+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79662+ if (!grsec_enable_blackhole || (ret == 1 &&
79663+ (skb->dev->flags & IFF_LOOPBACK)))
79664+#endif
79665 tcp_v4_send_reset(NULL, skb);
79666 }
79667
79668diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79669index a7302d9..e3ec754 100644
79670--- a/net/ipv4/tcp_minisocks.c
79671+++ b/net/ipv4/tcp_minisocks.c
79672@@ -27,6 +27,10 @@
79673 #include <net/inet_common.h>
79674 #include <net/xfrm.h>
79675
79676+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79677+extern int grsec_enable_blackhole;
79678+#endif
79679+
79680 int sysctl_tcp_syncookies __read_mostly = 1;
79681 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79682
79683@@ -742,7 +746,10 @@ embryonic_reset:
79684 * avoid becoming vulnerable to outside attack aiming at
79685 * resetting legit local connections.
79686 */
79687- req->rsk_ops->send_reset(sk, skb);
79688+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79689+ if (!grsec_enable_blackhole)
79690+#endif
79691+ req->rsk_ops->send_reset(sk, skb);
79692 } else if (fastopen) { /* received a valid RST pkt */
79693 reqsk_fastopen_remove(sk, req, true);
79694 tcp_reset(sk);
79695diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79696index 4526fe6..1a34e43 100644
79697--- a/net/ipv4/tcp_probe.c
79698+++ b/net/ipv4/tcp_probe.c
79699@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79700 if (cnt + width >= len)
79701 break;
79702
79703- if (copy_to_user(buf + cnt, tbuf, width))
79704+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79705 return -EFAULT;
79706 cnt += width;
79707 }
79708diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79709index d47c1b4..b0584de 100644
79710--- a/net/ipv4/tcp_timer.c
79711+++ b/net/ipv4/tcp_timer.c
79712@@ -22,6 +22,10 @@
79713 #include <linux/gfp.h>
79714 #include <net/tcp.h>
79715
79716+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79717+extern int grsec_lastack_retries;
79718+#endif
79719+
79720 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
79721 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
79722 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
79723@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
79724 }
79725 }
79726
79727+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79728+ if ((sk->sk_state == TCP_LAST_ACK) &&
79729+ (grsec_lastack_retries > 0) &&
79730+ (grsec_lastack_retries < retry_until))
79731+ retry_until = grsec_lastack_retries;
79732+#endif
79733+
79734 if (retransmits_timed_out(sk, retry_until,
79735 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
79736 /* Has it gone just too far? */
79737diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
79738index 1f4d405..3524677 100644
79739--- a/net/ipv4/udp.c
79740+++ b/net/ipv4/udp.c
79741@@ -87,6 +87,7 @@
79742 #include <linux/types.h>
79743 #include <linux/fcntl.h>
79744 #include <linux/module.h>
79745+#include <linux/security.h>
79746 #include <linux/socket.h>
79747 #include <linux/sockios.h>
79748 #include <linux/igmp.h>
79749@@ -111,6 +112,10 @@
79750 #include <trace/events/skb.h>
79751 #include "udp_impl.h"
79752
79753+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79754+extern int grsec_enable_blackhole;
79755+#endif
79756+
79757 struct udp_table udp_table __read_mostly;
79758 EXPORT_SYMBOL(udp_table);
79759
79760@@ -569,6 +574,9 @@ found:
79761 return s;
79762 }
79763
79764+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
79765+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
79766+
79767 /*
79768 * This routine is called by the ICMP module when it gets some
79769 * sort of error condition. If err < 0 then the socket should
79770@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
79771 dport = usin->sin_port;
79772 if (dport == 0)
79773 return -EINVAL;
79774+
79775+ err = gr_search_udp_sendmsg(sk, usin);
79776+ if (err)
79777+ return err;
79778 } else {
79779 if (sk->sk_state != TCP_ESTABLISHED)
79780 return -EDESTADDRREQ;
79781+
79782+ err = gr_search_udp_sendmsg(sk, NULL);
79783+ if (err)
79784+ return err;
79785+
79786 daddr = inet->inet_daddr;
79787 dport = inet->inet_dport;
79788 /* Open fast path for connected socket.
79789@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
79790 udp_lib_checksum_complete(skb)) {
79791 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79792 IS_UDPLITE(sk));
79793- atomic_inc(&sk->sk_drops);
79794+ atomic_inc_unchecked(&sk->sk_drops);
79795 __skb_unlink(skb, rcvq);
79796 __skb_queue_tail(&list_kill, skb);
79797 }
79798@@ -1194,6 +1211,10 @@ try_again:
79799 if (!skb)
79800 goto out;
79801
79802+ err = gr_search_udp_recvmsg(sk, skb);
79803+ if (err)
79804+ goto out_free;
79805+
79806 ulen = skb->len - sizeof(struct udphdr);
79807 copied = len;
79808 if (copied > ulen)
79809@@ -1227,7 +1248,7 @@ try_again:
79810 if (unlikely(err)) {
79811 trace_kfree_skb(skb, udp_recvmsg);
79812 if (!peeked) {
79813- atomic_inc(&sk->sk_drops);
79814+ atomic_inc_unchecked(&sk->sk_drops);
79815 UDP_INC_STATS_USER(sock_net(sk),
79816 UDP_MIB_INERRORS, is_udplite);
79817 }
79818@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79819
79820 drop:
79821 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
79822- atomic_inc(&sk->sk_drops);
79823+ atomic_inc_unchecked(&sk->sk_drops);
79824 kfree_skb(skb);
79825 return -1;
79826 }
79827@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
79828 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
79829
79830 if (!skb1) {
79831- atomic_inc(&sk->sk_drops);
79832+ atomic_inc_unchecked(&sk->sk_drops);
79833 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
79834 IS_UDPLITE(sk));
79835 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79836@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
79837 goto csum_error;
79838
79839 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
79840+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79841+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
79842+#endif
79843 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
79844
79845 /*
79846@@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
79847 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79848 0, sock_i_ino(sp),
79849 atomic_read(&sp->sk_refcnt), sp,
79850- atomic_read(&sp->sk_drops), len);
79851+ atomic_read_unchecked(&sp->sk_drops), len);
79852 }
79853
79854 int udp4_seq_show(struct seq_file *seq, void *v)
79855diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
79856index a468a36..b50ffde 100644
79857--- a/net/ipv6/addrconf.c
79858+++ b/net/ipv6/addrconf.c
79859@@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
79860 p.iph.ihl = 5;
79861 p.iph.protocol = IPPROTO_IPV6;
79862 p.iph.ttl = 64;
79863- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
79864+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
79865
79866 if (ops->ndo_do_ioctl) {
79867 mm_segment_t oldfs = get_fs();
79868diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
79869index a23350c..899c62c 100644
79870--- a/net/ipv6/ip6_gre.c
79871+++ b/net/ipv6/ip6_gre.c
79872@@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
79873 }
79874
79875
79876-static struct inet6_protocol ip6gre_protocol __read_mostly = {
79877+static struct inet6_protocol ip6gre_protocol = {
79878 .handler = ip6gre_rcv,
79879 .err_handler = ip6gre_err,
79880 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
79881diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
79882index e02faed..9780f28 100644
79883--- a/net/ipv6/ipv6_sockglue.c
79884+++ b/net/ipv6/ipv6_sockglue.c
79885@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
79886 if (sk->sk_type != SOCK_STREAM)
79887 return -ENOPROTOOPT;
79888
79889- msg.msg_control = optval;
79890+ msg.msg_control = (void __force_kernel *)optval;
79891 msg.msg_controllen = len;
79892 msg.msg_flags = flags;
79893
79894diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
79895index d7cb045..8c0ded6 100644
79896--- a/net/ipv6/netfilter/ip6_tables.c
79897+++ b/net/ipv6/netfilter/ip6_tables.c
79898@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
79899 #endif
79900
79901 static int get_info(struct net *net, void __user *user,
79902- const int *len, int compat)
79903+ int len, int compat)
79904 {
79905 char name[XT_TABLE_MAXNAMELEN];
79906 struct xt_table *t;
79907 int ret;
79908
79909- if (*len != sizeof(struct ip6t_getinfo)) {
79910- duprintf("length %u != %zu\n", *len,
79911+ if (len != sizeof(struct ip6t_getinfo)) {
79912+ duprintf("length %u != %zu\n", len,
79913 sizeof(struct ip6t_getinfo));
79914 return -EINVAL;
79915 }
79916@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
79917 info.size = private->size;
79918 strcpy(info.name, name);
79919
79920- if (copy_to_user(user, &info, *len) != 0)
79921+ if (copy_to_user(user, &info, len) != 0)
79922 ret = -EFAULT;
79923 else
79924 ret = 0;
79925@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79926
79927 switch (cmd) {
79928 case IP6T_SO_GET_INFO:
79929- ret = get_info(sock_net(sk), user, len, 1);
79930+ ret = get_info(sock_net(sk), user, *len, 1);
79931 break;
79932 case IP6T_SO_GET_ENTRIES:
79933 ret = compat_get_entries(sock_net(sk), user, len);
79934@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79935
79936 switch (cmd) {
79937 case IP6T_SO_GET_INFO:
79938- ret = get_info(sock_net(sk), user, len, 0);
79939+ ret = get_info(sock_net(sk), user, *len, 0);
79940 break;
79941
79942 case IP6T_SO_GET_ENTRIES:
79943diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
79944index d8e95c7..81422bc 100644
79945--- a/net/ipv6/raw.c
79946+++ b/net/ipv6/raw.c
79947@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
79948 {
79949 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
79950 skb_checksum_complete(skb)) {
79951- atomic_inc(&sk->sk_drops);
79952+ atomic_inc_unchecked(&sk->sk_drops);
79953 kfree_skb(skb);
79954 return NET_RX_DROP;
79955 }
79956@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79957 struct raw6_sock *rp = raw6_sk(sk);
79958
79959 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
79960- atomic_inc(&sk->sk_drops);
79961+ atomic_inc_unchecked(&sk->sk_drops);
79962 kfree_skb(skb);
79963 return NET_RX_DROP;
79964 }
79965@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79966
79967 if (inet->hdrincl) {
79968 if (skb_checksum_complete(skb)) {
79969- atomic_inc(&sk->sk_drops);
79970+ atomic_inc_unchecked(&sk->sk_drops);
79971 kfree_skb(skb);
79972 return NET_RX_DROP;
79973 }
79974@@ -604,7 +604,7 @@ out:
79975 return err;
79976 }
79977
79978-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
79979+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
79980 struct flowi6 *fl6, struct dst_entry **dstp,
79981 unsigned int flags)
79982 {
79983@@ -916,12 +916,15 @@ do_confirm:
79984 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
79985 char __user *optval, int optlen)
79986 {
79987+ struct icmp6_filter filter;
79988+
79989 switch (optname) {
79990 case ICMPV6_FILTER:
79991 if (optlen > sizeof(struct icmp6_filter))
79992 optlen = sizeof(struct icmp6_filter);
79993- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
79994+ if (copy_from_user(&filter, optval, optlen))
79995 return -EFAULT;
79996+ raw6_sk(sk)->filter = filter;
79997 return 0;
79998 default:
79999 return -ENOPROTOOPT;
80000@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80001 char __user *optval, int __user *optlen)
80002 {
80003 int len;
80004+ struct icmp6_filter filter;
80005
80006 switch (optname) {
80007 case ICMPV6_FILTER:
80008@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80009 len = sizeof(struct icmp6_filter);
80010 if (put_user(len, optlen))
80011 return -EFAULT;
80012- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80013+ filter = raw6_sk(sk)->filter;
80014+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80015 return -EFAULT;
80016 return 0;
80017 default:
80018@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80019 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80020 0,
80021 sock_i_ino(sp),
80022- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80023+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80024 }
80025
80026 static int raw6_seq_show(struct seq_file *seq, void *v)
80027diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80028index 73f2a6b..f8049a1 100644
80029--- a/net/ipv6/tcp_ipv6.c
80030+++ b/net/ipv6/tcp_ipv6.c
80031@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80032 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80033 }
80034
80035+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80036+extern int grsec_enable_blackhole;
80037+#endif
80038+
80039 static void tcp_v6_hash(struct sock *sk)
80040 {
80041 if (sk->sk_state != TCP_CLOSE) {
80042@@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80043 return 0;
80044
80045 reset:
80046+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80047+ if (!grsec_enable_blackhole)
80048+#endif
80049 tcp_v6_send_reset(sk, skb);
80050 discard:
80051 if (opt_skb)
80052@@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80053 TCP_SKB_CB(skb)->sacked = 0;
80054
80055 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80056- if (!sk)
80057+ if (!sk) {
80058+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80059+ ret = 1;
80060+#endif
80061 goto no_tcp_socket;
80062+ }
80063
80064 process:
80065- if (sk->sk_state == TCP_TIME_WAIT)
80066+ if (sk->sk_state == TCP_TIME_WAIT) {
80067+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80068+ ret = 2;
80069+#endif
80070 goto do_time_wait;
80071+ }
80072
80073 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80074 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80075@@ -1660,6 +1675,10 @@ no_tcp_socket:
80076 bad_packet:
80077 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80078 } else {
80079+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80080+ if (!grsec_enable_blackhole || (ret == 1 &&
80081+ (skb->dev->flags & IFF_LOOPBACK)))
80082+#endif
80083 tcp_v6_send_reset(NULL, skb);
80084 }
80085
80086diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80087index fc99972..69397e8 100644
80088--- a/net/ipv6/udp.c
80089+++ b/net/ipv6/udp.c
80090@@ -51,6 +51,10 @@
80091 #include <trace/events/skb.h>
80092 #include "udp_impl.h"
80093
80094+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80095+extern int grsec_enable_blackhole;
80096+#endif
80097+
80098 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80099 {
80100 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80101@@ -395,7 +399,7 @@ try_again:
80102 if (unlikely(err)) {
80103 trace_kfree_skb(skb, udpv6_recvmsg);
80104 if (!peeked) {
80105- atomic_inc(&sk->sk_drops);
80106+ atomic_inc_unchecked(&sk->sk_drops);
80107 if (is_udp4)
80108 UDP_INC_STATS_USER(sock_net(sk),
80109 UDP_MIB_INERRORS,
80110@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80111 return rc;
80112 drop:
80113 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80114- atomic_inc(&sk->sk_drops);
80115+ atomic_inc_unchecked(&sk->sk_drops);
80116 kfree_skb(skb);
80117 return -1;
80118 }
80119@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80120 if (likely(skb1 == NULL))
80121 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80122 if (!skb1) {
80123- atomic_inc(&sk->sk_drops);
80124+ atomic_inc_unchecked(&sk->sk_drops);
80125 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80126 IS_UDPLITE(sk));
80127 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80128@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80129 goto discard;
80130
80131 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80132+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80133+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80134+#endif
80135 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80136
80137 kfree_skb(skb);
80138@@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80139 0,
80140 sock_i_ino(sp),
80141 atomic_read(&sp->sk_refcnt), sp,
80142- atomic_read(&sp->sk_drops));
80143+ atomic_read_unchecked(&sp->sk_drops));
80144 }
80145
80146 int udp6_seq_show(struct seq_file *seq, void *v)
80147diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80148index 496ce2c..f79fac8 100644
80149--- a/net/irda/ircomm/ircomm_tty.c
80150+++ b/net/irda/ircomm/ircomm_tty.c
80151@@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80152 add_wait_queue(&port->open_wait, &wait);
80153
80154 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80155- __FILE__, __LINE__, tty->driver->name, port->count);
80156+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80157
80158 spin_lock_irqsave(&port->lock, flags);
80159 if (!tty_hung_up_p(filp)) {
80160 extra_count = 1;
80161- port->count--;
80162+ atomic_dec(&port->count);
80163 }
80164 spin_unlock_irqrestore(&port->lock, flags);
80165 port->blocked_open++;
80166@@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80167 }
80168
80169 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80170- __FILE__, __LINE__, tty->driver->name, port->count);
80171+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80172
80173 schedule();
80174 }
80175@@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80176 if (extra_count) {
80177 /* ++ is not atomic, so this should be protected - Jean II */
80178 spin_lock_irqsave(&port->lock, flags);
80179- port->count++;
80180+ atomic_inc(&port->count);
80181 spin_unlock_irqrestore(&port->lock, flags);
80182 }
80183 port->blocked_open--;
80184
80185 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80186- __FILE__, __LINE__, tty->driver->name, port->count);
80187+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80188
80189 if (!retval)
80190 port->flags |= ASYNC_NORMAL_ACTIVE;
80191@@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80192
80193 /* ++ is not atomic, so this should be protected - Jean II */
80194 spin_lock_irqsave(&self->port.lock, flags);
80195- self->port.count++;
80196+ atomic_inc(&self->port.count);
80197 spin_unlock_irqrestore(&self->port.lock, flags);
80198 tty_port_tty_set(&self->port, tty);
80199
80200 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80201- self->line, self->port.count);
80202+ self->line, atomic_read(&self->port.count));
80203
80204 /* Not really used by us, but lets do it anyway */
80205 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80206@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80207 tty_kref_put(port->tty);
80208 }
80209 port->tty = NULL;
80210- port->count = 0;
80211+ atomic_set(&port->count, 0);
80212 spin_unlock_irqrestore(&port->lock, flags);
80213
80214 wake_up_interruptible(&port->open_wait);
80215@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80216 seq_putc(m, '\n');
80217
80218 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80219- seq_printf(m, "Open count: %d\n", self->port.count);
80220+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80221 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80222 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80223
80224diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80225index cd6f7a9..e63fe89 100644
80226--- a/net/iucv/af_iucv.c
80227+++ b/net/iucv/af_iucv.c
80228@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80229
80230 write_lock_bh(&iucv_sk_list.lock);
80231
80232- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80233+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80234 while (__iucv_get_sock_by_name(name)) {
80235 sprintf(name, "%08x",
80236- atomic_inc_return(&iucv_sk_list.autobind_name));
80237+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80238 }
80239
80240 write_unlock_bh(&iucv_sk_list.lock);
80241diff --git a/net/key/af_key.c b/net/key/af_key.c
80242index 08897a3..0b812ab 100644
80243--- a/net/key/af_key.c
80244+++ b/net/key/af_key.c
80245@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80246 static u32 get_acqseq(void)
80247 {
80248 u32 res;
80249- static atomic_t acqseq;
80250+ static atomic_unchecked_t acqseq;
80251
80252 do {
80253- res = atomic_inc_return(&acqseq);
80254+ res = atomic_inc_return_unchecked(&acqseq);
80255 } while (!res);
80256 return res;
80257 }
80258diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80259index 494da7f..6ce2ffd 100644
80260--- a/net/mac80211/cfg.c
80261+++ b/net/mac80211/cfg.c
80262@@ -2604,7 +2604,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80263 else
80264 local->probe_req_reg--;
80265
80266- if (!local->open_count)
80267+ if (!local_read(&local->open_count))
80268 break;
80269
80270 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80271diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80272index 493e2e8..be76574 100644
80273--- a/net/mac80211/ieee80211_i.h
80274+++ b/net/mac80211/ieee80211_i.h
80275@@ -28,6 +28,7 @@
80276 #include <net/ieee80211_radiotap.h>
80277 #include <net/cfg80211.h>
80278 #include <net/mac80211.h>
80279+#include <asm/local.h>
80280 #include "key.h"
80281 #include "sta_info.h"
80282 #include "debug.h"
80283@@ -852,7 +853,7 @@ struct ieee80211_local {
80284 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80285 spinlock_t queue_stop_reason_lock;
80286
80287- int open_count;
80288+ local_t open_count;
80289 int monitors, cooked_mntrs;
80290 /* number of interfaces with corresponding FIF_ flags */
80291 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80292diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80293index 0f5af91..4dba9e7 100644
80294--- a/net/mac80211/iface.c
80295+++ b/net/mac80211/iface.c
80296@@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80297 break;
80298 }
80299
80300- if (local->open_count == 0) {
80301+ if (local_read(&local->open_count) == 0) {
80302 res = drv_start(local);
80303 if (res)
80304 goto err_del_bss;
80305@@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80306 break;
80307 }
80308
80309- if (local->monitors == 0 && local->open_count == 0) {
80310+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80311 res = ieee80211_add_virtual_monitor(local);
80312 if (res)
80313 goto err_stop;
80314@@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80315 mutex_unlock(&local->mtx);
80316
80317 if (coming_up)
80318- local->open_count++;
80319+ local_inc(&local->open_count);
80320
80321 if (hw_reconf_flags)
80322 ieee80211_hw_config(local, hw_reconf_flags);
80323@@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80324 err_del_interface:
80325 drv_remove_interface(local, sdata);
80326 err_stop:
80327- if (!local->open_count)
80328+ if (!local_read(&local->open_count))
80329 drv_stop(local);
80330 err_del_bss:
80331 sdata->bss = NULL;
80332@@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80333 }
80334
80335 if (going_down)
80336- local->open_count--;
80337+ local_dec(&local->open_count);
80338
80339 switch (sdata->vif.type) {
80340 case NL80211_IFTYPE_AP_VLAN:
80341@@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80342
80343 ieee80211_recalc_ps(local, -1);
80344
80345- if (local->open_count == 0) {
80346+ if (local_read(&local->open_count) == 0) {
80347 if (local->ops->napi_poll)
80348 napi_disable(&local->napi);
80349 ieee80211_clear_tx_pending(local);
80350@@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80351 }
80352 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80353
80354- if (local->monitors == local->open_count && local->monitors > 0)
80355+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80356 ieee80211_add_virtual_monitor(local);
80357 }
80358
80359diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80360index f57f597..e0a7c03 100644
80361--- a/net/mac80211/main.c
80362+++ b/net/mac80211/main.c
80363@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80364 local->hw.conf.power_level = power;
80365 }
80366
80367- if (changed && local->open_count) {
80368+ if (changed && local_read(&local->open_count)) {
80369 ret = drv_config(local, changed);
80370 /*
80371 * Goal:
80372diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80373index 5c572e7..ecf75ce 100644
80374--- a/net/mac80211/pm.c
80375+++ b/net/mac80211/pm.c
80376@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80377 struct ieee80211_sub_if_data *sdata;
80378 struct sta_info *sta;
80379
80380- if (!local->open_count)
80381+ if (!local_read(&local->open_count))
80382 goto suspend;
80383
80384 ieee80211_scan_cancel(local);
80385@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80386 cancel_work_sync(&local->dynamic_ps_enable_work);
80387 del_timer_sync(&local->dynamic_ps_timer);
80388
80389- local->wowlan = wowlan && local->open_count;
80390+ local->wowlan = wowlan && local_read(&local->open_count);
80391 if (local->wowlan) {
80392 int err = drv_suspend(local, wowlan);
80393 if (err < 0) {
80394@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80395 drv_remove_interface(local, sdata);
80396
80397 /* stop hardware - this must stop RX */
80398- if (local->open_count)
80399+ if (local_read(&local->open_count))
80400 ieee80211_stop_device(local);
80401
80402 suspend:
80403diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80404index 3313c11..bec9f17 100644
80405--- a/net/mac80211/rate.c
80406+++ b/net/mac80211/rate.c
80407@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80408
80409 ASSERT_RTNL();
80410
80411- if (local->open_count)
80412+ if (local_read(&local->open_count))
80413 return -EBUSY;
80414
80415 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80416diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80417index c97a065..ff61928 100644
80418--- a/net/mac80211/rc80211_pid_debugfs.c
80419+++ b/net/mac80211/rc80211_pid_debugfs.c
80420@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80421
80422 spin_unlock_irqrestore(&events->lock, status);
80423
80424- if (copy_to_user(buf, pb, p))
80425+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80426 return -EFAULT;
80427
80428 return p;
80429diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80430index 0151ae3..26709d3 100644
80431--- a/net/mac80211/util.c
80432+++ b/net/mac80211/util.c
80433@@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80434 }
80435 #endif
80436 /* everything else happens only if HW was up & running */
80437- if (!local->open_count)
80438+ if (!local_read(&local->open_count))
80439 goto wake_up;
80440
80441 /*
80442diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80443index 49e96df..63a51c3 100644
80444--- a/net/netfilter/Kconfig
80445+++ b/net/netfilter/Kconfig
80446@@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
80447
80448 To compile it as a module, choose M here. If unsure, say N.
80449
80450+config NETFILTER_XT_MATCH_GRADM
80451+ tristate '"gradm" match support'
80452+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80453+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80454+ ---help---
80455+ The gradm match allows to match on grsecurity RBAC being enabled.
80456+ It is useful when iptables rules are applied early on bootup to
80457+ prevent connections to the machine (except from a trusted host)
80458+ while the RBAC system is disabled.
80459+
80460 config NETFILTER_XT_MATCH_HASHLIMIT
80461 tristate '"hashlimit" match support'
80462 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80463diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80464index 3259697..54d5393 100644
80465--- a/net/netfilter/Makefile
80466+++ b/net/netfilter/Makefile
80467@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80468 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80469 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80470 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80471+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80472 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80473 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80474 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80475diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80476index 1548df9..98ad9b4 100644
80477--- a/net/netfilter/ipvs/ip_vs_conn.c
80478+++ b/net/netfilter/ipvs/ip_vs_conn.c
80479@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80480 /* Increase the refcnt counter of the dest */
80481 atomic_inc(&dest->refcnt);
80482
80483- conn_flags = atomic_read(&dest->conn_flags);
80484+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
80485 if (cp->protocol != IPPROTO_UDP)
80486 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80487 flags = cp->flags;
80488@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80489 atomic_set(&cp->refcnt, 1);
80490
80491 atomic_set(&cp->n_control, 0);
80492- atomic_set(&cp->in_pkts, 0);
80493+ atomic_set_unchecked(&cp->in_pkts, 0);
80494
80495 atomic_inc(&ipvs->conn_count);
80496 if (flags & IP_VS_CONN_F_NO_CPORT)
80497@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80498
80499 /* Don't drop the entry if its number of incoming packets is not
80500 located in [0, 8] */
80501- i = atomic_read(&cp->in_pkts);
80502+ i = atomic_read_unchecked(&cp->in_pkts);
80503 if (i > 8 || i < 0) return 0;
80504
80505 if (!todrop_rate[i]) return 0;
80506diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80507index 58918e2..4d177a9 100644
80508--- a/net/netfilter/ipvs/ip_vs_core.c
80509+++ b/net/netfilter/ipvs/ip_vs_core.c
80510@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80511 ret = cp->packet_xmit(skb, cp, pd->pp);
80512 /* do not touch skb anymore */
80513
80514- atomic_inc(&cp->in_pkts);
80515+ atomic_inc_unchecked(&cp->in_pkts);
80516 ip_vs_conn_put(cp);
80517 return ret;
80518 }
80519@@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80520 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80521 pkts = sysctl_sync_threshold(ipvs);
80522 else
80523- pkts = atomic_add_return(1, &cp->in_pkts);
80524+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80525
80526 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80527 ip_vs_sync_conn(net, cp, pkts);
80528diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80529index c4ee437..a774a74 100644
80530--- a/net/netfilter/ipvs/ip_vs_ctl.c
80531+++ b/net/netfilter/ipvs/ip_vs_ctl.c
80532@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80533 ip_vs_rs_hash(ipvs, dest);
80534 write_unlock_bh(&ipvs->rs_lock);
80535 }
80536- atomic_set(&dest->conn_flags, conn_flags);
80537+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
80538
80539 /* bind the service */
80540 if (!dest->svc) {
80541@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80542 " %-7s %-6d %-10d %-10d\n",
80543 &dest->addr.in6,
80544 ntohs(dest->port),
80545- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80546+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80547 atomic_read(&dest->weight),
80548 atomic_read(&dest->activeconns),
80549 atomic_read(&dest->inactconns));
80550@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80551 "%-7s %-6d %-10d %-10d\n",
80552 ntohl(dest->addr.ip),
80553 ntohs(dest->port),
80554- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80555+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80556 atomic_read(&dest->weight),
80557 atomic_read(&dest->activeconns),
80558 atomic_read(&dest->inactconns));
80559@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80560
80561 entry.addr = dest->addr.ip;
80562 entry.port = dest->port;
80563- entry.conn_flags = atomic_read(&dest->conn_flags);
80564+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80565 entry.weight = atomic_read(&dest->weight);
80566 entry.u_threshold = dest->u_threshold;
80567 entry.l_threshold = dest->l_threshold;
80568@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80569 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80570 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80571 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80572- (atomic_read(&dest->conn_flags) &
80573+ (atomic_read_unchecked(&dest->conn_flags) &
80574 IP_VS_CONN_F_FWD_MASK)) ||
80575 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80576 atomic_read(&dest->weight)) ||
80577diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80578index effa10c..9058928 100644
80579--- a/net/netfilter/ipvs/ip_vs_sync.c
80580+++ b/net/netfilter/ipvs/ip_vs_sync.c
80581@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80582 cp = cp->control;
80583 if (cp) {
80584 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80585- pkts = atomic_add_return(1, &cp->in_pkts);
80586+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80587 else
80588 pkts = sysctl_sync_threshold(ipvs);
80589 ip_vs_sync_conn(net, cp->control, pkts);
80590@@ -758,7 +758,7 @@ control:
80591 if (!cp)
80592 return;
80593 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80594- pkts = atomic_add_return(1, &cp->in_pkts);
80595+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80596 else
80597 pkts = sysctl_sync_threshold(ipvs);
80598 goto sloop;
80599@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80600
80601 if (opt)
80602 memcpy(&cp->in_seq, opt, sizeof(*opt));
80603- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80604+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80605 cp->state = state;
80606 cp->old_state = cp->state;
80607 /*
80608diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80609index cc4c809..50f8fe5 100644
80610--- a/net/netfilter/ipvs/ip_vs_xmit.c
80611+++ b/net/netfilter/ipvs/ip_vs_xmit.c
80612@@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80613 else
80614 rc = NF_ACCEPT;
80615 /* do not touch skb anymore */
80616- atomic_inc(&cp->in_pkts);
80617+ atomic_inc_unchecked(&cp->in_pkts);
80618 goto out;
80619 }
80620
80621@@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80622 else
80623 rc = NF_ACCEPT;
80624 /* do not touch skb anymore */
80625- atomic_inc(&cp->in_pkts);
80626+ atomic_inc_unchecked(&cp->in_pkts);
80627 goto out;
80628 }
80629
80630diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80631index ec02168..f0caab6 100644
80632--- a/net/netfilter/nf_conntrack_core.c
80633+++ b/net/netfilter/nf_conntrack_core.c
80634@@ -1533,6 +1533,10 @@ err_extend:
80635 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80636 #define DYING_NULLS_VAL ((1<<30)+1)
80637
80638+#ifdef CONFIG_GRKERNSEC_HIDESYM
80639+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80640+#endif
80641+
80642 static int nf_conntrack_init_net(struct net *net)
80643 {
80644 int ret;
80645@@ -1546,7 +1550,11 @@ static int nf_conntrack_init_net(struct net *net)
80646 goto err_stat;
80647 }
80648
80649+#ifdef CONFIG_GRKERNSEC_HIDESYM
80650+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80651+#else
80652 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80653+#endif
80654 if (!net->ct.slabname) {
80655 ret = -ENOMEM;
80656 goto err_slabname;
80657diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80658index 92fd8ec..3f6ea4b 100644
80659--- a/net/netfilter/nfnetlink_log.c
80660+++ b/net/netfilter/nfnetlink_log.c
80661@@ -72,7 +72,7 @@ struct nfulnl_instance {
80662 };
80663
80664 static DEFINE_SPINLOCK(instances_lock);
80665-static atomic_t global_seq;
80666+static atomic_unchecked_t global_seq;
80667
80668 #define INSTANCE_BUCKETS 16
80669 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80670@@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80671 /* global sequence number */
80672 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80673 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80674- htonl(atomic_inc_return(&global_seq))))
80675+ htonl(atomic_inc_return_unchecked(&global_seq))))
80676 goto nla_put_failure;
80677
80678 if (data_len) {
80679diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80680new file mode 100644
80681index 0000000..c566332
80682--- /dev/null
80683+++ b/net/netfilter/xt_gradm.c
80684@@ -0,0 +1,51 @@
80685+/*
80686+ * gradm match for netfilter
80687