]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/3.7.5/grsecurity-2.9.1-3.7.5-201301281957.patch
Auto commit, grsecurity-3.1-4.9.13-201703052141.patch added.
[thirdparty/grsecurity-scrape.git] / test / 3.7.5 / grsecurity-2.9.1-3.7.5-201301281957.patch
CommitLineData
70c3f69f
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 ecf87b1..f0c8483 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/map.h b/arch/arm/include/asm/mach/map.h
1541index 195ac2f..2272f0d 100644
1542--- a/arch/arm/include/asm/mach/map.h
1543+++ b/arch/arm/include/asm/mach/map.h
1544@@ -34,6 +34,9 @@ struct map_desc {
1545 #define MT_MEMORY_ITCM 13
1546 #define MT_MEMORY_SO 14
1547 #define MT_MEMORY_DMA_READY 15
1548+#define MT_MEMORY_R 16
1549+#define MT_MEMORY_RW 17
1550+#define MT_MEMORY_RX 18
1551
1552 #ifdef CONFIG_MMU
1553 extern void iotable_init(struct map_desc *, int);
1554diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1555index 53426c6..c7baff3 100644
1556--- a/arch/arm/include/asm/outercache.h
1557+++ b/arch/arm/include/asm/outercache.h
1558@@ -35,7 +35,7 @@ struct outer_cache_fns {
1559 #endif
1560 void (*set_debug)(unsigned long);
1561 void (*resume)(void);
1562-};
1563+} __no_const;
1564
1565 #ifdef CONFIG_OUTER_CACHE
1566
1567diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1568index 812a494..71fc0b6 100644
1569--- a/arch/arm/include/asm/page.h
1570+++ b/arch/arm/include/asm/page.h
1571@@ -114,7 +114,7 @@ struct cpu_user_fns {
1572 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1573 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1574 unsigned long vaddr, struct vm_area_struct *vma);
1575-};
1576+} __no_const;
1577
1578 #ifdef MULTI_USER
1579 extern struct cpu_user_fns cpu_user;
1580diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1581index 943504f..1ad2de8 100644
1582--- a/arch/arm/include/asm/pgalloc.h
1583+++ b/arch/arm/include/asm/pgalloc.h
1584@@ -22,7 +22,7 @@
1585
1586 #ifdef CONFIG_MMU
1587
1588-#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1589+#define _PAGE_USER_TABLE (PMD_TYPE_TABLE | PMD_PXNTABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_USER))
1590 #define _PAGE_KERNEL_TABLE (PMD_TYPE_TABLE | PMD_BIT4 | PMD_DOMAIN(DOMAIN_KERNEL))
1591
1592 #ifdef CONFIG_ARM_LPAE
1593@@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1594 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1595 }
1596
1597+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1598+{
1599+ pud_populate(mm, pud, pmd);
1600+}
1601+
1602 #else /* !CONFIG_ARM_LPAE */
1603
1604 /*
1605@@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1606 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1607 #define pmd_free(mm, pmd) do { } while (0)
1608 #define pud_populate(mm,pmd,pte) BUG()
1609+#define pud_populate_kernel(mm,pmd,pte) BUG()
1610
1611 #endif /* CONFIG_ARM_LPAE */
1612
1613@@ -126,6 +132,16 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1614 __free_page(pte);
1615 }
1616
1617+static inline void __pmd_update(pmd_t *pmdp, pmdval_t prot)
1618+{
1619+ pmdval_t pmdval = pmd_val(*pmdp) | prot;
1620+ pmdp[0] = __pmd(pmdval);
1621+#ifndef CONFIG_ARM_LPAE
1622+ pmdp[1] = __pmd(pmdval + 256 * sizeof(pte_t));
1623+#endif
1624+ flush_pmd_entry(pmdp);
1625+}
1626+
1627 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1628 pmdval_t prot)
1629 {
1630diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1631index 5cfba15..d437dc2 100644
1632--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1633+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1634@@ -20,12 +20,15 @@
1635 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1636 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1637 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1638+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* PXN */
1639 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1640 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1641 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1642+
1643 /*
1644 * - section
1645 */
1646+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0)
1647 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1648 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1649 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1650@@ -37,6 +40,7 @@
1651 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1652 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1653 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1654+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 0))
1655
1656 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1657 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1658diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1659index d795282..d82ff13 100644
1660--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1661+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1662@@ -32,6 +32,7 @@
1663 #define PMD_TYPE_SECT (_AT(pmdval_t, 1) << 0)
1664 #define PMD_BIT4 (_AT(pmdval_t, 0))
1665 #define PMD_DOMAIN(x) (_AT(pmdval_t, 0))
1666+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 59) /* PXNTable */
1667
1668 /*
1669 * - section
1670@@ -41,9 +42,11 @@
1671 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1672 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1673 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1674+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 53)
1675 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 54)
1676 #define PMD_SECT_AP_WRITE (_AT(pmdval_t, 0))
1677 #define PMD_SECT_AP_READ (_AT(pmdval_t, 0))
1678+#define PMD_SECT_AP_RDONLY (_AT(pmdval_t, 1) << 7)
1679 #define PMD_SECT_TEX(x) (_AT(pmdval_t, 0))
1680
1681 /*
1682@@ -66,6 +69,7 @@
1683 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1684 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1685 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1686+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1687 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1688
1689 /*
1690diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1691index b249035..4ab204b 100644
1692--- a/arch/arm/include/asm/pgtable-3level.h
1693+++ b/arch/arm/include/asm/pgtable-3level.h
1694@@ -73,6 +73,7 @@
1695 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1696 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1697 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1698+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1699 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1700 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1701 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1702@@ -80,6 +81,7 @@
1703 /*
1704 * To be used in assembly code with the upper page attributes.
1705 */
1706+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1707 #define L_PTE_XN_HIGH (1 << (54 - 32))
1708 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1709
1710diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1711index 08c1231..6a2d6b0 100644
1712--- a/arch/arm/include/asm/pgtable.h
1713+++ b/arch/arm/include/asm/pgtable.h
1714@@ -30,6 +30,9 @@
1715 #include <asm/pgtable-2level.h>
1716 #endif
1717
1718+#define ktla_ktva(addr) (addr)
1719+#define ktva_ktla(addr) (addr)
1720+
1721 /*
1722 * Just any arbitrary offset to the start of the vmalloc VM area: the
1723 * current 8MB value just means that there will be a 8MB "hole" after the
1724@@ -53,6 +56,17 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1725 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1726 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1727
1728+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1729+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1730+
1731+#ifdef CONFIG_PAX_KERNEXEC
1732+static inline unsigned long pax_open_kernel(void) { return 0; /* TODO */ }
1733+static inline unsigned long pax_close_kernel(void) { return 0; /* TODO */ }
1734+#else
1735+static inline unsigned long pax_open_kernel(void) { return 0; }
1736+static inline unsigned long pax_close_kernel(void) { return 0; }
1737+#endif
1738+
1739 /*
1740 * This is the lowest virtual address we can permit any user space
1741 * mapping to be mapped at. This is particularly important for
1742@@ -73,23 +87,23 @@ extern pgprot_t pgprot_kernel;
1743
1744 #define _MOD_PROT(p, b) __pgprot(pgprot_val(p) | (b))
1745
1746-#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_RDONLY)
1747-#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN)
1748-#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER)
1749-#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1750-#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1751-#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1752-#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY)
1753+#define PAGE_NONE _MOD_PROT(pgprot_user, L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY)
1754+#define PAGE_SHARED _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1755+#define PAGE_SHARED_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_PXN)
1756+#define PAGE_COPY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1757+#define PAGE_COPY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1758+#define PAGE_READONLY _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1759+#define PAGE_READONLY_EXEC _MOD_PROT(pgprot_user, L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1760 #define PAGE_KERNEL _MOD_PROT(pgprot_kernel, L_PTE_XN)
1761 #define PAGE_KERNEL_EXEC pgprot_kernel
1762
1763-#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN)
1764-#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN)
1765-#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER)
1766-#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1767-#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1768-#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN)
1769-#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY)
1770+#define __PAGE_NONE __pgprot(_L_PTE_DEFAULT | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1771+#define __PAGE_SHARED __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_XN | L_PTE_PXN)
1772+#define __PAGE_SHARED_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_PXN)
1773+#define __PAGE_COPY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1774+#define __PAGE_COPY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1775+#define __PAGE_READONLY __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_XN | L_PTE_PXN)
1776+#define __PAGE_READONLY_EXEC __pgprot(_L_PTE_DEFAULT | L_PTE_USER | L_PTE_RDONLY | L_PTE_PXN)
1777
1778 #define __pgprot_modify(prot,mask,bits) \
1779 __pgprot((pgprot_val(prot) & ~(mask)) | (bits))
1780@@ -242,7 +256,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1781
1782 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1783 {
1784- const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER;
1785+ const pteval_t mask = L_PTE_XN | L_PTE_PXN | L_PTE_RDONLY | L_PTE_USER;
1786 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
1787 return pte;
1788 }
1789diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
1790index f3628fb..a0672dd 100644
1791--- a/arch/arm/include/asm/proc-fns.h
1792+++ b/arch/arm/include/asm/proc-fns.h
1793@@ -75,7 +75,7 @@ extern struct processor {
1794 unsigned int suspend_size;
1795 void (*do_suspend)(void *);
1796 void (*do_resume)(void *);
1797-} processor;
1798+} __do_const processor;
1799
1800 #ifndef MULTI_CPU
1801 extern void cpu_proc_init(void);
1802diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
1803index 2e3be16..4dc90fc 100644
1804--- a/arch/arm/include/asm/smp.h
1805+++ b/arch/arm/include/asm/smp.h
1806@@ -106,7 +106,7 @@ struct smp_operations {
1807 int (*cpu_disable)(unsigned int cpu);
1808 #endif
1809 #endif
1810-};
1811+} __no_const;
1812
1813 /*
1814 * set platform specific SMP operations
1815diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1816index 8477b4c..801a6a9 100644
1817--- a/arch/arm/include/asm/thread_info.h
1818+++ b/arch/arm/include/asm/thread_info.h
1819@@ -151,6 +151,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1820 #define TIF_SYSCALL_TRACE 8
1821 #define TIF_SYSCALL_AUDIT 9
1822 #define TIF_SYSCALL_TRACEPOINT 10
1823+
1824+/* within 8 bits of TIF_SYSCALL_TRACE
1825+ to meet flexible second operand requirements
1826+*/
1827+#define TIF_GRSEC_SETXID 11
1828+
1829 #define TIF_USING_IWMMXT 17
1830 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1831 #define TIF_RESTORE_SIGMASK 20
1832@@ -165,9 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1833 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
1834 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1835 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1836+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1837
1838 /* Checks for any syscall work in entry-common.S */
1839-#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
1840+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | \
1841+ _TIF_GRSEC_SETXID)
1842
1843 /*
1844 * Change these and you break ASM code in entry-common.S
1845diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1846index 7e1f760..1af891c 100644
1847--- a/arch/arm/include/asm/uaccess.h
1848+++ b/arch/arm/include/asm/uaccess.h
1849@@ -22,6 +22,8 @@
1850 #define VERIFY_READ 0
1851 #define VERIFY_WRITE 1
1852
1853+extern void check_object_size(const void *ptr, unsigned long n, bool to);
1854+
1855 /*
1856 * The exception table consists of pairs of addresses: the first is the
1857 * address of an instruction that is allowed to fault, and the second is
1858@@ -418,8 +420,23 @@ do { \
1859
1860
1861 #ifdef CONFIG_MMU
1862-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1863-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1864+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1865+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1866+
1867+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1868+{
1869+ if (!__builtin_constant_p(n))
1870+ check_object_size(to, n, false);
1871+ return ___copy_from_user(to, from, n);
1872+}
1873+
1874+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1875+{
1876+ if (!__builtin_constant_p(n))
1877+ check_object_size(from, n, true);
1878+ return ___copy_to_user(to, from, n);
1879+}
1880+
1881 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1882 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1883 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1884@@ -431,6 +448,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
1885
1886 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1887 {
1888+ if ((long)n < 0)
1889+ return n;
1890+
1891 if (access_ok(VERIFY_READ, from, n))
1892 n = __copy_from_user(to, from, n);
1893 else /* security hole - plug it */
1894@@ -440,6 +460,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1895
1896 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1897 {
1898+ if ((long)n < 0)
1899+ return n;
1900+
1901 if (access_ok(VERIFY_WRITE, to, n))
1902 n = __copy_to_user(to, from, n);
1903 return n;
1904diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
1905index 96ee092..37f1844 100644
1906--- a/arch/arm/include/uapi/asm/ptrace.h
1907+++ b/arch/arm/include/uapi/asm/ptrace.h
1908@@ -73,7 +73,7 @@
1909 * ARMv7 groups of PSR bits
1910 */
1911 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
1912-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
1913+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
1914 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
1915 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
1916
1917diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1918index 60d3b73..9168db0 100644
1919--- a/arch/arm/kernel/armksyms.c
1920+++ b/arch/arm/kernel/armksyms.c
1921@@ -89,8 +89,8 @@ EXPORT_SYMBOL(__memzero);
1922 #ifdef CONFIG_MMU
1923 EXPORT_SYMBOL(copy_page);
1924
1925-EXPORT_SYMBOL(__copy_from_user);
1926-EXPORT_SYMBOL(__copy_to_user);
1927+EXPORT_SYMBOL(___copy_from_user);
1928+EXPORT_SYMBOL(___copy_to_user);
1929 EXPORT_SYMBOL(__clear_user);
1930
1931 EXPORT_SYMBOL(__get_user_1);
1932diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
1933index 4eee351..e247728 100644
1934--- a/arch/arm/kernel/head.S
1935+++ b/arch/arm/kernel/head.S
1936@@ -52,7 +52,9 @@
1937 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
1938
1939 .macro pgtbl, rd, phys
1940- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
1941+ mov \rd, #TEXT_OFFSET
1942+ sub \rd, #PG_DIR_SIZE
1943+ add \rd, \rd, \phys
1944 .endm
1945
1946 /*
1947diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
1948index 1e9be5d..b9a75e1 100644
1949--- a/arch/arm/kernel/module.c
1950+++ b/arch/arm/kernel/module.c
1951@@ -37,12 +37,35 @@
1952 #endif
1953
1954 #ifdef CONFIG_MMU
1955-void *module_alloc(unsigned long size)
1956+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
1957 {
1958 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
1959- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
1960+ GFP_KERNEL, prot, -1,
1961 __builtin_return_address(0));
1962 }
1963+
1964+void *module_alloc(unsigned long size)
1965+{
1966+
1967+#ifdef CONFIG_PAX_KERNEXEC
1968+ return __module_alloc(size, PAGE_KERNEL);
1969+#else
1970+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1971+#endif
1972+
1973+}
1974+
1975+#ifdef CONFIG_PAX_KERNEXEC
1976+void module_free_exec(struct module *mod, void *module_region)
1977+{
1978+ module_free(mod, module_region);
1979+}
1980+
1981+void *module_alloc_exec(unsigned long size)
1982+{
1983+ return __module_alloc(size, PAGE_KERNEL_EXEC);
1984+}
1985+#endif
1986 #endif
1987
1988 int
1989diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1990index 90084a6..bf4bcfb 100644
1991--- a/arch/arm/kernel/process.c
1992+++ b/arch/arm/kernel/process.c
1993@@ -28,7 +28,6 @@
1994 #include <linux/tick.h>
1995 #include <linux/utsname.h>
1996 #include <linux/uaccess.h>
1997-#include <linux/random.h>
1998 #include <linux/hw_breakpoint.h>
1999 #include <linux/cpuidle.h>
2000 #include <linux/leds.h>
2001@@ -256,9 +255,10 @@ void machine_power_off(void)
2002 machine_shutdown();
2003 if (pm_power_off)
2004 pm_power_off();
2005+ BUG();
2006 }
2007
2008-void machine_restart(char *cmd)
2009+__noreturn void machine_restart(char *cmd)
2010 {
2011 machine_shutdown();
2012
2013@@ -451,12 +451,6 @@ unsigned long get_wchan(struct task_struct *p)
2014 return 0;
2015 }
2016
2017-unsigned long arch_randomize_brk(struct mm_struct *mm)
2018-{
2019- unsigned long range_end = mm->brk + 0x02000000;
2020- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2021-}
2022-
2023 #ifdef CONFIG_MMU
2024 /*
2025 * The vectors page is always readable from user space for the
2026diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2027index 739db3a..7f4a272 100644
2028--- a/arch/arm/kernel/ptrace.c
2029+++ b/arch/arm/kernel/ptrace.c
2030@@ -916,6 +916,10 @@ enum ptrace_syscall_dir {
2031 PTRACE_SYSCALL_EXIT,
2032 };
2033
2034+#ifdef CONFIG_GRKERNSEC_SETXID
2035+extern void gr_delayed_cred_worker(void);
2036+#endif
2037+
2038 static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2039 enum ptrace_syscall_dir dir)
2040 {
2041@@ -923,6 +927,11 @@ static int ptrace_syscall_trace(struct pt_regs *regs, int scno,
2042
2043 current_thread_info()->syscall = scno;
2044
2045+#ifdef CONFIG_GRKERNSEC_SETXID
2046+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2047+ gr_delayed_cred_worker();
2048+#endif
2049+
2050 if (!test_thread_flag(TIF_SYSCALL_TRACE))
2051 return scno;
2052
2053diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2054index da1d1aa..5aaf182 100644
2055--- a/arch/arm/kernel/setup.c
2056+++ b/arch/arm/kernel/setup.c
2057@@ -99,19 +99,19 @@ EXPORT_SYMBOL(elf_hwcap);
2058
2059
2060 #ifdef MULTI_CPU
2061-struct processor processor __read_mostly;
2062+struct processor processor;
2063 #endif
2064 #ifdef MULTI_TLB
2065-struct cpu_tlb_fns cpu_tlb __read_mostly;
2066+struct cpu_tlb_fns cpu_tlb __read_only;
2067 #endif
2068 #ifdef MULTI_USER
2069-struct cpu_user_fns cpu_user __read_mostly;
2070+struct cpu_user_fns cpu_user __read_only;
2071 #endif
2072 #ifdef MULTI_CACHE
2073-struct cpu_cache_fns cpu_cache __read_mostly;
2074+struct cpu_cache_fns cpu_cache __read_only;
2075 #endif
2076 #ifdef CONFIG_OUTER_CACHE
2077-struct outer_cache_fns outer_cache __read_mostly;
2078+struct outer_cache_fns outer_cache __read_only;
2079 EXPORT_SYMBOL(outer_cache);
2080 #endif
2081
2082@@ -455,7 +455,7 @@ static void __init setup_processor(void)
2083 __cpu_architecture = __get_cpu_architecture();
2084
2085 #ifdef MULTI_CPU
2086- processor = *list->proc;
2087+ memcpy((void *)&processor, list->proc, sizeof processor);
2088 #endif
2089 #ifdef MULTI_TLB
2090 cpu_tlb = *list->tlb;
2091diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2092index fbc8b26..000ded0 100644
2093--- a/arch/arm/kernel/smp.c
2094+++ b/arch/arm/kernel/smp.c
2095@@ -70,7 +70,7 @@ enum ipi_msg_type {
2096
2097 static DECLARE_COMPLETION(cpu_running);
2098
2099-static struct smp_operations smp_ops;
2100+static struct smp_operations smp_ops __read_only;
2101
2102 void __init smp_set_ops(struct smp_operations *ops)
2103 {
2104diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2105index b0179b8..b54c6c1 100644
2106--- a/arch/arm/kernel/traps.c
2107+++ b/arch/arm/kernel/traps.c
2108@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
2109 static int die_owner = -1;
2110 static unsigned int die_nest_count;
2111
2112+extern void gr_handle_kernel_exploit(void);
2113+
2114 static unsigned long oops_begin(void)
2115 {
2116 int cpu;
2117@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
2118 panic("Fatal exception in interrupt");
2119 if (panic_on_oops)
2120 panic("Fatal exception");
2121+
2122+ gr_handle_kernel_exploit();
2123+
2124 if (signr)
2125 do_exit(signr);
2126 }
2127diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
2128index 36ff15b..75d9e9d 100644
2129--- a/arch/arm/kernel/vmlinux.lds.S
2130+++ b/arch/arm/kernel/vmlinux.lds.S
2131@@ -8,7 +8,11 @@
2132 #include <asm/thread_info.h>
2133 #include <asm/memory.h>
2134 #include <asm/page.h>
2135-
2136+
2137+#ifdef CONFIG_PAX_KERNEXEC
2138+#include <asm/pgtable.h>
2139+#endif
2140+
2141 #define PROC_INFO \
2142 . = ALIGN(4); \
2143 VMLINUX_SYMBOL(__proc_info_begin) = .; \
2144@@ -90,6 +94,11 @@ SECTIONS
2145 _text = .;
2146 HEAD_TEXT
2147 }
2148+
2149+#ifdef CONFIG_PAX_KERNEXEC
2150+ . = ALIGN(1<<SECTION_SHIFT);
2151+#endif
2152+
2153 .text : { /* Real text segment */
2154 _stext = .; /* Text and read-only data */
2155 __exception_text_start = .;
2156@@ -133,6 +142,10 @@ SECTIONS
2157
2158 _etext = .; /* End of text and rodata section */
2159
2160+#ifdef CONFIG_PAX_KERNEXEC
2161+ . = ALIGN(1<<SECTION_SHIFT);
2162+#endif
2163+
2164 #ifndef CONFIG_XIP_KERNEL
2165 . = ALIGN(PAGE_SIZE);
2166 __init_begin = .;
2167@@ -192,6 +205,11 @@ SECTIONS
2168 . = PAGE_OFFSET + TEXT_OFFSET;
2169 #else
2170 __init_end = .;
2171+
2172+#ifdef CONFIG_PAX_KERNEXEC
2173+ . = ALIGN(1<<SECTION_SHIFT);
2174+#endif
2175+
2176 . = ALIGN(THREAD_SIZE);
2177 __data_loc = .;
2178 #endif
2179diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
2180index 66a477a..bee61d3 100644
2181--- a/arch/arm/lib/copy_from_user.S
2182+++ b/arch/arm/lib/copy_from_user.S
2183@@ -16,7 +16,7 @@
2184 /*
2185 * Prototype:
2186 *
2187- * size_t __copy_from_user(void *to, const void *from, size_t n)
2188+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
2189 *
2190 * Purpose:
2191 *
2192@@ -84,11 +84,11 @@
2193
2194 .text
2195
2196-ENTRY(__copy_from_user)
2197+ENTRY(___copy_from_user)
2198
2199 #include "copy_template.S"
2200
2201-ENDPROC(__copy_from_user)
2202+ENDPROC(___copy_from_user)
2203
2204 .pushsection .fixup,"ax"
2205 .align 0
2206diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
2207index 6ee2f67..d1cce76 100644
2208--- a/arch/arm/lib/copy_page.S
2209+++ b/arch/arm/lib/copy_page.S
2210@@ -10,6 +10,7 @@
2211 * ASM optimised string functions
2212 */
2213 #include <linux/linkage.h>
2214+#include <linux/const.h>
2215 #include <asm/assembler.h>
2216 #include <asm/asm-offsets.h>
2217 #include <asm/cache.h>
2218diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
2219index d066df6..df28194 100644
2220--- a/arch/arm/lib/copy_to_user.S
2221+++ b/arch/arm/lib/copy_to_user.S
2222@@ -16,7 +16,7 @@
2223 /*
2224 * Prototype:
2225 *
2226- * size_t __copy_to_user(void *to, const void *from, size_t n)
2227+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
2228 *
2229 * Purpose:
2230 *
2231@@ -88,11 +88,11 @@
2232 .text
2233
2234 ENTRY(__copy_to_user_std)
2235-WEAK(__copy_to_user)
2236+WEAK(___copy_to_user)
2237
2238 #include "copy_template.S"
2239
2240-ENDPROC(__copy_to_user)
2241+ENDPROC(___copy_to_user)
2242 ENDPROC(__copy_to_user_std)
2243
2244 .pushsection .fixup,"ax"
2245diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
2246index 0dc5385..45833ef 100644
2247--- a/arch/arm/lib/delay.c
2248+++ b/arch/arm/lib/delay.c
2249@@ -28,12 +28,14 @@
2250 /*
2251 * Default to the loop-based delay implementation.
2252 */
2253-struct arm_delay_ops arm_delay_ops = {
2254+static struct arm_delay_ops arm_loop_delay_ops = {
2255 .delay = __loop_delay,
2256 .const_udelay = __loop_const_udelay,
2257 .udelay = __loop_udelay,
2258 };
2259
2260+struct arm_delay_ops *arm_delay_ops __read_only = &arm_loop_delay_ops;
2261+
2262 static const struct delay_timer *delay_timer;
2263 static bool delay_calibrated;
2264
2265@@ -67,6 +69,12 @@ static void __timer_udelay(unsigned long usecs)
2266 __timer_const_udelay(usecs * UDELAY_MULT);
2267 }
2268
2269+static struct arm_delay_ops arm_timer_delay_ops = {
2270+ .delay = __timer_delay,
2271+ .const_udelay = __timer_const_udelay,
2272+ .udelay = __timer_udelay,
2273+};
2274+
2275 void __init register_current_timer_delay(const struct delay_timer *timer)
2276 {
2277 if (!delay_calibrated) {
2278@@ -74,9 +82,7 @@ void __init register_current_timer_delay(const struct delay_timer *timer)
2279 delay_timer = timer;
2280 lpj_fine = timer->freq / HZ;
2281 loops_per_jiffy = lpj_fine;
2282- arm_delay_ops.delay = __timer_delay;
2283- arm_delay_ops.const_udelay = __timer_const_udelay;
2284- arm_delay_ops.udelay = __timer_udelay;
2285+ arm_delay_ops = &arm_timer_delay_ops;
2286 delay_calibrated = true;
2287 } else {
2288 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
2289diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
2290index 025f742..8432b08 100644
2291--- a/arch/arm/lib/uaccess_with_memcpy.c
2292+++ b/arch/arm/lib/uaccess_with_memcpy.c
2293@@ -104,7 +104,7 @@ out:
2294 }
2295
2296 unsigned long
2297-__copy_to_user(void __user *to, const void *from, unsigned long n)
2298+___copy_to_user(void __user *to, const void *from, unsigned long n)
2299 {
2300 /*
2301 * This test is stubbed out of the main function above to keep
2302diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
2303index 2c6c218..2b87c2d 100644
2304--- a/arch/arm/mach-kirkwood/common.c
2305+++ b/arch/arm/mach-kirkwood/common.c
2306@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
2307 clk_gate_ops.disable(hw);
2308 }
2309
2310-static struct clk_ops clk_gate_fn_ops;
2311+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
2312+{
2313+ return clk_gate_ops.is_enabled(hw);
2314+}
2315+
2316+static struct clk_ops clk_gate_fn_ops = {
2317+ .enable = clk_gate_fn_enable,
2318+ .disable = clk_gate_fn_disable,
2319+ .is_enabled = clk_gate_fn_is_enabled,
2320+};
2321
2322 static struct clk __init *clk_register_gate_fn(struct device *dev,
2323 const char *name,
2324@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
2325 gate_fn->fn_en = fn_en;
2326 gate_fn->fn_dis = fn_dis;
2327
2328- /* ops is the gate ops, but with our enable/disable functions */
2329- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
2330- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
2331- clk_gate_fn_ops = clk_gate_ops;
2332- clk_gate_fn_ops.enable = clk_gate_fn_enable;
2333- clk_gate_fn_ops.disable = clk_gate_fn_disable;
2334- }
2335-
2336 clk = clk_register(dev, &gate_fn->gate.hw);
2337
2338 if (IS_ERR(clk))
2339diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
2340index d95f727..12f10dd 100644
2341--- a/arch/arm/mach-omap2/board-n8x0.c
2342+++ b/arch/arm/mach-omap2/board-n8x0.c
2343@@ -589,7 +589,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
2344 }
2345 #endif
2346
2347-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
2348+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
2349 .late_init = n8x0_menelaus_late_init,
2350 };
2351
2352diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
2353index 87cc6d0..fd4f248 100644
2354--- a/arch/arm/mach-omap2/omap_hwmod.c
2355+++ b/arch/arm/mach-omap2/omap_hwmod.c
2356@@ -189,10 +189,10 @@ struct omap_hwmod_soc_ops {
2357 int (*is_hardreset_asserted)(struct omap_hwmod *oh,
2358 struct omap_hwmod_rst_info *ohri);
2359 int (*init_clkdm)(struct omap_hwmod *oh);
2360-};
2361+} __no_const;
2362
2363 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
2364-static struct omap_hwmod_soc_ops soc_ops;
2365+static struct omap_hwmod_soc_ops soc_ops __read_only;
2366
2367 /* omap_hwmod_list contains all registered struct omap_hwmods */
2368 static LIST_HEAD(omap_hwmod_list);
2369diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
2370index 5dbf13f..9be36fd 100644
2371--- a/arch/arm/mm/fault.c
2372+++ b/arch/arm/mm/fault.c
2373@@ -25,6 +25,7 @@
2374 #include <asm/system_misc.h>
2375 #include <asm/system_info.h>
2376 #include <asm/tlbflush.h>
2377+#include <asm/sections.h>
2378
2379 #include "fault.h"
2380
2381@@ -138,6 +139,19 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
2382 if (fixup_exception(regs))
2383 return;
2384
2385+#ifdef CONFIG_PAX_KERNEXEC
2386+ if (fsr & FSR_WRITE) {
2387+ if (((unsigned long)_stext <= addr && addr < init_mm.end_code) || (MODULES_VADDR <= addr && addr < MODULES_END)) {
2388+ if (current->signal->curr_ip)
2389+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2390+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
2391+ else
2392+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
2393+ current->comm, task_pid_nr(current), current_uid(), current_euid());
2394+ }
2395+ }
2396+#endif
2397+
2398 /*
2399 * No handler, we'll have to terminate things with extreme prejudice.
2400 */
2401@@ -174,6 +188,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
2402 }
2403 #endif
2404
2405+#ifdef CONFIG_PAX_PAGEEXEC
2406+ if (fsr & FSR_LNX_PF) {
2407+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
2408+ do_group_exit(SIGKILL);
2409+ }
2410+#endif
2411+
2412 tsk->thread.address = addr;
2413 tsk->thread.error_code = fsr;
2414 tsk->thread.trap_no = 14;
2415@@ -398,6 +419,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
2416 }
2417 #endif /* CONFIG_MMU */
2418
2419+#ifdef CONFIG_PAX_PAGEEXEC
2420+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2421+{
2422+ long i;
2423+
2424+ printk(KERN_ERR "PAX: bytes at PC: ");
2425+ for (i = 0; i < 20; i++) {
2426+ unsigned char c;
2427+ if (get_user(c, (__force unsigned char __user *)pc+i))
2428+ printk(KERN_CONT "?? ");
2429+ else
2430+ printk(KERN_CONT "%02x ", c);
2431+ }
2432+ printk("\n");
2433+
2434+ printk(KERN_ERR "PAX: bytes at SP-4: ");
2435+ for (i = -1; i < 20; i++) {
2436+ unsigned long c;
2437+ if (get_user(c, (__force unsigned long __user *)sp+i))
2438+ printk(KERN_CONT "???????? ");
2439+ else
2440+ printk(KERN_CONT "%08lx ", c);
2441+ }
2442+ printk("\n");
2443+}
2444+#endif
2445+
2446 /*
2447 * First Level Translation Fault Handler
2448 *
2449@@ -575,12 +623,41 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
2450 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
2451 struct siginfo info;
2452
2453+#ifdef CONFIG_PAX_KERNEXEC
2454+ if (!user_mode(regs) && is_xn_fault(ifsr)) {
2455+ if (current->signal->curr_ip)
2456+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2457+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid(),
2458+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2459+ else
2460+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n",
2461+ current->comm, task_pid_nr(current), current_uid(), current_euid(),
2462+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
2463+ goto die;
2464+ }
2465+#endif
2466+
2467+#ifdef CONFIG_PAX_REFCOUNT
2468+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
2469+ unsigned int bkpt;
2470+
2471+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
2472+ current->thread.error_code = ifsr;
2473+ current->thread.trap_no = 0;
2474+ pax_report_refcount_overflow(regs);
2475+ fixup_exception(regs);
2476+ return;
2477+ }
2478+ }
2479+#endif
2480+
2481 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
2482 return;
2483
2484 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
2485 inf->name, ifsr, addr);
2486
2487+die:
2488 info.si_signo = inf->sig;
2489 info.si_errno = 0;
2490 info.si_code = inf->code;
2491diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
2492index cf08bdf..f1a0383 100644
2493--- a/arch/arm/mm/fault.h
2494+++ b/arch/arm/mm/fault.h
2495@@ -3,6 +3,7 @@
2496
2497 /*
2498 * Fault status register encodings. We steal bit 31 for our own purposes.
2499+ * Set when the FSR value is from an instruction fault.
2500 */
2501 #define FSR_LNX_PF (1 << 31)
2502 #define FSR_WRITE (1 << 11)
2503@@ -22,6 +23,12 @@ static inline int fsr_fs(unsigned int fsr)
2504 }
2505 #endif
2506
2507+/* valid for LPAE and !LPAE */
2508+static inline int is_xn_fault(unsigned int fsr)
2509+{
2510+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
2511+}
2512+
2513 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
2514 unsigned long search_exception_table(unsigned long addr);
2515
2516diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
2517index ad722f1..46b670e 100644
2518--- a/arch/arm/mm/init.c
2519+++ b/arch/arm/mm/init.c
2520@@ -734,9 +734,43 @@ void __init mem_init(void)
2521
2522 void free_initmem(void)
2523 {
2524+
2525+#ifdef CONFIG_PAX_KERNEXEC
2526+ unsigned long addr;
2527+ pgd_t *pgd;
2528+ pud_t *pud;
2529+ pmd_t *pmd;
2530+#endif
2531+
2532 #ifdef CONFIG_HAVE_TCM
2533 extern char __tcm_start, __tcm_end;
2534+#endif
2535
2536+#ifdef CONFIG_PAX_KERNEXEC
2537+ /* make pages tables, etc before .text NX */
2538+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += PMD_SIZE) {
2539+ pgd = pgd_offset_k(addr);
2540+ pud = pud_offset(pgd, addr);
2541+ pmd = pmd_offset(pud, addr);
2542+ __pmd_update(pmd, PMD_SECT_XN);
2543+ }
2544+ /* make init NX */
2545+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += PMD_SIZE) {
2546+ pgd = pgd_offset_k(addr);
2547+ pud = pud_offset(pgd, addr);
2548+ pmd = pmd_offset(pud, addr);
2549+ __pmd_update(pmd, PMD_SECT_XN);
2550+ }
2551+ /* make kernel code/rodata read-only */
2552+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += PMD_SIZE) {
2553+ pgd = pgd_offset_k(addr);
2554+ pud = pud_offset(pgd, addr);
2555+ pmd = pmd_offset(pud, addr);
2556+ __pmd_update(pmd, PMD_SECT_AP_RDONLY);
2557+ }
2558+#endif
2559+
2560+#ifdef CONFIG_HAVE_TCM
2561 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
2562 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
2563 __phys_to_pfn(__pa(&__tcm_end)),
2564diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
2565index ce8cb19..b9fe4d7 100644
2566--- a/arch/arm/mm/mmap.c
2567+++ b/arch/arm/mm/mmap.c
2568@@ -72,6 +72,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2569 unsigned long start_addr;
2570 int do_align = 0;
2571 int aliasing = cache_is_vipt_aliasing();
2572+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2573
2574 /*
2575 * We only need to do colour alignment if either the I or D
2576@@ -93,6 +94,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2577 if (len > TASK_SIZE)
2578 return -ENOMEM;
2579
2580+#ifdef CONFIG_PAX_RANDMMAP
2581+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2582+#endif
2583+
2584 if (addr) {
2585 if (do_align)
2586 addr = COLOUR_ALIGN(addr, pgoff);
2587@@ -100,15 +105,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
2588 addr = PAGE_ALIGN(addr);
2589
2590 vma = find_vma(mm, addr);
2591- if (TASK_SIZE - len >= addr &&
2592- (!vma || addr + len <= vma->vm_start))
2593+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2594 return addr;
2595 }
2596 if (len > mm->cached_hole_size) {
2597- start_addr = addr = mm->free_area_cache;
2598+ start_addr = addr = mm->free_area_cache;
2599 } else {
2600- start_addr = addr = mm->mmap_base;
2601- mm->cached_hole_size = 0;
2602+ start_addr = addr = mm->mmap_base;
2603+ mm->cached_hole_size = 0;
2604 }
2605
2606 full_search:
2607@@ -124,14 +128,14 @@ full_search:
2608 * Start a new search - just in case we missed
2609 * some holes.
2610 */
2611- if (start_addr != TASK_UNMAPPED_BASE) {
2612- start_addr = addr = TASK_UNMAPPED_BASE;
2613+ if (start_addr != mm->mmap_base) {
2614+ start_addr = addr = mm->mmap_base;
2615 mm->cached_hole_size = 0;
2616 goto full_search;
2617 }
2618 return -ENOMEM;
2619 }
2620- if (!vma || addr + len <= vma->vm_start) {
2621+ if (check_heap_stack_gap(vma, addr, len, offset)) {
2622 /*
2623 * Remember the place where we stopped the search:
2624 */
2625@@ -156,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2626 unsigned long addr = addr0;
2627 int do_align = 0;
2628 int aliasing = cache_is_vipt_aliasing();
2629+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
2630
2631 /*
2632 * We only need to do colour alignment if either the I or D
2633@@ -175,6 +180,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2634 return addr;
2635 }
2636
2637+#ifdef CONFIG_PAX_RANDMMAP
2638+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2639+#endif
2640+
2641 /* requesting a specific address */
2642 if (addr) {
2643 if (do_align)
2644@@ -182,8 +191,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2645 else
2646 addr = PAGE_ALIGN(addr);
2647 vma = find_vma(mm, addr);
2648- if (TASK_SIZE - len >= addr &&
2649- (!vma || addr + len <= vma->vm_start))
2650+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
2651 return addr;
2652 }
2653
2654@@ -203,7 +211,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2655 /* make sure it can fit in the remaining address space */
2656 if (addr > len) {
2657 vma = find_vma(mm, addr-len);
2658- if (!vma || addr <= vma->vm_start)
2659+ if (check_heap_stack_gap(vma, addr - len, len, offset))
2660 /* remember the address as a hint for next time */
2661 return (mm->free_area_cache = addr-len);
2662 }
2663@@ -212,17 +220,17 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2664 goto bottomup;
2665
2666 addr = mm->mmap_base - len;
2667- if (do_align)
2668- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2669
2670 do {
2671+ if (do_align)
2672+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2673 /*
2674 * Lookup failure means no vma is above this address,
2675 * else if new region fits below vma->vm_start,
2676 * return with success:
2677 */
2678 vma = find_vma(mm, addr);
2679- if (!vma || addr+len <= vma->vm_start)
2680+ if (check_heap_stack_gap(vma, addr, len, offset))
2681 /* remember the address as a hint for next time */
2682 return (mm->free_area_cache = addr);
2683
2684@@ -231,10 +239,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
2685 mm->cached_hole_size = vma->vm_start - addr;
2686
2687 /* try just below the current vma->vm_start */
2688- addr = vma->vm_start - len;
2689- if (do_align)
2690- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
2691- } while (len < vma->vm_start);
2692+ addr = skip_heap_stack_gap(vma, len, offset);
2693+ } while (!IS_ERR_VALUE(addr));
2694
2695 bottomup:
2696 /*
2697@@ -266,10 +272,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2698
2699 if (mmap_is_legacy()) {
2700 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2701+
2702+#ifdef CONFIG_PAX_RANDMMAP
2703+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2704+ mm->mmap_base += mm->delta_mmap;
2705+#endif
2706+
2707 mm->get_unmapped_area = arch_get_unmapped_area;
2708 mm->unmap_area = arch_unmap_area;
2709 } else {
2710 mm->mmap_base = mmap_base(random_factor);
2711+
2712+#ifdef CONFIG_PAX_RANDMMAP
2713+ if (mm->pax_flags & MF_PAX_RANDMMAP)
2714+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2715+#endif
2716+
2717 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2718 mm->unmap_area = arch_unmap_area_topdown;
2719 }
2720diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
2721index 99b47b9..ede7824 100644
2722--- a/arch/arm/mm/mmu.c
2723+++ b/arch/arm/mm/mmu.c
2724@@ -227,16 +227,16 @@ static struct mem_type mem_types[] = {
2725 [MT_UNCACHED] = {
2726 .prot_pte = PROT_PTE_DEVICE,
2727 .prot_l1 = PMD_TYPE_TABLE,
2728- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2729+ .prot_sect = PROT_SECT_DEVICE | PMD_SECT_XN,
2730 .domain = DOMAIN_IO,
2731 },
2732 [MT_CACHECLEAN] = {
2733- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2734+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2735 .domain = DOMAIN_KERNEL,
2736 },
2737 #ifndef CONFIG_ARM_LPAE
2738 [MT_MINICLEAN] = {
2739- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
2740+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE | PMD_SECT_AP_RDONLY,
2741 .domain = DOMAIN_KERNEL,
2742 },
2743 #endif
2744@@ -258,8 +258,26 @@ static struct mem_type mem_types[] = {
2745 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
2746 .domain = DOMAIN_KERNEL,
2747 },
2748+ [MT_MEMORY_R] = {
2749+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY | L_PTE_XN,
2750+ .prot_l1 = PMD_TYPE_TABLE,
2751+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY | PMD_SECT_XN,
2752+ .domain = DOMAIN_KERNEL,
2753+ },
2754+ [MT_MEMORY_RW] = {
2755+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY | L_PTE_XN,
2756+ .prot_l1 = PMD_TYPE_TABLE,
2757+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_XN,
2758+ .domain = DOMAIN_KERNEL,
2759+ },
2760+ [MT_MEMORY_RX] = {
2761+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_RDONLY,
2762+ .prot_l1 = PMD_TYPE_TABLE,
2763+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2764+ .domain = DOMAIN_KERNEL,
2765+ },
2766 [MT_ROM] = {
2767- .prot_sect = PMD_TYPE_SECT,
2768+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_RDONLY,
2769 .domain = DOMAIN_KERNEL,
2770 },
2771 [MT_MEMORY_NONCACHED] = {
2772@@ -273,7 +291,7 @@ static struct mem_type mem_types[] = {
2773 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
2774 L_PTE_XN,
2775 .prot_l1 = PMD_TYPE_TABLE,
2776- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
2777+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_AP_RDONLY,
2778 .domain = DOMAIN_KERNEL,
2779 },
2780 [MT_MEMORY_ITCM] = {
2781@@ -432,6 +450,8 @@ static void __init build_mem_type_table(void)
2782 * from SVC mode and no access from userspace.
2783 */
2784 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2785+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2786+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2787 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2788 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
2789 #endif
2790@@ -450,6 +470,12 @@ static void __init build_mem_type_table(void)
2791 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
2792 mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
2793 mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
2794+ mem_types[MT_MEMORY_R].prot_sect |= PMD_SECT_S;
2795+ mem_types[MT_MEMORY_R].prot_pte |= L_PTE_SHARED;
2796+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
2797+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
2798+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
2799+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
2800 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
2801 mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
2802 mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
2803@@ -503,6 +529,12 @@ static void __init build_mem_type_table(void)
2804 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
2805 mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
2806 mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
2807+ mem_types[MT_MEMORY_R].prot_sect |= ecc_mask | cp->pmd;
2808+ mem_types[MT_MEMORY_R].prot_pte |= kern_pgprot;
2809+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
2810+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
2811+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
2812+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
2813 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
2814 mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
2815 mem_types[MT_ROM].prot_sect |= cp->pmd;
2816@@ -1198,8 +1230,37 @@ static void __init map_lowmem(void)
2817 map.pfn = __phys_to_pfn(start);
2818 map.virtual = __phys_to_virt(start);
2819 map.length = end - start;
2820- map.type = MT_MEMORY;
2821
2822+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
2823+ struct map_desc kernel;
2824+ struct map_desc initmap;
2825+
2826+ /* when freeing initmem we will make this RW */
2827+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
2828+ initmap.virtual = (unsigned long)__init_begin;
2829+ initmap.length = _sdata - __init_begin;
2830+ initmap.type = MT_MEMORY;
2831+ create_mapping(&initmap);
2832+
2833+ /* when freeing initmem we will make this RX */
2834+ kernel.pfn = __phys_to_pfn(__pa(_stext));
2835+ kernel.virtual = (unsigned long)_stext;
2836+ kernel.length = __init_begin - _stext;
2837+ kernel.type = MT_MEMORY;
2838+ create_mapping(&kernel);
2839+
2840+ if (map.virtual < (unsigned long)_stext) {
2841+ map.length = (unsigned long)_stext - map.virtual;
2842+ map.type = MT_MEMORY;
2843+ create_mapping(&map);
2844+ }
2845+
2846+ map.pfn = __phys_to_pfn(__pa(_sdata));
2847+ map.virtual = (unsigned long)_sdata;
2848+ map.length = end - __pa(_sdata);
2849+ }
2850+
2851+ map.type = MT_MEMORY_RW;
2852 create_mapping(&map);
2853 }
2854 }
2855diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2856index ec63e4a..62aa5f1d 100644
2857--- a/arch/arm/plat-orion/include/plat/addr-map.h
2858+++ b/arch/arm/plat-orion/include/plat/addr-map.h
2859@@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2860 value in bridge_virt_base */
2861 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2862 const int win);
2863-};
2864+} __no_const;
2865
2866 /*
2867 * Information needed to setup one address mapping.
2868diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2869index f5144cd..71f6d1f 100644
2870--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2871+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2872@@ -47,7 +47,7 @@ struct samsung_dma_ops {
2873 int (*started)(unsigned ch);
2874 int (*flush)(unsigned ch);
2875 int (*stop)(unsigned ch);
2876-};
2877+} __no_const;
2878
2879 extern void *samsung_dmadev_get_ops(void);
2880 extern void *s3c_dma_get_ops(void);
2881diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2882index c3a58a1..78fbf54 100644
2883--- a/arch/avr32/include/asm/cache.h
2884+++ b/arch/avr32/include/asm/cache.h
2885@@ -1,8 +1,10 @@
2886 #ifndef __ASM_AVR32_CACHE_H
2887 #define __ASM_AVR32_CACHE_H
2888
2889+#include <linux/const.h>
2890+
2891 #define L1_CACHE_SHIFT 5
2892-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2893+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2894
2895 /*
2896 * Memory returned by kmalloc() may be used for DMA, so we must make
2897diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2898index e2c3287..6c4f98c 100644
2899--- a/arch/avr32/include/asm/elf.h
2900+++ b/arch/avr32/include/asm/elf.h
2901@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2902 the loader. We need to make sure that it is out of the way of the program
2903 that it will "exec", and that there is sufficient room for the brk. */
2904
2905-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2906+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2907
2908+#ifdef CONFIG_PAX_ASLR
2909+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2910+
2911+#define PAX_DELTA_MMAP_LEN 15
2912+#define PAX_DELTA_STACK_LEN 15
2913+#endif
2914
2915 /* This yields a mask that user programs can use to figure out what
2916 instruction set this CPU supports. This could be done in user space,
2917diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2918index 479330b..53717a8 100644
2919--- a/arch/avr32/include/asm/kmap_types.h
2920+++ b/arch/avr32/include/asm/kmap_types.h
2921@@ -2,9 +2,9 @@
2922 #define __ASM_AVR32_KMAP_TYPES_H
2923
2924 #ifdef CONFIG_DEBUG_HIGHMEM
2925-# define KM_TYPE_NR 29
2926+# define KM_TYPE_NR 30
2927 #else
2928-# define KM_TYPE_NR 14
2929+# define KM_TYPE_NR 15
2930 #endif
2931
2932 #endif /* __ASM_AVR32_KMAP_TYPES_H */
2933diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2934index b2f2d2d..d1c85cb 100644
2935--- a/arch/avr32/mm/fault.c
2936+++ b/arch/avr32/mm/fault.c
2937@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2938
2939 int exception_trace = 1;
2940
2941+#ifdef CONFIG_PAX_PAGEEXEC
2942+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2943+{
2944+ unsigned long i;
2945+
2946+ printk(KERN_ERR "PAX: bytes at PC: ");
2947+ for (i = 0; i < 20; i++) {
2948+ unsigned char c;
2949+ if (get_user(c, (unsigned char *)pc+i))
2950+ printk(KERN_CONT "???????? ");
2951+ else
2952+ printk(KERN_CONT "%02x ", c);
2953+ }
2954+ printk("\n");
2955+}
2956+#endif
2957+
2958 /*
2959 * This routine handles page faults. It determines the address and the
2960 * problem, and then passes it off to one of the appropriate routines.
2961@@ -174,6 +191,16 @@ bad_area:
2962 up_read(&mm->mmap_sem);
2963
2964 if (user_mode(regs)) {
2965+
2966+#ifdef CONFIG_PAX_PAGEEXEC
2967+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2968+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2969+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2970+ do_group_exit(SIGKILL);
2971+ }
2972+ }
2973+#endif
2974+
2975 if (exception_trace && printk_ratelimit())
2976 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2977 "sp %08lx ecr %lu\n",
2978diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2979index 568885a..f8008df 100644
2980--- a/arch/blackfin/include/asm/cache.h
2981+++ b/arch/blackfin/include/asm/cache.h
2982@@ -7,6 +7,7 @@
2983 #ifndef __ARCH_BLACKFIN_CACHE_H
2984 #define __ARCH_BLACKFIN_CACHE_H
2985
2986+#include <linux/const.h>
2987 #include <linux/linkage.h> /* for asmlinkage */
2988
2989 /*
2990@@ -14,7 +15,7 @@
2991 * Blackfin loads 32 bytes for cache
2992 */
2993 #define L1_CACHE_SHIFT 5
2994-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2995+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2996 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2997
2998 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2999diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
3000index aea2718..3639a60 100644
3001--- a/arch/cris/include/arch-v10/arch/cache.h
3002+++ b/arch/cris/include/arch-v10/arch/cache.h
3003@@ -1,8 +1,9 @@
3004 #ifndef _ASM_ARCH_CACHE_H
3005 #define _ASM_ARCH_CACHE_H
3006
3007+#include <linux/const.h>
3008 /* Etrax 100LX have 32-byte cache-lines. */
3009-#define L1_CACHE_BYTES 32
3010 #define L1_CACHE_SHIFT 5
3011+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3012
3013 #endif /* _ASM_ARCH_CACHE_H */
3014diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
3015index 7caf25d..ee65ac5 100644
3016--- a/arch/cris/include/arch-v32/arch/cache.h
3017+++ b/arch/cris/include/arch-v32/arch/cache.h
3018@@ -1,11 +1,12 @@
3019 #ifndef _ASM_CRIS_ARCH_CACHE_H
3020 #define _ASM_CRIS_ARCH_CACHE_H
3021
3022+#include <linux/const.h>
3023 #include <arch/hwregs/dma.h>
3024
3025 /* A cache-line is 32 bytes. */
3026-#define L1_CACHE_BYTES 32
3027 #define L1_CACHE_SHIFT 5
3028+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3029
3030 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
3031
3032diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
3033index b86329d..6709906 100644
3034--- a/arch/frv/include/asm/atomic.h
3035+++ b/arch/frv/include/asm/atomic.h
3036@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
3037 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
3038 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
3039
3040+#define atomic64_read_unchecked(v) atomic64_read(v)
3041+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3042+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3043+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3044+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3045+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3046+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3047+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3048+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3049+
3050 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
3051 {
3052 int c, old;
3053diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
3054index 2797163..c2a401d 100644
3055--- a/arch/frv/include/asm/cache.h
3056+++ b/arch/frv/include/asm/cache.h
3057@@ -12,10 +12,11 @@
3058 #ifndef __ASM_CACHE_H
3059 #define __ASM_CACHE_H
3060
3061+#include <linux/const.h>
3062
3063 /* bytes per L1 cache line */
3064 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
3065-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3066+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3067
3068 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3069 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
3070diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
3071index 43901f2..0d8b865 100644
3072--- a/arch/frv/include/asm/kmap_types.h
3073+++ b/arch/frv/include/asm/kmap_types.h
3074@@ -2,6 +2,6 @@
3075 #ifndef _ASM_KMAP_TYPES_H
3076 #define _ASM_KMAP_TYPES_H
3077
3078-#define KM_TYPE_NR 17
3079+#define KM_TYPE_NR 18
3080
3081 #endif
3082diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
3083index 385fd30..3aaf4fe 100644
3084--- a/arch/frv/mm/elf-fdpic.c
3085+++ b/arch/frv/mm/elf-fdpic.c
3086@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3087 {
3088 struct vm_area_struct *vma;
3089 unsigned long limit;
3090+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
3091
3092 if (len > TASK_SIZE)
3093 return -ENOMEM;
3094@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3095 if (addr) {
3096 addr = PAGE_ALIGN(addr);
3097 vma = find_vma(current->mm, addr);
3098- if (TASK_SIZE - len >= addr &&
3099- (!vma || addr + len <= vma->vm_start))
3100+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3101 goto success;
3102 }
3103
3104@@ -89,7 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3105 for (; vma; vma = vma->vm_next) {
3106 if (addr > limit)
3107 break;
3108- if (addr + len <= vma->vm_start)
3109+ if (check_heap_stack_gap(vma, addr, len, offset))
3110 goto success;
3111 addr = vma->vm_end;
3112 }
3113@@ -104,7 +104,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
3114 for (; vma; vma = vma->vm_next) {
3115 if (addr > limit)
3116 break;
3117- if (addr + len <= vma->vm_start)
3118+ if (check_heap_stack_gap(vma, addr, len, offset))
3119 goto success;
3120 addr = vma->vm_end;
3121 }
3122diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
3123index f4ca594..adc72fd6 100644
3124--- a/arch/hexagon/include/asm/cache.h
3125+++ b/arch/hexagon/include/asm/cache.h
3126@@ -21,9 +21,11 @@
3127 #ifndef __ASM_CACHE_H
3128 #define __ASM_CACHE_H
3129
3130+#include <linux/const.h>
3131+
3132 /* Bytes per L1 cache line */
3133-#define L1_CACHE_SHIFT (5)
3134-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3135+#define L1_CACHE_SHIFT 5
3136+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3137
3138 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
3139 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
3140diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
3141index 6e6fe18..a6ae668 100644
3142--- a/arch/ia64/include/asm/atomic.h
3143+++ b/arch/ia64/include/asm/atomic.h
3144@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
3145 #define atomic64_inc(v) atomic64_add(1, (v))
3146 #define atomic64_dec(v) atomic64_sub(1, (v))
3147
3148+#define atomic64_read_unchecked(v) atomic64_read(v)
3149+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3150+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3151+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3152+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3153+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3154+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3155+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3156+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3157+
3158 /* Atomic operations are already serializing */
3159 #define smp_mb__before_atomic_dec() barrier()
3160 #define smp_mb__after_atomic_dec() barrier()
3161diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
3162index 988254a..e1ee885 100644
3163--- a/arch/ia64/include/asm/cache.h
3164+++ b/arch/ia64/include/asm/cache.h
3165@@ -1,6 +1,7 @@
3166 #ifndef _ASM_IA64_CACHE_H
3167 #define _ASM_IA64_CACHE_H
3168
3169+#include <linux/const.h>
3170
3171 /*
3172 * Copyright (C) 1998-2000 Hewlett-Packard Co
3173@@ -9,7 +10,7 @@
3174
3175 /* Bytes per L1 (data) cache line. */
3176 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
3177-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3178+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3179
3180 #ifdef CONFIG_SMP
3181 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3182diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
3183index b5298eb..67c6e62 100644
3184--- a/arch/ia64/include/asm/elf.h
3185+++ b/arch/ia64/include/asm/elf.h
3186@@ -42,6 +42,13 @@
3187 */
3188 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
3189
3190+#ifdef CONFIG_PAX_ASLR
3191+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
3192+
3193+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3194+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
3195+#endif
3196+
3197 #define PT_IA_64_UNWIND 0x70000001
3198
3199 /* IA-64 relocations: */
3200diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
3201index 96a8d92..617a1cf 100644
3202--- a/arch/ia64/include/asm/pgalloc.h
3203+++ b/arch/ia64/include/asm/pgalloc.h
3204@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3205 pgd_val(*pgd_entry) = __pa(pud);
3206 }
3207
3208+static inline void
3209+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
3210+{
3211+ pgd_populate(mm, pgd_entry, pud);
3212+}
3213+
3214 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3215 {
3216 return quicklist_alloc(0, GFP_KERNEL, NULL);
3217@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3218 pud_val(*pud_entry) = __pa(pmd);
3219 }
3220
3221+static inline void
3222+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
3223+{
3224+ pud_populate(mm, pud_entry, pmd);
3225+}
3226+
3227 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
3228 {
3229 return quicklist_alloc(0, GFP_KERNEL, NULL);
3230diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
3231index 815810c..d60bd4c 100644
3232--- a/arch/ia64/include/asm/pgtable.h
3233+++ b/arch/ia64/include/asm/pgtable.h
3234@@ -12,7 +12,7 @@
3235 * David Mosberger-Tang <davidm@hpl.hp.com>
3236 */
3237
3238-
3239+#include <linux/const.h>
3240 #include <asm/mman.h>
3241 #include <asm/page.h>
3242 #include <asm/processor.h>
3243@@ -142,6 +142,17 @@
3244 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3245 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3246 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
3247+
3248+#ifdef CONFIG_PAX_PAGEEXEC
3249+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
3250+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3251+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
3252+#else
3253+# define PAGE_SHARED_NOEXEC PAGE_SHARED
3254+# define PAGE_READONLY_NOEXEC PAGE_READONLY
3255+# define PAGE_COPY_NOEXEC PAGE_COPY
3256+#endif
3257+
3258 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
3259 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
3260 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
3261diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
3262index 54ff557..70c88b7 100644
3263--- a/arch/ia64/include/asm/spinlock.h
3264+++ b/arch/ia64/include/asm/spinlock.h
3265@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
3266 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
3267
3268 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
3269- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
3270+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
3271 }
3272
3273 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
3274diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
3275index 449c8c0..50cdf87 100644
3276--- a/arch/ia64/include/asm/uaccess.h
3277+++ b/arch/ia64/include/asm/uaccess.h
3278@@ -42,6 +42,8 @@
3279 #include <asm/pgtable.h>
3280 #include <asm/io.h>
3281
3282+extern void check_object_size(const void *ptr, unsigned long n, bool to);
3283+
3284 /*
3285 * For historical reasons, the following macros are grossly misnamed:
3286 */
3287@@ -240,12 +242,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
3288 static inline unsigned long
3289 __copy_to_user (void __user *to, const void *from, unsigned long count)
3290 {
3291+ if (count > INT_MAX)
3292+ return count;
3293+
3294+ if (!__builtin_constant_p(count))
3295+ check_object_size(from, count, true);
3296+
3297 return __copy_user(to, (__force void __user *) from, count);
3298 }
3299
3300 static inline unsigned long
3301 __copy_from_user (void *to, const void __user *from, unsigned long count)
3302 {
3303+ if (count > INT_MAX)
3304+ return count;
3305+
3306+ if (!__builtin_constant_p(count))
3307+ check_object_size(to, count, false);
3308+
3309 return __copy_user((__force void __user *) to, from, count);
3310 }
3311
3312@@ -255,10 +269,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3313 ({ \
3314 void __user *__cu_to = (to); \
3315 const void *__cu_from = (from); \
3316- long __cu_len = (n); \
3317+ unsigned long __cu_len = (n); \
3318 \
3319- if (__access_ok(__cu_to, __cu_len, get_fs())) \
3320+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
3321+ if (!__builtin_constant_p(n)) \
3322+ check_object_size(__cu_from, __cu_len, true); \
3323 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
3324+ } \
3325 __cu_len; \
3326 })
3327
3328@@ -266,11 +283,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
3329 ({ \
3330 void *__cu_to = (to); \
3331 const void __user *__cu_from = (from); \
3332- long __cu_len = (n); \
3333+ unsigned long __cu_len = (n); \
3334 \
3335 __chk_user_ptr(__cu_from); \
3336- if (__access_ok(__cu_from, __cu_len, get_fs())) \
3337+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
3338+ if (!__builtin_constant_p(n)) \
3339+ check_object_size(__cu_to, __cu_len, false); \
3340 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
3341+ } \
3342 __cu_len; \
3343 })
3344
3345diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
3346index 24603be..948052d 100644
3347--- a/arch/ia64/kernel/module.c
3348+++ b/arch/ia64/kernel/module.c
3349@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
3350 void
3351 module_free (struct module *mod, void *module_region)
3352 {
3353- if (mod && mod->arch.init_unw_table &&
3354- module_region == mod->module_init) {
3355+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
3356 unw_remove_unwind_table(mod->arch.init_unw_table);
3357 mod->arch.init_unw_table = NULL;
3358 }
3359@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
3360 }
3361
3362 static inline int
3363+in_init_rx (const struct module *mod, uint64_t addr)
3364+{
3365+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
3366+}
3367+
3368+static inline int
3369+in_init_rw (const struct module *mod, uint64_t addr)
3370+{
3371+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
3372+}
3373+
3374+static inline int
3375 in_init (const struct module *mod, uint64_t addr)
3376 {
3377- return addr - (uint64_t) mod->module_init < mod->init_size;
3378+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
3379+}
3380+
3381+static inline int
3382+in_core_rx (const struct module *mod, uint64_t addr)
3383+{
3384+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
3385+}
3386+
3387+static inline int
3388+in_core_rw (const struct module *mod, uint64_t addr)
3389+{
3390+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
3391 }
3392
3393 static inline int
3394 in_core (const struct module *mod, uint64_t addr)
3395 {
3396- return addr - (uint64_t) mod->module_core < mod->core_size;
3397+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
3398 }
3399
3400 static inline int
3401@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
3402 break;
3403
3404 case RV_BDREL:
3405- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
3406+ if (in_init_rx(mod, val))
3407+ val -= (uint64_t) mod->module_init_rx;
3408+ else if (in_init_rw(mod, val))
3409+ val -= (uint64_t) mod->module_init_rw;
3410+ else if (in_core_rx(mod, val))
3411+ val -= (uint64_t) mod->module_core_rx;
3412+ else if (in_core_rw(mod, val))
3413+ val -= (uint64_t) mod->module_core_rw;
3414 break;
3415
3416 case RV_LTV:
3417@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
3418 * addresses have been selected...
3419 */
3420 uint64_t gp;
3421- if (mod->core_size > MAX_LTOFF)
3422+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
3423 /*
3424 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
3425 * at the end of the module.
3426 */
3427- gp = mod->core_size - MAX_LTOFF / 2;
3428+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
3429 else
3430- gp = mod->core_size / 2;
3431- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
3432+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
3433+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
3434 mod->arch.gp = gp;
3435 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
3436 }
3437diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
3438index d9439ef..d0cac6b 100644
3439--- a/arch/ia64/kernel/sys_ia64.c
3440+++ b/arch/ia64/kernel/sys_ia64.c
3441@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3442 unsigned long start_addr, align_mask = PAGE_SIZE - 1;
3443 struct mm_struct *mm = current->mm;
3444 struct vm_area_struct *vma;
3445+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3446
3447 if (len > RGN_MAP_LIMIT)
3448 return -ENOMEM;
3449@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3450 if (REGION_NUMBER(addr) == RGN_HPAGE)
3451 addr = 0;
3452 #endif
3453+
3454+#ifdef CONFIG_PAX_RANDMMAP
3455+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3456+ addr = mm->free_area_cache;
3457+ else
3458+#endif
3459+
3460 if (!addr)
3461 addr = mm->free_area_cache;
3462
3463@@ -61,14 +69,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
3464 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
3465 /* At this point: (!vma || addr < vma->vm_end). */
3466 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
3467- if (start_addr != TASK_UNMAPPED_BASE) {
3468+ if (start_addr != mm->mmap_base) {
3469 /* Start a new search --- just in case we missed some holes. */
3470- addr = TASK_UNMAPPED_BASE;
3471+ addr = mm->mmap_base;
3472 goto full_search;
3473 }
3474 return -ENOMEM;
3475 }
3476- if (!vma || addr + len <= vma->vm_start) {
3477+ if (check_heap_stack_gap(vma, addr, len, offset)) {
3478 /* Remember the address where we stopped this search: */
3479 mm->free_area_cache = addr + len;
3480 return addr;
3481diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
3482index c64460b..4d250a6 100644
3483--- a/arch/ia64/kernel/topology.c
3484+++ b/arch/ia64/kernel/topology.c
3485@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
3486 return NOTIFY_OK;
3487 }
3488
3489-static struct notifier_block __cpuinitdata cache_cpu_notifier =
3490+static struct notifier_block cache_cpu_notifier =
3491 {
3492 .notifier_call = cache_cpu_callback
3493 };
3494diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
3495index 0ccb28f..8992469 100644
3496--- a/arch/ia64/kernel/vmlinux.lds.S
3497+++ b/arch/ia64/kernel/vmlinux.lds.S
3498@@ -198,7 +198,7 @@ SECTIONS {
3499 /* Per-cpu data: */
3500 . = ALIGN(PERCPU_PAGE_SIZE);
3501 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
3502- __phys_per_cpu_start = __per_cpu_load;
3503+ __phys_per_cpu_start = per_cpu_load;
3504 /*
3505 * ensure percpu data fits
3506 * into percpu page size
3507diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
3508index 6cf0341..d352594 100644
3509--- a/arch/ia64/mm/fault.c
3510+++ b/arch/ia64/mm/fault.c
3511@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
3512 return pte_present(pte);
3513 }
3514
3515+#ifdef CONFIG_PAX_PAGEEXEC
3516+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3517+{
3518+ unsigned long i;
3519+
3520+ printk(KERN_ERR "PAX: bytes at PC: ");
3521+ for (i = 0; i < 8; i++) {
3522+ unsigned int c;
3523+ if (get_user(c, (unsigned int *)pc+i))
3524+ printk(KERN_CONT "???????? ");
3525+ else
3526+ printk(KERN_CONT "%08x ", c);
3527+ }
3528+ printk("\n");
3529+}
3530+#endif
3531+
3532 # define VM_READ_BIT 0
3533 # define VM_WRITE_BIT 1
3534 # define VM_EXEC_BIT 2
3535@@ -149,8 +166,21 @@ retry:
3536 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
3537 goto bad_area;
3538
3539- if ((vma->vm_flags & mask) != mask)
3540+ if ((vma->vm_flags & mask) != mask) {
3541+
3542+#ifdef CONFIG_PAX_PAGEEXEC
3543+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
3544+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
3545+ goto bad_area;
3546+
3547+ up_read(&mm->mmap_sem);
3548+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
3549+ do_group_exit(SIGKILL);
3550+ }
3551+#endif
3552+
3553 goto bad_area;
3554+ }
3555
3556 /*
3557 * If for any reason at all we couldn't handle the fault, make
3558diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
3559index 5ca674b..127c3cb 100644
3560--- a/arch/ia64/mm/hugetlbpage.c
3561+++ b/arch/ia64/mm/hugetlbpage.c
3562@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3563 unsigned long pgoff, unsigned long flags)
3564 {
3565 struct vm_area_struct *vmm;
3566+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
3567
3568 if (len > RGN_MAP_LIMIT)
3569 return -ENOMEM;
3570@@ -171,7 +172,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
3571 /* At this point: (!vmm || addr < vmm->vm_end). */
3572 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
3573 return -ENOMEM;
3574- if (!vmm || (addr + len) <= vmm->vm_start)
3575+ if (check_heap_stack_gap(vmm, addr, len, offset))
3576 return addr;
3577 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
3578 }
3579diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
3580index 082e383..fb7be80 100644
3581--- a/arch/ia64/mm/init.c
3582+++ b/arch/ia64/mm/init.c
3583@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
3584 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
3585 vma->vm_end = vma->vm_start + PAGE_SIZE;
3586 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
3587+
3588+#ifdef CONFIG_PAX_PAGEEXEC
3589+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
3590+ vma->vm_flags &= ~VM_EXEC;
3591+
3592+#ifdef CONFIG_PAX_MPROTECT
3593+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
3594+ vma->vm_flags &= ~VM_MAYEXEC;
3595+#endif
3596+
3597+ }
3598+#endif
3599+
3600 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3601 down_write(&current->mm->mmap_sem);
3602 if (insert_vm_struct(current->mm, vma)) {
3603diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
3604index 40b3ee9..8c2c112 100644
3605--- a/arch/m32r/include/asm/cache.h
3606+++ b/arch/m32r/include/asm/cache.h
3607@@ -1,8 +1,10 @@
3608 #ifndef _ASM_M32R_CACHE_H
3609 #define _ASM_M32R_CACHE_H
3610
3611+#include <linux/const.h>
3612+
3613 /* L1 cache line size */
3614 #define L1_CACHE_SHIFT 4
3615-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3616+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3617
3618 #endif /* _ASM_M32R_CACHE_H */
3619diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
3620index 82abd15..d95ae5d 100644
3621--- a/arch/m32r/lib/usercopy.c
3622+++ b/arch/m32r/lib/usercopy.c
3623@@ -14,6 +14,9 @@
3624 unsigned long
3625 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3626 {
3627+ if ((long)n < 0)
3628+ return n;
3629+
3630 prefetch(from);
3631 if (access_ok(VERIFY_WRITE, to, n))
3632 __copy_user(to,from,n);
3633@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
3634 unsigned long
3635 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
3636 {
3637+ if ((long)n < 0)
3638+ return n;
3639+
3640 prefetchw(to);
3641 if (access_ok(VERIFY_READ, from, n))
3642 __copy_user_zeroing(to,from,n);
3643diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
3644index 0395c51..5f26031 100644
3645--- a/arch/m68k/include/asm/cache.h
3646+++ b/arch/m68k/include/asm/cache.h
3647@@ -4,9 +4,11 @@
3648 #ifndef __ARCH_M68K_CACHE_H
3649 #define __ARCH_M68K_CACHE_H
3650
3651+#include <linux/const.h>
3652+
3653 /* bytes per L1 cache line */
3654 #define L1_CACHE_SHIFT 4
3655-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
3656+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3657
3658 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
3659
3660diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
3661index 4efe96a..60e8699 100644
3662--- a/arch/microblaze/include/asm/cache.h
3663+++ b/arch/microblaze/include/asm/cache.h
3664@@ -13,11 +13,12 @@
3665 #ifndef _ASM_MICROBLAZE_CACHE_H
3666 #define _ASM_MICROBLAZE_CACHE_H
3667
3668+#include <linux/const.h>
3669 #include <asm/registers.h>
3670
3671 #define L1_CACHE_SHIFT 5
3672 /* word-granular cache in microblaze */
3673-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3674+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3675
3676 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3677
3678diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
3679index 01cc6ba..bcb7a5d 100644
3680--- a/arch/mips/include/asm/atomic.h
3681+++ b/arch/mips/include/asm/atomic.h
3682@@ -21,6 +21,10 @@
3683 #include <asm/cmpxchg.h>
3684 #include <asm/war.h>
3685
3686+#ifdef CONFIG_GENERIC_ATOMIC64
3687+#include <asm-generic/atomic64.h>
3688+#endif
3689+
3690 #define ATOMIC_INIT(i) { (i) }
3691
3692 /*
3693@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3694 */
3695 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
3696
3697+#define atomic64_read_unchecked(v) atomic64_read(v)
3698+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3699+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3700+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3701+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3702+#define atomic64_inc_unchecked(v) atomic64_inc(v)
3703+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3704+#define atomic64_dec_unchecked(v) atomic64_dec(v)
3705+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3706+
3707 #endif /* CONFIG_64BIT */
3708
3709 /*
3710diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
3711index b4db69f..8f3b093 100644
3712--- a/arch/mips/include/asm/cache.h
3713+++ b/arch/mips/include/asm/cache.h
3714@@ -9,10 +9,11 @@
3715 #ifndef _ASM_CACHE_H
3716 #define _ASM_CACHE_H
3717
3718+#include <linux/const.h>
3719 #include <kmalloc.h>
3720
3721 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
3722-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3723+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3724
3725 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
3726 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3727diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
3728index 455c0ac..ad65fbe 100644
3729--- a/arch/mips/include/asm/elf.h
3730+++ b/arch/mips/include/asm/elf.h
3731@@ -372,13 +372,16 @@ extern const char *__elf_platform;
3732 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
3733 #endif
3734
3735+#ifdef CONFIG_PAX_ASLR
3736+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3737+
3738+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3739+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3740+#endif
3741+
3742 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
3743 struct linux_binprm;
3744 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3745 int uses_interp);
3746
3747-struct mm_struct;
3748-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3749-#define arch_randomize_brk arch_randomize_brk
3750-
3751 #endif /* _ASM_ELF_H */
3752diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
3753index c1f6afa..38cc6e9 100644
3754--- a/arch/mips/include/asm/exec.h
3755+++ b/arch/mips/include/asm/exec.h
3756@@ -12,6 +12,6 @@
3757 #ifndef _ASM_EXEC_H
3758 #define _ASM_EXEC_H
3759
3760-extern unsigned long arch_align_stack(unsigned long sp);
3761+#define arch_align_stack(x) ((x) & ~0xfUL)
3762
3763 #endif /* _ASM_EXEC_H */
3764diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
3765index da9bd7d..91aa7ab 100644
3766--- a/arch/mips/include/asm/page.h
3767+++ b/arch/mips/include/asm/page.h
3768@@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
3769 #ifdef CONFIG_CPU_MIPS32
3770 typedef struct { unsigned long pte_low, pte_high; } pte_t;
3771 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
3772- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
3773+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
3774 #else
3775 typedef struct { unsigned long long pte; } pte_t;
3776 #define pte_val(x) ((x).pte)
3777diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
3778index 881d18b..cea38bc 100644
3779--- a/arch/mips/include/asm/pgalloc.h
3780+++ b/arch/mips/include/asm/pgalloc.h
3781@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3782 {
3783 set_pud(pud, __pud((unsigned long)pmd));
3784 }
3785+
3786+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3787+{
3788+ pud_populate(mm, pud, pmd);
3789+}
3790 #endif
3791
3792 /*
3793diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
3794index 18806a5..141ffcf 100644
3795--- a/arch/mips/include/asm/thread_info.h
3796+++ b/arch/mips/include/asm/thread_info.h
3797@@ -110,6 +110,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
3798 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
3799 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
3800 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
3801+/* li takes a 32bit immediate */
3802+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
3803 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
3804
3805 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3806@@ -125,15 +127,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
3807 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
3808 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
3809 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
3810+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3811+
3812+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3813
3814 /* work to do in syscall_trace_leave() */
3815-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
3816+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
3817
3818 /* work to do on interrupt/exception return */
3819 #define _TIF_WORK_MASK \
3820 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
3821 /* work to do on any return to u-space */
3822-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
3823+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
3824
3825 #endif /* __KERNEL__ */
3826
3827diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
3828index 9fdd8bc..4bd7f1a 100644
3829--- a/arch/mips/kernel/binfmt_elfn32.c
3830+++ b/arch/mips/kernel/binfmt_elfn32.c
3831@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3832 #undef ELF_ET_DYN_BASE
3833 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3834
3835+#ifdef CONFIG_PAX_ASLR
3836+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3837+
3838+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3839+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3840+#endif
3841+
3842 #include <asm/processor.h>
3843 #include <linux/module.h>
3844 #include <linux/elfcore.h>
3845diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
3846index ff44823..97f8906 100644
3847--- a/arch/mips/kernel/binfmt_elfo32.c
3848+++ b/arch/mips/kernel/binfmt_elfo32.c
3849@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
3850 #undef ELF_ET_DYN_BASE
3851 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
3852
3853+#ifdef CONFIG_PAX_ASLR
3854+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
3855+
3856+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3857+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
3858+#endif
3859+
3860 #include <asm/processor.h>
3861
3862 /*
3863diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
3864index 69b17a9..9db82f9 100644
3865--- a/arch/mips/kernel/process.c
3866+++ b/arch/mips/kernel/process.c
3867@@ -478,15 +478,3 @@ unsigned long get_wchan(struct task_struct *task)
3868 out:
3869 return pc;
3870 }
3871-
3872-/*
3873- * Don't forget that the stack pointer must be aligned on a 8 bytes
3874- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
3875- */
3876-unsigned long arch_align_stack(unsigned long sp)
3877-{
3878- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3879- sp -= get_random_int() & ~PAGE_MASK;
3880-
3881- return sp & ALMASK;
3882-}
3883diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3884index 4812c6d..2069554 100644
3885--- a/arch/mips/kernel/ptrace.c
3886+++ b/arch/mips/kernel/ptrace.c
3887@@ -528,6 +528,10 @@ static inline int audit_arch(void)
3888 return arch;
3889 }
3890
3891+#ifdef CONFIG_GRKERNSEC_SETXID
3892+extern void gr_delayed_cred_worker(void);
3893+#endif
3894+
3895 /*
3896 * Notification of system call entry/exit
3897 * - triggered by current->work.syscall_trace
3898@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3899 /* do the secure computing check first */
3900 secure_computing_strict(regs->regs[2]);
3901
3902+#ifdef CONFIG_GRKERNSEC_SETXID
3903+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3904+ gr_delayed_cred_worker();
3905+#endif
3906+
3907 if (!(current->ptrace & PT_PTRACED))
3908 goto out;
3909
3910diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3911index 374f66e..1c882a0 100644
3912--- a/arch/mips/kernel/scall32-o32.S
3913+++ b/arch/mips/kernel/scall32-o32.S
3914@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3915
3916 stack_done:
3917 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3918- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3919+ li t1, _TIF_SYSCALL_WORK
3920 and t0, t1
3921 bnez t0, syscall_trace_entry # -> yes
3922
3923diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3924index 169de6a..f594a89 100644
3925--- a/arch/mips/kernel/scall64-64.S
3926+++ b/arch/mips/kernel/scall64-64.S
3927@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3928
3929 sd a3, PT_R26(sp) # save a3 for syscall restarting
3930
3931- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3932+ li t1, _TIF_SYSCALL_WORK
3933 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3934 and t0, t1, t0
3935 bnez t0, syscall_trace_entry
3936diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3937index 86ec03f..1235baf 100644
3938--- a/arch/mips/kernel/scall64-n32.S
3939+++ b/arch/mips/kernel/scall64-n32.S
3940@@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3941
3942 sd a3, PT_R26(sp) # save a3 for syscall restarting
3943
3944- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3945+ li t1, _TIF_SYSCALL_WORK
3946 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3947 and t0, t1, t0
3948 bnez t0, n32_syscall_trace_entry
3949diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3950index 53c2d72..3734584 100644
3951--- a/arch/mips/kernel/scall64-o32.S
3952+++ b/arch/mips/kernel/scall64-o32.S
3953@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3954 PTR 4b, bad_stack
3955 .previous
3956
3957- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3958+ li t1, _TIF_SYSCALL_WORK
3959 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3960 and t0, t1, t0
3961 bnez t0, trace_a_syscall
3962diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3963index ddcec1e..c7f983e 100644
3964--- a/arch/mips/mm/fault.c
3965+++ b/arch/mips/mm/fault.c
3966@@ -27,6 +27,23 @@
3967 #include <asm/highmem.h> /* For VMALLOC_END */
3968 #include <linux/kdebug.h>
3969
3970+#ifdef CONFIG_PAX_PAGEEXEC
3971+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3972+{
3973+ unsigned long i;
3974+
3975+ printk(KERN_ERR "PAX: bytes at PC: ");
3976+ for (i = 0; i < 5; i++) {
3977+ unsigned int c;
3978+ if (get_user(c, (unsigned int *)pc+i))
3979+ printk(KERN_CONT "???????? ");
3980+ else
3981+ printk(KERN_CONT "%08x ", c);
3982+ }
3983+ printk("\n");
3984+}
3985+#endif
3986+
3987 /*
3988 * This routine handles page faults. It determines the address,
3989 * and the problem, and then passes it off to one of the appropriate
3990diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3991index 302d779..573314a 100644
3992--- a/arch/mips/mm/mmap.c
3993+++ b/arch/mips/mm/mmap.c
3994@@ -71,6 +71,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3995 struct vm_area_struct *vma;
3996 unsigned long addr = addr0;
3997 int do_color_align;
3998+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3999
4000 if (unlikely(len > TASK_SIZE))
4001 return -ENOMEM;
4002@@ -95,6 +96,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4003 do_color_align = 1;
4004
4005 /* requesting a specific address */
4006+
4007+#ifdef CONFIG_PAX_RANDMMAP
4008+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
4009+#endif
4010+
4011 if (addr) {
4012 if (do_color_align)
4013 addr = COLOUR_ALIGN(addr, pgoff);
4014@@ -102,8 +108,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4015 addr = PAGE_ALIGN(addr);
4016
4017 vma = find_vma(mm, addr);
4018- if (TASK_SIZE - len >= addr &&
4019- (!vma || addr + len <= vma->vm_start))
4020+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
4021 return addr;
4022 }
4023
4024@@ -118,7 +123,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4025 /* At this point: (!vma || addr < vma->vm_end). */
4026 if (TASK_SIZE - len < addr)
4027 return -ENOMEM;
4028- if (!vma || addr + len <= vma->vm_start)
4029+ if (check_heap_stack_gap(vmm, addr, len, offset))
4030 return addr;
4031 addr = vma->vm_end;
4032 if (do_color_align)
4033@@ -145,7 +150,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4034 /* make sure it can fit in the remaining address space */
4035 if (likely(addr > len)) {
4036 vma = find_vma(mm, addr - len);
4037- if (!vma || addr <= vma->vm_start) {
4038+ if (check_heap_stack_gap(vmm, addr - len, len, offset))
4039 /* cache the address as a hint for next time */
4040 return mm->free_area_cache = addr - len;
4041 }
4042@@ -155,17 +160,17 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4043 goto bottomup;
4044
4045 addr = mm->mmap_base - len;
4046- if (do_color_align)
4047- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4048
4049 do {
4050+ if (do_color_align)
4051+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4052 /*
4053 * Lookup failure means no vma is above this address,
4054 * else if new region fits below vma->vm_start,
4055 * return with success:
4056 */
4057 vma = find_vma(mm, addr);
4058- if (likely(!vma || addr + len <= vma->vm_start)) {
4059+ if (check_heap_stack_gap(vmm, addr, len, offset)) {
4060 /* cache the address as a hint for next time */
4061 return mm->free_area_cache = addr;
4062 }
4063@@ -175,10 +180,8 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
4064 mm->cached_hole_size = vma->vm_start - addr;
4065
4066 /* try just below the current vma->vm_start */
4067- addr = vma->vm_start - len;
4068- if (do_color_align)
4069- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
4070- } while (likely(len < vma->vm_start));
4071+ addr = skip_heap_stack_gap(vma, len, offset);
4072+ } while (!IS_ERR_VALUE(addr));
4073
4074 bottomup:
4075 /*
4076@@ -242,30 +245,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4077 mm->unmap_area = arch_unmap_area_topdown;
4078 }
4079 }
4080-
4081-static inline unsigned long brk_rnd(void)
4082-{
4083- unsigned long rnd = get_random_int();
4084-
4085- rnd = rnd << PAGE_SHIFT;
4086- /* 8MB for 32bit, 256MB for 64bit */
4087- if (TASK_IS_32BIT_ADDR)
4088- rnd = rnd & 0x7ffffful;
4089- else
4090- rnd = rnd & 0xffffffful;
4091-
4092- return rnd;
4093-}
4094-
4095-unsigned long arch_randomize_brk(struct mm_struct *mm)
4096-{
4097- unsigned long base = mm->brk;
4098- unsigned long ret;
4099-
4100- ret = PAGE_ALIGN(base + brk_rnd());
4101-
4102- if (ret < mm->brk)
4103- return mm->brk;
4104-
4105- return ret;
4106-}
4107diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4108index 967d144..db12197 100644
4109--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
4110+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
4111@@ -11,12 +11,14 @@
4112 #ifndef _ASM_PROC_CACHE_H
4113 #define _ASM_PROC_CACHE_H
4114
4115+#include <linux/const.h>
4116+
4117 /* L1 cache */
4118
4119 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4120 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
4121-#define L1_CACHE_BYTES 16 /* bytes per entry */
4122 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
4123+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4124 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
4125
4126 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4127diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4128index bcb5df2..84fabd2 100644
4129--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4130+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
4131@@ -16,13 +16,15 @@
4132 #ifndef _ASM_PROC_CACHE_H
4133 #define _ASM_PROC_CACHE_H
4134
4135+#include <linux/const.h>
4136+
4137 /*
4138 * L1 cache
4139 */
4140 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
4141 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
4142-#define L1_CACHE_BYTES 32 /* bytes per entry */
4143 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
4144+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
4145 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
4146
4147 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
4148diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
4149index 4ce7a01..449202a 100644
4150--- a/arch/openrisc/include/asm/cache.h
4151+++ b/arch/openrisc/include/asm/cache.h
4152@@ -19,11 +19,13 @@
4153 #ifndef __ASM_OPENRISC_CACHE_H
4154 #define __ASM_OPENRISC_CACHE_H
4155
4156+#include <linux/const.h>
4157+
4158 /* FIXME: How can we replace these with values from the CPU...
4159 * they shouldn't be hard-coded!
4160 */
4161
4162-#define L1_CACHE_BYTES 16
4163 #define L1_CACHE_SHIFT 4
4164+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4165
4166 #endif /* __ASM_OPENRISC_CACHE_H */
4167diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
4168index af9cf30..2aae9b2 100644
4169--- a/arch/parisc/include/asm/atomic.h
4170+++ b/arch/parisc/include/asm/atomic.h
4171@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
4172
4173 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4174
4175+#define atomic64_read_unchecked(v) atomic64_read(v)
4176+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4177+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4178+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4179+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4180+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4181+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4182+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4183+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4184+
4185 #endif /* !CONFIG_64BIT */
4186
4187
4188diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
4189index 47f11c7..3420df2 100644
4190--- a/arch/parisc/include/asm/cache.h
4191+++ b/arch/parisc/include/asm/cache.h
4192@@ -5,6 +5,7 @@
4193 #ifndef __ARCH_PARISC_CACHE_H
4194 #define __ARCH_PARISC_CACHE_H
4195
4196+#include <linux/const.h>
4197
4198 /*
4199 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
4200@@ -15,13 +16,13 @@
4201 * just ruin performance.
4202 */
4203 #ifdef CONFIG_PA20
4204-#define L1_CACHE_BYTES 64
4205 #define L1_CACHE_SHIFT 6
4206 #else
4207-#define L1_CACHE_BYTES 32
4208 #define L1_CACHE_SHIFT 5
4209 #endif
4210
4211+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4212+
4213 #ifndef __ASSEMBLY__
4214
4215 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4216diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
4217index 19f6cb1..6c78cf2 100644
4218--- a/arch/parisc/include/asm/elf.h
4219+++ b/arch/parisc/include/asm/elf.h
4220@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
4221
4222 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
4223
4224+#ifdef CONFIG_PAX_ASLR
4225+#define PAX_ELF_ET_DYN_BASE 0x10000UL
4226+
4227+#define PAX_DELTA_MMAP_LEN 16
4228+#define PAX_DELTA_STACK_LEN 16
4229+#endif
4230+
4231 /* This yields a mask that user programs can use to figure out what
4232 instruction set this CPU supports. This could be done in user space,
4233 but it's not easy, and we've already done it here. */
4234diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
4235index fc987a1..6e068ef 100644
4236--- a/arch/parisc/include/asm/pgalloc.h
4237+++ b/arch/parisc/include/asm/pgalloc.h
4238@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4239 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
4240 }
4241
4242+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
4243+{
4244+ pgd_populate(mm, pgd, pmd);
4245+}
4246+
4247 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
4248 {
4249 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
4250@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
4251 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
4252 #define pmd_free(mm, x) do { } while (0)
4253 #define pgd_populate(mm, pmd, pte) BUG()
4254+#define pgd_populate_kernel(mm, pmd, pte) BUG()
4255
4256 #endif
4257
4258diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
4259index ee99f23..802b0a1 100644
4260--- a/arch/parisc/include/asm/pgtable.h
4261+++ b/arch/parisc/include/asm/pgtable.h
4262@@ -212,6 +212,17 @@ struct vm_area_struct;
4263 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
4264 #define PAGE_COPY PAGE_EXECREAD
4265 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
4266+
4267+#ifdef CONFIG_PAX_PAGEEXEC
4268+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
4269+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4270+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
4271+#else
4272+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4273+# define PAGE_COPY_NOEXEC PAGE_COPY
4274+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4275+#endif
4276+
4277 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
4278 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
4279 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
4280diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
4281index 4ba2c93..f5e3974 100644
4282--- a/arch/parisc/include/asm/uaccess.h
4283+++ b/arch/parisc/include/asm/uaccess.h
4284@@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
4285 const void __user *from,
4286 unsigned long n)
4287 {
4288- int sz = __compiletime_object_size(to);
4289+ size_t sz = __compiletime_object_size(to);
4290 int ret = -EFAULT;
4291
4292- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
4293+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
4294 ret = __copy_from_user(to, from, n);
4295 else
4296 copy_from_user_overflow();
4297diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
4298index 5e34ccf..672bc9c 100644
4299--- a/arch/parisc/kernel/module.c
4300+++ b/arch/parisc/kernel/module.c
4301@@ -98,16 +98,38 @@
4302
4303 /* three functions to determine where in the module core
4304 * or init pieces the location is */
4305+static inline int in_init_rx(struct module *me, void *loc)
4306+{
4307+ return (loc >= me->module_init_rx &&
4308+ loc < (me->module_init_rx + me->init_size_rx));
4309+}
4310+
4311+static inline int in_init_rw(struct module *me, void *loc)
4312+{
4313+ return (loc >= me->module_init_rw &&
4314+ loc < (me->module_init_rw + me->init_size_rw));
4315+}
4316+
4317 static inline int in_init(struct module *me, void *loc)
4318 {
4319- return (loc >= me->module_init &&
4320- loc <= (me->module_init + me->init_size));
4321+ return in_init_rx(me, loc) || in_init_rw(me, loc);
4322+}
4323+
4324+static inline int in_core_rx(struct module *me, void *loc)
4325+{
4326+ return (loc >= me->module_core_rx &&
4327+ loc < (me->module_core_rx + me->core_size_rx));
4328+}
4329+
4330+static inline int in_core_rw(struct module *me, void *loc)
4331+{
4332+ return (loc >= me->module_core_rw &&
4333+ loc < (me->module_core_rw + me->core_size_rw));
4334 }
4335
4336 static inline int in_core(struct module *me, void *loc)
4337 {
4338- return (loc >= me->module_core &&
4339- loc <= (me->module_core + me->core_size));
4340+ return in_core_rx(me, loc) || in_core_rw(me, loc);
4341 }
4342
4343 static inline int in_local(struct module *me, void *loc)
4344@@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
4345 }
4346
4347 /* align things a bit */
4348- me->core_size = ALIGN(me->core_size, 16);
4349- me->arch.got_offset = me->core_size;
4350- me->core_size += gots * sizeof(struct got_entry);
4351+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4352+ me->arch.got_offset = me->core_size_rw;
4353+ me->core_size_rw += gots * sizeof(struct got_entry);
4354
4355- me->core_size = ALIGN(me->core_size, 16);
4356- me->arch.fdesc_offset = me->core_size;
4357- me->core_size += fdescs * sizeof(Elf_Fdesc);
4358+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
4359+ me->arch.fdesc_offset = me->core_size_rw;
4360+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
4361
4362 me->arch.got_max = gots;
4363 me->arch.fdesc_max = fdescs;
4364@@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4365
4366 BUG_ON(value == 0);
4367
4368- got = me->module_core + me->arch.got_offset;
4369+ got = me->module_core_rw + me->arch.got_offset;
4370 for (i = 0; got[i].addr; i++)
4371 if (got[i].addr == value)
4372 goto out;
4373@@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
4374 #ifdef CONFIG_64BIT
4375 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4376 {
4377- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
4378+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
4379
4380 if (!value) {
4381 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
4382@@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
4383
4384 /* Create new one */
4385 fdesc->addr = value;
4386- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4387+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4388 return (Elf_Addr)fdesc;
4389 }
4390 #endif /* CONFIG_64BIT */
4391@@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
4392
4393 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
4394 end = table + sechdrs[me->arch.unwind_section].sh_size;
4395- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
4396+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
4397
4398 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
4399 me->arch.unwind_section, table, end, gp);
4400diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
4401index f76c108..92bad82 100644
4402--- a/arch/parisc/kernel/sys_parisc.c
4403+++ b/arch/parisc/kernel/sys_parisc.c
4404@@ -33,9 +33,11 @@
4405 #include <linux/utsname.h>
4406 #include <linux/personality.h>
4407
4408-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4409+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
4410+ unsigned long flags)
4411 {
4412 struct vm_area_struct *vma;
4413+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4414
4415 addr = PAGE_ALIGN(addr);
4416
4417@@ -43,7 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
4418 /* At this point: (!vma || addr < vma->vm_end). */
4419 if (TASK_SIZE - len < addr)
4420 return -ENOMEM;
4421- if (!vma || addr + len <= vma->vm_start)
4422+ if (check_heap_stack_gap(vma, addr, len, offset))
4423 return addr;
4424 addr = vma->vm_end;
4425 }
4426@@ -67,11 +69,12 @@ static int get_offset(struct address_space *mapping)
4427 return offset & 0x3FF000;
4428 }
4429
4430-static unsigned long get_shared_area(struct address_space *mapping,
4431- unsigned long addr, unsigned long len, unsigned long pgoff)
4432+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
4433+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
4434 {
4435 struct vm_area_struct *vma;
4436 int offset = mapping ? get_offset(mapping) : 0;
4437+ unsigned long rand_offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4438
4439 offset = (offset + (pgoff << PAGE_SHIFT)) & 0x3FF000;
4440
4441@@ -81,7 +84,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
4442 /* At this point: (!vma || addr < vma->vm_end). */
4443 if (TASK_SIZE - len < addr)
4444 return -ENOMEM;
4445- if (!vma || addr + len <= vma->vm_start)
4446+ if (check_heap_stack_gap(vma, addr, len, rand_offset))
4447 return addr;
4448 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
4449 if (addr < vma->vm_end) /* handle wraparound */
4450@@ -100,14 +103,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
4451 if (flags & MAP_FIXED)
4452 return addr;
4453 if (!addr)
4454- addr = TASK_UNMAPPED_BASE;
4455+ addr = current->mm->mmap_base;
4456
4457 if (filp) {
4458- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
4459+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
4460 } else if(flags & MAP_SHARED) {
4461- addr = get_shared_area(NULL, addr, len, pgoff);
4462+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
4463 } else {
4464- addr = get_unshared_area(addr, len);
4465+ addr = get_unshared_area(filp, addr, len, flags);
4466 }
4467 return addr;
4468 }
4469diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
4470index 45ba99f..8e22c33 100644
4471--- a/arch/parisc/kernel/traps.c
4472+++ b/arch/parisc/kernel/traps.c
4473@@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
4474
4475 down_read(&current->mm->mmap_sem);
4476 vma = find_vma(current->mm,regs->iaoq[0]);
4477- if (vma && (regs->iaoq[0] >= vma->vm_start)
4478- && (vma->vm_flags & VM_EXEC)) {
4479-
4480+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
4481 fault_address = regs->iaoq[0];
4482 fault_space = regs->iasq[0];
4483
4484diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
4485index 18162ce..94de376 100644
4486--- a/arch/parisc/mm/fault.c
4487+++ b/arch/parisc/mm/fault.c
4488@@ -15,6 +15,7 @@
4489 #include <linux/sched.h>
4490 #include <linux/interrupt.h>
4491 #include <linux/module.h>
4492+#include <linux/unistd.h>
4493
4494 #include <asm/uaccess.h>
4495 #include <asm/traps.h>
4496@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
4497 static unsigned long
4498 parisc_acctyp(unsigned long code, unsigned int inst)
4499 {
4500- if (code == 6 || code == 16)
4501+ if (code == 6 || code == 7 || code == 16)
4502 return VM_EXEC;
4503
4504 switch (inst & 0xf0000000) {
4505@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
4506 }
4507 #endif
4508
4509+#ifdef CONFIG_PAX_PAGEEXEC
4510+/*
4511+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
4512+ *
4513+ * returns 1 when task should be killed
4514+ * 2 when rt_sigreturn trampoline was detected
4515+ * 3 when unpatched PLT trampoline was detected
4516+ */
4517+static int pax_handle_fetch_fault(struct pt_regs *regs)
4518+{
4519+
4520+#ifdef CONFIG_PAX_EMUPLT
4521+ int err;
4522+
4523+ do { /* PaX: unpatched PLT emulation */
4524+ unsigned int bl, depwi;
4525+
4526+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
4527+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
4528+
4529+ if (err)
4530+ break;
4531+
4532+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
4533+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
4534+
4535+ err = get_user(ldw, (unsigned int *)addr);
4536+ err |= get_user(bv, (unsigned int *)(addr+4));
4537+ err |= get_user(ldw2, (unsigned int *)(addr+8));
4538+
4539+ if (err)
4540+ break;
4541+
4542+ if (ldw == 0x0E801096U &&
4543+ bv == 0xEAC0C000U &&
4544+ ldw2 == 0x0E881095U)
4545+ {
4546+ unsigned int resolver, map;
4547+
4548+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
4549+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
4550+ if (err)
4551+ break;
4552+
4553+ regs->gr[20] = instruction_pointer(regs)+8;
4554+ regs->gr[21] = map;
4555+ regs->gr[22] = resolver;
4556+ regs->iaoq[0] = resolver | 3UL;
4557+ regs->iaoq[1] = regs->iaoq[0] + 4;
4558+ return 3;
4559+ }
4560+ }
4561+ } while (0);
4562+#endif
4563+
4564+#ifdef CONFIG_PAX_EMUTRAMP
4565+
4566+#ifndef CONFIG_PAX_EMUSIGRT
4567+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
4568+ return 1;
4569+#endif
4570+
4571+ do { /* PaX: rt_sigreturn emulation */
4572+ unsigned int ldi1, ldi2, bel, nop;
4573+
4574+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
4575+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
4576+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
4577+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
4578+
4579+ if (err)
4580+ break;
4581+
4582+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
4583+ ldi2 == 0x3414015AU &&
4584+ bel == 0xE4008200U &&
4585+ nop == 0x08000240U)
4586+ {
4587+ regs->gr[25] = (ldi1 & 2) >> 1;
4588+ regs->gr[20] = __NR_rt_sigreturn;
4589+ regs->gr[31] = regs->iaoq[1] + 16;
4590+ regs->sr[0] = regs->iasq[1];
4591+ regs->iaoq[0] = 0x100UL;
4592+ regs->iaoq[1] = regs->iaoq[0] + 4;
4593+ regs->iasq[0] = regs->sr[2];
4594+ regs->iasq[1] = regs->sr[2];
4595+ return 2;
4596+ }
4597+ } while (0);
4598+#endif
4599+
4600+ return 1;
4601+}
4602+
4603+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4604+{
4605+ unsigned long i;
4606+
4607+ printk(KERN_ERR "PAX: bytes at PC: ");
4608+ for (i = 0; i < 5; i++) {
4609+ unsigned int c;
4610+ if (get_user(c, (unsigned int *)pc+i))
4611+ printk(KERN_CONT "???????? ");
4612+ else
4613+ printk(KERN_CONT "%08x ", c);
4614+ }
4615+ printk("\n");
4616+}
4617+#endif
4618+
4619 int fixup_exception(struct pt_regs *regs)
4620 {
4621 const struct exception_table_entry *fix;
4622@@ -192,8 +303,33 @@ good_area:
4623
4624 acc_type = parisc_acctyp(code,regs->iir);
4625
4626- if ((vma->vm_flags & acc_type) != acc_type)
4627+ if ((vma->vm_flags & acc_type) != acc_type) {
4628+
4629+#ifdef CONFIG_PAX_PAGEEXEC
4630+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
4631+ (address & ~3UL) == instruction_pointer(regs))
4632+ {
4633+ up_read(&mm->mmap_sem);
4634+ switch (pax_handle_fetch_fault(regs)) {
4635+
4636+#ifdef CONFIG_PAX_EMUPLT
4637+ case 3:
4638+ return;
4639+#endif
4640+
4641+#ifdef CONFIG_PAX_EMUTRAMP
4642+ case 2:
4643+ return;
4644+#endif
4645+
4646+ }
4647+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
4648+ do_group_exit(SIGKILL);
4649+ }
4650+#endif
4651+
4652 goto bad_area;
4653+ }
4654
4655 /*
4656 * If for any reason at all we couldn't handle the fault, make
4657diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
4658index e3b1d41..8e81edf 100644
4659--- a/arch/powerpc/include/asm/atomic.h
4660+++ b/arch/powerpc/include/asm/atomic.h
4661@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
4662 return t1;
4663 }
4664
4665+#define atomic64_read_unchecked(v) atomic64_read(v)
4666+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4667+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4668+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4669+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4670+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4671+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4672+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4673+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4674+
4675 #endif /* __powerpc64__ */
4676
4677 #endif /* __KERNEL__ */
4678diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
4679index 9e495c9..b6878e5 100644
4680--- a/arch/powerpc/include/asm/cache.h
4681+++ b/arch/powerpc/include/asm/cache.h
4682@@ -3,6 +3,7 @@
4683
4684 #ifdef __KERNEL__
4685
4686+#include <linux/const.h>
4687
4688 /* bytes per L1 cache line */
4689 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
4690@@ -22,7 +23,7 @@
4691 #define L1_CACHE_SHIFT 7
4692 #endif
4693
4694-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4695+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4696
4697 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4698
4699diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
4700index 6abf0a1..459d0f1 100644
4701--- a/arch/powerpc/include/asm/elf.h
4702+++ b/arch/powerpc/include/asm/elf.h
4703@@ -28,8 +28,19 @@
4704 the loader. We need to make sure that it is out of the way of the program
4705 that it will "exec", and that there is sufficient room for the brk. */
4706
4707-extern unsigned long randomize_et_dyn(unsigned long base);
4708-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
4709+#define ELF_ET_DYN_BASE (0x20000000)
4710+
4711+#ifdef CONFIG_PAX_ASLR
4712+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
4713+
4714+#ifdef __powerpc64__
4715+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
4716+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
4717+#else
4718+#define PAX_DELTA_MMAP_LEN 15
4719+#define PAX_DELTA_STACK_LEN 15
4720+#endif
4721+#endif
4722
4723 /*
4724 * Our registers are always unsigned longs, whether we're a 32 bit
4725@@ -124,10 +135,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
4726 (0x7ff >> (PAGE_SHIFT - 12)) : \
4727 (0x3ffff >> (PAGE_SHIFT - 12)))
4728
4729-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4730-#define arch_randomize_brk arch_randomize_brk
4731-
4732-
4733 #ifdef CONFIG_SPU_BASE
4734 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
4735 #define NT_SPU 1
4736diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
4737index 8196e9c..d83a9f3 100644
4738--- a/arch/powerpc/include/asm/exec.h
4739+++ b/arch/powerpc/include/asm/exec.h
4740@@ -4,6 +4,6 @@
4741 #ifndef _ASM_POWERPC_EXEC_H
4742 #define _ASM_POWERPC_EXEC_H
4743
4744-extern unsigned long arch_align_stack(unsigned long sp);
4745+#define arch_align_stack(x) ((x) & ~0xfUL)
4746
4747 #endif /* _ASM_POWERPC_EXEC_H */
4748diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
4749index 5acabbd..7ea14fa 100644
4750--- a/arch/powerpc/include/asm/kmap_types.h
4751+++ b/arch/powerpc/include/asm/kmap_types.h
4752@@ -10,7 +10,7 @@
4753 * 2 of the License, or (at your option) any later version.
4754 */
4755
4756-#define KM_TYPE_NR 16
4757+#define KM_TYPE_NR 17
4758
4759 #endif /* __KERNEL__ */
4760 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
4761diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
4762index 8565c25..2865190 100644
4763--- a/arch/powerpc/include/asm/mman.h
4764+++ b/arch/powerpc/include/asm/mman.h
4765@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
4766 }
4767 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
4768
4769-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
4770+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
4771 {
4772 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
4773 }
4774diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
4775index f072e97..b436dee 100644
4776--- a/arch/powerpc/include/asm/page.h
4777+++ b/arch/powerpc/include/asm/page.h
4778@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
4779 * and needs to be executable. This means the whole heap ends
4780 * up being executable.
4781 */
4782-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4783- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4784+#define VM_DATA_DEFAULT_FLAGS32 \
4785+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4786+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4787
4788 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4789 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4790@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
4791 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
4792 #endif
4793
4794+#define ktla_ktva(addr) (addr)
4795+#define ktva_ktla(addr) (addr)
4796+
4797 /*
4798 * Use the top bit of the higher-level page table entries to indicate whether
4799 * the entries we point to contain hugepages. This works because we know that
4800diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
4801index cd915d6..c10cee8 100644
4802--- a/arch/powerpc/include/asm/page_64.h
4803+++ b/arch/powerpc/include/asm/page_64.h
4804@@ -154,15 +154,18 @@ do { \
4805 * stack by default, so in the absence of a PT_GNU_STACK program header
4806 * we turn execute permission off.
4807 */
4808-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
4809- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4810+#define VM_STACK_DEFAULT_FLAGS32 \
4811+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
4812+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4813
4814 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
4815 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
4816
4817+#ifndef CONFIG_PAX_PAGEEXEC
4818 #define VM_STACK_DEFAULT_FLAGS \
4819 (is_32bit_task() ? \
4820 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
4821+#endif
4822
4823 #include <asm-generic/getorder.h>
4824
4825diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
4826index 292725c..f87ae14 100644
4827--- a/arch/powerpc/include/asm/pgalloc-64.h
4828+++ b/arch/powerpc/include/asm/pgalloc-64.h
4829@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
4830 #ifndef CONFIG_PPC_64K_PAGES
4831
4832 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
4833+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
4834
4835 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4836 {
4837@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4838 pud_set(pud, (unsigned long)pmd);
4839 }
4840
4841+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4842+{
4843+ pud_populate(mm, pud, pmd);
4844+}
4845+
4846 #define pmd_populate(mm, pmd, pte_page) \
4847 pmd_populate_kernel(mm, pmd, page_address(pte_page))
4848 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
4849@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
4850 #else /* CONFIG_PPC_64K_PAGES */
4851
4852 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
4853+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
4854
4855 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
4856 pte_t *pte)
4857diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
4858index a9cbd3b..3b67efa 100644
4859--- a/arch/powerpc/include/asm/pgtable.h
4860+++ b/arch/powerpc/include/asm/pgtable.h
4861@@ -2,6 +2,7 @@
4862 #define _ASM_POWERPC_PGTABLE_H
4863 #ifdef __KERNEL__
4864
4865+#include <linux/const.h>
4866 #ifndef __ASSEMBLY__
4867 #include <asm/processor.h> /* For TASK_SIZE */
4868 #include <asm/mmu.h>
4869diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
4870index 4aad413..85d86bf 100644
4871--- a/arch/powerpc/include/asm/pte-hash32.h
4872+++ b/arch/powerpc/include/asm/pte-hash32.h
4873@@ -21,6 +21,7 @@
4874 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
4875 #define _PAGE_USER 0x004 /* usermode access allowed */
4876 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
4877+#define _PAGE_EXEC _PAGE_GUARDED
4878 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
4879 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
4880 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
4881diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
4882index d24c141..b60696e 100644
4883--- a/arch/powerpc/include/asm/reg.h
4884+++ b/arch/powerpc/include/asm/reg.h
4885@@ -215,6 +215,7 @@
4886 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
4887 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
4888 #define DSISR_NOHPTE 0x40000000 /* no translation found */
4889+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
4890 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
4891 #define DSISR_ISSTORE 0x02000000 /* access was a store */
4892 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
4893diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
4894index 406b7b9..af63426 100644
4895--- a/arch/powerpc/include/asm/thread_info.h
4896+++ b/arch/powerpc/include/asm/thread_info.h
4897@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
4898 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
4899 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
4900 #define TIF_SINGLESTEP 8 /* singlestepping active */
4901-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
4902 #define TIF_SECCOMP 10 /* secure computing */
4903 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
4904 #define TIF_NOERROR 12 /* Force successful syscall return */
4905@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
4906 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
4907 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
4908 for stack store? */
4909+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
4910+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
4911+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
4912
4913 /* as above, but as bit values */
4914 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
4915@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
4916 #define _TIF_UPROBE (1<<TIF_UPROBE)
4917 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
4918 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
4919+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
4920 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
4921- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
4922+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
4923+ _TIF_GRSEC_SETXID)
4924
4925 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
4926 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
4927diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
4928index 4db4959..335e00c 100644
4929--- a/arch/powerpc/include/asm/uaccess.h
4930+++ b/arch/powerpc/include/asm/uaccess.h
4931@@ -13,6 +13,8 @@
4932 #define VERIFY_READ 0
4933 #define VERIFY_WRITE 1
4934
4935+extern void check_object_size(const void *ptr, unsigned long n, bool to);
4936+
4937 /*
4938 * The fs value determines whether argument validity checking should be
4939 * performed or not. If get_fs() == USER_DS, checking is performed, with
4940@@ -318,52 +320,6 @@ do { \
4941 extern unsigned long __copy_tofrom_user(void __user *to,
4942 const void __user *from, unsigned long size);
4943
4944-#ifndef __powerpc64__
4945-
4946-static inline unsigned long copy_from_user(void *to,
4947- const void __user *from, unsigned long n)
4948-{
4949- unsigned long over;
4950-
4951- if (access_ok(VERIFY_READ, from, n))
4952- return __copy_tofrom_user((__force void __user *)to, from, n);
4953- if ((unsigned long)from < TASK_SIZE) {
4954- over = (unsigned long)from + n - TASK_SIZE;
4955- return __copy_tofrom_user((__force void __user *)to, from,
4956- n - over) + over;
4957- }
4958- return n;
4959-}
4960-
4961-static inline unsigned long copy_to_user(void __user *to,
4962- const void *from, unsigned long n)
4963-{
4964- unsigned long over;
4965-
4966- if (access_ok(VERIFY_WRITE, to, n))
4967- return __copy_tofrom_user(to, (__force void __user *)from, n);
4968- if ((unsigned long)to < TASK_SIZE) {
4969- over = (unsigned long)to + n - TASK_SIZE;
4970- return __copy_tofrom_user(to, (__force void __user *)from,
4971- n - over) + over;
4972- }
4973- return n;
4974-}
4975-
4976-#else /* __powerpc64__ */
4977-
4978-#define __copy_in_user(to, from, size) \
4979- __copy_tofrom_user((to), (from), (size))
4980-
4981-extern unsigned long copy_from_user(void *to, const void __user *from,
4982- unsigned long n);
4983-extern unsigned long copy_to_user(void __user *to, const void *from,
4984- unsigned long n);
4985-extern unsigned long copy_in_user(void __user *to, const void __user *from,
4986- unsigned long n);
4987-
4988-#endif /* __powerpc64__ */
4989-
4990 static inline unsigned long __copy_from_user_inatomic(void *to,
4991 const void __user *from, unsigned long n)
4992 {
4993@@ -387,6 +343,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4994 if (ret == 0)
4995 return 0;
4996 }
4997+
4998+ if (!__builtin_constant_p(n))
4999+ check_object_size(to, n, false);
5000+
5001 return __copy_tofrom_user((__force void __user *)to, from, n);
5002 }
5003
5004@@ -413,6 +373,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
5005 if (ret == 0)
5006 return 0;
5007 }
5008+
5009+ if (!__builtin_constant_p(n))
5010+ check_object_size(from, n, true);
5011+
5012 return __copy_tofrom_user(to, (__force const void __user *)from, n);
5013 }
5014
5015@@ -430,6 +394,92 @@ static inline unsigned long __copy_to_user(void __user *to,
5016 return __copy_to_user_inatomic(to, from, size);
5017 }
5018
5019+#ifndef __powerpc64__
5020+
5021+static inline unsigned long __must_check copy_from_user(void *to,
5022+ const void __user *from, unsigned long n)
5023+{
5024+ unsigned long over;
5025+
5026+ if ((long)n < 0)
5027+ return n;
5028+
5029+ if (access_ok(VERIFY_READ, from, n)) {
5030+ if (!__builtin_constant_p(n))
5031+ check_object_size(to, n, false);
5032+ return __copy_tofrom_user((__force void __user *)to, from, n);
5033+ }
5034+ if ((unsigned long)from < TASK_SIZE) {
5035+ over = (unsigned long)from + n - TASK_SIZE;
5036+ if (!__builtin_constant_p(n - over))
5037+ check_object_size(to, n - over, false);
5038+ return __copy_tofrom_user((__force void __user *)to, from,
5039+ n - over) + over;
5040+ }
5041+ return n;
5042+}
5043+
5044+static inline unsigned long __must_check copy_to_user(void __user *to,
5045+ const void *from, unsigned long n)
5046+{
5047+ unsigned long over;
5048+
5049+ if ((long)n < 0)
5050+ return n;
5051+
5052+ if (access_ok(VERIFY_WRITE, to, n)) {
5053+ if (!__builtin_constant_p(n))
5054+ check_object_size(from, n, true);
5055+ return __copy_tofrom_user(to, (__force void __user *)from, n);
5056+ }
5057+ if ((unsigned long)to < TASK_SIZE) {
5058+ over = (unsigned long)to + n - TASK_SIZE;
5059+ if (!__builtin_constant_p(n))
5060+ check_object_size(from, n - over, true);
5061+ return __copy_tofrom_user(to, (__force void __user *)from,
5062+ n - over) + over;
5063+ }
5064+ return n;
5065+}
5066+
5067+#else /* __powerpc64__ */
5068+
5069+#define __copy_in_user(to, from, size) \
5070+ __copy_tofrom_user((to), (from), (size))
5071+
5072+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
5073+{
5074+ if ((long)n < 0 || n > INT_MAX)
5075+ return n;
5076+
5077+ if (!__builtin_constant_p(n))
5078+ check_object_size(to, n, false);
5079+
5080+ if (likely(access_ok(VERIFY_READ, from, n)))
5081+ n = __copy_from_user(to, from, n);
5082+ else
5083+ memset(to, 0, n);
5084+ return n;
5085+}
5086+
5087+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
5088+{
5089+ if ((long)n < 0 || n > INT_MAX)
5090+ return n;
5091+
5092+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
5093+ if (!__builtin_constant_p(n))
5094+ check_object_size(from, n, true);
5095+ n = __copy_to_user(to, from, n);
5096+ }
5097+ return n;
5098+}
5099+
5100+extern unsigned long copy_in_user(void __user *to, const void __user *from,
5101+ unsigned long n);
5102+
5103+#endif /* __powerpc64__ */
5104+
5105 extern unsigned long __clear_user(void __user *addr, unsigned long size);
5106
5107 static inline unsigned long clear_user(void __user *addr, unsigned long size)
5108diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
5109index 4684e33..acc4d19e 100644
5110--- a/arch/powerpc/kernel/exceptions-64e.S
5111+++ b/arch/powerpc/kernel/exceptions-64e.S
5112@@ -715,6 +715,7 @@ storage_fault_common:
5113 std r14,_DAR(r1)
5114 std r15,_DSISR(r1)
5115 addi r3,r1,STACK_FRAME_OVERHEAD
5116+ bl .save_nvgprs
5117 mr r4,r14
5118 mr r5,r15
5119 ld r14,PACA_EXGEN+EX_R14(r13)
5120@@ -723,8 +724,7 @@ storage_fault_common:
5121 cmpdi r3,0
5122 bne- 1f
5123 b .ret_from_except_lite
5124-1: bl .save_nvgprs
5125- mr r5,r3
5126+1: mr r5,r3
5127 addi r3,r1,STACK_FRAME_OVERHEAD
5128 ld r4,_DAR(r1)
5129 bl .bad_page_fault
5130diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
5131index 10b658a..e542888 100644
5132--- a/arch/powerpc/kernel/exceptions-64s.S
5133+++ b/arch/powerpc/kernel/exceptions-64s.S
5134@@ -1013,10 +1013,10 @@ handle_page_fault:
5135 11: ld r4,_DAR(r1)
5136 ld r5,_DSISR(r1)
5137 addi r3,r1,STACK_FRAME_OVERHEAD
5138+ bl .save_nvgprs
5139 bl .do_page_fault
5140 cmpdi r3,0
5141 beq+ 12f
5142- bl .save_nvgprs
5143 mr r5,r3
5144 addi r3,r1,STACK_FRAME_OVERHEAD
5145 lwz r4,_DAR(r1)
5146diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
5147index 2e3200c..72095ce 100644
5148--- a/arch/powerpc/kernel/module_32.c
5149+++ b/arch/powerpc/kernel/module_32.c
5150@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
5151 me->arch.core_plt_section = i;
5152 }
5153 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
5154- printk("Module doesn't contain .plt or .init.plt sections.\n");
5155+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
5156 return -ENOEXEC;
5157 }
5158
5159@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
5160
5161 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
5162 /* Init, or core PLT? */
5163- if (location >= mod->module_core
5164- && location < mod->module_core + mod->core_size)
5165+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
5166+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
5167 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
5168- else
5169+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
5170+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
5171 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
5172+ else {
5173+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
5174+ return ~0UL;
5175+ }
5176
5177 /* Find this entry, or if that fails, the next avail. entry */
5178 while (entry->jump[0]) {
5179diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
5180index ba48233..16ac31d 100644
5181--- a/arch/powerpc/kernel/process.c
5182+++ b/arch/powerpc/kernel/process.c
5183@@ -680,8 +680,8 @@ void show_regs(struct pt_regs * regs)
5184 * Lookup NIP late so we have the best change of getting the
5185 * above info out without failing
5186 */
5187- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
5188- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
5189+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
5190+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
5191 #endif
5192 show_stack(current, (unsigned long *) regs->gpr[1]);
5193 if (!user_mode(regs))
5194@@ -1175,10 +1175,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5195 newsp = stack[0];
5196 ip = stack[STACK_FRAME_LR_SAVE];
5197 if (!firstframe || ip != lr) {
5198- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
5199+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
5200 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
5201 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
5202- printk(" (%pS)",
5203+ printk(" (%pA)",
5204 (void *)current->ret_stack[curr_frame].ret);
5205 curr_frame--;
5206 }
5207@@ -1198,7 +1198,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
5208 struct pt_regs *regs = (struct pt_regs *)
5209 (sp + STACK_FRAME_OVERHEAD);
5210 lr = regs->link;
5211- printk("--- Exception: %lx at %pS\n LR = %pS\n",
5212+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
5213 regs->trap, (void *)regs->nip, (void *)lr);
5214 firstframe = 1;
5215 }
5216@@ -1240,58 +1240,3 @@ void __ppc64_runlatch_off(void)
5217 mtspr(SPRN_CTRLT, ctrl);
5218 }
5219 #endif /* CONFIG_PPC64 */
5220-
5221-unsigned long arch_align_stack(unsigned long sp)
5222-{
5223- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5224- sp -= get_random_int() & ~PAGE_MASK;
5225- return sp & ~0xf;
5226-}
5227-
5228-static inline unsigned long brk_rnd(void)
5229-{
5230- unsigned long rnd = 0;
5231-
5232- /* 8MB for 32bit, 1GB for 64bit */
5233- if (is_32bit_task())
5234- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
5235- else
5236- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
5237-
5238- return rnd << PAGE_SHIFT;
5239-}
5240-
5241-unsigned long arch_randomize_brk(struct mm_struct *mm)
5242-{
5243- unsigned long base = mm->brk;
5244- unsigned long ret;
5245-
5246-#ifdef CONFIG_PPC_STD_MMU_64
5247- /*
5248- * If we are using 1TB segments and we are allowed to randomise
5249- * the heap, we can put it above 1TB so it is backed by a 1TB
5250- * segment. Otherwise the heap will be in the bottom 1TB
5251- * which always uses 256MB segments and this may result in a
5252- * performance penalty.
5253- */
5254- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
5255- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
5256-#endif
5257-
5258- ret = PAGE_ALIGN(base + brk_rnd());
5259-
5260- if (ret < mm->brk)
5261- return mm->brk;
5262-
5263- return ret;
5264-}
5265-
5266-unsigned long randomize_et_dyn(unsigned long base)
5267-{
5268- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5269-
5270- if (ret < base)
5271- return base;
5272-
5273- return ret;
5274-}
5275diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
5276index 79d8e56..38ffcbb 100644
5277--- a/arch/powerpc/kernel/ptrace.c
5278+++ b/arch/powerpc/kernel/ptrace.c
5279@@ -1663,6 +1663,10 @@ long arch_ptrace(struct task_struct *child, long request,
5280 return ret;
5281 }
5282
5283+#ifdef CONFIG_GRKERNSEC_SETXID
5284+extern void gr_delayed_cred_worker(void);
5285+#endif
5286+
5287 /*
5288 * We must return the syscall number to actually look up in the table.
5289 * This can be -1L to skip running any syscall at all.
5290@@ -1673,6 +1677,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
5291
5292 secure_computing_strict(regs->gpr[0]);
5293
5294+#ifdef CONFIG_GRKERNSEC_SETXID
5295+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5296+ gr_delayed_cred_worker();
5297+#endif
5298+
5299 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
5300 tracehook_report_syscall_entry(regs))
5301 /*
5302@@ -1707,6 +1716,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
5303 {
5304 int step;
5305
5306+#ifdef CONFIG_GRKERNSEC_SETXID
5307+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5308+ gr_delayed_cred_worker();
5309+#endif
5310+
5311 audit_syscall_exit(regs);
5312
5313 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5314diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
5315index 804e323..79181c1 100644
5316--- a/arch/powerpc/kernel/signal_32.c
5317+++ b/arch/powerpc/kernel/signal_32.c
5318@@ -851,7 +851,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
5319 /* Save user registers on the stack */
5320 frame = &rt_sf->uc.uc_mcontext;
5321 addr = frame;
5322- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
5323+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5324 if (save_user_regs(regs, frame, 0, 1))
5325 goto badframe;
5326 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
5327diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
5328index d183f87..1867f1a 100644
5329--- a/arch/powerpc/kernel/signal_64.c
5330+++ b/arch/powerpc/kernel/signal_64.c
5331@@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
5332 current->thread.fpscr.val = 0;
5333
5334 /* Set up to return from userspace. */
5335- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
5336+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
5337 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
5338 } else {
5339 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
5340diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
5341index 3251840..3f7c77a 100644
5342--- a/arch/powerpc/kernel/traps.c
5343+++ b/arch/powerpc/kernel/traps.c
5344@@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
5345 return flags;
5346 }
5347
5348+extern void gr_handle_kernel_exploit(void);
5349+
5350 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5351 int signr)
5352 {
5353@@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
5354 panic("Fatal exception in interrupt");
5355 if (panic_on_oops)
5356 panic("Fatal exception");
5357+
5358+ gr_handle_kernel_exploit();
5359+
5360 do_exit(signr);
5361 }
5362
5363diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
5364index 1b2076f..835e4be 100644
5365--- a/arch/powerpc/kernel/vdso.c
5366+++ b/arch/powerpc/kernel/vdso.c
5367@@ -34,6 +34,7 @@
5368 #include <asm/firmware.h>
5369 #include <asm/vdso.h>
5370 #include <asm/vdso_datapage.h>
5371+#include <asm/mman.h>
5372
5373 #include "setup.h"
5374
5375@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5376 vdso_base = VDSO32_MBASE;
5377 #endif
5378
5379- current->mm->context.vdso_base = 0;
5380+ current->mm->context.vdso_base = ~0UL;
5381
5382 /* vDSO has a problem and was disabled, just don't "enable" it for the
5383 * process
5384@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
5385 vdso_base = get_unmapped_area(NULL, vdso_base,
5386 (vdso_pages << PAGE_SHIFT) +
5387 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
5388- 0, 0);
5389+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
5390 if (IS_ERR_VALUE(vdso_base)) {
5391 rc = vdso_base;
5392 goto fail_mmapsem;
5393diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
5394index 5eea6f3..5d10396 100644
5395--- a/arch/powerpc/lib/usercopy_64.c
5396+++ b/arch/powerpc/lib/usercopy_64.c
5397@@ -9,22 +9,6 @@
5398 #include <linux/module.h>
5399 #include <asm/uaccess.h>
5400
5401-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5402-{
5403- if (likely(access_ok(VERIFY_READ, from, n)))
5404- n = __copy_from_user(to, from, n);
5405- else
5406- memset(to, 0, n);
5407- return n;
5408-}
5409-
5410-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5411-{
5412- if (likely(access_ok(VERIFY_WRITE, to, n)))
5413- n = __copy_to_user(to, from, n);
5414- return n;
5415-}
5416-
5417 unsigned long copy_in_user(void __user *to, const void __user *from,
5418 unsigned long n)
5419 {
5420@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
5421 return n;
5422 }
5423
5424-EXPORT_SYMBOL(copy_from_user);
5425-EXPORT_SYMBOL(copy_to_user);
5426 EXPORT_SYMBOL(copy_in_user);
5427
5428diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
5429index 0a6b283..7674925 100644
5430--- a/arch/powerpc/mm/fault.c
5431+++ b/arch/powerpc/mm/fault.c
5432@@ -32,6 +32,10 @@
5433 #include <linux/perf_event.h>
5434 #include <linux/magic.h>
5435 #include <linux/ratelimit.h>
5436+#include <linux/slab.h>
5437+#include <linux/pagemap.h>
5438+#include <linux/compiler.h>
5439+#include <linux/unistd.h>
5440
5441 #include <asm/firmware.h>
5442 #include <asm/page.h>
5443@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
5444 }
5445 #endif
5446
5447+#ifdef CONFIG_PAX_PAGEEXEC
5448+/*
5449+ * PaX: decide what to do with offenders (regs->nip = fault address)
5450+ *
5451+ * returns 1 when task should be killed
5452+ */
5453+static int pax_handle_fetch_fault(struct pt_regs *regs)
5454+{
5455+ return 1;
5456+}
5457+
5458+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5459+{
5460+ unsigned long i;
5461+
5462+ printk(KERN_ERR "PAX: bytes at PC: ");
5463+ for (i = 0; i < 5; i++) {
5464+ unsigned int c;
5465+ if (get_user(c, (unsigned int __user *)pc+i))
5466+ printk(KERN_CONT "???????? ");
5467+ else
5468+ printk(KERN_CONT "%08x ", c);
5469+ }
5470+ printk("\n");
5471+}
5472+#endif
5473+
5474 /*
5475 * Check whether the instruction at regs->nip is a store using
5476 * an update addressing form which will update r1.
5477@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
5478 * indicate errors in DSISR but can validly be set in SRR1.
5479 */
5480 if (trap == 0x400)
5481- error_code &= 0x48200000;
5482+ error_code &= 0x58200000;
5483 else
5484 is_write = error_code & DSISR_ISSTORE;
5485 #else
5486@@ -367,7 +398,7 @@ good_area:
5487 * "undefined". Of those that can be set, this is the only
5488 * one which seems bad.
5489 */
5490- if (error_code & 0x10000000)
5491+ if (error_code & DSISR_GUARDED)
5492 /* Guarded storage error. */
5493 goto bad_area;
5494 #endif /* CONFIG_8xx */
5495@@ -382,7 +413,7 @@ good_area:
5496 * processors use the same I/D cache coherency mechanism
5497 * as embedded.
5498 */
5499- if (error_code & DSISR_PROTFAULT)
5500+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
5501 goto bad_area;
5502 #endif /* CONFIG_PPC_STD_MMU */
5503
5504@@ -465,6 +496,23 @@ bad_area:
5505 bad_area_nosemaphore:
5506 /* User mode accesses cause a SIGSEGV */
5507 if (user_mode(regs)) {
5508+
5509+#ifdef CONFIG_PAX_PAGEEXEC
5510+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5511+#ifdef CONFIG_PPC_STD_MMU
5512+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
5513+#else
5514+ if (is_exec && regs->nip == address) {
5515+#endif
5516+ switch (pax_handle_fetch_fault(regs)) {
5517+ }
5518+
5519+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
5520+ do_group_exit(SIGKILL);
5521+ }
5522+ }
5523+#endif
5524+
5525 _exception(SIGSEGV, regs, code, address);
5526 return 0;
5527 }
5528diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
5529index 67a42ed..1c7210c 100644
5530--- a/arch/powerpc/mm/mmap_64.c
5531+++ b/arch/powerpc/mm/mmap_64.c
5532@@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5533 */
5534 if (mmap_is_legacy()) {
5535 mm->mmap_base = TASK_UNMAPPED_BASE;
5536+
5537+#ifdef CONFIG_PAX_RANDMMAP
5538+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5539+ mm->mmap_base += mm->delta_mmap;
5540+#endif
5541+
5542 mm->get_unmapped_area = arch_get_unmapped_area;
5543 mm->unmap_area = arch_unmap_area;
5544 } else {
5545 mm->mmap_base = mmap_base();
5546+
5547+#ifdef CONFIG_PAX_RANDMMAP
5548+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5549+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5550+#endif
5551+
5552 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5553 mm->unmap_area = arch_unmap_area_topdown;
5554 }
5555diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
5556index 5829d2a..af84242 100644
5557--- a/arch/powerpc/mm/slice.c
5558+++ b/arch/powerpc/mm/slice.c
5559@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
5560 if ((mm->task_size - len) < addr)
5561 return 0;
5562 vma = find_vma(mm, addr);
5563- return (!vma || (addr + len) <= vma->vm_start);
5564+ return check_heap_stack_gap(vma, addr, len, 0);
5565 }
5566
5567 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
5568@@ -272,7 +272,7 @@ full_search:
5569 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
5570 continue;
5571 }
5572- if (!vma || addr + len <= vma->vm_start) {
5573+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5574 /*
5575 * Remember the place where we stopped the search:
5576 */
5577@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5578 }
5579 }
5580
5581- addr = mm->mmap_base;
5582- while (addr > len) {
5583+ if (mm->mmap_base < len)
5584+ addr = -ENOMEM;
5585+ else
5586+ addr = mm->mmap_base - len;
5587+
5588+ while (!IS_ERR_VALUE(addr)) {
5589 /* Go down by chunk size */
5590- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
5591+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
5592
5593 /* Check for hit with different page size */
5594 mask = slice_range_to_mask(addr, len);
5595@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5596 * return with success:
5597 */
5598 vma = find_vma(mm, addr);
5599- if (!vma || (addr + len) <= vma->vm_start) {
5600+ if (check_heap_stack_gap(vma, addr, len, 0)) {
5601 /* remember the address as a hint for next time */
5602 if (use_cache)
5603 mm->free_area_cache = addr;
5604@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
5605 mm->cached_hole_size = vma->vm_start - addr;
5606
5607 /* try just below the current vma->vm_start */
5608- addr = vma->vm_start;
5609+ addr = skip_heap_stack_gap(vma, len, 0);
5610 }
5611
5612 /*
5613@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
5614 if (fixed && addr > (mm->task_size - len))
5615 return -EINVAL;
5616
5617+#ifdef CONFIG_PAX_RANDMMAP
5618+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
5619+ addr = 0;
5620+#endif
5621+
5622 /* If hint, make sure it matches our alignment restrictions */
5623 if (!fixed && addr) {
5624 addr = _ALIGN_UP(addr, 1ul << pshift);
5625diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
5626index c797832..ce575c8 100644
5627--- a/arch/s390/include/asm/atomic.h
5628+++ b/arch/s390/include/asm/atomic.h
5629@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
5630 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
5631 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5632
5633+#define atomic64_read_unchecked(v) atomic64_read(v)
5634+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5635+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5636+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5637+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5638+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5639+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5640+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5641+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5642+
5643 #define smp_mb__before_atomic_dec() smp_mb()
5644 #define smp_mb__after_atomic_dec() smp_mb()
5645 #define smp_mb__before_atomic_inc() smp_mb()
5646diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
5647index 4d7ccac..d03d0ad 100644
5648--- a/arch/s390/include/asm/cache.h
5649+++ b/arch/s390/include/asm/cache.h
5650@@ -9,8 +9,10 @@
5651 #ifndef __ARCH_S390_CACHE_H
5652 #define __ARCH_S390_CACHE_H
5653
5654-#define L1_CACHE_BYTES 256
5655+#include <linux/const.h>
5656+
5657 #define L1_CACHE_SHIFT 8
5658+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5659 #define NET_SKB_PAD 32
5660
5661 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5662diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
5663index 178ff96..8c93bd1 100644
5664--- a/arch/s390/include/asm/elf.h
5665+++ b/arch/s390/include/asm/elf.h
5666@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
5667 the loader. We need to make sure that it is out of the way of the program
5668 that it will "exec", and that there is sufficient room for the brk. */
5669
5670-extern unsigned long randomize_et_dyn(unsigned long base);
5671-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
5672+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
5673+
5674+#ifdef CONFIG_PAX_ASLR
5675+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
5676+
5677+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5678+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
5679+#endif
5680
5681 /* This yields a mask that user programs can use to figure out what
5682 instruction set this CPU supports. */
5683@@ -210,9 +216,6 @@ struct linux_binprm;
5684 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5685 int arch_setup_additional_pages(struct linux_binprm *, int);
5686
5687-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5688-#define arch_randomize_brk arch_randomize_brk
5689-
5690 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
5691
5692 #endif
5693diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
5694index c4a93d6..4d2a9b4 100644
5695--- a/arch/s390/include/asm/exec.h
5696+++ b/arch/s390/include/asm/exec.h
5697@@ -7,6 +7,6 @@
5698 #ifndef __ASM_EXEC_H
5699 #define __ASM_EXEC_H
5700
5701-extern unsigned long arch_align_stack(unsigned long sp);
5702+#define arch_align_stack(x) ((x) & ~0xfUL)
5703
5704 #endif /* __ASM_EXEC_H */
5705diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
5706index 34268df..ea97318 100644
5707--- a/arch/s390/include/asm/uaccess.h
5708+++ b/arch/s390/include/asm/uaccess.h
5709@@ -252,6 +252,10 @@ static inline unsigned long __must_check
5710 copy_to_user(void __user *to, const void *from, unsigned long n)
5711 {
5712 might_fault();
5713+
5714+ if ((long)n < 0)
5715+ return n;
5716+
5717 if (access_ok(VERIFY_WRITE, to, n))
5718 n = __copy_to_user(to, from, n);
5719 return n;
5720@@ -277,6 +281,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
5721 static inline unsigned long __must_check
5722 __copy_from_user(void *to, const void __user *from, unsigned long n)
5723 {
5724+ if ((long)n < 0)
5725+ return n;
5726+
5727 if (__builtin_constant_p(n) && (n <= 256))
5728 return uaccess.copy_from_user_small(n, from, to);
5729 else
5730@@ -308,10 +315,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
5731 static inline unsigned long __must_check
5732 copy_from_user(void *to, const void __user *from, unsigned long n)
5733 {
5734- unsigned int sz = __compiletime_object_size(to);
5735+ size_t sz = __compiletime_object_size(to);
5736
5737 might_fault();
5738- if (unlikely(sz != -1 && sz < n)) {
5739+
5740+ if ((long)n < 0)
5741+ return n;
5742+
5743+ if (unlikely(sz != (size_t)-1 && sz < n)) {
5744 copy_from_user_overflow();
5745 return n;
5746 }
5747diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
5748index 4610dea..cf0af21 100644
5749--- a/arch/s390/kernel/module.c
5750+++ b/arch/s390/kernel/module.c
5751@@ -171,11 +171,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
5752
5753 /* Increase core size by size of got & plt and set start
5754 offsets for got and plt. */
5755- me->core_size = ALIGN(me->core_size, 4);
5756- me->arch.got_offset = me->core_size;
5757- me->core_size += me->arch.got_size;
5758- me->arch.plt_offset = me->core_size;
5759- me->core_size += me->arch.plt_size;
5760+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
5761+ me->arch.got_offset = me->core_size_rw;
5762+ me->core_size_rw += me->arch.got_size;
5763+ me->arch.plt_offset = me->core_size_rx;
5764+ me->core_size_rx += me->arch.plt_size;
5765 return 0;
5766 }
5767
5768@@ -252,7 +252,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5769 if (info->got_initialized == 0) {
5770 Elf_Addr *gotent;
5771
5772- gotent = me->module_core + me->arch.got_offset +
5773+ gotent = me->module_core_rw + me->arch.got_offset +
5774 info->got_offset;
5775 *gotent = val;
5776 info->got_initialized = 1;
5777@@ -276,7 +276,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5778 else if (r_type == R_390_GOTENT ||
5779 r_type == R_390_GOTPLTENT)
5780 *(unsigned int *) loc =
5781- (val + (Elf_Addr) me->module_core - loc) >> 1;
5782+ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
5783 else if (r_type == R_390_GOT64 ||
5784 r_type == R_390_GOTPLT64)
5785 *(unsigned long *) loc = val;
5786@@ -290,7 +290,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5787 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
5788 if (info->plt_initialized == 0) {
5789 unsigned int *ip;
5790- ip = me->module_core + me->arch.plt_offset +
5791+ ip = me->module_core_rx + me->arch.plt_offset +
5792 info->plt_offset;
5793 #ifndef CONFIG_64BIT
5794 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
5795@@ -315,7 +315,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5796 val - loc + 0xffffUL < 0x1ffffeUL) ||
5797 (r_type == R_390_PLT32DBL &&
5798 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
5799- val = (Elf_Addr) me->module_core +
5800+ val = (Elf_Addr) me->module_core_rx +
5801 me->arch.plt_offset +
5802 info->plt_offset;
5803 val += rela->r_addend - loc;
5804@@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5805 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
5806 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
5807 val = val + rela->r_addend -
5808- ((Elf_Addr) me->module_core + me->arch.got_offset);
5809+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
5810 if (r_type == R_390_GOTOFF16)
5811 *(unsigned short *) loc = val;
5812 else if (r_type == R_390_GOTOFF32)
5813@@ -347,7 +347,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
5814 break;
5815 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
5816 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
5817- val = (Elf_Addr) me->module_core + me->arch.got_offset +
5818+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
5819 rela->r_addend - loc;
5820 if (r_type == R_390_GOTPC)
5821 *(unsigned int *) loc = val;
5822diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
5823index cd31ad4..201c5a3 100644
5824--- a/arch/s390/kernel/process.c
5825+++ b/arch/s390/kernel/process.c
5826@@ -283,39 +283,3 @@ unsigned long get_wchan(struct task_struct *p)
5827 }
5828 return 0;
5829 }
5830-
5831-unsigned long arch_align_stack(unsigned long sp)
5832-{
5833- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5834- sp -= get_random_int() & ~PAGE_MASK;
5835- return sp & ~0xf;
5836-}
5837-
5838-static inline unsigned long brk_rnd(void)
5839-{
5840- /* 8MB for 32bit, 1GB for 64bit */
5841- if (is_32bit_task())
5842- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
5843- else
5844- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
5845-}
5846-
5847-unsigned long arch_randomize_brk(struct mm_struct *mm)
5848-{
5849- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
5850-
5851- if (ret < mm->brk)
5852- return mm->brk;
5853- return ret;
5854-}
5855-
5856-unsigned long randomize_et_dyn(unsigned long base)
5857-{
5858- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
5859-
5860- if (!(current->flags & PF_RANDOMIZE))
5861- return base;
5862- if (ret < base)
5863- return base;
5864- return ret;
5865-}
5866diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
5867index c59a5ef..3fae59c 100644
5868--- a/arch/s390/mm/mmap.c
5869+++ b/arch/s390/mm/mmap.c
5870@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5871 */
5872 if (mmap_is_legacy()) {
5873 mm->mmap_base = TASK_UNMAPPED_BASE;
5874+
5875+#ifdef CONFIG_PAX_RANDMMAP
5876+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5877+ mm->mmap_base += mm->delta_mmap;
5878+#endif
5879+
5880 mm->get_unmapped_area = arch_get_unmapped_area;
5881 mm->unmap_area = arch_unmap_area;
5882 } else {
5883 mm->mmap_base = mmap_base();
5884+
5885+#ifdef CONFIG_PAX_RANDMMAP
5886+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5887+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5888+#endif
5889+
5890 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5891 mm->unmap_area = arch_unmap_area_topdown;
5892 }
5893@@ -172,10 +184,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5894 */
5895 if (mmap_is_legacy()) {
5896 mm->mmap_base = TASK_UNMAPPED_BASE;
5897+
5898+#ifdef CONFIG_PAX_RANDMMAP
5899+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5900+ mm->mmap_base += mm->delta_mmap;
5901+#endif
5902+
5903 mm->get_unmapped_area = s390_get_unmapped_area;
5904 mm->unmap_area = arch_unmap_area;
5905 } else {
5906 mm->mmap_base = mmap_base();
5907+
5908+#ifdef CONFIG_PAX_RANDMMAP
5909+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5910+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5911+#endif
5912+
5913 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
5914 mm->unmap_area = arch_unmap_area_topdown;
5915 }
5916diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
5917index ae3d59f..f65f075 100644
5918--- a/arch/score/include/asm/cache.h
5919+++ b/arch/score/include/asm/cache.h
5920@@ -1,7 +1,9 @@
5921 #ifndef _ASM_SCORE_CACHE_H
5922 #define _ASM_SCORE_CACHE_H
5923
5924+#include <linux/const.h>
5925+
5926 #define L1_CACHE_SHIFT 4
5927-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5928+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5929
5930 #endif /* _ASM_SCORE_CACHE_H */
5931diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5932index f9f3cd5..58ff438 100644
5933--- a/arch/score/include/asm/exec.h
5934+++ b/arch/score/include/asm/exec.h
5935@@ -1,6 +1,6 @@
5936 #ifndef _ASM_SCORE_EXEC_H
5937 #define _ASM_SCORE_EXEC_H
5938
5939-extern unsigned long arch_align_stack(unsigned long sp);
5940+#define arch_align_stack(x) (x)
5941
5942 #endif /* _ASM_SCORE_EXEC_H */
5943diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5944index 637970c..0b6556b 100644
5945--- a/arch/score/kernel/process.c
5946+++ b/arch/score/kernel/process.c
5947@@ -161,8 +161,3 @@ unsigned long get_wchan(struct task_struct *task)
5948
5949 return task_pt_regs(task)->cp0_epc;
5950 }
5951-
5952-unsigned long arch_align_stack(unsigned long sp)
5953-{
5954- return sp;
5955-}
5956diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5957index ef9e555..331bd29 100644
5958--- a/arch/sh/include/asm/cache.h
5959+++ b/arch/sh/include/asm/cache.h
5960@@ -9,10 +9,11 @@
5961 #define __ASM_SH_CACHE_H
5962 #ifdef __KERNEL__
5963
5964+#include <linux/const.h>
5965 #include <linux/init.h>
5966 #include <cpu/cache.h>
5967
5968-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5969+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5970
5971 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5972
5973diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5974index afeb710..e8366ef 100644
5975--- a/arch/sh/mm/mmap.c
5976+++ b/arch/sh/mm/mmap.c
5977@@ -49,6 +49,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5978 struct vm_area_struct *vma;
5979 unsigned long start_addr;
5980 int do_colour_align;
5981+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5982
5983 if (flags & MAP_FIXED) {
5984 /* We do not accept a shared mapping if it would violate
5985@@ -74,8 +75,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5986 addr = PAGE_ALIGN(addr);
5987
5988 vma = find_vma(mm, addr);
5989- if (TASK_SIZE - len >= addr &&
5990- (!vma || addr + len <= vma->vm_start))
5991+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5992 return addr;
5993 }
5994
5995@@ -106,7 +106,7 @@ full_search:
5996 }
5997 return -ENOMEM;
5998 }
5999- if (likely(!vma || addr + len <= vma->vm_start)) {
6000+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6001 /*
6002 * Remember the place where we stopped the search:
6003 */
6004@@ -131,6 +131,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6005 struct mm_struct *mm = current->mm;
6006 unsigned long addr = addr0;
6007 int do_colour_align;
6008+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6009
6010 if (flags & MAP_FIXED) {
6011 /* We do not accept a shared mapping if it would violate
6012@@ -157,8 +158,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6013 addr = PAGE_ALIGN(addr);
6014
6015 vma = find_vma(mm, addr);
6016- if (TASK_SIZE - len >= addr &&
6017- (!vma || addr + len <= vma->vm_start))
6018+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6019 return addr;
6020 }
6021
6022@@ -179,7 +179,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6023 /* make sure it can fit in the remaining address space */
6024 if (likely(addr > len)) {
6025 vma = find_vma(mm, addr-len);
6026- if (!vma || addr <= vma->vm_start) {
6027+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6028 /* remember the address as a hint for next time */
6029 return (mm->free_area_cache = addr-len);
6030 }
6031@@ -188,18 +188,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6032 if (unlikely(mm->mmap_base < len))
6033 goto bottomup;
6034
6035- addr = mm->mmap_base-len;
6036- if (do_colour_align)
6037- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6038+ addr = mm->mmap_base - len;
6039
6040 do {
6041+ if (do_colour_align)
6042+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6043 /*
6044 * Lookup failure means no vma is above this address,
6045 * else if new region fits below vma->vm_start,
6046 * return with success:
6047 */
6048 vma = find_vma(mm, addr);
6049- if (likely(!vma || addr+len <= vma->vm_start)) {
6050+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6051 /* remember the address as a hint for next time */
6052 return (mm->free_area_cache = addr);
6053 }
6054@@ -209,10 +209,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6055 mm->cached_hole_size = vma->vm_start - addr;
6056
6057 /* try just below the current vma->vm_start */
6058- addr = vma->vm_start-len;
6059- if (do_colour_align)
6060- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6061- } while (likely(len < vma->vm_start));
6062+ addr = skip_heap_stack_gap(vma, len, offset);
6063+ } while (!IS_ERR_VALUE(addr));
6064
6065 bottomup:
6066 /*
6067diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
6068index be56a24..443328f 100644
6069--- a/arch/sparc/include/asm/atomic_64.h
6070+++ b/arch/sparc/include/asm/atomic_64.h
6071@@ -14,18 +14,40 @@
6072 #define ATOMIC64_INIT(i) { (i) }
6073
6074 #define atomic_read(v) (*(volatile int *)&(v)->counter)
6075+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
6076+{
6077+ return v->counter;
6078+}
6079 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
6080+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6081+{
6082+ return v->counter;
6083+}
6084
6085 #define atomic_set(v, i) (((v)->counter) = i)
6086+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
6087+{
6088+ v->counter = i;
6089+}
6090 #define atomic64_set(v, i) (((v)->counter) = i)
6091+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6092+{
6093+ v->counter = i;
6094+}
6095
6096 extern void atomic_add(int, atomic_t *);
6097+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
6098 extern void atomic64_add(long, atomic64_t *);
6099+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
6100 extern void atomic_sub(int, atomic_t *);
6101+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
6102 extern void atomic64_sub(long, atomic64_t *);
6103+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
6104
6105 extern int atomic_add_ret(int, atomic_t *);
6106+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
6107 extern long atomic64_add_ret(long, atomic64_t *);
6108+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
6109 extern int atomic_sub_ret(int, atomic_t *);
6110 extern long atomic64_sub_ret(long, atomic64_t *);
6111
6112@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6113 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
6114
6115 #define atomic_inc_return(v) atomic_add_ret(1, v)
6116+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6117+{
6118+ return atomic_add_ret_unchecked(1, v);
6119+}
6120 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
6121+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
6122+{
6123+ return atomic64_add_ret_unchecked(1, v);
6124+}
6125
6126 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
6127 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
6128
6129 #define atomic_add_return(i, v) atomic_add_ret(i, v)
6130+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6131+{
6132+ return atomic_add_ret_unchecked(i, v);
6133+}
6134 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
6135+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6136+{
6137+ return atomic64_add_ret_unchecked(i, v);
6138+}
6139
6140 /*
6141 * atomic_inc_and_test - increment and test
6142@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6143 * other cases.
6144 */
6145 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6146+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6147+{
6148+ return atomic_inc_return_unchecked(v) == 0;
6149+}
6150 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6151
6152 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
6153@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
6154 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
6155
6156 #define atomic_inc(v) atomic_add(1, v)
6157+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
6158+{
6159+ atomic_add_unchecked(1, v);
6160+}
6161 #define atomic64_inc(v) atomic64_add(1, v)
6162+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
6163+{
6164+ atomic64_add_unchecked(1, v);
6165+}
6166
6167 #define atomic_dec(v) atomic_sub(1, v)
6168+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
6169+{
6170+ atomic_sub_unchecked(1, v);
6171+}
6172 #define atomic64_dec(v) atomic64_sub(1, v)
6173+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
6174+{
6175+ atomic64_sub_unchecked(1, v);
6176+}
6177
6178 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
6179 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
6180
6181 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6182+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
6183+{
6184+ return cmpxchg(&v->counter, old, new);
6185+}
6186 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
6187+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6188+{
6189+ return xchg(&v->counter, new);
6190+}
6191
6192 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6193 {
6194- int c, old;
6195+ int c, old, new;
6196 c = atomic_read(v);
6197 for (;;) {
6198- if (unlikely(c == (u)))
6199+ if (unlikely(c == u))
6200 break;
6201- old = atomic_cmpxchg((v), c, c + (a));
6202+
6203+ asm volatile("addcc %2, %0, %0\n"
6204+
6205+#ifdef CONFIG_PAX_REFCOUNT
6206+ "tvs %%icc, 6\n"
6207+#endif
6208+
6209+ : "=r" (new)
6210+ : "0" (c), "ir" (a)
6211+ : "cc");
6212+
6213+ old = atomic_cmpxchg(v, c, new);
6214 if (likely(old == c))
6215 break;
6216 c = old;
6217@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
6218 #define atomic64_cmpxchg(v, o, n) \
6219 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6220 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
6221+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6222+{
6223+ return xchg(&v->counter, new);
6224+}
6225
6226 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
6227 {
6228- long c, old;
6229+ long c, old, new;
6230 c = atomic64_read(v);
6231 for (;;) {
6232- if (unlikely(c == (u)))
6233+ if (unlikely(c == u))
6234 break;
6235- old = atomic64_cmpxchg((v), c, c + (a));
6236+
6237+ asm volatile("addcc %2, %0, %0\n"
6238+
6239+#ifdef CONFIG_PAX_REFCOUNT
6240+ "tvs %%xcc, 6\n"
6241+#endif
6242+
6243+ : "=r" (new)
6244+ : "0" (c), "ir" (a)
6245+ : "cc");
6246+
6247+ old = atomic64_cmpxchg(v, c, new);
6248 if (likely(old == c))
6249 break;
6250 c = old;
6251 }
6252- return c != (u);
6253+ return c != u;
6254 }
6255
6256 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
6257diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
6258index 5bb6991..5c2132e 100644
6259--- a/arch/sparc/include/asm/cache.h
6260+++ b/arch/sparc/include/asm/cache.h
6261@@ -7,10 +7,12 @@
6262 #ifndef _SPARC_CACHE_H
6263 #define _SPARC_CACHE_H
6264
6265+#include <linux/const.h>
6266+
6267 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
6268
6269 #define L1_CACHE_SHIFT 5
6270-#define L1_CACHE_BYTES 32
6271+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6272
6273 #ifdef CONFIG_SPARC32
6274 #define SMP_CACHE_BYTES_SHIFT 5
6275diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
6276index ac74a2c..a9e58af 100644
6277--- a/arch/sparc/include/asm/elf_32.h
6278+++ b/arch/sparc/include/asm/elf_32.h
6279@@ -114,6 +114,13 @@ typedef struct {
6280
6281 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
6282
6283+#ifdef CONFIG_PAX_ASLR
6284+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6285+
6286+#define PAX_DELTA_MMAP_LEN 16
6287+#define PAX_DELTA_STACK_LEN 16
6288+#endif
6289+
6290 /* This yields a mask that user programs can use to figure out what
6291 instruction set this cpu supports. This can NOT be done in userspace
6292 on Sparc. */
6293diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
6294index 370ca1e..d4f4a98 100644
6295--- a/arch/sparc/include/asm/elf_64.h
6296+++ b/arch/sparc/include/asm/elf_64.h
6297@@ -189,6 +189,13 @@ typedef struct {
6298 #define ELF_ET_DYN_BASE 0x0000010000000000UL
6299 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
6300
6301+#ifdef CONFIG_PAX_ASLR
6302+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
6303+
6304+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
6305+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
6306+#endif
6307+
6308 extern unsigned long sparc64_elf_hwcap;
6309 #define ELF_HWCAP sparc64_elf_hwcap
6310
6311diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
6312index 9b1c36d..209298b 100644
6313--- a/arch/sparc/include/asm/pgalloc_32.h
6314+++ b/arch/sparc/include/asm/pgalloc_32.h
6315@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
6316 }
6317
6318 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
6319+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
6320
6321 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
6322 unsigned long address)
6323diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
6324index bcfe063..b333142 100644
6325--- a/arch/sparc/include/asm/pgalloc_64.h
6326+++ b/arch/sparc/include/asm/pgalloc_64.h
6327@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6328 }
6329
6330 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
6331+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
6332
6333 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
6334 {
6335diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
6336index 6fc1348..390c50a 100644
6337--- a/arch/sparc/include/asm/pgtable_32.h
6338+++ b/arch/sparc/include/asm/pgtable_32.h
6339@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
6340 #define PAGE_SHARED SRMMU_PAGE_SHARED
6341 #define PAGE_COPY SRMMU_PAGE_COPY
6342 #define PAGE_READONLY SRMMU_PAGE_RDONLY
6343+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
6344+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
6345+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
6346 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
6347
6348 /* Top-level page directory - dummy used by init-mm.
6349@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
6350
6351 /* xwr */
6352 #define __P000 PAGE_NONE
6353-#define __P001 PAGE_READONLY
6354-#define __P010 PAGE_COPY
6355-#define __P011 PAGE_COPY
6356+#define __P001 PAGE_READONLY_NOEXEC
6357+#define __P010 PAGE_COPY_NOEXEC
6358+#define __P011 PAGE_COPY_NOEXEC
6359 #define __P100 PAGE_READONLY
6360 #define __P101 PAGE_READONLY
6361 #define __P110 PAGE_COPY
6362 #define __P111 PAGE_COPY
6363
6364 #define __S000 PAGE_NONE
6365-#define __S001 PAGE_READONLY
6366-#define __S010 PAGE_SHARED
6367-#define __S011 PAGE_SHARED
6368+#define __S001 PAGE_READONLY_NOEXEC
6369+#define __S010 PAGE_SHARED_NOEXEC
6370+#define __S011 PAGE_SHARED_NOEXEC
6371 #define __S100 PAGE_READONLY
6372 #define __S101 PAGE_READONLY
6373 #define __S110 PAGE_SHARED
6374diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
6375index 79da178..c2eede8 100644
6376--- a/arch/sparc/include/asm/pgtsrmmu.h
6377+++ b/arch/sparc/include/asm/pgtsrmmu.h
6378@@ -115,6 +115,11 @@
6379 SRMMU_EXEC | SRMMU_REF)
6380 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
6381 SRMMU_EXEC | SRMMU_REF)
6382+
6383+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
6384+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6385+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
6386+
6387 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
6388 SRMMU_DIRTY | SRMMU_REF)
6389
6390diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
6391index 9689176..63c18ea 100644
6392--- a/arch/sparc/include/asm/spinlock_64.h
6393+++ b/arch/sparc/include/asm/spinlock_64.h
6394@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
6395
6396 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
6397
6398-static void inline arch_read_lock(arch_rwlock_t *lock)
6399+static inline void arch_read_lock(arch_rwlock_t *lock)
6400 {
6401 unsigned long tmp1, tmp2;
6402
6403 __asm__ __volatile__ (
6404 "1: ldsw [%2], %0\n"
6405 " brlz,pn %0, 2f\n"
6406-"4: add %0, 1, %1\n"
6407+"4: addcc %0, 1, %1\n"
6408+
6409+#ifdef CONFIG_PAX_REFCOUNT
6410+" tvs %%icc, 6\n"
6411+#endif
6412+
6413 " cas [%2], %0, %1\n"
6414 " cmp %0, %1\n"
6415 " bne,pn %%icc, 1b\n"
6416@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
6417 " .previous"
6418 : "=&r" (tmp1), "=&r" (tmp2)
6419 : "r" (lock)
6420- : "memory");
6421+ : "memory", "cc");
6422 }
6423
6424-static int inline arch_read_trylock(arch_rwlock_t *lock)
6425+static inline int arch_read_trylock(arch_rwlock_t *lock)
6426 {
6427 int tmp1, tmp2;
6428
6429@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6430 "1: ldsw [%2], %0\n"
6431 " brlz,a,pn %0, 2f\n"
6432 " mov 0, %0\n"
6433-" add %0, 1, %1\n"
6434+" addcc %0, 1, %1\n"
6435+
6436+#ifdef CONFIG_PAX_REFCOUNT
6437+" tvs %%icc, 6\n"
6438+#endif
6439+
6440 " cas [%2], %0, %1\n"
6441 " cmp %0, %1\n"
6442 " bne,pn %%icc, 1b\n"
6443@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
6444 return tmp1;
6445 }
6446
6447-static void inline arch_read_unlock(arch_rwlock_t *lock)
6448+static inline void arch_read_unlock(arch_rwlock_t *lock)
6449 {
6450 unsigned long tmp1, tmp2;
6451
6452 __asm__ __volatile__(
6453 "1: lduw [%2], %0\n"
6454-" sub %0, 1, %1\n"
6455+" subcc %0, 1, %1\n"
6456+
6457+#ifdef CONFIG_PAX_REFCOUNT
6458+" tvs %%icc, 6\n"
6459+#endif
6460+
6461 " cas [%2], %0, %1\n"
6462 " cmp %0, %1\n"
6463 " bne,pn %%xcc, 1b\n"
6464@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
6465 : "memory");
6466 }
6467
6468-static void inline arch_write_lock(arch_rwlock_t *lock)
6469+static inline void arch_write_lock(arch_rwlock_t *lock)
6470 {
6471 unsigned long mask, tmp1, tmp2;
6472
6473@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
6474 : "memory");
6475 }
6476
6477-static void inline arch_write_unlock(arch_rwlock_t *lock)
6478+static inline void arch_write_unlock(arch_rwlock_t *lock)
6479 {
6480 __asm__ __volatile__(
6481 " stw %%g0, [%0]"
6482@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
6483 : "memory");
6484 }
6485
6486-static int inline arch_write_trylock(arch_rwlock_t *lock)
6487+static inline int arch_write_trylock(arch_rwlock_t *lock)
6488 {
6489 unsigned long mask, tmp1, tmp2, result;
6490
6491diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
6492index 25849ae..924c54b 100644
6493--- a/arch/sparc/include/asm/thread_info_32.h
6494+++ b/arch/sparc/include/asm/thread_info_32.h
6495@@ -49,6 +49,8 @@ struct thread_info {
6496 unsigned long w_saved;
6497
6498 struct restart_block restart_block;
6499+
6500+ unsigned long lowest_stack;
6501 };
6502
6503 /*
6504diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
6505index a3fe4dc..cae132a 100644
6506--- a/arch/sparc/include/asm/thread_info_64.h
6507+++ b/arch/sparc/include/asm/thread_info_64.h
6508@@ -63,6 +63,8 @@ struct thread_info {
6509 struct pt_regs *kern_una_regs;
6510 unsigned int kern_una_insn;
6511
6512+ unsigned long lowest_stack;
6513+
6514 unsigned long fpregs[0] __attribute__ ((aligned(64)));
6515 };
6516
6517@@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
6518 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
6519 /* flag bit 6 is available */
6520 #define TIF_32BIT 7 /* 32-bit binary */
6521-/* flag bit 8 is available */
6522+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
6523 #define TIF_SECCOMP 9 /* secure computing */
6524 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
6525 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
6526+
6527 /* NOTE: Thread flags >= 12 should be ones we have no interest
6528 * in using in assembly, else we can't use the mask as
6529 * an immediate value in instructions such as andcc.
6530@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
6531 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
6532 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6533 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
6534+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6535
6536 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
6537 _TIF_DO_NOTIFY_RESUME_MASK | \
6538 _TIF_NEED_RESCHED)
6539 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
6540
6541+#define _TIF_WORK_SYSCALL \
6542+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
6543+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6544+
6545+
6546 /*
6547 * Thread-synchronous status.
6548 *
6549diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
6550index 0167d26..9acd8ed 100644
6551--- a/arch/sparc/include/asm/uaccess.h
6552+++ b/arch/sparc/include/asm/uaccess.h
6553@@ -1,5 +1,13 @@
6554 #ifndef ___ASM_SPARC_UACCESS_H
6555 #define ___ASM_SPARC_UACCESS_H
6556+
6557+#ifdef __KERNEL__
6558+#ifndef __ASSEMBLY__
6559+#include <linux/types.h>
6560+extern void check_object_size(const void *ptr, unsigned long n, bool to);
6561+#endif
6562+#endif
6563+
6564 #if defined(__sparc__) && defined(__arch64__)
6565 #include <asm/uaccess_64.h>
6566 #else
6567diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
6568index 53a28dd..50c38c3 100644
6569--- a/arch/sparc/include/asm/uaccess_32.h
6570+++ b/arch/sparc/include/asm/uaccess_32.h
6571@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
6572
6573 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6574 {
6575- if (n && __access_ok((unsigned long) to, n))
6576+ if ((long)n < 0)
6577+ return n;
6578+
6579+ if (n && __access_ok((unsigned long) to, n)) {
6580+ if (!__builtin_constant_p(n))
6581+ check_object_size(from, n, true);
6582 return __copy_user(to, (__force void __user *) from, n);
6583- else
6584+ } else
6585 return n;
6586 }
6587
6588 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
6589 {
6590+ if ((long)n < 0)
6591+ return n;
6592+
6593+ if (!__builtin_constant_p(n))
6594+ check_object_size(from, n, true);
6595+
6596 return __copy_user(to, (__force void __user *) from, n);
6597 }
6598
6599 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6600 {
6601- if (n && __access_ok((unsigned long) from, n))
6602+ if ((long)n < 0)
6603+ return n;
6604+
6605+ if (n && __access_ok((unsigned long) from, n)) {
6606+ if (!__builtin_constant_p(n))
6607+ check_object_size(to, n, false);
6608 return __copy_user((__force void __user *) to, from, n);
6609- else
6610+ } else
6611 return n;
6612 }
6613
6614 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
6615 {
6616+ if ((long)n < 0)
6617+ return n;
6618+
6619 return __copy_user((__force void __user *) to, from, n);
6620 }
6621
6622diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
6623index 73083e1..2bc62a6 100644
6624--- a/arch/sparc/include/asm/uaccess_64.h
6625+++ b/arch/sparc/include/asm/uaccess_64.h
6626@@ -10,6 +10,7 @@
6627 #include <linux/compiler.h>
6628 #include <linux/string.h>
6629 #include <linux/thread_info.h>
6630+#include <linux/kernel.h>
6631 #include <asm/asi.h>
6632 #include <asm/spitfire.h>
6633 #include <asm-generic/uaccess-unaligned.h>
6634@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
6635 static inline unsigned long __must_check
6636 copy_from_user(void *to, const void __user *from, unsigned long size)
6637 {
6638- unsigned long ret = ___copy_from_user(to, from, size);
6639+ unsigned long ret;
6640
6641+ if ((long)size < 0 || size > INT_MAX)
6642+ return size;
6643+
6644+ if (!__builtin_constant_p(size))
6645+ check_object_size(to, size, false);
6646+
6647+ ret = ___copy_from_user(to, from, size);
6648 if (unlikely(ret))
6649 ret = copy_from_user_fixup(to, from, size);
6650
6651@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
6652 static inline unsigned long __must_check
6653 copy_to_user(void __user *to, const void *from, unsigned long size)
6654 {
6655- unsigned long ret = ___copy_to_user(to, from, size);
6656+ unsigned long ret;
6657
6658+ if ((long)size < 0 || size > INT_MAX)
6659+ return size;
6660+
6661+ if (!__builtin_constant_p(size))
6662+ check_object_size(from, size, true);
6663+
6664+ ret = ___copy_to_user(to, from, size);
6665 if (unlikely(ret))
6666 ret = copy_to_user_fixup(to, from, size);
6667 return ret;
6668diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
6669index 6cf591b..b49e65a 100644
6670--- a/arch/sparc/kernel/Makefile
6671+++ b/arch/sparc/kernel/Makefile
6672@@ -3,7 +3,7 @@
6673 #
6674
6675 asflags-y := -ansi
6676-ccflags-y := -Werror
6677+#ccflags-y := -Werror
6678
6679 extra-y := head_$(BITS).o
6680
6681diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
6682index 487bffb..955a925 100644
6683--- a/arch/sparc/kernel/process_32.c
6684+++ b/arch/sparc/kernel/process_32.c
6685@@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
6686
6687 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
6688 r->psr, r->pc, r->npc, r->y, print_tainted());
6689- printk("PC: <%pS>\n", (void *) r->pc);
6690+ printk("PC: <%pA>\n", (void *) r->pc);
6691 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6692 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
6693 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
6694 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6695 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
6696 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
6697- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
6698+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
6699
6700 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
6701 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
6702@@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6703 rw = (struct reg_window32 *) fp;
6704 pc = rw->ins[7];
6705 printk("[%08lx : ", pc);
6706- printk("%pS ] ", (void *) pc);
6707+ printk("%pA ] ", (void *) pc);
6708 fp = rw->ins[6];
6709 } while (++count < 16);
6710 printk("\n");
6711diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
6712index c6e0c29..052832b 100644
6713--- a/arch/sparc/kernel/process_64.c
6714+++ b/arch/sparc/kernel/process_64.c
6715@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
6716 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
6717 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
6718 if (regs->tstate & TSTATE_PRIV)
6719- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
6720+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
6721 }
6722
6723 void show_regs(struct pt_regs *regs)
6724 {
6725 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
6726 regs->tpc, regs->tnpc, regs->y, print_tainted());
6727- printk("TPC: <%pS>\n", (void *) regs->tpc);
6728+ printk("TPC: <%pA>\n", (void *) regs->tpc);
6729 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
6730 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
6731 regs->u_regs[3]);
6732@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
6733 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
6734 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
6735 regs->u_regs[15]);
6736- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
6737+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
6738 show_regwindow(regs);
6739 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
6740 }
6741@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
6742 ((tp && tp->task) ? tp->task->pid : -1));
6743
6744 if (gp->tstate & TSTATE_PRIV) {
6745- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
6746+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
6747 (void *) gp->tpc,
6748 (void *) gp->o7,
6749 (void *) gp->i7,
6750diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
6751index 7ff45e4..a58f271 100644
6752--- a/arch/sparc/kernel/ptrace_64.c
6753+++ b/arch/sparc/kernel/ptrace_64.c
6754@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
6755 return ret;
6756 }
6757
6758+#ifdef CONFIG_GRKERNSEC_SETXID
6759+extern void gr_delayed_cred_worker(void);
6760+#endif
6761+
6762 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6763 {
6764 int ret = 0;
6765@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6766 /* do the secure computing check first */
6767 secure_computing_strict(regs->u_regs[UREG_G1]);
6768
6769+#ifdef CONFIG_GRKERNSEC_SETXID
6770+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6771+ gr_delayed_cred_worker();
6772+#endif
6773+
6774 if (test_thread_flag(TIF_SYSCALL_TRACE))
6775 ret = tracehook_report_syscall_entry(regs);
6776
6777@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
6778
6779 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
6780 {
6781+#ifdef CONFIG_GRKERNSEC_SETXID
6782+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6783+ gr_delayed_cred_worker();
6784+#endif
6785+
6786 audit_syscall_exit(regs);
6787
6788 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6789diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
6790index 0c9b31b..55a8ba6 100644
6791--- a/arch/sparc/kernel/sys_sparc_32.c
6792+++ b/arch/sparc/kernel/sys_sparc_32.c
6793@@ -39,6 +39,7 @@ asmlinkage unsigned long sys_getpagesize(void)
6794 unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
6795 {
6796 struct vm_area_struct * vmm;
6797+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
6798
6799 if (flags & MAP_FIXED) {
6800 /* We do not accept a shared mapping if it would violate
6801@@ -54,7 +55,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6802 if (len > TASK_SIZE - PAGE_SIZE)
6803 return -ENOMEM;
6804 if (!addr)
6805- addr = TASK_UNMAPPED_BASE;
6806+ addr = current->mm->mmap_base;
6807
6808 if (flags & MAP_SHARED)
6809 addr = COLOUR_ALIGN(addr);
6810@@ -65,7 +66,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6811 /* At this point: (!vmm || addr < vmm->vm_end). */
6812 if (TASK_SIZE - PAGE_SIZE - len < addr)
6813 return -ENOMEM;
6814- if (!vmm || addr + len <= vmm->vm_start)
6815+ if (check_heap_stack_gap(vmm, addr, len, offset))
6816 return addr;
6817 addr = vmm->vm_end;
6818 if (flags & MAP_SHARED)
6819diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
6820index 878ef3d..609e41f 100644
6821--- a/arch/sparc/kernel/sys_sparc_64.c
6822+++ b/arch/sparc/kernel/sys_sparc_64.c
6823@@ -102,12 +102,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6824 unsigned long task_size = TASK_SIZE;
6825 unsigned long start_addr;
6826 int do_color_align;
6827+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6828
6829 if (flags & MAP_FIXED) {
6830 /* We do not accept a shared mapping if it would violate
6831 * cache aliasing constraints.
6832 */
6833- if ((flags & MAP_SHARED) &&
6834+ if ((filp || (flags & MAP_SHARED)) &&
6835 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6836 return -EINVAL;
6837 return addr;
6838@@ -122,6 +123,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6839 if (filp || (flags & MAP_SHARED))
6840 do_color_align = 1;
6841
6842+#ifdef CONFIG_PAX_RANDMMAP
6843+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6844+#endif
6845+
6846 if (addr) {
6847 if (do_color_align)
6848 addr = COLOUR_ALIGN(addr, pgoff);
6849@@ -129,15 +134,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
6850 addr = PAGE_ALIGN(addr);
6851
6852 vma = find_vma(mm, addr);
6853- if (task_size - len >= addr &&
6854- (!vma || addr + len <= vma->vm_start))
6855+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6856 return addr;
6857 }
6858
6859 if (len > mm->cached_hole_size) {
6860- start_addr = addr = mm->free_area_cache;
6861+ start_addr = addr = mm->free_area_cache;
6862 } else {
6863- start_addr = addr = TASK_UNMAPPED_BASE;
6864+ start_addr = addr = mm->mmap_base;
6865 mm->cached_hole_size = 0;
6866 }
6867
6868@@ -157,14 +161,14 @@ full_search:
6869 vma = find_vma(mm, VA_EXCLUDE_END);
6870 }
6871 if (unlikely(task_size < addr)) {
6872- if (start_addr != TASK_UNMAPPED_BASE) {
6873- start_addr = addr = TASK_UNMAPPED_BASE;
6874+ if (start_addr != mm->mmap_base) {
6875+ start_addr = addr = mm->mmap_base;
6876 mm->cached_hole_size = 0;
6877 goto full_search;
6878 }
6879 return -ENOMEM;
6880 }
6881- if (likely(!vma || addr + len <= vma->vm_start)) {
6882+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6883 /*
6884 * Remember the place where we stopped the search:
6885 */
6886@@ -190,6 +194,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6887 unsigned long task_size = STACK_TOP32;
6888 unsigned long addr = addr0;
6889 int do_color_align;
6890+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6891
6892 /* This should only ever run for 32-bit processes. */
6893 BUG_ON(!test_thread_flag(TIF_32BIT));
6894@@ -198,7 +203,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6895 /* We do not accept a shared mapping if it would violate
6896 * cache aliasing constraints.
6897 */
6898- if ((flags & MAP_SHARED) &&
6899+ if ((filp || (flags & MAP_SHARED)) &&
6900 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
6901 return -EINVAL;
6902 return addr;
6903@@ -219,8 +224,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6904 addr = PAGE_ALIGN(addr);
6905
6906 vma = find_vma(mm, addr);
6907- if (task_size - len >= addr &&
6908- (!vma || addr + len <= vma->vm_start))
6909+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
6910 return addr;
6911 }
6912
6913@@ -241,7 +245,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6914 /* make sure it can fit in the remaining address space */
6915 if (likely(addr > len)) {
6916 vma = find_vma(mm, addr-len);
6917- if (!vma || addr <= vma->vm_start) {
6918+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
6919 /* remember the address as a hint for next time */
6920 return (mm->free_area_cache = addr-len);
6921 }
6922@@ -250,18 +254,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6923 if (unlikely(mm->mmap_base < len))
6924 goto bottomup;
6925
6926- addr = mm->mmap_base-len;
6927- if (do_color_align)
6928- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6929+ addr = mm->mmap_base - len;
6930
6931 do {
6932+ if (do_color_align)
6933+ addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6934 /*
6935 * Lookup failure means no vma is above this address,
6936 * else if new region fits below vma->vm_start,
6937 * return with success:
6938 */
6939 vma = find_vma(mm, addr);
6940- if (likely(!vma || addr+len <= vma->vm_start)) {
6941+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
6942 /* remember the address as a hint for next time */
6943 return (mm->free_area_cache = addr);
6944 }
6945@@ -271,10 +275,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
6946 mm->cached_hole_size = vma->vm_start - addr;
6947
6948 /* try just below the current vma->vm_start */
6949- addr = vma->vm_start-len;
6950- if (do_color_align)
6951- addr = COLOUR_ALIGN_DOWN(addr, pgoff);
6952- } while (likely(len < vma->vm_start));
6953+ addr = skip_heap_stack_gap(vma, len, offset);
6954+ } while (!IS_ERR_VALUE(addr));
6955
6956 bottomup:
6957 /*
6958@@ -373,6 +375,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6959 gap == RLIM_INFINITY ||
6960 sysctl_legacy_va_layout) {
6961 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6962+
6963+#ifdef CONFIG_PAX_RANDMMAP
6964+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6965+ mm->mmap_base += mm->delta_mmap;
6966+#endif
6967+
6968 mm->get_unmapped_area = arch_get_unmapped_area;
6969 mm->unmap_area = arch_unmap_area;
6970 } else {
6971@@ -385,6 +393,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6972 gap = (task_size / 6 * 5);
6973
6974 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6975+
6976+#ifdef CONFIG_PAX_RANDMMAP
6977+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6978+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6979+#endif
6980+
6981 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6982 mm->unmap_area = arch_unmap_area_topdown;
6983 }
6984diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6985index bf23477..b7425a6 100644
6986--- a/arch/sparc/kernel/syscalls.S
6987+++ b/arch/sparc/kernel/syscalls.S
6988@@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6989 #endif
6990 .align 32
6991 1: ldx [%g6 + TI_FLAGS], %l5
6992- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6993+ andcc %l5, _TIF_WORK_SYSCALL, %g0
6994 be,pt %icc, rtrap
6995 nop
6996 call syscall_trace_leave
6997@@ -189,7 +189,7 @@ linux_sparc_syscall32:
6998
6999 srl %i5, 0, %o5 ! IEU1
7000 srl %i2, 0, %o2 ! IEU0 Group
7001- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7002+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7003 bne,pn %icc, linux_syscall_trace32 ! CTI
7004 mov %i0, %l5 ! IEU1
7005 call %l7 ! CTI Group brk forced
7006@@ -212,7 +212,7 @@ linux_sparc_syscall:
7007
7008 mov %i3, %o3 ! IEU1
7009 mov %i4, %o4 ! IEU0 Group
7010- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7011+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7012 bne,pn %icc, linux_syscall_trace ! CTI Group
7013 mov %i0, %l5 ! IEU0
7014 2: call %l7 ! CTI Group brk forced
7015@@ -228,7 +228,7 @@ ret_sys_call:
7016
7017 cmp %o0, -ERESTART_RESTARTBLOCK
7018 bgeu,pn %xcc, 1f
7019- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
7020+ andcc %l0, _TIF_WORK_SYSCALL, %g0
7021 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
7022
7023 2:
7024diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
7025index a5785ea..405c5f7 100644
7026--- a/arch/sparc/kernel/traps_32.c
7027+++ b/arch/sparc/kernel/traps_32.c
7028@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
7029 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
7030 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
7031
7032+extern void gr_handle_kernel_exploit(void);
7033+
7034 void die_if_kernel(char *str, struct pt_regs *regs)
7035 {
7036 static int die_counter;
7037@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7038 count++ < 30 &&
7039 (((unsigned long) rw) >= PAGE_OFFSET) &&
7040 !(((unsigned long) rw) & 0x7)) {
7041- printk("Caller[%08lx]: %pS\n", rw->ins[7],
7042+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
7043 (void *) rw->ins[7]);
7044 rw = (struct reg_window32 *)rw->ins[6];
7045 }
7046 }
7047 printk("Instruction DUMP:");
7048 instruction_dump ((unsigned long *) regs->pc);
7049- if(regs->psr & PSR_PS)
7050+ if(regs->psr & PSR_PS) {
7051+ gr_handle_kernel_exploit();
7052 do_exit(SIGKILL);
7053+ }
7054 do_exit(SIGSEGV);
7055 }
7056
7057diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
7058index b66a779..8e8d66c 100644
7059--- a/arch/sparc/kernel/traps_64.c
7060+++ b/arch/sparc/kernel/traps_64.c
7061@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
7062 i + 1,
7063 p->trapstack[i].tstate, p->trapstack[i].tpc,
7064 p->trapstack[i].tnpc, p->trapstack[i].tt);
7065- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
7066+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
7067 }
7068 }
7069
7070@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
7071
7072 lvl -= 0x100;
7073 if (regs->tstate & TSTATE_PRIV) {
7074+
7075+#ifdef CONFIG_PAX_REFCOUNT
7076+ if (lvl == 6)
7077+ pax_report_refcount_overflow(regs);
7078+#endif
7079+
7080 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
7081 die_if_kernel(buffer, regs);
7082 }
7083@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
7084 void bad_trap_tl1(struct pt_regs *regs, long lvl)
7085 {
7086 char buffer[32];
7087-
7088+
7089 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
7090 0, lvl, SIGTRAP) == NOTIFY_STOP)
7091 return;
7092
7093+#ifdef CONFIG_PAX_REFCOUNT
7094+ if (lvl == 6)
7095+ pax_report_refcount_overflow(regs);
7096+#endif
7097+
7098 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
7099
7100 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
7101@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
7102 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
7103 printk("%s" "ERROR(%d): ",
7104 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
7105- printk("TPC<%pS>\n", (void *) regs->tpc);
7106+ printk("TPC<%pA>\n", (void *) regs->tpc);
7107 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
7108 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
7109 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
7110@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7111 smp_processor_id(),
7112 (type & 0x1) ? 'I' : 'D',
7113 regs->tpc);
7114- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
7115+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
7116 panic("Irrecoverable Cheetah+ parity error.");
7117 }
7118
7119@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
7120 smp_processor_id(),
7121 (type & 0x1) ? 'I' : 'D',
7122 regs->tpc);
7123- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
7124+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
7125 }
7126
7127 struct sun4v_error_entry {
7128@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
7129
7130 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
7131 regs->tpc, tl);
7132- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
7133+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
7134 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7135- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
7136+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
7137 (void *) regs->u_regs[UREG_I7]);
7138 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
7139 "pte[%lx] error[%lx]\n",
7140@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
7141
7142 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
7143 regs->tpc, tl);
7144- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
7145+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
7146 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
7147- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
7148+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
7149 (void *) regs->u_regs[UREG_I7]);
7150 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
7151 "pte[%lx] error[%lx]\n",
7152@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
7153 fp = (unsigned long)sf->fp + STACK_BIAS;
7154 }
7155
7156- printk(" [%016lx] %pS\n", pc, (void *) pc);
7157+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7158 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7159 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
7160 int index = tsk->curr_ret_stack;
7161 if (tsk->ret_stack && index >= graph) {
7162 pc = tsk->ret_stack[index - graph].ret;
7163- printk(" [%016lx] %pS\n", pc, (void *) pc);
7164+ printk(" [%016lx] %pA\n", pc, (void *) pc);
7165 graph++;
7166 }
7167 }
7168@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
7169 return (struct reg_window *) (fp + STACK_BIAS);
7170 }
7171
7172+extern void gr_handle_kernel_exploit(void);
7173+
7174 void die_if_kernel(char *str, struct pt_regs *regs)
7175 {
7176 static int die_counter;
7177@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7178 while (rw &&
7179 count++ < 30 &&
7180 kstack_valid(tp, (unsigned long) rw)) {
7181- printk("Caller[%016lx]: %pS\n", rw->ins[7],
7182+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
7183 (void *) rw->ins[7]);
7184
7185 rw = kernel_stack_up(rw);
7186@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
7187 }
7188 user_instruction_dump ((unsigned int __user *) regs->tpc);
7189 }
7190- if (regs->tstate & TSTATE_PRIV)
7191+ if (regs->tstate & TSTATE_PRIV) {
7192+ gr_handle_kernel_exploit();
7193 do_exit(SIGKILL);
7194+ }
7195 do_exit(SIGSEGV);
7196 }
7197 EXPORT_SYMBOL(die_if_kernel);
7198diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
7199index 8201c25e..072a2a7 100644
7200--- a/arch/sparc/kernel/unaligned_64.c
7201+++ b/arch/sparc/kernel/unaligned_64.c
7202@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
7203 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
7204
7205 if (__ratelimit(&ratelimit)) {
7206- printk("Kernel unaligned access at TPC[%lx] %pS\n",
7207+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
7208 regs->tpc, (void *) regs->tpc);
7209 }
7210 }
7211diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
7212index 8410065f2..4fd4ca22 100644
7213--- a/arch/sparc/lib/Makefile
7214+++ b/arch/sparc/lib/Makefile
7215@@ -2,7 +2,7 @@
7216 #
7217
7218 asflags-y := -ansi -DST_DIV0=0x02
7219-ccflags-y := -Werror
7220+#ccflags-y := -Werror
7221
7222 lib-$(CONFIG_SPARC32) += ashrdi3.o
7223 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
7224diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
7225index 85c233d..68500e0 100644
7226--- a/arch/sparc/lib/atomic_64.S
7227+++ b/arch/sparc/lib/atomic_64.S
7228@@ -17,7 +17,12 @@
7229 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7230 BACKOFF_SETUP(%o2)
7231 1: lduw [%o1], %g1
7232- add %g1, %o0, %g7
7233+ addcc %g1, %o0, %g7
7234+
7235+#ifdef CONFIG_PAX_REFCOUNT
7236+ tvs %icc, 6
7237+#endif
7238+
7239 cas [%o1], %g1, %g7
7240 cmp %g1, %g7
7241 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7242@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
7243 2: BACKOFF_SPIN(%o2, %o3, 1b)
7244 ENDPROC(atomic_add)
7245
7246+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7247+ BACKOFF_SETUP(%o2)
7248+1: lduw [%o1], %g1
7249+ add %g1, %o0, %g7
7250+ cas [%o1], %g1, %g7
7251+ cmp %g1, %g7
7252+ bne,pn %icc, 2f
7253+ nop
7254+ retl
7255+ nop
7256+2: BACKOFF_SPIN(%o2, %o3, 1b)
7257+ENDPROC(atomic_add_unchecked)
7258+
7259 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7260 BACKOFF_SETUP(%o2)
7261 1: lduw [%o1], %g1
7262- sub %g1, %o0, %g7
7263+ subcc %g1, %o0, %g7
7264+
7265+#ifdef CONFIG_PAX_REFCOUNT
7266+ tvs %icc, 6
7267+#endif
7268+
7269 cas [%o1], %g1, %g7
7270 cmp %g1, %g7
7271 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7272@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7273 2: BACKOFF_SPIN(%o2, %o3, 1b)
7274 ENDPROC(atomic_sub)
7275
7276+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7277+ BACKOFF_SETUP(%o2)
7278+1: lduw [%o1], %g1
7279+ sub %g1, %o0, %g7
7280+ cas [%o1], %g1, %g7
7281+ cmp %g1, %g7
7282+ bne,pn %icc, 2f
7283+ nop
7284+ retl
7285+ nop
7286+2: BACKOFF_SPIN(%o2, %o3, 1b)
7287+ENDPROC(atomic_sub_unchecked)
7288+
7289 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7290 BACKOFF_SETUP(%o2)
7291 1: lduw [%o1], %g1
7292- add %g1, %o0, %g7
7293+ addcc %g1, %o0, %g7
7294+
7295+#ifdef CONFIG_PAX_REFCOUNT
7296+ tvs %icc, 6
7297+#endif
7298+
7299 cas [%o1], %g1, %g7
7300 cmp %g1, %g7
7301 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7302@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7303 2: BACKOFF_SPIN(%o2, %o3, 1b)
7304 ENDPROC(atomic_add_ret)
7305
7306+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7307+ BACKOFF_SETUP(%o2)
7308+1: lduw [%o1], %g1
7309+ addcc %g1, %o0, %g7
7310+ cas [%o1], %g1, %g7
7311+ cmp %g1, %g7
7312+ bne,pn %icc, 2f
7313+ add %g7, %o0, %g7
7314+ sra %g7, 0, %o0
7315+ retl
7316+ nop
7317+2: BACKOFF_SPIN(%o2, %o3, 1b)
7318+ENDPROC(atomic_add_ret_unchecked)
7319+
7320 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7321 BACKOFF_SETUP(%o2)
7322 1: lduw [%o1], %g1
7323- sub %g1, %o0, %g7
7324+ subcc %g1, %o0, %g7
7325+
7326+#ifdef CONFIG_PAX_REFCOUNT
7327+ tvs %icc, 6
7328+#endif
7329+
7330 cas [%o1], %g1, %g7
7331 cmp %g1, %g7
7332 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
7333@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
7334 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7335 BACKOFF_SETUP(%o2)
7336 1: ldx [%o1], %g1
7337- add %g1, %o0, %g7
7338+ addcc %g1, %o0, %g7
7339+
7340+#ifdef CONFIG_PAX_REFCOUNT
7341+ tvs %xcc, 6
7342+#endif
7343+
7344 casx [%o1], %g1, %g7
7345 cmp %g1, %g7
7346 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7347@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
7348 2: BACKOFF_SPIN(%o2, %o3, 1b)
7349 ENDPROC(atomic64_add)
7350
7351+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7352+ BACKOFF_SETUP(%o2)
7353+1: ldx [%o1], %g1
7354+ addcc %g1, %o0, %g7
7355+ casx [%o1], %g1, %g7
7356+ cmp %g1, %g7
7357+ bne,pn %xcc, 2f
7358+ nop
7359+ retl
7360+ nop
7361+2: BACKOFF_SPIN(%o2, %o3, 1b)
7362+ENDPROC(atomic64_add_unchecked)
7363+
7364 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7365 BACKOFF_SETUP(%o2)
7366 1: ldx [%o1], %g1
7367- sub %g1, %o0, %g7
7368+ subcc %g1, %o0, %g7
7369+
7370+#ifdef CONFIG_PAX_REFCOUNT
7371+ tvs %xcc, 6
7372+#endif
7373+
7374 casx [%o1], %g1, %g7
7375 cmp %g1, %g7
7376 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7377@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
7378 2: BACKOFF_SPIN(%o2, %o3, 1b)
7379 ENDPROC(atomic64_sub)
7380
7381+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
7382+ BACKOFF_SETUP(%o2)
7383+1: ldx [%o1], %g1
7384+ subcc %g1, %o0, %g7
7385+ casx [%o1], %g1, %g7
7386+ cmp %g1, %g7
7387+ bne,pn %xcc, 2f
7388+ nop
7389+ retl
7390+ nop
7391+2: BACKOFF_SPIN(%o2, %o3, 1b)
7392+ENDPROC(atomic64_sub_unchecked)
7393+
7394 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7395 BACKOFF_SETUP(%o2)
7396 1: ldx [%o1], %g1
7397- add %g1, %o0, %g7
7398+ addcc %g1, %o0, %g7
7399+
7400+#ifdef CONFIG_PAX_REFCOUNT
7401+ tvs %xcc, 6
7402+#endif
7403+
7404 casx [%o1], %g1, %g7
7405 cmp %g1, %g7
7406 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7407@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
7408 2: BACKOFF_SPIN(%o2, %o3, 1b)
7409 ENDPROC(atomic64_add_ret)
7410
7411+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
7412+ BACKOFF_SETUP(%o2)
7413+1: ldx [%o1], %g1
7414+ addcc %g1, %o0, %g7
7415+ casx [%o1], %g1, %g7
7416+ cmp %g1, %g7
7417+ bne,pn %xcc, 2f
7418+ add %g7, %o0, %g7
7419+ mov %g7, %o0
7420+ retl
7421+ nop
7422+2: BACKOFF_SPIN(%o2, %o3, 1b)
7423+ENDPROC(atomic64_add_ret_unchecked)
7424+
7425 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
7426 BACKOFF_SETUP(%o2)
7427 1: ldx [%o1], %g1
7428- sub %g1, %o0, %g7
7429+ subcc %g1, %o0, %g7
7430+
7431+#ifdef CONFIG_PAX_REFCOUNT
7432+ tvs %xcc, 6
7433+#endif
7434+
7435 casx [%o1], %g1, %g7
7436 cmp %g1, %g7
7437 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
7438diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
7439index 0c4e35e..745d3e4 100644
7440--- a/arch/sparc/lib/ksyms.c
7441+++ b/arch/sparc/lib/ksyms.c
7442@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
7443
7444 /* Atomic counter implementation. */
7445 EXPORT_SYMBOL(atomic_add);
7446+EXPORT_SYMBOL(atomic_add_unchecked);
7447 EXPORT_SYMBOL(atomic_add_ret);
7448+EXPORT_SYMBOL(atomic_add_ret_unchecked);
7449 EXPORT_SYMBOL(atomic_sub);
7450+EXPORT_SYMBOL(atomic_sub_unchecked);
7451 EXPORT_SYMBOL(atomic_sub_ret);
7452 EXPORT_SYMBOL(atomic64_add);
7453+EXPORT_SYMBOL(atomic64_add_unchecked);
7454 EXPORT_SYMBOL(atomic64_add_ret);
7455+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
7456 EXPORT_SYMBOL(atomic64_sub);
7457+EXPORT_SYMBOL(atomic64_sub_unchecked);
7458 EXPORT_SYMBOL(atomic64_sub_ret);
7459 EXPORT_SYMBOL(atomic64_dec_if_positive);
7460
7461diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
7462index 30c3ecc..736f015 100644
7463--- a/arch/sparc/mm/Makefile
7464+++ b/arch/sparc/mm/Makefile
7465@@ -2,7 +2,7 @@
7466 #
7467
7468 asflags-y := -ansi
7469-ccflags-y := -Werror
7470+#ccflags-y := -Werror
7471
7472 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
7473 obj-y += fault_$(BITS).o
7474diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
7475index e98bfda..ea8d221 100644
7476--- a/arch/sparc/mm/fault_32.c
7477+++ b/arch/sparc/mm/fault_32.c
7478@@ -21,6 +21,9 @@
7479 #include <linux/perf_event.h>
7480 #include <linux/interrupt.h>
7481 #include <linux/kdebug.h>
7482+#include <linux/slab.h>
7483+#include <linux/pagemap.h>
7484+#include <linux/compiler.h>
7485
7486 #include <asm/page.h>
7487 #include <asm/pgtable.h>
7488@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
7489 return safe_compute_effective_address(regs, insn);
7490 }
7491
7492+#ifdef CONFIG_PAX_PAGEEXEC
7493+#ifdef CONFIG_PAX_DLRESOLVE
7494+static void pax_emuplt_close(struct vm_area_struct *vma)
7495+{
7496+ vma->vm_mm->call_dl_resolve = 0UL;
7497+}
7498+
7499+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7500+{
7501+ unsigned int *kaddr;
7502+
7503+ vmf->page = alloc_page(GFP_HIGHUSER);
7504+ if (!vmf->page)
7505+ return VM_FAULT_OOM;
7506+
7507+ kaddr = kmap(vmf->page);
7508+ memset(kaddr, 0, PAGE_SIZE);
7509+ kaddr[0] = 0x9DE3BFA8U; /* save */
7510+ flush_dcache_page(vmf->page);
7511+ kunmap(vmf->page);
7512+ return VM_FAULT_MAJOR;
7513+}
7514+
7515+static const struct vm_operations_struct pax_vm_ops = {
7516+ .close = pax_emuplt_close,
7517+ .fault = pax_emuplt_fault
7518+};
7519+
7520+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7521+{
7522+ int ret;
7523+
7524+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7525+ vma->vm_mm = current->mm;
7526+ vma->vm_start = addr;
7527+ vma->vm_end = addr + PAGE_SIZE;
7528+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7529+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7530+ vma->vm_ops = &pax_vm_ops;
7531+
7532+ ret = insert_vm_struct(current->mm, vma);
7533+ if (ret)
7534+ return ret;
7535+
7536+ ++current->mm->total_vm;
7537+ return 0;
7538+}
7539+#endif
7540+
7541+/*
7542+ * PaX: decide what to do with offenders (regs->pc = fault address)
7543+ *
7544+ * returns 1 when task should be killed
7545+ * 2 when patched PLT trampoline was detected
7546+ * 3 when unpatched PLT trampoline was detected
7547+ */
7548+static int pax_handle_fetch_fault(struct pt_regs *regs)
7549+{
7550+
7551+#ifdef CONFIG_PAX_EMUPLT
7552+ int err;
7553+
7554+ do { /* PaX: patched PLT emulation #1 */
7555+ unsigned int sethi1, sethi2, jmpl;
7556+
7557+ err = get_user(sethi1, (unsigned int *)regs->pc);
7558+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
7559+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
7560+
7561+ if (err)
7562+ break;
7563+
7564+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7565+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7566+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7567+ {
7568+ unsigned int addr;
7569+
7570+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7571+ addr = regs->u_regs[UREG_G1];
7572+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7573+ regs->pc = addr;
7574+ regs->npc = addr+4;
7575+ return 2;
7576+ }
7577+ } while (0);
7578+
7579+ do { /* PaX: patched PLT emulation #2 */
7580+ unsigned int ba;
7581+
7582+ err = get_user(ba, (unsigned int *)regs->pc);
7583+
7584+ if (err)
7585+ break;
7586+
7587+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7588+ unsigned int addr;
7589+
7590+ if ((ba & 0xFFC00000U) == 0x30800000U)
7591+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7592+ else
7593+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7594+ regs->pc = addr;
7595+ regs->npc = addr+4;
7596+ return 2;
7597+ }
7598+ } while (0);
7599+
7600+ do { /* PaX: patched PLT emulation #3 */
7601+ unsigned int sethi, bajmpl, nop;
7602+
7603+ err = get_user(sethi, (unsigned int *)regs->pc);
7604+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
7605+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7606+
7607+ if (err)
7608+ break;
7609+
7610+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7611+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7612+ nop == 0x01000000U)
7613+ {
7614+ unsigned int addr;
7615+
7616+ addr = (sethi & 0x003FFFFFU) << 10;
7617+ regs->u_regs[UREG_G1] = addr;
7618+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7619+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7620+ else
7621+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7622+ regs->pc = addr;
7623+ regs->npc = addr+4;
7624+ return 2;
7625+ }
7626+ } while (0);
7627+
7628+ do { /* PaX: unpatched PLT emulation step 1 */
7629+ unsigned int sethi, ba, nop;
7630+
7631+ err = get_user(sethi, (unsigned int *)regs->pc);
7632+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
7633+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
7634+
7635+ if (err)
7636+ break;
7637+
7638+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7639+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7640+ nop == 0x01000000U)
7641+ {
7642+ unsigned int addr, save, call;
7643+
7644+ if ((ba & 0xFFC00000U) == 0x30800000U)
7645+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
7646+ else
7647+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
7648+
7649+ err = get_user(save, (unsigned int *)addr);
7650+ err |= get_user(call, (unsigned int *)(addr+4));
7651+ err |= get_user(nop, (unsigned int *)(addr+8));
7652+ if (err)
7653+ break;
7654+
7655+#ifdef CONFIG_PAX_DLRESOLVE
7656+ if (save == 0x9DE3BFA8U &&
7657+ (call & 0xC0000000U) == 0x40000000U &&
7658+ nop == 0x01000000U)
7659+ {
7660+ struct vm_area_struct *vma;
7661+ unsigned long call_dl_resolve;
7662+
7663+ down_read(&current->mm->mmap_sem);
7664+ call_dl_resolve = current->mm->call_dl_resolve;
7665+ up_read(&current->mm->mmap_sem);
7666+ if (likely(call_dl_resolve))
7667+ goto emulate;
7668+
7669+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7670+
7671+ down_write(&current->mm->mmap_sem);
7672+ if (current->mm->call_dl_resolve) {
7673+ call_dl_resolve = current->mm->call_dl_resolve;
7674+ up_write(&current->mm->mmap_sem);
7675+ if (vma)
7676+ kmem_cache_free(vm_area_cachep, vma);
7677+ goto emulate;
7678+ }
7679+
7680+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7681+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7682+ up_write(&current->mm->mmap_sem);
7683+ if (vma)
7684+ kmem_cache_free(vm_area_cachep, vma);
7685+ return 1;
7686+ }
7687+
7688+ if (pax_insert_vma(vma, call_dl_resolve)) {
7689+ up_write(&current->mm->mmap_sem);
7690+ kmem_cache_free(vm_area_cachep, vma);
7691+ return 1;
7692+ }
7693+
7694+ current->mm->call_dl_resolve = call_dl_resolve;
7695+ up_write(&current->mm->mmap_sem);
7696+
7697+emulate:
7698+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7699+ regs->pc = call_dl_resolve;
7700+ regs->npc = addr+4;
7701+ return 3;
7702+ }
7703+#endif
7704+
7705+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7706+ if ((save & 0xFFC00000U) == 0x05000000U &&
7707+ (call & 0xFFFFE000U) == 0x85C0A000U &&
7708+ nop == 0x01000000U)
7709+ {
7710+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7711+ regs->u_regs[UREG_G2] = addr + 4;
7712+ addr = (save & 0x003FFFFFU) << 10;
7713+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
7714+ regs->pc = addr;
7715+ regs->npc = addr+4;
7716+ return 3;
7717+ }
7718+ }
7719+ } while (0);
7720+
7721+ do { /* PaX: unpatched PLT emulation step 2 */
7722+ unsigned int save, call, nop;
7723+
7724+ err = get_user(save, (unsigned int *)(regs->pc-4));
7725+ err |= get_user(call, (unsigned int *)regs->pc);
7726+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
7727+ if (err)
7728+ break;
7729+
7730+ if (save == 0x9DE3BFA8U &&
7731+ (call & 0xC0000000U) == 0x40000000U &&
7732+ nop == 0x01000000U)
7733+ {
7734+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
7735+
7736+ regs->u_regs[UREG_RETPC] = regs->pc;
7737+ regs->pc = dl_resolve;
7738+ regs->npc = dl_resolve+4;
7739+ return 3;
7740+ }
7741+ } while (0);
7742+#endif
7743+
7744+ return 1;
7745+}
7746+
7747+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7748+{
7749+ unsigned long i;
7750+
7751+ printk(KERN_ERR "PAX: bytes at PC: ");
7752+ for (i = 0; i < 8; i++) {
7753+ unsigned int c;
7754+ if (get_user(c, (unsigned int *)pc+i))
7755+ printk(KERN_CONT "???????? ");
7756+ else
7757+ printk(KERN_CONT "%08x ", c);
7758+ }
7759+ printk("\n");
7760+}
7761+#endif
7762+
7763 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
7764 int text_fault)
7765 {
7766@@ -230,6 +504,24 @@ good_area:
7767 if (!(vma->vm_flags & VM_WRITE))
7768 goto bad_area;
7769 } else {
7770+
7771+#ifdef CONFIG_PAX_PAGEEXEC
7772+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
7773+ up_read(&mm->mmap_sem);
7774+ switch (pax_handle_fetch_fault(regs)) {
7775+
7776+#ifdef CONFIG_PAX_EMUPLT
7777+ case 2:
7778+ case 3:
7779+ return;
7780+#endif
7781+
7782+ }
7783+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
7784+ do_group_exit(SIGKILL);
7785+ }
7786+#endif
7787+
7788 /* Allow reads even for write-only mappings */
7789 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
7790 goto bad_area;
7791diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
7792index 097aee7..5ca6697 100644
7793--- a/arch/sparc/mm/fault_64.c
7794+++ b/arch/sparc/mm/fault_64.c
7795@@ -21,6 +21,9 @@
7796 #include <linux/kprobes.h>
7797 #include <linux/kdebug.h>
7798 #include <linux/percpu.h>
7799+#include <linux/slab.h>
7800+#include <linux/pagemap.h>
7801+#include <linux/compiler.h>
7802
7803 #include <asm/page.h>
7804 #include <asm/pgtable.h>
7805@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
7806 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
7807 regs->tpc);
7808 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
7809- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
7810+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
7811 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
7812 dump_stack();
7813 unhandled_fault(regs->tpc, current, regs);
7814@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
7815 show_regs(regs);
7816 }
7817
7818+#ifdef CONFIG_PAX_PAGEEXEC
7819+#ifdef CONFIG_PAX_DLRESOLVE
7820+static void pax_emuplt_close(struct vm_area_struct *vma)
7821+{
7822+ vma->vm_mm->call_dl_resolve = 0UL;
7823+}
7824+
7825+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7826+{
7827+ unsigned int *kaddr;
7828+
7829+ vmf->page = alloc_page(GFP_HIGHUSER);
7830+ if (!vmf->page)
7831+ return VM_FAULT_OOM;
7832+
7833+ kaddr = kmap(vmf->page);
7834+ memset(kaddr, 0, PAGE_SIZE);
7835+ kaddr[0] = 0x9DE3BFA8U; /* save */
7836+ flush_dcache_page(vmf->page);
7837+ kunmap(vmf->page);
7838+ return VM_FAULT_MAJOR;
7839+}
7840+
7841+static const struct vm_operations_struct pax_vm_ops = {
7842+ .close = pax_emuplt_close,
7843+ .fault = pax_emuplt_fault
7844+};
7845+
7846+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
7847+{
7848+ int ret;
7849+
7850+ INIT_LIST_HEAD(&vma->anon_vma_chain);
7851+ vma->vm_mm = current->mm;
7852+ vma->vm_start = addr;
7853+ vma->vm_end = addr + PAGE_SIZE;
7854+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
7855+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
7856+ vma->vm_ops = &pax_vm_ops;
7857+
7858+ ret = insert_vm_struct(current->mm, vma);
7859+ if (ret)
7860+ return ret;
7861+
7862+ ++current->mm->total_vm;
7863+ return 0;
7864+}
7865+#endif
7866+
7867+/*
7868+ * PaX: decide what to do with offenders (regs->tpc = fault address)
7869+ *
7870+ * returns 1 when task should be killed
7871+ * 2 when patched PLT trampoline was detected
7872+ * 3 when unpatched PLT trampoline was detected
7873+ */
7874+static int pax_handle_fetch_fault(struct pt_regs *regs)
7875+{
7876+
7877+#ifdef CONFIG_PAX_EMUPLT
7878+ int err;
7879+
7880+ do { /* PaX: patched PLT emulation #1 */
7881+ unsigned int sethi1, sethi2, jmpl;
7882+
7883+ err = get_user(sethi1, (unsigned int *)regs->tpc);
7884+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
7885+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
7886+
7887+ if (err)
7888+ break;
7889+
7890+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
7891+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
7892+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
7893+ {
7894+ unsigned long addr;
7895+
7896+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
7897+ addr = regs->u_regs[UREG_G1];
7898+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7899+
7900+ if (test_thread_flag(TIF_32BIT))
7901+ addr &= 0xFFFFFFFFUL;
7902+
7903+ regs->tpc = addr;
7904+ regs->tnpc = addr+4;
7905+ return 2;
7906+ }
7907+ } while (0);
7908+
7909+ do { /* PaX: patched PLT emulation #2 */
7910+ unsigned int ba;
7911+
7912+ err = get_user(ba, (unsigned int *)regs->tpc);
7913+
7914+ if (err)
7915+ break;
7916+
7917+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
7918+ unsigned long addr;
7919+
7920+ if ((ba & 0xFFC00000U) == 0x30800000U)
7921+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7922+ else
7923+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7924+
7925+ if (test_thread_flag(TIF_32BIT))
7926+ addr &= 0xFFFFFFFFUL;
7927+
7928+ regs->tpc = addr;
7929+ regs->tnpc = addr+4;
7930+ return 2;
7931+ }
7932+ } while (0);
7933+
7934+ do { /* PaX: patched PLT emulation #3 */
7935+ unsigned int sethi, bajmpl, nop;
7936+
7937+ err = get_user(sethi, (unsigned int *)regs->tpc);
7938+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
7939+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7940+
7941+ if (err)
7942+ break;
7943+
7944+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7945+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
7946+ nop == 0x01000000U)
7947+ {
7948+ unsigned long addr;
7949+
7950+ addr = (sethi & 0x003FFFFFU) << 10;
7951+ regs->u_regs[UREG_G1] = addr;
7952+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
7953+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7954+ else
7955+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7956+
7957+ if (test_thread_flag(TIF_32BIT))
7958+ addr &= 0xFFFFFFFFUL;
7959+
7960+ regs->tpc = addr;
7961+ regs->tnpc = addr+4;
7962+ return 2;
7963+ }
7964+ } while (0);
7965+
7966+ do { /* PaX: patched PLT emulation #4 */
7967+ unsigned int sethi, mov1, call, mov2;
7968+
7969+ err = get_user(sethi, (unsigned int *)regs->tpc);
7970+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7971+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
7972+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7973+
7974+ if (err)
7975+ break;
7976+
7977+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
7978+ mov1 == 0x8210000FU &&
7979+ (call & 0xC0000000U) == 0x40000000U &&
7980+ mov2 == 0x9E100001U)
7981+ {
7982+ unsigned long addr;
7983+
7984+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7985+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7986+
7987+ if (test_thread_flag(TIF_32BIT))
7988+ addr &= 0xFFFFFFFFUL;
7989+
7990+ regs->tpc = addr;
7991+ regs->tnpc = addr+4;
7992+ return 2;
7993+ }
7994+ } while (0);
7995+
7996+ do { /* PaX: patched PLT emulation #5 */
7997+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7998+
7999+ err = get_user(sethi, (unsigned int *)regs->tpc);
8000+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8001+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8002+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
8003+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
8004+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
8005+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
8006+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
8007+
8008+ if (err)
8009+ break;
8010+
8011+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8012+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8013+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8014+ (or1 & 0xFFFFE000U) == 0x82106000U &&
8015+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8016+ sllx == 0x83287020U &&
8017+ jmpl == 0x81C04005U &&
8018+ nop == 0x01000000U)
8019+ {
8020+ unsigned long addr;
8021+
8022+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8023+ regs->u_regs[UREG_G1] <<= 32;
8024+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8025+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8026+ regs->tpc = addr;
8027+ regs->tnpc = addr+4;
8028+ return 2;
8029+ }
8030+ } while (0);
8031+
8032+ do { /* PaX: patched PLT emulation #6 */
8033+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
8034+
8035+ err = get_user(sethi, (unsigned int *)regs->tpc);
8036+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
8037+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
8038+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
8039+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
8040+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
8041+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
8042+
8043+ if (err)
8044+ break;
8045+
8046+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8047+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
8048+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8049+ sllx == 0x83287020U &&
8050+ (or & 0xFFFFE000U) == 0x8A116000U &&
8051+ jmpl == 0x81C04005U &&
8052+ nop == 0x01000000U)
8053+ {
8054+ unsigned long addr;
8055+
8056+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
8057+ regs->u_regs[UREG_G1] <<= 32;
8058+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
8059+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
8060+ regs->tpc = addr;
8061+ regs->tnpc = addr+4;
8062+ return 2;
8063+ }
8064+ } while (0);
8065+
8066+ do { /* PaX: unpatched PLT emulation step 1 */
8067+ unsigned int sethi, ba, nop;
8068+
8069+ err = get_user(sethi, (unsigned int *)regs->tpc);
8070+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8071+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8072+
8073+ if (err)
8074+ break;
8075+
8076+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8077+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
8078+ nop == 0x01000000U)
8079+ {
8080+ unsigned long addr;
8081+ unsigned int save, call;
8082+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
8083+
8084+ if ((ba & 0xFFC00000U) == 0x30800000U)
8085+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
8086+ else
8087+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8088+
8089+ if (test_thread_flag(TIF_32BIT))
8090+ addr &= 0xFFFFFFFFUL;
8091+
8092+ err = get_user(save, (unsigned int *)addr);
8093+ err |= get_user(call, (unsigned int *)(addr+4));
8094+ err |= get_user(nop, (unsigned int *)(addr+8));
8095+ if (err)
8096+ break;
8097+
8098+#ifdef CONFIG_PAX_DLRESOLVE
8099+ if (save == 0x9DE3BFA8U &&
8100+ (call & 0xC0000000U) == 0x40000000U &&
8101+ nop == 0x01000000U)
8102+ {
8103+ struct vm_area_struct *vma;
8104+ unsigned long call_dl_resolve;
8105+
8106+ down_read(&current->mm->mmap_sem);
8107+ call_dl_resolve = current->mm->call_dl_resolve;
8108+ up_read(&current->mm->mmap_sem);
8109+ if (likely(call_dl_resolve))
8110+ goto emulate;
8111+
8112+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
8113+
8114+ down_write(&current->mm->mmap_sem);
8115+ if (current->mm->call_dl_resolve) {
8116+ call_dl_resolve = current->mm->call_dl_resolve;
8117+ up_write(&current->mm->mmap_sem);
8118+ if (vma)
8119+ kmem_cache_free(vm_area_cachep, vma);
8120+ goto emulate;
8121+ }
8122+
8123+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
8124+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
8125+ up_write(&current->mm->mmap_sem);
8126+ if (vma)
8127+ kmem_cache_free(vm_area_cachep, vma);
8128+ return 1;
8129+ }
8130+
8131+ if (pax_insert_vma(vma, call_dl_resolve)) {
8132+ up_write(&current->mm->mmap_sem);
8133+ kmem_cache_free(vm_area_cachep, vma);
8134+ return 1;
8135+ }
8136+
8137+ current->mm->call_dl_resolve = call_dl_resolve;
8138+ up_write(&current->mm->mmap_sem);
8139+
8140+emulate:
8141+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8142+ regs->tpc = call_dl_resolve;
8143+ regs->tnpc = addr+4;
8144+ return 3;
8145+ }
8146+#endif
8147+
8148+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
8149+ if ((save & 0xFFC00000U) == 0x05000000U &&
8150+ (call & 0xFFFFE000U) == 0x85C0A000U &&
8151+ nop == 0x01000000U)
8152+ {
8153+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8154+ regs->u_regs[UREG_G2] = addr + 4;
8155+ addr = (save & 0x003FFFFFU) << 10;
8156+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
8157+
8158+ if (test_thread_flag(TIF_32BIT))
8159+ addr &= 0xFFFFFFFFUL;
8160+
8161+ regs->tpc = addr;
8162+ regs->tnpc = addr+4;
8163+ return 3;
8164+ }
8165+
8166+ /* PaX: 64-bit PLT stub */
8167+ err = get_user(sethi1, (unsigned int *)addr);
8168+ err |= get_user(sethi2, (unsigned int *)(addr+4));
8169+ err |= get_user(or1, (unsigned int *)(addr+8));
8170+ err |= get_user(or2, (unsigned int *)(addr+12));
8171+ err |= get_user(sllx, (unsigned int *)(addr+16));
8172+ err |= get_user(add, (unsigned int *)(addr+20));
8173+ err |= get_user(jmpl, (unsigned int *)(addr+24));
8174+ err |= get_user(nop, (unsigned int *)(addr+28));
8175+ if (err)
8176+ break;
8177+
8178+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
8179+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
8180+ (or1 & 0xFFFFE000U) == 0x88112000U &&
8181+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
8182+ sllx == 0x89293020U &&
8183+ add == 0x8A010005U &&
8184+ jmpl == 0x89C14000U &&
8185+ nop == 0x01000000U)
8186+ {
8187+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
8188+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
8189+ regs->u_regs[UREG_G4] <<= 32;
8190+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
8191+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
8192+ regs->u_regs[UREG_G4] = addr + 24;
8193+ addr = regs->u_regs[UREG_G5];
8194+ regs->tpc = addr;
8195+ regs->tnpc = addr+4;
8196+ return 3;
8197+ }
8198+ }
8199+ } while (0);
8200+
8201+#ifdef CONFIG_PAX_DLRESOLVE
8202+ do { /* PaX: unpatched PLT emulation step 2 */
8203+ unsigned int save, call, nop;
8204+
8205+ err = get_user(save, (unsigned int *)(regs->tpc-4));
8206+ err |= get_user(call, (unsigned int *)regs->tpc);
8207+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
8208+ if (err)
8209+ break;
8210+
8211+ if (save == 0x9DE3BFA8U &&
8212+ (call & 0xC0000000U) == 0x40000000U &&
8213+ nop == 0x01000000U)
8214+ {
8215+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
8216+
8217+ if (test_thread_flag(TIF_32BIT))
8218+ dl_resolve &= 0xFFFFFFFFUL;
8219+
8220+ regs->u_regs[UREG_RETPC] = regs->tpc;
8221+ regs->tpc = dl_resolve;
8222+ regs->tnpc = dl_resolve+4;
8223+ return 3;
8224+ }
8225+ } while (0);
8226+#endif
8227+
8228+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
8229+ unsigned int sethi, ba, nop;
8230+
8231+ err = get_user(sethi, (unsigned int *)regs->tpc);
8232+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
8233+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
8234+
8235+ if (err)
8236+ break;
8237+
8238+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
8239+ (ba & 0xFFF00000U) == 0x30600000U &&
8240+ nop == 0x01000000U)
8241+ {
8242+ unsigned long addr;
8243+
8244+ addr = (sethi & 0x003FFFFFU) << 10;
8245+ regs->u_regs[UREG_G1] = addr;
8246+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
8247+
8248+ if (test_thread_flag(TIF_32BIT))
8249+ addr &= 0xFFFFFFFFUL;
8250+
8251+ regs->tpc = addr;
8252+ regs->tnpc = addr+4;
8253+ return 2;
8254+ }
8255+ } while (0);
8256+
8257+#endif
8258+
8259+ return 1;
8260+}
8261+
8262+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8263+{
8264+ unsigned long i;
8265+
8266+ printk(KERN_ERR "PAX: bytes at PC: ");
8267+ for (i = 0; i < 8; i++) {
8268+ unsigned int c;
8269+ if (get_user(c, (unsigned int *)pc+i))
8270+ printk(KERN_CONT "???????? ");
8271+ else
8272+ printk(KERN_CONT "%08x ", c);
8273+ }
8274+ printk("\n");
8275+}
8276+#endif
8277+
8278 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
8279 {
8280 struct mm_struct *mm = current->mm;
8281@@ -341,6 +804,29 @@ retry:
8282 if (!vma)
8283 goto bad_area;
8284
8285+#ifdef CONFIG_PAX_PAGEEXEC
8286+ /* PaX: detect ITLB misses on non-exec pages */
8287+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
8288+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
8289+ {
8290+ if (address != regs->tpc)
8291+ goto good_area;
8292+
8293+ up_read(&mm->mmap_sem);
8294+ switch (pax_handle_fetch_fault(regs)) {
8295+
8296+#ifdef CONFIG_PAX_EMUPLT
8297+ case 2:
8298+ case 3:
8299+ return;
8300+#endif
8301+
8302+ }
8303+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
8304+ do_group_exit(SIGKILL);
8305+ }
8306+#endif
8307+
8308 /* Pure DTLB misses do not tell us whether the fault causing
8309 * load/store/atomic was a write or not, it only says that there
8310 * was no match. So in such a case we (carefully) read the
8311diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
8312index f76f83d..ee0d859 100644
8313--- a/arch/sparc/mm/hugetlbpage.c
8314+++ b/arch/sparc/mm/hugetlbpage.c
8315@@ -34,6 +34,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
8316 struct vm_area_struct * vma;
8317 unsigned long task_size = TASK_SIZE;
8318 unsigned long start_addr;
8319+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8320
8321 if (test_thread_flag(TIF_32BIT))
8322 task_size = STACK_TOP32;
8323@@ -67,7 +68,7 @@ full_search:
8324 }
8325 return -ENOMEM;
8326 }
8327- if (likely(!vma || addr + len <= vma->vm_start)) {
8328+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8329 /*
8330 * Remember the place where we stopped the search:
8331 */
8332@@ -90,6 +91,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8333 struct vm_area_struct *vma;
8334 struct mm_struct *mm = current->mm;
8335 unsigned long addr = addr0;
8336+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8337
8338 /* This should only ever run for 32-bit processes. */
8339 BUG_ON(!test_thread_flag(TIF_32BIT));
8340@@ -106,7 +108,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8341 /* make sure it can fit in the remaining address space */
8342 if (likely(addr > len)) {
8343 vma = find_vma(mm, addr-len);
8344- if (!vma || addr <= vma->vm_start) {
8345+ if (check_heap_stack_gap(vma, addr - len, len, offset)) {
8346 /* remember the address as a hint for next time */
8347 return (mm->free_area_cache = addr-len);
8348 }
8349@@ -115,16 +117,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8350 if (unlikely(mm->mmap_base < len))
8351 goto bottomup;
8352
8353- addr = (mm->mmap_base-len) & HPAGE_MASK;
8354+ addr = mm->mmap_base - len;
8355
8356 do {
8357+ addr &= HPAGE_MASK;
8358 /*
8359 * Lookup failure means no vma is above this address,
8360 * else if new region fits below vma->vm_start,
8361 * return with success:
8362 */
8363 vma = find_vma(mm, addr);
8364- if (likely(!vma || addr+len <= vma->vm_start)) {
8365+ if (likely(check_heap_stack_gap(vma, addr, len, offset))) {
8366 /* remember the address as a hint for next time */
8367 return (mm->free_area_cache = addr);
8368 }
8369@@ -134,8 +137,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8370 mm->cached_hole_size = vma->vm_start - addr;
8371
8372 /* try just below the current vma->vm_start */
8373- addr = (vma->vm_start-len) & HPAGE_MASK;
8374- } while (likely(len < vma->vm_start));
8375+ addr = skip_heap_stack_gap(vma, len, offset);
8376+ } while (!IS_ERR_VALUE(addr));
8377
8378 bottomup:
8379 /*
8380@@ -163,6 +166,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8381 struct mm_struct *mm = current->mm;
8382 struct vm_area_struct *vma;
8383 unsigned long task_size = TASK_SIZE;
8384+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8385
8386 if (test_thread_flag(TIF_32BIT))
8387 task_size = STACK_TOP32;
8388@@ -181,8 +185,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
8389 if (addr) {
8390 addr = ALIGN(addr, HPAGE_SIZE);
8391 vma = find_vma(mm, addr);
8392- if (task_size - len >= addr &&
8393- (!vma || addr + len <= vma->vm_start))
8394+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8395 return addr;
8396 }
8397 if (mm->get_unmapped_area == arch_get_unmapped_area)
8398diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
8399index f4500c6..889656c 100644
8400--- a/arch/tile/include/asm/atomic_64.h
8401+++ b/arch/tile/include/asm/atomic_64.h
8402@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8403
8404 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8405
8406+#define atomic64_read_unchecked(v) atomic64_read(v)
8407+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8408+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8409+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8410+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8411+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8412+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8413+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8414+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8415+
8416 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
8417 #define smp_mb__before_atomic_dec() smp_mb()
8418 #define smp_mb__after_atomic_dec() smp_mb()
8419diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
8420index a9a5299..0fce79e 100644
8421--- a/arch/tile/include/asm/cache.h
8422+++ b/arch/tile/include/asm/cache.h
8423@@ -15,11 +15,12 @@
8424 #ifndef _ASM_TILE_CACHE_H
8425 #define _ASM_TILE_CACHE_H
8426
8427+#include <linux/const.h>
8428 #include <arch/chip.h>
8429
8430 /* bytes per L1 data cache line */
8431 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
8432-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8433+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8434
8435 /* bytes per L2 cache line */
8436 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
8437diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
8438index 9ab078a..d6635c2 100644
8439--- a/arch/tile/include/asm/uaccess.h
8440+++ b/arch/tile/include/asm/uaccess.h
8441@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
8442 const void __user *from,
8443 unsigned long n)
8444 {
8445- int sz = __compiletime_object_size(to);
8446+ size_t sz = __compiletime_object_size(to);
8447
8448- if (likely(sz == -1 || sz >= n))
8449+ if (likely(sz == (size_t)-1 || sz >= n))
8450 n = _copy_from_user(to, from, n);
8451 else
8452 copy_from_user_overflow();
8453diff --git a/arch/um/Makefile b/arch/um/Makefile
8454index 133f7de..1d6f2f1 100644
8455--- a/arch/um/Makefile
8456+++ b/arch/um/Makefile
8457@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
8458 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
8459 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
8460
8461+ifdef CONSTIFY_PLUGIN
8462+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8463+endif
8464+
8465 #This will adjust *FLAGS accordingly to the platform.
8466 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
8467
8468diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
8469index 19e1bdd..3665b77 100644
8470--- a/arch/um/include/asm/cache.h
8471+++ b/arch/um/include/asm/cache.h
8472@@ -1,6 +1,7 @@
8473 #ifndef __UM_CACHE_H
8474 #define __UM_CACHE_H
8475
8476+#include <linux/const.h>
8477
8478 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
8479 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
8480@@ -12,6 +13,6 @@
8481 # define L1_CACHE_SHIFT 5
8482 #endif
8483
8484-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8485+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8486
8487 #endif
8488diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
8489index 2e0a6b1..a64d0f5 100644
8490--- a/arch/um/include/asm/kmap_types.h
8491+++ b/arch/um/include/asm/kmap_types.h
8492@@ -8,6 +8,6 @@
8493
8494 /* No more #include "asm/arch/kmap_types.h" ! */
8495
8496-#define KM_TYPE_NR 14
8497+#define KM_TYPE_NR 15
8498
8499 #endif
8500diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
8501index 5ff53d9..5850cdf 100644
8502--- a/arch/um/include/asm/page.h
8503+++ b/arch/um/include/asm/page.h
8504@@ -14,6 +14,9 @@
8505 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
8506 #define PAGE_MASK (~(PAGE_SIZE-1))
8507
8508+#define ktla_ktva(addr) (addr)
8509+#define ktva_ktla(addr) (addr)
8510+
8511 #ifndef __ASSEMBLY__
8512
8513 struct page;
8514diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
8515index 0032f92..cd151e0 100644
8516--- a/arch/um/include/asm/pgtable-3level.h
8517+++ b/arch/um/include/asm/pgtable-3level.h
8518@@ -58,6 +58,7 @@
8519 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
8520 #define pud_populate(mm, pud, pmd) \
8521 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
8522+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8523
8524 #ifdef CONFIG_64BIT
8525 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
8526diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
8527index b6d699c..df7ac1d 100644
8528--- a/arch/um/kernel/process.c
8529+++ b/arch/um/kernel/process.c
8530@@ -387,22 +387,6 @@ int singlestepping(void * t)
8531 return 2;
8532 }
8533
8534-/*
8535- * Only x86 and x86_64 have an arch_align_stack().
8536- * All other arches have "#define arch_align_stack(x) (x)"
8537- * in their asm/system.h
8538- * As this is included in UML from asm-um/system-generic.h,
8539- * we can use it to behave as the subarch does.
8540- */
8541-#ifndef arch_align_stack
8542-unsigned long arch_align_stack(unsigned long sp)
8543-{
8544- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8545- sp -= get_random_int() % 8192;
8546- return sp & ~0xf;
8547-}
8548-#endif
8549-
8550 unsigned long get_wchan(struct task_struct *p)
8551 {
8552 unsigned long stack_page, sp, ip;
8553diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
8554index ad8f795..2c7eec6 100644
8555--- a/arch/unicore32/include/asm/cache.h
8556+++ b/arch/unicore32/include/asm/cache.h
8557@@ -12,8 +12,10 @@
8558 #ifndef __UNICORE_CACHE_H__
8559 #define __UNICORE_CACHE_H__
8560
8561-#define L1_CACHE_SHIFT (5)
8562-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8563+#include <linux/const.h>
8564+
8565+#define L1_CACHE_SHIFT 5
8566+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8567
8568 /*
8569 * Memory returned by kmalloc() may be used for DMA, so we must make
8570diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
8571index 46c3bff..c2286e7 100644
8572--- a/arch/x86/Kconfig
8573+++ b/arch/x86/Kconfig
8574@@ -241,7 +241,7 @@ config X86_HT
8575
8576 config X86_32_LAZY_GS
8577 def_bool y
8578- depends on X86_32 && !CC_STACKPROTECTOR
8579+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
8580
8581 config ARCH_HWEIGHT_CFLAGS
8582 string
8583@@ -1056,7 +1056,7 @@ choice
8584
8585 config NOHIGHMEM
8586 bool "off"
8587- depends on !X86_NUMAQ
8588+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8589 ---help---
8590 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
8591 However, the address space of 32-bit x86 processors is only 4
8592@@ -1093,7 +1093,7 @@ config NOHIGHMEM
8593
8594 config HIGHMEM4G
8595 bool "4GB"
8596- depends on !X86_NUMAQ
8597+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
8598 ---help---
8599 Select this if you have a 32-bit processor and between 1 and 4
8600 gigabytes of physical RAM.
8601@@ -1147,7 +1147,7 @@ config PAGE_OFFSET
8602 hex
8603 default 0xB0000000 if VMSPLIT_3G_OPT
8604 default 0x80000000 if VMSPLIT_2G
8605- default 0x78000000 if VMSPLIT_2G_OPT
8606+ default 0x70000000 if VMSPLIT_2G_OPT
8607 default 0x40000000 if VMSPLIT_1G
8608 default 0xC0000000
8609 depends on X86_32
8610@@ -1548,6 +1548,7 @@ config SECCOMP
8611
8612 config CC_STACKPROTECTOR
8613 bool "Enable -fstack-protector buffer overflow detection"
8614+ depends on X86_64 || !PAX_MEMORY_UDEREF
8615 ---help---
8616 This option turns on the -fstack-protector GCC feature. This
8617 feature puts, at the beginning of functions, a canary value on
8618@@ -1605,6 +1606,7 @@ config KEXEC_JUMP
8619 config PHYSICAL_START
8620 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
8621 default "0x1000000"
8622+ range 0x400000 0x40000000
8623 ---help---
8624 This gives the physical address where the kernel is loaded.
8625
8626@@ -1668,6 +1670,7 @@ config X86_NEED_RELOCS
8627 config PHYSICAL_ALIGN
8628 hex "Alignment value to which kernel should be aligned" if X86_32
8629 default "0x1000000"
8630+ range 0x400000 0x1000000 if PAX_KERNEXEC
8631 range 0x2000 0x1000000
8632 ---help---
8633 This value puts the alignment restrictions on physical address
8634@@ -1699,9 +1702,10 @@ config HOTPLUG_CPU
8635 Say N if you want to disable CPU hotplug.
8636
8637 config COMPAT_VDSO
8638- def_bool y
8639+ def_bool n
8640 prompt "Compat VDSO support"
8641 depends on X86_32 || IA32_EMULATION
8642+ depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
8643 ---help---
8644 Map the 32-bit VDSO to the predictable old-style address too.
8645
8646diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
8647index f3b86d0..17fd30f 100644
8648--- a/arch/x86/Kconfig.cpu
8649+++ b/arch/x86/Kconfig.cpu
8650@@ -335,7 +335,7 @@ config X86_PPRO_FENCE
8651
8652 config X86_F00F_BUG
8653 def_bool y
8654- depends on M586MMX || M586TSC || M586 || M486 || M386
8655+ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8656
8657 config X86_INVD_BUG
8658 def_bool y
8659@@ -359,7 +359,7 @@ config X86_POPAD_OK
8660
8661 config X86_ALIGNMENT_16
8662 def_bool y
8663- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8664+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8665
8666 config X86_INTEL_USERCOPY
8667 def_bool y
8668@@ -405,7 +405,7 @@ config X86_CMPXCHG64
8669 # generates cmov.
8670 config X86_CMOV
8671 def_bool y
8672- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8673+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
8674
8675 config X86_MINIMUM_CPU_FAMILY
8676 int
8677diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
8678index b322f12..652d0d9 100644
8679--- a/arch/x86/Kconfig.debug
8680+++ b/arch/x86/Kconfig.debug
8681@@ -84,7 +84,7 @@ config X86_PTDUMP
8682 config DEBUG_RODATA
8683 bool "Write protect kernel read-only data structures"
8684 default y
8685- depends on DEBUG_KERNEL
8686+ depends on DEBUG_KERNEL && BROKEN
8687 ---help---
8688 Mark the kernel read-only data as write-protected in the pagetables,
8689 in order to catch accidental (and incorrect) writes to such const
8690@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
8691
8692 config DEBUG_SET_MODULE_RONX
8693 bool "Set loadable kernel module data as NX and text as RO"
8694- depends on MODULES
8695+ depends on MODULES && BROKEN
8696 ---help---
8697 This option helps catch unintended modifications to loadable
8698 kernel module's text and read-only data. It also prevents execution
8699@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
8700
8701 config DEBUG_STRICT_USER_COPY_CHECKS
8702 bool "Strict copy size checks"
8703- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
8704+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
8705 ---help---
8706 Enabling this option turns a certain set of sanity checks for user
8707 copy operations into compile time failures.
8708diff --git a/arch/x86/Makefile b/arch/x86/Makefile
8709index 05afcca..b6ecb51 100644
8710--- a/arch/x86/Makefile
8711+++ b/arch/x86/Makefile
8712@@ -50,6 +50,7 @@ else
8713 UTS_MACHINE := x86_64
8714 CHECKFLAGS += -D__x86_64__ -m64
8715
8716+ biarch := $(call cc-option,-m64)
8717 KBUILD_AFLAGS += -m64
8718 KBUILD_CFLAGS += -m64
8719
8720@@ -229,3 +230,12 @@ define archhelp
8721 echo ' FDARGS="..." arguments for the booted kernel'
8722 echo ' FDINITRD=file initrd for the booted kernel'
8723 endef
8724+
8725+define OLD_LD
8726+
8727+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
8728+*** Please upgrade your binutils to 2.18 or newer
8729+endef
8730+
8731+archprepare:
8732+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
8733diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
8734index ccce0ed..fd9da25 100644
8735--- a/arch/x86/boot/Makefile
8736+++ b/arch/x86/boot/Makefile
8737@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
8738 $(call cc-option, -fno-stack-protector) \
8739 $(call cc-option, -mpreferred-stack-boundary=2)
8740 KBUILD_CFLAGS += $(call cc-option, -m32)
8741+ifdef CONSTIFY_PLUGIN
8742+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8743+endif
8744 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8745 GCOV_PROFILE := n
8746
8747diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
8748index 878e4b9..20537ab 100644
8749--- a/arch/x86/boot/bitops.h
8750+++ b/arch/x86/boot/bitops.h
8751@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8752 u8 v;
8753 const u32 *p = (const u32 *)addr;
8754
8755- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8756+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
8757 return v;
8758 }
8759
8760@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
8761
8762 static inline void set_bit(int nr, void *addr)
8763 {
8764- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8765+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
8766 }
8767
8768 #endif /* BOOT_BITOPS_H */
8769diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
8770index 18997e5..83d9c67 100644
8771--- a/arch/x86/boot/boot.h
8772+++ b/arch/x86/boot/boot.h
8773@@ -85,7 +85,7 @@ static inline void io_delay(void)
8774 static inline u16 ds(void)
8775 {
8776 u16 seg;
8777- asm("movw %%ds,%0" : "=rm" (seg));
8778+ asm volatile("movw %%ds,%0" : "=rm" (seg));
8779 return seg;
8780 }
8781
8782@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
8783 static inline int memcmp(const void *s1, const void *s2, size_t len)
8784 {
8785 u8 diff;
8786- asm("repe; cmpsb; setnz %0"
8787+ asm volatile("repe; cmpsb; setnz %0"
8788 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
8789 return diff;
8790 }
8791diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
8792index 8a84501..b2d165f 100644
8793--- a/arch/x86/boot/compressed/Makefile
8794+++ b/arch/x86/boot/compressed/Makefile
8795@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
8796 KBUILD_CFLAGS += $(cflags-y)
8797 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
8798 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
8799+ifdef CONSTIFY_PLUGIN
8800+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
8801+endif
8802
8803 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
8804 GCOV_PROFILE := n
8805diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
8806index e87b0ca..2bce457 100644
8807--- a/arch/x86/boot/compressed/eboot.c
8808+++ b/arch/x86/boot/compressed/eboot.c
8809@@ -144,7 +144,6 @@ again:
8810 *addr = max_addr;
8811 }
8812
8813-free_pool:
8814 efi_call_phys1(sys_table->boottime->free_pool, map);
8815
8816 fail:
8817@@ -208,7 +207,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
8818 if (i == map_size / desc_size)
8819 status = EFI_NOT_FOUND;
8820
8821-free_pool:
8822 efi_call_phys1(sys_table->boottime->free_pool, map);
8823 fail:
8824 return status;
8825diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
8826index aa4aaf1..6656f2f 100644
8827--- a/arch/x86/boot/compressed/head_32.S
8828+++ b/arch/x86/boot/compressed/head_32.S
8829@@ -116,7 +116,7 @@ preferred_addr:
8830 notl %eax
8831 andl %eax, %ebx
8832 #else
8833- movl $LOAD_PHYSICAL_ADDR, %ebx
8834+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8835 #endif
8836
8837 /* Target address to relocate to for decompression */
8838@@ -202,7 +202,7 @@ relocated:
8839 * and where it was actually loaded.
8840 */
8841 movl %ebp, %ebx
8842- subl $LOAD_PHYSICAL_ADDR, %ebx
8843+ subl $____LOAD_PHYSICAL_ADDR, %ebx
8844 jz 2f /* Nothing to be done if loaded at compiled addr. */
8845 /*
8846 * Process relocations.
8847@@ -210,8 +210,7 @@ relocated:
8848
8849 1: subl $4, %edi
8850 movl (%edi), %ecx
8851- testl %ecx, %ecx
8852- jz 2f
8853+ jecxz 2f
8854 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
8855 jmp 1b
8856 2:
8857diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
8858index 2c4b171..e1fa5b1 100644
8859--- a/arch/x86/boot/compressed/head_64.S
8860+++ b/arch/x86/boot/compressed/head_64.S
8861@@ -91,7 +91,7 @@ ENTRY(startup_32)
8862 notl %eax
8863 andl %eax, %ebx
8864 #else
8865- movl $LOAD_PHYSICAL_ADDR, %ebx
8866+ movl $____LOAD_PHYSICAL_ADDR, %ebx
8867 #endif
8868
8869 /* Target address to relocate to for decompression */
8870@@ -273,7 +273,7 @@ preferred_addr:
8871 notq %rax
8872 andq %rax, %rbp
8873 #else
8874- movq $LOAD_PHYSICAL_ADDR, %rbp
8875+ movq $____LOAD_PHYSICAL_ADDR, %rbp
8876 #endif
8877
8878 /* Target address to relocate to for decompression */
8879diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
8880index 88f7ff6..ed695dd 100644
8881--- a/arch/x86/boot/compressed/misc.c
8882+++ b/arch/x86/boot/compressed/misc.c
8883@@ -303,7 +303,7 @@ static void parse_elf(void *output)
8884 case PT_LOAD:
8885 #ifdef CONFIG_RELOCATABLE
8886 dest = output;
8887- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
8888+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
8889 #else
8890 dest = (void *)(phdr->p_paddr);
8891 #endif
8892@@ -352,7 +352,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
8893 error("Destination address too large");
8894 #endif
8895 #ifndef CONFIG_RELOCATABLE
8896- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
8897+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
8898 error("Wrong destination address");
8899 #endif
8900
8901diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
8902index 4d3ff03..e4972ff 100644
8903--- a/arch/x86/boot/cpucheck.c
8904+++ b/arch/x86/boot/cpucheck.c
8905@@ -74,7 +74,7 @@ static int has_fpu(void)
8906 u16 fcw = -1, fsw = -1;
8907 u32 cr0;
8908
8909- asm("movl %%cr0,%0" : "=r" (cr0));
8910+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
8911 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
8912 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
8913 asm volatile("movl %0,%%cr0" : : "r" (cr0));
8914@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
8915 {
8916 u32 f0, f1;
8917
8918- asm("pushfl ; "
8919+ asm volatile("pushfl ; "
8920 "pushfl ; "
8921 "popl %0 ; "
8922 "movl %0,%1 ; "
8923@@ -115,7 +115,7 @@ static void get_flags(void)
8924 set_bit(X86_FEATURE_FPU, cpu.flags);
8925
8926 if (has_eflag(X86_EFLAGS_ID)) {
8927- asm("cpuid"
8928+ asm volatile("cpuid"
8929 : "=a" (max_intel_level),
8930 "=b" (cpu_vendor[0]),
8931 "=d" (cpu_vendor[1]),
8932@@ -124,7 +124,7 @@ static void get_flags(void)
8933
8934 if (max_intel_level >= 0x00000001 &&
8935 max_intel_level <= 0x0000ffff) {
8936- asm("cpuid"
8937+ asm volatile("cpuid"
8938 : "=a" (tfms),
8939 "=c" (cpu.flags[4]),
8940 "=d" (cpu.flags[0])
8941@@ -136,7 +136,7 @@ static void get_flags(void)
8942 cpu.model += ((tfms >> 16) & 0xf) << 4;
8943 }
8944
8945- asm("cpuid"
8946+ asm volatile("cpuid"
8947 : "=a" (max_amd_level)
8948 : "a" (0x80000000)
8949 : "ebx", "ecx", "edx");
8950@@ -144,7 +144,7 @@ static void get_flags(void)
8951 if (max_amd_level >= 0x80000001 &&
8952 max_amd_level <= 0x8000ffff) {
8953 u32 eax = 0x80000001;
8954- asm("cpuid"
8955+ asm volatile("cpuid"
8956 : "+a" (eax),
8957 "=c" (cpu.flags[6]),
8958 "=d" (cpu.flags[1])
8959@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8960 u32 ecx = MSR_K7_HWCR;
8961 u32 eax, edx;
8962
8963- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8964+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8965 eax &= ~(1 << 15);
8966- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8967+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8968
8969 get_flags(); /* Make sure it really did something */
8970 err = check_flags();
8971@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8972 u32 ecx = MSR_VIA_FCR;
8973 u32 eax, edx;
8974
8975- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8976+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8977 eax |= (1<<1)|(1<<7);
8978- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8979+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8980
8981 set_bit(X86_FEATURE_CX8, cpu.flags);
8982 err = check_flags();
8983@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8984 u32 eax, edx;
8985 u32 level = 1;
8986
8987- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8988- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8989- asm("cpuid"
8990+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8991+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8992+ asm volatile("cpuid"
8993 : "+a" (level), "=d" (cpu.flags[0])
8994 : : "ecx", "ebx");
8995- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8996+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8997
8998 err = check_flags();
8999 }
9000diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
9001index 8c132a6..13e5c96 100644
9002--- a/arch/x86/boot/header.S
9003+++ b/arch/x86/boot/header.S
9004@@ -387,10 +387,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
9005 # single linked list of
9006 # struct setup_data
9007
9008-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
9009+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
9010
9011 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
9012+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
9013+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
9014+#else
9015 #define VO_INIT_SIZE (VO__end - VO__text)
9016+#endif
9017 #if ZO_INIT_SIZE > VO_INIT_SIZE
9018 #define INIT_SIZE ZO_INIT_SIZE
9019 #else
9020diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
9021index db75d07..8e6d0af 100644
9022--- a/arch/x86/boot/memory.c
9023+++ b/arch/x86/boot/memory.c
9024@@ -19,7 +19,7 @@
9025
9026 static int detect_memory_e820(void)
9027 {
9028- int count = 0;
9029+ unsigned int count = 0;
9030 struct biosregs ireg, oreg;
9031 struct e820entry *desc = boot_params.e820_map;
9032 static struct e820entry buf; /* static so it is zeroed */
9033diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
9034index 11e8c6e..fdbb1ed 100644
9035--- a/arch/x86/boot/video-vesa.c
9036+++ b/arch/x86/boot/video-vesa.c
9037@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
9038
9039 boot_params.screen_info.vesapm_seg = oreg.es;
9040 boot_params.screen_info.vesapm_off = oreg.di;
9041+ boot_params.screen_info.vesapm_size = oreg.cx;
9042 }
9043
9044 /*
9045diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
9046index 43eda28..5ab5fdb 100644
9047--- a/arch/x86/boot/video.c
9048+++ b/arch/x86/boot/video.c
9049@@ -96,7 +96,7 @@ static void store_mode_params(void)
9050 static unsigned int get_entry(void)
9051 {
9052 char entry_buf[4];
9053- int i, len = 0;
9054+ unsigned int i, len = 0;
9055 int key;
9056 unsigned int v;
9057
9058diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
9059index 5b577d5..3c1fed4 100644
9060--- a/arch/x86/crypto/aes-x86_64-asm_64.S
9061+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
9062@@ -8,6 +8,8 @@
9063 * including this sentence is retained in full.
9064 */
9065
9066+#include <asm/alternative-asm.h>
9067+
9068 .extern crypto_ft_tab
9069 .extern crypto_it_tab
9070 .extern crypto_fl_tab
9071@@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
9072 je B192; \
9073 leaq 32(r9),r9;
9074
9075+#define ret pax_force_retaddr 0, 1; ret
9076+
9077 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
9078 movq r1,r2; \
9079 movq r3,r4; \
9080diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
9081index 3470624..201259d 100644
9082--- a/arch/x86/crypto/aesni-intel_asm.S
9083+++ b/arch/x86/crypto/aesni-intel_asm.S
9084@@ -31,6 +31,7 @@
9085
9086 #include <linux/linkage.h>
9087 #include <asm/inst.h>
9088+#include <asm/alternative-asm.h>
9089
9090 #ifdef __x86_64__
9091 .data
9092@@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
9093 pop %r14
9094 pop %r13
9095 pop %r12
9096+ pax_force_retaddr 0, 1
9097 ret
9098+ENDPROC(aesni_gcm_dec)
9099
9100
9101 /*****************************************************************************
9102@@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
9103 pop %r14
9104 pop %r13
9105 pop %r12
9106+ pax_force_retaddr 0, 1
9107 ret
9108+ENDPROC(aesni_gcm_enc)
9109
9110 #endif
9111
9112@@ -1714,6 +1719,7 @@ _key_expansion_256a:
9113 pxor %xmm1, %xmm0
9114 movaps %xmm0, (TKEYP)
9115 add $0x10, TKEYP
9116+ pax_force_retaddr_bts
9117 ret
9118
9119 .align 4
9120@@ -1738,6 +1744,7 @@ _key_expansion_192a:
9121 shufps $0b01001110, %xmm2, %xmm1
9122 movaps %xmm1, 0x10(TKEYP)
9123 add $0x20, TKEYP
9124+ pax_force_retaddr_bts
9125 ret
9126
9127 .align 4
9128@@ -1757,6 +1764,7 @@ _key_expansion_192b:
9129
9130 movaps %xmm0, (TKEYP)
9131 add $0x10, TKEYP
9132+ pax_force_retaddr_bts
9133 ret
9134
9135 .align 4
9136@@ -1769,6 +1777,7 @@ _key_expansion_256b:
9137 pxor %xmm1, %xmm2
9138 movaps %xmm2, (TKEYP)
9139 add $0x10, TKEYP
9140+ pax_force_retaddr_bts
9141 ret
9142
9143 /*
9144@@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
9145 #ifndef __x86_64__
9146 popl KEYP
9147 #endif
9148+ pax_force_retaddr 0, 1
9149 ret
9150+ENDPROC(aesni_set_key)
9151
9152 /*
9153 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
9154@@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
9155 popl KLEN
9156 popl KEYP
9157 #endif
9158+ pax_force_retaddr 0, 1
9159 ret
9160+ENDPROC(aesni_enc)
9161
9162 /*
9163 * _aesni_enc1: internal ABI
9164@@ -1959,6 +1972,7 @@ _aesni_enc1:
9165 AESENC KEY STATE
9166 movaps 0x70(TKEYP), KEY
9167 AESENCLAST KEY STATE
9168+ pax_force_retaddr_bts
9169 ret
9170
9171 /*
9172@@ -2067,6 +2081,7 @@ _aesni_enc4:
9173 AESENCLAST KEY STATE2
9174 AESENCLAST KEY STATE3
9175 AESENCLAST KEY STATE4
9176+ pax_force_retaddr_bts
9177 ret
9178
9179 /*
9180@@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
9181 popl KLEN
9182 popl KEYP
9183 #endif
9184+ pax_force_retaddr 0, 1
9185 ret
9186+ENDPROC(aesni_dec)
9187
9188 /*
9189 * _aesni_dec1: internal ABI
9190@@ -2146,6 +2163,7 @@ _aesni_dec1:
9191 AESDEC KEY STATE
9192 movaps 0x70(TKEYP), KEY
9193 AESDECLAST KEY STATE
9194+ pax_force_retaddr_bts
9195 ret
9196
9197 /*
9198@@ -2254,6 +2272,7 @@ _aesni_dec4:
9199 AESDECLAST KEY STATE2
9200 AESDECLAST KEY STATE3
9201 AESDECLAST KEY STATE4
9202+ pax_force_retaddr_bts
9203 ret
9204
9205 /*
9206@@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
9207 popl KEYP
9208 popl LEN
9209 #endif
9210+ pax_force_retaddr 0, 1
9211 ret
9212+ENDPROC(aesni_ecb_enc)
9213
9214 /*
9215 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9216@@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
9217 popl KEYP
9218 popl LEN
9219 #endif
9220+ pax_force_retaddr 0, 1
9221 ret
9222+ENDPROC(aesni_ecb_dec)
9223
9224 /*
9225 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9226@@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
9227 popl LEN
9228 popl IVP
9229 #endif
9230+ pax_force_retaddr 0, 1
9231 ret
9232+ENDPROC(aesni_cbc_enc)
9233
9234 /*
9235 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
9236@@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
9237 popl LEN
9238 popl IVP
9239 #endif
9240+ pax_force_retaddr 0, 1
9241 ret
9242+ENDPROC(aesni_cbc_dec)
9243
9244 #ifdef __x86_64__
9245 .align 16
9246@@ -2526,6 +2553,7 @@ _aesni_inc_init:
9247 mov $1, TCTR_LOW
9248 MOVQ_R64_XMM TCTR_LOW INC
9249 MOVQ_R64_XMM CTR TCTR_LOW
9250+ pax_force_retaddr_bts
9251 ret
9252
9253 /*
9254@@ -2554,6 +2582,7 @@ _aesni_inc:
9255 .Linc_low:
9256 movaps CTR, IV
9257 PSHUFB_XMM BSWAP_MASK IV
9258+ pax_force_retaddr_bts
9259 ret
9260
9261 /*
9262@@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
9263 .Lctr_enc_ret:
9264 movups IV, (IVP)
9265 .Lctr_enc_just_ret:
9266+ pax_force_retaddr 0, 1
9267 ret
9268+ENDPROC(aesni_ctr_enc)
9269 #endif
9270diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9271index 391d245..67f35c2 100644
9272--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
9273+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
9274@@ -20,6 +20,8 @@
9275 *
9276 */
9277
9278+#include <asm/alternative-asm.h>
9279+
9280 .file "blowfish-x86_64-asm.S"
9281 .text
9282
9283@@ -151,9 +153,11 @@ __blowfish_enc_blk:
9284 jnz __enc_xor;
9285
9286 write_block();
9287+ pax_force_retaddr 0, 1
9288 ret;
9289 __enc_xor:
9290 xor_block();
9291+ pax_force_retaddr 0, 1
9292 ret;
9293
9294 .align 8
9295@@ -188,6 +192,7 @@ blowfish_dec_blk:
9296
9297 movq %r11, %rbp;
9298
9299+ pax_force_retaddr 0, 1
9300 ret;
9301
9302 /**********************************************************************
9303@@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
9304
9305 popq %rbx;
9306 popq %rbp;
9307+ pax_force_retaddr 0, 1
9308 ret;
9309
9310 __enc_xor4:
9311@@ -349,6 +355,7 @@ __enc_xor4:
9312
9313 popq %rbx;
9314 popq %rbp;
9315+ pax_force_retaddr 0, 1
9316 ret;
9317
9318 .align 8
9319@@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
9320 popq %rbx;
9321 popq %rbp;
9322
9323+ pax_force_retaddr 0, 1
9324 ret;
9325
9326diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
9327index 0b33743..7a56206 100644
9328--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
9329+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
9330@@ -20,6 +20,8 @@
9331 *
9332 */
9333
9334+#include <asm/alternative-asm.h>
9335+
9336 .file "camellia-x86_64-asm_64.S"
9337 .text
9338
9339@@ -229,12 +231,14 @@ __enc_done:
9340 enc_outunpack(mov, RT1);
9341
9342 movq RRBP, %rbp;
9343+ pax_force_retaddr 0, 1
9344 ret;
9345
9346 __enc_xor:
9347 enc_outunpack(xor, RT1);
9348
9349 movq RRBP, %rbp;
9350+ pax_force_retaddr 0, 1
9351 ret;
9352
9353 .global camellia_dec_blk;
9354@@ -275,6 +279,7 @@ __dec_rounds16:
9355 dec_outunpack();
9356
9357 movq RRBP, %rbp;
9358+ pax_force_retaddr 0, 1
9359 ret;
9360
9361 /**********************************************************************
9362@@ -468,6 +473,7 @@ __enc2_done:
9363
9364 movq RRBP, %rbp;
9365 popq %rbx;
9366+ pax_force_retaddr 0, 1
9367 ret;
9368
9369 __enc2_xor:
9370@@ -475,6 +481,7 @@ __enc2_xor:
9371
9372 movq RRBP, %rbp;
9373 popq %rbx;
9374+ pax_force_retaddr 0, 1
9375 ret;
9376
9377 .global camellia_dec_blk_2way;
9378@@ -517,4 +524,5 @@ __dec2_rounds16:
9379
9380 movq RRBP, %rbp;
9381 movq RXOR, %rbx;
9382+ pax_force_retaddr 0, 1
9383 ret;
9384diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9385index a41a3aa..bdf5753 100644
9386--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9387+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
9388@@ -23,6 +23,8 @@
9389 *
9390 */
9391
9392+#include <asm/alternative-asm.h>
9393+
9394 .file "cast5-avx-x86_64-asm_64.S"
9395
9396 .extern cast5_s1
9397@@ -293,6 +295,7 @@ __skip_enc:
9398 leaq 3*(2*4*4)(%r11), %rax;
9399 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9400
9401+ pax_force_retaddr 0, 1
9402 ret;
9403
9404 __enc_xor16:
9405@@ -303,6 +306,7 @@ __enc_xor16:
9406 leaq 3*(2*4*4)(%r11), %rax;
9407 outunpack_xor_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9408
9409+ pax_force_retaddr 0, 1
9410 ret;
9411
9412 .align 16
9413@@ -369,6 +373,7 @@ __dec_tail:
9414 leaq 3*(2*4*4)(%r11), %rax;
9415 outunpack_blocks(%rax, RR4, RL4, RTMP, RX, RKM);
9416
9417+ pax_force_retaddr 0, 1
9418 ret;
9419
9420 __skip_dec:
9421diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9422index 218d283..819e6da 100644
9423--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9424+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
9425@@ -23,6 +23,8 @@
9426 *
9427 */
9428
9429+#include <asm/alternative-asm.h>
9430+
9431 .file "cast6-avx-x86_64-asm_64.S"
9432
9433 .extern cast6_s1
9434@@ -324,12 +326,14 @@ __cast6_enc_blk_8way:
9435 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9436 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9437
9438+ pax_force_retaddr 0, 1
9439 ret;
9440
9441 __enc_xor8:
9442 outunpack_xor_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9443 outunpack_xor_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9444
9445+ pax_force_retaddr 0, 1
9446 ret;
9447
9448 .align 16
9449@@ -380,4 +384,5 @@ cast6_dec_blk_8way:
9450 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
9451 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
9452
9453+ pax_force_retaddr 0, 1
9454 ret;
9455diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9456index 6214a9b..1f4fc9a 100644
9457--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
9458+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
9459@@ -1,3 +1,5 @@
9460+#include <asm/alternative-asm.h>
9461+
9462 # enter ECRYPT_encrypt_bytes
9463 .text
9464 .p2align 5
9465@@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
9466 add %r11,%rsp
9467 mov %rdi,%rax
9468 mov %rsi,%rdx
9469+ pax_force_retaddr 0, 1
9470 ret
9471 # bytesatleast65:
9472 ._bytesatleast65:
9473@@ -891,6 +894,7 @@ ECRYPT_keysetup:
9474 add %r11,%rsp
9475 mov %rdi,%rax
9476 mov %rsi,%rdx
9477+ pax_force_retaddr
9478 ret
9479 # enter ECRYPT_ivsetup
9480 .text
9481@@ -917,4 +921,5 @@ ECRYPT_ivsetup:
9482 add %r11,%rsp
9483 mov %rdi,%rax
9484 mov %rsi,%rdx
9485+ pax_force_retaddr
9486 ret
9487diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9488index 504106b..4e50951 100644
9489--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9490+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
9491@@ -24,6 +24,8 @@
9492 *
9493 */
9494
9495+#include <asm/alternative-asm.h>
9496+
9497 .file "serpent-avx-x86_64-asm_64.S"
9498 .text
9499
9500@@ -638,12 +640,14 @@ __serpent_enc_blk_8way_avx:
9501 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9502 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9503
9504+ pax_force_retaddr
9505 ret;
9506
9507 __enc_xor8:
9508 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9509 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9510
9511+ pax_force_retaddr
9512 ret;
9513
9514 .align 8
9515@@ -701,4 +705,5 @@ serpent_dec_blk_8way_avx:
9516 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9517 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9518
9519+ pax_force_retaddr
9520 ret;
9521diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9522index 3ee1ff0..cbc568b 100644
9523--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9524+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
9525@@ -24,6 +24,8 @@
9526 *
9527 */
9528
9529+#include <asm/alternative-asm.h>
9530+
9531 .file "serpent-sse2-x86_64-asm_64.S"
9532 .text
9533
9534@@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
9535 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9536 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9537
9538+ pax_force_retaddr
9539 ret;
9540
9541 __enc_xor8:
9542 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
9543 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
9544
9545+ pax_force_retaddr
9546 ret;
9547
9548 .align 8
9549@@ -755,4 +759,5 @@ serpent_dec_blk_8way:
9550 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
9551 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
9552
9553+ pax_force_retaddr
9554 ret;
9555diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
9556index 49d6987..df66bd4 100644
9557--- a/arch/x86/crypto/sha1_ssse3_asm.S
9558+++ b/arch/x86/crypto/sha1_ssse3_asm.S
9559@@ -28,6 +28,8 @@
9560 * (at your option) any later version.
9561 */
9562
9563+#include <asm/alternative-asm.h>
9564+
9565 #define CTX %rdi // arg1
9566 #define BUF %rsi // arg2
9567 #define CNT %rdx // arg3
9568@@ -104,6 +106,7 @@
9569 pop %r12
9570 pop %rbp
9571 pop %rbx
9572+ pax_force_retaddr 0, 1
9573 ret
9574
9575 .size \name, .-\name
9576diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9577index 1585abb..4a9af16 100644
9578--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9579+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
9580@@ -23,6 +23,8 @@
9581 *
9582 */
9583
9584+#include <asm/alternative-asm.h>
9585+
9586 .file "twofish-avx-x86_64-asm_64.S"
9587 .text
9588
9589@@ -303,12 +305,14 @@ __twofish_enc_blk_8way:
9590 outunpack_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9591 outunpack_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9592
9593+ pax_force_retaddr
9594 ret;
9595
9596 __enc_xor8:
9597 outunpack_xor_blocks(%r11, RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
9598 outunpack_xor_blocks(%rax, RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
9599
9600+ pax_force_retaddr
9601 ret;
9602
9603 .align 8
9604@@ -354,4 +358,5 @@ twofish_dec_blk_8way:
9605 outunpack_blocks(%r11, RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
9606 outunpack_blocks(%rax, RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
9607
9608+ pax_force_retaddr
9609 ret;
9610diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9611index 5b012a2..36d5364 100644
9612--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9613+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
9614@@ -20,6 +20,8 @@
9615 *
9616 */
9617
9618+#include <asm/alternative-asm.h>
9619+
9620 .file "twofish-x86_64-asm-3way.S"
9621 .text
9622
9623@@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
9624 popq %r13;
9625 popq %r14;
9626 popq %r15;
9627+ pax_force_retaddr 0, 1
9628 ret;
9629
9630 __enc_xor3:
9631@@ -271,6 +274,7 @@ __enc_xor3:
9632 popq %r13;
9633 popq %r14;
9634 popq %r15;
9635+ pax_force_retaddr 0, 1
9636 ret;
9637
9638 .global twofish_dec_blk_3way
9639@@ -312,5 +316,6 @@ twofish_dec_blk_3way:
9640 popq %r13;
9641 popq %r14;
9642 popq %r15;
9643+ pax_force_retaddr 0, 1
9644 ret;
9645
9646diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
9647index 7bcf3fc..f53832f 100644
9648--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
9649+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
9650@@ -21,6 +21,7 @@
9651 .text
9652
9653 #include <asm/asm-offsets.h>
9654+#include <asm/alternative-asm.h>
9655
9656 #define a_offset 0
9657 #define b_offset 4
9658@@ -268,6 +269,7 @@ twofish_enc_blk:
9659
9660 popq R1
9661 movq $1,%rax
9662+ pax_force_retaddr 0, 1
9663 ret
9664
9665 twofish_dec_blk:
9666@@ -319,4 +321,5 @@ twofish_dec_blk:
9667
9668 popq R1
9669 movq $1,%rax
9670+ pax_force_retaddr 0, 1
9671 ret
9672diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
9673index 07b3a68..bd2a388 100644
9674--- a/arch/x86/ia32/ia32_aout.c
9675+++ b/arch/x86/ia32/ia32_aout.c
9676@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
9677 unsigned long dump_start, dump_size;
9678 struct user32 dump;
9679
9680+ memset(&dump, 0, sizeof(dump));
9681+
9682 fs = get_fs();
9683 set_fs(KERNEL_DS);
9684 has_dumped = 1;
9685diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
9686index efc6a95..95abfe2 100644
9687--- a/arch/x86/ia32/ia32_signal.c
9688+++ b/arch/x86/ia32/ia32_signal.c
9689@@ -163,8 +163,8 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
9690 }
9691 seg = get_fs();
9692 set_fs(KERNEL_DS);
9693- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
9694- (stack_t __force __user *) &uoss, regs->sp);
9695+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
9696+ (stack_t __force_user *) &uoss, regs->sp);
9697 set_fs(seg);
9698 if (ret >= 0 && uoss_ptr) {
9699 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
9700@@ -396,7 +396,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
9701 sp -= frame_size;
9702 /* Align the stack pointer according to the i386 ABI,
9703 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
9704- sp = ((sp + 4) & -16ul) - 4;
9705+ sp = ((sp - 12) & -16ul) - 4;
9706 return (void __user *) sp;
9707 }
9708
9709@@ -454,7 +454,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
9710 * These are actually not used anymore, but left because some
9711 * gdb versions depend on them as a marker.
9712 */
9713- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9714+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9715 } put_user_catch(err);
9716
9717 if (err)
9718@@ -496,7 +496,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9719 0xb8,
9720 __NR_ia32_rt_sigreturn,
9721 0x80cd,
9722- 0,
9723+ 0
9724 };
9725
9726 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
9727@@ -522,16 +522,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
9728
9729 if (ka->sa.sa_flags & SA_RESTORER)
9730 restorer = ka->sa.sa_restorer;
9731+ else if (current->mm->context.vdso)
9732+ /* Return stub is in 32bit vsyscall page */
9733+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
9734 else
9735- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
9736- rt_sigreturn);
9737+ restorer = &frame->retcode;
9738 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
9739
9740 /*
9741 * Not actually used anymore, but left because some gdb
9742 * versions need it.
9743 */
9744- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
9745+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
9746 } put_user_catch(err);
9747
9748 err |= copy_siginfo_to_user32(&frame->info, info);
9749diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
9750index 076745f..ae8f6cb 100644
9751--- a/arch/x86/ia32/ia32entry.S
9752+++ b/arch/x86/ia32/ia32entry.S
9753@@ -15,8 +15,10 @@
9754 #include <asm/irqflags.h>
9755 #include <asm/asm.h>
9756 #include <asm/smap.h>
9757+#include <asm/pgtable.h>
9758 #include <linux/linkage.h>
9759 #include <linux/err.h>
9760+#include <asm/alternative-asm.h>
9761
9762 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
9763 #include <linux/elf-em.h>
9764@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
9765 ENDPROC(native_irq_enable_sysexit)
9766 #endif
9767
9768+ .macro pax_enter_kernel_user
9769+ pax_set_fptr_mask
9770+#ifdef CONFIG_PAX_MEMORY_UDEREF
9771+ call pax_enter_kernel_user
9772+#endif
9773+ .endm
9774+
9775+ .macro pax_exit_kernel_user
9776+#ifdef CONFIG_PAX_MEMORY_UDEREF
9777+ call pax_exit_kernel_user
9778+#endif
9779+#ifdef CONFIG_PAX_RANDKSTACK
9780+ pushq %rax
9781+ pushq %r11
9782+ call pax_randomize_kstack
9783+ popq %r11
9784+ popq %rax
9785+#endif
9786+ .endm
9787+
9788+.macro pax_erase_kstack
9789+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
9790+ call pax_erase_kstack
9791+#endif
9792+.endm
9793+
9794 /*
9795 * 32bit SYSENTER instruction entry.
9796 *
9797@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
9798 CFI_REGISTER rsp,rbp
9799 SWAPGS_UNSAFE_STACK
9800 movq PER_CPU_VAR(kernel_stack), %rsp
9801- addq $(KERNEL_STACK_OFFSET),%rsp
9802- /*
9803- * No need to follow this irqs on/off section: the syscall
9804- * disabled irqs, here we enable it straight after entry:
9805- */
9806- ENABLE_INTERRUPTS(CLBR_NONE)
9807 movl %ebp,%ebp /* zero extension */
9808 pushq_cfi $__USER32_DS
9809 /*CFI_REL_OFFSET ss,0*/
9810@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
9811 CFI_REL_OFFSET rsp,0
9812 pushfq_cfi
9813 /*CFI_REL_OFFSET rflags,0*/
9814- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
9815- CFI_REGISTER rip,r10
9816+ orl $X86_EFLAGS_IF,(%rsp)
9817+ GET_THREAD_INFO(%r11)
9818+ movl TI_sysenter_return(%r11), %r11d
9819+ CFI_REGISTER rip,r11
9820 pushq_cfi $__USER32_CS
9821 /*CFI_REL_OFFSET cs,0*/
9822 movl %eax, %eax
9823- pushq_cfi %r10
9824+ pushq_cfi %r11
9825 CFI_REL_OFFSET rip,0
9826 pushq_cfi %rax
9827 cld
9828 SAVE_ARGS 0,1,0
9829+ pax_enter_kernel_user
9830+
9831+#ifdef CONFIG_PAX_RANDKSTACK
9832+ pax_erase_kstack
9833+#endif
9834+
9835+ /*
9836+ * No need to follow this irqs on/off section: the syscall
9837+ * disabled irqs, here we enable it straight after entry:
9838+ */
9839+ ENABLE_INTERRUPTS(CLBR_NONE)
9840 /* no need to do an access_ok check here because rbp has been
9841 32bit zero extended */
9842+
9843+#ifdef CONFIG_PAX_MEMORY_UDEREF
9844+ mov $PAX_USER_SHADOW_BASE,%r11
9845+ add %r11,%rbp
9846+#endif
9847+
9848 ASM_STAC
9849 1: movl (%rbp),%ebp
9850 _ASM_EXTABLE(1b,ia32_badarg)
9851 ASM_CLAC
9852- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9853- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9854+ GET_THREAD_INFO(%r11)
9855+ orl $TS_COMPAT,TI_status(%r11)
9856+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9857 CFI_REMEMBER_STATE
9858 jnz sysenter_tracesys
9859 cmpq $(IA32_NR_syscalls-1),%rax
9860@@ -162,12 +204,15 @@ sysenter_do_call:
9861 sysenter_dispatch:
9862 call *ia32_sys_call_table(,%rax,8)
9863 movq %rax,RAX-ARGOFFSET(%rsp)
9864+ GET_THREAD_INFO(%r11)
9865 DISABLE_INTERRUPTS(CLBR_NONE)
9866 TRACE_IRQS_OFF
9867- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9868+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9869 jnz sysexit_audit
9870 sysexit_from_sys_call:
9871- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9872+ pax_exit_kernel_user
9873+ pax_erase_kstack
9874+ andl $~TS_COMPAT,TI_status(%r11)
9875 /* clear IF, that popfq doesn't enable interrupts early */
9876 andl $~0x200,EFLAGS-R11(%rsp)
9877 movl RIP-R11(%rsp),%edx /* User %eip */
9878@@ -193,6 +238,9 @@ sysexit_from_sys_call:
9879 movl %eax,%esi /* 2nd arg: syscall number */
9880 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
9881 call __audit_syscall_entry
9882+
9883+ pax_erase_kstack
9884+
9885 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
9886 cmpq $(IA32_NR_syscalls-1),%rax
9887 ja ia32_badsys
9888@@ -204,7 +252,7 @@ sysexit_from_sys_call:
9889 .endm
9890
9891 .macro auditsys_exit exit
9892- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9893+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9894 jnz ia32_ret_from_sys_call
9895 TRACE_IRQS_ON
9896 sti
9897@@ -215,11 +263,12 @@ sysexit_from_sys_call:
9898 1: setbe %al /* 1 if error, 0 if not */
9899 movzbl %al,%edi /* zero-extend that into %edi */
9900 call __audit_syscall_exit
9901+ GET_THREAD_INFO(%r11)
9902 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
9903 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
9904 cli
9905 TRACE_IRQS_OFF
9906- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9907+ testl %edi,TI_flags(%r11)
9908 jz \exit
9909 CLEAR_RREGS -ARGOFFSET
9910 jmp int_with_check
9911@@ -237,7 +286,7 @@ sysexit_audit:
9912
9913 sysenter_tracesys:
9914 #ifdef CONFIG_AUDITSYSCALL
9915- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9916+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
9917 jz sysenter_auditsys
9918 #endif
9919 SAVE_REST
9920@@ -249,6 +298,9 @@ sysenter_tracesys:
9921 RESTORE_REST
9922 cmpq $(IA32_NR_syscalls-1),%rax
9923 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
9924+
9925+ pax_erase_kstack
9926+
9927 jmp sysenter_do_call
9928 CFI_ENDPROC
9929 ENDPROC(ia32_sysenter_target)
9930@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
9931 ENTRY(ia32_cstar_target)
9932 CFI_STARTPROC32 simple
9933 CFI_SIGNAL_FRAME
9934- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
9935+ CFI_DEF_CFA rsp,0
9936 CFI_REGISTER rip,rcx
9937 /*CFI_REGISTER rflags,r11*/
9938 SWAPGS_UNSAFE_STACK
9939 movl %esp,%r8d
9940 CFI_REGISTER rsp,r8
9941 movq PER_CPU_VAR(kernel_stack),%rsp
9942+ SAVE_ARGS 8*6,0,0
9943+ pax_enter_kernel_user
9944+
9945+#ifdef CONFIG_PAX_RANDKSTACK
9946+ pax_erase_kstack
9947+#endif
9948+
9949 /*
9950 * No need to follow this irqs on/off section: the syscall
9951 * disabled irqs and here we enable it straight after entry:
9952 */
9953 ENABLE_INTERRUPTS(CLBR_NONE)
9954- SAVE_ARGS 8,0,0
9955 movl %eax,%eax /* zero extension */
9956 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
9957 movq %rcx,RIP-ARGOFFSET(%rsp)
9958@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
9959 /* no need to do an access_ok check here because r8 has been
9960 32bit zero extended */
9961 /* hardware stack frame is complete now */
9962+
9963+#ifdef CONFIG_PAX_MEMORY_UDEREF
9964+ mov $PAX_USER_SHADOW_BASE,%r11
9965+ add %r11,%r8
9966+#endif
9967+
9968 ASM_STAC
9969 1: movl (%r8),%r9d
9970 _ASM_EXTABLE(1b,ia32_badarg)
9971 ASM_CLAC
9972- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9973- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9974+ GET_THREAD_INFO(%r11)
9975+ orl $TS_COMPAT,TI_status(%r11)
9976+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
9977 CFI_REMEMBER_STATE
9978 jnz cstar_tracesys
9979 cmpq $IA32_NR_syscalls-1,%rax
9980@@ -319,12 +384,15 @@ cstar_do_call:
9981 cstar_dispatch:
9982 call *ia32_sys_call_table(,%rax,8)
9983 movq %rax,RAX-ARGOFFSET(%rsp)
9984+ GET_THREAD_INFO(%r11)
9985 DISABLE_INTERRUPTS(CLBR_NONE)
9986 TRACE_IRQS_OFF
9987- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9988+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
9989 jnz sysretl_audit
9990 sysretl_from_sys_call:
9991- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
9992+ pax_exit_kernel_user
9993+ pax_erase_kstack
9994+ andl $~TS_COMPAT,TI_status(%r11)
9995 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
9996 movl RIP-ARGOFFSET(%rsp),%ecx
9997 CFI_REGISTER rip,rcx
9998@@ -352,7 +420,7 @@ sysretl_audit:
9999
10000 cstar_tracesys:
10001 #ifdef CONFIG_AUDITSYSCALL
10002- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10003+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
10004 jz cstar_auditsys
10005 #endif
10006 xchgl %r9d,%ebp
10007@@ -366,6 +434,9 @@ cstar_tracesys:
10008 xchgl %ebp,%r9d
10009 cmpq $(IA32_NR_syscalls-1),%rax
10010 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
10011+
10012+ pax_erase_kstack
10013+
10014 jmp cstar_do_call
10015 END(ia32_cstar_target)
10016
10017@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
10018 CFI_REL_OFFSET rip,RIP-RIP
10019 PARAVIRT_ADJUST_EXCEPTION_FRAME
10020 SWAPGS
10021- /*
10022- * No need to follow this irqs on/off section: the syscall
10023- * disabled irqs and here we enable it straight after entry:
10024- */
10025- ENABLE_INTERRUPTS(CLBR_NONE)
10026 movl %eax,%eax
10027 pushq_cfi %rax
10028 cld
10029 /* note the registers are not zero extended to the sf.
10030 this could be a problem. */
10031 SAVE_ARGS 0,1,0
10032- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10033- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
10034+ pax_enter_kernel_user
10035+
10036+#ifdef CONFIG_PAX_RANDKSTACK
10037+ pax_erase_kstack
10038+#endif
10039+
10040+ /*
10041+ * No need to follow this irqs on/off section: the syscall
10042+ * disabled irqs and here we enable it straight after entry:
10043+ */
10044+ ENABLE_INTERRUPTS(CLBR_NONE)
10045+ GET_THREAD_INFO(%r11)
10046+ orl $TS_COMPAT,TI_status(%r11)
10047+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
10048 jnz ia32_tracesys
10049 cmpq $(IA32_NR_syscalls-1),%rax
10050 ja ia32_badsys
10051@@ -442,6 +520,9 @@ ia32_tracesys:
10052 RESTORE_REST
10053 cmpq $(IA32_NR_syscalls-1),%rax
10054 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
10055+
10056+ pax_erase_kstack
10057+
10058 jmp ia32_do_call
10059 END(ia32_syscall)
10060
10061diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
10062index 86d68d1..f9960fe 100644
10063--- a/arch/x86/ia32/sys_ia32.c
10064+++ b/arch/x86/ia32/sys_ia32.c
10065@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
10066 */
10067 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
10068 {
10069- typeof(ubuf->st_uid) uid = 0;
10070- typeof(ubuf->st_gid) gid = 0;
10071+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
10072+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
10073 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
10074 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
10075 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
10076@@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
10077 mm_segment_t old_fs = get_fs();
10078
10079 set_fs(KERNEL_DS);
10080- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
10081+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
10082 set_fs(old_fs);
10083 if (put_compat_timespec(&t, interval))
10084 return -EFAULT;
10085@@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
10086 mm_segment_t old_fs = get_fs();
10087
10088 set_fs(KERNEL_DS);
10089- ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
10090+ ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
10091 set_fs(old_fs);
10092 if (!ret) {
10093 switch (_NSIG_WORDS) {
10094@@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
10095 if (copy_siginfo_from_user32(&info, uinfo))
10096 return -EFAULT;
10097 set_fs(KERNEL_DS);
10098- ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
10099+ ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
10100 set_fs(old_fs);
10101 return ret;
10102 }
10103@@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
10104 return -EFAULT;
10105
10106 set_fs(KERNEL_DS);
10107- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
10108+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
10109 count);
10110 set_fs(old_fs);
10111
10112diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
10113index 372231c..a5aa1a1 100644
10114--- a/arch/x86/include/asm/alternative-asm.h
10115+++ b/arch/x86/include/asm/alternative-asm.h
10116@@ -18,6 +18,45 @@
10117 .endm
10118 #endif
10119
10120+#ifdef KERNEXEC_PLUGIN
10121+ .macro pax_force_retaddr_bts rip=0
10122+ btsq $63,\rip(%rsp)
10123+ .endm
10124+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
10125+ .macro pax_force_retaddr rip=0, reload=0
10126+ btsq $63,\rip(%rsp)
10127+ .endm
10128+ .macro pax_force_fptr ptr
10129+ btsq $63,\ptr
10130+ .endm
10131+ .macro pax_set_fptr_mask
10132+ .endm
10133+#endif
10134+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
10135+ .macro pax_force_retaddr rip=0, reload=0
10136+ .if \reload
10137+ pax_set_fptr_mask
10138+ .endif
10139+ orq %r10,\rip(%rsp)
10140+ .endm
10141+ .macro pax_force_fptr ptr
10142+ orq %r10,\ptr
10143+ .endm
10144+ .macro pax_set_fptr_mask
10145+ movabs $0x8000000000000000,%r10
10146+ .endm
10147+#endif
10148+#else
10149+ .macro pax_force_retaddr rip=0, reload=0
10150+ .endm
10151+ .macro pax_force_fptr ptr
10152+ .endm
10153+ .macro pax_force_retaddr_bts rip=0
10154+ .endm
10155+ .macro pax_set_fptr_mask
10156+ .endm
10157+#endif
10158+
10159 .macro altinstruction_entry orig alt feature orig_len alt_len
10160 .long \orig - .
10161 .long \alt - .
10162diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
10163index 58ed6d9..f1cbe58 100644
10164--- a/arch/x86/include/asm/alternative.h
10165+++ b/arch/x86/include/asm/alternative.h
10166@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10167 ".pushsection .discard,\"aw\",@progbits\n" \
10168 DISCARD_ENTRY(1) \
10169 ".popsection\n" \
10170- ".pushsection .altinstr_replacement, \"ax\"\n" \
10171+ ".pushsection .altinstr_replacement, \"a\"\n" \
10172 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
10173 ".popsection"
10174
10175@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
10176 DISCARD_ENTRY(1) \
10177 DISCARD_ENTRY(2) \
10178 ".popsection\n" \
10179- ".pushsection .altinstr_replacement, \"ax\"\n" \
10180+ ".pushsection .altinstr_replacement, \"a\"\n" \
10181 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
10182 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
10183 ".popsection"
10184diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
10185index 3388034..ba52312 100644
10186--- a/arch/x86/include/asm/apic.h
10187+++ b/arch/x86/include/asm/apic.h
10188@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
10189
10190 #ifdef CONFIG_X86_LOCAL_APIC
10191
10192-extern unsigned int apic_verbosity;
10193+extern int apic_verbosity;
10194 extern int local_apic_timer_c2_ok;
10195
10196 extern int disable_apic;
10197@@ -391,7 +391,7 @@ struct apic {
10198 */
10199 int (*x86_32_numa_cpu_node)(int cpu);
10200 #endif
10201-};
10202+} __do_const;
10203
10204 /*
10205 * Pointer to the local APIC driver in use on this system (there's
10206diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
10207index 20370c6..a2eb9b0 100644
10208--- a/arch/x86/include/asm/apm.h
10209+++ b/arch/x86/include/asm/apm.h
10210@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
10211 __asm__ __volatile__(APM_DO_ZERO_SEGS
10212 "pushl %%edi\n\t"
10213 "pushl %%ebp\n\t"
10214- "lcall *%%cs:apm_bios_entry\n\t"
10215+ "lcall *%%ss:apm_bios_entry\n\t"
10216 "setc %%al\n\t"
10217 "popl %%ebp\n\t"
10218 "popl %%edi\n\t"
10219@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
10220 __asm__ __volatile__(APM_DO_ZERO_SEGS
10221 "pushl %%edi\n\t"
10222 "pushl %%ebp\n\t"
10223- "lcall *%%cs:apm_bios_entry\n\t"
10224+ "lcall *%%ss:apm_bios_entry\n\t"
10225 "setc %%bl\n\t"
10226 "popl %%ebp\n\t"
10227 "popl %%edi\n\t"
10228diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
10229index b6c3b82..b4c077a 100644
10230--- a/arch/x86/include/asm/atomic.h
10231+++ b/arch/x86/include/asm/atomic.h
10232@@ -22,7 +22,18 @@
10233 */
10234 static inline int atomic_read(const atomic_t *v)
10235 {
10236- return (*(volatile int *)&(v)->counter);
10237+ return (*(volatile const int *)&(v)->counter);
10238+}
10239+
10240+/**
10241+ * atomic_read_unchecked - read atomic variable
10242+ * @v: pointer of type atomic_unchecked_t
10243+ *
10244+ * Atomically reads the value of @v.
10245+ */
10246+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10247+{
10248+ return (*(volatile const int *)&(v)->counter);
10249 }
10250
10251 /**
10252@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
10253 }
10254
10255 /**
10256+ * atomic_set_unchecked - set atomic variable
10257+ * @v: pointer of type atomic_unchecked_t
10258+ * @i: required value
10259+ *
10260+ * Atomically sets the value of @v to @i.
10261+ */
10262+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10263+{
10264+ v->counter = i;
10265+}
10266+
10267+/**
10268 * atomic_add - add integer to atomic variable
10269 * @i: integer value to add
10270 * @v: pointer of type atomic_t
10271@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
10272 */
10273 static inline void atomic_add(int i, atomic_t *v)
10274 {
10275- asm volatile(LOCK_PREFIX "addl %1,%0"
10276+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10277+
10278+#ifdef CONFIG_PAX_REFCOUNT
10279+ "jno 0f\n"
10280+ LOCK_PREFIX "subl %1,%0\n"
10281+ "int $4\n0:\n"
10282+ _ASM_EXTABLE(0b, 0b)
10283+#endif
10284+
10285+ : "+m" (v->counter)
10286+ : "ir" (i));
10287+}
10288+
10289+/**
10290+ * atomic_add_unchecked - add integer to atomic variable
10291+ * @i: integer value to add
10292+ * @v: pointer of type atomic_unchecked_t
10293+ *
10294+ * Atomically adds @i to @v.
10295+ */
10296+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
10297+{
10298+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
10299 : "+m" (v->counter)
10300 : "ir" (i));
10301 }
10302@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
10303 */
10304 static inline void atomic_sub(int i, atomic_t *v)
10305 {
10306- asm volatile(LOCK_PREFIX "subl %1,%0"
10307+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10308+
10309+#ifdef CONFIG_PAX_REFCOUNT
10310+ "jno 0f\n"
10311+ LOCK_PREFIX "addl %1,%0\n"
10312+ "int $4\n0:\n"
10313+ _ASM_EXTABLE(0b, 0b)
10314+#endif
10315+
10316+ : "+m" (v->counter)
10317+ : "ir" (i));
10318+}
10319+
10320+/**
10321+ * atomic_sub_unchecked - subtract integer from atomic variable
10322+ * @i: integer value to subtract
10323+ * @v: pointer of type atomic_unchecked_t
10324+ *
10325+ * Atomically subtracts @i from @v.
10326+ */
10327+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
10328+{
10329+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
10330 : "+m" (v->counter)
10331 : "ir" (i));
10332 }
10333@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10334 {
10335 unsigned char c;
10336
10337- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
10338+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
10339+
10340+#ifdef CONFIG_PAX_REFCOUNT
10341+ "jno 0f\n"
10342+ LOCK_PREFIX "addl %2,%0\n"
10343+ "int $4\n0:\n"
10344+ _ASM_EXTABLE(0b, 0b)
10345+#endif
10346+
10347+ "sete %1\n"
10348 : "+m" (v->counter), "=qm" (c)
10349 : "ir" (i) : "memory");
10350 return c;
10351@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
10352 */
10353 static inline void atomic_inc(atomic_t *v)
10354 {
10355- asm volatile(LOCK_PREFIX "incl %0"
10356+ asm volatile(LOCK_PREFIX "incl %0\n"
10357+
10358+#ifdef CONFIG_PAX_REFCOUNT
10359+ "jno 0f\n"
10360+ LOCK_PREFIX "decl %0\n"
10361+ "int $4\n0:\n"
10362+ _ASM_EXTABLE(0b, 0b)
10363+#endif
10364+
10365+ : "+m" (v->counter));
10366+}
10367+
10368+/**
10369+ * atomic_inc_unchecked - increment atomic variable
10370+ * @v: pointer of type atomic_unchecked_t
10371+ *
10372+ * Atomically increments @v by 1.
10373+ */
10374+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10375+{
10376+ asm volatile(LOCK_PREFIX "incl %0\n"
10377 : "+m" (v->counter));
10378 }
10379
10380@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
10381 */
10382 static inline void atomic_dec(atomic_t *v)
10383 {
10384- asm volatile(LOCK_PREFIX "decl %0"
10385+ asm volatile(LOCK_PREFIX "decl %0\n"
10386+
10387+#ifdef CONFIG_PAX_REFCOUNT
10388+ "jno 0f\n"
10389+ LOCK_PREFIX "incl %0\n"
10390+ "int $4\n0:\n"
10391+ _ASM_EXTABLE(0b, 0b)
10392+#endif
10393+
10394+ : "+m" (v->counter));
10395+}
10396+
10397+/**
10398+ * atomic_dec_unchecked - decrement atomic variable
10399+ * @v: pointer of type atomic_unchecked_t
10400+ *
10401+ * Atomically decrements @v by 1.
10402+ */
10403+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10404+{
10405+ asm volatile(LOCK_PREFIX "decl %0\n"
10406 : "+m" (v->counter));
10407 }
10408
10409@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
10410 {
10411 unsigned char c;
10412
10413- asm volatile(LOCK_PREFIX "decl %0; sete %1"
10414+ asm volatile(LOCK_PREFIX "decl %0\n"
10415+
10416+#ifdef CONFIG_PAX_REFCOUNT
10417+ "jno 0f\n"
10418+ LOCK_PREFIX "incl %0\n"
10419+ "int $4\n0:\n"
10420+ _ASM_EXTABLE(0b, 0b)
10421+#endif
10422+
10423+ "sete %1\n"
10424 : "+m" (v->counter), "=qm" (c)
10425 : : "memory");
10426 return c != 0;
10427@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
10428 {
10429 unsigned char c;
10430
10431- asm volatile(LOCK_PREFIX "incl %0; sete %1"
10432+ asm volatile(LOCK_PREFIX "incl %0\n"
10433+
10434+#ifdef CONFIG_PAX_REFCOUNT
10435+ "jno 0f\n"
10436+ LOCK_PREFIX "decl %0\n"
10437+ "int $4\n0:\n"
10438+ _ASM_EXTABLE(0b, 0b)
10439+#endif
10440+
10441+ "sete %1\n"
10442+ : "+m" (v->counter), "=qm" (c)
10443+ : : "memory");
10444+ return c != 0;
10445+}
10446+
10447+/**
10448+ * atomic_inc_and_test_unchecked - increment and test
10449+ * @v: pointer of type atomic_unchecked_t
10450+ *
10451+ * Atomically increments @v by 1
10452+ * and returns true if the result is zero, or false for all
10453+ * other cases.
10454+ */
10455+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10456+{
10457+ unsigned char c;
10458+
10459+ asm volatile(LOCK_PREFIX "incl %0\n"
10460+ "sete %1\n"
10461 : "+m" (v->counter), "=qm" (c)
10462 : : "memory");
10463 return c != 0;
10464@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
10465 {
10466 unsigned char c;
10467
10468- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
10469+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
10470+
10471+#ifdef CONFIG_PAX_REFCOUNT
10472+ "jno 0f\n"
10473+ LOCK_PREFIX "subl %2,%0\n"
10474+ "int $4\n0:\n"
10475+ _ASM_EXTABLE(0b, 0b)
10476+#endif
10477+
10478+ "sets %1\n"
10479 : "+m" (v->counter), "=qm" (c)
10480 : "ir" (i) : "memory");
10481 return c;
10482@@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
10483 goto no_xadd;
10484 #endif
10485 /* Modern 486+ processor */
10486- return i + xadd(&v->counter, i);
10487+ return i + xadd_check_overflow(&v->counter, i);
10488
10489 #ifdef CONFIG_M386
10490 no_xadd: /* Legacy 386 processor */
10491@@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
10492 }
10493
10494 /**
10495+ * atomic_add_return_unchecked - add integer and return
10496+ * @i: integer value to add
10497+ * @v: pointer of type atomic_unchecked_t
10498+ *
10499+ * Atomically adds @i to @v and returns @i + @v
10500+ */
10501+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10502+{
10503+#ifdef CONFIG_M386
10504+ int __i;
10505+ unsigned long flags;
10506+ if (unlikely(boot_cpu_data.x86 <= 3))
10507+ goto no_xadd;
10508+#endif
10509+ /* Modern 486+ processor */
10510+ return i + xadd(&v->counter, i);
10511+
10512+#ifdef CONFIG_M386
10513+no_xadd: /* Legacy 386 processor */
10514+ raw_local_irq_save(flags);
10515+ __i = atomic_read_unchecked(v);
10516+ atomic_set_unchecked(v, i + __i);
10517+ raw_local_irq_restore(flags);
10518+ return i + __i;
10519+#endif
10520+}
10521+
10522+/**
10523 * atomic_sub_return - subtract integer and return
10524 * @v: pointer of type atomic_t
10525 * @i: integer value to subtract
10526@@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
10527 }
10528
10529 #define atomic_inc_return(v) (atomic_add_return(1, v))
10530+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10531+{
10532+ return atomic_add_return_unchecked(1, v);
10533+}
10534 #define atomic_dec_return(v) (atomic_sub_return(1, v))
10535
10536 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10537@@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
10538 return cmpxchg(&v->counter, old, new);
10539 }
10540
10541+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10542+{
10543+ return cmpxchg(&v->counter, old, new);
10544+}
10545+
10546 static inline int atomic_xchg(atomic_t *v, int new)
10547 {
10548 return xchg(&v->counter, new);
10549 }
10550
10551+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10552+{
10553+ return xchg(&v->counter, new);
10554+}
10555+
10556 /**
10557 * __atomic_add_unless - add unless the number is already a given value
10558 * @v: pointer of type atomic_t
10559@@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
10560 */
10561 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10562 {
10563- int c, old;
10564+ int c, old, new;
10565 c = atomic_read(v);
10566 for (;;) {
10567- if (unlikely(c == (u)))
10568+ if (unlikely(c == u))
10569 break;
10570- old = atomic_cmpxchg((v), c, c + (a));
10571+
10572+ asm volatile("addl %2,%0\n"
10573+
10574+#ifdef CONFIG_PAX_REFCOUNT
10575+ "jno 0f\n"
10576+ "subl %2,%0\n"
10577+ "int $4\n0:\n"
10578+ _ASM_EXTABLE(0b, 0b)
10579+#endif
10580+
10581+ : "=r" (new)
10582+ : "0" (c), "ir" (a));
10583+
10584+ old = atomic_cmpxchg(v, c, new);
10585 if (likely(old == c))
10586 break;
10587 c = old;
10588@@ -241,6 +458,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10589 }
10590
10591 /**
10592+ * atomic_inc_not_zero_hint - increment if not null
10593+ * @v: pointer of type atomic_t
10594+ * @hint: probable value of the atomic before the increment
10595+ *
10596+ * This version of atomic_inc_not_zero() gives a hint of probable
10597+ * value of the atomic. This helps processor to not read the memory
10598+ * before doing the atomic read/modify/write cycle, lowering
10599+ * number of bus transactions on some arches.
10600+ *
10601+ * Returns: 0 if increment was not done, 1 otherwise.
10602+ */
10603+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
10604+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
10605+{
10606+ int val, c = hint, new;
10607+
10608+ /* sanity test, should be removed by compiler if hint is a constant */
10609+ if (!hint)
10610+ return __atomic_add_unless(v, 1, 0);
10611+
10612+ do {
10613+ asm volatile("incl %0\n"
10614+
10615+#ifdef CONFIG_PAX_REFCOUNT
10616+ "jno 0f\n"
10617+ "decl %0\n"
10618+ "int $4\n0:\n"
10619+ _ASM_EXTABLE(0b, 0b)
10620+#endif
10621+
10622+ : "=r" (new)
10623+ : "0" (c));
10624+
10625+ val = atomic_cmpxchg(v, c, new);
10626+ if (val == c)
10627+ return 1;
10628+ c = val;
10629+ } while (c);
10630+
10631+ return 0;
10632+}
10633+
10634+/**
10635 * atomic_inc_short - increment of a short integer
10636 * @v: pointer to type int
10637 *
10638@@ -269,14 +529,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
10639 #endif
10640
10641 /* These are x86-specific, used by some header files */
10642-#define atomic_clear_mask(mask, addr) \
10643- asm volatile(LOCK_PREFIX "andl %0,%1" \
10644- : : "r" (~(mask)), "m" (*(addr)) : "memory")
10645+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
10646+{
10647+ asm volatile(LOCK_PREFIX "andl %1,%0"
10648+ : "+m" (v->counter)
10649+ : "r" (~(mask))
10650+ : "memory");
10651+}
10652
10653-#define atomic_set_mask(mask, addr) \
10654- asm volatile(LOCK_PREFIX "orl %0,%1" \
10655- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
10656- : "memory")
10657+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10658+{
10659+ asm volatile(LOCK_PREFIX "andl %1,%0"
10660+ : "+m" (v->counter)
10661+ : "r" (~(mask))
10662+ : "memory");
10663+}
10664+
10665+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
10666+{
10667+ asm volatile(LOCK_PREFIX "orl %1,%0"
10668+ : "+m" (v->counter)
10669+ : "r" (mask)
10670+ : "memory");
10671+}
10672+
10673+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
10674+{
10675+ asm volatile(LOCK_PREFIX "orl %1,%0"
10676+ : "+m" (v->counter)
10677+ : "r" (mask)
10678+ : "memory");
10679+}
10680
10681 /* Atomic operations are already serializing on x86 */
10682 #define smp_mb__before_atomic_dec() barrier()
10683diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
10684index b154de7..aadebd8 100644
10685--- a/arch/x86/include/asm/atomic64_32.h
10686+++ b/arch/x86/include/asm/atomic64_32.h
10687@@ -12,6 +12,14 @@ typedef struct {
10688 u64 __aligned(8) counter;
10689 } atomic64_t;
10690
10691+#ifdef CONFIG_PAX_REFCOUNT
10692+typedef struct {
10693+ u64 __aligned(8) counter;
10694+} atomic64_unchecked_t;
10695+#else
10696+typedef atomic64_t atomic64_unchecked_t;
10697+#endif
10698+
10699 #define ATOMIC64_INIT(val) { (val) }
10700
10701 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
10702@@ -37,21 +45,31 @@ typedef struct {
10703 ATOMIC64_DECL_ONE(sym##_386)
10704
10705 ATOMIC64_DECL_ONE(add_386);
10706+ATOMIC64_DECL_ONE(add_unchecked_386);
10707 ATOMIC64_DECL_ONE(sub_386);
10708+ATOMIC64_DECL_ONE(sub_unchecked_386);
10709 ATOMIC64_DECL_ONE(inc_386);
10710+ATOMIC64_DECL_ONE(inc_unchecked_386);
10711 ATOMIC64_DECL_ONE(dec_386);
10712+ATOMIC64_DECL_ONE(dec_unchecked_386);
10713 #endif
10714
10715 #define alternative_atomic64(f, out, in...) \
10716 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
10717
10718 ATOMIC64_DECL(read);
10719+ATOMIC64_DECL(read_unchecked);
10720 ATOMIC64_DECL(set);
10721+ATOMIC64_DECL(set_unchecked);
10722 ATOMIC64_DECL(xchg);
10723 ATOMIC64_DECL(add_return);
10724+ATOMIC64_DECL(add_return_unchecked);
10725 ATOMIC64_DECL(sub_return);
10726+ATOMIC64_DECL(sub_return_unchecked);
10727 ATOMIC64_DECL(inc_return);
10728+ATOMIC64_DECL(inc_return_unchecked);
10729 ATOMIC64_DECL(dec_return);
10730+ATOMIC64_DECL(dec_return_unchecked);
10731 ATOMIC64_DECL(dec_if_positive);
10732 ATOMIC64_DECL(inc_not_zero);
10733 ATOMIC64_DECL(add_unless);
10734@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
10735 }
10736
10737 /**
10738+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
10739+ * @p: pointer to type atomic64_unchecked_t
10740+ * @o: expected value
10741+ * @n: new value
10742+ *
10743+ * Atomically sets @v to @n if it was equal to @o and returns
10744+ * the old value.
10745+ */
10746+
10747+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
10748+{
10749+ return cmpxchg64(&v->counter, o, n);
10750+}
10751+
10752+/**
10753 * atomic64_xchg - xchg atomic64 variable
10754 * @v: pointer to type atomic64_t
10755 * @n: value to assign
10756@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
10757 }
10758
10759 /**
10760+ * atomic64_set_unchecked - set atomic64 variable
10761+ * @v: pointer to type atomic64_unchecked_t
10762+ * @n: value to assign
10763+ *
10764+ * Atomically sets the value of @v to @n.
10765+ */
10766+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
10767+{
10768+ unsigned high = (unsigned)(i >> 32);
10769+ unsigned low = (unsigned)i;
10770+ alternative_atomic64(set, /* no output */,
10771+ "S" (v), "b" (low), "c" (high)
10772+ : "eax", "edx", "memory");
10773+}
10774+
10775+/**
10776 * atomic64_read - read atomic64 variable
10777 * @v: pointer to type atomic64_t
10778 *
10779@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
10780 }
10781
10782 /**
10783+ * atomic64_read_unchecked - read atomic64 variable
10784+ * @v: pointer to type atomic64_unchecked_t
10785+ *
10786+ * Atomically reads the value of @v and returns it.
10787+ */
10788+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
10789+{
10790+ long long r;
10791+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
10792+ return r;
10793+ }
10794+
10795+/**
10796 * atomic64_add_return - add and return
10797 * @i: integer value to add
10798 * @v: pointer to type atomic64_t
10799@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
10800 return i;
10801 }
10802
10803+/**
10804+ * atomic64_add_return_unchecked - add and return
10805+ * @i: integer value to add
10806+ * @v: pointer to type atomic64_unchecked_t
10807+ *
10808+ * Atomically adds @i to @v and returns @i + *@v
10809+ */
10810+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
10811+{
10812+ alternative_atomic64(add_return_unchecked,
10813+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10814+ ASM_NO_INPUT_CLOBBER("memory"));
10815+ return i;
10816+}
10817+
10818 /*
10819 * Other variants with different arithmetic operators:
10820 */
10821@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
10822 return a;
10823 }
10824
10825+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10826+{
10827+ long long a;
10828+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
10829+ "S" (v) : "memory", "ecx");
10830+ return a;
10831+}
10832+
10833 static inline long long atomic64_dec_return(atomic64_t *v)
10834 {
10835 long long a;
10836@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
10837 }
10838
10839 /**
10840+ * atomic64_add_unchecked - add integer to atomic64 variable
10841+ * @i: integer value to add
10842+ * @v: pointer to type atomic64_unchecked_t
10843+ *
10844+ * Atomically adds @i to @v.
10845+ */
10846+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
10847+{
10848+ __alternative_atomic64(add_unchecked, add_return_unchecked,
10849+ ASM_OUTPUT2("+A" (i), "+c" (v)),
10850+ ASM_NO_INPUT_CLOBBER("memory"));
10851+ return i;
10852+}
10853+
10854+/**
10855 * atomic64_sub - subtract the atomic64 variable
10856 * @i: integer value to subtract
10857 * @v: pointer to type atomic64_t
10858diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
10859index 0e1cbfc..5623683 100644
10860--- a/arch/x86/include/asm/atomic64_64.h
10861+++ b/arch/x86/include/asm/atomic64_64.h
10862@@ -18,7 +18,19 @@
10863 */
10864 static inline long atomic64_read(const atomic64_t *v)
10865 {
10866- return (*(volatile long *)&(v)->counter);
10867+ return (*(volatile const long *)&(v)->counter);
10868+}
10869+
10870+/**
10871+ * atomic64_read_unchecked - read atomic64 variable
10872+ * @v: pointer of type atomic64_unchecked_t
10873+ *
10874+ * Atomically reads the value of @v.
10875+ * Doesn't imply a read memory barrier.
10876+ */
10877+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10878+{
10879+ return (*(volatile const long *)&(v)->counter);
10880 }
10881
10882 /**
10883@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
10884 }
10885
10886 /**
10887+ * atomic64_set_unchecked - set atomic64 variable
10888+ * @v: pointer to type atomic64_unchecked_t
10889+ * @i: required value
10890+ *
10891+ * Atomically sets the value of @v to @i.
10892+ */
10893+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10894+{
10895+ v->counter = i;
10896+}
10897+
10898+/**
10899 * atomic64_add - add integer to atomic64 variable
10900 * @i: integer value to add
10901 * @v: pointer to type atomic64_t
10902@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
10903 */
10904 static inline void atomic64_add(long i, atomic64_t *v)
10905 {
10906+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
10907+
10908+#ifdef CONFIG_PAX_REFCOUNT
10909+ "jno 0f\n"
10910+ LOCK_PREFIX "subq %1,%0\n"
10911+ "int $4\n0:\n"
10912+ _ASM_EXTABLE(0b, 0b)
10913+#endif
10914+
10915+ : "=m" (v->counter)
10916+ : "er" (i), "m" (v->counter));
10917+}
10918+
10919+/**
10920+ * atomic64_add_unchecked - add integer to atomic64 variable
10921+ * @i: integer value to add
10922+ * @v: pointer to type atomic64_unchecked_t
10923+ *
10924+ * Atomically adds @i to @v.
10925+ */
10926+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
10927+{
10928 asm volatile(LOCK_PREFIX "addq %1,%0"
10929 : "=m" (v->counter)
10930 : "er" (i), "m" (v->counter));
10931@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
10932 */
10933 static inline void atomic64_sub(long i, atomic64_t *v)
10934 {
10935- asm volatile(LOCK_PREFIX "subq %1,%0"
10936+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
10937+
10938+#ifdef CONFIG_PAX_REFCOUNT
10939+ "jno 0f\n"
10940+ LOCK_PREFIX "addq %1,%0\n"
10941+ "int $4\n0:\n"
10942+ _ASM_EXTABLE(0b, 0b)
10943+#endif
10944+
10945+ : "=m" (v->counter)
10946+ : "er" (i), "m" (v->counter));
10947+}
10948+
10949+/**
10950+ * atomic64_sub_unchecked - subtract the atomic64 variable
10951+ * @i: integer value to subtract
10952+ * @v: pointer to type atomic64_unchecked_t
10953+ *
10954+ * Atomically subtracts @i from @v.
10955+ */
10956+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
10957+{
10958+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
10959 : "=m" (v->counter)
10960 : "er" (i), "m" (v->counter));
10961 }
10962@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10963 {
10964 unsigned char c;
10965
10966- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
10967+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
10968+
10969+#ifdef CONFIG_PAX_REFCOUNT
10970+ "jno 0f\n"
10971+ LOCK_PREFIX "addq %2,%0\n"
10972+ "int $4\n0:\n"
10973+ _ASM_EXTABLE(0b, 0b)
10974+#endif
10975+
10976+ "sete %1\n"
10977 : "=m" (v->counter), "=qm" (c)
10978 : "er" (i), "m" (v->counter) : "memory");
10979 return c;
10980@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
10981 */
10982 static inline void atomic64_inc(atomic64_t *v)
10983 {
10984+ asm volatile(LOCK_PREFIX "incq %0\n"
10985+
10986+#ifdef CONFIG_PAX_REFCOUNT
10987+ "jno 0f\n"
10988+ LOCK_PREFIX "decq %0\n"
10989+ "int $4\n0:\n"
10990+ _ASM_EXTABLE(0b, 0b)
10991+#endif
10992+
10993+ : "=m" (v->counter)
10994+ : "m" (v->counter));
10995+}
10996+
10997+/**
10998+ * atomic64_inc_unchecked - increment atomic64 variable
10999+ * @v: pointer to type atomic64_unchecked_t
11000+ *
11001+ * Atomically increments @v by 1.
11002+ */
11003+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
11004+{
11005 asm volatile(LOCK_PREFIX "incq %0"
11006 : "=m" (v->counter)
11007 : "m" (v->counter));
11008@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
11009 */
11010 static inline void atomic64_dec(atomic64_t *v)
11011 {
11012- asm volatile(LOCK_PREFIX "decq %0"
11013+ asm volatile(LOCK_PREFIX "decq %0\n"
11014+
11015+#ifdef CONFIG_PAX_REFCOUNT
11016+ "jno 0f\n"
11017+ LOCK_PREFIX "incq %0\n"
11018+ "int $4\n0:\n"
11019+ _ASM_EXTABLE(0b, 0b)
11020+#endif
11021+
11022+ : "=m" (v->counter)
11023+ : "m" (v->counter));
11024+}
11025+
11026+/**
11027+ * atomic64_dec_unchecked - decrement atomic64 variable
11028+ * @v: pointer to type atomic64_t
11029+ *
11030+ * Atomically decrements @v by 1.
11031+ */
11032+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
11033+{
11034+ asm volatile(LOCK_PREFIX "decq %0\n"
11035 : "=m" (v->counter)
11036 : "m" (v->counter));
11037 }
11038@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
11039 {
11040 unsigned char c;
11041
11042- asm volatile(LOCK_PREFIX "decq %0; sete %1"
11043+ asm volatile(LOCK_PREFIX "decq %0\n"
11044+
11045+#ifdef CONFIG_PAX_REFCOUNT
11046+ "jno 0f\n"
11047+ LOCK_PREFIX "incq %0\n"
11048+ "int $4\n0:\n"
11049+ _ASM_EXTABLE(0b, 0b)
11050+#endif
11051+
11052+ "sete %1\n"
11053 : "=m" (v->counter), "=qm" (c)
11054 : "m" (v->counter) : "memory");
11055 return c != 0;
11056@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
11057 {
11058 unsigned char c;
11059
11060- asm volatile(LOCK_PREFIX "incq %0; sete %1"
11061+ asm volatile(LOCK_PREFIX "incq %0\n"
11062+
11063+#ifdef CONFIG_PAX_REFCOUNT
11064+ "jno 0f\n"
11065+ LOCK_PREFIX "decq %0\n"
11066+ "int $4\n0:\n"
11067+ _ASM_EXTABLE(0b, 0b)
11068+#endif
11069+
11070+ "sete %1\n"
11071 : "=m" (v->counter), "=qm" (c)
11072 : "m" (v->counter) : "memory");
11073 return c != 0;
11074@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11075 {
11076 unsigned char c;
11077
11078- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
11079+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
11080+
11081+#ifdef CONFIG_PAX_REFCOUNT
11082+ "jno 0f\n"
11083+ LOCK_PREFIX "subq %2,%0\n"
11084+ "int $4\n0:\n"
11085+ _ASM_EXTABLE(0b, 0b)
11086+#endif
11087+
11088+ "sets %1\n"
11089 : "=m" (v->counter), "=qm" (c)
11090 : "er" (i), "m" (v->counter) : "memory");
11091 return c;
11092@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
11093 */
11094 static inline long atomic64_add_return(long i, atomic64_t *v)
11095 {
11096+ return i + xadd_check_overflow(&v->counter, i);
11097+}
11098+
11099+/**
11100+ * atomic64_add_return_unchecked - add and return
11101+ * @i: integer value to add
11102+ * @v: pointer to type atomic64_unchecked_t
11103+ *
11104+ * Atomically adds @i to @v and returns @i + @v
11105+ */
11106+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
11107+{
11108 return i + xadd(&v->counter, i);
11109 }
11110
11111@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
11112 }
11113
11114 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
11115+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
11116+{
11117+ return atomic64_add_return_unchecked(1, v);
11118+}
11119 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
11120
11121 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11122@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
11123 return cmpxchg(&v->counter, old, new);
11124 }
11125
11126+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
11127+{
11128+ return cmpxchg(&v->counter, old, new);
11129+}
11130+
11131 static inline long atomic64_xchg(atomic64_t *v, long new)
11132 {
11133 return xchg(&v->counter, new);
11134@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
11135 */
11136 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
11137 {
11138- long c, old;
11139+ long c, old, new;
11140 c = atomic64_read(v);
11141 for (;;) {
11142- if (unlikely(c == (u)))
11143+ if (unlikely(c == u))
11144 break;
11145- old = atomic64_cmpxchg((v), c, c + (a));
11146+
11147+ asm volatile("add %2,%0\n"
11148+
11149+#ifdef CONFIG_PAX_REFCOUNT
11150+ "jno 0f\n"
11151+ "sub %2,%0\n"
11152+ "int $4\n0:\n"
11153+ _ASM_EXTABLE(0b, 0b)
11154+#endif
11155+
11156+ : "=r" (new)
11157+ : "0" (c), "ir" (a));
11158+
11159+ old = atomic64_cmpxchg(v, c, new);
11160 if (likely(old == c))
11161 break;
11162 c = old;
11163 }
11164- return c != (u);
11165+ return c != u;
11166 }
11167
11168 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11169diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
11170index 6dfd019..0c6699f 100644
11171--- a/arch/x86/include/asm/bitops.h
11172+++ b/arch/x86/include/asm/bitops.h
11173@@ -40,7 +40,7 @@
11174 * a mask operation on a byte.
11175 */
11176 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
11177-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
11178+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
11179 #define CONST_MASK(nr) (1 << ((nr) & 7))
11180
11181 /**
11182diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
11183index b13fe63..0dab13a 100644
11184--- a/arch/x86/include/asm/boot.h
11185+++ b/arch/x86/include/asm/boot.h
11186@@ -11,10 +11,15 @@
11187 #include <asm/pgtable_types.h>
11188
11189 /* Physical address where kernel should be loaded. */
11190-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11191+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
11192 + (CONFIG_PHYSICAL_ALIGN - 1)) \
11193 & ~(CONFIG_PHYSICAL_ALIGN - 1))
11194
11195+#ifndef __ASSEMBLY__
11196+extern unsigned char __LOAD_PHYSICAL_ADDR[];
11197+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
11198+#endif
11199+
11200 /* Minimum kernel alignment, as a power of two */
11201 #ifdef CONFIG_X86_64
11202 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
11203diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
11204index 48f99f1..d78ebf9 100644
11205--- a/arch/x86/include/asm/cache.h
11206+++ b/arch/x86/include/asm/cache.h
11207@@ -5,12 +5,13 @@
11208
11209 /* L1 cache line size */
11210 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11211-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11212+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11213
11214 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
11215+#define __read_only __attribute__((__section__(".data..read_only")))
11216
11217 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
11218-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
11219+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
11220
11221 #ifdef CONFIG_X86_VSMP
11222 #ifdef CONFIG_SMP
11223diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
11224index 9863ee3..4a1f8e1 100644
11225--- a/arch/x86/include/asm/cacheflush.h
11226+++ b/arch/x86/include/asm/cacheflush.h
11227@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
11228 unsigned long pg_flags = pg->flags & _PGMT_MASK;
11229
11230 if (pg_flags == _PGMT_DEFAULT)
11231- return -1;
11232+ return ~0UL;
11233 else if (pg_flags == _PGMT_WC)
11234 return _PAGE_CACHE_WC;
11235 else if (pg_flags == _PGMT_UC_MINUS)
11236diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
11237index 46fc474..b02b0f9 100644
11238--- a/arch/x86/include/asm/checksum_32.h
11239+++ b/arch/x86/include/asm/checksum_32.h
11240@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
11241 int len, __wsum sum,
11242 int *src_err_ptr, int *dst_err_ptr);
11243
11244+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
11245+ int len, __wsum sum,
11246+ int *src_err_ptr, int *dst_err_ptr);
11247+
11248+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
11249+ int len, __wsum sum,
11250+ int *src_err_ptr, int *dst_err_ptr);
11251+
11252 /*
11253 * Note: when you get a NULL pointer exception here this means someone
11254 * passed in an incorrect kernel address to one of these functions.
11255@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
11256 int *err_ptr)
11257 {
11258 might_sleep();
11259- return csum_partial_copy_generic((__force void *)src, dst,
11260+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
11261 len, sum, err_ptr, NULL);
11262 }
11263
11264@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
11265 {
11266 might_sleep();
11267 if (access_ok(VERIFY_WRITE, dst, len))
11268- return csum_partial_copy_generic(src, (__force void *)dst,
11269+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
11270 len, sum, NULL, err_ptr);
11271
11272 if (len)
11273diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
11274index 8d871ea..c1a0dc9 100644
11275--- a/arch/x86/include/asm/cmpxchg.h
11276+++ b/arch/x86/include/asm/cmpxchg.h
11277@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
11278 __compiletime_error("Bad argument size for cmpxchg");
11279 extern void __xadd_wrong_size(void)
11280 __compiletime_error("Bad argument size for xadd");
11281+extern void __xadd_check_overflow_wrong_size(void)
11282+ __compiletime_error("Bad argument size for xadd_check_overflow");
11283 extern void __add_wrong_size(void)
11284 __compiletime_error("Bad argument size for add");
11285+extern void __add_check_overflow_wrong_size(void)
11286+ __compiletime_error("Bad argument size for add_check_overflow");
11287
11288 /*
11289 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
11290@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
11291 __ret; \
11292 })
11293
11294+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
11295+ ({ \
11296+ __typeof__ (*(ptr)) __ret = (arg); \
11297+ switch (sizeof(*(ptr))) { \
11298+ case __X86_CASE_L: \
11299+ asm volatile (lock #op "l %0, %1\n" \
11300+ "jno 0f\n" \
11301+ "mov %0,%1\n" \
11302+ "int $4\n0:\n" \
11303+ _ASM_EXTABLE(0b, 0b) \
11304+ : "+r" (__ret), "+m" (*(ptr)) \
11305+ : : "memory", "cc"); \
11306+ break; \
11307+ case __X86_CASE_Q: \
11308+ asm volatile (lock #op "q %q0, %1\n" \
11309+ "jno 0f\n" \
11310+ "mov %0,%1\n" \
11311+ "int $4\n0:\n" \
11312+ _ASM_EXTABLE(0b, 0b) \
11313+ : "+r" (__ret), "+m" (*(ptr)) \
11314+ : : "memory", "cc"); \
11315+ break; \
11316+ default: \
11317+ __ ## op ## _check_overflow_wrong_size(); \
11318+ } \
11319+ __ret; \
11320+ })
11321+
11322 /*
11323 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
11324 * Since this is generally used to protect other memory information, we
11325@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
11326 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
11327 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
11328
11329+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
11330+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
11331+
11332 #define __add(ptr, inc, lock) \
11333 ({ \
11334 __typeof__ (*(ptr)) __ret = (inc); \
11335diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
11336index 8c297aa..7a90f03 100644
11337--- a/arch/x86/include/asm/cpufeature.h
11338+++ b/arch/x86/include/asm/cpufeature.h
11339@@ -205,7 +205,7 @@
11340 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
11341 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
11342 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
11343-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
11344+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
11345 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
11346 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
11347 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
11348@@ -379,7 +379,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
11349 ".section .discard,\"aw\",@progbits\n"
11350 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
11351 ".previous\n"
11352- ".section .altinstr_replacement,\"ax\"\n"
11353+ ".section .altinstr_replacement,\"a\"\n"
11354 "3: movb $1,%0\n"
11355 "4:\n"
11356 ".previous\n"
11357diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
11358index 8bf1c06..f723dfd 100644
11359--- a/arch/x86/include/asm/desc.h
11360+++ b/arch/x86/include/asm/desc.h
11361@@ -4,6 +4,7 @@
11362 #include <asm/desc_defs.h>
11363 #include <asm/ldt.h>
11364 #include <asm/mmu.h>
11365+#include <asm/pgtable.h>
11366
11367 #include <linux/smp.h>
11368 #include <linux/percpu.h>
11369@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11370
11371 desc->type = (info->read_exec_only ^ 1) << 1;
11372 desc->type |= info->contents << 2;
11373+ desc->type |= info->seg_not_present ^ 1;
11374
11375 desc->s = 1;
11376 desc->dpl = 0x3;
11377@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
11378 }
11379
11380 extern struct desc_ptr idt_descr;
11381-extern gate_desc idt_table[];
11382 extern struct desc_ptr nmi_idt_descr;
11383-extern gate_desc nmi_idt_table[];
11384-
11385-struct gdt_page {
11386- struct desc_struct gdt[GDT_ENTRIES];
11387-} __attribute__((aligned(PAGE_SIZE)));
11388-
11389-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
11390+extern gate_desc idt_table[256];
11391+extern gate_desc nmi_idt_table[256];
11392
11393+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
11394 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
11395 {
11396- return per_cpu(gdt_page, cpu).gdt;
11397+ return cpu_gdt_table[cpu];
11398 }
11399
11400 #ifdef CONFIG_X86_64
11401@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
11402 unsigned long base, unsigned dpl, unsigned flags,
11403 unsigned short seg)
11404 {
11405- gate->a = (seg << 16) | (base & 0xffff);
11406- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
11407+ gate->gate.offset_low = base;
11408+ gate->gate.seg = seg;
11409+ gate->gate.reserved = 0;
11410+ gate->gate.type = type;
11411+ gate->gate.s = 0;
11412+ gate->gate.dpl = dpl;
11413+ gate->gate.p = 1;
11414+ gate->gate.offset_high = base >> 16;
11415 }
11416
11417 #endif
11418@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
11419
11420 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
11421 {
11422+ pax_open_kernel();
11423 memcpy(&idt[entry], gate, sizeof(*gate));
11424+ pax_close_kernel();
11425 }
11426
11427 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
11428 {
11429+ pax_open_kernel();
11430 memcpy(&ldt[entry], desc, 8);
11431+ pax_close_kernel();
11432 }
11433
11434 static inline void
11435@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
11436 default: size = sizeof(*gdt); break;
11437 }
11438
11439+ pax_open_kernel();
11440 memcpy(&gdt[entry], desc, size);
11441+ pax_close_kernel();
11442 }
11443
11444 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
11445@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
11446
11447 static inline void native_load_tr_desc(void)
11448 {
11449+ pax_open_kernel();
11450 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
11451+ pax_close_kernel();
11452 }
11453
11454 static inline void native_load_gdt(const struct desc_ptr *dtr)
11455@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
11456 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
11457 unsigned int i;
11458
11459+ pax_open_kernel();
11460 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
11461 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
11462+ pax_close_kernel();
11463 }
11464
11465 #define _LDT_empty(info) \
11466@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
11467 }
11468
11469 #ifdef CONFIG_X86_64
11470-static inline void set_nmi_gate(int gate, void *addr)
11471+static inline void set_nmi_gate(int gate, const void *addr)
11472 {
11473 gate_desc s;
11474
11475@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
11476 }
11477 #endif
11478
11479-static inline void _set_gate(int gate, unsigned type, void *addr,
11480+static inline void _set_gate(int gate, unsigned type, const void *addr,
11481 unsigned dpl, unsigned ist, unsigned seg)
11482 {
11483 gate_desc s;
11484@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
11485 * Pentium F0 0F bugfix can have resulted in the mapped
11486 * IDT being write-protected.
11487 */
11488-static inline void set_intr_gate(unsigned int n, void *addr)
11489+static inline void set_intr_gate(unsigned int n, const void *addr)
11490 {
11491 BUG_ON((unsigned)n > 0xFF);
11492 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
11493@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
11494 /*
11495 * This routine sets up an interrupt gate at directory privilege level 3.
11496 */
11497-static inline void set_system_intr_gate(unsigned int n, void *addr)
11498+static inline void set_system_intr_gate(unsigned int n, const void *addr)
11499 {
11500 BUG_ON((unsigned)n > 0xFF);
11501 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
11502 }
11503
11504-static inline void set_system_trap_gate(unsigned int n, void *addr)
11505+static inline void set_system_trap_gate(unsigned int n, const void *addr)
11506 {
11507 BUG_ON((unsigned)n > 0xFF);
11508 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
11509 }
11510
11511-static inline void set_trap_gate(unsigned int n, void *addr)
11512+static inline void set_trap_gate(unsigned int n, const void *addr)
11513 {
11514 BUG_ON((unsigned)n > 0xFF);
11515 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
11516@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
11517 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
11518 {
11519 BUG_ON((unsigned)n > 0xFF);
11520- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
11521+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
11522 }
11523
11524-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
11525+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
11526 {
11527 BUG_ON((unsigned)n > 0xFF);
11528 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
11529 }
11530
11531-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
11532+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
11533 {
11534 BUG_ON((unsigned)n > 0xFF);
11535 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
11536 }
11537
11538+#ifdef CONFIG_X86_32
11539+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
11540+{
11541+ struct desc_struct d;
11542+
11543+ if (likely(limit))
11544+ limit = (limit - 1UL) >> PAGE_SHIFT;
11545+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
11546+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
11547+}
11548+#endif
11549+
11550 #endif /* _ASM_X86_DESC_H */
11551diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
11552index 278441f..b95a174 100644
11553--- a/arch/x86/include/asm/desc_defs.h
11554+++ b/arch/x86/include/asm/desc_defs.h
11555@@ -31,6 +31,12 @@ struct desc_struct {
11556 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
11557 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
11558 };
11559+ struct {
11560+ u16 offset_low;
11561+ u16 seg;
11562+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
11563+ unsigned offset_high: 16;
11564+ } gate;
11565 };
11566 } __attribute__((packed));
11567
11568diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
11569index 3778256..c5d4fce 100644
11570--- a/arch/x86/include/asm/e820.h
11571+++ b/arch/x86/include/asm/e820.h
11572@@ -69,7 +69,7 @@ struct e820map {
11573 #define ISA_START_ADDRESS 0xa0000
11574 #define ISA_END_ADDRESS 0x100000
11575
11576-#define BIOS_BEGIN 0x000a0000
11577+#define BIOS_BEGIN 0x000c0000
11578 #define BIOS_END 0x00100000
11579
11580 #define BIOS_ROM_BASE 0xffe00000
11581diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
11582index 5939f44..f8845f6 100644
11583--- a/arch/x86/include/asm/elf.h
11584+++ b/arch/x86/include/asm/elf.h
11585@@ -243,7 +243,25 @@ extern int force_personality32;
11586 the loader. We need to make sure that it is out of the way of the program
11587 that it will "exec", and that there is sufficient room for the brk. */
11588
11589+#ifdef CONFIG_PAX_SEGMEXEC
11590+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
11591+#else
11592 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
11593+#endif
11594+
11595+#ifdef CONFIG_PAX_ASLR
11596+#ifdef CONFIG_X86_32
11597+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
11598+
11599+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11600+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
11601+#else
11602+#define PAX_ELF_ET_DYN_BASE 0x400000UL
11603+
11604+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11605+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
11606+#endif
11607+#endif
11608
11609 /* This yields a mask that user programs can use to figure out what
11610 instruction set this CPU supports. This could be done in user space,
11611@@ -296,16 +314,12 @@ do { \
11612
11613 #define ARCH_DLINFO \
11614 do { \
11615- if (vdso_enabled) \
11616- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11617- (unsigned long)current->mm->context.vdso); \
11618+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11619 } while (0)
11620
11621 #define ARCH_DLINFO_X32 \
11622 do { \
11623- if (vdso_enabled) \
11624- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
11625- (unsigned long)current->mm->context.vdso); \
11626+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
11627 } while (0)
11628
11629 #define AT_SYSINFO 32
11630@@ -320,7 +334,7 @@ else \
11631
11632 #endif /* !CONFIG_X86_32 */
11633
11634-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
11635+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
11636
11637 #define VDSO_ENTRY \
11638 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
11639@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
11640 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
11641 #define compat_arch_setup_additional_pages syscall32_setup_pages
11642
11643-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
11644-#define arch_randomize_brk arch_randomize_brk
11645-
11646 /*
11647 * True on X86_32 or when emulating IA32 on X86_64
11648 */
11649diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
11650index 75ce3f4..882e801 100644
11651--- a/arch/x86/include/asm/emergency-restart.h
11652+++ b/arch/x86/include/asm/emergency-restart.h
11653@@ -13,6 +13,6 @@ enum reboot_type {
11654
11655 extern enum reboot_type reboot_type;
11656
11657-extern void machine_emergency_restart(void);
11658+extern void machine_emergency_restart(void) __noreturn;
11659
11660 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
11661diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
11662index 41ab26e..a88c9e6 100644
11663--- a/arch/x86/include/asm/fpu-internal.h
11664+++ b/arch/x86/include/asm/fpu-internal.h
11665@@ -126,7 +126,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
11666 ({ \
11667 int err; \
11668 asm volatile(ASM_STAC "\n" \
11669- "1:" #insn "\n\t" \
11670+ "1:" \
11671+ __copyuser_seg \
11672+ #insn "\n\t" \
11673 "2: " ASM_CLAC "\n" \
11674 ".section .fixup,\"ax\"\n" \
11675 "3: movl $-1,%[err]\n" \
11676@@ -299,7 +301,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
11677 "emms\n\t" /* clear stack tags */
11678 "fildl %P[addr]", /* set F?P to defined value */
11679 X86_FEATURE_FXSAVE_LEAK,
11680- [addr] "m" (tsk->thread.fpu.has_fpu));
11681+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
11682
11683 return fpu_restore_checking(&tsk->thread.fpu);
11684 }
11685diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
11686index f373046..02653e2 100644
11687--- a/arch/x86/include/asm/futex.h
11688+++ b/arch/x86/include/asm/futex.h
11689@@ -12,6 +12,7 @@
11690 #include <asm/smap.h>
11691
11692 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
11693+ typecheck(u32 __user *, uaddr); \
11694 asm volatile("\t" ASM_STAC "\n" \
11695 "1:\t" insn "\n" \
11696 "2:\t" ASM_CLAC "\n" \
11697@@ -20,15 +21,16 @@
11698 "\tjmp\t2b\n" \
11699 "\t.previous\n" \
11700 _ASM_EXTABLE(1b, 3b) \
11701- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
11702+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
11703 : "i" (-EFAULT), "0" (oparg), "1" (0))
11704
11705 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
11706+ typecheck(u32 __user *, uaddr); \
11707 asm volatile("\t" ASM_STAC "\n" \
11708 "1:\tmovl %2, %0\n" \
11709 "\tmovl\t%0, %3\n" \
11710 "\t" insn "\n" \
11711- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
11712+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
11713 "\tjnz\t1b\n" \
11714 "3:\t" ASM_CLAC "\n" \
11715 "\t.section .fixup,\"ax\"\n" \
11716@@ -38,7 +40,7 @@
11717 _ASM_EXTABLE(1b, 4b) \
11718 _ASM_EXTABLE(2b, 4b) \
11719 : "=&a" (oldval), "=&r" (ret), \
11720- "+m" (*uaddr), "=&r" (tem) \
11721+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
11722 : "r" (oparg), "i" (-EFAULT), "1" (0))
11723
11724 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11725@@ -65,10 +67,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
11726
11727 switch (op) {
11728 case FUTEX_OP_SET:
11729- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
11730+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
11731 break;
11732 case FUTEX_OP_ADD:
11733- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
11734+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
11735 uaddr, oparg);
11736 break;
11737 case FUTEX_OP_OR:
11738@@ -128,14 +130,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
11739 return -EFAULT;
11740
11741 asm volatile("\t" ASM_STAC "\n"
11742- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
11743+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
11744 "2:\t" ASM_CLAC "\n"
11745 "\t.section .fixup, \"ax\"\n"
11746 "3:\tmov %3, %0\n"
11747 "\tjmp 2b\n"
11748 "\t.previous\n"
11749 _ASM_EXTABLE(1b, 3b)
11750- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
11751+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
11752 : "i" (-EFAULT), "r" (newval), "1" (oldval)
11753 : "memory"
11754 );
11755diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
11756index eb92a6e..b98b2f4 100644
11757--- a/arch/x86/include/asm/hw_irq.h
11758+++ b/arch/x86/include/asm/hw_irq.h
11759@@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
11760 extern void enable_IO_APIC(void);
11761
11762 /* Statistics */
11763-extern atomic_t irq_err_count;
11764-extern atomic_t irq_mis_count;
11765+extern atomic_unchecked_t irq_err_count;
11766+extern atomic_unchecked_t irq_mis_count;
11767
11768 /* EISA */
11769 extern void eisa_set_level_irq(unsigned int irq);
11770diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
11771index d8e8eef..15b1179 100644
11772--- a/arch/x86/include/asm/io.h
11773+++ b/arch/x86/include/asm/io.h
11774@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
11775 return ioremap_nocache(offset, size);
11776 }
11777
11778-extern void iounmap(volatile void __iomem *addr);
11779+extern void iounmap(const volatile void __iomem *addr);
11780
11781 extern void set_iounmap_nonlazy(void);
11782
11783@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
11784
11785 #include <linux/vmalloc.h>
11786
11787+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
11788+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
11789+{
11790+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11791+}
11792+
11793+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
11794+{
11795+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
11796+}
11797+
11798 /*
11799 * Convert a virtual cached pointer to an uncached pointer
11800 */
11801diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
11802index bba3cf8..06bc8da 100644
11803--- a/arch/x86/include/asm/irqflags.h
11804+++ b/arch/x86/include/asm/irqflags.h
11805@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
11806 sti; \
11807 sysexit
11808
11809+#define GET_CR0_INTO_RDI mov %cr0, %rdi
11810+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
11811+#define GET_CR3_INTO_RDI mov %cr3, %rdi
11812+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
11813+
11814 #else
11815 #define INTERRUPT_RETURN iret
11816 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
11817diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
11818index d3ddd17..c9fb0cc 100644
11819--- a/arch/x86/include/asm/kprobes.h
11820+++ b/arch/x86/include/asm/kprobes.h
11821@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
11822 #define RELATIVEJUMP_SIZE 5
11823 #define RELATIVECALL_OPCODE 0xe8
11824 #define RELATIVE_ADDR_SIZE 4
11825-#define MAX_STACK_SIZE 64
11826-#define MIN_STACK_SIZE(ADDR) \
11827- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
11828- THREAD_SIZE - (unsigned long)(ADDR))) \
11829- ? (MAX_STACK_SIZE) \
11830- : (((unsigned long)current_thread_info()) + \
11831- THREAD_SIZE - (unsigned long)(ADDR)))
11832+#define MAX_STACK_SIZE 64UL
11833+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
11834
11835 #define flush_insn_slot(p) do { } while (0)
11836
11837diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
11838index b2e11f4..f293e2e 100644
11839--- a/arch/x86/include/asm/kvm_host.h
11840+++ b/arch/x86/include/asm/kvm_host.h
11841@@ -707,7 +707,7 @@ struct kvm_x86_ops {
11842 int (*check_intercept)(struct kvm_vcpu *vcpu,
11843 struct x86_instruction_info *info,
11844 enum x86_intercept_stage stage);
11845-};
11846+} __do_const;
11847
11848 struct kvm_arch_async_pf {
11849 u32 token;
11850diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
11851index c8bed0d..85c03fd 100644
11852--- a/arch/x86/include/asm/local.h
11853+++ b/arch/x86/include/asm/local.h
11854@@ -10,33 +10,97 @@ typedef struct {
11855 atomic_long_t a;
11856 } local_t;
11857
11858+typedef struct {
11859+ atomic_long_unchecked_t a;
11860+} local_unchecked_t;
11861+
11862 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
11863
11864 #define local_read(l) atomic_long_read(&(l)->a)
11865+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
11866 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
11867+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
11868
11869 static inline void local_inc(local_t *l)
11870 {
11871- asm volatile(_ASM_INC "%0"
11872+ asm volatile(_ASM_INC "%0\n"
11873+
11874+#ifdef CONFIG_PAX_REFCOUNT
11875+ "jno 0f\n"
11876+ _ASM_DEC "%0\n"
11877+ "int $4\n0:\n"
11878+ _ASM_EXTABLE(0b, 0b)
11879+#endif
11880+
11881+ : "+m" (l->a.counter));
11882+}
11883+
11884+static inline void local_inc_unchecked(local_unchecked_t *l)
11885+{
11886+ asm volatile(_ASM_INC "%0\n"
11887 : "+m" (l->a.counter));
11888 }
11889
11890 static inline void local_dec(local_t *l)
11891 {
11892- asm volatile(_ASM_DEC "%0"
11893+ asm volatile(_ASM_DEC "%0\n"
11894+
11895+#ifdef CONFIG_PAX_REFCOUNT
11896+ "jno 0f\n"
11897+ _ASM_INC "%0\n"
11898+ "int $4\n0:\n"
11899+ _ASM_EXTABLE(0b, 0b)
11900+#endif
11901+
11902+ : "+m" (l->a.counter));
11903+}
11904+
11905+static inline void local_dec_unchecked(local_unchecked_t *l)
11906+{
11907+ asm volatile(_ASM_DEC "%0\n"
11908 : "+m" (l->a.counter));
11909 }
11910
11911 static inline void local_add(long i, local_t *l)
11912 {
11913- asm volatile(_ASM_ADD "%1,%0"
11914+ asm volatile(_ASM_ADD "%1,%0\n"
11915+
11916+#ifdef CONFIG_PAX_REFCOUNT
11917+ "jno 0f\n"
11918+ _ASM_SUB "%1,%0\n"
11919+ "int $4\n0:\n"
11920+ _ASM_EXTABLE(0b, 0b)
11921+#endif
11922+
11923+ : "+m" (l->a.counter)
11924+ : "ir" (i));
11925+}
11926+
11927+static inline void local_add_unchecked(long i, local_unchecked_t *l)
11928+{
11929+ asm volatile(_ASM_ADD "%1,%0\n"
11930 : "+m" (l->a.counter)
11931 : "ir" (i));
11932 }
11933
11934 static inline void local_sub(long i, local_t *l)
11935 {
11936- asm volatile(_ASM_SUB "%1,%0"
11937+ asm volatile(_ASM_SUB "%1,%0\n"
11938+
11939+#ifdef CONFIG_PAX_REFCOUNT
11940+ "jno 0f\n"
11941+ _ASM_ADD "%1,%0\n"
11942+ "int $4\n0:\n"
11943+ _ASM_EXTABLE(0b, 0b)
11944+#endif
11945+
11946+ : "+m" (l->a.counter)
11947+ : "ir" (i));
11948+}
11949+
11950+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
11951+{
11952+ asm volatile(_ASM_SUB "%1,%0\n"
11953 : "+m" (l->a.counter)
11954 : "ir" (i));
11955 }
11956@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
11957 {
11958 unsigned char c;
11959
11960- asm volatile(_ASM_SUB "%2,%0; sete %1"
11961+ asm volatile(_ASM_SUB "%2,%0\n"
11962+
11963+#ifdef CONFIG_PAX_REFCOUNT
11964+ "jno 0f\n"
11965+ _ASM_ADD "%2,%0\n"
11966+ "int $4\n0:\n"
11967+ _ASM_EXTABLE(0b, 0b)
11968+#endif
11969+
11970+ "sete %1\n"
11971 : "+m" (l->a.counter), "=qm" (c)
11972 : "ir" (i) : "memory");
11973 return c;
11974@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
11975 {
11976 unsigned char c;
11977
11978- asm volatile(_ASM_DEC "%0; sete %1"
11979+ asm volatile(_ASM_DEC "%0\n"
11980+
11981+#ifdef CONFIG_PAX_REFCOUNT
11982+ "jno 0f\n"
11983+ _ASM_INC "%0\n"
11984+ "int $4\n0:\n"
11985+ _ASM_EXTABLE(0b, 0b)
11986+#endif
11987+
11988+ "sete %1\n"
11989 : "+m" (l->a.counter), "=qm" (c)
11990 : : "memory");
11991 return c != 0;
11992@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
11993 {
11994 unsigned char c;
11995
11996- asm volatile(_ASM_INC "%0; sete %1"
11997+ asm volatile(_ASM_INC "%0\n"
11998+
11999+#ifdef CONFIG_PAX_REFCOUNT
12000+ "jno 0f\n"
12001+ _ASM_DEC "%0\n"
12002+ "int $4\n0:\n"
12003+ _ASM_EXTABLE(0b, 0b)
12004+#endif
12005+
12006+ "sete %1\n"
12007 : "+m" (l->a.counter), "=qm" (c)
12008 : : "memory");
12009 return c != 0;
12010@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
12011 {
12012 unsigned char c;
12013
12014- asm volatile(_ASM_ADD "%2,%0; sets %1"
12015+ asm volatile(_ASM_ADD "%2,%0\n"
12016+
12017+#ifdef CONFIG_PAX_REFCOUNT
12018+ "jno 0f\n"
12019+ _ASM_SUB "%2,%0\n"
12020+ "int $4\n0:\n"
12021+ _ASM_EXTABLE(0b, 0b)
12022+#endif
12023+
12024+ "sets %1\n"
12025 : "+m" (l->a.counter), "=qm" (c)
12026 : "ir" (i) : "memory");
12027 return c;
12028@@ -132,7 +232,15 @@ static inline long local_add_return(long i, local_t *l)
12029 #endif
12030 /* Modern 486+ processor */
12031 __i = i;
12032- asm volatile(_ASM_XADD "%0, %1;"
12033+ asm volatile(_ASM_XADD "%0, %1\n"
12034+
12035+#ifdef CONFIG_PAX_REFCOUNT
12036+ "jno 0f\n"
12037+ _ASM_MOV "%0,%1\n"
12038+ "int $4\n0:\n"
12039+ _ASM_EXTABLE(0b, 0b)
12040+#endif
12041+
12042 : "+r" (i), "+m" (l->a.counter)
12043 : : "memory");
12044 return i + __i;
12045@@ -147,6 +255,38 @@ no_xadd: /* Legacy 386 processor */
12046 #endif
12047 }
12048
12049+/**
12050+ * local_add_return_unchecked - add and return
12051+ * @i: integer value to add
12052+ * @l: pointer to type local_unchecked_t
12053+ *
12054+ * Atomically adds @i to @l and returns @i + @l
12055+ */
12056+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
12057+{
12058+ long __i;
12059+#ifdef CONFIG_M386
12060+ unsigned long flags;
12061+ if (unlikely(boot_cpu_data.x86 <= 3))
12062+ goto no_xadd;
12063+#endif
12064+ /* Modern 486+ processor */
12065+ __i = i;
12066+ asm volatile(_ASM_XADD "%0, %1\n"
12067+ : "+r" (i), "+m" (l->a.counter)
12068+ : : "memory");
12069+ return i + __i;
12070+
12071+#ifdef CONFIG_M386
12072+no_xadd: /* Legacy 386 processor */
12073+ local_irq_save(flags);
12074+ __i = local_read_unchecked(l);
12075+ local_set_unchecked(l, i + __i);
12076+ local_irq_restore(flags);
12077+ return i + __i;
12078+#endif
12079+}
12080+
12081 static inline long local_sub_return(long i, local_t *l)
12082 {
12083 return local_add_return(-i, l);
12084@@ -157,6 +297,8 @@ static inline long local_sub_return(long i, local_t *l)
12085
12086 #define local_cmpxchg(l, o, n) \
12087 (cmpxchg_local(&((l)->a.counter), (o), (n)))
12088+#define local_cmpxchg_unchecked(l, o, n) \
12089+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
12090 /* Always has a lock prefix */
12091 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
12092
12093diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
12094index 593e51d..fa69c9a 100644
12095--- a/arch/x86/include/asm/mman.h
12096+++ b/arch/x86/include/asm/mman.h
12097@@ -5,4 +5,14 @@
12098
12099 #include <asm-generic/mman.h>
12100
12101+#ifdef __KERNEL__
12102+#ifndef __ASSEMBLY__
12103+#ifdef CONFIG_X86_32
12104+#define arch_mmap_check i386_mmap_check
12105+int i386_mmap_check(unsigned long addr, unsigned long len,
12106+ unsigned long flags);
12107+#endif
12108+#endif
12109+#endif
12110+
12111 #endif /* _ASM_X86_MMAN_H */
12112diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
12113index 5f55e69..e20bfb1 100644
12114--- a/arch/x86/include/asm/mmu.h
12115+++ b/arch/x86/include/asm/mmu.h
12116@@ -9,7 +9,7 @@
12117 * we put the segment information here.
12118 */
12119 typedef struct {
12120- void *ldt;
12121+ struct desc_struct *ldt;
12122 int size;
12123
12124 #ifdef CONFIG_X86_64
12125@@ -18,7 +18,19 @@ typedef struct {
12126 #endif
12127
12128 struct mutex lock;
12129- void *vdso;
12130+ unsigned long vdso;
12131+
12132+#ifdef CONFIG_X86_32
12133+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12134+ unsigned long user_cs_base;
12135+ unsigned long user_cs_limit;
12136+
12137+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12138+ cpumask_t cpu_user_cs_mask;
12139+#endif
12140+
12141+#endif
12142+#endif
12143 } mm_context_t;
12144
12145 #ifdef CONFIG_SMP
12146diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
12147index cdbf367..adb37ac 100644
12148--- a/arch/x86/include/asm/mmu_context.h
12149+++ b/arch/x86/include/asm/mmu_context.h
12150@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
12151
12152 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
12153 {
12154+
12155+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12156+ unsigned int i;
12157+ pgd_t *pgd;
12158+
12159+ pax_open_kernel();
12160+ pgd = get_cpu_pgd(smp_processor_id());
12161+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
12162+ set_pgd_batched(pgd+i, native_make_pgd(0));
12163+ pax_close_kernel();
12164+#endif
12165+
12166 #ifdef CONFIG_SMP
12167 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
12168 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
12169@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12170 struct task_struct *tsk)
12171 {
12172 unsigned cpu = smp_processor_id();
12173+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12174+ int tlbstate = TLBSTATE_OK;
12175+#endif
12176
12177 if (likely(prev != next)) {
12178 #ifdef CONFIG_SMP
12179+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12180+ tlbstate = this_cpu_read(cpu_tlbstate.state);
12181+#endif
12182 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12183 this_cpu_write(cpu_tlbstate.active_mm, next);
12184 #endif
12185 cpumask_set_cpu(cpu, mm_cpumask(next));
12186
12187 /* Re-load page tables */
12188+#ifdef CONFIG_PAX_PER_CPU_PGD
12189+ pax_open_kernel();
12190+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12191+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12192+ pax_close_kernel();
12193+ load_cr3(get_cpu_pgd(cpu));
12194+#else
12195 load_cr3(next->pgd);
12196+#endif
12197
12198 /* stop flush ipis for the previous mm */
12199 cpumask_clear_cpu(cpu, mm_cpumask(prev));
12200@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12201 */
12202 if (unlikely(prev->context.ldt != next->context.ldt))
12203 load_LDT_nolock(&next->context);
12204- }
12205+
12206+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
12207+ if (!(__supported_pte_mask & _PAGE_NX)) {
12208+ smp_mb__before_clear_bit();
12209+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
12210+ smp_mb__after_clear_bit();
12211+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12212+ }
12213+#endif
12214+
12215+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12216+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
12217+ prev->context.user_cs_limit != next->context.user_cs_limit))
12218+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12219 #ifdef CONFIG_SMP
12220+ else if (unlikely(tlbstate != TLBSTATE_OK))
12221+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12222+#endif
12223+#endif
12224+
12225+ }
12226 else {
12227+
12228+#ifdef CONFIG_PAX_PER_CPU_PGD
12229+ pax_open_kernel();
12230+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
12231+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
12232+ pax_close_kernel();
12233+ load_cr3(get_cpu_pgd(cpu));
12234+#endif
12235+
12236+#ifdef CONFIG_SMP
12237 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
12238 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
12239
12240@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
12241 * tlb flush IPI delivery. We must reload CR3
12242 * to make sure to use no freed page tables.
12243 */
12244+
12245+#ifndef CONFIG_PAX_PER_CPU_PGD
12246 load_cr3(next->pgd);
12247+#endif
12248+
12249 load_LDT_nolock(&next->context);
12250+
12251+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
12252+ if (!(__supported_pte_mask & _PAGE_NX))
12253+ cpu_set(cpu, next->context.cpu_user_cs_mask);
12254+#endif
12255+
12256+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
12257+#ifdef CONFIG_PAX_PAGEEXEC
12258+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
12259+#endif
12260+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
12261+#endif
12262+
12263 }
12264+#endif
12265 }
12266-#endif
12267 }
12268
12269 #define activate_mm(prev, next) \
12270diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
12271index 9eae775..c914fea 100644
12272--- a/arch/x86/include/asm/module.h
12273+++ b/arch/x86/include/asm/module.h
12274@@ -5,6 +5,7 @@
12275
12276 #ifdef CONFIG_X86_64
12277 /* X86_64 does not define MODULE_PROC_FAMILY */
12278+#define MODULE_PROC_FAMILY ""
12279 #elif defined CONFIG_M386
12280 #define MODULE_PROC_FAMILY "386 "
12281 #elif defined CONFIG_M486
12282@@ -59,8 +60,20 @@
12283 #error unknown processor family
12284 #endif
12285
12286-#ifdef CONFIG_X86_32
12287-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
12288+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
12289+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
12290+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
12291+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
12292+#else
12293+#define MODULE_PAX_KERNEXEC ""
12294 #endif
12295
12296+#ifdef CONFIG_PAX_MEMORY_UDEREF
12297+#define MODULE_PAX_UDEREF "UDEREF "
12298+#else
12299+#define MODULE_PAX_UDEREF ""
12300+#endif
12301+
12302+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
12303+
12304 #endif /* _ASM_X86_MODULE_H */
12305diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
12306index 320f7bb..e89f8f8 100644
12307--- a/arch/x86/include/asm/page_64_types.h
12308+++ b/arch/x86/include/asm/page_64_types.h
12309@@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
12310
12311 /* duplicated to the one in bootmem.h */
12312 extern unsigned long max_pfn;
12313-extern unsigned long phys_base;
12314+extern const unsigned long phys_base;
12315
12316 extern unsigned long __phys_addr(unsigned long);
12317 #define __phys_reloc_hide(x) (x)
12318diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
12319index a0facf3..c017b15 100644
12320--- a/arch/x86/include/asm/paravirt.h
12321+++ b/arch/x86/include/asm/paravirt.h
12322@@ -632,6 +632,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
12323 val);
12324 }
12325
12326+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12327+{
12328+ pgdval_t val = native_pgd_val(pgd);
12329+
12330+ if (sizeof(pgdval_t) > sizeof(long))
12331+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
12332+ val, (u64)val >> 32);
12333+ else
12334+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
12335+ val);
12336+}
12337+
12338 static inline void pgd_clear(pgd_t *pgdp)
12339 {
12340 set_pgd(pgdp, __pgd(0));
12341@@ -713,6 +725,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
12342 pv_mmu_ops.set_fixmap(idx, phys, flags);
12343 }
12344
12345+#ifdef CONFIG_PAX_KERNEXEC
12346+static inline unsigned long pax_open_kernel(void)
12347+{
12348+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
12349+}
12350+
12351+static inline unsigned long pax_close_kernel(void)
12352+{
12353+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
12354+}
12355+#else
12356+static inline unsigned long pax_open_kernel(void) { return 0; }
12357+static inline unsigned long pax_close_kernel(void) { return 0; }
12358+#endif
12359+
12360 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
12361
12362 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
12363@@ -929,7 +956,7 @@ extern void default_banner(void);
12364
12365 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
12366 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
12367-#define PARA_INDIRECT(addr) *%cs:addr
12368+#define PARA_INDIRECT(addr) *%ss:addr
12369 #endif
12370
12371 #define INTERRUPT_RETURN \
12372@@ -1004,6 +1031,21 @@ extern void default_banner(void);
12373 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
12374 CLBR_NONE, \
12375 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
12376+
12377+#define GET_CR0_INTO_RDI \
12378+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
12379+ mov %rax,%rdi
12380+
12381+#define SET_RDI_INTO_CR0 \
12382+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
12383+
12384+#define GET_CR3_INTO_RDI \
12385+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
12386+ mov %rax,%rdi
12387+
12388+#define SET_RDI_INTO_CR3 \
12389+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
12390+
12391 #endif /* CONFIG_X86_32 */
12392
12393 #endif /* __ASSEMBLY__ */
12394diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
12395index 142236e..57cf5ea 100644
12396--- a/arch/x86/include/asm/paravirt_types.h
12397+++ b/arch/x86/include/asm/paravirt_types.h
12398@@ -312,6 +312,7 @@ struct pv_mmu_ops {
12399 struct paravirt_callee_save make_pud;
12400
12401 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
12402+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
12403 #endif /* PAGETABLE_LEVELS == 4 */
12404 #endif /* PAGETABLE_LEVELS >= 3 */
12405
12406@@ -323,6 +324,12 @@ struct pv_mmu_ops {
12407 an mfn. We can tell which is which from the index. */
12408 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
12409 phys_addr_t phys, pgprot_t flags);
12410+
12411+#ifdef CONFIG_PAX_KERNEXEC
12412+ unsigned long (*pax_open_kernel)(void);
12413+ unsigned long (*pax_close_kernel)(void);
12414+#endif
12415+
12416 };
12417
12418 struct arch_spinlock;
12419diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
12420index b4389a4..7024269 100644
12421--- a/arch/x86/include/asm/pgalloc.h
12422+++ b/arch/x86/include/asm/pgalloc.h
12423@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
12424 pmd_t *pmd, pte_t *pte)
12425 {
12426 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12427+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
12428+}
12429+
12430+static inline void pmd_populate_user(struct mm_struct *mm,
12431+ pmd_t *pmd, pte_t *pte)
12432+{
12433+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
12434 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
12435 }
12436
12437@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
12438
12439 #ifdef CONFIG_X86_PAE
12440 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
12441+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
12442+{
12443+ pud_populate(mm, pudp, pmd);
12444+}
12445 #else /* !CONFIG_X86_PAE */
12446 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12447 {
12448 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12449 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
12450 }
12451+
12452+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
12453+{
12454+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
12455+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
12456+}
12457 #endif /* CONFIG_X86_PAE */
12458
12459 #if PAGETABLE_LEVELS > 3
12460@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12461 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
12462 }
12463
12464+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
12465+{
12466+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
12467+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
12468+}
12469+
12470 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
12471 {
12472 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
12473diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
12474index f2b489c..4f7e2e5 100644
12475--- a/arch/x86/include/asm/pgtable-2level.h
12476+++ b/arch/x86/include/asm/pgtable-2level.h
12477@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
12478
12479 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12480 {
12481+ pax_open_kernel();
12482 *pmdp = pmd;
12483+ pax_close_kernel();
12484 }
12485
12486 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12487diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
12488index 4cc9f2b..5fd9226 100644
12489--- a/arch/x86/include/asm/pgtable-3level.h
12490+++ b/arch/x86/include/asm/pgtable-3level.h
12491@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12492
12493 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12494 {
12495+ pax_open_kernel();
12496 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
12497+ pax_close_kernel();
12498 }
12499
12500 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12501 {
12502+ pax_open_kernel();
12503 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
12504+ pax_close_kernel();
12505 }
12506
12507 /*
12508diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
12509index a1f780d..5f38ced4 100644
12510--- a/arch/x86/include/asm/pgtable.h
12511+++ b/arch/x86/include/asm/pgtable.h
12512@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12513
12514 #ifndef __PAGETABLE_PUD_FOLDED
12515 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
12516+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
12517 #define pgd_clear(pgd) native_pgd_clear(pgd)
12518 #endif
12519
12520@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
12521
12522 #define arch_end_context_switch(prev) do {} while(0)
12523
12524+#define pax_open_kernel() native_pax_open_kernel()
12525+#define pax_close_kernel() native_pax_close_kernel()
12526 #endif /* CONFIG_PARAVIRT */
12527
12528+#define __HAVE_ARCH_PAX_OPEN_KERNEL
12529+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
12530+
12531+#ifdef CONFIG_PAX_KERNEXEC
12532+static inline unsigned long native_pax_open_kernel(void)
12533+{
12534+ unsigned long cr0;
12535+
12536+ preempt_disable();
12537+ barrier();
12538+ cr0 = read_cr0() ^ X86_CR0_WP;
12539+ BUG_ON(unlikely(cr0 & X86_CR0_WP));
12540+ write_cr0(cr0);
12541+ return cr0 ^ X86_CR0_WP;
12542+}
12543+
12544+static inline unsigned long native_pax_close_kernel(void)
12545+{
12546+ unsigned long cr0;
12547+
12548+ cr0 = read_cr0() ^ X86_CR0_WP;
12549+ BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
12550+ write_cr0(cr0);
12551+ barrier();
12552+ preempt_enable_no_resched();
12553+ return cr0 ^ X86_CR0_WP;
12554+}
12555+#else
12556+static inline unsigned long native_pax_open_kernel(void) { return 0; }
12557+static inline unsigned long native_pax_close_kernel(void) { return 0; }
12558+#endif
12559+
12560 /*
12561 * The following only work if pte_present() is true.
12562 * Undefined behaviour if not..
12563 */
12564+static inline int pte_user(pte_t pte)
12565+{
12566+ return pte_val(pte) & _PAGE_USER;
12567+}
12568+
12569 static inline int pte_dirty(pte_t pte)
12570 {
12571 return pte_flags(pte) & _PAGE_DIRTY;
12572@@ -195,9 +235,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
12573 return pte_clear_flags(pte, _PAGE_RW);
12574 }
12575
12576+static inline pte_t pte_mkread(pte_t pte)
12577+{
12578+ return __pte(pte_val(pte) | _PAGE_USER);
12579+}
12580+
12581 static inline pte_t pte_mkexec(pte_t pte)
12582 {
12583- return pte_clear_flags(pte, _PAGE_NX);
12584+#ifdef CONFIG_X86_PAE
12585+ if (__supported_pte_mask & _PAGE_NX)
12586+ return pte_clear_flags(pte, _PAGE_NX);
12587+ else
12588+#endif
12589+ return pte_set_flags(pte, _PAGE_USER);
12590+}
12591+
12592+static inline pte_t pte_exprotect(pte_t pte)
12593+{
12594+#ifdef CONFIG_X86_PAE
12595+ if (__supported_pte_mask & _PAGE_NX)
12596+ return pte_set_flags(pte, _PAGE_NX);
12597+ else
12598+#endif
12599+ return pte_clear_flags(pte, _PAGE_USER);
12600 }
12601
12602 static inline pte_t pte_mkdirty(pte_t pte)
12603@@ -389,6 +449,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
12604 #endif
12605
12606 #ifndef __ASSEMBLY__
12607+
12608+#ifdef CONFIG_PAX_PER_CPU_PGD
12609+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
12610+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
12611+{
12612+ return cpu_pgd[cpu];
12613+}
12614+#endif
12615+
12616 #include <linux/mm_types.h>
12617
12618 static inline int pte_none(pte_t pte)
12619@@ -565,7 +634,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
12620
12621 static inline int pgd_bad(pgd_t pgd)
12622 {
12623- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
12624+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
12625 }
12626
12627 static inline int pgd_none(pgd_t pgd)
12628@@ -588,7 +657,12 @@ static inline int pgd_none(pgd_t pgd)
12629 * pgd_offset() returns a (pgd_t *)
12630 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
12631 */
12632-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
12633+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
12634+
12635+#ifdef CONFIG_PAX_PER_CPU_PGD
12636+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
12637+#endif
12638+
12639 /*
12640 * a shortcut which implies the use of the kernel's pgd, instead
12641 * of a process's
12642@@ -599,6 +673,20 @@ static inline int pgd_none(pgd_t pgd)
12643 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
12644 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
12645
12646+#ifdef CONFIG_X86_32
12647+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
12648+#else
12649+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
12650+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
12651+
12652+#ifdef CONFIG_PAX_MEMORY_UDEREF
12653+#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
12654+#else
12655+#define PAX_USER_SHADOW_BASE (_AC(0,UL))
12656+#endif
12657+
12658+#endif
12659+
12660 #ifndef __ASSEMBLY__
12661
12662 extern int direct_gbpages;
12663@@ -763,11 +851,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
12664 * dst and src can be on the same page, but the range must not overlap,
12665 * and must not cross a page boundary.
12666 */
12667-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
12668+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
12669 {
12670- memcpy(dst, src, count * sizeof(pgd_t));
12671+ pax_open_kernel();
12672+ while (count--)
12673+ *dst++ = *src++;
12674+ pax_close_kernel();
12675 }
12676
12677+#ifdef CONFIG_PAX_PER_CPU_PGD
12678+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
12679+#endif
12680+
12681+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12682+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
12683+#else
12684+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
12685+#endif
12686
12687 #include <asm-generic/pgtable.h>
12688 #endif /* __ASSEMBLY__ */
12689diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
12690index 8faa215..a8a17ea 100644
12691--- a/arch/x86/include/asm/pgtable_32.h
12692+++ b/arch/x86/include/asm/pgtable_32.h
12693@@ -25,9 +25,6 @@
12694 struct mm_struct;
12695 struct vm_area_struct;
12696
12697-extern pgd_t swapper_pg_dir[1024];
12698-extern pgd_t initial_page_table[1024];
12699-
12700 static inline void pgtable_cache_init(void) { }
12701 static inline void check_pgt_cache(void) { }
12702 void paging_init(void);
12703@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12704 # include <asm/pgtable-2level.h>
12705 #endif
12706
12707+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
12708+extern pgd_t initial_page_table[PTRS_PER_PGD];
12709+#ifdef CONFIG_X86_PAE
12710+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
12711+#endif
12712+
12713 #if defined(CONFIG_HIGHPTE)
12714 #define pte_offset_map(dir, address) \
12715 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
12716@@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
12717 /* Clear a kernel PTE and flush it from the TLB */
12718 #define kpte_clear_flush(ptep, vaddr) \
12719 do { \
12720+ pax_open_kernel(); \
12721 pte_clear(&init_mm, (vaddr), (ptep)); \
12722+ pax_close_kernel(); \
12723 __flush_tlb_one((vaddr)); \
12724 } while (0)
12725
12726@@ -75,6 +80,9 @@ do { \
12727
12728 #endif /* !__ASSEMBLY__ */
12729
12730+#define HAVE_ARCH_UNMAPPED_AREA
12731+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
12732+
12733 /*
12734 * kern_addr_valid() is (1) for FLATMEM and (0) for
12735 * SPARSEMEM and DISCONTIGMEM
12736diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
12737index ed5903b..c7fe163 100644
12738--- a/arch/x86/include/asm/pgtable_32_types.h
12739+++ b/arch/x86/include/asm/pgtable_32_types.h
12740@@ -8,7 +8,7 @@
12741 */
12742 #ifdef CONFIG_X86_PAE
12743 # include <asm/pgtable-3level_types.h>
12744-# define PMD_SIZE (1UL << PMD_SHIFT)
12745+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
12746 # define PMD_MASK (~(PMD_SIZE - 1))
12747 #else
12748 # include <asm/pgtable-2level_types.h>
12749@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
12750 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
12751 #endif
12752
12753+#ifdef CONFIG_PAX_KERNEXEC
12754+#ifndef __ASSEMBLY__
12755+extern unsigned char MODULES_EXEC_VADDR[];
12756+extern unsigned char MODULES_EXEC_END[];
12757+#endif
12758+#include <asm/boot.h>
12759+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
12760+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
12761+#else
12762+#define ktla_ktva(addr) (addr)
12763+#define ktva_ktla(addr) (addr)
12764+#endif
12765+
12766 #define MODULES_VADDR VMALLOC_START
12767 #define MODULES_END VMALLOC_END
12768 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
12769diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
12770index 47356f9..deb94a2 100644
12771--- a/arch/x86/include/asm/pgtable_64.h
12772+++ b/arch/x86/include/asm/pgtable_64.h
12773@@ -16,10 +16,14 @@
12774
12775 extern pud_t level3_kernel_pgt[512];
12776 extern pud_t level3_ident_pgt[512];
12777+extern pud_t level3_vmalloc_start_pgt[512];
12778+extern pud_t level3_vmalloc_end_pgt[512];
12779+extern pud_t level3_vmemmap_pgt[512];
12780+extern pud_t level2_vmemmap_pgt[512];
12781 extern pmd_t level2_kernel_pgt[512];
12782 extern pmd_t level2_fixmap_pgt[512];
12783-extern pmd_t level2_ident_pgt[512];
12784-extern pgd_t init_level4_pgt[];
12785+extern pmd_t level2_ident_pgt[512*2];
12786+extern pgd_t init_level4_pgt[512];
12787
12788 #define swapper_pg_dir init_level4_pgt
12789
12790@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
12791
12792 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
12793 {
12794+ pax_open_kernel();
12795 *pmdp = pmd;
12796+ pax_close_kernel();
12797 }
12798
12799 static inline void native_pmd_clear(pmd_t *pmd)
12800@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
12801
12802 static inline void native_set_pud(pud_t *pudp, pud_t pud)
12803 {
12804+ pax_open_kernel();
12805 *pudp = pud;
12806+ pax_close_kernel();
12807 }
12808
12809 static inline void native_pud_clear(pud_t *pud)
12810@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
12811
12812 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
12813 {
12814+ pax_open_kernel();
12815+ *pgdp = pgd;
12816+ pax_close_kernel();
12817+}
12818+
12819+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
12820+{
12821 *pgdp = pgd;
12822 }
12823
12824diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
12825index 766ea16..5b96cb3 100644
12826--- a/arch/x86/include/asm/pgtable_64_types.h
12827+++ b/arch/x86/include/asm/pgtable_64_types.h
12828@@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
12829 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
12830 #define MODULES_END _AC(0xffffffffff000000, UL)
12831 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
12832+#define MODULES_EXEC_VADDR MODULES_VADDR
12833+#define MODULES_EXEC_END MODULES_END
12834+
12835+#define ktla_ktva(addr) (addr)
12836+#define ktva_ktla(addr) (addr)
12837
12838 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
12839diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
12840index ec8a1fc..7ccb593 100644
12841--- a/arch/x86/include/asm/pgtable_types.h
12842+++ b/arch/x86/include/asm/pgtable_types.h
12843@@ -16,13 +16,12 @@
12844 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
12845 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
12846 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
12847-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
12848+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
12849 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
12850 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
12851 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
12852-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
12853-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
12854-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
12855+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
12856+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
12857 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
12858
12859 /* If _PAGE_BIT_PRESENT is clear, we use these: */
12860@@ -40,7 +39,6 @@
12861 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
12862 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
12863 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
12864-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
12865 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
12866 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
12867 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
12868@@ -57,8 +55,10 @@
12869
12870 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
12871 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
12872-#else
12873+#elif defined(CONFIG_KMEMCHECK)
12874 #define _PAGE_NX (_AT(pteval_t, 0))
12875+#else
12876+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
12877 #endif
12878
12879 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
12880@@ -96,6 +96,9 @@
12881 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
12882 _PAGE_ACCESSED)
12883
12884+#define PAGE_READONLY_NOEXEC PAGE_READONLY
12885+#define PAGE_SHARED_NOEXEC PAGE_SHARED
12886+
12887 #define __PAGE_KERNEL_EXEC \
12888 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
12889 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
12890@@ -106,7 +109,7 @@
12891 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
12892 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
12893 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
12894-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
12895+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
12896 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
12897 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
12898 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
12899@@ -168,8 +171,8 @@
12900 * bits are combined, this will alow user to access the high address mapped
12901 * VDSO in the presence of CONFIG_COMPAT_VDSO
12902 */
12903-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
12904-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
12905+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12906+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
12907 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
12908 #endif
12909
12910@@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
12911 {
12912 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
12913 }
12914+#endif
12915
12916+#if PAGETABLE_LEVELS == 3
12917+#include <asm-generic/pgtable-nopud.h>
12918+#endif
12919+
12920+#if PAGETABLE_LEVELS == 2
12921+#include <asm-generic/pgtable-nopmd.h>
12922+#endif
12923+
12924+#ifndef __ASSEMBLY__
12925 #if PAGETABLE_LEVELS > 3
12926 typedef struct { pudval_t pud; } pud_t;
12927
12928@@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
12929 return pud.pud;
12930 }
12931 #else
12932-#include <asm-generic/pgtable-nopud.h>
12933-
12934 static inline pudval_t native_pud_val(pud_t pud)
12935 {
12936 return native_pgd_val(pud.pgd);
12937@@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
12938 return pmd.pmd;
12939 }
12940 #else
12941-#include <asm-generic/pgtable-nopmd.h>
12942-
12943 static inline pmdval_t native_pmd_val(pmd_t pmd)
12944 {
12945 return native_pgd_val(pmd.pud.pgd);
12946@@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
12947
12948 extern pteval_t __supported_pte_mask;
12949 extern void set_nx(void);
12950-extern int nx_enabled;
12951
12952 #define pgprot_writecombine pgprot_writecombine
12953 extern pgprot_t pgprot_writecombine(pgprot_t prot);
12954diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
12955index ad1fc85..0b15fe1 100644
12956--- a/arch/x86/include/asm/processor.h
12957+++ b/arch/x86/include/asm/processor.h
12958@@ -289,7 +289,7 @@ struct tss_struct {
12959
12960 } ____cacheline_aligned;
12961
12962-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
12963+extern struct tss_struct init_tss[NR_CPUS];
12964
12965 /*
12966 * Save the original ist values for checking stack pointers during debugging
12967@@ -818,11 +818,18 @@ static inline void spin_lock_prefetch(const void *x)
12968 */
12969 #define TASK_SIZE PAGE_OFFSET
12970 #define TASK_SIZE_MAX TASK_SIZE
12971+
12972+#ifdef CONFIG_PAX_SEGMEXEC
12973+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
12974+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
12975+#else
12976 #define STACK_TOP TASK_SIZE
12977-#define STACK_TOP_MAX STACK_TOP
12978+#endif
12979+
12980+#define STACK_TOP_MAX TASK_SIZE
12981
12982 #define INIT_THREAD { \
12983- .sp0 = sizeof(init_stack) + (long)&init_stack, \
12984+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12985 .vm86_info = NULL, \
12986 .sysenter_cs = __KERNEL_CS, \
12987 .io_bitmap_ptr = NULL, \
12988@@ -836,7 +843,7 @@ static inline void spin_lock_prefetch(const void *x)
12989 */
12990 #define INIT_TSS { \
12991 .x86_tss = { \
12992- .sp0 = sizeof(init_stack) + (long)&init_stack, \
12993+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
12994 .ss0 = __KERNEL_DS, \
12995 .ss1 = __KERNEL_CS, \
12996 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
12997@@ -847,11 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
12998 extern unsigned long thread_saved_pc(struct task_struct *tsk);
12999
13000 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
13001-#define KSTK_TOP(info) \
13002-({ \
13003- unsigned long *__ptr = (unsigned long *)(info); \
13004- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
13005-})
13006+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
13007
13008 /*
13009 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
13010@@ -866,7 +869,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13011 #define task_pt_regs(task) \
13012 ({ \
13013 struct pt_regs *__regs__; \
13014- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
13015+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
13016 __regs__ - 1; \
13017 })
13018
13019@@ -876,13 +879,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13020 /*
13021 * User space process size. 47bits minus one guard page.
13022 */
13023-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
13024+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
13025
13026 /* This decides where the kernel will search for a free chunk of vm
13027 * space during mmap's.
13028 */
13029 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
13030- 0xc0000000 : 0xFFFFe000)
13031+ 0xc0000000 : 0xFFFFf000)
13032
13033 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
13034 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
13035@@ -893,11 +896,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
13036 #define STACK_TOP_MAX TASK_SIZE_MAX
13037
13038 #define INIT_THREAD { \
13039- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13040+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13041 }
13042
13043 #define INIT_TSS { \
13044- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
13045+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
13046 }
13047
13048 /*
13049@@ -925,6 +928,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
13050 */
13051 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
13052
13053+#ifdef CONFIG_PAX_SEGMEXEC
13054+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
13055+#endif
13056+
13057 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
13058
13059 /* Get/set a process' ability to use the timestamp counter instruction */
13060@@ -985,12 +992,12 @@ extern bool cpu_has_amd_erratum(const int *);
13061 #define cpu_has_amd_erratum(x) (false)
13062 #endif /* CONFIG_CPU_SUP_AMD */
13063
13064-extern unsigned long arch_align_stack(unsigned long sp);
13065+#define arch_align_stack(x) ((x) & ~0xfUL)
13066 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
13067
13068 void default_idle(void);
13069 bool set_pm_idle_to_default(void);
13070
13071-void stop_this_cpu(void *dummy);
13072+void stop_this_cpu(void *dummy) __noreturn;
13073
13074 #endif /* _ASM_X86_PROCESSOR_H */
13075diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
13076index 19f16eb..b50624b 100644
13077--- a/arch/x86/include/asm/ptrace.h
13078+++ b/arch/x86/include/asm/ptrace.h
13079@@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
13080 }
13081
13082 /*
13083- * user_mode_vm(regs) determines whether a register set came from user mode.
13084+ * user_mode(regs) determines whether a register set came from user mode.
13085 * This is true if V8086 mode was enabled OR if the register set was from
13086 * protected mode with RPL-3 CS value. This tricky test checks that with
13087 * one comparison. Many places in the kernel can bypass this full check
13088- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
13089+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
13090+ * be used.
13091 */
13092-static inline int user_mode(struct pt_regs *regs)
13093+static inline int user_mode_novm(struct pt_regs *regs)
13094 {
13095 #ifdef CONFIG_X86_32
13096 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
13097 #else
13098- return !!(regs->cs & 3);
13099+ return !!(regs->cs & SEGMENT_RPL_MASK);
13100 #endif
13101 }
13102
13103-static inline int user_mode_vm(struct pt_regs *regs)
13104+static inline int user_mode(struct pt_regs *regs)
13105 {
13106 #ifdef CONFIG_X86_32
13107 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
13108 USER_RPL;
13109 #else
13110- return user_mode(regs);
13111+ return user_mode_novm(regs);
13112 #endif
13113 }
13114
13115@@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
13116 #ifdef CONFIG_X86_64
13117 static inline bool user_64bit_mode(struct pt_regs *regs)
13118 {
13119+ unsigned long cs = regs->cs & 0xffff;
13120 #ifndef CONFIG_PARAVIRT
13121 /*
13122 * On non-paravirt systems, this is the only long mode CPL 3
13123 * selector. We do not allow long mode selectors in the LDT.
13124 */
13125- return regs->cs == __USER_CS;
13126+ return cs == __USER_CS;
13127 #else
13128 /* Headers are too twisted for this to go in paravirt.h. */
13129- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
13130+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
13131 #endif
13132 }
13133 #endif
13134diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
13135index fe1ec5b..dc5c3fe 100644
13136--- a/arch/x86/include/asm/realmode.h
13137+++ b/arch/x86/include/asm/realmode.h
13138@@ -22,16 +22,14 @@ struct real_mode_header {
13139 #endif
13140 /* APM/BIOS reboot */
13141 u32 machine_real_restart_asm;
13142-#ifdef CONFIG_X86_64
13143 u32 machine_real_restart_seg;
13144-#endif
13145 };
13146
13147 /* This must match data at trampoline_32/64.S */
13148 struct trampoline_header {
13149 #ifdef CONFIG_X86_32
13150 u32 start;
13151- u16 gdt_pad;
13152+ u16 boot_cs;
13153 u16 gdt_limit;
13154 u32 gdt_base;
13155 #else
13156diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
13157index a82c4f1..f9c9696 100644
13158--- a/arch/x86/include/asm/reboot.h
13159+++ b/arch/x86/include/asm/reboot.h
13160@@ -6,12 +6,12 @@
13161 struct pt_regs;
13162
13163 struct machine_ops {
13164- void (*restart)(char *cmd);
13165- void (*halt)(void);
13166- void (*power_off)(void);
13167+ void (* __noreturn restart)(char *cmd);
13168+ void (* __noreturn halt)(void);
13169+ void (* __noreturn power_off)(void);
13170 void (*shutdown)(void);
13171 void (*crash_shutdown)(struct pt_regs *);
13172- void (*emergency_restart)(void);
13173+ void (* __noreturn emergency_restart)(void);
13174 };
13175
13176 extern struct machine_ops machine_ops;
13177diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
13178index 2dbe4a7..ce1db00 100644
13179--- a/arch/x86/include/asm/rwsem.h
13180+++ b/arch/x86/include/asm/rwsem.h
13181@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
13182 {
13183 asm volatile("# beginning down_read\n\t"
13184 LOCK_PREFIX _ASM_INC "(%1)\n\t"
13185+
13186+#ifdef CONFIG_PAX_REFCOUNT
13187+ "jno 0f\n"
13188+ LOCK_PREFIX _ASM_DEC "(%1)\n"
13189+ "int $4\n0:\n"
13190+ _ASM_EXTABLE(0b, 0b)
13191+#endif
13192+
13193 /* adds 0x00000001 */
13194 " jns 1f\n"
13195 " call call_rwsem_down_read_failed\n"
13196@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
13197 "1:\n\t"
13198 " mov %1,%2\n\t"
13199 " add %3,%2\n\t"
13200+
13201+#ifdef CONFIG_PAX_REFCOUNT
13202+ "jno 0f\n"
13203+ "sub %3,%2\n"
13204+ "int $4\n0:\n"
13205+ _ASM_EXTABLE(0b, 0b)
13206+#endif
13207+
13208 " jle 2f\n\t"
13209 LOCK_PREFIX " cmpxchg %2,%0\n\t"
13210 " jnz 1b\n\t"
13211@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
13212 long tmp;
13213 asm volatile("# beginning down_write\n\t"
13214 LOCK_PREFIX " xadd %1,(%2)\n\t"
13215+
13216+#ifdef CONFIG_PAX_REFCOUNT
13217+ "jno 0f\n"
13218+ "mov %1,(%2)\n"
13219+ "int $4\n0:\n"
13220+ _ASM_EXTABLE(0b, 0b)
13221+#endif
13222+
13223 /* adds 0xffff0001, returns the old value */
13224 " test %1,%1\n\t"
13225 /* was the count 0 before? */
13226@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
13227 long tmp;
13228 asm volatile("# beginning __up_read\n\t"
13229 LOCK_PREFIX " xadd %1,(%2)\n\t"
13230+
13231+#ifdef CONFIG_PAX_REFCOUNT
13232+ "jno 0f\n"
13233+ "mov %1,(%2)\n"
13234+ "int $4\n0:\n"
13235+ _ASM_EXTABLE(0b, 0b)
13236+#endif
13237+
13238 /* subtracts 1, returns the old value */
13239 " jns 1f\n\t"
13240 " call call_rwsem_wake\n" /* expects old value in %edx */
13241@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
13242 long tmp;
13243 asm volatile("# beginning __up_write\n\t"
13244 LOCK_PREFIX " xadd %1,(%2)\n\t"
13245+
13246+#ifdef CONFIG_PAX_REFCOUNT
13247+ "jno 0f\n"
13248+ "mov %1,(%2)\n"
13249+ "int $4\n0:\n"
13250+ _ASM_EXTABLE(0b, 0b)
13251+#endif
13252+
13253 /* subtracts 0xffff0001, returns the old value */
13254 " jns 1f\n\t"
13255 " call call_rwsem_wake\n" /* expects old value in %edx */
13256@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13257 {
13258 asm volatile("# beginning __downgrade_write\n\t"
13259 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
13260+
13261+#ifdef CONFIG_PAX_REFCOUNT
13262+ "jno 0f\n"
13263+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
13264+ "int $4\n0:\n"
13265+ _ASM_EXTABLE(0b, 0b)
13266+#endif
13267+
13268 /*
13269 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
13270 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
13271@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
13272 */
13273 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13274 {
13275- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
13276+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
13277+
13278+#ifdef CONFIG_PAX_REFCOUNT
13279+ "jno 0f\n"
13280+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
13281+ "int $4\n0:\n"
13282+ _ASM_EXTABLE(0b, 0b)
13283+#endif
13284+
13285 : "+m" (sem->count)
13286 : "er" (delta));
13287 }
13288@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
13289 */
13290 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
13291 {
13292- return delta + xadd(&sem->count, delta);
13293+ return delta + xadd_check_overflow(&sem->count, delta);
13294 }
13295
13296 #endif /* __KERNEL__ */
13297diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
13298index c48a950..c6d7468 100644
13299--- a/arch/x86/include/asm/segment.h
13300+++ b/arch/x86/include/asm/segment.h
13301@@ -64,10 +64,15 @@
13302 * 26 - ESPFIX small SS
13303 * 27 - per-cpu [ offset to per-cpu data area ]
13304 * 28 - stack_canary-20 [ for stack protector ]
13305- * 29 - unused
13306- * 30 - unused
13307+ * 29 - PCI BIOS CS
13308+ * 30 - PCI BIOS DS
13309 * 31 - TSS for double fault handler
13310 */
13311+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
13312+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
13313+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
13314+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
13315+
13316 #define GDT_ENTRY_TLS_MIN 6
13317 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
13318
13319@@ -79,6 +84,8 @@
13320
13321 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
13322
13323+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
13324+
13325 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
13326
13327 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
13328@@ -104,6 +111,12 @@
13329 #define __KERNEL_STACK_CANARY 0
13330 #endif
13331
13332+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
13333+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
13334+
13335+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
13336+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
13337+
13338 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
13339
13340 /*
13341@@ -141,7 +154,7 @@
13342 */
13343
13344 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
13345-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
13346+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
13347
13348
13349 #else
13350@@ -165,6 +178,8 @@
13351 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
13352 #define __USER32_DS __USER_DS
13353
13354+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
13355+
13356 #define GDT_ENTRY_TSS 8 /* needs two entries */
13357 #define GDT_ENTRY_LDT 10 /* needs two entries */
13358 #define GDT_ENTRY_TLS_MIN 12
13359@@ -185,6 +200,7 @@
13360 #endif
13361
13362 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
13363+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
13364 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
13365 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
13366 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
13367@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
13368 {
13369 unsigned long __limit;
13370 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
13371- return __limit + 1;
13372+ return __limit;
13373 }
13374
13375 #endif /* !__ASSEMBLY__ */
13376diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
13377index 4f19a15..e04d86f 100644
13378--- a/arch/x86/include/asm/smp.h
13379+++ b/arch/x86/include/asm/smp.h
13380@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
13381 /* cpus sharing the last level cache: */
13382 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
13383 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
13384-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
13385+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
13386
13387 static inline struct cpumask *cpu_sibling_mask(int cpu)
13388 {
13389@@ -190,14 +190,8 @@ extern unsigned disabled_cpus __cpuinitdata;
13390 extern int safe_smp_processor_id(void);
13391
13392 #elif defined(CONFIG_X86_64_SMP)
13393-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13394-
13395-#define stack_smp_processor_id() \
13396-({ \
13397- struct thread_info *ti; \
13398- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
13399- ti->cpu; \
13400-})
13401+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
13402+#define stack_smp_processor_id() raw_smp_processor_id()
13403 #define safe_smp_processor_id() smp_processor_id()
13404
13405 #endif
13406diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
13407index 33692ea..350a534 100644
13408--- a/arch/x86/include/asm/spinlock.h
13409+++ b/arch/x86/include/asm/spinlock.h
13410@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
13411 static inline void arch_read_lock(arch_rwlock_t *rw)
13412 {
13413 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
13414+
13415+#ifdef CONFIG_PAX_REFCOUNT
13416+ "jno 0f\n"
13417+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
13418+ "int $4\n0:\n"
13419+ _ASM_EXTABLE(0b, 0b)
13420+#endif
13421+
13422 "jns 1f\n"
13423 "call __read_lock_failed\n\t"
13424 "1:\n"
13425@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
13426 static inline void arch_write_lock(arch_rwlock_t *rw)
13427 {
13428 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
13429+
13430+#ifdef CONFIG_PAX_REFCOUNT
13431+ "jno 0f\n"
13432+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
13433+ "int $4\n0:\n"
13434+ _ASM_EXTABLE(0b, 0b)
13435+#endif
13436+
13437 "jz 1f\n"
13438 "call __write_lock_failed\n\t"
13439 "1:\n"
13440@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
13441
13442 static inline void arch_read_unlock(arch_rwlock_t *rw)
13443 {
13444- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
13445+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
13446+
13447+#ifdef CONFIG_PAX_REFCOUNT
13448+ "jno 0f\n"
13449+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
13450+ "int $4\n0:\n"
13451+ _ASM_EXTABLE(0b, 0b)
13452+#endif
13453+
13454 :"+m" (rw->lock) : : "memory");
13455 }
13456
13457 static inline void arch_write_unlock(arch_rwlock_t *rw)
13458 {
13459- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
13460+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
13461+
13462+#ifdef CONFIG_PAX_REFCOUNT
13463+ "jno 0f\n"
13464+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
13465+ "int $4\n0:\n"
13466+ _ASM_EXTABLE(0b, 0b)
13467+#endif
13468+
13469 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
13470 }
13471
13472diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
13473index 6a99859..03cb807 100644
13474--- a/arch/x86/include/asm/stackprotector.h
13475+++ b/arch/x86/include/asm/stackprotector.h
13476@@ -47,7 +47,7 @@
13477 * head_32 for boot CPU and setup_per_cpu_areas() for others.
13478 */
13479 #define GDT_STACK_CANARY_INIT \
13480- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
13481+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
13482
13483 /*
13484 * Initialize the stackprotector canary value.
13485@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
13486
13487 static inline void load_stack_canary_segment(void)
13488 {
13489-#ifdef CONFIG_X86_32
13490+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
13491 asm volatile ("mov %0, %%gs" : : "r" (0));
13492 #endif
13493 }
13494diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
13495index 70bbe39..4ae2bd4 100644
13496--- a/arch/x86/include/asm/stacktrace.h
13497+++ b/arch/x86/include/asm/stacktrace.h
13498@@ -11,28 +11,20 @@
13499
13500 extern int kstack_depth_to_print;
13501
13502-struct thread_info;
13503+struct task_struct;
13504 struct stacktrace_ops;
13505
13506-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
13507- unsigned long *stack,
13508- unsigned long bp,
13509- const struct stacktrace_ops *ops,
13510- void *data,
13511- unsigned long *end,
13512- int *graph);
13513+typedef unsigned long walk_stack_t(struct task_struct *task,
13514+ void *stack_start,
13515+ unsigned long *stack,
13516+ unsigned long bp,
13517+ const struct stacktrace_ops *ops,
13518+ void *data,
13519+ unsigned long *end,
13520+ int *graph);
13521
13522-extern unsigned long
13523-print_context_stack(struct thread_info *tinfo,
13524- unsigned long *stack, unsigned long bp,
13525- const struct stacktrace_ops *ops, void *data,
13526- unsigned long *end, int *graph);
13527-
13528-extern unsigned long
13529-print_context_stack_bp(struct thread_info *tinfo,
13530- unsigned long *stack, unsigned long bp,
13531- const struct stacktrace_ops *ops, void *data,
13532- unsigned long *end, int *graph);
13533+extern walk_stack_t print_context_stack;
13534+extern walk_stack_t print_context_stack_bp;
13535
13536 /* Generic stack tracer with callbacks */
13537
13538@@ -40,7 +32,7 @@ struct stacktrace_ops {
13539 void (*address)(void *data, unsigned long address, int reliable);
13540 /* On negative return stop dumping */
13541 int (*stack)(void *data, char *name);
13542- walk_stack_t walk_stack;
13543+ walk_stack_t *walk_stack;
13544 };
13545
13546 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
13547diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
13548index 4ec45b3..a4f0a8a 100644
13549--- a/arch/x86/include/asm/switch_to.h
13550+++ b/arch/x86/include/asm/switch_to.h
13551@@ -108,7 +108,7 @@ do { \
13552 "call __switch_to\n\t" \
13553 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
13554 __switch_canary \
13555- "movq %P[thread_info](%%rsi),%%r8\n\t" \
13556+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
13557 "movq %%rax,%%rdi\n\t" \
13558 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
13559 "jnz ret_from_fork\n\t" \
13560@@ -119,7 +119,7 @@ do { \
13561 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
13562 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
13563 [_tif_fork] "i" (_TIF_FORK), \
13564- [thread_info] "i" (offsetof(struct task_struct, stack)), \
13565+ [thread_info] "m" (current_tinfo), \
13566 [current_task] "m" (current_task) \
13567 __switch_canary_iparam \
13568 : "memory", "cc" __EXTRA_CLOBBER)
13569diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
13570index 2d946e6..e453ec4 100644
13571--- a/arch/x86/include/asm/thread_info.h
13572+++ b/arch/x86/include/asm/thread_info.h
13573@@ -10,6 +10,7 @@
13574 #include <linux/compiler.h>
13575 #include <asm/page.h>
13576 #include <asm/types.h>
13577+#include <asm/percpu.h>
13578
13579 /*
13580 * low level task data that entry.S needs immediate access to
13581@@ -24,7 +25,6 @@ struct exec_domain;
13582 #include <linux/atomic.h>
13583
13584 struct thread_info {
13585- struct task_struct *task; /* main task structure */
13586 struct exec_domain *exec_domain; /* execution domain */
13587 __u32 flags; /* low level flags */
13588 __u32 status; /* thread synchronous flags */
13589@@ -34,19 +34,13 @@ struct thread_info {
13590 mm_segment_t addr_limit;
13591 struct restart_block restart_block;
13592 void __user *sysenter_return;
13593-#ifdef CONFIG_X86_32
13594- unsigned long previous_esp; /* ESP of the previous stack in
13595- case of nested (IRQ) stacks
13596- */
13597- __u8 supervisor_stack[0];
13598-#endif
13599+ unsigned long lowest_stack;
13600 unsigned int sig_on_uaccess_error:1;
13601 unsigned int uaccess_err:1; /* uaccess failed */
13602 };
13603
13604-#define INIT_THREAD_INFO(tsk) \
13605+#define INIT_THREAD_INFO \
13606 { \
13607- .task = &tsk, \
13608 .exec_domain = &default_exec_domain, \
13609 .flags = 0, \
13610 .cpu = 0, \
13611@@ -57,7 +51,7 @@ struct thread_info {
13612 }, \
13613 }
13614
13615-#define init_thread_info (init_thread_union.thread_info)
13616+#define init_thread_info (init_thread_union.stack)
13617 #define init_stack (init_thread_union.stack)
13618
13619 #else /* !__ASSEMBLY__ */
13620@@ -98,6 +92,7 @@ struct thread_info {
13621 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
13622 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
13623 #define TIF_X32 30 /* 32-bit native x86-64 binary */
13624+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
13625
13626 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
13627 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
13628@@ -122,17 +117,18 @@ struct thread_info {
13629 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
13630 #define _TIF_ADDR32 (1 << TIF_ADDR32)
13631 #define _TIF_X32 (1 << TIF_X32)
13632+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
13633
13634 /* work to do in syscall_trace_enter() */
13635 #define _TIF_WORK_SYSCALL_ENTRY \
13636 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
13637 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
13638- _TIF_NOHZ)
13639+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13640
13641 /* work to do in syscall_trace_leave() */
13642 #define _TIF_WORK_SYSCALL_EXIT \
13643 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
13644- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
13645+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
13646
13647 /* work to do on interrupt/exception return */
13648 #define _TIF_WORK_MASK \
13649@@ -143,7 +139,7 @@ struct thread_info {
13650 /* work to do on any return to user space */
13651 #define _TIF_ALLWORK_MASK \
13652 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
13653- _TIF_NOHZ)
13654+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
13655
13656 /* Only used for 64 bit */
13657 #define _TIF_DO_NOTIFY_MASK \
13658@@ -159,45 +155,40 @@ struct thread_info {
13659
13660 #define PREEMPT_ACTIVE 0x10000000
13661
13662-#ifdef CONFIG_X86_32
13663-
13664-#define STACK_WARN (THREAD_SIZE/8)
13665-/*
13666- * macros/functions for gaining access to the thread information structure
13667- *
13668- * preempt_count needs to be 1 initially, until the scheduler is functional.
13669- */
13670-#ifndef __ASSEMBLY__
13671-
13672-
13673-/* how to get the current stack pointer from C */
13674-register unsigned long current_stack_pointer asm("esp") __used;
13675-
13676-/* how to get the thread information struct from C */
13677-static inline struct thread_info *current_thread_info(void)
13678-{
13679- return (struct thread_info *)
13680- (current_stack_pointer & ~(THREAD_SIZE - 1));
13681-}
13682-
13683-#else /* !__ASSEMBLY__ */
13684-
13685+#ifdef __ASSEMBLY__
13686 /* how to get the thread information struct from ASM */
13687 #define GET_THREAD_INFO(reg) \
13688- movl $-THREAD_SIZE, reg; \
13689- andl %esp, reg
13690+ mov PER_CPU_VAR(current_tinfo), reg
13691
13692 /* use this one if reg already contains %esp */
13693-#define GET_THREAD_INFO_WITH_ESP(reg) \
13694- andl $-THREAD_SIZE, reg
13695+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
13696+#else
13697+/* how to get the thread information struct from C */
13698+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
13699+
13700+static __always_inline struct thread_info *current_thread_info(void)
13701+{
13702+ return this_cpu_read_stable(current_tinfo);
13703+}
13704+#endif
13705+
13706+#ifdef CONFIG_X86_32
13707+
13708+#define STACK_WARN (THREAD_SIZE/8)
13709+/*
13710+ * macros/functions for gaining access to the thread information structure
13711+ *
13712+ * preempt_count needs to be 1 initially, until the scheduler is functional.
13713+ */
13714+#ifndef __ASSEMBLY__
13715+
13716+/* how to get the current stack pointer from C */
13717+register unsigned long current_stack_pointer asm("esp") __used;
13718
13719 #endif
13720
13721 #else /* X86_32 */
13722
13723-#include <asm/percpu.h>
13724-#define KERNEL_STACK_OFFSET (5*8)
13725-
13726 /*
13727 * macros/functions for gaining access to the thread information structure
13728 * preempt_count needs to be 1 initially, until the scheduler is functional.
13729@@ -205,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
13730 #ifndef __ASSEMBLY__
13731 DECLARE_PER_CPU(unsigned long, kernel_stack);
13732
13733-static inline struct thread_info *current_thread_info(void)
13734-{
13735- struct thread_info *ti;
13736- ti = (void *)(this_cpu_read_stable(kernel_stack) +
13737- KERNEL_STACK_OFFSET - THREAD_SIZE);
13738- return ti;
13739-}
13740-
13741-#else /* !__ASSEMBLY__ */
13742-
13743-/* how to get the thread information struct from ASM */
13744-#define GET_THREAD_INFO(reg) \
13745- movq PER_CPU_VAR(kernel_stack),reg ; \
13746- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
13747-
13748-/*
13749- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
13750- * a certain register (to be used in assembler memory operands).
13751- */
13752-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
13753-
13754+/* how to get the current stack pointer from C */
13755+register unsigned long current_stack_pointer asm("rsp") __used;
13756 #endif
13757
13758 #endif /* !X86_32 */
13759@@ -286,5 +258,12 @@ static inline bool is_ia32_task(void)
13760 extern void arch_task_cache_init(void);
13761 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
13762 extern void arch_release_task_struct(struct task_struct *tsk);
13763+
13764+#define __HAVE_THREAD_FUNCTIONS
13765+#define task_thread_info(task) (&(task)->tinfo)
13766+#define task_stack_page(task) ((task)->stack)
13767+#define setup_thread_stack(p, org) do {} while (0)
13768+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
13769+
13770 #endif
13771 #endif /* _ASM_X86_THREAD_INFO_H */
13772diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
13773index 7ccf8d1..7cdca12 100644
13774--- a/arch/x86/include/asm/uaccess.h
13775+++ b/arch/x86/include/asm/uaccess.h
13776@@ -7,6 +7,7 @@
13777 #include <linux/compiler.h>
13778 #include <linux/thread_info.h>
13779 #include <linux/string.h>
13780+#include <linux/sched.h>
13781 #include <asm/asm.h>
13782 #include <asm/page.h>
13783 #include <asm/smap.h>
13784@@ -14,6 +15,8 @@
13785 #define VERIFY_READ 0
13786 #define VERIFY_WRITE 1
13787
13788+extern void check_object_size(const void *ptr, unsigned long n, bool to);
13789+
13790 /*
13791 * The fs value determines whether argument validity checking should be
13792 * performed or not. If get_fs() == USER_DS, checking is performed, with
13793@@ -29,7 +32,12 @@
13794
13795 #define get_ds() (KERNEL_DS)
13796 #define get_fs() (current_thread_info()->addr_limit)
13797+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13798+void __set_fs(mm_segment_t x);
13799+void set_fs(mm_segment_t x);
13800+#else
13801 #define set_fs(x) (current_thread_info()->addr_limit = (x))
13802+#endif
13803
13804 #define segment_eq(a, b) ((a).seg == (b).seg)
13805
13806@@ -77,8 +85,33 @@
13807 * checks that the pointer is in the user space range - after calling
13808 * this function, memory access functions may still return -EFAULT.
13809 */
13810-#define access_ok(type, addr, size) \
13811- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13812+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
13813+#define access_ok(type, addr, size) \
13814+({ \
13815+ long __size = size; \
13816+ unsigned long __addr = (unsigned long)addr; \
13817+ unsigned long __addr_ao = __addr & PAGE_MASK; \
13818+ unsigned long __end_ao = __addr + __size - 1; \
13819+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
13820+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
13821+ while(__addr_ao <= __end_ao) { \
13822+ char __c_ao; \
13823+ __addr_ao += PAGE_SIZE; \
13824+ if (__size > PAGE_SIZE) \
13825+ cond_resched(); \
13826+ if (__get_user(__c_ao, (char __user *)__addr)) \
13827+ break; \
13828+ if (type != VERIFY_WRITE) { \
13829+ __addr = __addr_ao; \
13830+ continue; \
13831+ } \
13832+ if (__put_user(__c_ao, (char __user *)__addr)) \
13833+ break; \
13834+ __addr = __addr_ao; \
13835+ } \
13836+ } \
13837+ __ret_ao; \
13838+})
13839
13840 /*
13841 * The exception table consists of pairs of addresses relative to the
13842@@ -189,13 +222,21 @@ extern int __get_user_bad(void);
13843 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
13844 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
13845
13846-
13847+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
13848+#define __copyuser_seg "gs;"
13849+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
13850+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
13851+#else
13852+#define __copyuser_seg
13853+#define __COPYUSER_SET_ES
13854+#define __COPYUSER_RESTORE_ES
13855+#endif
13856
13857 #ifdef CONFIG_X86_32
13858 #define __put_user_asm_u64(x, addr, err, errret) \
13859 asm volatile(ASM_STAC "\n" \
13860- "1: movl %%eax,0(%2)\n" \
13861- "2: movl %%edx,4(%2)\n" \
13862+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
13863+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
13864 "3: " ASM_CLAC "\n" \
13865 ".section .fixup,\"ax\"\n" \
13866 "4: movl %3,%0\n" \
13867@@ -208,8 +249,8 @@ extern int __get_user_bad(void);
13868
13869 #define __put_user_asm_ex_u64(x, addr) \
13870 asm volatile(ASM_STAC "\n" \
13871- "1: movl %%eax,0(%1)\n" \
13872- "2: movl %%edx,4(%1)\n" \
13873+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
13874+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
13875 "3: " ASM_CLAC "\n" \
13876 _ASM_EXTABLE_EX(1b, 2b) \
13877 _ASM_EXTABLE_EX(2b, 3b) \
13878@@ -261,7 +302,7 @@ extern void __put_user_8(void);
13879 __typeof__(*(ptr)) __pu_val; \
13880 __chk_user_ptr(ptr); \
13881 might_fault(); \
13882- __pu_val = x; \
13883+ __pu_val = (x); \
13884 switch (sizeof(*(ptr))) { \
13885 case 1: \
13886 __put_user_x(1, __pu_val, ptr, __ret_pu); \
13887@@ -383,7 +424,7 @@ do { \
13888
13889 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13890 asm volatile(ASM_STAC "\n" \
13891- "1: mov"itype" %2,%"rtype"1\n" \
13892+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
13893 "2: " ASM_CLAC "\n" \
13894 ".section .fixup,\"ax\"\n" \
13895 "3: mov %3,%0\n" \
13896@@ -391,7 +432,7 @@ do { \
13897 " jmp 2b\n" \
13898 ".previous\n" \
13899 _ASM_EXTABLE(1b, 3b) \
13900- : "=r" (err), ltype(x) \
13901+ : "=r" (err), ltype (x) \
13902 : "m" (__m(addr)), "i" (errret), "0" (err))
13903
13904 #define __get_user_size_ex(x, ptr, size) \
13905@@ -416,7 +457,7 @@ do { \
13906 } while (0)
13907
13908 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
13909- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
13910+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
13911 "2:\n" \
13912 _ASM_EXTABLE_EX(1b, 2b) \
13913 : ltype(x) : "m" (__m(addr)))
13914@@ -433,13 +474,24 @@ do { \
13915 int __gu_err; \
13916 unsigned long __gu_val; \
13917 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
13918- (x) = (__force __typeof__(*(ptr)))__gu_val; \
13919+ (x) = (__typeof__(*(ptr)))__gu_val; \
13920 __gu_err; \
13921 })
13922
13923 /* FIXME: this hack is definitely wrong -AK */
13924 struct __large_struct { unsigned long buf[100]; };
13925-#define __m(x) (*(struct __large_struct __user *)(x))
13926+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13927+#define ____m(x) \
13928+({ \
13929+ unsigned long ____x = (unsigned long)(x); \
13930+ if (____x < PAX_USER_SHADOW_BASE) \
13931+ ____x += PAX_USER_SHADOW_BASE; \
13932+ (void __user *)____x; \
13933+})
13934+#else
13935+#define ____m(x) (x)
13936+#endif
13937+#define __m(x) (*(struct __large_struct __user *)____m(x))
13938
13939 /*
13940 * Tell gcc we read from memory instead of writing: this is because
13941@@ -448,7 +500,7 @@ struct __large_struct { unsigned long buf[100]; };
13942 */
13943 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
13944 asm volatile(ASM_STAC "\n" \
13945- "1: mov"itype" %"rtype"1,%2\n" \
13946+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
13947 "2: " ASM_CLAC "\n" \
13948 ".section .fixup,\"ax\"\n" \
13949 "3: mov %3,%0\n" \
13950@@ -456,10 +508,10 @@ struct __large_struct { unsigned long buf[100]; };
13951 ".previous\n" \
13952 _ASM_EXTABLE(1b, 3b) \
13953 : "=r"(err) \
13954- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
13955+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
13956
13957 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
13958- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
13959+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
13960 "2:\n" \
13961 _ASM_EXTABLE_EX(1b, 2b) \
13962 : : ltype(x), "m" (__m(addr)))
13963@@ -498,8 +550,12 @@ struct __large_struct { unsigned long buf[100]; };
13964 * On error, the variable @x is set to zero.
13965 */
13966
13967+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13968+#define __get_user(x, ptr) get_user((x), (ptr))
13969+#else
13970 #define __get_user(x, ptr) \
13971 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
13972+#endif
13973
13974 /**
13975 * __put_user: - Write a simple value into user space, with less checking.
13976@@ -521,8 +577,12 @@ struct __large_struct { unsigned long buf[100]; };
13977 * Returns zero on success, or -EFAULT on error.
13978 */
13979
13980+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13981+#define __put_user(x, ptr) put_user((x), (ptr))
13982+#else
13983 #define __put_user(x, ptr) \
13984 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
13985+#endif
13986
13987 #define __get_user_unaligned __get_user
13988 #define __put_user_unaligned __put_user
13989@@ -540,7 +600,7 @@ struct __large_struct { unsigned long buf[100]; };
13990 #define get_user_ex(x, ptr) do { \
13991 unsigned long __gue_val; \
13992 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
13993- (x) = (__force __typeof__(*(ptr)))__gue_val; \
13994+ (x) = (__typeof__(*(ptr)))__gue_val; \
13995 } while (0)
13996
13997 #ifdef CONFIG_X86_WP_WORKS_OK
13998@@ -574,8 +634,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
13999 extern __must_check long strlen_user(const char __user *str);
14000 extern __must_check long strnlen_user(const char __user *str, long n);
14001
14002-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
14003-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
14004+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14005+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
14006
14007 /*
14008 * movsl can be slow when source and dest are not both 8-byte aligned
14009diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
14010index 7f760a9..00f93c0 100644
14011--- a/arch/x86/include/asm/uaccess_32.h
14012+++ b/arch/x86/include/asm/uaccess_32.h
14013@@ -11,15 +11,15 @@
14014 #include <asm/page.h>
14015
14016 unsigned long __must_check __copy_to_user_ll
14017- (void __user *to, const void *from, unsigned long n);
14018+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
14019 unsigned long __must_check __copy_from_user_ll
14020- (void *to, const void __user *from, unsigned long n);
14021+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14022 unsigned long __must_check __copy_from_user_ll_nozero
14023- (void *to, const void __user *from, unsigned long n);
14024+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14025 unsigned long __must_check __copy_from_user_ll_nocache
14026- (void *to, const void __user *from, unsigned long n);
14027+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14028 unsigned long __must_check __copy_from_user_ll_nocache_nozero
14029- (void *to, const void __user *from, unsigned long n);
14030+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
14031
14032 /**
14033 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
14034@@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
14035 static __always_inline unsigned long __must_check
14036 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14037 {
14038+ if ((long)n < 0)
14039+ return n;
14040+
14041 if (__builtin_constant_p(n)) {
14042 unsigned long ret;
14043
14044@@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
14045 return ret;
14046 }
14047 }
14048+ if (!__builtin_constant_p(n))
14049+ check_object_size(from, n, true);
14050 return __copy_to_user_ll(to, from, n);
14051 }
14052
14053@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
14054 __copy_to_user(void __user *to, const void *from, unsigned long n)
14055 {
14056 might_fault();
14057+
14058 return __copy_to_user_inatomic(to, from, n);
14059 }
14060
14061 static __always_inline unsigned long
14062 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
14063 {
14064+ if ((long)n < 0)
14065+ return n;
14066+
14067 /* Avoid zeroing the tail if the copy fails..
14068 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
14069 * but as the zeroing behaviour is only significant when n is not
14070@@ -137,6 +146,10 @@ static __always_inline unsigned long
14071 __copy_from_user(void *to, const void __user *from, unsigned long n)
14072 {
14073 might_fault();
14074+
14075+ if ((long)n < 0)
14076+ return n;
14077+
14078 if (__builtin_constant_p(n)) {
14079 unsigned long ret;
14080
14081@@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
14082 return ret;
14083 }
14084 }
14085+ if (!__builtin_constant_p(n))
14086+ check_object_size(to, n, false);
14087 return __copy_from_user_ll(to, from, n);
14088 }
14089
14090@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
14091 const void __user *from, unsigned long n)
14092 {
14093 might_fault();
14094+
14095+ if ((long)n < 0)
14096+ return n;
14097+
14098 if (__builtin_constant_p(n)) {
14099 unsigned long ret;
14100
14101@@ -181,15 +200,19 @@ static __always_inline unsigned long
14102 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
14103 unsigned long n)
14104 {
14105- return __copy_from_user_ll_nocache_nozero(to, from, n);
14106+ if ((long)n < 0)
14107+ return n;
14108+
14109+ return __copy_from_user_ll_nocache_nozero(to, from, n);
14110 }
14111
14112-unsigned long __must_check copy_to_user(void __user *to,
14113- const void *from, unsigned long n);
14114-unsigned long __must_check _copy_from_user(void *to,
14115- const void __user *from,
14116- unsigned long n);
14117-
14118+extern void copy_to_user_overflow(void)
14119+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14120+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14121+#else
14122+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14123+#endif
14124+;
14125
14126 extern void copy_from_user_overflow(void)
14127 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14128@@ -199,17 +222,61 @@ extern void copy_from_user_overflow(void)
14129 #endif
14130 ;
14131
14132-static inline unsigned long __must_check copy_from_user(void *to,
14133- const void __user *from,
14134- unsigned long n)
14135+/**
14136+ * copy_to_user: - Copy a block of data into user space.
14137+ * @to: Destination address, in user space.
14138+ * @from: Source address, in kernel space.
14139+ * @n: Number of bytes to copy.
14140+ *
14141+ * Context: User context only. This function may sleep.
14142+ *
14143+ * Copy data from kernel space to user space.
14144+ *
14145+ * Returns number of bytes that could not be copied.
14146+ * On success, this will be zero.
14147+ */
14148+static inline unsigned long __must_check
14149+copy_to_user(void __user *to, const void *from, unsigned long n)
14150 {
14151- int sz = __compiletime_object_size(to);
14152+ size_t sz = __compiletime_object_size(from);
14153
14154- if (likely(sz == -1 || sz >= n))
14155- n = _copy_from_user(to, from, n);
14156- else
14157+ if (unlikely(sz != (size_t)-1 && sz < n))
14158+ copy_to_user_overflow();
14159+ else if (access_ok(VERIFY_WRITE, to, n))
14160+ n = __copy_to_user(to, from, n);
14161+ return n;
14162+}
14163+
14164+/**
14165+ * copy_from_user: - Copy a block of data from user space.
14166+ * @to: Destination address, in kernel space.
14167+ * @from: Source address, in user space.
14168+ * @n: Number of bytes to copy.
14169+ *
14170+ * Context: User context only. This function may sleep.
14171+ *
14172+ * Copy data from user space to kernel space.
14173+ *
14174+ * Returns number of bytes that could not be copied.
14175+ * On success, this will be zero.
14176+ *
14177+ * If some data could not be copied, this function will pad the copied
14178+ * data to the requested size using zero bytes.
14179+ */
14180+static inline unsigned long __must_check
14181+copy_from_user(void *to, const void __user *from, unsigned long n)
14182+{
14183+ size_t sz = __compiletime_object_size(to);
14184+
14185+ if (unlikely(sz != (size_t)-1 && sz < n))
14186 copy_from_user_overflow();
14187-
14188+ else if (access_ok(VERIFY_READ, from, n))
14189+ n = __copy_from_user(to, from, n);
14190+ else if ((long)n > 0) {
14191+ if (!__builtin_constant_p(n))
14192+ check_object_size(to, n, false);
14193+ memset(to, 0, n);
14194+ }
14195 return n;
14196 }
14197
14198diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
14199index 142810c..4389299 100644
14200--- a/arch/x86/include/asm/uaccess_64.h
14201+++ b/arch/x86/include/asm/uaccess_64.h
14202@@ -10,6 +10,9 @@
14203 #include <asm/alternative.h>
14204 #include <asm/cpufeature.h>
14205 #include <asm/page.h>
14206+#include <asm/pgtable.h>
14207+
14208+#define set_fs(x) (current_thread_info()->addr_limit = (x))
14209
14210 /*
14211 * Copy To/From Userspace
14212@@ -17,13 +20,13 @@
14213
14214 /* Handles exceptions in both to and from, but doesn't do access_ok */
14215 __must_check unsigned long
14216-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
14217+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
14218 __must_check unsigned long
14219-copy_user_generic_string(void *to, const void *from, unsigned len);
14220+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
14221 __must_check unsigned long
14222-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
14223+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
14224
14225-static __always_inline __must_check unsigned long
14226+static __always_inline __must_check __size_overflow(3) unsigned long
14227 copy_user_generic(void *to, const void *from, unsigned len)
14228 {
14229 unsigned ret;
14230@@ -41,142 +44,205 @@ copy_user_generic(void *to, const void *from, unsigned len)
14231 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
14232 "=d" (len)),
14233 "1" (to), "2" (from), "3" (len)
14234- : "memory", "rcx", "r8", "r9", "r10", "r11");
14235+ : "memory", "rcx", "r8", "r9", "r11");
14236 return ret;
14237 }
14238
14239+static __always_inline __must_check unsigned long
14240+__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
14241+static __always_inline __must_check unsigned long
14242+__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
14243 __must_check unsigned long
14244-_copy_to_user(void __user *to, const void *from, unsigned len);
14245-__must_check unsigned long
14246-_copy_from_user(void *to, const void __user *from, unsigned len);
14247-__must_check unsigned long
14248-copy_in_user(void __user *to, const void __user *from, unsigned len);
14249+copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
14250+
14251+extern void copy_to_user_overflow(void)
14252+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14253+ __compiletime_error("copy_to_user() buffer size is not provably correct")
14254+#else
14255+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
14256+#endif
14257+;
14258+
14259+extern void copy_from_user_overflow(void)
14260+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
14261+ __compiletime_error("copy_from_user() buffer size is not provably correct")
14262+#else
14263+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
14264+#endif
14265+;
14266
14267 static inline unsigned long __must_check copy_from_user(void *to,
14268 const void __user *from,
14269 unsigned long n)
14270 {
14271- int sz = __compiletime_object_size(to);
14272-
14273 might_fault();
14274- if (likely(sz == -1 || sz >= n))
14275- n = _copy_from_user(to, from, n);
14276-#ifdef CONFIG_DEBUG_VM
14277- else
14278- WARN(1, "Buffer overflow detected!\n");
14279-#endif
14280+
14281+ if (access_ok(VERIFY_READ, from, n))
14282+ n = __copy_from_user(to, from, n);
14283+ else if (n < INT_MAX) {
14284+ if (!__builtin_constant_p(n))
14285+ check_object_size(to, n, false);
14286+ memset(to, 0, n);
14287+ }
14288 return n;
14289 }
14290
14291 static __always_inline __must_check
14292-int copy_to_user(void __user *dst, const void *src, unsigned size)
14293+int copy_to_user(void __user *dst, const void *src, unsigned long size)
14294 {
14295 might_fault();
14296
14297- return _copy_to_user(dst, src, size);
14298+ if (access_ok(VERIFY_WRITE, dst, size))
14299+ size = __copy_to_user(dst, src, size);
14300+ return size;
14301 }
14302
14303 static __always_inline __must_check
14304-int __copy_from_user(void *dst, const void __user *src, unsigned size)
14305+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
14306 {
14307- int ret = 0;
14308+ size_t sz = __compiletime_object_size(dst);
14309+ unsigned ret = 0;
14310
14311 might_fault();
14312- if (!__builtin_constant_p(size))
14313- return copy_user_generic(dst, (__force void *)src, size);
14314+
14315+ if (size > INT_MAX)
14316+ return size;
14317+
14318+#ifdef CONFIG_PAX_MEMORY_UDEREF
14319+ if (!__access_ok(VERIFY_READ, src, size))
14320+ return size;
14321+#endif
14322+
14323+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14324+ copy_from_user_overflow();
14325+ return size;
14326+ }
14327+
14328+ if (!__builtin_constant_p(size)) {
14329+ check_object_size(dst, size, false);
14330+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14331+ }
14332 switch (size) {
14333- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
14334+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
14335 ret, "b", "b", "=q", 1);
14336 return ret;
14337- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
14338+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
14339 ret, "w", "w", "=r", 2);
14340 return ret;
14341- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
14342+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
14343 ret, "l", "k", "=r", 4);
14344 return ret;
14345- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
14346+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14347 ret, "q", "", "=r", 8);
14348 return ret;
14349 case 10:
14350- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14351+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14352 ret, "q", "", "=r", 10);
14353 if (unlikely(ret))
14354 return ret;
14355 __get_user_asm(*(u16 *)(8 + (char *)dst),
14356- (u16 __user *)(8 + (char __user *)src),
14357+ (const u16 __user *)(8 + (const char __user *)src),
14358 ret, "w", "w", "=r", 2);
14359 return ret;
14360 case 16:
14361- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
14362+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
14363 ret, "q", "", "=r", 16);
14364 if (unlikely(ret))
14365 return ret;
14366 __get_user_asm(*(u64 *)(8 + (char *)dst),
14367- (u64 __user *)(8 + (char __user *)src),
14368+ (const u64 __user *)(8 + (const char __user *)src),
14369 ret, "q", "", "=r", 8);
14370 return ret;
14371 default:
14372- return copy_user_generic(dst, (__force void *)src, size);
14373+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14374 }
14375 }
14376
14377 static __always_inline __must_check
14378-int __copy_to_user(void __user *dst, const void *src, unsigned size)
14379+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
14380 {
14381- int ret = 0;
14382+ size_t sz = __compiletime_object_size(src);
14383+ unsigned ret = 0;
14384
14385 might_fault();
14386- if (!__builtin_constant_p(size))
14387- return copy_user_generic((__force void *)dst, src, size);
14388+
14389+ if (size > INT_MAX)
14390+ return size;
14391+
14392+#ifdef CONFIG_PAX_MEMORY_UDEREF
14393+ if (!__access_ok(VERIFY_WRITE, dst, size))
14394+ return size;
14395+#endif
14396+
14397+ if (unlikely(sz != (size_t)-1 && sz < size)) {
14398+ copy_to_user_overflow();
14399+ return size;
14400+ }
14401+
14402+ if (!__builtin_constant_p(size)) {
14403+ check_object_size(src, size, true);
14404+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14405+ }
14406 switch (size) {
14407- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
14408+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
14409 ret, "b", "b", "iq", 1);
14410 return ret;
14411- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
14412+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
14413 ret, "w", "w", "ir", 2);
14414 return ret;
14415- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
14416+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
14417 ret, "l", "k", "ir", 4);
14418 return ret;
14419- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
14420+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14421 ret, "q", "", "er", 8);
14422 return ret;
14423 case 10:
14424- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14425+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14426 ret, "q", "", "er", 10);
14427 if (unlikely(ret))
14428 return ret;
14429 asm("":::"memory");
14430- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
14431+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
14432 ret, "w", "w", "ir", 2);
14433 return ret;
14434 case 16:
14435- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
14436+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
14437 ret, "q", "", "er", 16);
14438 if (unlikely(ret))
14439 return ret;
14440 asm("":::"memory");
14441- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
14442+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
14443 ret, "q", "", "er", 8);
14444 return ret;
14445 default:
14446- return copy_user_generic((__force void *)dst, src, size);
14447+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14448 }
14449 }
14450
14451 static __always_inline __must_check
14452-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14453+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
14454 {
14455- int ret = 0;
14456+ unsigned ret = 0;
14457
14458 might_fault();
14459+
14460+ if (size > INT_MAX)
14461+ return size;
14462+
14463+#ifdef CONFIG_PAX_MEMORY_UDEREF
14464+ if (!__access_ok(VERIFY_READ, src, size))
14465+ return size;
14466+ if (!__access_ok(VERIFY_WRITE, dst, size))
14467+ return size;
14468+#endif
14469+
14470 if (!__builtin_constant_p(size))
14471- return copy_user_generic((__force void *)dst,
14472- (__force void *)src, size);
14473+ return copy_user_generic((__force_kernel void *)____m(dst),
14474+ (__force_kernel const void *)____m(src), size);
14475 switch (size) {
14476 case 1: {
14477 u8 tmp;
14478- __get_user_asm(tmp, (u8 __user *)src,
14479+ __get_user_asm(tmp, (const u8 __user *)src,
14480 ret, "b", "b", "=q", 1);
14481 if (likely(!ret))
14482 __put_user_asm(tmp, (u8 __user *)dst,
14483@@ -185,7 +251,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14484 }
14485 case 2: {
14486 u16 tmp;
14487- __get_user_asm(tmp, (u16 __user *)src,
14488+ __get_user_asm(tmp, (const u16 __user *)src,
14489 ret, "w", "w", "=r", 2);
14490 if (likely(!ret))
14491 __put_user_asm(tmp, (u16 __user *)dst,
14492@@ -195,7 +261,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14493
14494 case 4: {
14495 u32 tmp;
14496- __get_user_asm(tmp, (u32 __user *)src,
14497+ __get_user_asm(tmp, (const u32 __user *)src,
14498 ret, "l", "k", "=r", 4);
14499 if (likely(!ret))
14500 __put_user_asm(tmp, (u32 __user *)dst,
14501@@ -204,7 +270,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14502 }
14503 case 8: {
14504 u64 tmp;
14505- __get_user_asm(tmp, (u64 __user *)src,
14506+ __get_user_asm(tmp, (const u64 __user *)src,
14507 ret, "q", "", "=r", 8);
14508 if (likely(!ret))
14509 __put_user_asm(tmp, (u64 __user *)dst,
14510@@ -212,41 +278,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
14511 return ret;
14512 }
14513 default:
14514- return copy_user_generic((__force void *)dst,
14515- (__force void *)src, size);
14516+ return copy_user_generic((__force_kernel void *)____m(dst),
14517+ (__force_kernel const void *)____m(src), size);
14518 }
14519 }
14520
14521 static __must_check __always_inline int
14522-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
14523+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
14524 {
14525- return copy_user_generic(dst, (__force const void *)src, size);
14526+ if (size > INT_MAX)
14527+ return size;
14528+
14529+#ifdef CONFIG_PAX_MEMORY_UDEREF
14530+ if (!__access_ok(VERIFY_READ, src, size))
14531+ return size;
14532+#endif
14533+
14534+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
14535 }
14536
14537-static __must_check __always_inline int
14538-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
14539+static __must_check __always_inline unsigned long
14540+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
14541 {
14542- return copy_user_generic((__force void *)dst, src, size);
14543+ if (size > INT_MAX)
14544+ return size;
14545+
14546+#ifdef CONFIG_PAX_MEMORY_UDEREF
14547+ if (!__access_ok(VERIFY_WRITE, dst, size))
14548+ return size;
14549+#endif
14550+
14551+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
14552 }
14553
14554-extern long __copy_user_nocache(void *dst, const void __user *src,
14555- unsigned size, int zerorest);
14556+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
14557+ unsigned long size, int zerorest) __size_overflow(3);
14558
14559-static inline int
14560-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
14561+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
14562 {
14563 might_sleep();
14564+
14565+ if (size > INT_MAX)
14566+ return size;
14567+
14568+#ifdef CONFIG_PAX_MEMORY_UDEREF
14569+ if (!__access_ok(VERIFY_READ, src, size))
14570+ return size;
14571+#endif
14572+
14573 return __copy_user_nocache(dst, src, size, 1);
14574 }
14575
14576-static inline int
14577-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14578- unsigned size)
14579+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
14580+ unsigned long size)
14581 {
14582+ if (size > INT_MAX)
14583+ return size;
14584+
14585+#ifdef CONFIG_PAX_MEMORY_UDEREF
14586+ if (!__access_ok(VERIFY_READ, src, size))
14587+ return size;
14588+#endif
14589+
14590 return __copy_user_nocache(dst, src, size, 0);
14591 }
14592
14593-unsigned long
14594-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
14595+extern unsigned long
14596+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
14597
14598 #endif /* _ASM_X86_UACCESS_64_H */
14599diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
14600index 5b238981..77fdd78 100644
14601--- a/arch/x86/include/asm/word-at-a-time.h
14602+++ b/arch/x86/include/asm/word-at-a-time.h
14603@@ -11,7 +11,7 @@
14604 * and shift, for example.
14605 */
14606 struct word_at_a_time {
14607- const unsigned long one_bits, high_bits;
14608+ unsigned long one_bits, high_bits;
14609 };
14610
14611 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
14612diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
14613index 0415cda..b43d877 100644
14614--- a/arch/x86/include/asm/xsave.h
14615+++ b/arch/x86/include/asm/xsave.h
14616@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14617 return -EFAULT;
14618
14619 __asm__ __volatile__(ASM_STAC "\n"
14620- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
14621+ "1:"
14622+ __copyuser_seg
14623+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
14624 "2: " ASM_CLAC "\n"
14625 ".section .fixup,\"ax\"\n"
14626 "3: movl $-1,%[err]\n"
14627@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
14628 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
14629 {
14630 int err;
14631- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
14632+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
14633 u32 lmask = mask;
14634 u32 hmask = mask >> 32;
14635
14636 __asm__ __volatile__(ASM_STAC "\n"
14637- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14638+ "1:"
14639+ __copyuser_seg
14640+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
14641 "2: " ASM_CLAC "\n"
14642 ".section .fixup,\"ax\"\n"
14643 "3: movl $-1,%[err]\n"
14644diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
14645index 91ce48f..a48ea05 100644
14646--- a/arch/x86/kernel/Makefile
14647+++ b/arch/x86/kernel/Makefile
14648@@ -23,7 +23,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
14649 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
14650 obj-$(CONFIG_IRQ_WORK) += irq_work.o
14651 obj-y += probe_roms.o
14652-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
14653+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
14654 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
14655 obj-y += syscall_$(BITS).o
14656 obj-$(CONFIG_X86_64) += vsyscall_64.o
14657diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
14658index e651f7a..c995dc4 100644
14659--- a/arch/x86/kernel/acpi/boot.c
14660+++ b/arch/x86/kernel/acpi/boot.c
14661@@ -1576,7 +1576,7 @@ int __init acpi_boot_init(void)
14662 acpi_table_parse(ACPI_SIG_HPET, acpi_parse_hpet);
14663
14664 if (!acpi_noirq)
14665- x86_init.pci.init = pci_acpi_init;
14666+ *(void **)&x86_init.pci.init = pci_acpi_init;
14667
14668 return 0;
14669 }
14670diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
14671index 11676cf..a8cf3ec 100644
14672--- a/arch/x86/kernel/acpi/sleep.c
14673+++ b/arch/x86/kernel/acpi/sleep.c
14674@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
14675 #else /* CONFIG_64BIT */
14676 #ifdef CONFIG_SMP
14677 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
14678+
14679+ pax_open_kernel();
14680 early_gdt_descr.address =
14681 (unsigned long)get_cpu_gdt_table(smp_processor_id());
14682+ pax_close_kernel();
14683+
14684 initial_gs = per_cpu_offset(smp_processor_id());
14685 #endif
14686 initial_code = (unsigned long)wakeup_long64;
14687diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
14688index 13ab720..95d5442 100644
14689--- a/arch/x86/kernel/acpi/wakeup_32.S
14690+++ b/arch/x86/kernel/acpi/wakeup_32.S
14691@@ -30,13 +30,11 @@ wakeup_pmode_return:
14692 # and restore the stack ... but you need gdt for this to work
14693 movl saved_context_esp, %esp
14694
14695- movl %cs:saved_magic, %eax
14696- cmpl $0x12345678, %eax
14697+ cmpl $0x12345678, saved_magic
14698 jne bogus_magic
14699
14700 # jump to place where we left off
14701- movl saved_eip, %eax
14702- jmp *%eax
14703+ jmp *(saved_eip)
14704
14705 bogus_magic:
14706 jmp bogus_magic
14707diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
14708index ef5ccca..bd83949 100644
14709--- a/arch/x86/kernel/alternative.c
14710+++ b/arch/x86/kernel/alternative.c
14711@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
14712 */
14713 for (a = start; a < end; a++) {
14714 instr = (u8 *)&a->instr_offset + a->instr_offset;
14715+
14716+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14717+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14718+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
14719+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14720+#endif
14721+
14722 replacement = (u8 *)&a->repl_offset + a->repl_offset;
14723 BUG_ON(a->replacementlen > a->instrlen);
14724 BUG_ON(a->instrlen > sizeof(insnbuf));
14725@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
14726 for (poff = start; poff < end; poff++) {
14727 u8 *ptr = (u8 *)poff + *poff;
14728
14729+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14730+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14731+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14732+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14733+#endif
14734+
14735 if (!*poff || ptr < text || ptr >= text_end)
14736 continue;
14737 /* turn DS segment override prefix into lock prefix */
14738- if (*ptr == 0x3e)
14739+ if (*ktla_ktva(ptr) == 0x3e)
14740 text_poke(ptr, ((unsigned char []){0xf0}), 1);
14741 }
14742 mutex_unlock(&text_mutex);
14743@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
14744 for (poff = start; poff < end; poff++) {
14745 u8 *ptr = (u8 *)poff + *poff;
14746
14747+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
14748+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14749+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
14750+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
14751+#endif
14752+
14753 if (!*poff || ptr < text || ptr >= text_end)
14754 continue;
14755 /* turn lock prefix into DS segment override prefix */
14756- if (*ptr == 0xf0)
14757+ if (*ktla_ktva(ptr) == 0xf0)
14758 text_poke(ptr, ((unsigned char []){0x3E}), 1);
14759 }
14760 mutex_unlock(&text_mutex);
14761@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
14762
14763 BUG_ON(p->len > MAX_PATCH_LEN);
14764 /* prep the buffer with the original instructions */
14765- memcpy(insnbuf, p->instr, p->len);
14766+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
14767 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
14768 (unsigned long)p->instr, p->len);
14769
14770@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
14771 if (!uniproc_patched || num_possible_cpus() == 1)
14772 free_init_pages("SMP alternatives",
14773 (unsigned long)__smp_locks,
14774- (unsigned long)__smp_locks_end);
14775+ PAGE_ALIGN((unsigned long)__smp_locks_end));
14776 #endif
14777
14778 apply_paravirt(__parainstructions, __parainstructions_end);
14779@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
14780 * instructions. And on the local CPU you need to be protected again NMI or MCE
14781 * handlers seeing an inconsistent instruction while you patch.
14782 */
14783-void *__init_or_module text_poke_early(void *addr, const void *opcode,
14784+void *__kprobes text_poke_early(void *addr, const void *opcode,
14785 size_t len)
14786 {
14787 unsigned long flags;
14788 local_irq_save(flags);
14789- memcpy(addr, opcode, len);
14790+
14791+ pax_open_kernel();
14792+ memcpy(ktla_ktva(addr), opcode, len);
14793 sync_core();
14794+ pax_close_kernel();
14795+
14796 local_irq_restore(flags);
14797 /* Could also do a CLFLUSH here to speed up CPU recovery; but
14798 that causes hangs on some VIA CPUs. */
14799@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
14800 */
14801 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
14802 {
14803- unsigned long flags;
14804- char *vaddr;
14805+ unsigned char *vaddr = ktla_ktva(addr);
14806 struct page *pages[2];
14807- int i;
14808+ size_t i;
14809
14810 if (!core_kernel_text((unsigned long)addr)) {
14811- pages[0] = vmalloc_to_page(addr);
14812- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
14813+ pages[0] = vmalloc_to_page(vaddr);
14814+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
14815 } else {
14816- pages[0] = virt_to_page(addr);
14817+ pages[0] = virt_to_page(vaddr);
14818 WARN_ON(!PageReserved(pages[0]));
14819- pages[1] = virt_to_page(addr + PAGE_SIZE);
14820+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
14821 }
14822 BUG_ON(!pages[0]);
14823- local_irq_save(flags);
14824- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
14825- if (pages[1])
14826- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
14827- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
14828- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
14829- clear_fixmap(FIX_TEXT_POKE0);
14830- if (pages[1])
14831- clear_fixmap(FIX_TEXT_POKE1);
14832- local_flush_tlb();
14833- sync_core();
14834- /* Could also do a CLFLUSH here to speed up CPU recovery; but
14835- that causes hangs on some VIA CPUs. */
14836+ text_poke_early(addr, opcode, len);
14837 for (i = 0; i < len; i++)
14838- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
14839- local_irq_restore(flags);
14840+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
14841 return addr;
14842 }
14843
14844diff --git a/arch/x86/kernel/amd_gart_64.c b/arch/x86/kernel/amd_gart_64.c
14845index e663112..21938a3 100644
14846--- a/arch/x86/kernel/amd_gart_64.c
14847+++ b/arch/x86/kernel/amd_gart_64.c
14848@@ -851,7 +851,7 @@ int __init gart_iommu_init(void)
14849
14850 flush_gart();
14851 dma_ops = &gart_dma_ops;
14852- x86_platform.iommu_shutdown = gart_iommu_shutdown;
14853+ *(void **)&x86_platform.iommu_shutdown = gart_iommu_shutdown;
14854 swiotlb = 0;
14855
14856 return 0;
14857diff --git a/arch/x86/kernel/aperture_64.c b/arch/x86/kernel/aperture_64.c
14858index d5fd66f..6119b16 100644
14859--- a/arch/x86/kernel/aperture_64.c
14860+++ b/arch/x86/kernel/aperture_64.c
14861@@ -390,7 +390,7 @@ int __init gart_iommu_hole_init(void)
14862
14863 iommu_detected = 1;
14864 gart_iommu_aperture = 1;
14865- x86_init.iommu.iommu_init = gart_iommu_init;
14866+ *(void **)&x86_init.iommu.iommu_init = gart_iommu_init;
14867
14868 ctl = read_pci_config(bus, slot, 3,
14869 AMD64_GARTAPERTURECTL);
14870diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
14871index b17416e..be6e5dc 100644
14872--- a/arch/x86/kernel/apic/apic.c
14873+++ b/arch/x86/kernel/apic/apic.c
14874@@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
14875 /*
14876 * Debug level, exported for io_apic.c
14877 */
14878-unsigned int apic_verbosity;
14879+int apic_verbosity;
14880
14881 int pic_mode;
14882
14883@@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
14884 apic_write(APIC_ESR, 0);
14885 v1 = apic_read(APIC_ESR);
14886 ack_APIC_irq();
14887- atomic_inc(&irq_err_count);
14888+ atomic_inc_unchecked(&irq_err_count);
14889
14890 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
14891 smp_processor_id(), v0 , v1);
14892@@ -2155,7 +2155,9 @@ void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v))
14893 for (drv = __apicdrivers; drv < __apicdrivers_end; drv++) {
14894 /* Should happen once for each apic */
14895 WARN_ON((*drv)->eoi_write == eoi_write);
14896- (*drv)->eoi_write = eoi_write;
14897+ pax_open_kernel();
14898+ *(void **)&(*drv)->eoi_write = eoi_write;
14899+ pax_close_kernel();
14900 }
14901 }
14902
14903diff --git a/arch/x86/kernel/apic/apic_numachip.c b/arch/x86/kernel/apic/apic_numachip.c
14904index a65829a..6ddc249 100644
14905--- a/arch/x86/kernel/apic/apic_numachip.c
14906+++ b/arch/x86/kernel/apic/apic_numachip.c
14907@@ -178,7 +178,7 @@ static int __init numachip_system_init(void)
14908 if (!numachip_system)
14909 return 0;
14910
14911- x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14912+ *(void **)&x86_cpuinit.fixup_cpu_id = fixup_cpu_id;
14913
14914 map_csrs();
14915
14916diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
14917index 1817fa9..7bff097 100644
14918--- a/arch/x86/kernel/apic/io_apic.c
14919+++ b/arch/x86/kernel/apic/io_apic.c
14920@@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
14921 }
14922 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
14923
14924-void lock_vector_lock(void)
14925+void lock_vector_lock(void) __acquires(vector_lock)
14926 {
14927 /* Used to the online set of cpus does not change
14928 * during assign_irq_vector.
14929@@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
14930 raw_spin_lock(&vector_lock);
14931 }
14932
14933-void unlock_vector_lock(void)
14934+void unlock_vector_lock(void) __releases(vector_lock)
14935 {
14936 raw_spin_unlock(&vector_lock);
14937 }
14938@@ -2411,7 +2411,7 @@ static void ack_apic_edge(struct irq_data *data)
14939 ack_APIC_irq();
14940 }
14941
14942-atomic_t irq_mis_count;
14943+atomic_unchecked_t irq_mis_count;
14944
14945 #ifdef CONFIG_GENERIC_PENDING_IRQ
14946 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
14947@@ -2552,7 +2552,7 @@ static void ack_apic_level(struct irq_data *data)
14948 * at the cpu.
14949 */
14950 if (!(v & (1 << (i & 0x1f)))) {
14951- atomic_inc(&irq_mis_count);
14952+ atomic_inc_unchecked(&irq_mis_count);
14953
14954 eoi_ioapic_irq(irq, cfg);
14955 }
14956diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
14957index d661ee9..512c0a1 100644
14958--- a/arch/x86/kernel/apic/numaq_32.c
14959+++ b/arch/x86/kernel/apic/numaq_32.c
14960@@ -257,14 +257,14 @@ static __init void early_check_numaq(void)
14961 early_get_smp_config();
14962
14963 if (found_numaq) {
14964- x86_init.mpparse.mpc_record = numaq_mpc_record;
14965- x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14966- x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14967- x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14968- x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14969- x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14970- x86_init.timers.tsc_pre_init = numaq_tsc_init;
14971- x86_init.pci.init = pci_numaq_init;
14972+ *(void **)&x86_init.mpparse.mpc_record = numaq_mpc_record;
14973+ *(void **)&x86_init.mpparse.setup_ioapic_ids = x86_init_noop;
14974+ *(void **)&x86_init.mpparse.mpc_apic_id = mpc_apic_id;
14975+ *(void **)&x86_init.mpparse.smp_read_mpc_oem = smp_read_mpc_oem;
14976+ *(void **)&x86_init.mpparse.mpc_oem_pci_bus = mpc_oem_pci_bus;
14977+ *(void **)&x86_init.mpparse.mpc_oem_bus_info = mpc_oem_bus_info;
14978+ *(void **)&x86_init.timers.tsc_pre_init = numaq_tsc_init;
14979+ *(void **)&x86_init.pci.init = pci_numaq_init;
14980 }
14981 }
14982
14983diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
14984index 8cfade9..8ea7b51 100644
14985--- a/arch/x86/kernel/apic/x2apic_uv_x.c
14986+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
14987@@ -139,8 +139,8 @@ static int __init uv_acpi_madt_oem_check(char *oem_id, char *oem_table_id)
14988 is_uv1 ? UV1_HUB_REVISION_BASE : UV2_HUB_REVISION_BASE;
14989 pnodeid = early_get_pnodeid();
14990 early_get_apic_pnode_shift();
14991- x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
14992- x86_platform.nmi_init = uv_nmi_init;
14993+ *(void **)&x86_platform.is_untracked_pat_range = uv_is_untracked_pat_range;
14994+ *(void **)&x86_platform.nmi_init = uv_nmi_init;
14995 if (!strcmp(oem_table_id, "UVL"))
14996 uv_system_type = UV_LEGACY_APIC;
14997 else if (!strcmp(oem_table_id, "UVX"))
14998diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
14999index d65464e..1035d31 100644
15000--- a/arch/x86/kernel/apm_32.c
15001+++ b/arch/x86/kernel/apm_32.c
15002@@ -412,7 +412,7 @@ static DEFINE_MUTEX(apm_mutex);
15003 * This is for buggy BIOS's that refer to (real mode) segment 0x40
15004 * even though they are called in protected mode.
15005 */
15006-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
15007+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
15008 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
15009
15010 static const char driver_version[] = "1.16ac"; /* no spaces */
15011@@ -590,7 +590,10 @@ static long __apm_bios_call(void *_call)
15012 BUG_ON(cpu != 0);
15013 gdt = get_cpu_gdt_table(cpu);
15014 save_desc_40 = gdt[0x40 / 8];
15015+
15016+ pax_open_kernel();
15017 gdt[0x40 / 8] = bad_bios_desc;
15018+ pax_close_kernel();
15019
15020 apm_irq_save(flags);
15021 APM_DO_SAVE_SEGS;
15022@@ -599,7 +602,11 @@ static long __apm_bios_call(void *_call)
15023 &call->esi);
15024 APM_DO_RESTORE_SEGS;
15025 apm_irq_restore(flags);
15026+
15027+ pax_open_kernel();
15028 gdt[0x40 / 8] = save_desc_40;
15029+ pax_close_kernel();
15030+
15031 put_cpu();
15032
15033 return call->eax & 0xff;
15034@@ -666,7 +673,10 @@ static long __apm_bios_call_simple(void *_call)
15035 BUG_ON(cpu != 0);
15036 gdt = get_cpu_gdt_table(cpu);
15037 save_desc_40 = gdt[0x40 / 8];
15038+
15039+ pax_open_kernel();
15040 gdt[0x40 / 8] = bad_bios_desc;
15041+ pax_close_kernel();
15042
15043 apm_irq_save(flags);
15044 APM_DO_SAVE_SEGS;
15045@@ -674,7 +684,11 @@ static long __apm_bios_call_simple(void *_call)
15046 &call->eax);
15047 APM_DO_RESTORE_SEGS;
15048 apm_irq_restore(flags);
15049+
15050+ pax_open_kernel();
15051 gdt[0x40 / 8] = save_desc_40;
15052+ pax_close_kernel();
15053+
15054 put_cpu();
15055 return error;
15056 }
15057@@ -2345,12 +2359,15 @@ static int __init apm_init(void)
15058 * code to that CPU.
15059 */
15060 gdt = get_cpu_gdt_table(0);
15061+
15062+ pax_open_kernel();
15063 set_desc_base(&gdt[APM_CS >> 3],
15064 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
15065 set_desc_base(&gdt[APM_CS_16 >> 3],
15066 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
15067 set_desc_base(&gdt[APM_DS >> 3],
15068 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
15069+ pax_close_kernel();
15070
15071 proc_create("apm", 0, NULL, &apm_file_ops);
15072
15073diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
15074index 2861082..6d4718e 100644
15075--- a/arch/x86/kernel/asm-offsets.c
15076+++ b/arch/x86/kernel/asm-offsets.c
15077@@ -33,6 +33,8 @@ void common(void) {
15078 OFFSET(TI_status, thread_info, status);
15079 OFFSET(TI_addr_limit, thread_info, addr_limit);
15080 OFFSET(TI_preempt_count, thread_info, preempt_count);
15081+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
15082+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
15083
15084 BLANK();
15085 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
15086@@ -53,8 +55,26 @@ void common(void) {
15087 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
15088 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
15089 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
15090+
15091+#ifdef CONFIG_PAX_KERNEXEC
15092+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
15093 #endif
15094
15095+#ifdef CONFIG_PAX_MEMORY_UDEREF
15096+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
15097+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
15098+#ifdef CONFIG_X86_64
15099+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
15100+#endif
15101+#endif
15102+
15103+#endif
15104+
15105+ BLANK();
15106+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
15107+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
15108+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
15109+
15110 #ifdef CONFIG_XEN
15111 BLANK();
15112 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
15113diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
15114index 1b4754f..fbb4227 100644
15115--- a/arch/x86/kernel/asm-offsets_64.c
15116+++ b/arch/x86/kernel/asm-offsets_64.c
15117@@ -76,6 +76,7 @@ int main(void)
15118 BLANK();
15119 #undef ENTRY
15120
15121+ DEFINE(TSS_size, sizeof(struct tss_struct));
15122 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
15123 BLANK();
15124
15125diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
15126index a0e067d..9c7db16 100644
15127--- a/arch/x86/kernel/cpu/Makefile
15128+++ b/arch/x86/kernel/cpu/Makefile
15129@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
15130 CFLAGS_REMOVE_perf_event.o = -pg
15131 endif
15132
15133-# Make sure load_percpu_segment has no stackprotector
15134-nostackp := $(call cc-option, -fno-stack-protector)
15135-CFLAGS_common.o := $(nostackp)
15136-
15137 obj-y := intel_cacheinfo.o scattered.o topology.o
15138 obj-y += proc.o capflags.o powerflags.o common.o
15139 obj-y += vmware.o hypervisor.o mshyperv.o
15140diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
15141index 1b7d165..b9e2627 100644
15142--- a/arch/x86/kernel/cpu/amd.c
15143+++ b/arch/x86/kernel/cpu/amd.c
15144@@ -738,7 +738,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
15145 unsigned int size)
15146 {
15147 /* AMD errata T13 (order #21922) */
15148- if ((c->x86 == 6)) {
15149+ if (c->x86 == 6) {
15150 /* Duron Rev A0 */
15151 if (c->x86_model == 3 && c->x86_mask == 0)
15152 size = 64;
15153diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
15154index 7505f7b..d59dac0 100644
15155--- a/arch/x86/kernel/cpu/common.c
15156+++ b/arch/x86/kernel/cpu/common.c
15157@@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
15158
15159 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
15160
15161-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
15162-#ifdef CONFIG_X86_64
15163- /*
15164- * We need valid kernel segments for data and code in long mode too
15165- * IRET will check the segment types kkeil 2000/10/28
15166- * Also sysret mandates a special GDT layout
15167- *
15168- * TLS descriptors are currently at a different place compared to i386.
15169- * Hopefully nobody expects them at a fixed place (Wine?)
15170- */
15171- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
15172- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
15173- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
15174- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
15175- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
15176- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
15177-#else
15178- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
15179- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15180- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
15181- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
15182- /*
15183- * Segments used for calling PnP BIOS have byte granularity.
15184- * They code segments and data segments have fixed 64k limits,
15185- * the transfer segment sizes are set at run time.
15186- */
15187- /* 32-bit code */
15188- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15189- /* 16-bit code */
15190- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15191- /* 16-bit data */
15192- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
15193- /* 16-bit data */
15194- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
15195- /* 16-bit data */
15196- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
15197- /*
15198- * The APM segments have byte granularity and their bases
15199- * are set at run time. All have 64k limits.
15200- */
15201- /* 32-bit code */
15202- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
15203- /* 16-bit code */
15204- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
15205- /* data */
15206- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
15207-
15208- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15209- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
15210- GDT_STACK_CANARY_INIT
15211-#endif
15212-} };
15213-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
15214-
15215 static int __init x86_xsave_setup(char *s)
15216 {
15217 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
15218@@ -389,7 +335,7 @@ void switch_to_new_gdt(int cpu)
15219 {
15220 struct desc_ptr gdt_descr;
15221
15222- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
15223+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
15224 gdt_descr.size = GDT_SIZE - 1;
15225 load_gdt(&gdt_descr);
15226 /* Reload the per-cpu base */
15227@@ -885,6 +831,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
15228 /* Filter out anything that depends on CPUID levels we don't have */
15229 filter_cpuid_features(c, true);
15230
15231+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
15232+ setup_clear_cpu_cap(X86_FEATURE_SEP);
15233+#endif
15234+
15235 /* If the model name is still unset, do table lookup. */
15236 if (!c->x86_model_id[0]) {
15237 const char *p;
15238@@ -1068,10 +1018,12 @@ static __init int setup_disablecpuid(char *arg)
15239 }
15240 __setup("clearcpuid=", setup_disablecpuid);
15241
15242+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
15243+EXPORT_PER_CPU_SYMBOL(current_tinfo);
15244+
15245 #ifdef CONFIG_X86_64
15246 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
15247-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
15248- (unsigned long) nmi_idt_table };
15249+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
15250
15251 DEFINE_PER_CPU_FIRST(union irq_stack_union,
15252 irq_stack_union) __aligned(PAGE_SIZE);
15253@@ -1085,7 +1037,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
15254 EXPORT_PER_CPU_SYMBOL(current_task);
15255
15256 DEFINE_PER_CPU(unsigned long, kernel_stack) =
15257- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
15258+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
15259 EXPORT_PER_CPU_SYMBOL(kernel_stack);
15260
15261 DEFINE_PER_CPU(char *, irq_stack_ptr) =
15262@@ -1178,7 +1130,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
15263 {
15264 memset(regs, 0, sizeof(struct pt_regs));
15265 regs->fs = __KERNEL_PERCPU;
15266- regs->gs = __KERNEL_STACK_CANARY;
15267+ savesegment(gs, regs->gs);
15268
15269 return regs;
15270 }
15271@@ -1233,7 +1185,7 @@ void __cpuinit cpu_init(void)
15272 int i;
15273
15274 cpu = stack_smp_processor_id();
15275- t = &per_cpu(init_tss, cpu);
15276+ t = init_tss + cpu;
15277 oist = &per_cpu(orig_ist, cpu);
15278
15279 #ifdef CONFIG_NUMA
15280@@ -1259,7 +1211,7 @@ void __cpuinit cpu_init(void)
15281 switch_to_new_gdt(cpu);
15282 loadsegment(fs, 0);
15283
15284- load_idt((const struct desc_ptr *)&idt_descr);
15285+ load_idt(&idt_descr);
15286
15287 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
15288 syscall_init();
15289@@ -1268,7 +1220,6 @@ void __cpuinit cpu_init(void)
15290 wrmsrl(MSR_KERNEL_GS_BASE, 0);
15291 barrier();
15292
15293- x86_configure_nx();
15294 if (cpu != 0)
15295 enable_x2apic();
15296
15297@@ -1321,7 +1272,7 @@ void __cpuinit cpu_init(void)
15298 {
15299 int cpu = smp_processor_id();
15300 struct task_struct *curr = current;
15301- struct tss_struct *t = &per_cpu(init_tss, cpu);
15302+ struct tss_struct *t = init_tss + cpu;
15303 struct thread_struct *thread = &curr->thread;
15304
15305 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
15306diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
15307index 198e019..867575e 100644
15308--- a/arch/x86/kernel/cpu/intel.c
15309+++ b/arch/x86/kernel/cpu/intel.c
15310@@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
15311 * Update the IDT descriptor and reload the IDT so that
15312 * it uses the read-only mapped virtual address.
15313 */
15314- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
15315+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
15316 load_idt(&idt_descr);
15317 }
15318 #endif
15319diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
15320index 93c5451..3887433 100644
15321--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
15322+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
15323@@ -983,6 +983,22 @@ static struct attribute *default_attrs[] = {
15324 };
15325
15326 #ifdef CONFIG_AMD_NB
15327+static struct attribute *default_attrs_amd_nb[] = {
15328+ &type.attr,
15329+ &level.attr,
15330+ &coherency_line_size.attr,
15331+ &physical_line_partition.attr,
15332+ &ways_of_associativity.attr,
15333+ &number_of_sets.attr,
15334+ &size.attr,
15335+ &shared_cpu_map.attr,
15336+ &shared_cpu_list.attr,
15337+ NULL,
15338+ NULL,
15339+ NULL,
15340+ NULL
15341+};
15342+
15343 static struct attribute ** __cpuinit amd_l3_attrs(void)
15344 {
15345 static struct attribute **attrs;
15346@@ -993,18 +1009,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
15347
15348 n = ARRAY_SIZE(default_attrs);
15349
15350- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
15351- n += 2;
15352-
15353- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
15354- n += 1;
15355-
15356- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
15357- if (attrs == NULL)
15358- return attrs = default_attrs;
15359-
15360- for (n = 0; default_attrs[n]; n++)
15361- attrs[n] = default_attrs[n];
15362+ attrs = default_attrs_amd_nb;
15363
15364 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
15365 attrs[n++] = &cache_disable_0.attr;
15366@@ -1055,6 +1060,13 @@ static struct kobj_type ktype_cache = {
15367 .default_attrs = default_attrs,
15368 };
15369
15370+#ifdef CONFIG_AMD_NB
15371+static struct kobj_type ktype_cache_amd_nb = {
15372+ .sysfs_ops = &sysfs_ops,
15373+ .default_attrs = default_attrs_amd_nb,
15374+};
15375+#endif
15376+
15377 static struct kobj_type ktype_percpu_entry = {
15378 .sysfs_ops = &sysfs_ops,
15379 };
15380@@ -1120,20 +1132,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
15381 return retval;
15382 }
15383
15384+#ifdef CONFIG_AMD_NB
15385+ amd_l3_attrs();
15386+#endif
15387+
15388 for (i = 0; i < num_cache_leaves; i++) {
15389+ struct kobj_type *ktype;
15390+
15391 this_object = INDEX_KOBJECT_PTR(cpu, i);
15392 this_object->cpu = cpu;
15393 this_object->index = i;
15394
15395 this_leaf = CPUID4_INFO_IDX(cpu, i);
15396
15397- ktype_cache.default_attrs = default_attrs;
15398+ ktype = &ktype_cache;
15399 #ifdef CONFIG_AMD_NB
15400 if (this_leaf->base.nb)
15401- ktype_cache.default_attrs = amd_l3_attrs();
15402+ ktype = &ktype_cache_amd_nb;
15403 #endif
15404 retval = kobject_init_and_add(&(this_object->kobj),
15405- &ktype_cache,
15406+ ktype,
15407 per_cpu(ici_cache_kobject, cpu),
15408 "index%1lu", i);
15409 if (unlikely(retval)) {
15410diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
15411index 46cbf86..55c7292 100644
15412--- a/arch/x86/kernel/cpu/mcheck/mce.c
15413+++ b/arch/x86/kernel/cpu/mcheck/mce.c
15414@@ -45,6 +45,7 @@
15415 #include <asm/processor.h>
15416 #include <asm/mce.h>
15417 #include <asm/msr.h>
15418+#include <asm/local.h>
15419
15420 #include "mce-internal.h"
15421
15422@@ -254,7 +255,7 @@ static void print_mce(struct mce *m)
15423 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
15424 m->cs, m->ip);
15425
15426- if (m->cs == __KERNEL_CS)
15427+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
15428 print_symbol("{%s}", m->ip);
15429 pr_cont("\n");
15430 }
15431@@ -287,10 +288,10 @@ static void print_mce(struct mce *m)
15432
15433 #define PANIC_TIMEOUT 5 /* 5 seconds */
15434
15435-static atomic_t mce_paniced;
15436+static atomic_unchecked_t mce_paniced;
15437
15438 static int fake_panic;
15439-static atomic_t mce_fake_paniced;
15440+static atomic_unchecked_t mce_fake_paniced;
15441
15442 /* Panic in progress. Enable interrupts and wait for final IPI */
15443 static void wait_for_panic(void)
15444@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15445 /*
15446 * Make sure only one CPU runs in machine check panic
15447 */
15448- if (atomic_inc_return(&mce_paniced) > 1)
15449+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
15450 wait_for_panic();
15451 barrier();
15452
15453@@ -322,7 +323,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
15454 console_verbose();
15455 } else {
15456 /* Don't log too much for fake panic */
15457- if (atomic_inc_return(&mce_fake_paniced) > 1)
15458+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
15459 return;
15460 }
15461 /* First print corrected ones that are still unlogged */
15462@@ -694,7 +695,7 @@ static int mce_timed_out(u64 *t)
15463 * might have been modified by someone else.
15464 */
15465 rmb();
15466- if (atomic_read(&mce_paniced))
15467+ if (atomic_read_unchecked(&mce_paniced))
15468 wait_for_panic();
15469 if (!monarch_timeout)
15470 goto out;
15471@@ -1659,7 +1660,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
15472 }
15473
15474 /* Call the installed machine check handler for this CPU setup. */
15475-void (*machine_check_vector)(struct pt_regs *, long error_code) =
15476+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
15477 unexpected_machine_check;
15478
15479 /*
15480@@ -1682,7 +1683,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15481 return;
15482 }
15483
15484+ pax_open_kernel();
15485 machine_check_vector = do_machine_check;
15486+ pax_close_kernel();
15487
15488 __mcheck_cpu_init_generic();
15489 __mcheck_cpu_init_vendor(c);
15490@@ -1696,7 +1699,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
15491 */
15492
15493 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
15494-static int mce_chrdev_open_count; /* #times opened */
15495+static local_t mce_chrdev_open_count; /* #times opened */
15496 static int mce_chrdev_open_exclu; /* already open exclusive? */
15497
15498 static int mce_chrdev_open(struct inode *inode, struct file *file)
15499@@ -1704,7 +1707,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15500 spin_lock(&mce_chrdev_state_lock);
15501
15502 if (mce_chrdev_open_exclu ||
15503- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
15504+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
15505 spin_unlock(&mce_chrdev_state_lock);
15506
15507 return -EBUSY;
15508@@ -1712,7 +1715,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
15509
15510 if (file->f_flags & O_EXCL)
15511 mce_chrdev_open_exclu = 1;
15512- mce_chrdev_open_count++;
15513+ local_inc(&mce_chrdev_open_count);
15514
15515 spin_unlock(&mce_chrdev_state_lock);
15516
15517@@ -1723,7 +1726,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
15518 {
15519 spin_lock(&mce_chrdev_state_lock);
15520
15521- mce_chrdev_open_count--;
15522+ local_dec(&mce_chrdev_open_count);
15523 mce_chrdev_open_exclu = 0;
15524
15525 spin_unlock(&mce_chrdev_state_lock);
15526@@ -2367,7 +2370,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
15527 return NOTIFY_OK;
15528 }
15529
15530-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
15531+static struct notifier_block mce_cpu_notifier __cpuinitconst = {
15532 .notifier_call = mce_cpu_callback,
15533 };
15534
15535@@ -2445,7 +2448,7 @@ struct dentry *mce_get_debugfs_dir(void)
15536 static void mce_reset(void)
15537 {
15538 cpu_missing = 0;
15539- atomic_set(&mce_fake_paniced, 0);
15540+ atomic_set_unchecked(&mce_fake_paniced, 0);
15541 atomic_set(&mce_executing, 0);
15542 atomic_set(&mce_callin, 0);
15543 atomic_set(&global_nwo, 0);
15544diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
15545index 2d5454c..51987eb 100644
15546--- a/arch/x86/kernel/cpu/mcheck/p5.c
15547+++ b/arch/x86/kernel/cpu/mcheck/p5.c
15548@@ -11,6 +11,7 @@
15549 #include <asm/processor.h>
15550 #include <asm/mce.h>
15551 #include <asm/msr.h>
15552+#include <asm/pgtable.h>
15553
15554 /* By default disabled */
15555 int mce_p5_enabled __read_mostly;
15556@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
15557 if (!cpu_has(c, X86_FEATURE_MCE))
15558 return;
15559
15560+ pax_open_kernel();
15561 machine_check_vector = pentium_machine_check;
15562+ pax_close_kernel();
15563 /* Make sure the vector pointer is visible before we enable MCEs: */
15564 wmb();
15565
15566diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
15567index 2d7998f..17c9de1 100644
15568--- a/arch/x86/kernel/cpu/mcheck/winchip.c
15569+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
15570@@ -10,6 +10,7 @@
15571 #include <asm/processor.h>
15572 #include <asm/mce.h>
15573 #include <asm/msr.h>
15574+#include <asm/pgtable.h>
15575
15576 /* Machine check handler for WinChip C6: */
15577 static void winchip_machine_check(struct pt_regs *regs, long error_code)
15578@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
15579 {
15580 u32 lo, hi;
15581
15582+ pax_open_kernel();
15583 machine_check_vector = winchip_machine_check;
15584+ pax_close_kernel();
15585 /* Make sure the vector pointer is visible before we enable MCEs: */
15586 wmb();
15587
15588diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
15589index 6b96110..0da73eb 100644
15590--- a/arch/x86/kernel/cpu/mtrr/main.c
15591+++ b/arch/x86/kernel/cpu/mtrr/main.c
15592@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
15593 u64 size_or_mask, size_and_mask;
15594 static bool mtrr_aps_delayed_init;
15595
15596-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
15597+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
15598
15599 const struct mtrr_ops *mtrr_if;
15600
15601diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
15602index df5e41f..816c719 100644
15603--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
15604+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
15605@@ -25,7 +25,7 @@ struct mtrr_ops {
15606 int (*validate_add_page)(unsigned long base, unsigned long size,
15607 unsigned int type);
15608 int (*have_wrcomb)(void);
15609-};
15610+} __do_const;
15611
15612 extern int generic_get_free_region(unsigned long base, unsigned long size,
15613 int replace_reg);
15614diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
15615index d18b2b8..d3b834c 100644
15616--- a/arch/x86/kernel/cpu/perf_event.c
15617+++ b/arch/x86/kernel/cpu/perf_event.c
15618@@ -1759,7 +1759,7 @@ static unsigned long get_segment_base(unsigned int segment)
15619 if (idx > GDT_ENTRIES)
15620 return 0;
15621
15622- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
15623+ desc = get_cpu_gdt_table(smp_processor_id());
15624 }
15625
15626 return get_desc_base(desc + idx);
15627@@ -1849,7 +1849,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
15628 break;
15629
15630 perf_callchain_store(entry, frame.return_address);
15631- fp = frame.next_frame;
15632+ fp = (const void __force_user *)frame.next_frame;
15633 }
15634 }
15635
15636diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
15637index 324bb52..1a93d85 100644
15638--- a/arch/x86/kernel/cpu/perf_event_intel.c
15639+++ b/arch/x86/kernel/cpu/perf_event_intel.c
15640@@ -1949,10 +1949,10 @@ __init int intel_pmu_init(void)
15641 * v2 and above have a perf capabilities MSR
15642 */
15643 if (version > 1) {
15644- u64 capabilities;
15645+ u64 capabilities = x86_pmu.intel_cap.capabilities;
15646
15647- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
15648- x86_pmu.intel_cap.capabilities = capabilities;
15649+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
15650+ x86_pmu.intel_cap.capabilities = capabilities;
15651 }
15652
15653 intel_ds_init();
15654diff --git a/arch/x86/kernel/cpu/vmware.c b/arch/x86/kernel/cpu/vmware.c
15655index d22d0c4..088eb6f 100644
15656--- a/arch/x86/kernel/cpu/vmware.c
15657+++ b/arch/x86/kernel/cpu/vmware.c
15658@@ -79,7 +79,7 @@ static void __init vmware_platform_setup(void)
15659 VMWARE_PORT(GETHZ, eax, ebx, ecx, edx);
15660
15661 if (ebx != UINT_MAX)
15662- x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15663+ *(void **)&x86_platform.calibrate_tsc = vmware_get_tsc_khz;
15664 else
15665 printk(KERN_WARNING
15666 "Failed to get TSC freq from the hypervisor\n");
15667diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
15668index 13ad899..f642b9a 100644
15669--- a/arch/x86/kernel/crash.c
15670+++ b/arch/x86/kernel/crash.c
15671@@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
15672 {
15673 #ifdef CONFIG_X86_32
15674 struct pt_regs fixed_regs;
15675-#endif
15676
15677-#ifdef CONFIG_X86_32
15678- if (!user_mode_vm(regs)) {
15679+ if (!user_mode(regs)) {
15680 crash_fixup_ss_esp(&fixed_regs, regs);
15681 regs = &fixed_regs;
15682 }
15683diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
15684index 37250fe..bf2ec74 100644
15685--- a/arch/x86/kernel/doublefault_32.c
15686+++ b/arch/x86/kernel/doublefault_32.c
15687@@ -11,7 +11,7 @@
15688
15689 #define DOUBLEFAULT_STACKSIZE (1024)
15690 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
15691-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
15692+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
15693
15694 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
15695
15696@@ -21,7 +21,7 @@ static void doublefault_fn(void)
15697 unsigned long gdt, tss;
15698
15699 store_gdt(&gdt_desc);
15700- gdt = gdt_desc.address;
15701+ gdt = (unsigned long)gdt_desc.address;
15702
15703 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
15704
15705@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
15706 /* 0x2 bit is always set */
15707 .flags = X86_EFLAGS_SF | 0x2,
15708 .sp = STACK_START,
15709- .es = __USER_DS,
15710+ .es = __KERNEL_DS,
15711 .cs = __KERNEL_CS,
15712 .ss = __KERNEL_DS,
15713- .ds = __USER_DS,
15714+ .ds = __KERNEL_DS,
15715 .fs = __KERNEL_PERCPU,
15716
15717 .__cr3 = __pa_nodebug(swapper_pg_dir),
15718diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
15719index ae42418b..787c16b 100644
15720--- a/arch/x86/kernel/dumpstack.c
15721+++ b/arch/x86/kernel/dumpstack.c
15722@@ -2,6 +2,9 @@
15723 * Copyright (C) 1991, 1992 Linus Torvalds
15724 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
15725 */
15726+#ifdef CONFIG_GRKERNSEC_HIDESYM
15727+#define __INCLUDED_BY_HIDESYM 1
15728+#endif
15729 #include <linux/kallsyms.h>
15730 #include <linux/kprobes.h>
15731 #include <linux/uaccess.h>
15732@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
15733 static void
15734 print_ftrace_graph_addr(unsigned long addr, void *data,
15735 const struct stacktrace_ops *ops,
15736- struct thread_info *tinfo, int *graph)
15737+ struct task_struct *task, int *graph)
15738 {
15739- struct task_struct *task;
15740 unsigned long ret_addr;
15741 int index;
15742
15743 if (addr != (unsigned long)return_to_handler)
15744 return;
15745
15746- task = tinfo->task;
15747 index = task->curr_ret_stack;
15748
15749 if (!task->ret_stack || index < *graph)
15750@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15751 static inline void
15752 print_ftrace_graph_addr(unsigned long addr, void *data,
15753 const struct stacktrace_ops *ops,
15754- struct thread_info *tinfo, int *graph)
15755+ struct task_struct *task, int *graph)
15756 { }
15757 #endif
15758
15759@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
15760 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
15761 */
15762
15763-static inline int valid_stack_ptr(struct thread_info *tinfo,
15764- void *p, unsigned int size, void *end)
15765+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
15766 {
15767- void *t = tinfo;
15768 if (end) {
15769 if (p < end && p >= (end-THREAD_SIZE))
15770 return 1;
15771@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
15772 }
15773
15774 unsigned long
15775-print_context_stack(struct thread_info *tinfo,
15776+print_context_stack(struct task_struct *task, void *stack_start,
15777 unsigned long *stack, unsigned long bp,
15778 const struct stacktrace_ops *ops, void *data,
15779 unsigned long *end, int *graph)
15780 {
15781 struct stack_frame *frame = (struct stack_frame *)bp;
15782
15783- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
15784+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
15785 unsigned long addr;
15786
15787 addr = *stack;
15788@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
15789 } else {
15790 ops->address(data, addr, 0);
15791 }
15792- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15793+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15794 }
15795 stack++;
15796 }
15797@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
15798 EXPORT_SYMBOL_GPL(print_context_stack);
15799
15800 unsigned long
15801-print_context_stack_bp(struct thread_info *tinfo,
15802+print_context_stack_bp(struct task_struct *task, void *stack_start,
15803 unsigned long *stack, unsigned long bp,
15804 const struct stacktrace_ops *ops, void *data,
15805 unsigned long *end, int *graph)
15806@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15807 struct stack_frame *frame = (struct stack_frame *)bp;
15808 unsigned long *ret_addr = &frame->return_address;
15809
15810- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
15811+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
15812 unsigned long addr = *ret_addr;
15813
15814 if (!__kernel_text_address(addr))
15815@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
15816 ops->address(data, addr, 1);
15817 frame = frame->next_frame;
15818 ret_addr = &frame->return_address;
15819- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
15820+ print_ftrace_graph_addr(addr, data, ops, task, graph);
15821 }
15822
15823 return (unsigned long)frame;
15824@@ -189,7 +188,7 @@ void dump_stack(void)
15825
15826 bp = stack_frame(current, NULL);
15827 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
15828- current->pid, current->comm, print_tainted(),
15829+ task_pid_nr(current), current->comm, print_tainted(),
15830 init_utsname()->release,
15831 (int)strcspn(init_utsname()->version, " "),
15832 init_utsname()->version);
15833@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
15834 }
15835 EXPORT_SYMBOL_GPL(oops_begin);
15836
15837+extern void gr_handle_kernel_exploit(void);
15838+
15839 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15840 {
15841 if (regs && kexec_should_crash(current))
15842@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
15843 panic("Fatal exception in interrupt");
15844 if (panic_on_oops)
15845 panic("Fatal exception");
15846- do_exit(signr);
15847+
15848+ gr_handle_kernel_exploit();
15849+
15850+ do_group_exit(signr);
15851 }
15852
15853 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15854@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
15855 print_modules();
15856 show_regs(regs);
15857 #ifdef CONFIG_X86_32
15858- if (user_mode_vm(regs)) {
15859+ if (user_mode(regs)) {
15860 sp = regs->sp;
15861 ss = regs->ss & 0xffff;
15862 } else {
15863@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
15864 unsigned long flags = oops_begin();
15865 int sig = SIGSEGV;
15866
15867- if (!user_mode_vm(regs))
15868+ if (!user_mode(regs))
15869 report_bug(regs->ip, regs);
15870
15871 if (__die(str, regs, err))
15872diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
15873index 1038a41..db2c12b 100644
15874--- a/arch/x86/kernel/dumpstack_32.c
15875+++ b/arch/x86/kernel/dumpstack_32.c
15876@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15877 bp = stack_frame(task, regs);
15878
15879 for (;;) {
15880- struct thread_info *context;
15881+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
15882
15883- context = (struct thread_info *)
15884- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
15885- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
15886+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
15887
15888- stack = (unsigned long *)context->previous_esp;
15889- if (!stack)
15890+ if (stack_start == task_stack_page(task))
15891 break;
15892+ stack = *(unsigned long **)stack_start;
15893 if (ops->stack(data, "IRQ") < 0)
15894 break;
15895 touch_nmi_watchdog();
15896@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
15897 {
15898 int i;
15899
15900- __show_regs(regs, !user_mode_vm(regs));
15901+ __show_regs(regs, !user_mode(regs));
15902
15903 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
15904 TASK_COMM_LEN, current->comm, task_pid_nr(current),
15905@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
15906 * When in-kernel, we also print out the stack and code at the
15907 * time of the fault..
15908 */
15909- if (!user_mode_vm(regs)) {
15910+ if (!user_mode(regs)) {
15911 unsigned int code_prologue = code_bytes * 43 / 64;
15912 unsigned int code_len = code_bytes;
15913 unsigned char c;
15914 u8 *ip;
15915+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
15916
15917 pr_emerg("Stack:\n");
15918 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
15919
15920 pr_emerg("Code:");
15921
15922- ip = (u8 *)regs->ip - code_prologue;
15923+ ip = (u8 *)regs->ip - code_prologue + cs_base;
15924 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
15925 /* try starting at IP */
15926- ip = (u8 *)regs->ip;
15927+ ip = (u8 *)regs->ip + cs_base;
15928 code_len = code_len - code_prologue + 1;
15929 }
15930 for (i = 0; i < code_len; i++, ip++) {
15931@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
15932 pr_cont(" Bad EIP value.");
15933 break;
15934 }
15935- if (ip == (u8 *)regs->ip)
15936+ if (ip == (u8 *)regs->ip + cs_base)
15937 pr_cont(" <%02x>", c);
15938 else
15939 pr_cont(" %02x", c);
15940@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
15941 {
15942 unsigned short ud2;
15943
15944+ ip = ktla_ktva(ip);
15945 if (ip < PAGE_OFFSET)
15946 return 0;
15947 if (probe_kernel_address((unsigned short *)ip, ud2))
15948@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
15949
15950 return ud2 == 0x0b0f;
15951 }
15952+
15953+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15954+void pax_check_alloca(unsigned long size)
15955+{
15956+ unsigned long sp = (unsigned long)&sp, stack_left;
15957+
15958+ /* all kernel stacks are of the same size */
15959+ stack_left = sp & (THREAD_SIZE - 1);
15960+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
15961+}
15962+EXPORT_SYMBOL(pax_check_alloca);
15963+#endif
15964diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
15965index b653675..51cc8c0 100644
15966--- a/arch/x86/kernel/dumpstack_64.c
15967+++ b/arch/x86/kernel/dumpstack_64.c
15968@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15969 unsigned long *irq_stack_end =
15970 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
15971 unsigned used = 0;
15972- struct thread_info *tinfo;
15973 int graph = 0;
15974 unsigned long dummy;
15975+ void *stack_start;
15976
15977 if (!task)
15978 task = current;
15979@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15980 * current stack address. If the stacks consist of nested
15981 * exceptions
15982 */
15983- tinfo = task_thread_info(task);
15984 for (;;) {
15985 char *id;
15986 unsigned long *estack_end;
15987+
15988 estack_end = in_exception_stack(cpu, (unsigned long)stack,
15989 &used, &id);
15990
15991@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
15992 if (ops->stack(data, id) < 0)
15993 break;
15994
15995- bp = ops->walk_stack(tinfo, stack, bp, ops,
15996+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
15997 data, estack_end, &graph);
15998 ops->stack(data, "<EOE>");
15999 /*
16000@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16001 * second-to-last pointer (index -2 to end) in the
16002 * exception stack:
16003 */
16004+ if ((u16)estack_end[-1] != __KERNEL_DS)
16005+ goto out;
16006 stack = (unsigned long *) estack_end[-2];
16007 continue;
16008 }
16009@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16010 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
16011 if (ops->stack(data, "IRQ") < 0)
16012 break;
16013- bp = ops->walk_stack(tinfo, stack, bp,
16014+ bp = ops->walk_stack(task, irq_stack, stack, bp,
16015 ops, data, irq_stack_end, &graph);
16016 /*
16017 * We link to the next stack (which would be
16018@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
16019 /*
16020 * This handles the process stack:
16021 */
16022- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
16023+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
16024+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
16025+out:
16026 put_cpu();
16027 }
16028 EXPORT_SYMBOL(dump_trace);
16029@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
16030 {
16031 int i;
16032 unsigned long sp;
16033- const int cpu = smp_processor_id();
16034+ const int cpu = raw_smp_processor_id();
16035 struct task_struct *cur = current;
16036
16037 sp = regs->sp;
16038@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
16039
16040 return ud2 == 0x0b0f;
16041 }
16042+
16043+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16044+void pax_check_alloca(unsigned long size)
16045+{
16046+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
16047+ unsigned cpu, used;
16048+ char *id;
16049+
16050+ /* check the process stack first */
16051+ stack_start = (unsigned long)task_stack_page(current);
16052+ stack_end = stack_start + THREAD_SIZE;
16053+ if (likely(stack_start <= sp && sp < stack_end)) {
16054+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
16055+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16056+ return;
16057+ }
16058+
16059+ cpu = get_cpu();
16060+
16061+ /* check the irq stacks */
16062+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
16063+ stack_start = stack_end - IRQ_STACK_SIZE;
16064+ if (stack_start <= sp && sp < stack_end) {
16065+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
16066+ put_cpu();
16067+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16068+ return;
16069+ }
16070+
16071+ /* check the exception stacks */
16072+ used = 0;
16073+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
16074+ stack_start = stack_end - EXCEPTION_STKSZ;
16075+ if (stack_end && stack_start <= sp && sp < stack_end) {
16076+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
16077+ put_cpu();
16078+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
16079+ return;
16080+ }
16081+
16082+ put_cpu();
16083+
16084+ /* unknown stack */
16085+ BUG();
16086+}
16087+EXPORT_SYMBOL(pax_check_alloca);
16088+#endif
16089diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
16090index 9b9f18b..9fcaa04 100644
16091--- a/arch/x86/kernel/early_printk.c
16092+++ b/arch/x86/kernel/early_printk.c
16093@@ -7,6 +7,7 @@
16094 #include <linux/pci_regs.h>
16095 #include <linux/pci_ids.h>
16096 #include <linux/errno.h>
16097+#include <linux/sched.h>
16098 #include <asm/io.h>
16099 #include <asm/processor.h>
16100 #include <asm/fcntl.h>
16101diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
16102index cf8639b..98fcee6 100644
16103--- a/arch/x86/kernel/entry_32.S
16104+++ b/arch/x86/kernel/entry_32.S
16105@@ -177,13 +177,153 @@
16106 /*CFI_REL_OFFSET gs, PT_GS*/
16107 .endm
16108 .macro SET_KERNEL_GS reg
16109+
16110+#ifdef CONFIG_CC_STACKPROTECTOR
16111 movl $(__KERNEL_STACK_CANARY), \reg
16112+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
16113+ movl $(__USER_DS), \reg
16114+#else
16115+ xorl \reg, \reg
16116+#endif
16117+
16118 movl \reg, %gs
16119 .endm
16120
16121 #endif /* CONFIG_X86_32_LAZY_GS */
16122
16123-.macro SAVE_ALL
16124+.macro pax_enter_kernel
16125+#ifdef CONFIG_PAX_KERNEXEC
16126+ call pax_enter_kernel
16127+#endif
16128+.endm
16129+
16130+.macro pax_exit_kernel
16131+#ifdef CONFIG_PAX_KERNEXEC
16132+ call pax_exit_kernel
16133+#endif
16134+.endm
16135+
16136+#ifdef CONFIG_PAX_KERNEXEC
16137+ENTRY(pax_enter_kernel)
16138+#ifdef CONFIG_PARAVIRT
16139+ pushl %eax
16140+ pushl %ecx
16141+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
16142+ mov %eax, %esi
16143+#else
16144+ mov %cr0, %esi
16145+#endif
16146+ bts $16, %esi
16147+ jnc 1f
16148+ mov %cs, %esi
16149+ cmp $__KERNEL_CS, %esi
16150+ jz 3f
16151+ ljmp $__KERNEL_CS, $3f
16152+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
16153+2:
16154+#ifdef CONFIG_PARAVIRT
16155+ mov %esi, %eax
16156+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16157+#else
16158+ mov %esi, %cr0
16159+#endif
16160+3:
16161+#ifdef CONFIG_PARAVIRT
16162+ popl %ecx
16163+ popl %eax
16164+#endif
16165+ ret
16166+ENDPROC(pax_enter_kernel)
16167+
16168+ENTRY(pax_exit_kernel)
16169+#ifdef CONFIG_PARAVIRT
16170+ pushl %eax
16171+ pushl %ecx
16172+#endif
16173+ mov %cs, %esi
16174+ cmp $__KERNEXEC_KERNEL_CS, %esi
16175+ jnz 2f
16176+#ifdef CONFIG_PARAVIRT
16177+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
16178+ mov %eax, %esi
16179+#else
16180+ mov %cr0, %esi
16181+#endif
16182+ btr $16, %esi
16183+ ljmp $__KERNEL_CS, $1f
16184+1:
16185+#ifdef CONFIG_PARAVIRT
16186+ mov %esi, %eax
16187+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
16188+#else
16189+ mov %esi, %cr0
16190+#endif
16191+2:
16192+#ifdef CONFIG_PARAVIRT
16193+ popl %ecx
16194+ popl %eax
16195+#endif
16196+ ret
16197+ENDPROC(pax_exit_kernel)
16198+#endif
16199+
16200+.macro pax_erase_kstack
16201+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16202+ call pax_erase_kstack
16203+#endif
16204+.endm
16205+
16206+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16207+/*
16208+ * ebp: thread_info
16209+ */
16210+ENTRY(pax_erase_kstack)
16211+ pushl %edi
16212+ pushl %ecx
16213+ pushl %eax
16214+
16215+ mov TI_lowest_stack(%ebp), %edi
16216+ mov $-0xBEEF, %eax
16217+ std
16218+
16219+1: mov %edi, %ecx
16220+ and $THREAD_SIZE_asm - 1, %ecx
16221+ shr $2, %ecx
16222+ repne scasl
16223+ jecxz 2f
16224+
16225+ cmp $2*16, %ecx
16226+ jc 2f
16227+
16228+ mov $2*16, %ecx
16229+ repe scasl
16230+ jecxz 2f
16231+ jne 1b
16232+
16233+2: cld
16234+ mov %esp, %ecx
16235+ sub %edi, %ecx
16236+
16237+ cmp $THREAD_SIZE_asm, %ecx
16238+ jb 3f
16239+ ud2
16240+3:
16241+
16242+ shr $2, %ecx
16243+ rep stosl
16244+
16245+ mov TI_task_thread_sp0(%ebp), %edi
16246+ sub $128, %edi
16247+ mov %edi, TI_lowest_stack(%ebp)
16248+
16249+ popl %eax
16250+ popl %ecx
16251+ popl %edi
16252+ ret
16253+ENDPROC(pax_erase_kstack)
16254+#endif
16255+
16256+.macro __SAVE_ALL _DS
16257 cld
16258 PUSH_GS
16259 pushl_cfi %fs
16260@@ -206,7 +346,7 @@
16261 CFI_REL_OFFSET ecx, 0
16262 pushl_cfi %ebx
16263 CFI_REL_OFFSET ebx, 0
16264- movl $(__USER_DS), %edx
16265+ movl $\_DS, %edx
16266 movl %edx, %ds
16267 movl %edx, %es
16268 movl $(__KERNEL_PERCPU), %edx
16269@@ -214,6 +354,15 @@
16270 SET_KERNEL_GS %edx
16271 .endm
16272
16273+.macro SAVE_ALL
16274+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
16275+ __SAVE_ALL __KERNEL_DS
16276+ pax_enter_kernel
16277+#else
16278+ __SAVE_ALL __USER_DS
16279+#endif
16280+.endm
16281+
16282 .macro RESTORE_INT_REGS
16283 popl_cfi %ebx
16284 CFI_RESTORE ebx
16285@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
16286 popfl_cfi
16287 jmp syscall_exit
16288 CFI_ENDPROC
16289-END(ret_from_fork)
16290+ENDPROC(ret_from_fork)
16291
16292 ENTRY(ret_from_kernel_thread)
16293 CFI_STARTPROC
16294@@ -344,7 +493,15 @@ ret_from_intr:
16295 andl $SEGMENT_RPL_MASK, %eax
16296 #endif
16297 cmpl $USER_RPL, %eax
16298+
16299+#ifdef CONFIG_PAX_KERNEXEC
16300+ jae resume_userspace
16301+
16302+ pax_exit_kernel
16303+ jmp resume_kernel
16304+#else
16305 jb resume_kernel # not returning to v8086 or userspace
16306+#endif
16307
16308 ENTRY(resume_userspace)
16309 LOCKDEP_SYS_EXIT
16310@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
16311 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
16312 # int/exception return?
16313 jne work_pending
16314- jmp restore_all
16315-END(ret_from_exception)
16316+ jmp restore_all_pax
16317+ENDPROC(ret_from_exception)
16318
16319 #ifdef CONFIG_PREEMPT
16320 ENTRY(resume_kernel)
16321@@ -372,7 +529,7 @@ need_resched:
16322 jz restore_all
16323 call preempt_schedule_irq
16324 jmp need_resched
16325-END(resume_kernel)
16326+ENDPROC(resume_kernel)
16327 #endif
16328 CFI_ENDPROC
16329 /*
16330@@ -406,30 +563,45 @@ sysenter_past_esp:
16331 /*CFI_REL_OFFSET cs, 0*/
16332 /*
16333 * Push current_thread_info()->sysenter_return to the stack.
16334- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
16335- * pushed above; +8 corresponds to copy_thread's esp0 setting.
16336 */
16337- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
16338+ pushl_cfi $0
16339 CFI_REL_OFFSET eip, 0
16340
16341 pushl_cfi %eax
16342 SAVE_ALL
16343+ GET_THREAD_INFO(%ebp)
16344+ movl TI_sysenter_return(%ebp),%ebp
16345+ movl %ebp,PT_EIP(%esp)
16346 ENABLE_INTERRUPTS(CLBR_NONE)
16347
16348 /*
16349 * Load the potential sixth argument from user stack.
16350 * Careful about security.
16351 */
16352+ movl PT_OLDESP(%esp),%ebp
16353+
16354+#ifdef CONFIG_PAX_MEMORY_UDEREF
16355+ mov PT_OLDSS(%esp),%ds
16356+1: movl %ds:(%ebp),%ebp
16357+ push %ss
16358+ pop %ds
16359+#else
16360 cmpl $__PAGE_OFFSET-3,%ebp
16361 jae syscall_fault
16362 ASM_STAC
16363 1: movl (%ebp),%ebp
16364 ASM_CLAC
16365+#endif
16366+
16367 movl %ebp,PT_EBP(%esp)
16368 _ASM_EXTABLE(1b,syscall_fault)
16369
16370 GET_THREAD_INFO(%ebp)
16371
16372+#ifdef CONFIG_PAX_RANDKSTACK
16373+ pax_erase_kstack
16374+#endif
16375+
16376 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16377 jnz sysenter_audit
16378 sysenter_do_call:
16379@@ -444,12 +616,24 @@ sysenter_do_call:
16380 testl $_TIF_ALLWORK_MASK, %ecx
16381 jne sysexit_audit
16382 sysenter_exit:
16383+
16384+#ifdef CONFIG_PAX_RANDKSTACK
16385+ pushl_cfi %eax
16386+ movl %esp, %eax
16387+ call pax_randomize_kstack
16388+ popl_cfi %eax
16389+#endif
16390+
16391+ pax_erase_kstack
16392+
16393 /* if something modifies registers it must also disable sysexit */
16394 movl PT_EIP(%esp), %edx
16395 movl PT_OLDESP(%esp), %ecx
16396 xorl %ebp,%ebp
16397 TRACE_IRQS_ON
16398 1: mov PT_FS(%esp), %fs
16399+2: mov PT_DS(%esp), %ds
16400+3: mov PT_ES(%esp), %es
16401 PTGS_TO_GS
16402 ENABLE_INTERRUPTS_SYSEXIT
16403
16404@@ -466,6 +650,9 @@ sysenter_audit:
16405 movl %eax,%edx /* 2nd arg: syscall number */
16406 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
16407 call __audit_syscall_entry
16408+
16409+ pax_erase_kstack
16410+
16411 pushl_cfi %ebx
16412 movl PT_EAX(%esp),%eax /* reload syscall number */
16413 jmp sysenter_do_call
16414@@ -491,10 +678,16 @@ sysexit_audit:
16415
16416 CFI_ENDPROC
16417 .pushsection .fixup,"ax"
16418-2: movl $0,PT_FS(%esp)
16419+4: movl $0,PT_FS(%esp)
16420+ jmp 1b
16421+5: movl $0,PT_DS(%esp)
16422+ jmp 1b
16423+6: movl $0,PT_ES(%esp)
16424 jmp 1b
16425 .popsection
16426- _ASM_EXTABLE(1b,2b)
16427+ _ASM_EXTABLE(1b,4b)
16428+ _ASM_EXTABLE(2b,5b)
16429+ _ASM_EXTABLE(3b,6b)
16430 PTGS_TO_GS_EX
16431 ENDPROC(ia32_sysenter_target)
16432
16433@@ -509,6 +702,11 @@ ENTRY(system_call)
16434 pushl_cfi %eax # save orig_eax
16435 SAVE_ALL
16436 GET_THREAD_INFO(%ebp)
16437+
16438+#ifdef CONFIG_PAX_RANDKSTACK
16439+ pax_erase_kstack
16440+#endif
16441+
16442 # system call tracing in operation / emulation
16443 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
16444 jnz syscall_trace_entry
16445@@ -527,6 +725,15 @@ syscall_exit:
16446 testl $_TIF_ALLWORK_MASK, %ecx # current->work
16447 jne syscall_exit_work
16448
16449+restore_all_pax:
16450+
16451+#ifdef CONFIG_PAX_RANDKSTACK
16452+ movl %esp, %eax
16453+ call pax_randomize_kstack
16454+#endif
16455+
16456+ pax_erase_kstack
16457+
16458 restore_all:
16459 TRACE_IRQS_IRET
16460 restore_all_notrace:
16461@@ -583,14 +790,34 @@ ldt_ss:
16462 * compensating for the offset by changing to the ESPFIX segment with
16463 * a base address that matches for the difference.
16464 */
16465-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
16466+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
16467 mov %esp, %edx /* load kernel esp */
16468 mov PT_OLDESP(%esp), %eax /* load userspace esp */
16469 mov %dx, %ax /* eax: new kernel esp */
16470 sub %eax, %edx /* offset (low word is 0) */
16471+#ifdef CONFIG_SMP
16472+ movl PER_CPU_VAR(cpu_number), %ebx
16473+ shll $PAGE_SHIFT_asm, %ebx
16474+ addl $cpu_gdt_table, %ebx
16475+#else
16476+ movl $cpu_gdt_table, %ebx
16477+#endif
16478 shr $16, %edx
16479- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
16480- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
16481+
16482+#ifdef CONFIG_PAX_KERNEXEC
16483+ mov %cr0, %esi
16484+ btr $16, %esi
16485+ mov %esi, %cr0
16486+#endif
16487+
16488+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
16489+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
16490+
16491+#ifdef CONFIG_PAX_KERNEXEC
16492+ bts $16, %esi
16493+ mov %esi, %cr0
16494+#endif
16495+
16496 pushl_cfi $__ESPFIX_SS
16497 pushl_cfi %eax /* new kernel esp */
16498 /* Disable interrupts, but do not irqtrace this section: we
16499@@ -619,20 +846,18 @@ work_resched:
16500 movl TI_flags(%ebp), %ecx
16501 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
16502 # than syscall tracing?
16503- jz restore_all
16504+ jz restore_all_pax
16505 testb $_TIF_NEED_RESCHED, %cl
16506 jnz work_resched
16507
16508 work_notifysig: # deal with pending signals and
16509 # notify-resume requests
16510+ movl %esp, %eax
16511 #ifdef CONFIG_VM86
16512 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
16513- movl %esp, %eax
16514 jne work_notifysig_v86 # returning to kernel-space or
16515 # vm86-space
16516 1:
16517-#else
16518- movl %esp, %eax
16519 #endif
16520 TRACE_IRQS_ON
16521 ENABLE_INTERRUPTS(CLBR_NONE)
16522@@ -653,7 +878,7 @@ work_notifysig_v86:
16523 movl %eax, %esp
16524 jmp 1b
16525 #endif
16526-END(work_pending)
16527+ENDPROC(work_pending)
16528
16529 # perform syscall exit tracing
16530 ALIGN
16531@@ -661,11 +886,14 @@ syscall_trace_entry:
16532 movl $-ENOSYS,PT_EAX(%esp)
16533 movl %esp, %eax
16534 call syscall_trace_enter
16535+
16536+ pax_erase_kstack
16537+
16538 /* What it returned is what we'll actually use. */
16539 cmpl $(NR_syscalls), %eax
16540 jnae syscall_call
16541 jmp syscall_exit
16542-END(syscall_trace_entry)
16543+ENDPROC(syscall_trace_entry)
16544
16545 # perform syscall exit tracing
16546 ALIGN
16547@@ -678,21 +906,25 @@ syscall_exit_work:
16548 movl %esp, %eax
16549 call syscall_trace_leave
16550 jmp resume_userspace
16551-END(syscall_exit_work)
16552+ENDPROC(syscall_exit_work)
16553 CFI_ENDPROC
16554
16555 RING0_INT_FRAME # can't unwind into user space anyway
16556 syscall_fault:
16557+#ifdef CONFIG_PAX_MEMORY_UDEREF
16558+ push %ss
16559+ pop %ds
16560+#endif
16561 ASM_CLAC
16562 GET_THREAD_INFO(%ebp)
16563 movl $-EFAULT,PT_EAX(%esp)
16564 jmp resume_userspace
16565-END(syscall_fault)
16566+ENDPROC(syscall_fault)
16567
16568 syscall_badsys:
16569 movl $-ENOSYS,PT_EAX(%esp)
16570 jmp resume_userspace
16571-END(syscall_badsys)
16572+ENDPROC(syscall_badsys)
16573 CFI_ENDPROC
16574 /*
16575 * End of kprobes section
16576@@ -763,6 +995,36 @@ ENTRY(ptregs_clone)
16577 CFI_ENDPROC
16578 ENDPROC(ptregs_clone)
16579
16580+ ALIGN;
16581+ENTRY(kernel_execve)
16582+ CFI_STARTPROC
16583+ pushl_cfi %ebp
16584+ sub $PT_OLDSS+4,%esp
16585+ pushl_cfi %edi
16586+ pushl_cfi %ecx
16587+ pushl_cfi %eax
16588+ lea 3*4(%esp),%edi
16589+ mov $PT_OLDSS/4+1,%ecx
16590+ xorl %eax,%eax
16591+ rep stosl
16592+ popl_cfi %eax
16593+ popl_cfi %ecx
16594+ popl_cfi %edi
16595+ movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
16596+ pushl_cfi %esp
16597+ call sys_execve
16598+ add $4,%esp
16599+ CFI_ADJUST_CFA_OFFSET -4
16600+ GET_THREAD_INFO(%ebp)
16601+ test %eax,%eax
16602+ jz syscall_exit
16603+ add $PT_OLDSS+4,%esp
16604+ CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
16605+ popl_cfi %ebp
16606+ ret
16607+ CFI_ENDPROC
16608+ENDPROC(kernel_execve)
16609+
16610 .macro FIXUP_ESPFIX_STACK
16611 /*
16612 * Switch back for ESPFIX stack to the normal zerobased stack
16613@@ -772,8 +1034,15 @@ ENDPROC(ptregs_clone)
16614 * normal stack and adjusts ESP with the matching offset.
16615 */
16616 /* fixup the stack */
16617- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
16618- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
16619+#ifdef CONFIG_SMP
16620+ movl PER_CPU_VAR(cpu_number), %ebx
16621+ shll $PAGE_SHIFT_asm, %ebx
16622+ addl $cpu_gdt_table, %ebx
16623+#else
16624+ movl $cpu_gdt_table, %ebx
16625+#endif
16626+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
16627+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
16628 shl $16, %eax
16629 addl %esp, %eax /* the adjusted stack pointer */
16630 pushl_cfi $__KERNEL_DS
16631@@ -826,7 +1095,7 @@ vector=vector+1
16632 .endr
16633 2: jmp common_interrupt
16634 .endr
16635-END(irq_entries_start)
16636+ENDPROC(irq_entries_start)
16637
16638 .previous
16639 END(interrupt)
16640@@ -877,7 +1146,7 @@ ENTRY(coprocessor_error)
16641 pushl_cfi $do_coprocessor_error
16642 jmp error_code
16643 CFI_ENDPROC
16644-END(coprocessor_error)
16645+ENDPROC(coprocessor_error)
16646
16647 ENTRY(simd_coprocessor_error)
16648 RING0_INT_FRAME
16649@@ -899,7 +1168,7 @@ ENTRY(simd_coprocessor_error)
16650 #endif
16651 jmp error_code
16652 CFI_ENDPROC
16653-END(simd_coprocessor_error)
16654+ENDPROC(simd_coprocessor_error)
16655
16656 ENTRY(device_not_available)
16657 RING0_INT_FRAME
16658@@ -908,18 +1177,18 @@ ENTRY(device_not_available)
16659 pushl_cfi $do_device_not_available
16660 jmp error_code
16661 CFI_ENDPROC
16662-END(device_not_available)
16663+ENDPROC(device_not_available)
16664
16665 #ifdef CONFIG_PARAVIRT
16666 ENTRY(native_iret)
16667 iret
16668 _ASM_EXTABLE(native_iret, iret_exc)
16669-END(native_iret)
16670+ENDPROC(native_iret)
16671
16672 ENTRY(native_irq_enable_sysexit)
16673 sti
16674 sysexit
16675-END(native_irq_enable_sysexit)
16676+ENDPROC(native_irq_enable_sysexit)
16677 #endif
16678
16679 ENTRY(overflow)
16680@@ -929,7 +1198,7 @@ ENTRY(overflow)
16681 pushl_cfi $do_overflow
16682 jmp error_code
16683 CFI_ENDPROC
16684-END(overflow)
16685+ENDPROC(overflow)
16686
16687 ENTRY(bounds)
16688 RING0_INT_FRAME
16689@@ -938,7 +1207,7 @@ ENTRY(bounds)
16690 pushl_cfi $do_bounds
16691 jmp error_code
16692 CFI_ENDPROC
16693-END(bounds)
16694+ENDPROC(bounds)
16695
16696 ENTRY(invalid_op)
16697 RING0_INT_FRAME
16698@@ -947,7 +1216,7 @@ ENTRY(invalid_op)
16699 pushl_cfi $do_invalid_op
16700 jmp error_code
16701 CFI_ENDPROC
16702-END(invalid_op)
16703+ENDPROC(invalid_op)
16704
16705 ENTRY(coprocessor_segment_overrun)
16706 RING0_INT_FRAME
16707@@ -956,7 +1225,7 @@ ENTRY(coprocessor_segment_overrun)
16708 pushl_cfi $do_coprocessor_segment_overrun
16709 jmp error_code
16710 CFI_ENDPROC
16711-END(coprocessor_segment_overrun)
16712+ENDPROC(coprocessor_segment_overrun)
16713
16714 ENTRY(invalid_TSS)
16715 RING0_EC_FRAME
16716@@ -964,7 +1233,7 @@ ENTRY(invalid_TSS)
16717 pushl_cfi $do_invalid_TSS
16718 jmp error_code
16719 CFI_ENDPROC
16720-END(invalid_TSS)
16721+ENDPROC(invalid_TSS)
16722
16723 ENTRY(segment_not_present)
16724 RING0_EC_FRAME
16725@@ -972,7 +1241,7 @@ ENTRY(segment_not_present)
16726 pushl_cfi $do_segment_not_present
16727 jmp error_code
16728 CFI_ENDPROC
16729-END(segment_not_present)
16730+ENDPROC(segment_not_present)
16731
16732 ENTRY(stack_segment)
16733 RING0_EC_FRAME
16734@@ -980,7 +1249,7 @@ ENTRY(stack_segment)
16735 pushl_cfi $do_stack_segment
16736 jmp error_code
16737 CFI_ENDPROC
16738-END(stack_segment)
16739+ENDPROC(stack_segment)
16740
16741 ENTRY(alignment_check)
16742 RING0_EC_FRAME
16743@@ -988,7 +1257,7 @@ ENTRY(alignment_check)
16744 pushl_cfi $do_alignment_check
16745 jmp error_code
16746 CFI_ENDPROC
16747-END(alignment_check)
16748+ENDPROC(alignment_check)
16749
16750 ENTRY(divide_error)
16751 RING0_INT_FRAME
16752@@ -997,7 +1266,7 @@ ENTRY(divide_error)
16753 pushl_cfi $do_divide_error
16754 jmp error_code
16755 CFI_ENDPROC
16756-END(divide_error)
16757+ENDPROC(divide_error)
16758
16759 #ifdef CONFIG_X86_MCE
16760 ENTRY(machine_check)
16761@@ -1007,7 +1276,7 @@ ENTRY(machine_check)
16762 pushl_cfi machine_check_vector
16763 jmp error_code
16764 CFI_ENDPROC
16765-END(machine_check)
16766+ENDPROC(machine_check)
16767 #endif
16768
16769 ENTRY(spurious_interrupt_bug)
16770@@ -1017,7 +1286,7 @@ ENTRY(spurious_interrupt_bug)
16771 pushl_cfi $do_spurious_interrupt_bug
16772 jmp error_code
16773 CFI_ENDPROC
16774-END(spurious_interrupt_bug)
16775+ENDPROC(spurious_interrupt_bug)
16776 /*
16777 * End of kprobes section
16778 */
16779@@ -1120,7 +1389,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
16780
16781 ENTRY(mcount)
16782 ret
16783-END(mcount)
16784+ENDPROC(mcount)
16785
16786 ENTRY(ftrace_caller)
16787 cmpl $0, function_trace_stop
16788@@ -1153,7 +1422,7 @@ ftrace_graph_call:
16789 .globl ftrace_stub
16790 ftrace_stub:
16791 ret
16792-END(ftrace_caller)
16793+ENDPROC(ftrace_caller)
16794
16795 ENTRY(ftrace_regs_caller)
16796 pushf /* push flags before compare (in cs location) */
16797@@ -1254,7 +1523,7 @@ trace:
16798 popl %ecx
16799 popl %eax
16800 jmp ftrace_stub
16801-END(mcount)
16802+ENDPROC(mcount)
16803 #endif /* CONFIG_DYNAMIC_FTRACE */
16804 #endif /* CONFIG_FUNCTION_TRACER */
16805
16806@@ -1272,7 +1541,7 @@ ENTRY(ftrace_graph_caller)
16807 popl %ecx
16808 popl %eax
16809 ret
16810-END(ftrace_graph_caller)
16811+ENDPROC(ftrace_graph_caller)
16812
16813 .globl return_to_handler
16814 return_to_handler:
16815@@ -1328,15 +1597,18 @@ error_code:
16816 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
16817 REG_TO_PTGS %ecx
16818 SET_KERNEL_GS %ecx
16819- movl $(__USER_DS), %ecx
16820+ movl $(__KERNEL_DS), %ecx
16821 movl %ecx, %ds
16822 movl %ecx, %es
16823+
16824+ pax_enter_kernel
16825+
16826 TRACE_IRQS_OFF
16827 movl %esp,%eax # pt_regs pointer
16828 call *%edi
16829 jmp ret_from_exception
16830 CFI_ENDPROC
16831-END(page_fault)
16832+ENDPROC(page_fault)
16833
16834 /*
16835 * Debug traps and NMI can happen at the one SYSENTER instruction
16836@@ -1379,7 +1651,7 @@ debug_stack_correct:
16837 call do_debug
16838 jmp ret_from_exception
16839 CFI_ENDPROC
16840-END(debug)
16841+ENDPROC(debug)
16842
16843 /*
16844 * NMI is doubly nasty. It can happen _while_ we're handling
16845@@ -1417,6 +1689,9 @@ nmi_stack_correct:
16846 xorl %edx,%edx # zero error code
16847 movl %esp,%eax # pt_regs pointer
16848 call do_nmi
16849+
16850+ pax_exit_kernel
16851+
16852 jmp restore_all_notrace
16853 CFI_ENDPROC
16854
16855@@ -1453,12 +1728,15 @@ nmi_espfix_stack:
16856 FIXUP_ESPFIX_STACK # %eax == %esp
16857 xorl %edx,%edx # zero error code
16858 call do_nmi
16859+
16860+ pax_exit_kernel
16861+
16862 RESTORE_REGS
16863 lss 12+4(%esp), %esp # back to espfix stack
16864 CFI_ADJUST_CFA_OFFSET -24
16865 jmp irq_return
16866 CFI_ENDPROC
16867-END(nmi)
16868+ENDPROC(nmi)
16869
16870 ENTRY(int3)
16871 RING0_INT_FRAME
16872@@ -1471,14 +1749,14 @@ ENTRY(int3)
16873 call do_int3
16874 jmp ret_from_exception
16875 CFI_ENDPROC
16876-END(int3)
16877+ENDPROC(int3)
16878
16879 ENTRY(general_protection)
16880 RING0_EC_FRAME
16881 pushl_cfi $do_general_protection
16882 jmp error_code
16883 CFI_ENDPROC
16884-END(general_protection)
16885+ENDPROC(general_protection)
16886
16887 #ifdef CONFIG_KVM_GUEST
16888 ENTRY(async_page_fault)
16889@@ -1487,7 +1765,7 @@ ENTRY(async_page_fault)
16890 pushl_cfi $do_async_page_fault
16891 jmp error_code
16892 CFI_ENDPROC
16893-END(async_page_fault)
16894+ENDPROC(async_page_fault)
16895 #endif
16896
16897 /*
16898diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
16899index 1328fe4..cb03298 100644
16900--- a/arch/x86/kernel/entry_64.S
16901+++ b/arch/x86/kernel/entry_64.S
16902@@ -59,6 +59,8 @@
16903 #include <asm/rcu.h>
16904 #include <asm/smap.h>
16905 #include <linux/err.h>
16906+#include <asm/pgtable.h>
16907+#include <asm/alternative-asm.h>
16908
16909 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
16910 #include <linux/elf-em.h>
16911@@ -80,8 +82,9 @@
16912 #ifdef CONFIG_DYNAMIC_FTRACE
16913
16914 ENTRY(function_hook)
16915+ pax_force_retaddr
16916 retq
16917-END(function_hook)
16918+ENDPROC(function_hook)
16919
16920 /* skip is set if stack has been adjusted */
16921 .macro ftrace_caller_setup skip=0
16922@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
16923 #endif
16924
16925 GLOBAL(ftrace_stub)
16926+ pax_force_retaddr
16927 retq
16928-END(ftrace_caller)
16929+ENDPROC(ftrace_caller)
16930
16931 ENTRY(ftrace_regs_caller)
16932 /* Save the current flags before compare (in SS location)*/
16933@@ -191,7 +195,7 @@ ftrace_restore_flags:
16934 popfq
16935 jmp ftrace_stub
16936
16937-END(ftrace_regs_caller)
16938+ENDPROC(ftrace_regs_caller)
16939
16940
16941 #else /* ! CONFIG_DYNAMIC_FTRACE */
16942@@ -212,6 +216,7 @@ ENTRY(function_hook)
16943 #endif
16944
16945 GLOBAL(ftrace_stub)
16946+ pax_force_retaddr
16947 retq
16948
16949 trace:
16950@@ -225,12 +230,13 @@ trace:
16951 #endif
16952 subq $MCOUNT_INSN_SIZE, %rdi
16953
16954+ pax_force_fptr ftrace_trace_function
16955 call *ftrace_trace_function
16956
16957 MCOUNT_RESTORE_FRAME
16958
16959 jmp ftrace_stub
16960-END(function_hook)
16961+ENDPROC(function_hook)
16962 #endif /* CONFIG_DYNAMIC_FTRACE */
16963 #endif /* CONFIG_FUNCTION_TRACER */
16964
16965@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
16966
16967 MCOUNT_RESTORE_FRAME
16968
16969+ pax_force_retaddr
16970 retq
16971-END(ftrace_graph_caller)
16972+ENDPROC(ftrace_graph_caller)
16973
16974 GLOBAL(return_to_handler)
16975 subq $24, %rsp
16976@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
16977 movq 8(%rsp), %rdx
16978 movq (%rsp), %rax
16979 addq $24, %rsp
16980+ pax_force_fptr %rdi
16981 jmp *%rdi
16982+ENDPROC(return_to_handler)
16983 #endif
16984
16985
16986@@ -284,6 +293,273 @@ ENTRY(native_usergs_sysret64)
16987 ENDPROC(native_usergs_sysret64)
16988 #endif /* CONFIG_PARAVIRT */
16989
16990+ .macro ljmpq sel, off
16991+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
16992+ .byte 0x48; ljmp *1234f(%rip)
16993+ .pushsection .rodata
16994+ .align 16
16995+ 1234: .quad \off; .word \sel
16996+ .popsection
16997+#else
16998+ pushq $\sel
16999+ pushq $\off
17000+ lretq
17001+#endif
17002+ .endm
17003+
17004+ .macro pax_enter_kernel
17005+ pax_set_fptr_mask
17006+#ifdef CONFIG_PAX_KERNEXEC
17007+ call pax_enter_kernel
17008+#endif
17009+ .endm
17010+
17011+ .macro pax_exit_kernel
17012+#ifdef CONFIG_PAX_KERNEXEC
17013+ call pax_exit_kernel
17014+#endif
17015+ .endm
17016+
17017+#ifdef CONFIG_PAX_KERNEXEC
17018+ENTRY(pax_enter_kernel)
17019+ pushq %rdi
17020+
17021+#ifdef CONFIG_PARAVIRT
17022+ PV_SAVE_REGS(CLBR_RDI)
17023+#endif
17024+
17025+ GET_CR0_INTO_RDI
17026+ bts $16,%rdi
17027+ jnc 3f
17028+ mov %cs,%edi
17029+ cmp $__KERNEL_CS,%edi
17030+ jnz 2f
17031+1:
17032+
17033+#ifdef CONFIG_PARAVIRT
17034+ PV_RESTORE_REGS(CLBR_RDI)
17035+#endif
17036+
17037+ popq %rdi
17038+ pax_force_retaddr
17039+ retq
17040+
17041+2: ljmpq __KERNEL_CS,1f
17042+3: ljmpq __KERNEXEC_KERNEL_CS,4f
17043+4: SET_RDI_INTO_CR0
17044+ jmp 1b
17045+ENDPROC(pax_enter_kernel)
17046+
17047+ENTRY(pax_exit_kernel)
17048+ pushq %rdi
17049+
17050+#ifdef CONFIG_PARAVIRT
17051+ PV_SAVE_REGS(CLBR_RDI)
17052+#endif
17053+
17054+ mov %cs,%rdi
17055+ cmp $__KERNEXEC_KERNEL_CS,%edi
17056+ jz 2f
17057+1:
17058+
17059+#ifdef CONFIG_PARAVIRT
17060+ PV_RESTORE_REGS(CLBR_RDI);
17061+#endif
17062+
17063+ popq %rdi
17064+ pax_force_retaddr
17065+ retq
17066+
17067+2: GET_CR0_INTO_RDI
17068+ btr $16,%rdi
17069+ ljmpq __KERNEL_CS,3f
17070+3: SET_RDI_INTO_CR0
17071+ jmp 1b
17072+ENDPROC(pax_exit_kernel)
17073+#endif
17074+
17075+ .macro pax_enter_kernel_user
17076+ pax_set_fptr_mask
17077+#ifdef CONFIG_PAX_MEMORY_UDEREF
17078+ call pax_enter_kernel_user
17079+#endif
17080+ .endm
17081+
17082+ .macro pax_exit_kernel_user
17083+#ifdef CONFIG_PAX_MEMORY_UDEREF
17084+ call pax_exit_kernel_user
17085+#endif
17086+#ifdef CONFIG_PAX_RANDKSTACK
17087+ pushq %rax
17088+ call pax_randomize_kstack
17089+ popq %rax
17090+#endif
17091+ .endm
17092+
17093+#ifdef CONFIG_PAX_MEMORY_UDEREF
17094+ENTRY(pax_enter_kernel_user)
17095+ pushq %rdi
17096+ pushq %rbx
17097+
17098+#ifdef CONFIG_PARAVIRT
17099+ PV_SAVE_REGS(CLBR_RDI)
17100+#endif
17101+
17102+ GET_CR3_INTO_RDI
17103+ mov %rdi,%rbx
17104+ add $__START_KERNEL_map,%rbx
17105+ sub phys_base(%rip),%rbx
17106+
17107+#ifdef CONFIG_PARAVIRT
17108+ pushq %rdi
17109+ cmpl $0, pv_info+PARAVIRT_enabled
17110+ jz 1f
17111+ i = 0
17112+ .rept USER_PGD_PTRS
17113+ mov i*8(%rbx),%rsi
17114+ mov $0,%sil
17115+ lea i*8(%rbx),%rdi
17116+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17117+ i = i + 1
17118+ .endr
17119+ jmp 2f
17120+1:
17121+#endif
17122+
17123+ i = 0
17124+ .rept USER_PGD_PTRS
17125+ movb $0,i*8(%rbx)
17126+ i = i + 1
17127+ .endr
17128+
17129+#ifdef CONFIG_PARAVIRT
17130+2: popq %rdi
17131+#endif
17132+ SET_RDI_INTO_CR3
17133+
17134+#ifdef CONFIG_PAX_KERNEXEC
17135+ GET_CR0_INTO_RDI
17136+ bts $16,%rdi
17137+ SET_RDI_INTO_CR0
17138+#endif
17139+
17140+#ifdef CONFIG_PARAVIRT
17141+ PV_RESTORE_REGS(CLBR_RDI)
17142+#endif
17143+
17144+ popq %rbx
17145+ popq %rdi
17146+ pax_force_retaddr
17147+ retq
17148+ENDPROC(pax_enter_kernel_user)
17149+
17150+ENTRY(pax_exit_kernel_user)
17151+ push %rdi
17152+
17153+#ifdef CONFIG_PARAVIRT
17154+ pushq %rbx
17155+ PV_SAVE_REGS(CLBR_RDI)
17156+#endif
17157+
17158+#ifdef CONFIG_PAX_KERNEXEC
17159+ GET_CR0_INTO_RDI
17160+ btr $16,%rdi
17161+ SET_RDI_INTO_CR0
17162+#endif
17163+
17164+ GET_CR3_INTO_RDI
17165+ add $__START_KERNEL_map,%rdi
17166+ sub phys_base(%rip),%rdi
17167+
17168+#ifdef CONFIG_PARAVIRT
17169+ cmpl $0, pv_info+PARAVIRT_enabled
17170+ jz 1f
17171+ mov %rdi,%rbx
17172+ i = 0
17173+ .rept USER_PGD_PTRS
17174+ mov i*8(%rbx),%rsi
17175+ mov $0x67,%sil
17176+ lea i*8(%rbx),%rdi
17177+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
17178+ i = i + 1
17179+ .endr
17180+ jmp 2f
17181+1:
17182+#endif
17183+
17184+ i = 0
17185+ .rept USER_PGD_PTRS
17186+ movb $0x67,i*8(%rdi)
17187+ i = i + 1
17188+ .endr
17189+
17190+#ifdef CONFIG_PARAVIRT
17191+2: PV_RESTORE_REGS(CLBR_RDI)
17192+ popq %rbx
17193+#endif
17194+
17195+ popq %rdi
17196+ pax_force_retaddr
17197+ retq
17198+ENDPROC(pax_exit_kernel_user)
17199+#endif
17200+
17201+.macro pax_erase_kstack
17202+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17203+ call pax_erase_kstack
17204+#endif
17205+.endm
17206+
17207+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
17208+ENTRY(pax_erase_kstack)
17209+ pushq %rdi
17210+ pushq %rcx
17211+ pushq %rax
17212+ pushq %r11
17213+
17214+ GET_THREAD_INFO(%r11)
17215+ mov TI_lowest_stack(%r11), %rdi
17216+ mov $-0xBEEF, %rax
17217+ std
17218+
17219+1: mov %edi, %ecx
17220+ and $THREAD_SIZE_asm - 1, %ecx
17221+ shr $3, %ecx
17222+ repne scasq
17223+ jecxz 2f
17224+
17225+ cmp $2*8, %ecx
17226+ jc 2f
17227+
17228+ mov $2*8, %ecx
17229+ repe scasq
17230+ jecxz 2f
17231+ jne 1b
17232+
17233+2: cld
17234+ mov %esp, %ecx
17235+ sub %edi, %ecx
17236+
17237+ cmp $THREAD_SIZE_asm, %rcx
17238+ jb 3f
17239+ ud2
17240+3:
17241+
17242+ shr $3, %ecx
17243+ rep stosq
17244+
17245+ mov TI_task_thread_sp0(%r11), %rdi
17246+ sub $256, %rdi
17247+ mov %rdi, TI_lowest_stack(%r11)
17248+
17249+ popq %r11
17250+ popq %rax
17251+ popq %rcx
17252+ popq %rdi
17253+ pax_force_retaddr
17254+ ret
17255+ENDPROC(pax_erase_kstack)
17256+#endif
17257
17258 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
17259 #ifdef CONFIG_TRACE_IRQFLAGS
17260@@ -375,8 +651,8 @@ ENDPROC(native_usergs_sysret64)
17261 .endm
17262
17263 .macro UNFAKE_STACK_FRAME
17264- addq $8*6, %rsp
17265- CFI_ADJUST_CFA_OFFSET -(6*8)
17266+ addq $8*6 + ARG_SKIP, %rsp
17267+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
17268 .endm
17269
17270 /*
17271@@ -463,7 +739,7 @@ ENDPROC(native_usergs_sysret64)
17272 movq %rsp, %rsi
17273
17274 leaq -RBP(%rsp),%rdi /* arg1 for handler */
17275- testl $3, CS-RBP(%rsi)
17276+ testb $3, CS-RBP(%rsi)
17277 je 1f
17278 SWAPGS
17279 /*
17280@@ -498,9 +774,10 @@ ENTRY(save_rest)
17281 movq_cfi r15, R15+16
17282 movq %r11, 8(%rsp) /* return address */
17283 FIXUP_TOP_OF_STACK %r11, 16
17284+ pax_force_retaddr
17285 ret
17286 CFI_ENDPROC
17287-END(save_rest)
17288+ENDPROC(save_rest)
17289
17290 /* save complete stack frame */
17291 .pushsection .kprobes.text, "ax"
17292@@ -529,9 +806,10 @@ ENTRY(save_paranoid)
17293 js 1f /* negative -> in kernel */
17294 SWAPGS
17295 xorl %ebx,%ebx
17296-1: ret
17297+1: pax_force_retaddr_bts
17298+ ret
17299 CFI_ENDPROC
17300-END(save_paranoid)
17301+ENDPROC(save_paranoid)
17302 .popsection
17303
17304 /*
17305@@ -553,7 +831,7 @@ ENTRY(ret_from_fork)
17306
17307 RESTORE_REST
17308
17309- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17310+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
17311 jz 1f
17312
17313 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
17314@@ -571,7 +849,7 @@ ENTRY(ret_from_fork)
17315 RESTORE_REST
17316 jmp int_ret_from_sys_call
17317 CFI_ENDPROC
17318-END(ret_from_fork)
17319+ENDPROC(ret_from_fork)
17320
17321 /*
17322 * System call entry. Up to 6 arguments in registers are supported.
17323@@ -608,7 +886,7 @@ END(ret_from_fork)
17324 ENTRY(system_call)
17325 CFI_STARTPROC simple
17326 CFI_SIGNAL_FRAME
17327- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
17328+ CFI_DEF_CFA rsp,0
17329 CFI_REGISTER rip,rcx
17330 /*CFI_REGISTER rflags,r11*/
17331 SWAPGS_UNSAFE_STACK
17332@@ -621,16 +899,23 @@ GLOBAL(system_call_after_swapgs)
17333
17334 movq %rsp,PER_CPU_VAR(old_rsp)
17335 movq PER_CPU_VAR(kernel_stack),%rsp
17336+ SAVE_ARGS 8*6,0
17337+ pax_enter_kernel_user
17338+
17339+#ifdef CONFIG_PAX_RANDKSTACK
17340+ pax_erase_kstack
17341+#endif
17342+
17343 /*
17344 * No need to follow this irqs off/on section - it's straight
17345 * and short:
17346 */
17347 ENABLE_INTERRUPTS(CLBR_NONE)
17348- SAVE_ARGS 8,0
17349 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
17350 movq %rcx,RIP-ARGOFFSET(%rsp)
17351 CFI_REL_OFFSET rip,RIP-ARGOFFSET
17352- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17353+ GET_THREAD_INFO(%rcx)
17354+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
17355 jnz tracesys
17356 system_call_fastpath:
17357 #if __SYSCALL_MASK == ~0
17358@@ -640,7 +925,7 @@ system_call_fastpath:
17359 cmpl $__NR_syscall_max,%eax
17360 #endif
17361 ja badsys
17362- movq %r10,%rcx
17363+ movq R10-ARGOFFSET(%rsp),%rcx
17364 call *sys_call_table(,%rax,8) # XXX: rip relative
17365 movq %rax,RAX-ARGOFFSET(%rsp)
17366 /*
17367@@ -654,10 +939,13 @@ sysret_check:
17368 LOCKDEP_SYS_EXIT
17369 DISABLE_INTERRUPTS(CLBR_NONE)
17370 TRACE_IRQS_OFF
17371- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
17372+ GET_THREAD_INFO(%rcx)
17373+ movl TI_flags(%rcx),%edx
17374 andl %edi,%edx
17375 jnz sysret_careful
17376 CFI_REMEMBER_STATE
17377+ pax_exit_kernel_user
17378+ pax_erase_kstack
17379 /*
17380 * sysretq will re-enable interrupts:
17381 */
17382@@ -709,14 +997,18 @@ badsys:
17383 * jump back to the normal fast path.
17384 */
17385 auditsys:
17386- movq %r10,%r9 /* 6th arg: 4th syscall arg */
17387+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
17388 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
17389 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
17390 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
17391 movq %rax,%rsi /* 2nd arg: syscall number */
17392 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
17393 call __audit_syscall_entry
17394+
17395+ pax_erase_kstack
17396+
17397 LOAD_ARGS 0 /* reload call-clobbered registers */
17398+ pax_set_fptr_mask
17399 jmp system_call_fastpath
17400
17401 /*
17402@@ -737,7 +1029,7 @@ sysret_audit:
17403 /* Do syscall tracing */
17404 tracesys:
17405 #ifdef CONFIG_AUDITSYSCALL
17406- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
17407+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
17408 jz auditsys
17409 #endif
17410 SAVE_REST
17411@@ -745,12 +1037,16 @@ tracesys:
17412 FIXUP_TOP_OF_STACK %rdi
17413 movq %rsp,%rdi
17414 call syscall_trace_enter
17415+
17416+ pax_erase_kstack
17417+
17418 /*
17419 * Reload arg registers from stack in case ptrace changed them.
17420 * We don't reload %rax because syscall_trace_enter() returned
17421 * the value it wants us to use in the table lookup.
17422 */
17423 LOAD_ARGS ARGOFFSET, 1
17424+ pax_set_fptr_mask
17425 RESTORE_REST
17426 #if __SYSCALL_MASK == ~0
17427 cmpq $__NR_syscall_max,%rax
17428@@ -759,7 +1055,7 @@ tracesys:
17429 cmpl $__NR_syscall_max,%eax
17430 #endif
17431 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
17432- movq %r10,%rcx /* fixup for C */
17433+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
17434 call *sys_call_table(,%rax,8)
17435 movq %rax,RAX-ARGOFFSET(%rsp)
17436 /* Use IRET because user could have changed frame */
17437@@ -780,7 +1076,9 @@ GLOBAL(int_with_check)
17438 andl %edi,%edx
17439 jnz int_careful
17440 andl $~TS_COMPAT,TI_status(%rcx)
17441- jmp retint_swapgs
17442+ pax_exit_kernel_user
17443+ pax_erase_kstack
17444+ jmp retint_swapgs_pax
17445
17446 /* Either reschedule or signal or syscall exit tracking needed. */
17447 /* First do a reschedule test. */
17448@@ -826,7 +1124,7 @@ int_restore_rest:
17449 TRACE_IRQS_OFF
17450 jmp int_with_check
17451 CFI_ENDPROC
17452-END(system_call)
17453+ENDPROC(system_call)
17454
17455 /*
17456 * Certain special system calls that need to save a complete full stack frame.
17457@@ -842,7 +1140,7 @@ ENTRY(\label)
17458 call \func
17459 jmp ptregscall_common
17460 CFI_ENDPROC
17461-END(\label)
17462+ENDPROC(\label)
17463 .endm
17464
17465 PTREGSCALL stub_clone, sys_clone, %r8
17466@@ -860,9 +1158,10 @@ ENTRY(ptregscall_common)
17467 movq_cfi_restore R12+8, r12
17468 movq_cfi_restore RBP+8, rbp
17469 movq_cfi_restore RBX+8, rbx
17470+ pax_force_retaddr
17471 ret $REST_SKIP /* pop extended registers */
17472 CFI_ENDPROC
17473-END(ptregscall_common)
17474+ENDPROC(ptregscall_common)
17475
17476 ENTRY(stub_execve)
17477 CFI_STARTPROC
17478@@ -876,7 +1175,7 @@ ENTRY(stub_execve)
17479 RESTORE_REST
17480 jmp int_ret_from_sys_call
17481 CFI_ENDPROC
17482-END(stub_execve)
17483+ENDPROC(stub_execve)
17484
17485 /*
17486 * sigreturn is special because it needs to restore all registers on return.
17487@@ -894,7 +1193,7 @@ ENTRY(stub_rt_sigreturn)
17488 RESTORE_REST
17489 jmp int_ret_from_sys_call
17490 CFI_ENDPROC
17491-END(stub_rt_sigreturn)
17492+ENDPROC(stub_rt_sigreturn)
17493
17494 #ifdef CONFIG_X86_X32_ABI
17495 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
17496@@ -962,7 +1261,7 @@ vector=vector+1
17497 2: jmp common_interrupt
17498 .endr
17499 CFI_ENDPROC
17500-END(irq_entries_start)
17501+ENDPROC(irq_entries_start)
17502
17503 .previous
17504 END(interrupt)
17505@@ -982,6 +1281,16 @@ END(interrupt)
17506 subq $ORIG_RAX-RBP, %rsp
17507 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
17508 SAVE_ARGS_IRQ
17509+#ifdef CONFIG_PAX_MEMORY_UDEREF
17510+ testb $3, CS(%rdi)
17511+ jnz 1f
17512+ pax_enter_kernel
17513+ jmp 2f
17514+1: pax_enter_kernel_user
17515+2:
17516+#else
17517+ pax_enter_kernel
17518+#endif
17519 call \func
17520 .endm
17521
17522@@ -1014,7 +1323,7 @@ ret_from_intr:
17523
17524 exit_intr:
17525 GET_THREAD_INFO(%rcx)
17526- testl $3,CS-ARGOFFSET(%rsp)
17527+ testb $3,CS-ARGOFFSET(%rsp)
17528 je retint_kernel
17529
17530 /* Interrupt came from user space */
17531@@ -1036,12 +1345,16 @@ retint_swapgs: /* return to user-space */
17532 * The iretq could re-enable interrupts:
17533 */
17534 DISABLE_INTERRUPTS(CLBR_ANY)
17535+ pax_exit_kernel_user
17536+retint_swapgs_pax:
17537 TRACE_IRQS_IRETQ
17538 SWAPGS
17539 jmp restore_args
17540
17541 retint_restore_args: /* return to kernel space */
17542 DISABLE_INTERRUPTS(CLBR_ANY)
17543+ pax_exit_kernel
17544+ pax_force_retaddr (RIP-ARGOFFSET)
17545 /*
17546 * The iretq could re-enable interrupts:
17547 */
17548@@ -1124,7 +1437,7 @@ ENTRY(retint_kernel)
17549 #endif
17550
17551 CFI_ENDPROC
17552-END(common_interrupt)
17553+ENDPROC(common_interrupt)
17554 /*
17555 * End of kprobes section
17556 */
17557@@ -1142,7 +1455,7 @@ ENTRY(\sym)
17558 interrupt \do_sym
17559 jmp ret_from_intr
17560 CFI_ENDPROC
17561-END(\sym)
17562+ENDPROC(\sym)
17563 .endm
17564
17565 #ifdef CONFIG_SMP
17566@@ -1198,12 +1511,22 @@ ENTRY(\sym)
17567 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17568 call error_entry
17569 DEFAULT_FRAME 0
17570+#ifdef CONFIG_PAX_MEMORY_UDEREF
17571+ testb $3, CS(%rsp)
17572+ jnz 1f
17573+ pax_enter_kernel
17574+ jmp 2f
17575+1: pax_enter_kernel_user
17576+2:
17577+#else
17578+ pax_enter_kernel
17579+#endif
17580 movq %rsp,%rdi /* pt_regs pointer */
17581 xorl %esi,%esi /* no error code */
17582 call \do_sym
17583 jmp error_exit /* %ebx: no swapgs flag */
17584 CFI_ENDPROC
17585-END(\sym)
17586+ENDPROC(\sym)
17587 .endm
17588
17589 .macro paranoidzeroentry sym do_sym
17590@@ -1216,15 +1539,25 @@ ENTRY(\sym)
17591 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17592 call save_paranoid
17593 TRACE_IRQS_OFF
17594+#ifdef CONFIG_PAX_MEMORY_UDEREF
17595+ testb $3, CS(%rsp)
17596+ jnz 1f
17597+ pax_enter_kernel
17598+ jmp 2f
17599+1: pax_enter_kernel_user
17600+2:
17601+#else
17602+ pax_enter_kernel
17603+#endif
17604 movq %rsp,%rdi /* pt_regs pointer */
17605 xorl %esi,%esi /* no error code */
17606 call \do_sym
17607 jmp paranoid_exit /* %ebx: no swapgs flag */
17608 CFI_ENDPROC
17609-END(\sym)
17610+ENDPROC(\sym)
17611 .endm
17612
17613-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
17614+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
17615 .macro paranoidzeroentry_ist sym do_sym ist
17616 ENTRY(\sym)
17617 INTR_FRAME
17618@@ -1235,14 +1568,30 @@ ENTRY(\sym)
17619 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17620 call save_paranoid
17621 TRACE_IRQS_OFF_DEBUG
17622+#ifdef CONFIG_PAX_MEMORY_UDEREF
17623+ testb $3, CS(%rsp)
17624+ jnz 1f
17625+ pax_enter_kernel
17626+ jmp 2f
17627+1: pax_enter_kernel_user
17628+2:
17629+#else
17630+ pax_enter_kernel
17631+#endif
17632 movq %rsp,%rdi /* pt_regs pointer */
17633 xorl %esi,%esi /* no error code */
17634+#ifdef CONFIG_SMP
17635+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
17636+ lea init_tss(%r12), %r12
17637+#else
17638+ lea init_tss(%rip), %r12
17639+#endif
17640 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17641 call \do_sym
17642 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
17643 jmp paranoid_exit /* %ebx: no swapgs flag */
17644 CFI_ENDPROC
17645-END(\sym)
17646+ENDPROC(\sym)
17647 .endm
17648
17649 .macro errorentry sym do_sym
17650@@ -1254,13 +1603,23 @@ ENTRY(\sym)
17651 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
17652 call error_entry
17653 DEFAULT_FRAME 0
17654+#ifdef CONFIG_PAX_MEMORY_UDEREF
17655+ testb $3, CS(%rsp)
17656+ jnz 1f
17657+ pax_enter_kernel
17658+ jmp 2f
17659+1: pax_enter_kernel_user
17660+2:
17661+#else
17662+ pax_enter_kernel
17663+#endif
17664 movq %rsp,%rdi /* pt_regs pointer */
17665 movq ORIG_RAX(%rsp),%rsi /* get error code */
17666 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17667 call \do_sym
17668 jmp error_exit /* %ebx: no swapgs flag */
17669 CFI_ENDPROC
17670-END(\sym)
17671+ENDPROC(\sym)
17672 .endm
17673
17674 /* error code is on the stack already */
17675@@ -1274,13 +1633,23 @@ ENTRY(\sym)
17676 call save_paranoid
17677 DEFAULT_FRAME 0
17678 TRACE_IRQS_OFF
17679+#ifdef CONFIG_PAX_MEMORY_UDEREF
17680+ testb $3, CS(%rsp)
17681+ jnz 1f
17682+ pax_enter_kernel
17683+ jmp 2f
17684+1: pax_enter_kernel_user
17685+2:
17686+#else
17687+ pax_enter_kernel
17688+#endif
17689 movq %rsp,%rdi /* pt_regs pointer */
17690 movq ORIG_RAX(%rsp),%rsi /* get error code */
17691 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
17692 call \do_sym
17693 jmp paranoid_exit /* %ebx: no swapgs flag */
17694 CFI_ENDPROC
17695-END(\sym)
17696+ENDPROC(\sym)
17697 .endm
17698
17699 zeroentry divide_error do_divide_error
17700@@ -1310,9 +1679,10 @@ gs_change:
17701 2: mfence /* workaround */
17702 SWAPGS
17703 popfq_cfi
17704+ pax_force_retaddr
17705 ret
17706 CFI_ENDPROC
17707-END(native_load_gs_index)
17708+ENDPROC(native_load_gs_index)
17709
17710 _ASM_EXTABLE(gs_change,bad_gs)
17711 .section .fixup,"ax"
17712@@ -1340,9 +1710,10 @@ ENTRY(call_softirq)
17713 CFI_DEF_CFA_REGISTER rsp
17714 CFI_ADJUST_CFA_OFFSET -8
17715 decl PER_CPU_VAR(irq_count)
17716+ pax_force_retaddr
17717 ret
17718 CFI_ENDPROC
17719-END(call_softirq)
17720+ENDPROC(call_softirq)
17721
17722 #ifdef CONFIG_XEN
17723 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
17724@@ -1380,7 +1751,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
17725 decl PER_CPU_VAR(irq_count)
17726 jmp error_exit
17727 CFI_ENDPROC
17728-END(xen_do_hypervisor_callback)
17729+ENDPROC(xen_do_hypervisor_callback)
17730
17731 /*
17732 * Hypervisor uses this for application faults while it executes.
17733@@ -1439,7 +1810,7 @@ ENTRY(xen_failsafe_callback)
17734 SAVE_ALL
17735 jmp error_exit
17736 CFI_ENDPROC
17737-END(xen_failsafe_callback)
17738+ENDPROC(xen_failsafe_callback)
17739
17740 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
17741 xen_hvm_callback_vector xen_evtchn_do_upcall
17742@@ -1488,16 +1859,31 @@ ENTRY(paranoid_exit)
17743 TRACE_IRQS_OFF_DEBUG
17744 testl %ebx,%ebx /* swapgs needed? */
17745 jnz paranoid_restore
17746- testl $3,CS(%rsp)
17747+ testb $3,CS(%rsp)
17748 jnz paranoid_userspace
17749+#ifdef CONFIG_PAX_MEMORY_UDEREF
17750+ pax_exit_kernel
17751+ TRACE_IRQS_IRETQ 0
17752+ SWAPGS_UNSAFE_STACK
17753+ RESTORE_ALL 8
17754+ pax_force_retaddr_bts
17755+ jmp irq_return
17756+#endif
17757 paranoid_swapgs:
17758+#ifdef CONFIG_PAX_MEMORY_UDEREF
17759+ pax_exit_kernel_user
17760+#else
17761+ pax_exit_kernel
17762+#endif
17763 TRACE_IRQS_IRETQ 0
17764 SWAPGS_UNSAFE_STACK
17765 RESTORE_ALL 8
17766 jmp irq_return
17767 paranoid_restore:
17768+ pax_exit_kernel
17769 TRACE_IRQS_IRETQ_DEBUG 0
17770 RESTORE_ALL 8
17771+ pax_force_retaddr_bts
17772 jmp irq_return
17773 paranoid_userspace:
17774 GET_THREAD_INFO(%rcx)
17775@@ -1526,7 +1912,7 @@ paranoid_schedule:
17776 TRACE_IRQS_OFF
17777 jmp paranoid_userspace
17778 CFI_ENDPROC
17779-END(paranoid_exit)
17780+ENDPROC(paranoid_exit)
17781
17782 /*
17783 * Exception entry point. This expects an error code/orig_rax on the stack.
17784@@ -1553,12 +1939,13 @@ ENTRY(error_entry)
17785 movq_cfi r14, R14+8
17786 movq_cfi r15, R15+8
17787 xorl %ebx,%ebx
17788- testl $3,CS+8(%rsp)
17789+ testb $3,CS+8(%rsp)
17790 je error_kernelspace
17791 error_swapgs:
17792 SWAPGS
17793 error_sti:
17794 TRACE_IRQS_OFF
17795+ pax_force_retaddr_bts
17796 ret
17797
17798 /*
17799@@ -1585,7 +1972,7 @@ bstep_iret:
17800 movq %rcx,RIP+8(%rsp)
17801 jmp error_swapgs
17802 CFI_ENDPROC
17803-END(error_entry)
17804+ENDPROC(error_entry)
17805
17806
17807 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
17808@@ -1605,7 +1992,7 @@ ENTRY(error_exit)
17809 jnz retint_careful
17810 jmp retint_swapgs
17811 CFI_ENDPROC
17812-END(error_exit)
17813+ENDPROC(error_exit)
17814
17815 /*
17816 * Test if a given stack is an NMI stack or not.
17817@@ -1663,9 +2050,11 @@ ENTRY(nmi)
17818 * If %cs was not the kernel segment, then the NMI triggered in user
17819 * space, which means it is definitely not nested.
17820 */
17821+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
17822+ je 1f
17823 cmpl $__KERNEL_CS, 16(%rsp)
17824 jne first_nmi
17825-
17826+1:
17827 /*
17828 * Check the special variable on the stack to see if NMIs are
17829 * executing.
17830@@ -1824,6 +2213,17 @@ end_repeat_nmi:
17831 */
17832 movq %cr2, %r12
17833
17834+#ifdef CONFIG_PAX_MEMORY_UDEREF
17835+ testb $3, CS(%rsp)
17836+ jnz 1f
17837+ pax_enter_kernel
17838+ jmp 2f
17839+1: pax_enter_kernel_user
17840+2:
17841+#else
17842+ pax_enter_kernel
17843+#endif
17844+
17845 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
17846 movq %rsp,%rdi
17847 movq $-1,%rsi
17848@@ -1839,21 +2239,32 @@ end_repeat_nmi:
17849 testl %ebx,%ebx /* swapgs needed? */
17850 jnz nmi_restore
17851 nmi_swapgs:
17852+#ifdef CONFIG_PAX_MEMORY_UDEREF
17853+ pax_exit_kernel_user
17854+#else
17855+ pax_exit_kernel
17856+#endif
17857 SWAPGS_UNSAFE_STACK
17858+ RESTORE_ALL 8
17859+ /* Clear the NMI executing stack variable */
17860+ movq $0, 10*8(%rsp)
17861+ jmp irq_return
17862 nmi_restore:
17863+ pax_exit_kernel
17864 RESTORE_ALL 8
17865+ pax_force_retaddr_bts
17866 /* Clear the NMI executing stack variable */
17867 movq $0, 10*8(%rsp)
17868 jmp irq_return
17869 CFI_ENDPROC
17870-END(nmi)
17871+ENDPROC(nmi)
17872
17873 ENTRY(ignore_sysret)
17874 CFI_STARTPROC
17875 mov $-ENOSYS,%eax
17876 sysret
17877 CFI_ENDPROC
17878-END(ignore_sysret)
17879+ENDPROC(ignore_sysret)
17880
17881 /*
17882 * End of kprobes section
17883diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
17884index 1d41402..af9a46a 100644
17885--- a/arch/x86/kernel/ftrace.c
17886+++ b/arch/x86/kernel/ftrace.c
17887@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
17888 {
17889 unsigned char replaced[MCOUNT_INSN_SIZE];
17890
17891+ ip = ktla_ktva(ip);
17892+
17893 /*
17894 * Note: Due to modules and __init, code can
17895 * disappear and change, we need to protect against faulting
17896@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17897 unsigned char old[MCOUNT_INSN_SIZE], *new;
17898 int ret;
17899
17900- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
17901+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
17902 new = ftrace_call_replace(ip, (unsigned long)func);
17903
17904 /* See comment above by declaration of modifying_ftrace_code */
17905@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
17906 /* Also update the regs callback function */
17907 if (!ret) {
17908 ip = (unsigned long)(&ftrace_regs_call);
17909- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
17910+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
17911 new = ftrace_call_replace(ip, (unsigned long)func);
17912 ret = ftrace_modify_code(ip, old, new);
17913 }
17914@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
17915 * kernel identity mapping to modify code.
17916 */
17917 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
17918- ip = (unsigned long)__va(__pa(ip));
17919+ ip = (unsigned long)__va(__pa(ktla_ktva(ip)));
17920
17921 return probe_kernel_write((void *)ip, val, size);
17922 }
17923@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
17924 unsigned char replaced[MCOUNT_INSN_SIZE];
17925 unsigned char brk = BREAKPOINT_INSTRUCTION;
17926
17927- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
17928+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
17929 return -EFAULT;
17930
17931 /* Make sure it is what we expect it to be */
17932@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
17933 return ret;
17934
17935 fail_update:
17936- probe_kernel_write((void *)ip, &old_code[0], 1);
17937+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
17938 goto out;
17939 }
17940
17941@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
17942 {
17943 unsigned char code[MCOUNT_INSN_SIZE];
17944
17945+ ip = ktla_ktva(ip);
17946+
17947 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
17948 return -EFAULT;
17949
17950diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
17951index c18f59d..69ddbc4 100644
17952--- a/arch/x86/kernel/head32.c
17953+++ b/arch/x86/kernel/head32.c
17954@@ -18,20 +18,20 @@
17955 #include <asm/io_apic.h>
17956 #include <asm/bios_ebda.h>
17957 #include <asm/tlbflush.h>
17958+#include <asm/boot.h>
17959
17960 static void __init i386_default_early_setup(void)
17961 {
17962 /* Initialize 32bit specific setup functions */
17963- x86_init.resources.reserve_resources = i386_reserve_resources;
17964- x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17965+ *(void **)&x86_init.resources.reserve_resources = i386_reserve_resources;
17966+ *(void **)&x86_init.mpparse.setup_ioapic_ids = setup_ioapic_ids_from_mpc;
17967
17968 reserve_ebda_region();
17969 }
17970
17971 void __init i386_start_kernel(void)
17972 {
17973- memblock_reserve(__pa_symbol(&_text),
17974- __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
17975+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
17976
17977 #ifdef CONFIG_BLK_DEV_INITRD
17978 /* Reserve INITRD */
17979diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
17980index 4dac2f6..bc6a335 100644
17981--- a/arch/x86/kernel/head_32.S
17982+++ b/arch/x86/kernel/head_32.S
17983@@ -26,6 +26,12 @@
17984 /* Physical address */
17985 #define pa(X) ((X) - __PAGE_OFFSET)
17986
17987+#ifdef CONFIG_PAX_KERNEXEC
17988+#define ta(X) (X)
17989+#else
17990+#define ta(X) ((X) - __PAGE_OFFSET)
17991+#endif
17992+
17993 /*
17994 * References to members of the new_cpu_data structure.
17995 */
17996@@ -55,11 +61,7 @@
17997 * and small than max_low_pfn, otherwise will waste some page table entries
17998 */
17999
18000-#if PTRS_PER_PMD > 1
18001-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
18002-#else
18003-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
18004-#endif
18005+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
18006
18007 /* Number of possible pages in the lowmem region */
18008 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
18009@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
18010 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18011
18012 /*
18013+ * Real beginning of normal "text" segment
18014+ */
18015+ENTRY(stext)
18016+ENTRY(_stext)
18017+
18018+/*
18019 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
18020 * %esi points to the real-mode code as a 32-bit pointer.
18021 * CS and DS must be 4 GB flat segments, but we don't depend on
18022@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
18023 * can.
18024 */
18025 __HEAD
18026+
18027+#ifdef CONFIG_PAX_KERNEXEC
18028+ jmp startup_32
18029+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
18030+.fill PAGE_SIZE-5,1,0xcc
18031+#endif
18032+
18033 ENTRY(startup_32)
18034 movl pa(stack_start),%ecx
18035
18036@@ -106,6 +121,59 @@ ENTRY(startup_32)
18037 2:
18038 leal -__PAGE_OFFSET(%ecx),%esp
18039
18040+#ifdef CONFIG_SMP
18041+ movl $pa(cpu_gdt_table),%edi
18042+ movl $__per_cpu_load,%eax
18043+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
18044+ rorl $16,%eax
18045+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
18046+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
18047+ movl $__per_cpu_end - 1,%eax
18048+ subl $__per_cpu_start,%eax
18049+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
18050+#endif
18051+
18052+#ifdef CONFIG_PAX_MEMORY_UDEREF
18053+ movl $NR_CPUS,%ecx
18054+ movl $pa(cpu_gdt_table),%edi
18055+1:
18056+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
18057+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
18058+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
18059+ addl $PAGE_SIZE_asm,%edi
18060+ loop 1b
18061+#endif
18062+
18063+#ifdef CONFIG_PAX_KERNEXEC
18064+ movl $pa(boot_gdt),%edi
18065+ movl $__LOAD_PHYSICAL_ADDR,%eax
18066+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
18067+ rorl $16,%eax
18068+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
18069+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
18070+ rorl $16,%eax
18071+
18072+ ljmp $(__BOOT_CS),$1f
18073+1:
18074+
18075+ movl $NR_CPUS,%ecx
18076+ movl $pa(cpu_gdt_table),%edi
18077+ addl $__PAGE_OFFSET,%eax
18078+1:
18079+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
18080+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
18081+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
18082+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
18083+ rorl $16,%eax
18084+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
18085+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
18086+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
18087+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
18088+ rorl $16,%eax
18089+ addl $PAGE_SIZE_asm,%edi
18090+ loop 1b
18091+#endif
18092+
18093 /*
18094 * Clear BSS first so that there are no surprises...
18095 */
18096@@ -196,8 +264,11 @@ ENTRY(startup_32)
18097 movl %eax, pa(max_pfn_mapped)
18098
18099 /* Do early initialization of the fixmap area */
18100- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18101- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
18102+#ifdef CONFIG_COMPAT_VDSO
18103+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
18104+#else
18105+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
18106+#endif
18107 #else /* Not PAE */
18108
18109 page_pde_offset = (__PAGE_OFFSET >> 20);
18110@@ -227,8 +298,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18111 movl %eax, pa(max_pfn_mapped)
18112
18113 /* Do early initialization of the fixmap area */
18114- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
18115- movl %eax,pa(initial_page_table+0xffc)
18116+#ifdef CONFIG_COMPAT_VDSO
18117+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
18118+#else
18119+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
18120+#endif
18121 #endif
18122
18123 #ifdef CONFIG_PARAVIRT
18124@@ -242,9 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
18125 cmpl $num_subarch_entries, %eax
18126 jae bad_subarch
18127
18128- movl pa(subarch_entries)(,%eax,4), %eax
18129- subl $__PAGE_OFFSET, %eax
18130- jmp *%eax
18131+ jmp *pa(subarch_entries)(,%eax,4)
18132
18133 bad_subarch:
18134 WEAK(lguest_entry)
18135@@ -256,10 +328,10 @@ WEAK(xen_entry)
18136 __INITDATA
18137
18138 subarch_entries:
18139- .long default_entry /* normal x86/PC */
18140- .long lguest_entry /* lguest hypervisor */
18141- .long xen_entry /* Xen hypervisor */
18142- .long default_entry /* Moorestown MID */
18143+ .long ta(default_entry) /* normal x86/PC */
18144+ .long ta(lguest_entry) /* lguest hypervisor */
18145+ .long ta(xen_entry) /* Xen hypervisor */
18146+ .long ta(default_entry) /* Moorestown MID */
18147 num_subarch_entries = (. - subarch_entries) / 4
18148 .previous
18149 #else
18150@@ -316,6 +388,7 @@ default_entry:
18151 movl pa(mmu_cr4_features),%eax
18152 movl %eax,%cr4
18153
18154+#ifdef CONFIG_X86_PAE
18155 testb $X86_CR4_PAE, %al # check if PAE is enabled
18156 jz 6f
18157
18158@@ -344,6 +417,9 @@ default_entry:
18159 /* Make changes effective */
18160 wrmsr
18161
18162+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
18163+#endif
18164+
18165 6:
18166
18167 /*
18168@@ -442,14 +518,20 @@ is386: movl $2,%ecx # set MP
18169 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
18170 movl %eax,%ss # after changing gdt.
18171
18172- movl $(__USER_DS),%eax # DS/ES contains default USER segment
18173+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
18174 movl %eax,%ds
18175 movl %eax,%es
18176
18177 movl $(__KERNEL_PERCPU), %eax
18178 movl %eax,%fs # set this cpu's percpu
18179
18180+#ifdef CONFIG_CC_STACKPROTECTOR
18181 movl $(__KERNEL_STACK_CANARY),%eax
18182+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18183+ movl $(__USER_DS),%eax
18184+#else
18185+ xorl %eax,%eax
18186+#endif
18187 movl %eax,%gs
18188
18189 xorl %eax,%eax # Clear LDT
18190@@ -526,8 +608,11 @@ setup_once:
18191 * relocation. Manually set base address in stack canary
18192 * segment descriptor.
18193 */
18194- movl $gdt_page,%eax
18195+ movl $cpu_gdt_table,%eax
18196 movl $stack_canary,%ecx
18197+#ifdef CONFIG_SMP
18198+ addl $__per_cpu_load,%ecx
18199+#endif
18200 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
18201 shrl $16, %ecx
18202 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
18203@@ -558,7 +643,7 @@ ENDPROC(early_idt_handlers)
18204 /* This is global to keep gas from relaxing the jumps */
18205 ENTRY(early_idt_handler)
18206 cld
18207- cmpl $2,%ss:early_recursion_flag
18208+ cmpl $1,%ss:early_recursion_flag
18209 je hlt_loop
18210 incl %ss:early_recursion_flag
18211
18212@@ -596,8 +681,8 @@ ENTRY(early_idt_handler)
18213 pushl (20+6*4)(%esp) /* trapno */
18214 pushl $fault_msg
18215 call printk
18216-#endif
18217 call dump_stack
18218+#endif
18219 hlt_loop:
18220 hlt
18221 jmp hlt_loop
18222@@ -616,8 +701,11 @@ ENDPROC(early_idt_handler)
18223 /* This is the default interrupt "handler" :-) */
18224 ALIGN
18225 ignore_int:
18226- cld
18227 #ifdef CONFIG_PRINTK
18228+ cmpl $2,%ss:early_recursion_flag
18229+ je hlt_loop
18230+ incl %ss:early_recursion_flag
18231+ cld
18232 pushl %eax
18233 pushl %ecx
18234 pushl %edx
18235@@ -626,9 +714,6 @@ ignore_int:
18236 movl $(__KERNEL_DS),%eax
18237 movl %eax,%ds
18238 movl %eax,%es
18239- cmpl $2,early_recursion_flag
18240- je hlt_loop
18241- incl early_recursion_flag
18242 pushl 16(%esp)
18243 pushl 24(%esp)
18244 pushl 32(%esp)
18245@@ -662,29 +747,43 @@ ENTRY(setup_once_ref)
18246 /*
18247 * BSS section
18248 */
18249-__PAGE_ALIGNED_BSS
18250- .align PAGE_SIZE
18251 #ifdef CONFIG_X86_PAE
18252+.section .initial_pg_pmd,"a",@progbits
18253 initial_pg_pmd:
18254 .fill 1024*KPMDS,4,0
18255 #else
18256+.section .initial_page_table,"a",@progbits
18257 ENTRY(initial_page_table)
18258 .fill 1024,4,0
18259 #endif
18260+.section .initial_pg_fixmap,"a",@progbits
18261 initial_pg_fixmap:
18262 .fill 1024,4,0
18263+.section .empty_zero_page,"a",@progbits
18264 ENTRY(empty_zero_page)
18265 .fill 4096,1,0
18266+.section .swapper_pg_dir,"a",@progbits
18267 ENTRY(swapper_pg_dir)
18268+#ifdef CONFIG_X86_PAE
18269+ .fill 4,8,0
18270+#else
18271 .fill 1024,4,0
18272+#endif
18273+
18274+/*
18275+ * The IDT has to be page-aligned to simplify the Pentium
18276+ * F0 0F bug workaround.. We have a special link segment
18277+ * for this.
18278+ */
18279+.section .idt,"a",@progbits
18280+ENTRY(idt_table)
18281+ .fill 256,8,0
18282
18283 /*
18284 * This starts the data section.
18285 */
18286 #ifdef CONFIG_X86_PAE
18287-__PAGE_ALIGNED_DATA
18288- /* Page-aligned for the benefit of paravirt? */
18289- .align PAGE_SIZE
18290+.section .initial_page_table,"a",@progbits
18291 ENTRY(initial_page_table)
18292 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
18293 # if KPMDS == 3
18294@@ -703,12 +802,20 @@ ENTRY(initial_page_table)
18295 # error "Kernel PMDs should be 1, 2 or 3"
18296 # endif
18297 .align PAGE_SIZE /* needs to be page-sized too */
18298+
18299+#ifdef CONFIG_PAX_PER_CPU_PGD
18300+ENTRY(cpu_pgd)
18301+ .rept NR_CPUS
18302+ .fill 4,8,0
18303+ .endr
18304+#endif
18305+
18306 #endif
18307
18308 .data
18309 .balign 4
18310 ENTRY(stack_start)
18311- .long init_thread_union+THREAD_SIZE
18312+ .long init_thread_union+THREAD_SIZE-8
18313
18314 __INITRODATA
18315 int_msg:
18316@@ -736,7 +843,7 @@ fault_msg:
18317 * segment size, and 32-bit linear address value:
18318 */
18319
18320- .data
18321+.section .rodata,"a",@progbits
18322 .globl boot_gdt_descr
18323 .globl idt_descr
18324
18325@@ -745,7 +852,7 @@ fault_msg:
18326 .word 0 # 32 bit align gdt_desc.address
18327 boot_gdt_descr:
18328 .word __BOOT_DS+7
18329- .long boot_gdt - __PAGE_OFFSET
18330+ .long pa(boot_gdt)
18331
18332 .word 0 # 32-bit align idt_desc.address
18333 idt_descr:
18334@@ -756,7 +863,7 @@ idt_descr:
18335 .word 0 # 32 bit align gdt_desc.address
18336 ENTRY(early_gdt_descr)
18337 .word GDT_ENTRIES*8-1
18338- .long gdt_page /* Overwritten for secondary CPUs */
18339+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
18340
18341 /*
18342 * The boot_gdt must mirror the equivalent in setup.S and is
18343@@ -765,5 +872,65 @@ ENTRY(early_gdt_descr)
18344 .align L1_CACHE_BYTES
18345 ENTRY(boot_gdt)
18346 .fill GDT_ENTRY_BOOT_CS,8,0
18347- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
18348- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
18349+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
18350+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
18351+
18352+ .align PAGE_SIZE_asm
18353+ENTRY(cpu_gdt_table)
18354+ .rept NR_CPUS
18355+ .quad 0x0000000000000000 /* NULL descriptor */
18356+ .quad 0x0000000000000000 /* 0x0b reserved */
18357+ .quad 0x0000000000000000 /* 0x13 reserved */
18358+ .quad 0x0000000000000000 /* 0x1b reserved */
18359+
18360+#ifdef CONFIG_PAX_KERNEXEC
18361+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
18362+#else
18363+ .quad 0x0000000000000000 /* 0x20 unused */
18364+#endif
18365+
18366+ .quad 0x0000000000000000 /* 0x28 unused */
18367+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
18368+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
18369+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
18370+ .quad 0x0000000000000000 /* 0x4b reserved */
18371+ .quad 0x0000000000000000 /* 0x53 reserved */
18372+ .quad 0x0000000000000000 /* 0x5b reserved */
18373+
18374+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
18375+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
18376+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
18377+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
18378+
18379+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
18380+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
18381+
18382+ /*
18383+ * Segments used for calling PnP BIOS have byte granularity.
18384+ * The code segments and data segments have fixed 64k limits,
18385+ * the transfer segment sizes are set at run time.
18386+ */
18387+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
18388+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
18389+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
18390+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
18391+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
18392+
18393+ /*
18394+ * The APM segments have byte granularity and their bases
18395+ * are set at run time. All have 64k limits.
18396+ */
18397+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
18398+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
18399+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
18400+
18401+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
18402+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
18403+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
18404+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
18405+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
18406+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
18407+
18408+ /* Be sure this is zeroed to avoid false validations in Xen */
18409+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
18410+ .endr
18411diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
18412index 94bf9cc..400455a 100644
18413--- a/arch/x86/kernel/head_64.S
18414+++ b/arch/x86/kernel/head_64.S
18415@@ -20,6 +20,8 @@
18416 #include <asm/processor-flags.h>
18417 #include <asm/percpu.h>
18418 #include <asm/nops.h>
18419+#include <asm/cpufeature.h>
18420+#include <asm/alternative-asm.h>
18421
18422 #ifdef CONFIG_PARAVIRT
18423 #include <asm/asm-offsets.h>
18424@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
18425 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
18426 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
18427 L3_START_KERNEL = pud_index(__START_KERNEL_map)
18428+L4_VMALLOC_START = pgd_index(VMALLOC_START)
18429+L3_VMALLOC_START = pud_index(VMALLOC_START)
18430+L4_VMALLOC_END = pgd_index(VMALLOC_END)
18431+L3_VMALLOC_END = pud_index(VMALLOC_END)
18432+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
18433+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
18434
18435 .text
18436 __HEAD
18437@@ -88,35 +96,23 @@ startup_64:
18438 */
18439 addq %rbp, init_level4_pgt + 0(%rip)
18440 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
18441+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
18442+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
18443+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
18444 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
18445
18446 addq %rbp, level3_ident_pgt + 0(%rip)
18447+#ifndef CONFIG_XEN
18448+ addq %rbp, level3_ident_pgt + 8(%rip)
18449+#endif
18450
18451- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
18452- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
18453+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
18454+
18455+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
18456+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
18457
18458 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
18459-
18460- /* Add an Identity mapping if I am above 1G */
18461- leaq _text(%rip), %rdi
18462- andq $PMD_PAGE_MASK, %rdi
18463-
18464- movq %rdi, %rax
18465- shrq $PUD_SHIFT, %rax
18466- andq $(PTRS_PER_PUD - 1), %rax
18467- jz ident_complete
18468-
18469- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
18470- leaq level3_ident_pgt(%rip), %rbx
18471- movq %rdx, 0(%rbx, %rax, 8)
18472-
18473- movq %rdi, %rax
18474- shrq $PMD_SHIFT, %rax
18475- andq $(PTRS_PER_PMD - 1), %rax
18476- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
18477- leaq level2_spare_pgt(%rip), %rbx
18478- movq %rdx, 0(%rbx, %rax, 8)
18479-ident_complete:
18480+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
18481
18482 /*
18483 * Fixup the kernel text+data virtual addresses. Note that
18484@@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
18485 * after the boot processor executes this code.
18486 */
18487
18488- /* Enable PAE mode and PGE */
18489- movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
18490+ /* Enable PAE mode and PSE/PGE */
18491+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
18492 movq %rax, %cr4
18493
18494 /* Setup early boot stage 4 level pagetables. */
18495@@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
18496 movl $MSR_EFER, %ecx
18497 rdmsr
18498 btsl $_EFER_SCE, %eax /* Enable System Call */
18499- btl $20,%edi /* No Execute supported? */
18500+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
18501 jnc 1f
18502 btsl $_EFER_NX, %eax
18503+ leaq init_level4_pgt(%rip), %rdi
18504+#ifndef CONFIG_EFI
18505+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
18506+#endif
18507+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
18508+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
18509+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
18510+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
18511 1: wrmsr /* Make changes effective */
18512
18513 /* Setup cr0 */
18514@@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
18515 * jump. In addition we need to ensure %cs is set so we make this
18516 * a far return.
18517 */
18518+ pax_set_fptr_mask
18519 movq initial_code(%rip),%rax
18520 pushq $0 # fake return address to stop unwinder
18521 pushq $__KERNEL_CS # set correct cs
18522@@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
18523 bad_address:
18524 jmp bad_address
18525
18526- .section ".init.text","ax"
18527+ __INIT
18528 .globl early_idt_handlers
18529 early_idt_handlers:
18530 # 104(%rsp) %rflags
18531@@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
18532 addq $16,%rsp # drop vector number and error code
18533 decl early_recursion_flag(%rip)
18534 INTERRUPT_RETURN
18535+ .previous
18536
18537+ __INITDATA
18538 .balign 4
18539 early_recursion_flag:
18540 .long 0
18541+ .previous
18542
18543+ .section .rodata,"a",@progbits
18544 #ifdef CONFIG_EARLY_PRINTK
18545 early_idt_msg:
18546 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
18547@@ -360,6 +369,7 @@ early_idt_ripmsg:
18548 #endif /* CONFIG_EARLY_PRINTK */
18549 .previous
18550
18551+ .section .rodata,"a",@progbits
18552 #define NEXT_PAGE(name) \
18553 .balign PAGE_SIZE; \
18554 ENTRY(name)
18555@@ -372,7 +382,6 @@ ENTRY(name)
18556 i = i + 1 ; \
18557 .endr
18558
18559- .data
18560 /*
18561 * This default setting generates an ident mapping at address 0x100000
18562 * and a mapping for the kernel that precisely maps virtual address
18563@@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
18564 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18565 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
18566 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18567+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
18568+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
18569+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
18570+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
18571+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
18572+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18573 .org init_level4_pgt + L4_START_KERNEL*8, 0
18574 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
18575 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
18576
18577+#ifdef CONFIG_PAX_PER_CPU_PGD
18578+NEXT_PAGE(cpu_pgd)
18579+ .rept NR_CPUS
18580+ .fill 512,8,0
18581+ .endr
18582+#endif
18583+
18584 NEXT_PAGE(level3_ident_pgt)
18585 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
18586+#ifdef CONFIG_XEN
18587 .fill 511,8,0
18588+#else
18589+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
18590+ .fill 510,8,0
18591+#endif
18592+
18593+NEXT_PAGE(level3_vmalloc_start_pgt)
18594+ .fill 512,8,0
18595+
18596+NEXT_PAGE(level3_vmalloc_end_pgt)
18597+ .fill 512,8,0
18598+
18599+NEXT_PAGE(level3_vmemmap_pgt)
18600+ .fill L3_VMEMMAP_START,8,0
18601+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
18602
18603 NEXT_PAGE(level3_kernel_pgt)
18604 .fill L3_START_KERNEL,8,0
18605@@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
18606 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
18607 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18608
18609+NEXT_PAGE(level2_vmemmap_pgt)
18610+ .fill 512,8,0
18611+
18612 NEXT_PAGE(level2_fixmap_pgt)
18613- .fill 506,8,0
18614- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
18615- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
18616- .fill 5,8,0
18617+ .fill 507,8,0
18618+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
18619+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
18620+ .fill 4,8,0
18621
18622-NEXT_PAGE(level1_fixmap_pgt)
18623+NEXT_PAGE(level1_vsyscall_pgt)
18624 .fill 512,8,0
18625
18626-NEXT_PAGE(level2_ident_pgt)
18627- /* Since I easily can, map the first 1G.
18628+ /* Since I easily can, map the first 2G.
18629 * Don't set NX because code runs from these pages.
18630 */
18631- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
18632+NEXT_PAGE(level2_ident_pgt)
18633+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
18634
18635 NEXT_PAGE(level2_kernel_pgt)
18636 /*
18637@@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
18638 * If you want to increase this then increase MODULES_VADDR
18639 * too.)
18640 */
18641- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
18642- KERNEL_IMAGE_SIZE/PMD_SIZE)
18643-
18644-NEXT_PAGE(level2_spare_pgt)
18645- .fill 512, 8, 0
18646+ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
18647
18648 #undef PMDS
18649 #undef NEXT_PAGE
18650
18651- .data
18652+ .align PAGE_SIZE
18653+ENTRY(cpu_gdt_table)
18654+ .rept NR_CPUS
18655+ .quad 0x0000000000000000 /* NULL descriptor */
18656+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
18657+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
18658+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
18659+ .quad 0x00cffb000000ffff /* __USER32_CS */
18660+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
18661+ .quad 0x00affb000000ffff /* __USER_CS */
18662+
18663+#ifdef CONFIG_PAX_KERNEXEC
18664+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
18665+#else
18666+ .quad 0x0 /* unused */
18667+#endif
18668+
18669+ .quad 0,0 /* TSS */
18670+ .quad 0,0 /* LDT */
18671+ .quad 0,0,0 /* three TLS descriptors */
18672+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
18673+ /* asm/segment.h:GDT_ENTRIES must match this */
18674+
18675+ /* zero the remaining page */
18676+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
18677+ .endr
18678+
18679 .align 16
18680 .globl early_gdt_descr
18681 early_gdt_descr:
18682 .word GDT_ENTRIES*8-1
18683 early_gdt_descr_base:
18684- .quad INIT_PER_CPU_VAR(gdt_page)
18685+ .quad cpu_gdt_table
18686
18687 ENTRY(phys_base)
18688 /* This must match the first entry in level2_kernel_pgt */
18689 .quad 0x0000000000000000
18690
18691 #include "../../x86/xen/xen-head.S"
18692-
18693- .section .bss, "aw", @nobits
18694+
18695+ .section .rodata,"a",@progbits
18696 .align L1_CACHE_BYTES
18697 ENTRY(idt_table)
18698- .skip IDT_ENTRIES * 16
18699+ .fill 512,8,0
18700
18701 .align L1_CACHE_BYTES
18702 ENTRY(nmi_idt_table)
18703- .skip IDT_ENTRIES * 16
18704+ .fill 512,8,0
18705
18706 __PAGE_ALIGNED_BSS
18707 .align PAGE_SIZE
18708diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
18709index 9c3bd4a..e1d9b35 100644
18710--- a/arch/x86/kernel/i386_ksyms_32.c
18711+++ b/arch/x86/kernel/i386_ksyms_32.c
18712@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
18713 EXPORT_SYMBOL(cmpxchg8b_emu);
18714 #endif
18715
18716+EXPORT_SYMBOL_GPL(cpu_gdt_table);
18717+
18718 /* Networking helper routines. */
18719 EXPORT_SYMBOL(csum_partial_copy_generic);
18720+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
18721+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
18722
18723 EXPORT_SYMBOL(__get_user_1);
18724 EXPORT_SYMBOL(__get_user_2);
18725@@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
18726
18727 EXPORT_SYMBOL(csum_partial);
18728 EXPORT_SYMBOL(empty_zero_page);
18729+
18730+#ifdef CONFIG_PAX_KERNEXEC
18731+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
18732+#endif
18733diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
18734index 675a050..95febfd 100644
18735--- a/arch/x86/kernel/i387.c
18736+++ b/arch/x86/kernel/i387.c
18737@@ -55,7 +55,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
18738 static inline bool interrupted_user_mode(void)
18739 {
18740 struct pt_regs *regs = get_irq_regs();
18741- return regs && user_mode_vm(regs);
18742+ return regs && user_mode(regs);
18743 }
18744
18745 /*
18746diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
18747index 9a5c460..dc4374d 100644
18748--- a/arch/x86/kernel/i8259.c
18749+++ b/arch/x86/kernel/i8259.c
18750@@ -209,7 +209,7 @@ spurious_8259A_irq:
18751 "spurious 8259A interrupt: IRQ%d.\n", irq);
18752 spurious_irq_mask |= irqmask;
18753 }
18754- atomic_inc(&irq_err_count);
18755+ atomic_inc_unchecked(&irq_err_count);
18756 /*
18757 * Theoretically we do not have to handle this IRQ,
18758 * but in Linux this does not cause problems and is
18759diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
18760index 8c96897..be66bfa 100644
18761--- a/arch/x86/kernel/ioport.c
18762+++ b/arch/x86/kernel/ioport.c
18763@@ -6,6 +6,7 @@
18764 #include <linux/sched.h>
18765 #include <linux/kernel.h>
18766 #include <linux/capability.h>
18767+#include <linux/security.h>
18768 #include <linux/errno.h>
18769 #include <linux/types.h>
18770 #include <linux/ioport.h>
18771@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18772
18773 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
18774 return -EINVAL;
18775+#ifdef CONFIG_GRKERNSEC_IO
18776+ if (turn_on && grsec_disable_privio) {
18777+ gr_handle_ioperm();
18778+ return -EPERM;
18779+ }
18780+#endif
18781 if (turn_on && !capable(CAP_SYS_RAWIO))
18782 return -EPERM;
18783
18784@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
18785 * because the ->io_bitmap_max value must match the bitmap
18786 * contents:
18787 */
18788- tss = &per_cpu(init_tss, get_cpu());
18789+ tss = init_tss + get_cpu();
18790
18791 if (turn_on)
18792 bitmap_clear(t->io_bitmap_ptr, from, num);
18793@@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
18794 return -EINVAL;
18795 /* Trying to gain more privileges? */
18796 if (level > old) {
18797+#ifdef CONFIG_GRKERNSEC_IO
18798+ if (grsec_disable_privio) {
18799+ gr_handle_iopl();
18800+ return -EPERM;
18801+ }
18802+#endif
18803 if (!capable(CAP_SYS_RAWIO))
18804 return -EPERM;
18805 }
18806diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
18807index e4595f1..ee3bfb8 100644
18808--- a/arch/x86/kernel/irq.c
18809+++ b/arch/x86/kernel/irq.c
18810@@ -18,7 +18,7 @@
18811 #include <asm/mce.h>
18812 #include <asm/hw_irq.h>
18813
18814-atomic_t irq_err_count;
18815+atomic_unchecked_t irq_err_count;
18816
18817 /* Function pointer for generic interrupt vector handling */
18818 void (*x86_platform_ipi_callback)(void) = NULL;
18819@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
18820 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
18821 seq_printf(p, " Machine check polls\n");
18822 #endif
18823- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
18824+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
18825 #if defined(CONFIG_X86_IO_APIC)
18826- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
18827+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
18828 #endif
18829 return 0;
18830 }
18831@@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
18832
18833 u64 arch_irq_stat(void)
18834 {
18835- u64 sum = atomic_read(&irq_err_count);
18836+ u64 sum = atomic_read_unchecked(&irq_err_count);
18837
18838 #ifdef CONFIG_X86_IO_APIC
18839- sum += atomic_read(&irq_mis_count);
18840+ sum += atomic_read_unchecked(&irq_mis_count);
18841 #endif
18842 return sum;
18843 }
18844diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
18845index 344faf8..355f60d 100644
18846--- a/arch/x86/kernel/irq_32.c
18847+++ b/arch/x86/kernel/irq_32.c
18848@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
18849 __asm__ __volatile__("andl %%esp,%0" :
18850 "=r" (sp) : "0" (THREAD_SIZE - 1));
18851
18852- return sp < (sizeof(struct thread_info) + STACK_WARN);
18853+ return sp < STACK_WARN;
18854 }
18855
18856 static void print_stack_overflow(void)
18857@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
18858 * per-CPU IRQ handling contexts (thread information and stack)
18859 */
18860 union irq_ctx {
18861- struct thread_info tinfo;
18862- u32 stack[THREAD_SIZE/sizeof(u32)];
18863+ unsigned long previous_esp;
18864+ u32 stack[THREAD_SIZE/sizeof(u32)];
18865 } __attribute__((aligned(THREAD_SIZE)));
18866
18867 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
18868@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
18869 static inline int
18870 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18871 {
18872- union irq_ctx *curctx, *irqctx;
18873+ union irq_ctx *irqctx;
18874 u32 *isp, arg1, arg2;
18875
18876- curctx = (union irq_ctx *) current_thread_info();
18877 irqctx = __this_cpu_read(hardirq_ctx);
18878
18879 /*
18880@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18881 * handler) we can't do that and just have to keep using the
18882 * current stack (which is the irq stack already after all)
18883 */
18884- if (unlikely(curctx == irqctx))
18885+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
18886 return 0;
18887
18888 /* build the stack frame on the IRQ stack */
18889- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18890- irqctx->tinfo.task = curctx->tinfo.task;
18891- irqctx->tinfo.previous_esp = current_stack_pointer;
18892+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18893+ irqctx->previous_esp = current_stack_pointer;
18894
18895- /* Copy the preempt_count so that the [soft]irq checks work. */
18896- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
18897+#ifdef CONFIG_PAX_MEMORY_UDEREF
18898+ __set_fs(MAKE_MM_SEG(0));
18899+#endif
18900
18901 if (unlikely(overflow))
18902 call_on_stack(print_stack_overflow, isp);
18903@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18904 : "0" (irq), "1" (desc), "2" (isp),
18905 "D" (desc->handle_irq)
18906 : "memory", "cc", "ecx");
18907+
18908+#ifdef CONFIG_PAX_MEMORY_UDEREF
18909+ __set_fs(current_thread_info()->addr_limit);
18910+#endif
18911+
18912 return 1;
18913 }
18914
18915@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
18916 */
18917 void __cpuinit irq_ctx_init(int cpu)
18918 {
18919- union irq_ctx *irqctx;
18920-
18921 if (per_cpu(hardirq_ctx, cpu))
18922 return;
18923
18924- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18925- THREADINFO_GFP,
18926- THREAD_SIZE_ORDER));
18927- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18928- irqctx->tinfo.cpu = cpu;
18929- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
18930- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18931-
18932- per_cpu(hardirq_ctx, cpu) = irqctx;
18933-
18934- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
18935- THREADINFO_GFP,
18936- THREAD_SIZE_ORDER));
18937- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
18938- irqctx->tinfo.cpu = cpu;
18939- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
18940-
18941- per_cpu(softirq_ctx, cpu) = irqctx;
18942+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18943+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
18944+
18945+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18946+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18947
18948 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
18949 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
18950@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
18951 asmlinkage void do_softirq(void)
18952 {
18953 unsigned long flags;
18954- struct thread_info *curctx;
18955 union irq_ctx *irqctx;
18956 u32 *isp;
18957
18958@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
18959 local_irq_save(flags);
18960
18961 if (local_softirq_pending()) {
18962- curctx = current_thread_info();
18963 irqctx = __this_cpu_read(softirq_ctx);
18964- irqctx->tinfo.task = curctx->task;
18965- irqctx->tinfo.previous_esp = current_stack_pointer;
18966+ irqctx->previous_esp = current_stack_pointer;
18967
18968 /* build the stack frame on the softirq stack */
18969- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
18970+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
18971+
18972+#ifdef CONFIG_PAX_MEMORY_UDEREF
18973+ __set_fs(MAKE_MM_SEG(0));
18974+#endif
18975
18976 call_on_stack(__do_softirq, isp);
18977+
18978+#ifdef CONFIG_PAX_MEMORY_UDEREF
18979+ __set_fs(current_thread_info()->addr_limit);
18980+#endif
18981+
18982 /*
18983 * Shouldn't happen, we returned above if in_interrupt():
18984 */
18985@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
18986 if (unlikely(!desc))
18987 return false;
18988
18989- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18990+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
18991 if (unlikely(overflow))
18992 print_stack_overflow();
18993 desc->handle_irq(irq, desc);
18994diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
18995index d04d3ec..ea4b374 100644
18996--- a/arch/x86/kernel/irq_64.c
18997+++ b/arch/x86/kernel/irq_64.c
18998@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
18999 u64 estack_top, estack_bottom;
19000 u64 curbase = (u64)task_stack_page(current);
19001
19002- if (user_mode_vm(regs))
19003+ if (user_mode(regs))
19004 return;
19005
19006 if (regs->sp >= curbase + sizeof(struct thread_info) +
19007diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
19008index dc1404b..bbc43e7 100644
19009--- a/arch/x86/kernel/kdebugfs.c
19010+++ b/arch/x86/kernel/kdebugfs.c
19011@@ -27,7 +27,7 @@ struct setup_data_node {
19012 u32 len;
19013 };
19014
19015-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
19016+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
19017 size_t count, loff_t *ppos)
19018 {
19019 struct setup_data_node *node = file->private_data;
19020diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
19021index 836f832..a8bda67 100644
19022--- a/arch/x86/kernel/kgdb.c
19023+++ b/arch/x86/kernel/kgdb.c
19024@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
19025 #ifdef CONFIG_X86_32
19026 switch (regno) {
19027 case GDB_SS:
19028- if (!user_mode_vm(regs))
19029+ if (!user_mode(regs))
19030 *(unsigned long *)mem = __KERNEL_DS;
19031 break;
19032 case GDB_SP:
19033- if (!user_mode_vm(regs))
19034+ if (!user_mode(regs))
19035 *(unsigned long *)mem = kernel_stack_pointer(regs);
19036 break;
19037 case GDB_GS:
19038@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
19039 bp->attr.bp_addr = breakinfo[breakno].addr;
19040 bp->attr.bp_len = breakinfo[breakno].len;
19041 bp->attr.bp_type = breakinfo[breakno].type;
19042- info->address = breakinfo[breakno].addr;
19043+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
19044+ info->address = ktla_ktva(breakinfo[breakno].addr);
19045+ else
19046+ info->address = breakinfo[breakno].addr;
19047 info->len = breakinfo[breakno].len;
19048 info->type = breakinfo[breakno].type;
19049 val = arch_install_hw_breakpoint(bp);
19050@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
19051 case 'k':
19052 /* clear the trace bit */
19053 linux_regs->flags &= ~X86_EFLAGS_TF;
19054- atomic_set(&kgdb_cpu_doing_single_step, -1);
19055+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
19056
19057 /* set the trace bit if we're stepping */
19058 if (remcomInBuffer[0] == 's') {
19059 linux_regs->flags |= X86_EFLAGS_TF;
19060- atomic_set(&kgdb_cpu_doing_single_step,
19061+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
19062 raw_smp_processor_id());
19063 }
19064
19065@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
19066
19067 switch (cmd) {
19068 case DIE_DEBUG:
19069- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
19070+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
19071 if (user_mode(regs))
19072 return single_step_cont(regs, args);
19073 break;
19074@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19075 #endif /* CONFIG_DEBUG_RODATA */
19076
19077 bpt->type = BP_BREAKPOINT;
19078- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
19079+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
19080 BREAK_INSTR_SIZE);
19081 if (err)
19082 return err;
19083- err = probe_kernel_write((char *)bpt->bpt_addr,
19084+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19085 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
19086 #ifdef CONFIG_DEBUG_RODATA
19087 if (!err)
19088@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
19089 return -EBUSY;
19090 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
19091 BREAK_INSTR_SIZE);
19092- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19093+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19094 if (err)
19095 return err;
19096 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
19097@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
19098 if (mutex_is_locked(&text_mutex))
19099 goto knl_write;
19100 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
19101- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
19102+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
19103 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
19104 goto knl_write;
19105 return err;
19106 knl_write:
19107 #endif /* CONFIG_DEBUG_RODATA */
19108- return probe_kernel_write((char *)bpt->bpt_addr,
19109+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
19110 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
19111 }
19112
19113diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
19114index c5e410e..ed5a7f0 100644
19115--- a/arch/x86/kernel/kprobes-opt.c
19116+++ b/arch/x86/kernel/kprobes-opt.c
19117@@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19118 * Verify if the address gap is in 2GB range, because this uses
19119 * a relative jump.
19120 */
19121- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
19122+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
19123 if (abs(rel) > 0x7fffffff)
19124 return -ERANGE;
19125
19126@@ -353,16 +353,16 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
19127 op->optinsn.size = ret;
19128
19129 /* Copy arch-dep-instance from template */
19130- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
19131+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
19132
19133 /* Set probe information */
19134 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
19135
19136 /* Set probe function call */
19137- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
19138+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
19139
19140 /* Set returning jmp instruction at the tail of out-of-line buffer */
19141- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
19142+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
19143 (u8 *)op->kp.addr + op->optinsn.size);
19144
19145 flush_icache_range((unsigned long) buf,
19146@@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
19147 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
19148
19149 /* Backup instructions which will be replaced by jump address */
19150- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
19151+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
19152 RELATIVE_ADDR_SIZE);
19153
19154 insn_buf[0] = RELATIVEJUMP_OPCODE;
19155@@ -483,7 +483,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
19156 /* This kprobe is really able to run optimized path. */
19157 op = container_of(p, struct optimized_kprobe, kp);
19158 /* Detour through copied instructions */
19159- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
19160+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
19161 if (!reenter)
19162 reset_current_kprobe();
19163 preempt_enable_no_resched();
19164diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
19165index 57916c0..9e0b9d0 100644
19166--- a/arch/x86/kernel/kprobes.c
19167+++ b/arch/x86/kernel/kprobes.c
19168@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
19169 s32 raddr;
19170 } __attribute__((packed)) *insn;
19171
19172- insn = (struct __arch_relative_insn *)from;
19173+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
19174+
19175+ pax_open_kernel();
19176 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
19177 insn->op = op;
19178+ pax_close_kernel();
19179 }
19180
19181 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
19182@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
19183 kprobe_opcode_t opcode;
19184 kprobe_opcode_t *orig_opcodes = opcodes;
19185
19186- if (search_exception_tables((unsigned long)opcodes))
19187+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
19188 return 0; /* Page fault may occur on this address. */
19189
19190 retry:
19191@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
19192 * for the first byte, we can recover the original instruction
19193 * from it and kp->opcode.
19194 */
19195- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19196+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
19197 buf[0] = kp->opcode;
19198- return (unsigned long)buf;
19199+ return ktva_ktla((unsigned long)buf);
19200 }
19201
19202 /*
19203@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19204 /* Another subsystem puts a breakpoint, failed to recover */
19205 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
19206 return 0;
19207+ pax_open_kernel();
19208 memcpy(dest, insn.kaddr, insn.length);
19209+ pax_close_kernel();
19210
19211 #ifdef CONFIG_X86_64
19212 if (insn_rip_relative(&insn)) {
19213@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
19214 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
19215 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
19216 disp = (u8 *) dest + insn_offset_displacement(&insn);
19217+ pax_open_kernel();
19218 *(s32 *) disp = (s32) newdisp;
19219+ pax_close_kernel();
19220 }
19221 #endif
19222 return insn.length;
19223@@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19224 * nor set current_kprobe, because it doesn't use single
19225 * stepping.
19226 */
19227- regs->ip = (unsigned long)p->ainsn.insn;
19228+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19229 preempt_enable_no_resched();
19230 return;
19231 }
19232@@ -502,9 +509,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
19233 regs->flags &= ~X86_EFLAGS_IF;
19234 /* single step inline if the instruction is an int3 */
19235 if (p->opcode == BREAKPOINT_INSTRUCTION)
19236- regs->ip = (unsigned long)p->addr;
19237+ regs->ip = ktla_ktva((unsigned long)p->addr);
19238 else
19239- regs->ip = (unsigned long)p->ainsn.insn;
19240+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
19241 }
19242
19243 /*
19244@@ -600,7 +607,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
19245 setup_singlestep(p, regs, kcb, 0);
19246 return 1;
19247 }
19248- } else if (*addr != BREAKPOINT_INSTRUCTION) {
19249+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
19250 /*
19251 * The breakpoint instruction was removed right
19252 * after we hit it. Another cpu has removed
19253@@ -651,6 +658,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
19254 " movq %rax, 152(%rsp)\n"
19255 RESTORE_REGS_STRING
19256 " popfq\n"
19257+#ifdef KERNEXEC_PLUGIN
19258+ " btsq $63,(%rsp)\n"
19259+#endif
19260 #else
19261 " pushf\n"
19262 SAVE_REGS_STRING
19263@@ -788,7 +798,7 @@ static void __kprobes
19264 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
19265 {
19266 unsigned long *tos = stack_addr(regs);
19267- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
19268+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
19269 unsigned long orig_ip = (unsigned long)p->addr;
19270 kprobe_opcode_t *insn = p->ainsn.insn;
19271
19272@@ -970,7 +980,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
19273 struct die_args *args = data;
19274 int ret = NOTIFY_DONE;
19275
19276- if (args->regs && user_mode_vm(args->regs))
19277+ if (args->regs && user_mode(args->regs))
19278 return ret;
19279
19280 switch (val) {
19281diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
19282index 4180a87..4678e4f 100644
19283--- a/arch/x86/kernel/kvm.c
19284+++ b/arch/x86/kernel/kvm.c
19285@@ -267,7 +267,7 @@ static void __init paravirt_ops_setup(void)
19286 pv_info.paravirt_enabled = 1;
19287
19288 if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
19289- pv_cpu_ops.io_delay = kvm_io_delay;
19290+ *(void **)&pv_cpu_ops.io_delay = kvm_io_delay;
19291
19292 #ifdef CONFIG_X86_IO_APIC
19293 no_timer_check = 1;
19294@@ -461,18 +461,18 @@ void __init kvm_guest_init(void)
19295 for (i = 0; i < KVM_TASK_SLEEP_HASHSIZE; i++)
19296 spin_lock_init(&async_pf_sleepers[i].lock);
19297 if (kvm_para_has_feature(KVM_FEATURE_ASYNC_PF))
19298- x86_init.irqs.trap_init = kvm_apf_trap_init;
19299+ *(void **)&x86_init.irqs.trap_init = kvm_apf_trap_init;
19300
19301 if (kvm_para_has_feature(KVM_FEATURE_STEAL_TIME)) {
19302 has_steal_clock = 1;
19303- pv_time_ops.steal_clock = kvm_steal_clock;
19304+ *(void **)&pv_time_ops.steal_clock = kvm_steal_clock;
19305 }
19306
19307 if (kvm_para_has_feature(KVM_FEATURE_PV_EOI))
19308 apic_set_eoi_write(kvm_guest_apic_eoi_write);
19309
19310 #ifdef CONFIG_SMP
19311- smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19312+ *(void **)&smp_ops.smp_prepare_boot_cpu = kvm_smp_prepare_boot_cpu;
19313 register_cpu_notifier(&kvm_cpu_notifier);
19314 #else
19315 kvm_guest_cpu_init();
19316diff --git a/arch/x86/kernel/kvmclock.c b/arch/x86/kernel/kvmclock.c
19317index f1b42b3..27ac4e7 100644
19318--- a/arch/x86/kernel/kvmclock.c
19319+++ b/arch/x86/kernel/kvmclock.c
19320@@ -211,19 +211,19 @@ void __init kvmclock_init(void)
19321
19322 if (kvm_register_clock("boot clock"))
19323 return;
19324- pv_time_ops.sched_clock = kvm_clock_read;
19325- x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19326- x86_platform.get_wallclock = kvm_get_wallclock;
19327- x86_platform.set_wallclock = kvm_set_wallclock;
19328+ *(void **)&pv_time_ops.sched_clock = kvm_clock_read;
19329+ *(void **)&x86_platform.calibrate_tsc = kvm_get_tsc_khz;
19330+ *(void **)&x86_platform.get_wallclock = kvm_get_wallclock;
19331+ *(void **)&x86_platform.set_wallclock = kvm_set_wallclock;
19332 #ifdef CONFIG_X86_LOCAL_APIC
19333- x86_cpuinit.early_percpu_clock_init =
19334+ *(void **)&x86_cpuinit.early_percpu_clock_init =
19335 kvm_setup_secondary_clock;
19336 #endif
19337- x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19338- x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19339- machine_ops.shutdown = kvm_shutdown;
19340+ *(void **)&x86_platform.save_sched_clock_state = kvm_save_sched_clock_state;
19341+ *(void **)&x86_platform.restore_sched_clock_state = kvm_restore_sched_clock_state;
19342+ *(void **)&machine_ops.shutdown = kvm_shutdown;
19343 #ifdef CONFIG_KEXEC
19344- machine_ops.crash_shutdown = kvm_crash_shutdown;
19345+ *(void **)&machine_ops.crash_shutdown = kvm_crash_shutdown;
19346 #endif
19347 kvm_get_preset_lpj();
19348 clocksource_register_hz(&kvm_clock, NSEC_PER_SEC);
19349diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
19350index ebc9873..1b9724b 100644
19351--- a/arch/x86/kernel/ldt.c
19352+++ b/arch/x86/kernel/ldt.c
19353@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
19354 if (reload) {
19355 #ifdef CONFIG_SMP
19356 preempt_disable();
19357- load_LDT(pc);
19358+ load_LDT_nolock(pc);
19359 if (!cpumask_equal(mm_cpumask(current->mm),
19360 cpumask_of(smp_processor_id())))
19361 smp_call_function(flush_ldt, current->mm, 1);
19362 preempt_enable();
19363 #else
19364- load_LDT(pc);
19365+ load_LDT_nolock(pc);
19366 #endif
19367 }
19368 if (oldsize) {
19369@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
19370 return err;
19371
19372 for (i = 0; i < old->size; i++)
19373- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
19374+ write_ldt_entry(new->ldt, i, old->ldt + i);
19375 return 0;
19376 }
19377
19378@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
19379 retval = copy_ldt(&mm->context, &old_mm->context);
19380 mutex_unlock(&old_mm->context.lock);
19381 }
19382+
19383+ if (tsk == current) {
19384+ mm->context.vdso = 0;
19385+
19386+#ifdef CONFIG_X86_32
19387+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19388+ mm->context.user_cs_base = 0UL;
19389+ mm->context.user_cs_limit = ~0UL;
19390+
19391+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
19392+ cpus_clear(mm->context.cpu_user_cs_mask);
19393+#endif
19394+
19395+#endif
19396+#endif
19397+
19398+ }
19399+
19400 return retval;
19401 }
19402
19403@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
19404 }
19405 }
19406
19407+#ifdef CONFIG_PAX_SEGMEXEC
19408+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
19409+ error = -EINVAL;
19410+ goto out_unlock;
19411+ }
19412+#endif
19413+
19414 fill_ldt(&ldt, &ldt_info);
19415 if (oldmode)
19416 ldt.avl = 0;
19417diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
19418index 5b19e4d..6476a76 100644
19419--- a/arch/x86/kernel/machine_kexec_32.c
19420+++ b/arch/x86/kernel/machine_kexec_32.c
19421@@ -26,7 +26,7 @@
19422 #include <asm/cacheflush.h>
19423 #include <asm/debugreg.h>
19424
19425-static void set_idt(void *newidt, __u16 limit)
19426+static void set_idt(struct desc_struct *newidt, __u16 limit)
19427 {
19428 struct desc_ptr curidt;
19429
19430@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
19431 }
19432
19433
19434-static void set_gdt(void *newgdt, __u16 limit)
19435+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
19436 {
19437 struct desc_ptr curgdt;
19438
19439@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
19440 }
19441
19442 control_page = page_address(image->control_code_page);
19443- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
19444+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
19445
19446 relocate_kernel_ptr = control_page;
19447 page_list[PA_CONTROL_PAGE] = __pa(control_page);
19448diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
19449index 3544aed..01ddc1c 100644
19450--- a/arch/x86/kernel/microcode_intel.c
19451+++ b/arch/x86/kernel/microcode_intel.c
19452@@ -431,13 +431,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
19453
19454 static int get_ucode_user(void *to, const void *from, size_t n)
19455 {
19456- return copy_from_user(to, from, n);
19457+ return copy_from_user(to, (const void __force_user *)from, n);
19458 }
19459
19460 static enum ucode_state
19461 request_microcode_user(int cpu, const void __user *buf, size_t size)
19462 {
19463- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
19464+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
19465 }
19466
19467 static void microcode_fini_cpu(int cpu)
19468diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
19469index 216a4d7..b328f09 100644
19470--- a/arch/x86/kernel/module.c
19471+++ b/arch/x86/kernel/module.c
19472@@ -43,15 +43,60 @@ do { \
19473 } while (0)
19474 #endif
19475
19476-void *module_alloc(unsigned long size)
19477+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
19478 {
19479- if (PAGE_ALIGN(size) > MODULES_LEN)
19480+ if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
19481 return NULL;
19482 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
19483- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
19484+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
19485 -1, __builtin_return_address(0));
19486 }
19487
19488+void *module_alloc(unsigned long size)
19489+{
19490+
19491+#ifdef CONFIG_PAX_KERNEXEC
19492+ return __module_alloc(size, PAGE_KERNEL);
19493+#else
19494+ return __module_alloc(size, PAGE_KERNEL_EXEC);
19495+#endif
19496+
19497+}
19498+
19499+#ifdef CONFIG_PAX_KERNEXEC
19500+#ifdef CONFIG_X86_32
19501+void *module_alloc_exec(unsigned long size)
19502+{
19503+ struct vm_struct *area;
19504+
19505+ if (size == 0)
19506+ return NULL;
19507+
19508+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
19509+ return area ? area->addr : NULL;
19510+}
19511+EXPORT_SYMBOL(module_alloc_exec);
19512+
19513+void module_free_exec(struct module *mod, void *module_region)
19514+{
19515+ vunmap(module_region);
19516+}
19517+EXPORT_SYMBOL(module_free_exec);
19518+#else
19519+void module_free_exec(struct module *mod, void *module_region)
19520+{
19521+ module_free(mod, module_region);
19522+}
19523+EXPORT_SYMBOL(module_free_exec);
19524+
19525+void *module_alloc_exec(unsigned long size)
19526+{
19527+ return __module_alloc(size, PAGE_KERNEL_RX);
19528+}
19529+EXPORT_SYMBOL(module_alloc_exec);
19530+#endif
19531+#endif
19532+
19533 #ifdef CONFIG_X86_32
19534 int apply_relocate(Elf32_Shdr *sechdrs,
19535 const char *strtab,
19536@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19537 unsigned int i;
19538 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
19539 Elf32_Sym *sym;
19540- uint32_t *location;
19541+ uint32_t *plocation, location;
19542
19543 DEBUGP("Applying relocate section %u to %u\n",
19544 relsec, sechdrs[relsec].sh_info);
19545 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
19546 /* This is where to make the change */
19547- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
19548- + rel[i].r_offset;
19549+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
19550+ location = (uint32_t)plocation;
19551+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
19552+ plocation = ktla_ktva((void *)plocation);
19553 /* This is the symbol it is referring to. Note that all
19554 undefined symbols have been resolved. */
19555 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
19556@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
19557 switch (ELF32_R_TYPE(rel[i].r_info)) {
19558 case R_386_32:
19559 /* We add the value into the location given */
19560- *location += sym->st_value;
19561+ pax_open_kernel();
19562+ *plocation += sym->st_value;
19563+ pax_close_kernel();
19564 break;
19565 case R_386_PC32:
19566 /* Add the value, subtract its position */
19567- *location += sym->st_value - (uint32_t)location;
19568+ pax_open_kernel();
19569+ *plocation += sym->st_value - location;
19570+ pax_close_kernel();
19571 break;
19572 default:
19573 pr_err("%s: Unknown relocation: %u\n",
19574@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
19575 case R_X86_64_NONE:
19576 break;
19577 case R_X86_64_64:
19578+ pax_open_kernel();
19579 *(u64 *)loc = val;
19580+ pax_close_kernel();
19581 break;
19582 case R_X86_64_32:
19583+ pax_open_kernel();
19584 *(u32 *)loc = val;
19585+ pax_close_kernel();
19586 if (val != *(u32 *)loc)
19587 goto overflow;
19588 break;
19589 case R_X86_64_32S:
19590+ pax_open_kernel();
19591 *(s32 *)loc = val;
19592+ pax_close_kernel();
19593 if ((s64)val != *(s32 *)loc)
19594 goto overflow;
19595 break;
19596 case R_X86_64_PC32:
19597 val -= (u64)loc;
19598+ pax_open_kernel();
19599 *(u32 *)loc = val;
19600+ pax_close_kernel();
19601+
19602 #if 0
19603 if ((s64)val != *(s32 *)loc)
19604 goto overflow;
19605diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
19606index f84f5c5..e27e54b 100644
19607--- a/arch/x86/kernel/nmi.c
19608+++ b/arch/x86/kernel/nmi.c
19609@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
19610 dotraplinkage notrace __kprobes void
19611 do_nmi(struct pt_regs *regs, long error_code)
19612 {
19613+
19614+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19615+ if (!user_mode(regs)) {
19616+ unsigned long cs = regs->cs & 0xFFFF;
19617+ unsigned long ip = ktva_ktla(regs->ip);
19618+
19619+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
19620+ regs->ip = ip;
19621+ }
19622+#endif
19623+
19624 nmi_nesting_preprocess(regs);
19625
19626 nmi_enter();
19627diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
19628index 676b8c7..870ba04 100644
19629--- a/arch/x86/kernel/paravirt-spinlocks.c
19630+++ b/arch/x86/kernel/paravirt-spinlocks.c
19631@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
19632 arch_spin_lock(lock);
19633 }
19634
19635-struct pv_lock_ops pv_lock_ops = {
19636+struct pv_lock_ops pv_lock_ops __read_only = {
19637 #ifdef CONFIG_SMP
19638 .spin_is_locked = __ticket_spin_is_locked,
19639 .spin_is_contended = __ticket_spin_is_contended,
19640diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
19641index 17fff18..0f5f957 100644
19642--- a/arch/x86/kernel/paravirt.c
19643+++ b/arch/x86/kernel/paravirt.c
19644@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
19645 {
19646 return x;
19647 }
19648+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19649+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
19650+#endif
19651
19652 void __init default_banner(void)
19653 {
19654@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
19655 if (opfunc == NULL)
19656 /* If there's no function, patch it with a ud2a (BUG) */
19657 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
19658- else if (opfunc == _paravirt_nop)
19659+ else if (opfunc == (void *)_paravirt_nop)
19660 /* If the operation is a nop, then nop the callsite */
19661 ret = paravirt_patch_nop();
19662
19663 /* identity functions just return their single argument */
19664- else if (opfunc == _paravirt_ident_32)
19665+ else if (opfunc == (void *)_paravirt_ident_32)
19666 ret = paravirt_patch_ident_32(insnbuf, len);
19667- else if (opfunc == _paravirt_ident_64)
19668+ else if (opfunc == (void *)_paravirt_ident_64)
19669 ret = paravirt_patch_ident_64(insnbuf, len);
19670+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
19671+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
19672+ ret = paravirt_patch_ident_64(insnbuf, len);
19673+#endif
19674
19675 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
19676 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
19677@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
19678 if (insn_len > len || start == NULL)
19679 insn_len = len;
19680 else
19681- memcpy(insnbuf, start, insn_len);
19682+ memcpy(insnbuf, ktla_ktva(start), insn_len);
19683
19684 return insn_len;
19685 }
19686@@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
19687 preempt_enable();
19688 }
19689
19690-struct pv_info pv_info = {
19691+struct pv_info pv_info __read_only = {
19692 .name = "bare hardware",
19693 .paravirt_enabled = 0,
19694 .kernel_rpl = 0,
19695@@ -324,7 +331,7 @@ struct pv_time_ops pv_time_ops = {
19696 .steal_clock = native_steal_clock,
19697 };
19698
19699-struct pv_irq_ops pv_irq_ops = {
19700+struct pv_irq_ops pv_irq_ops __read_only = {
19701 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
19702 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
19703 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
19704@@ -401,15 +408,20 @@ struct pv_apic_ops pv_apic_ops = {
19705 #endif
19706 };
19707
19708-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
19709+#ifdef CONFIG_X86_32
19710+#ifdef CONFIG_X86_PAE
19711+/* 64-bit pagetable entries */
19712+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
19713+#else
19714 /* 32-bit pagetable entries */
19715 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
19716+#endif
19717 #else
19718 /* 64-bit pagetable entries */
19719 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
19720 #endif
19721
19722-struct pv_mmu_ops pv_mmu_ops = {
19723+struct pv_mmu_ops pv_mmu_ops __read_only = {
19724
19725 .read_cr2 = native_read_cr2,
19726 .write_cr2 = native_write_cr2,
19727@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
19728 .make_pud = PTE_IDENT,
19729
19730 .set_pgd = native_set_pgd,
19731+ .set_pgd_batched = native_set_pgd_batched,
19732 #endif
19733 #endif /* PAGETABLE_LEVELS >= 3 */
19734
19735@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
19736 },
19737
19738 .set_fixmap = native_set_fixmap,
19739+
19740+#ifdef CONFIG_PAX_KERNEXEC
19741+ .pax_open_kernel = native_pax_open_kernel,
19742+ .pax_close_kernel = native_pax_close_kernel,
19743+#endif
19744+
19745 };
19746
19747 EXPORT_SYMBOL_GPL(pv_time_ops);
19748diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
19749index 299d493..79c13dd 100644
19750--- a/arch/x86/kernel/pci-calgary_64.c
19751+++ b/arch/x86/kernel/pci-calgary_64.c
19752@@ -1461,7 +1461,7 @@ int __init detect_calgary(void)
19753 printk(KERN_INFO "PCI-DMA: Calgary TCE table spec is %d\n",
19754 specified_table_size);
19755
19756- x86_init.iommu.iommu_init = calgary_iommu_init;
19757+ *(void **)&x86_init.iommu.iommu_init = calgary_iommu_init;
19758 }
19759 return calgary_found;
19760
19761diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
19762index 35ccf75..7a15747 100644
19763--- a/arch/x86/kernel/pci-iommu_table.c
19764+++ b/arch/x86/kernel/pci-iommu_table.c
19765@@ -2,7 +2,7 @@
19766 #include <asm/iommu_table.h>
19767 #include <linux/string.h>
19768 #include <linux/kallsyms.h>
19769-
19770+#include <linux/sched.h>
19771
19772 #define DEBUG 1
19773
19774diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
19775index b644e1c..4a6d379 100644
19776--- a/arch/x86/kernel/process.c
19777+++ b/arch/x86/kernel/process.c
19778@@ -36,7 +36,8 @@
19779 * section. Since TSS's are completely CPU-local, we want them
19780 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
19781 */
19782-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
19783+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
19784+EXPORT_SYMBOL(init_tss);
19785
19786 #ifdef CONFIG_X86_64
19787 static DEFINE_PER_CPU(unsigned char, is_idle);
19788@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
19789 task_xstate_cachep =
19790 kmem_cache_create("task_xstate", xstate_size,
19791 __alignof__(union thread_xstate),
19792- SLAB_PANIC | SLAB_NOTRACK, NULL);
19793+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
19794 }
19795
19796 /*
19797@@ -105,7 +106,7 @@ void exit_thread(void)
19798 unsigned long *bp = t->io_bitmap_ptr;
19799
19800 if (bp) {
19801- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
19802+ struct tss_struct *tss = init_tss + get_cpu();
19803
19804 t->io_bitmap_ptr = NULL;
19805 clear_thread_flag(TIF_IO_BITMAP);
19806@@ -136,7 +137,7 @@ void show_regs_common(void)
19807 board = dmi_get_system_info(DMI_BOARD_NAME);
19808
19809 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
19810- current->pid, current->comm, print_tainted(),
19811+ task_pid_nr(current), current->comm, print_tainted(),
19812 init_utsname()->release,
19813 (int)strcspn(init_utsname()->version, " "),
19814 init_utsname()->version,
19815@@ -149,6 +150,9 @@ void flush_thread(void)
19816 {
19817 struct task_struct *tsk = current;
19818
19819+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19820+ loadsegment(gs, 0);
19821+#endif
19822 flush_ptrace_hw_breakpoint(tsk);
19823 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
19824 drop_init_fpu(tsk);
19825@@ -336,7 +340,7 @@ static void __exit_idle(void)
19826 void exit_idle(void)
19827 {
19828 /* idle loop has pid 0 */
19829- if (current->pid)
19830+ if (task_pid_nr(current))
19831 return;
19832 __exit_idle();
19833 }
19834@@ -445,7 +449,7 @@ bool set_pm_idle_to_default(void)
19835
19836 return ret;
19837 }
19838-void stop_this_cpu(void *dummy)
19839+__noreturn void stop_this_cpu(void *dummy)
19840 {
19841 local_irq_disable();
19842 /*
19843@@ -673,16 +677,37 @@ static int __init idle_setup(char *str)
19844 }
19845 early_param("idle", idle_setup);
19846
19847-unsigned long arch_align_stack(unsigned long sp)
19848+#ifdef CONFIG_PAX_RANDKSTACK
19849+void pax_randomize_kstack(struct pt_regs *regs)
19850 {
19851- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
19852- sp -= get_random_int() % 8192;
19853- return sp & ~0xf;
19854-}
19855+ struct thread_struct *thread = &current->thread;
19856+ unsigned long time;
19857
19858-unsigned long arch_randomize_brk(struct mm_struct *mm)
19859-{
19860- unsigned long range_end = mm->brk + 0x02000000;
19861- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
19862-}
19863+ if (!randomize_va_space)
19864+ return;
19865+
19866+ if (v8086_mode(regs))
19867+ return;
19868
19869+ rdtscl(time);
19870+
19871+ /* P4 seems to return a 0 LSB, ignore it */
19872+#ifdef CONFIG_MPENTIUM4
19873+ time &= 0x3EUL;
19874+ time <<= 2;
19875+#elif defined(CONFIG_X86_64)
19876+ time &= 0xFUL;
19877+ time <<= 4;
19878+#else
19879+ time &= 0x1FUL;
19880+ time <<= 3;
19881+#endif
19882+
19883+ thread->sp0 ^= time;
19884+ load_sp0(init_tss + smp_processor_id(), thread);
19885+
19886+#ifdef CONFIG_X86_64
19887+ this_cpu_write(kernel_stack, thread->sp0);
19888+#endif
19889+}
19890+#endif
19891diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
19892index 44e0bff..5ceb99c 100644
19893--- a/arch/x86/kernel/process_32.c
19894+++ b/arch/x86/kernel/process_32.c
19895@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
19896 unsigned long thread_saved_pc(struct task_struct *tsk)
19897 {
19898 return ((unsigned long *)tsk->thread.sp)[3];
19899+//XXX return tsk->thread.eip;
19900 }
19901
19902 void __show_regs(struct pt_regs *regs, int all)
19903@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
19904 unsigned long sp;
19905 unsigned short ss, gs;
19906
19907- if (user_mode_vm(regs)) {
19908+ if (user_mode(regs)) {
19909 sp = regs->sp;
19910 ss = regs->ss & 0xffff;
19911- gs = get_user_gs(regs);
19912 } else {
19913 sp = kernel_stack_pointer(regs);
19914 savesegment(ss, ss);
19915- savesegment(gs, gs);
19916 }
19917+ gs = get_user_gs(regs);
19918
19919 show_regs_common();
19920
19921 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
19922 (u16)regs->cs, regs->ip, regs->flags,
19923- smp_processor_id());
19924+ raw_smp_processor_id());
19925 print_symbol("EIP is at %s\n", regs->ip);
19926
19927 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
19928@@ -131,20 +131,21 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
19929 unsigned long arg,
19930 struct task_struct *p, struct pt_regs *regs)
19931 {
19932- struct pt_regs *childregs = task_pt_regs(p);
19933+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
19934 struct task_struct *tsk;
19935 int err;
19936
19937 p->thread.sp = (unsigned long) childregs;
19938 p->thread.sp0 = (unsigned long) (childregs+1);
19939+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
19940
19941 if (unlikely(!regs)) {
19942 /* kernel thread */
19943 memset(childregs, 0, sizeof(struct pt_regs));
19944 p->thread.ip = (unsigned long) ret_from_kernel_thread;
19945- task_user_gs(p) = __KERNEL_STACK_CANARY;
19946- childregs->ds = __USER_DS;
19947- childregs->es = __USER_DS;
19948+ savesegment(gs, childregs->gs);
19949+ childregs->ds = __KERNEL_DS;
19950+ childregs->es = __KERNEL_DS;
19951 childregs->fs = __KERNEL_PERCPU;
19952 childregs->bx = sp; /* function */
19953 childregs->bp = arg;
19954@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19955 struct thread_struct *prev = &prev_p->thread,
19956 *next = &next_p->thread;
19957 int cpu = smp_processor_id();
19958- struct tss_struct *tss = &per_cpu(init_tss, cpu);
19959+ struct tss_struct *tss = init_tss + cpu;
19960 fpu_switch_t fpu;
19961
19962 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
19963@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19964 */
19965 lazy_save_gs(prev->gs);
19966
19967+#ifdef CONFIG_PAX_MEMORY_UDEREF
19968+ __set_fs(task_thread_info(next_p)->addr_limit);
19969+#endif
19970+
19971 /*
19972 * Load the per-thread Thread-Local Storage descriptor.
19973 */
19974@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19975 */
19976 arch_end_context_switch(next_p);
19977
19978+ this_cpu_write(current_task, next_p);
19979+ this_cpu_write(current_tinfo, &next_p->tinfo);
19980+
19981 /*
19982 * Restore %gs if needed (which is common)
19983 */
19984@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
19985
19986 switch_fpu_finish(next_p, fpu);
19987
19988- this_cpu_write(current_task, next_p);
19989-
19990 return prev_p;
19991 }
19992
19993@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
19994 } while (count++ < 16);
19995 return 0;
19996 }
19997-
19998diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
19999index 16c6365..5d32218 100644
20000--- a/arch/x86/kernel/process_64.c
20001+++ b/arch/x86/kernel/process_64.c
20002@@ -153,10 +153,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
20003 struct pt_regs *childregs;
20004 struct task_struct *me = current;
20005
20006- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
20007+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
20008 childregs = task_pt_regs(p);
20009 p->thread.sp = (unsigned long) childregs;
20010 p->thread.usersp = me->thread.usersp;
20011+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
20012 set_tsk_thread_flag(p, TIF_FORK);
20013 p->fpu_counter = 0;
20014 p->thread.io_bitmap_ptr = NULL;
20015@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20016 struct thread_struct *prev = &prev_p->thread;
20017 struct thread_struct *next = &next_p->thread;
20018 int cpu = smp_processor_id();
20019- struct tss_struct *tss = &per_cpu(init_tss, cpu);
20020+ struct tss_struct *tss = init_tss + cpu;
20021 unsigned fsindex, gsindex;
20022 fpu_switch_t fpu;
20023
20024@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
20025 prev->usersp = this_cpu_read(old_rsp);
20026 this_cpu_write(old_rsp, next->usersp);
20027 this_cpu_write(current_task, next_p);
20028+ this_cpu_write(current_tinfo, &next_p->tinfo);
20029
20030- this_cpu_write(kernel_stack,
20031- (unsigned long)task_stack_page(next_p) +
20032- THREAD_SIZE - KERNEL_STACK_OFFSET);
20033+ this_cpu_write(kernel_stack, next->sp0);
20034
20035 /*
20036 * Now maybe reload the debug registers and handle I/O bitmaps
20037@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
20038 if (!p || p == current || p->state == TASK_RUNNING)
20039 return 0;
20040 stack = (unsigned long)task_stack_page(p);
20041- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
20042+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
20043 return 0;
20044 fp = *(u64 *)(p->thread.sp);
20045 do {
20046- if (fp < (unsigned long)stack ||
20047- fp >= (unsigned long)stack+THREAD_SIZE)
20048+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
20049 return 0;
20050 ip = *(u64 *)(fp+8);
20051 if (!in_sched_functions(ip))
20052diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
20053index 974b67e..12cb2b5 100644
20054--- a/arch/x86/kernel/ptrace.c
20055+++ b/arch/x86/kernel/ptrace.c
20056@@ -183,14 +183,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
20057 {
20058 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
20059 unsigned long sp = (unsigned long)&regs->sp;
20060- struct thread_info *tinfo;
20061
20062- if (context == (sp & ~(THREAD_SIZE - 1)))
20063+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
20064 return sp;
20065
20066- tinfo = (struct thread_info *)context;
20067- if (tinfo->previous_esp)
20068- return tinfo->previous_esp;
20069+ sp = *(unsigned long *)context;
20070+ if (sp)
20071+ return sp;
20072
20073 return (unsigned long)regs;
20074 }
20075@@ -587,7 +586,7 @@ static void ptrace_triggered(struct perf_event *bp,
20076 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
20077 {
20078 int i;
20079- int dr7 = 0;
20080+ unsigned long dr7 = 0;
20081 struct arch_hw_breakpoint *info;
20082
20083 for (i = 0; i < HBP_NUM; i++) {
20084@@ -855,7 +854,7 @@ long arch_ptrace(struct task_struct *child, long request,
20085 unsigned long addr, unsigned long data)
20086 {
20087 int ret;
20088- unsigned long __user *datap = (unsigned long __user *)data;
20089+ unsigned long __user *datap = (__force unsigned long __user *)data;
20090
20091 switch (request) {
20092 /* read the word at location addr in the USER area. */
20093@@ -940,14 +939,14 @@ long arch_ptrace(struct task_struct *child, long request,
20094 if ((int) addr < 0)
20095 return -EIO;
20096 ret = do_get_thread_area(child, addr,
20097- (struct user_desc __user *)data);
20098+ (__force struct user_desc __user *) data);
20099 break;
20100
20101 case PTRACE_SET_THREAD_AREA:
20102 if ((int) addr < 0)
20103 return -EIO;
20104 ret = do_set_thread_area(child, addr,
20105- (struct user_desc __user *)data, 0);
20106+ (__force struct user_desc __user *) data, 0);
20107 break;
20108 #endif
20109
20110@@ -1325,7 +1324,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
20111
20112 #ifdef CONFIG_X86_64
20113
20114-static struct user_regset x86_64_regsets[] __read_mostly = {
20115+static struct user_regset x86_64_regsets[] = {
20116 [REGSET_GENERAL] = {
20117 .core_note_type = NT_PRSTATUS,
20118 .n = sizeof(struct user_regs_struct) / sizeof(long),
20119@@ -1366,7 +1365,7 @@ static const struct user_regset_view user_x86_64_view = {
20120 #endif /* CONFIG_X86_64 */
20121
20122 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20123-static struct user_regset x86_32_regsets[] __read_mostly = {
20124+static struct user_regset x86_32_regsets[] = {
20125 [REGSET_GENERAL] = {
20126 .core_note_type = NT_PRSTATUS,
20127 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
20128@@ -1419,13 +1418,13 @@ static const struct user_regset_view user_x86_32_view = {
20129 */
20130 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
20131
20132-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20133+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
20134 {
20135 #ifdef CONFIG_X86_64
20136- x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20137+ *(unsigned int *)&x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20138 #endif
20139 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
20140- x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20141+ *(unsigned int *)&x86_32_regsets[REGSET_XSTATE].n = size / sizeof(u64);
20142 #endif
20143 xstate_fx_sw_bytes[USER_XSTATE_XCR0_WORD] = xstate_mask;
20144 }
20145@@ -1454,7 +1453,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
20146 memset(info, 0, sizeof(*info));
20147 info->si_signo = SIGTRAP;
20148 info->si_code = si_code;
20149- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
20150+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
20151 }
20152
20153 void user_single_step_siginfo(struct task_struct *tsk,
20154@@ -1483,6 +1482,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
20155 # define IS_IA32 0
20156 #endif
20157
20158+#ifdef CONFIG_GRKERNSEC_SETXID
20159+extern void gr_delayed_cred_worker(void);
20160+#endif
20161+
20162 /*
20163 * We must return the syscall number to actually look up in the table.
20164 * This can be -1L to skip running any syscall at all.
20165@@ -1493,6 +1496,11 @@ long syscall_trace_enter(struct pt_regs *regs)
20166
20167 rcu_user_exit();
20168
20169+#ifdef CONFIG_GRKERNSEC_SETXID
20170+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20171+ gr_delayed_cred_worker();
20172+#endif
20173+
20174 /*
20175 * If we stepped into a sysenter/syscall insn, it trapped in
20176 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
20177@@ -1548,6 +1556,11 @@ void syscall_trace_leave(struct pt_regs *regs)
20178 */
20179 rcu_user_exit();
20180
20181+#ifdef CONFIG_GRKERNSEC_SETXID
20182+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
20183+ gr_delayed_cred_worker();
20184+#endif
20185+
20186 audit_syscall_exit(regs);
20187
20188 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
20189diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
20190index 42eb330..139955c 100644
20191--- a/arch/x86/kernel/pvclock.c
20192+++ b/arch/x86/kernel/pvclock.c
20193@@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
20194 return pv_tsc_khz;
20195 }
20196
20197-static atomic64_t last_value = ATOMIC64_INIT(0);
20198+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
20199
20200 void pvclock_resume(void)
20201 {
20202- atomic64_set(&last_value, 0);
20203+ atomic64_set_unchecked(&last_value, 0);
20204 }
20205
20206 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20207@@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
20208 * updating at the same time, and one of them could be slightly behind,
20209 * making the assumption that last_value always go forward fail to hold.
20210 */
20211- last = atomic64_read(&last_value);
20212+ last = atomic64_read_unchecked(&last_value);
20213 do {
20214 if (ret < last)
20215 return last;
20216- last = atomic64_cmpxchg(&last_value, last, ret);
20217+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
20218 } while (unlikely(last != ret));
20219
20220 return ret;
20221diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
20222index 4e8ba39..e0186b3 100644
20223--- a/arch/x86/kernel/reboot.c
20224+++ b/arch/x86/kernel/reboot.c
20225@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
20226 EXPORT_SYMBOL(pm_power_off);
20227
20228 static const struct desc_ptr no_idt = {};
20229-static int reboot_mode;
20230+static unsigned short reboot_mode;
20231 enum reboot_type reboot_type = BOOT_ACPI;
20232 int reboot_force;
20233
20234@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
20235
20236 void __noreturn machine_real_restart(unsigned int type)
20237 {
20238+
20239+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20240+ struct desc_struct *gdt;
20241+#endif
20242+
20243 local_irq_disable();
20244
20245 /*
20246@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
20247
20248 /* Jump to the identity-mapped low memory code */
20249 #ifdef CONFIG_X86_32
20250- asm volatile("jmpl *%0" : :
20251+
20252+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20253+ gdt = get_cpu_gdt_table(smp_processor_id());
20254+ pax_open_kernel();
20255+#ifdef CONFIG_PAX_MEMORY_UDEREF
20256+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
20257+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
20258+ loadsegment(ds, __KERNEL_DS);
20259+ loadsegment(es, __KERNEL_DS);
20260+ loadsegment(ss, __KERNEL_DS);
20261+#endif
20262+#ifdef CONFIG_PAX_KERNEXEC
20263+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
20264+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
20265+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
20266+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
20267+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
20268+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
20269+#endif
20270+ pax_close_kernel();
20271+#endif
20272+
20273+ asm volatile("ljmpl *%0" : :
20274 "rm" (real_mode_header->machine_real_restart_asm),
20275 "a" (type));
20276 #else
20277@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
20278 * try to force a triple fault and then cycle between hitting the keyboard
20279 * controller and doing that
20280 */
20281-static void native_machine_emergency_restart(void)
20282+static void __noreturn native_machine_emergency_restart(void)
20283 {
20284 int i;
20285 int attempt = 0;
20286@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
20287 #endif
20288 }
20289
20290-static void __machine_emergency_restart(int emergency)
20291+static void __noreturn __machine_emergency_restart(int emergency)
20292 {
20293 reboot_emergency = emergency;
20294 machine_ops.emergency_restart();
20295 }
20296
20297-static void native_machine_restart(char *__unused)
20298+static void __noreturn native_machine_restart(char *__unused)
20299 {
20300 pr_notice("machine restart\n");
20301
20302@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
20303 __machine_emergency_restart(0);
20304 }
20305
20306-static void native_machine_halt(void)
20307+static void __noreturn native_machine_halt(void)
20308 {
20309 /* Stop other cpus and apics */
20310 machine_shutdown();
20311@@ -679,7 +706,7 @@ static void native_machine_halt(void)
20312 stop_this_cpu(NULL);
20313 }
20314
20315-static void native_machine_power_off(void)
20316+static void __noreturn native_machine_power_off(void)
20317 {
20318 if (pm_power_off) {
20319 if (!reboot_force)
20320@@ -688,6 +715,7 @@ static void native_machine_power_off(void)
20321 }
20322 /* A fallback in case there is no PM info available */
20323 tboot_shutdown(TB_SHUTDOWN_HALT);
20324+ unreachable();
20325 }
20326
20327 struct machine_ops machine_ops = {
20328diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
20329index 7a6f3b3..bed145d7 100644
20330--- a/arch/x86/kernel/relocate_kernel_64.S
20331+++ b/arch/x86/kernel/relocate_kernel_64.S
20332@@ -11,6 +11,7 @@
20333 #include <asm/kexec.h>
20334 #include <asm/processor-flags.h>
20335 #include <asm/pgtable_types.h>
20336+#include <asm/alternative-asm.h>
20337
20338 /*
20339 * Must be relocatable PIC code callable as a C function
20340@@ -160,13 +161,14 @@ identity_mapped:
20341 xorq %rbp, %rbp
20342 xorq %r8, %r8
20343 xorq %r9, %r9
20344- xorq %r10, %r9
20345+ xorq %r10, %r10
20346 xorq %r11, %r11
20347 xorq %r12, %r12
20348 xorq %r13, %r13
20349 xorq %r14, %r14
20350 xorq %r15, %r15
20351
20352+ pax_force_retaddr 0, 1
20353 ret
20354
20355 1:
20356diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
20357index 86c524c..bae70c5 100644
20358--- a/arch/x86/kernel/setup.c
20359+++ b/arch/x86/kernel/setup.c
20360@@ -441,7 +441,7 @@ static void __init parse_setup_data(void)
20361
20362 switch (data->type) {
20363 case SETUP_E820_EXT:
20364- parse_e820_ext(data);
20365+ parse_e820_ext((struct setup_data __force_kernel *)data);
20366 break;
20367 case SETUP_DTB:
20368 add_dtb(pa_data);
20369@@ -708,7 +708,7 @@ static void __init trim_bios_range(void)
20370 * area (640->1Mb) as ram even though it is not.
20371 * take them out.
20372 */
20373- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
20374+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
20375
20376 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
20377 }
20378@@ -832,14 +832,14 @@ void __init setup_arch(char **cmdline_p)
20379
20380 if (!boot_params.hdr.root_flags)
20381 root_mountflags &= ~MS_RDONLY;
20382- init_mm.start_code = (unsigned long) _text;
20383- init_mm.end_code = (unsigned long) _etext;
20384+ init_mm.start_code = ktla_ktva((unsigned long) _text);
20385+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
20386 init_mm.end_data = (unsigned long) _edata;
20387 init_mm.brk = _brk_end;
20388
20389- code_resource.start = virt_to_phys(_text);
20390- code_resource.end = virt_to_phys(_etext)-1;
20391- data_resource.start = virt_to_phys(_etext);
20392+ code_resource.start = virt_to_phys(ktla_ktva(_text));
20393+ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
20394+ data_resource.start = virt_to_phys(_sdata);
20395 data_resource.end = virt_to_phys(_edata)-1;
20396 bss_resource.start = virt_to_phys(&__bss_start);
20397 bss_resource.end = virt_to_phys(&__bss_stop)-1;
20398diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
20399index 5cdff03..5810740 100644
20400--- a/arch/x86/kernel/setup_percpu.c
20401+++ b/arch/x86/kernel/setup_percpu.c
20402@@ -21,19 +21,17 @@
20403 #include <asm/cpu.h>
20404 #include <asm/stackprotector.h>
20405
20406-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
20407+#ifdef CONFIG_SMP
20408+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
20409 EXPORT_PER_CPU_SYMBOL(cpu_number);
20410+#endif
20411
20412-#ifdef CONFIG_X86_64
20413 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
20414-#else
20415-#define BOOT_PERCPU_OFFSET 0
20416-#endif
20417
20418 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
20419 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
20420
20421-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
20422+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
20423 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
20424 };
20425 EXPORT_SYMBOL(__per_cpu_offset);
20426@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
20427 {
20428 #ifdef CONFIG_X86_32
20429 struct desc_struct gdt;
20430+ unsigned long base = per_cpu_offset(cpu);
20431
20432- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
20433- 0x2 | DESCTYPE_S, 0x8);
20434- gdt.s = 1;
20435+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
20436+ 0x83 | DESCTYPE_S, 0xC);
20437 write_gdt_entry(get_cpu_gdt_table(cpu),
20438 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
20439 #endif
20440@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
20441 /* alrighty, percpu areas up and running */
20442 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
20443 for_each_possible_cpu(cpu) {
20444+#ifdef CONFIG_CC_STACKPROTECTOR
20445+#ifdef CONFIG_X86_32
20446+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
20447+#endif
20448+#endif
20449 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
20450 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
20451 per_cpu(cpu_number, cpu) = cpu;
20452@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
20453 */
20454 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
20455 #endif
20456+#ifdef CONFIG_CC_STACKPROTECTOR
20457+#ifdef CONFIG_X86_32
20458+ if (!cpu)
20459+ per_cpu(stack_canary.canary, cpu) = canary;
20460+#endif
20461+#endif
20462 /*
20463 * Up to this point, the boot CPU has been using .init.data
20464 * area. Reload any changed state for the boot CPU.
20465diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
20466index 70b27ee..fcf827f 100644
20467--- a/arch/x86/kernel/signal.c
20468+++ b/arch/x86/kernel/signal.c
20469@@ -195,7 +195,7 @@ static unsigned long align_sigframe(unsigned long sp)
20470 * Align the stack pointer according to the i386 ABI,
20471 * i.e. so that on function entry ((sp + 4) & 15) == 0.
20472 */
20473- sp = ((sp + 4) & -16ul) - 4;
20474+ sp = ((sp - 12) & -16ul) - 4;
20475 #else /* !CONFIG_X86_32 */
20476 sp = round_down(sp, 16) - 8;
20477 #endif
20478@@ -303,9 +303,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20479 }
20480
20481 if (current->mm->context.vdso)
20482- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20483+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
20484 else
20485- restorer = &frame->retcode;
20486+ restorer = (void __user *)&frame->retcode;
20487 if (ka->sa.sa_flags & SA_RESTORER)
20488 restorer = ka->sa.sa_restorer;
20489
20490@@ -319,7 +319,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
20491 * reasons and because gdb uses it as a signature to notice
20492 * signal handler stack frames.
20493 */
20494- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
20495+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
20496
20497 if (err)
20498 return -EFAULT;
20499@@ -369,7 +369,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20500 put_user_ex(current->sas_ss_size, &frame->uc.uc_stack.ss_size);
20501
20502 /* Set up to return from userspace. */
20503- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20504+ if (current->mm->context.vdso)
20505+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
20506+ else
20507+ restorer = (void __user *)&frame->retcode;
20508 if (ka->sa.sa_flags & SA_RESTORER)
20509 restorer = ka->sa.sa_restorer;
20510 put_user_ex(restorer, &frame->pretcode);
20511@@ -381,7 +384,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
20512 * reasons and because gdb uses it as a signature to notice
20513 * signal handler stack frames.
20514 */
20515- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
20516+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
20517 } put_user_catch(err);
20518
20519 err |= copy_siginfo_to_user(&frame->info, info);
20520diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
20521index f3e2ec8..ad5287a 100644
20522--- a/arch/x86/kernel/smpboot.c
20523+++ b/arch/x86/kernel/smpboot.c
20524@@ -673,6 +673,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20525 idle->thread.sp = (unsigned long) (((struct pt_regs *)
20526 (THREAD_SIZE + task_stack_page(idle))) - 1);
20527 per_cpu(current_task, cpu) = idle;
20528+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
20529
20530 #ifdef CONFIG_X86_32
20531 /* Stack for startup_32 can be just as for start_secondary onwards */
20532@@ -680,11 +681,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
20533 #else
20534 clear_tsk_thread_flag(idle, TIF_FORK);
20535 initial_gs = per_cpu_offset(cpu);
20536- per_cpu(kernel_stack, cpu) =
20537- (unsigned long)task_stack_page(idle) -
20538- KERNEL_STACK_OFFSET + THREAD_SIZE;
20539+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
20540 #endif
20541+
20542+ pax_open_kernel();
20543 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20544+ pax_close_kernel();
20545+
20546 initial_code = (unsigned long)start_secondary;
20547 stack_start = idle->thread.sp;
20548
20549@@ -823,6 +826,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
20550 /* the FPU context is blank, nobody can own it */
20551 __cpu_disable_lazy_restore(cpu);
20552
20553+#ifdef CONFIG_PAX_PER_CPU_PGD
20554+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
20555+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
20556+ KERNEL_PGD_PTRS);
20557+#endif
20558+
20559+ /* the FPU context is blank, nobody can own it */
20560+ __cpu_disable_lazy_restore(cpu);
20561+
20562 err = do_boot_cpu(apicid, cpu, tidle);
20563 if (err) {
20564 pr_debug("do_boot_cpu failed %d\n", err);
20565diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
20566index 9b4d51d..5d28b58 100644
20567--- a/arch/x86/kernel/step.c
20568+++ b/arch/x86/kernel/step.c
20569@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20570 struct desc_struct *desc;
20571 unsigned long base;
20572
20573- seg &= ~7UL;
20574+ seg >>= 3;
20575
20576 mutex_lock(&child->mm->context.lock);
20577- if (unlikely((seg >> 3) >= child->mm->context.size))
20578+ if (unlikely(seg >= child->mm->context.size))
20579 addr = -1L; /* bogus selector, access would fault */
20580 else {
20581 desc = child->mm->context.ldt + seg;
20582@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
20583 addr += base;
20584 }
20585 mutex_unlock(&child->mm->context.lock);
20586- }
20587+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
20588+ addr = ktla_ktva(addr);
20589
20590 return addr;
20591 }
20592@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
20593 unsigned char opcode[15];
20594 unsigned long addr = convert_ip_to_linear(child, regs);
20595
20596+ if (addr == -EINVAL)
20597+ return 0;
20598+
20599 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
20600 for (i = 0; i < copied; i++) {
20601 switch (opcode[i]) {
20602diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
20603new file mode 100644
20604index 0000000..26bb1af
20605--- /dev/null
20606+++ b/arch/x86/kernel/sys_i386_32.c
20607@@ -0,0 +1,249 @@
20608+/*
20609+ * This file contains various random system calls that
20610+ * have a non-standard calling sequence on the Linux/i386
20611+ * platform.
20612+ */
20613+
20614+#include <linux/errno.h>
20615+#include <linux/sched.h>
20616+#include <linux/mm.h>
20617+#include <linux/fs.h>
20618+#include <linux/smp.h>
20619+#include <linux/sem.h>
20620+#include <linux/msg.h>
20621+#include <linux/shm.h>
20622+#include <linux/stat.h>
20623+#include <linux/syscalls.h>
20624+#include <linux/mman.h>
20625+#include <linux/file.h>
20626+#include <linux/utsname.h>
20627+#include <linux/ipc.h>
20628+
20629+#include <linux/uaccess.h>
20630+#include <linux/unistd.h>
20631+
20632+#include <asm/syscalls.h>
20633+
20634+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
20635+{
20636+ unsigned long pax_task_size = TASK_SIZE;
20637+
20638+#ifdef CONFIG_PAX_SEGMEXEC
20639+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
20640+ pax_task_size = SEGMEXEC_TASK_SIZE;
20641+#endif
20642+
20643+ if (len > pax_task_size || addr > pax_task_size - len)
20644+ return -EINVAL;
20645+
20646+ return 0;
20647+}
20648+
20649+unsigned long
20650+arch_get_unmapped_area(struct file *filp, unsigned long addr,
20651+ unsigned long len, unsigned long pgoff, unsigned long flags)
20652+{
20653+ struct mm_struct *mm = current->mm;
20654+ struct vm_area_struct *vma;
20655+ unsigned long start_addr, pax_task_size = TASK_SIZE;
20656+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20657+
20658+#ifdef CONFIG_PAX_SEGMEXEC
20659+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20660+ pax_task_size = SEGMEXEC_TASK_SIZE;
20661+#endif
20662+
20663+ pax_task_size -= PAGE_SIZE;
20664+
20665+ if (len > pax_task_size)
20666+ return -ENOMEM;
20667+
20668+ if (flags & MAP_FIXED)
20669+ return addr;
20670+
20671+#ifdef CONFIG_PAX_RANDMMAP
20672+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20673+#endif
20674+
20675+ if (addr) {
20676+ addr = PAGE_ALIGN(addr);
20677+ if (pax_task_size - len >= addr) {
20678+ vma = find_vma(mm, addr);
20679+ if (check_heap_stack_gap(vma, addr, len, offset))
20680+ return addr;
20681+ }
20682+ }
20683+ if (len > mm->cached_hole_size) {
20684+ start_addr = addr = mm->free_area_cache;
20685+ } else {
20686+ start_addr = addr = mm->mmap_base;
20687+ mm->cached_hole_size = 0;
20688+ }
20689+
20690+#ifdef CONFIG_PAX_PAGEEXEC
20691+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
20692+ start_addr = 0x00110000UL;
20693+
20694+#ifdef CONFIG_PAX_RANDMMAP
20695+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20696+ start_addr += mm->delta_mmap & 0x03FFF000UL;
20697+#endif
20698+
20699+ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
20700+ start_addr = addr = mm->mmap_base;
20701+ else
20702+ addr = start_addr;
20703+ }
20704+#endif
20705+
20706+full_search:
20707+ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
20708+ /* At this point: (!vma || addr < vma->vm_end). */
20709+ if (pax_task_size - len < addr) {
20710+ /*
20711+ * Start a new search - just in case we missed
20712+ * some holes.
20713+ */
20714+ if (start_addr != mm->mmap_base) {
20715+ start_addr = addr = mm->mmap_base;
20716+ mm->cached_hole_size = 0;
20717+ goto full_search;
20718+ }
20719+ return -ENOMEM;
20720+ }
20721+ if (check_heap_stack_gap(vma, addr, len, offset))
20722+ break;
20723+ if (addr + mm->cached_hole_size < vma->vm_start)
20724+ mm->cached_hole_size = vma->vm_start - addr;
20725+ addr = vma->vm_end;
20726+ if (mm->start_brk <= addr && addr < mm->mmap_base) {
20727+ start_addr = addr = mm->mmap_base;
20728+ mm->cached_hole_size = 0;
20729+ goto full_search;
20730+ }
20731+ }
20732+
20733+ /*
20734+ * Remember the place where we stopped the search:
20735+ */
20736+ mm->free_area_cache = addr + len;
20737+ return addr;
20738+}
20739+
20740+unsigned long
20741+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20742+ const unsigned long len, const unsigned long pgoff,
20743+ const unsigned long flags)
20744+{
20745+ struct vm_area_struct *vma;
20746+ struct mm_struct *mm = current->mm;
20747+ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
20748+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20749+
20750+#ifdef CONFIG_PAX_SEGMEXEC
20751+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20752+ pax_task_size = SEGMEXEC_TASK_SIZE;
20753+#endif
20754+
20755+ pax_task_size -= PAGE_SIZE;
20756+
20757+ /* requested length too big for entire address space */
20758+ if (len > pax_task_size)
20759+ return -ENOMEM;
20760+
20761+ if (flags & MAP_FIXED)
20762+ return addr;
20763+
20764+#ifdef CONFIG_PAX_PAGEEXEC
20765+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
20766+ goto bottomup;
20767+#endif
20768+
20769+#ifdef CONFIG_PAX_RANDMMAP
20770+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20771+#endif
20772+
20773+ /* requesting a specific address */
20774+ if (addr) {
20775+ addr = PAGE_ALIGN(addr);
20776+ if (pax_task_size - len >= addr) {
20777+ vma = find_vma(mm, addr);
20778+ if (check_heap_stack_gap(vma, addr, len, offset))
20779+ return addr;
20780+ }
20781+ }
20782+
20783+ /* check if free_area_cache is useful for us */
20784+ if (len <= mm->cached_hole_size) {
20785+ mm->cached_hole_size = 0;
20786+ mm->free_area_cache = mm->mmap_base;
20787+ }
20788+
20789+ /* either no address requested or can't fit in requested address hole */
20790+ addr = mm->free_area_cache;
20791+
20792+ /* make sure it can fit in the remaining address space */
20793+ if (addr > len) {
20794+ vma = find_vma(mm, addr-len);
20795+ if (check_heap_stack_gap(vma, addr - len, len, offset))
20796+ /* remember the address as a hint for next time */
20797+ return (mm->free_area_cache = addr-len);
20798+ }
20799+
20800+ if (mm->mmap_base < len)
20801+ goto bottomup;
20802+
20803+ addr = mm->mmap_base-len;
20804+
20805+ do {
20806+ /*
20807+ * Lookup failure means no vma is above this address,
20808+ * else if new region fits below vma->vm_start,
20809+ * return with success:
20810+ */
20811+ vma = find_vma(mm, addr);
20812+ if (check_heap_stack_gap(vma, addr, len, offset))
20813+ /* remember the address as a hint for next time */
20814+ return (mm->free_area_cache = addr);
20815+
20816+ /* remember the largest hole we saw so far */
20817+ if (addr + mm->cached_hole_size < vma->vm_start)
20818+ mm->cached_hole_size = vma->vm_start - addr;
20819+
20820+ /* try just below the current vma->vm_start */
20821+ addr = skip_heap_stack_gap(vma, len, offset);
20822+ } while (!IS_ERR_VALUE(addr));
20823+
20824+bottomup:
20825+ /*
20826+ * A failed mmap() very likely causes application failure,
20827+ * so fall back to the bottom-up function here. This scenario
20828+ * can happen with large stack limits and large mmap()
20829+ * allocations.
20830+ */
20831+
20832+#ifdef CONFIG_PAX_SEGMEXEC
20833+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
20834+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
20835+ else
20836+#endif
20837+
20838+ mm->mmap_base = TASK_UNMAPPED_BASE;
20839+
20840+#ifdef CONFIG_PAX_RANDMMAP
20841+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20842+ mm->mmap_base += mm->delta_mmap;
20843+#endif
20844+
20845+ mm->free_area_cache = mm->mmap_base;
20846+ mm->cached_hole_size = ~0UL;
20847+ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20848+ /*
20849+ * Restore the topdown base:
20850+ */
20851+ mm->mmap_base = base;
20852+ mm->free_area_cache = base;
20853+ mm->cached_hole_size = ~0UL;
20854+
20855+ return addr;
20856+}
20857diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
20858index b4d3c39..d699d77 100644
20859--- a/arch/x86/kernel/sys_x86_64.c
20860+++ b/arch/x86/kernel/sys_x86_64.c
20861@@ -95,8 +95,8 @@ out:
20862 return error;
20863 }
20864
20865-static void find_start_end(unsigned long flags, unsigned long *begin,
20866- unsigned long *end)
20867+static void find_start_end(struct mm_struct *mm, unsigned long flags,
20868+ unsigned long *begin, unsigned long *end)
20869 {
20870 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
20871 unsigned long new_begin;
20872@@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
20873 *begin = new_begin;
20874 }
20875 } else {
20876- *begin = TASK_UNMAPPED_BASE;
20877+ *begin = mm->mmap_base;
20878 *end = TASK_SIZE;
20879 }
20880 }
20881@@ -128,20 +128,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
20882 struct vm_area_struct *vma;
20883 unsigned long start_addr;
20884 unsigned long begin, end;
20885+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20886
20887 if (flags & MAP_FIXED)
20888 return addr;
20889
20890- find_start_end(flags, &begin, &end);
20891+ find_start_end(mm, flags, &begin, &end);
20892
20893 if (len > end)
20894 return -ENOMEM;
20895
20896+#ifdef CONFIG_PAX_RANDMMAP
20897+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20898+#endif
20899+
20900 if (addr) {
20901 addr = PAGE_ALIGN(addr);
20902 vma = find_vma(mm, addr);
20903- if (end - len >= addr &&
20904- (!vma || addr + len <= vma->vm_start))
20905+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
20906 return addr;
20907 }
20908 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
20909@@ -172,7 +176,7 @@ full_search:
20910 }
20911 return -ENOMEM;
20912 }
20913- if (!vma || addr + len <= vma->vm_start) {
20914+ if (check_heap_stack_gap(vma, addr, len, offset)) {
20915 /*
20916 * Remember the place where we stopped the search:
20917 */
20918@@ -195,7 +199,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20919 {
20920 struct vm_area_struct *vma;
20921 struct mm_struct *mm = current->mm;
20922- unsigned long addr = addr0, start_addr;
20923+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
20924+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
20925
20926 /* requested length too big for entire address space */
20927 if (len > TASK_SIZE)
20928@@ -208,13 +213,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
20929 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
20930 goto bottomup;
20931
20932+#ifdef CONFIG_PAX_RANDMMAP
20933+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
20934+#endif
20935+
20936 /* requesting a specific address */
20937 if (addr) {
20938 addr = PAGE_ALIGN(addr);
20939- vma = find_vma(mm, addr);
20940- if (TASK_SIZE - len >= addr &&
20941- (!vma || addr + len <= vma->vm_start))
20942- return addr;
20943+ if (TASK_SIZE - len >= addr) {
20944+ vma = find_vma(mm, addr);
20945+ if (check_heap_stack_gap(vma, addr, len, offset))
20946+ return addr;
20947+ }
20948 }
20949
20950 /* check if free_area_cache is useful for us */
20951@@ -240,7 +250,7 @@ try_again:
20952 * return with success:
20953 */
20954 vma = find_vma(mm, addr);
20955- if (!vma || addr+len <= vma->vm_start)
20956+ if (check_heap_stack_gap(vma, addr, len, offset))
20957 /* remember the address as a hint for next time */
20958 return mm->free_area_cache = addr;
20959
20960@@ -249,8 +259,8 @@ try_again:
20961 mm->cached_hole_size = vma->vm_start - addr;
20962
20963 /* try just below the current vma->vm_start */
20964- addr = vma->vm_start-len;
20965- } while (len < vma->vm_start);
20966+ addr = skip_heap_stack_gap(vma, len, offset);
20967+ } while (!IS_ERR_VALUE(addr));
20968
20969 fail:
20970 /*
20971@@ -270,13 +280,21 @@ bottomup:
20972 * can happen with large stack limits and large mmap()
20973 * allocations.
20974 */
20975+ mm->mmap_base = TASK_UNMAPPED_BASE;
20976+
20977+#ifdef CONFIG_PAX_RANDMMAP
20978+ if (mm->pax_flags & MF_PAX_RANDMMAP)
20979+ mm->mmap_base += mm->delta_mmap;
20980+#endif
20981+
20982+ mm->free_area_cache = mm->mmap_base;
20983 mm->cached_hole_size = ~0UL;
20984- mm->free_area_cache = TASK_UNMAPPED_BASE;
20985 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
20986 /*
20987 * Restore the topdown base:
20988 */
20989- mm->free_area_cache = mm->mmap_base;
20990+ mm->mmap_base = base;
20991+ mm->free_area_cache = base;
20992 mm->cached_hole_size = ~0UL;
20993
20994 return addr;
20995diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
20996index f84fe00..93fe08f 100644
20997--- a/arch/x86/kernel/tboot.c
20998+++ b/arch/x86/kernel/tboot.c
20999@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
21000
21001 void tboot_shutdown(u32 shutdown_type)
21002 {
21003- void (*shutdown)(void);
21004+ void (* __noreturn shutdown)(void);
21005
21006 if (!tboot_enabled())
21007 return;
21008@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
21009
21010 switch_to_tboot_pt();
21011
21012- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
21013+ shutdown = (void *)tboot->shutdown_entry;
21014 shutdown();
21015
21016 /* should not reach here */
21017@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
21018 return 0;
21019 }
21020
21021-static atomic_t ap_wfs_count;
21022+static atomic_unchecked_t ap_wfs_count;
21023
21024 static int tboot_wait_for_aps(int num_aps)
21025 {
21026@@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
21027 {
21028 switch (action) {
21029 case CPU_DYING:
21030- atomic_inc(&ap_wfs_count);
21031+ atomic_inc_unchecked(&ap_wfs_count);
21032 if (num_online_cpus() == 1)
21033- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
21034+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
21035 return NOTIFY_BAD;
21036 break;
21037 }
21038@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
21039
21040 tboot_create_trampoline();
21041
21042- atomic_set(&ap_wfs_count, 0);
21043+ atomic_set_unchecked(&ap_wfs_count, 0);
21044 register_hotcpu_notifier(&tboot_cpu_notifier);
21045
21046 acpi_os_set_prepare_sleep(&tboot_sleep);
21047diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
21048index 24d3c91..d06b473 100644
21049--- a/arch/x86/kernel/time.c
21050+++ b/arch/x86/kernel/time.c
21051@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
21052 {
21053 unsigned long pc = instruction_pointer(regs);
21054
21055- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
21056+ if (!user_mode(regs) && in_lock_functions(pc)) {
21057 #ifdef CONFIG_FRAME_POINTER
21058- return *(unsigned long *)(regs->bp + sizeof(long));
21059+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
21060 #else
21061 unsigned long *sp =
21062 (unsigned long *)kernel_stack_pointer(regs);
21063@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
21064 * or above a saved flags. Eflags has bits 22-31 zero,
21065 * kernel addresses don't.
21066 */
21067+
21068+#ifdef CONFIG_PAX_KERNEXEC
21069+ return ktla_ktva(sp[0]);
21070+#else
21071 if (sp[0] >> 22)
21072 return sp[0];
21073 if (sp[1] >> 22)
21074 return sp[1];
21075 #endif
21076+
21077+#endif
21078 }
21079 return pc;
21080 }
21081diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
21082index 9d9d2f9..cad418a 100644
21083--- a/arch/x86/kernel/tls.c
21084+++ b/arch/x86/kernel/tls.c
21085@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
21086 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
21087 return -EINVAL;
21088
21089+#ifdef CONFIG_PAX_SEGMEXEC
21090+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
21091+ return -EINVAL;
21092+#endif
21093+
21094 set_tls_desc(p, idx, &info, 1);
21095
21096 return 0;
21097@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
21098
21099 if (kbuf)
21100 info = kbuf;
21101- else if (__copy_from_user(infobuf, ubuf, count))
21102+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
21103 return -EFAULT;
21104 else
21105 info = infobuf;
21106diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
21107index 8276dc6..4ca48a2 100644
21108--- a/arch/x86/kernel/traps.c
21109+++ b/arch/x86/kernel/traps.c
21110@@ -71,12 +71,6 @@ asmlinkage int system_call(void);
21111
21112 /* Do we ignore FPU interrupts ? */
21113 char ignore_fpu_irq;
21114-
21115-/*
21116- * The IDT has to be page-aligned to simplify the Pentium
21117- * F0 0F bug workaround.
21118- */
21119-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
21120 #endif
21121
21122 DECLARE_BITMAP(used_vectors, NR_VECTORS);
21123@@ -109,11 +103,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
21124 }
21125
21126 static int __kprobes
21127-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21128+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
21129 struct pt_regs *regs, long error_code)
21130 {
21131 #ifdef CONFIG_X86_32
21132- if (regs->flags & X86_VM_MASK) {
21133+ if (v8086_mode(regs)) {
21134 /*
21135 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
21136 * On nmi (interrupt 2), do_trap should not be called.
21137@@ -126,12 +120,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21138 return -1;
21139 }
21140 #endif
21141- if (!user_mode(regs)) {
21142+ if (!user_mode_novm(regs)) {
21143 if (!fixup_exception(regs)) {
21144 tsk->thread.error_code = error_code;
21145 tsk->thread.trap_nr = trapnr;
21146+
21147+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21148+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
21149+ str = "PAX: suspicious stack segment fault";
21150+#endif
21151+
21152 die(str, regs, error_code);
21153 }
21154+
21155+#ifdef CONFIG_PAX_REFCOUNT
21156+ if (trapnr == 4)
21157+ pax_report_refcount_overflow(regs);
21158+#endif
21159+
21160 return 0;
21161 }
21162
21163@@ -139,7 +145,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
21164 }
21165
21166 static void __kprobes
21167-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21168+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
21169 long error_code, siginfo_t *info)
21170 {
21171 struct task_struct *tsk = current;
21172@@ -163,7 +169,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
21173 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
21174 printk_ratelimit()) {
21175 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
21176- tsk->comm, tsk->pid, str,
21177+ tsk->comm, task_pid_nr(tsk), str,
21178 regs->ip, regs->sp, error_code);
21179 print_vma_addr(" in ", regs->ip);
21180 pr_cont("\n");
21181@@ -269,7 +275,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
21182 conditional_sti(regs);
21183
21184 #ifdef CONFIG_X86_32
21185- if (regs->flags & X86_VM_MASK) {
21186+ if (v8086_mode(regs)) {
21187 local_irq_enable();
21188 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
21189 goto exit;
21190@@ -277,18 +283,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
21191 #endif
21192
21193 tsk = current;
21194- if (!user_mode(regs)) {
21195+ if (!user_mode_novm(regs)) {
21196 if (fixup_exception(regs))
21197 goto exit;
21198
21199 tsk->thread.error_code = error_code;
21200 tsk->thread.trap_nr = X86_TRAP_GP;
21201 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
21202- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
21203+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
21204+
21205+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21206+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
21207+ die("PAX: suspicious general protection fault", regs, error_code);
21208+ else
21209+#endif
21210+
21211 die("general protection fault", regs, error_code);
21212+ }
21213 goto exit;
21214 }
21215
21216+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
21217+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
21218+ struct mm_struct *mm = tsk->mm;
21219+ unsigned long limit;
21220+
21221+ down_write(&mm->mmap_sem);
21222+ limit = mm->context.user_cs_limit;
21223+ if (limit < TASK_SIZE) {
21224+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
21225+ up_write(&mm->mmap_sem);
21226+ return;
21227+ }
21228+ up_write(&mm->mmap_sem);
21229+ }
21230+#endif
21231+
21232 tsk->thread.error_code = error_code;
21233 tsk->thread.trap_nr = X86_TRAP_GP;
21234
21235@@ -443,7 +473,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21236 /* It's safe to allow irq's after DR6 has been saved */
21237 preempt_conditional_sti(regs);
21238
21239- if (regs->flags & X86_VM_MASK) {
21240+ if (v8086_mode(regs)) {
21241 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
21242 X86_TRAP_DB);
21243 preempt_conditional_cli(regs);
21244@@ -458,7 +488,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
21245 * We already checked v86 mode above, so we can check for kernel mode
21246 * by just checking the CPL of CS.
21247 */
21248- if ((dr6 & DR_STEP) && !user_mode(regs)) {
21249+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
21250 tsk->thread.debugreg6 &= ~DR_STEP;
21251 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
21252 regs->flags &= ~X86_EFLAGS_TF;
21253@@ -490,7 +520,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
21254 return;
21255 conditional_sti(regs);
21256
21257- if (!user_mode_vm(regs))
21258+ if (!user_mode(regs))
21259 {
21260 if (!fixup_exception(regs)) {
21261 task->thread.error_code = error_code;
21262diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
21263index aafa555..a04691a 100644
21264--- a/arch/x86/kernel/uprobes.c
21265+++ b/arch/x86/kernel/uprobes.c
21266@@ -614,7 +614,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
21267 int ret = NOTIFY_DONE;
21268
21269 /* We are only interested in userspace traps */
21270- if (regs && !user_mode_vm(regs))
21271+ if (regs && !user_mode(regs))
21272 return NOTIFY_DONE;
21273
21274 switch (val) {
21275diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
21276index b9242ba..50c5edd 100644
21277--- a/arch/x86/kernel/verify_cpu.S
21278+++ b/arch/x86/kernel/verify_cpu.S
21279@@ -20,6 +20,7 @@
21280 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
21281 * arch/x86/kernel/trampoline_64.S: secondary processor verification
21282 * arch/x86/kernel/head_32.S: processor startup
21283+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
21284 *
21285 * verify_cpu, returns the status of longmode and SSE in register %eax.
21286 * 0: Success 1: Failure
21287diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
21288index 5c9687b..5f857d3 100644
21289--- a/arch/x86/kernel/vm86_32.c
21290+++ b/arch/x86/kernel/vm86_32.c
21291@@ -43,6 +43,7 @@
21292 #include <linux/ptrace.h>
21293 #include <linux/audit.h>
21294 #include <linux/stddef.h>
21295+#include <linux/grsecurity.h>
21296
21297 #include <asm/uaccess.h>
21298 #include <asm/io.h>
21299@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
21300 do_exit(SIGSEGV);
21301 }
21302
21303- tss = &per_cpu(init_tss, get_cpu());
21304+ tss = init_tss + get_cpu();
21305 current->thread.sp0 = current->thread.saved_sp0;
21306 current->thread.sysenter_cs = __KERNEL_CS;
21307 load_sp0(tss, &current->thread);
21308@@ -212,6 +213,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
21309 struct task_struct *tsk;
21310 int tmp, ret = -EPERM;
21311
21312+#ifdef CONFIG_GRKERNSEC_VM86
21313+ if (!capable(CAP_SYS_RAWIO)) {
21314+ gr_handle_vm86();
21315+ goto out;
21316+ }
21317+#endif
21318+
21319 tsk = current;
21320 if (tsk->thread.saved_sp0)
21321 goto out;
21322@@ -242,6 +250,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
21323 int tmp, ret;
21324 struct vm86plus_struct __user *v86;
21325
21326+#ifdef CONFIG_GRKERNSEC_VM86
21327+ if (!capable(CAP_SYS_RAWIO)) {
21328+ gr_handle_vm86();
21329+ ret = -EPERM;
21330+ goto out;
21331+ }
21332+#endif
21333+
21334 tsk = current;
21335 switch (cmd) {
21336 case VM86_REQUEST_IRQ:
21337@@ -328,7 +344,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
21338 tsk->thread.saved_fs = info->regs32->fs;
21339 tsk->thread.saved_gs = get_user_gs(info->regs32);
21340
21341- tss = &per_cpu(init_tss, get_cpu());
21342+ tss = init_tss + get_cpu();
21343 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
21344 if (cpu_has_sep)
21345 tsk->thread.sysenter_cs = 0;
21346@@ -535,7 +551,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
21347 goto cannot_handle;
21348 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
21349 goto cannot_handle;
21350- intr_ptr = (unsigned long __user *) (i << 2);
21351+ intr_ptr = (__force unsigned long __user *) (i << 2);
21352 if (get_user(segoffs, intr_ptr))
21353 goto cannot_handle;
21354 if ((segoffs >> 16) == BIOSSEG)
21355diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
21356index 22a1530..8fbaaad 100644
21357--- a/arch/x86/kernel/vmlinux.lds.S
21358+++ b/arch/x86/kernel/vmlinux.lds.S
21359@@ -26,6 +26,13 @@
21360 #include <asm/page_types.h>
21361 #include <asm/cache.h>
21362 #include <asm/boot.h>
21363+#include <asm/segment.h>
21364+
21365+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21366+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
21367+#else
21368+#define __KERNEL_TEXT_OFFSET 0
21369+#endif
21370
21371 #undef i386 /* in case the preprocessor is a 32bit one */
21372
21373@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
21374
21375 PHDRS {
21376 text PT_LOAD FLAGS(5); /* R_E */
21377+#ifdef CONFIG_X86_32
21378+ module PT_LOAD FLAGS(5); /* R_E */
21379+#endif
21380+#ifdef CONFIG_XEN
21381+ rodata PT_LOAD FLAGS(5); /* R_E */
21382+#else
21383+ rodata PT_LOAD FLAGS(4); /* R__ */
21384+#endif
21385 data PT_LOAD FLAGS(6); /* RW_ */
21386-#ifdef CONFIG_X86_64
21387+ init.begin PT_LOAD FLAGS(6); /* RW_ */
21388 #ifdef CONFIG_SMP
21389 percpu PT_LOAD FLAGS(6); /* RW_ */
21390 #endif
21391+ text.init PT_LOAD FLAGS(5); /* R_E */
21392+ text.exit PT_LOAD FLAGS(5); /* R_E */
21393 init PT_LOAD FLAGS(7); /* RWE */
21394-#endif
21395 note PT_NOTE FLAGS(0); /* ___ */
21396 }
21397
21398 SECTIONS
21399 {
21400 #ifdef CONFIG_X86_32
21401- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
21402- phys_startup_32 = startup_32 - LOAD_OFFSET;
21403+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
21404 #else
21405- . = __START_KERNEL;
21406- phys_startup_64 = startup_64 - LOAD_OFFSET;
21407+ . = __START_KERNEL;
21408 #endif
21409
21410 /* Text and read-only data */
21411- .text : AT(ADDR(.text) - LOAD_OFFSET) {
21412- _text = .;
21413+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21414 /* bootstrapping code */
21415+#ifdef CONFIG_X86_32
21416+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21417+#else
21418+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21419+#endif
21420+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
21421+ _text = .;
21422 HEAD_TEXT
21423 #ifdef CONFIG_X86_32
21424 . = ALIGN(PAGE_SIZE);
21425@@ -108,13 +128,48 @@ SECTIONS
21426 IRQENTRY_TEXT
21427 *(.fixup)
21428 *(.gnu.warning)
21429- /* End of text section */
21430- _etext = .;
21431 } :text = 0x9090
21432
21433- NOTES :text :note
21434+ . += __KERNEL_TEXT_OFFSET;
21435
21436- EXCEPTION_TABLE(16) :text = 0x9090
21437+#ifdef CONFIG_X86_32
21438+ . = ALIGN(PAGE_SIZE);
21439+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
21440+
21441+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
21442+ MODULES_EXEC_VADDR = .;
21443+ BYTE(0)
21444+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
21445+ . = ALIGN(HPAGE_SIZE) - 1;
21446+ MODULES_EXEC_END = .;
21447+#endif
21448+
21449+ } :module
21450+#endif
21451+
21452+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
21453+ /* End of text section */
21454+ BYTE(0)
21455+ _etext = . - __KERNEL_TEXT_OFFSET;
21456+ }
21457+
21458+#ifdef CONFIG_X86_32
21459+ . = ALIGN(PAGE_SIZE);
21460+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
21461+ *(.idt)
21462+ . = ALIGN(PAGE_SIZE);
21463+ *(.empty_zero_page)
21464+ *(.initial_pg_fixmap)
21465+ *(.initial_pg_pmd)
21466+ *(.initial_page_table)
21467+ *(.swapper_pg_dir)
21468+ } :rodata
21469+#endif
21470+
21471+ . = ALIGN(PAGE_SIZE);
21472+ NOTES :rodata :note
21473+
21474+ EXCEPTION_TABLE(16) :rodata
21475
21476 #if defined(CONFIG_DEBUG_RODATA)
21477 /* .text should occupy whole number of pages */
21478@@ -126,16 +181,20 @@ SECTIONS
21479
21480 /* Data */
21481 .data : AT(ADDR(.data) - LOAD_OFFSET) {
21482+
21483+#ifdef CONFIG_PAX_KERNEXEC
21484+ . = ALIGN(HPAGE_SIZE);
21485+#else
21486+ . = ALIGN(PAGE_SIZE);
21487+#endif
21488+
21489 /* Start of data section */
21490 _sdata = .;
21491
21492 /* init_task */
21493 INIT_TASK_DATA(THREAD_SIZE)
21494
21495-#ifdef CONFIG_X86_32
21496- /* 32 bit has nosave before _edata */
21497 NOSAVE_DATA
21498-#endif
21499
21500 PAGE_ALIGNED_DATA(PAGE_SIZE)
21501
21502@@ -176,12 +235,19 @@ SECTIONS
21503 #endif /* CONFIG_X86_64 */
21504
21505 /* Init code and data - will be freed after init */
21506- . = ALIGN(PAGE_SIZE);
21507 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
21508+ BYTE(0)
21509+
21510+#ifdef CONFIG_PAX_KERNEXEC
21511+ . = ALIGN(HPAGE_SIZE);
21512+#else
21513+ . = ALIGN(PAGE_SIZE);
21514+#endif
21515+
21516 __init_begin = .; /* paired with __init_end */
21517- }
21518+ } :init.begin
21519
21520-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
21521+#ifdef CONFIG_SMP
21522 /*
21523 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
21524 * output PHDR, so the next output section - .init.text - should
21525@@ -190,12 +256,27 @@ SECTIONS
21526 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
21527 #endif
21528
21529- INIT_TEXT_SECTION(PAGE_SIZE)
21530-#ifdef CONFIG_X86_64
21531- :init
21532-#endif
21533+ . = ALIGN(PAGE_SIZE);
21534+ init_begin = .;
21535+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
21536+ VMLINUX_SYMBOL(_sinittext) = .;
21537+ INIT_TEXT
21538+ VMLINUX_SYMBOL(_einittext) = .;
21539+ . = ALIGN(PAGE_SIZE);
21540+ } :text.init
21541
21542- INIT_DATA_SECTION(16)
21543+ /*
21544+ * .exit.text is discard at runtime, not link time, to deal with
21545+ * references from .altinstructions and .eh_frame
21546+ */
21547+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
21548+ EXIT_TEXT
21549+ . = ALIGN(16);
21550+ } :text.exit
21551+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
21552+
21553+ . = ALIGN(PAGE_SIZE);
21554+ INIT_DATA_SECTION(16) :init
21555
21556 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
21557 __x86_cpu_dev_start = .;
21558@@ -257,19 +338,12 @@ SECTIONS
21559 }
21560
21561 . = ALIGN(8);
21562- /*
21563- * .exit.text is discard at runtime, not link time, to deal with
21564- * references from .altinstructions and .eh_frame
21565- */
21566- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
21567- EXIT_TEXT
21568- }
21569
21570 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
21571 EXIT_DATA
21572 }
21573
21574-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
21575+#ifndef CONFIG_SMP
21576 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
21577 #endif
21578
21579@@ -288,16 +362,10 @@ SECTIONS
21580 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
21581 __smp_locks = .;
21582 *(.smp_locks)
21583- . = ALIGN(PAGE_SIZE);
21584 __smp_locks_end = .;
21585+ . = ALIGN(PAGE_SIZE);
21586 }
21587
21588-#ifdef CONFIG_X86_64
21589- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
21590- NOSAVE_DATA
21591- }
21592-#endif
21593-
21594 /* BSS */
21595 . = ALIGN(PAGE_SIZE);
21596 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
21597@@ -313,6 +381,7 @@ SECTIONS
21598 __brk_base = .;
21599 . += 64 * 1024; /* 64k alignment slop space */
21600 *(.brk_reservation) /* areas brk users have reserved */
21601+ . = ALIGN(HPAGE_SIZE);
21602 __brk_limit = .;
21603 }
21604
21605@@ -339,13 +408,12 @@ SECTIONS
21606 * for the boot processor.
21607 */
21608 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
21609-INIT_PER_CPU(gdt_page);
21610 INIT_PER_CPU(irq_stack_union);
21611
21612 /*
21613 * Build-time check on the image size:
21614 */
21615-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
21616+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
21617 "kernel image bigger than KERNEL_IMAGE_SIZE");
21618
21619 #ifdef CONFIG_SMP
21620diff --git a/arch/x86/kernel/vsmp_64.c b/arch/x86/kernel/vsmp_64.c
21621index 992f890..0ab1aae 100644
21622--- a/arch/x86/kernel/vsmp_64.c
21623+++ b/arch/x86/kernel/vsmp_64.c
21624@@ -114,7 +114,7 @@ static void __init set_vsmp_pv_ops(void)
21625 pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
21626 pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
21627 pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
21628- pv_init_ops.patch = vsmp_patch;
21629+ *(void **)&pv_init_ops.patch = vsmp_patch;
21630 ctl &= ~(1 << 4);
21631 }
21632 writel(ctl, address + 4);
21633@@ -217,8 +217,8 @@ static void fill_vector_allocation_domain(int cpu, struct cpumask *retmask,
21634 static void vsmp_apic_post_init(void)
21635 {
21636 /* need to update phys_pkg_id */
21637- apic->phys_pkg_id = apicid_phys_pkg_id;
21638- apic->vector_allocation_domain = fill_vector_allocation_domain;
21639+ *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
21640+ *(void **)&apic->vector_allocation_domain = fill_vector_allocation_domain;
21641 }
21642
21643 void __init vsmp_init(void)
21644@@ -227,7 +227,7 @@ void __init vsmp_init(void)
21645 if (!is_vsmp_box())
21646 return;
21647
21648- x86_platform.apic_post_init = vsmp_apic_post_init;
21649+ *(void **)&x86_platform.apic_post_init = vsmp_apic_post_init;
21650
21651 vsmp_cap_cpus();
21652
21653diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
21654index 3a3e8c9..1af9465 100644
21655--- a/arch/x86/kernel/vsyscall_64.c
21656+++ b/arch/x86/kernel/vsyscall_64.c
21657@@ -56,15 +56,13 @@
21658 DEFINE_VVAR(int, vgetcpu_mode);
21659 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
21660
21661-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
21662+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
21663
21664 static int __init vsyscall_setup(char *str)
21665 {
21666 if (str) {
21667 if (!strcmp("emulate", str))
21668 vsyscall_mode = EMULATE;
21669- else if (!strcmp("native", str))
21670- vsyscall_mode = NATIVE;
21671 else if (!strcmp("none", str))
21672 vsyscall_mode = NONE;
21673 else
21674@@ -315,8 +313,7 @@ done:
21675 return true;
21676
21677 sigsegv:
21678- force_sig(SIGSEGV, current);
21679- return true;
21680+ do_group_exit(SIGKILL);
21681 }
21682
21683 /*
21684@@ -369,10 +366,7 @@ void __init map_vsyscall(void)
21685 extern char __vvar_page;
21686 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
21687
21688- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
21689- vsyscall_mode == NATIVE
21690- ? PAGE_KERNEL_VSYSCALL
21691- : PAGE_KERNEL_VVAR);
21692+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
21693 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
21694 (unsigned long)VSYSCALL_START);
21695
21696diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
21697index 1330dd1..d220b99 100644
21698--- a/arch/x86/kernel/x8664_ksyms_64.c
21699+++ b/arch/x86/kernel/x8664_ksyms_64.c
21700@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
21701 EXPORT_SYMBOL(copy_user_generic_unrolled);
21702 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
21703 EXPORT_SYMBOL(__copy_user_nocache);
21704-EXPORT_SYMBOL(_copy_from_user);
21705-EXPORT_SYMBOL(_copy_to_user);
21706
21707 EXPORT_SYMBOL(copy_page);
21708 EXPORT_SYMBOL(clear_page);
21709diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
21710index ada87a3..afea76d 100644
21711--- a/arch/x86/kernel/xsave.c
21712+++ b/arch/x86/kernel/xsave.c
21713@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
21714 {
21715 int err;
21716
21717+ buf = (struct xsave_struct __user *)____m(buf);
21718 if (use_xsave())
21719 err = xsave_user(buf);
21720 else if (use_fxsr())
21721@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
21722 */
21723 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
21724 {
21725+ buf = (void __user *)____m(buf);
21726 if (use_xsave()) {
21727 if ((unsigned long)buf % 64 || fx_only) {
21728 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
21729diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
21730index ec79e77..420f5cc 100644
21731--- a/arch/x86/kvm/cpuid.c
21732+++ b/arch/x86/kvm/cpuid.c
21733@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
21734 struct kvm_cpuid2 *cpuid,
21735 struct kvm_cpuid_entry2 __user *entries)
21736 {
21737- int r;
21738+ int r, i;
21739
21740 r = -E2BIG;
21741 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
21742 goto out;
21743 r = -EFAULT;
21744- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
21745- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21746+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
21747 goto out;
21748+ for (i = 0; i < cpuid->nent; ++i) {
21749+ struct kvm_cpuid_entry2 cpuid_entry;
21750+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
21751+ goto out;
21752+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
21753+ }
21754 vcpu->arch.cpuid_nent = cpuid->nent;
21755 kvm_apic_set_version(vcpu);
21756 kvm_x86_ops->cpuid_update(vcpu);
21757@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
21758 struct kvm_cpuid2 *cpuid,
21759 struct kvm_cpuid_entry2 __user *entries)
21760 {
21761- int r;
21762+ int r, i;
21763
21764 r = -E2BIG;
21765 if (cpuid->nent < vcpu->arch.cpuid_nent)
21766 goto out;
21767 r = -EFAULT;
21768- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
21769- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21770+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
21771 goto out;
21772+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
21773+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
21774+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
21775+ goto out;
21776+ }
21777 return 0;
21778
21779 out:
21780diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
21781index bba39bf..296540a 100644
21782--- a/arch/x86/kvm/emulate.c
21783+++ b/arch/x86/kvm/emulate.c
21784@@ -292,6 +292,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21785
21786 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
21787 do { \
21788+ unsigned long _tmp; \
21789 __asm__ __volatile__ ( \
21790 _PRE_EFLAGS("0", "4", "2") \
21791 _op _suffix " %"_x"3,%1; " \
21792@@ -306,8 +307,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21793 /* Raw emulation: instruction has two explicit operands. */
21794 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
21795 do { \
21796- unsigned long _tmp; \
21797- \
21798 switch ((ctxt)->dst.bytes) { \
21799 case 2: \
21800 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
21801@@ -323,7 +322,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
21802
21803 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
21804 do { \
21805- unsigned long _tmp; \
21806 switch ((ctxt)->dst.bytes) { \
21807 case 1: \
21808 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
21809diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
21810index 43e9fad..3b7c059 100644
21811--- a/arch/x86/kvm/lapic.c
21812+++ b/arch/x86/kvm/lapic.c
21813@@ -55,7 +55,7 @@
21814 #define APIC_BUS_CYCLE_NS 1
21815
21816 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
21817-#define apic_debug(fmt, arg...)
21818+#define apic_debug(fmt, arg...) do {} while (0)
21819
21820 #define APIC_LVT_NUM 6
21821 /* 14 is the version for Xeon and Pentium 8.4.8*/
21822diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
21823index 714e2c0..3f7a086 100644
21824--- a/arch/x86/kvm/paging_tmpl.h
21825+++ b/arch/x86/kvm/paging_tmpl.h
21826@@ -208,7 +208,7 @@ retry_walk:
21827 if (unlikely(kvm_is_error_hva(host_addr)))
21828 goto error;
21829
21830- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
21831+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
21832 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
21833 goto error;
21834 walker->ptep_user[walker->level - 1] = ptep_user;
21835diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
21836index d017df3..61ae42e 100644
21837--- a/arch/x86/kvm/svm.c
21838+++ b/arch/x86/kvm/svm.c
21839@@ -3500,7 +3500,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
21840 int cpu = raw_smp_processor_id();
21841
21842 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
21843+
21844+ pax_open_kernel();
21845 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
21846+ pax_close_kernel();
21847+
21848 load_TR_desc();
21849 }
21850
21851@@ -3874,6 +3878,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
21852 #endif
21853 #endif
21854
21855+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21856+ __set_fs(current_thread_info()->addr_limit);
21857+#endif
21858+
21859 reload_tss(vcpu);
21860
21861 local_irq_disable();
21862diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
21863index f858159..4ab7dba 100644
21864--- a/arch/x86/kvm/vmx.c
21865+++ b/arch/x86/kvm/vmx.c
21866@@ -1332,7 +1332,11 @@ static void reload_tss(void)
21867 struct desc_struct *descs;
21868
21869 descs = (void *)gdt->address;
21870+
21871+ pax_open_kernel();
21872 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
21873+ pax_close_kernel();
21874+
21875 load_TR_desc();
21876 }
21877
21878@@ -1546,6 +1550,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
21879 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
21880 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
21881
21882+#ifdef CONFIG_PAX_PER_CPU_PGD
21883+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21884+#endif
21885+
21886 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
21887 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
21888 vmx->loaded_vmcs->cpu = cpu;
21889@@ -2669,8 +2677,11 @@ static __init int hardware_setup(void)
21890 if (!cpu_has_vmx_flexpriority())
21891 flexpriority_enabled = 0;
21892
21893- if (!cpu_has_vmx_tpr_shadow())
21894- kvm_x86_ops->update_cr8_intercept = NULL;
21895+ if (!cpu_has_vmx_tpr_shadow()) {
21896+ pax_open_kernel();
21897+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
21898+ pax_close_kernel();
21899+ }
21900
21901 if (enable_ept && !cpu_has_vmx_ept_2m_page())
21902 kvm_disable_largepages();
21903@@ -3712,7 +3723,10 @@ static void vmx_set_constant_host_state(void)
21904
21905 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
21906 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
21907+
21908+#ifndef CONFIG_PAX_PER_CPU_PGD
21909 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
21910+#endif
21911
21912 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
21913 #ifdef CONFIG_X86_64
21914@@ -3733,7 +3747,7 @@ static void vmx_set_constant_host_state(void)
21915 native_store_idt(&dt);
21916 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
21917
21918- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
21919+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
21920
21921 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
21922 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
21923@@ -6279,6 +6293,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21924 "jmp 2f \n\t"
21925 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
21926 "2: "
21927+
21928+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21929+ "ljmp %[cs],$3f\n\t"
21930+ "3: "
21931+#endif
21932+
21933 /* Save guest registers, load host registers, keep flags */
21934 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
21935 "pop %0 \n\t"
21936@@ -6331,6 +6351,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21937 #endif
21938 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
21939 [wordsize]"i"(sizeof(ulong))
21940+
21941+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21942+ ,[cs]"i"(__KERNEL_CS)
21943+#endif
21944+
21945 : "cc", "memory"
21946 #ifdef CONFIG_X86_64
21947 , "rax", "rbx", "rdi", "rsi"
21948@@ -6344,7 +6369,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21949 if (debugctlmsr)
21950 update_debugctlmsr(debugctlmsr);
21951
21952-#ifndef CONFIG_X86_64
21953+#ifdef CONFIG_X86_32
21954 /*
21955 * The sysexit path does not restore ds/es, so we must set them to
21956 * a reasonable value ourselves.
21957@@ -6353,8 +6378,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
21958 * may be executed in interrupt context, which saves and restore segments
21959 * around it, nullifying its effect.
21960 */
21961- loadsegment(ds, __USER_DS);
21962- loadsegment(es, __USER_DS);
21963+ loadsegment(ds, __KERNEL_DS);
21964+ loadsegment(es, __KERNEL_DS);
21965+ loadsegment(ss, __KERNEL_DS);
21966+
21967+#ifdef CONFIG_PAX_KERNEXEC
21968+ loadsegment(fs, __KERNEL_PERCPU);
21969+#endif
21970+
21971+#ifdef CONFIG_PAX_MEMORY_UDEREF
21972+ __set_fs(current_thread_info()->addr_limit);
21973+#endif
21974+
21975 #endif
21976
21977 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
21978diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
21979index 4f76417..93429b5 100644
21980--- a/arch/x86/kvm/x86.c
21981+++ b/arch/x86/kvm/x86.c
21982@@ -1390,8 +1390,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
21983 {
21984 struct kvm *kvm = vcpu->kvm;
21985 int lm = is_long_mode(vcpu);
21986- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21987- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21988+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
21989+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
21990 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
21991 : kvm->arch.xen_hvm_config.blob_size_32;
21992 u32 page_num = data & ~PAGE_MASK;
21993@@ -2255,6 +2255,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
21994 if (n < msr_list.nmsrs)
21995 goto out;
21996 r = -EFAULT;
21997+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
21998+ goto out;
21999 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
22000 num_msrs_to_save * sizeof(u32)))
22001 goto out;
22002@@ -2379,7 +2381,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
22003 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
22004 struct kvm_interrupt *irq)
22005 {
22006- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
22007+ if (irq->irq >= KVM_NR_INTERRUPTS)
22008 return -EINVAL;
22009 if (irqchip_in_kernel(vcpu->kvm))
22010 return -ENXIO;
22011@@ -4881,7 +4883,7 @@ static void kvm_set_mmio_spte_mask(void)
22012 kvm_mmu_set_mmio_spte_mask(mask);
22013 }
22014
22015-int kvm_arch_init(void *opaque)
22016+int kvm_arch_init(const void *opaque)
22017 {
22018 int r;
22019 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
22020diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
22021index 642d880..5dd034e 100644
22022--- a/arch/x86/lguest/boot.c
22023+++ b/arch/x86/lguest/boot.c
22024@@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
22025
22026 static void set_lguest_basic_apic_ops(void)
22027 {
22028- apic->read = lguest_apic_read;
22029- apic->write = lguest_apic_write;
22030- apic->icr_read = lguest_apic_icr_read;
22031- apic->icr_write = lguest_apic_icr_write;
22032- apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22033- apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22034+ *(void **)&apic->read = lguest_apic_read;
22035+ *(void **)&apic->write = lguest_apic_write;
22036+ *(void **)&apic->icr_read = lguest_apic_icr_read;
22037+ *(void **)&apic->icr_write = lguest_apic_icr_write;
22038+ *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
22039+ *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
22040 };
22041 #endif
22042
22043@@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
22044 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
22045 * Launcher to reboot us.
22046 */
22047-static void lguest_restart(char *reason)
22048+static __noreturn void lguest_restart(char *reason)
22049 {
22050 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
22051+ BUG();
22052 }
22053
22054 /*G:050
22055@@ -1292,28 +1293,28 @@ __init void lguest_init(void)
22056 pv_irq_ops.safe_halt = lguest_safe_halt;
22057
22058 /* Setup operations */
22059- pv_init_ops.patch = lguest_patch;
22060+ *(void **)&pv_init_ops.patch = lguest_patch;
22061
22062 /* Intercepts of various CPU instructions */
22063- pv_cpu_ops.load_gdt = lguest_load_gdt;
22064- pv_cpu_ops.cpuid = lguest_cpuid;
22065- pv_cpu_ops.load_idt = lguest_load_idt;
22066- pv_cpu_ops.iret = lguest_iret;
22067- pv_cpu_ops.load_sp0 = lguest_load_sp0;
22068- pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22069- pv_cpu_ops.set_ldt = lguest_set_ldt;
22070- pv_cpu_ops.load_tls = lguest_load_tls;
22071- pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22072- pv_cpu_ops.clts = lguest_clts;
22073- pv_cpu_ops.read_cr0 = lguest_read_cr0;
22074- pv_cpu_ops.write_cr0 = lguest_write_cr0;
22075- pv_cpu_ops.read_cr4 = lguest_read_cr4;
22076- pv_cpu_ops.write_cr4 = lguest_write_cr4;
22077- pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22078- pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22079- pv_cpu_ops.wbinvd = lguest_wbinvd;
22080- pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22081- pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22082+ *(void **)&pv_cpu_ops.load_gdt = lguest_load_gdt;
22083+ *(void **)&pv_cpu_ops.cpuid = lguest_cpuid;
22084+ *(void **)&pv_cpu_ops.load_idt = lguest_load_idt;
22085+ *(void **)&pv_cpu_ops.iret = lguest_iret;
22086+ *(void **)&pv_cpu_ops.load_sp0 = lguest_load_sp0;
22087+ *(void **)&pv_cpu_ops.load_tr_desc = lguest_load_tr_desc;
22088+ *(void **)&pv_cpu_ops.set_ldt = lguest_set_ldt;
22089+ *(void **)&pv_cpu_ops.load_tls = lguest_load_tls;
22090+ *(void **)&pv_cpu_ops.set_debugreg = lguest_set_debugreg;
22091+ *(void **)&pv_cpu_ops.clts = lguest_clts;
22092+ *(void **)&pv_cpu_ops.read_cr0 = lguest_read_cr0;
22093+ *(void **)&pv_cpu_ops.write_cr0 = lguest_write_cr0;
22094+ *(void **)&pv_cpu_ops.read_cr4 = lguest_read_cr4;
22095+ *(void **)&pv_cpu_ops.write_cr4 = lguest_write_cr4;
22096+ *(void **)&pv_cpu_ops.write_gdt_entry = lguest_write_gdt_entry;
22097+ *(void **)&pv_cpu_ops.write_idt_entry = lguest_write_idt_entry;
22098+ *(void **)&pv_cpu_ops.wbinvd = lguest_wbinvd;
22099+ *(void **)&pv_cpu_ops.start_context_switch = paravirt_start_context_switch;
22100+ *(void **)&pv_cpu_ops.end_context_switch = lguest_end_context_switch;
22101
22102 /* Pagetable management */
22103 pv_mmu_ops.write_cr3 = lguest_write_cr3;
22104@@ -1341,11 +1342,11 @@ __init void lguest_init(void)
22105 set_lguest_basic_apic_ops();
22106 #endif
22107
22108- x86_init.resources.memory_setup = lguest_memory_setup;
22109- x86_init.irqs.intr_init = lguest_init_IRQ;
22110- x86_init.timers.timer_init = lguest_time_init;
22111- x86_platform.calibrate_tsc = lguest_tsc_khz;
22112- x86_platform.get_wallclock = lguest_get_wallclock;
22113+ *(void **)&x86_init.resources.memory_setup = lguest_memory_setup;
22114+ *(void **)&x86_init.irqs.intr_init = lguest_init_IRQ;
22115+ *(void **)&x86_init.timers.timer_init = lguest_time_init;
22116+ *(void **)&x86_platform.calibrate_tsc = lguest_tsc_khz;
22117+ *(void **)&x86_platform.get_wallclock = lguest_get_wallclock;
22118
22119 /*
22120 * Now is a good time to look at the implementations of these functions
22121@@ -1434,7 +1435,7 @@ __init void lguest_init(void)
22122 * routine.
22123 */
22124 pm_power_off = lguest_power_off;
22125- machine_ops.restart = lguest_restart;
22126+ *(void **)&machine_ops.restart = lguest_restart;
22127
22128 /*
22129 * Now we're set up, call i386_start_kernel() in head32.c and we proceed
22130diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
22131index 00933d5..3a64af9 100644
22132--- a/arch/x86/lib/atomic64_386_32.S
22133+++ b/arch/x86/lib/atomic64_386_32.S
22134@@ -48,6 +48,10 @@ BEGIN(read)
22135 movl (v), %eax
22136 movl 4(v), %edx
22137 RET_ENDP
22138+BEGIN(read_unchecked)
22139+ movl (v), %eax
22140+ movl 4(v), %edx
22141+RET_ENDP
22142 #undef v
22143
22144 #define v %esi
22145@@ -55,6 +59,10 @@ BEGIN(set)
22146 movl %ebx, (v)
22147 movl %ecx, 4(v)
22148 RET_ENDP
22149+BEGIN(set_unchecked)
22150+ movl %ebx, (v)
22151+ movl %ecx, 4(v)
22152+RET_ENDP
22153 #undef v
22154
22155 #define v %esi
22156@@ -70,6 +78,20 @@ RET_ENDP
22157 BEGIN(add)
22158 addl %eax, (v)
22159 adcl %edx, 4(v)
22160+
22161+#ifdef CONFIG_PAX_REFCOUNT
22162+ jno 0f
22163+ subl %eax, (v)
22164+ sbbl %edx, 4(v)
22165+ int $4
22166+0:
22167+ _ASM_EXTABLE(0b, 0b)
22168+#endif
22169+
22170+RET_ENDP
22171+BEGIN(add_unchecked)
22172+ addl %eax, (v)
22173+ adcl %edx, 4(v)
22174 RET_ENDP
22175 #undef v
22176
22177@@ -77,6 +99,24 @@ RET_ENDP
22178 BEGIN(add_return)
22179 addl (v), %eax
22180 adcl 4(v), %edx
22181+
22182+#ifdef CONFIG_PAX_REFCOUNT
22183+ into
22184+1234:
22185+ _ASM_EXTABLE(1234b, 2f)
22186+#endif
22187+
22188+ movl %eax, (v)
22189+ movl %edx, 4(v)
22190+
22191+#ifdef CONFIG_PAX_REFCOUNT
22192+2:
22193+#endif
22194+
22195+RET_ENDP
22196+BEGIN(add_return_unchecked)
22197+ addl (v), %eax
22198+ adcl 4(v), %edx
22199 movl %eax, (v)
22200 movl %edx, 4(v)
22201 RET_ENDP
22202@@ -86,6 +126,20 @@ RET_ENDP
22203 BEGIN(sub)
22204 subl %eax, (v)
22205 sbbl %edx, 4(v)
22206+
22207+#ifdef CONFIG_PAX_REFCOUNT
22208+ jno 0f
22209+ addl %eax, (v)
22210+ adcl %edx, 4(v)
22211+ int $4
22212+0:
22213+ _ASM_EXTABLE(0b, 0b)
22214+#endif
22215+
22216+RET_ENDP
22217+BEGIN(sub_unchecked)
22218+ subl %eax, (v)
22219+ sbbl %edx, 4(v)
22220 RET_ENDP
22221 #undef v
22222
22223@@ -96,6 +150,27 @@ BEGIN(sub_return)
22224 sbbl $0, %edx
22225 addl (v), %eax
22226 adcl 4(v), %edx
22227+
22228+#ifdef CONFIG_PAX_REFCOUNT
22229+ into
22230+1234:
22231+ _ASM_EXTABLE(1234b, 2f)
22232+#endif
22233+
22234+ movl %eax, (v)
22235+ movl %edx, 4(v)
22236+
22237+#ifdef CONFIG_PAX_REFCOUNT
22238+2:
22239+#endif
22240+
22241+RET_ENDP
22242+BEGIN(sub_return_unchecked)
22243+ negl %edx
22244+ negl %eax
22245+ sbbl $0, %edx
22246+ addl (v), %eax
22247+ adcl 4(v), %edx
22248 movl %eax, (v)
22249 movl %edx, 4(v)
22250 RET_ENDP
22251@@ -105,6 +180,20 @@ RET_ENDP
22252 BEGIN(inc)
22253 addl $1, (v)
22254 adcl $0, 4(v)
22255+
22256+#ifdef CONFIG_PAX_REFCOUNT
22257+ jno 0f
22258+ subl $1, (v)
22259+ sbbl $0, 4(v)
22260+ int $4
22261+0:
22262+ _ASM_EXTABLE(0b, 0b)
22263+#endif
22264+
22265+RET_ENDP
22266+BEGIN(inc_unchecked)
22267+ addl $1, (v)
22268+ adcl $0, 4(v)
22269 RET_ENDP
22270 #undef v
22271
22272@@ -114,6 +203,26 @@ BEGIN(inc_return)
22273 movl 4(v), %edx
22274 addl $1, %eax
22275 adcl $0, %edx
22276+
22277+#ifdef CONFIG_PAX_REFCOUNT
22278+ into
22279+1234:
22280+ _ASM_EXTABLE(1234b, 2f)
22281+#endif
22282+
22283+ movl %eax, (v)
22284+ movl %edx, 4(v)
22285+
22286+#ifdef CONFIG_PAX_REFCOUNT
22287+2:
22288+#endif
22289+
22290+RET_ENDP
22291+BEGIN(inc_return_unchecked)
22292+ movl (v), %eax
22293+ movl 4(v), %edx
22294+ addl $1, %eax
22295+ adcl $0, %edx
22296 movl %eax, (v)
22297 movl %edx, 4(v)
22298 RET_ENDP
22299@@ -123,6 +232,20 @@ RET_ENDP
22300 BEGIN(dec)
22301 subl $1, (v)
22302 sbbl $0, 4(v)
22303+
22304+#ifdef CONFIG_PAX_REFCOUNT
22305+ jno 0f
22306+ addl $1, (v)
22307+ adcl $0, 4(v)
22308+ int $4
22309+0:
22310+ _ASM_EXTABLE(0b, 0b)
22311+#endif
22312+
22313+RET_ENDP
22314+BEGIN(dec_unchecked)
22315+ subl $1, (v)
22316+ sbbl $0, 4(v)
22317 RET_ENDP
22318 #undef v
22319
22320@@ -132,6 +255,26 @@ BEGIN(dec_return)
22321 movl 4(v), %edx
22322 subl $1, %eax
22323 sbbl $0, %edx
22324+
22325+#ifdef CONFIG_PAX_REFCOUNT
22326+ into
22327+1234:
22328+ _ASM_EXTABLE(1234b, 2f)
22329+#endif
22330+
22331+ movl %eax, (v)
22332+ movl %edx, 4(v)
22333+
22334+#ifdef CONFIG_PAX_REFCOUNT
22335+2:
22336+#endif
22337+
22338+RET_ENDP
22339+BEGIN(dec_return_unchecked)
22340+ movl (v), %eax
22341+ movl 4(v), %edx
22342+ subl $1, %eax
22343+ sbbl $0, %edx
22344 movl %eax, (v)
22345 movl %edx, 4(v)
22346 RET_ENDP
22347@@ -143,6 +286,13 @@ BEGIN(add_unless)
22348 adcl %edx, %edi
22349 addl (v), %eax
22350 adcl 4(v), %edx
22351+
22352+#ifdef CONFIG_PAX_REFCOUNT
22353+ into
22354+1234:
22355+ _ASM_EXTABLE(1234b, 2f)
22356+#endif
22357+
22358 cmpl %eax, %ecx
22359 je 3f
22360 1:
22361@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
22362 1:
22363 addl $1, %eax
22364 adcl $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 movl $1, %eax
22375@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
22376 movl 4(v), %edx
22377 subl $1, %eax
22378 sbbl $0, %edx
22379+
22380+#ifdef CONFIG_PAX_REFCOUNT
22381+ into
22382+1234:
22383+ _ASM_EXTABLE(1234b, 1f)
22384+#endif
22385+
22386 js 1f
22387 movl %eax, (v)
22388 movl %edx, 4(v)
22389diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
22390index f5cc9eb..51fa319 100644
22391--- a/arch/x86/lib/atomic64_cx8_32.S
22392+++ b/arch/x86/lib/atomic64_cx8_32.S
22393@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
22394 CFI_STARTPROC
22395
22396 read64 %ecx
22397+ pax_force_retaddr
22398 ret
22399 CFI_ENDPROC
22400 ENDPROC(atomic64_read_cx8)
22401
22402+ENTRY(atomic64_read_unchecked_cx8)
22403+ CFI_STARTPROC
22404+
22405+ read64 %ecx
22406+ pax_force_retaddr
22407+ ret
22408+ CFI_ENDPROC
22409+ENDPROC(atomic64_read_unchecked_cx8)
22410+
22411 ENTRY(atomic64_set_cx8)
22412 CFI_STARTPROC
22413
22414@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
22415 cmpxchg8b (%esi)
22416 jne 1b
22417
22418+ pax_force_retaddr
22419 ret
22420 CFI_ENDPROC
22421 ENDPROC(atomic64_set_cx8)
22422
22423+ENTRY(atomic64_set_unchecked_cx8)
22424+ CFI_STARTPROC
22425+
22426+1:
22427+/* we don't need LOCK_PREFIX since aligned 64-bit writes
22428+ * are atomic on 586 and newer */
22429+ cmpxchg8b (%esi)
22430+ jne 1b
22431+
22432+ pax_force_retaddr
22433+ ret
22434+ CFI_ENDPROC
22435+ENDPROC(atomic64_set_unchecked_cx8)
22436+
22437 ENTRY(atomic64_xchg_cx8)
22438 CFI_STARTPROC
22439
22440@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
22441 cmpxchg8b (%esi)
22442 jne 1b
22443
22444+ pax_force_retaddr
22445 ret
22446 CFI_ENDPROC
22447 ENDPROC(atomic64_xchg_cx8)
22448
22449-.macro addsub_return func ins insc
22450-ENTRY(atomic64_\func\()_return_cx8)
22451+.macro addsub_return func ins insc unchecked=""
22452+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22453 CFI_STARTPROC
22454 SAVE ebp
22455 SAVE ebx
22456@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
22457 movl %edx, %ecx
22458 \ins\()l %esi, %ebx
22459 \insc\()l %edi, %ecx
22460+
22461+.ifb \unchecked
22462+#ifdef CONFIG_PAX_REFCOUNT
22463+ into
22464+2:
22465+ _ASM_EXTABLE(2b, 3f)
22466+#endif
22467+.endif
22468+
22469 LOCK_PREFIX
22470 cmpxchg8b (%ebp)
22471 jne 1b
22472-
22473-10:
22474 movl %ebx, %eax
22475 movl %ecx, %edx
22476+
22477+.ifb \unchecked
22478+#ifdef CONFIG_PAX_REFCOUNT
22479+3:
22480+#endif
22481+.endif
22482+
22483 RESTORE edi
22484 RESTORE esi
22485 RESTORE ebx
22486 RESTORE ebp
22487+ pax_force_retaddr
22488 ret
22489 CFI_ENDPROC
22490-ENDPROC(atomic64_\func\()_return_cx8)
22491+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22492 .endm
22493
22494 addsub_return add add adc
22495 addsub_return sub sub sbb
22496+addsub_return add add adc _unchecked
22497+addsub_return sub sub sbb _unchecked
22498
22499-.macro incdec_return func ins insc
22500-ENTRY(atomic64_\func\()_return_cx8)
22501+.macro incdec_return func ins insc unchecked=""
22502+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
22503 CFI_STARTPROC
22504 SAVE ebx
22505
22506@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
22507 movl %edx, %ecx
22508 \ins\()l $1, %ebx
22509 \insc\()l $0, %ecx
22510+
22511+.ifb \unchecked
22512+#ifdef CONFIG_PAX_REFCOUNT
22513+ into
22514+2:
22515+ _ASM_EXTABLE(2b, 3f)
22516+#endif
22517+.endif
22518+
22519 LOCK_PREFIX
22520 cmpxchg8b (%esi)
22521 jne 1b
22522
22523-10:
22524 movl %ebx, %eax
22525 movl %ecx, %edx
22526+
22527+.ifb \unchecked
22528+#ifdef CONFIG_PAX_REFCOUNT
22529+3:
22530+#endif
22531+.endif
22532+
22533 RESTORE ebx
22534+ pax_force_retaddr
22535 ret
22536 CFI_ENDPROC
22537-ENDPROC(atomic64_\func\()_return_cx8)
22538+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
22539 .endm
22540
22541 incdec_return inc add adc
22542 incdec_return dec sub sbb
22543+incdec_return inc add adc _unchecked
22544+incdec_return dec sub sbb _unchecked
22545
22546 ENTRY(atomic64_dec_if_positive_cx8)
22547 CFI_STARTPROC
22548@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
22549 movl %edx, %ecx
22550 subl $1, %ebx
22551 sbb $0, %ecx
22552+
22553+#ifdef CONFIG_PAX_REFCOUNT
22554+ into
22555+1234:
22556+ _ASM_EXTABLE(1234b, 2f)
22557+#endif
22558+
22559 js 2f
22560 LOCK_PREFIX
22561 cmpxchg8b (%esi)
22562@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
22563 movl %ebx, %eax
22564 movl %ecx, %edx
22565 RESTORE ebx
22566+ pax_force_retaddr
22567 ret
22568 CFI_ENDPROC
22569 ENDPROC(atomic64_dec_if_positive_cx8)
22570@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
22571 movl %edx, %ecx
22572 addl %ebp, %ebx
22573 adcl %edi, %ecx
22574+
22575+#ifdef CONFIG_PAX_REFCOUNT
22576+ into
22577+1234:
22578+ _ASM_EXTABLE(1234b, 3f)
22579+#endif
22580+
22581 LOCK_PREFIX
22582 cmpxchg8b (%esi)
22583 jne 1b
22584@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
22585 CFI_ADJUST_CFA_OFFSET -8
22586 RESTORE ebx
22587 RESTORE ebp
22588+ pax_force_retaddr
22589 ret
22590 4:
22591 cmpl %edx, 4(%esp)
22592@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
22593 xorl %ecx, %ecx
22594 addl $1, %ebx
22595 adcl %edx, %ecx
22596+
22597+#ifdef CONFIG_PAX_REFCOUNT
22598+ into
22599+1234:
22600+ _ASM_EXTABLE(1234b, 3f)
22601+#endif
22602+
22603 LOCK_PREFIX
22604 cmpxchg8b (%esi)
22605 jne 1b
22606@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
22607 movl $1, %eax
22608 3:
22609 RESTORE ebx
22610+ pax_force_retaddr
22611 ret
22612 CFI_ENDPROC
22613 ENDPROC(atomic64_inc_not_zero_cx8)
22614diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
22615index 2af5df3..62b1a5a 100644
22616--- a/arch/x86/lib/checksum_32.S
22617+++ b/arch/x86/lib/checksum_32.S
22618@@ -29,7 +29,8 @@
22619 #include <asm/dwarf2.h>
22620 #include <asm/errno.h>
22621 #include <asm/asm.h>
22622-
22623+#include <asm/segment.h>
22624+
22625 /*
22626 * computes a partial checksum, e.g. for TCP/UDP fragments
22627 */
22628@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
22629
22630 #define ARGBASE 16
22631 #define FP 12
22632-
22633-ENTRY(csum_partial_copy_generic)
22634+
22635+ENTRY(csum_partial_copy_generic_to_user)
22636 CFI_STARTPROC
22637+
22638+#ifdef CONFIG_PAX_MEMORY_UDEREF
22639+ pushl_cfi %gs
22640+ popl_cfi %es
22641+ jmp csum_partial_copy_generic
22642+#endif
22643+
22644+ENTRY(csum_partial_copy_generic_from_user)
22645+
22646+#ifdef CONFIG_PAX_MEMORY_UDEREF
22647+ pushl_cfi %gs
22648+ popl_cfi %ds
22649+#endif
22650+
22651+ENTRY(csum_partial_copy_generic)
22652 subl $4,%esp
22653 CFI_ADJUST_CFA_OFFSET 4
22654 pushl_cfi %edi
22655@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
22656 jmp 4f
22657 SRC(1: movw (%esi), %bx )
22658 addl $2, %esi
22659-DST( movw %bx, (%edi) )
22660+DST( movw %bx, %es:(%edi) )
22661 addl $2, %edi
22662 addw %bx, %ax
22663 adcl $0, %eax
22664@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
22665 SRC(1: movl (%esi), %ebx )
22666 SRC( movl 4(%esi), %edx )
22667 adcl %ebx, %eax
22668-DST( movl %ebx, (%edi) )
22669+DST( movl %ebx, %es:(%edi) )
22670 adcl %edx, %eax
22671-DST( movl %edx, 4(%edi) )
22672+DST( movl %edx, %es:4(%edi) )
22673
22674 SRC( movl 8(%esi), %ebx )
22675 SRC( movl 12(%esi), %edx )
22676 adcl %ebx, %eax
22677-DST( movl %ebx, 8(%edi) )
22678+DST( movl %ebx, %es:8(%edi) )
22679 adcl %edx, %eax
22680-DST( movl %edx, 12(%edi) )
22681+DST( movl %edx, %es:12(%edi) )
22682
22683 SRC( movl 16(%esi), %ebx )
22684 SRC( movl 20(%esi), %edx )
22685 adcl %ebx, %eax
22686-DST( movl %ebx, 16(%edi) )
22687+DST( movl %ebx, %es:16(%edi) )
22688 adcl %edx, %eax
22689-DST( movl %edx, 20(%edi) )
22690+DST( movl %edx, %es:20(%edi) )
22691
22692 SRC( movl 24(%esi), %ebx )
22693 SRC( movl 28(%esi), %edx )
22694 adcl %ebx, %eax
22695-DST( movl %ebx, 24(%edi) )
22696+DST( movl %ebx, %es:24(%edi) )
22697 adcl %edx, %eax
22698-DST( movl %edx, 28(%edi) )
22699+DST( movl %edx, %es:28(%edi) )
22700
22701 lea 32(%esi), %esi
22702 lea 32(%edi), %edi
22703@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
22704 shrl $2, %edx # This clears CF
22705 SRC(3: movl (%esi), %ebx )
22706 adcl %ebx, %eax
22707-DST( movl %ebx, (%edi) )
22708+DST( movl %ebx, %es:(%edi) )
22709 lea 4(%esi), %esi
22710 lea 4(%edi), %edi
22711 dec %edx
22712@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
22713 jb 5f
22714 SRC( movw (%esi), %cx )
22715 leal 2(%esi), %esi
22716-DST( movw %cx, (%edi) )
22717+DST( movw %cx, %es:(%edi) )
22718 leal 2(%edi), %edi
22719 je 6f
22720 shll $16,%ecx
22721 SRC(5: movb (%esi), %cl )
22722-DST( movb %cl, (%edi) )
22723+DST( movb %cl, %es:(%edi) )
22724 6: addl %ecx, %eax
22725 adcl $0, %eax
22726 7:
22727@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
22728
22729 6001:
22730 movl ARGBASE+20(%esp), %ebx # src_err_ptr
22731- movl $-EFAULT, (%ebx)
22732+ movl $-EFAULT, %ss:(%ebx)
22733
22734 # zero the complete destination - computing the rest
22735 # is too much work
22736@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
22737
22738 6002:
22739 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22740- movl $-EFAULT,(%ebx)
22741+ movl $-EFAULT,%ss:(%ebx)
22742 jmp 5000b
22743
22744 .previous
22745
22746+ pushl_cfi %ss
22747+ popl_cfi %ds
22748+ pushl_cfi %ss
22749+ popl_cfi %es
22750 popl_cfi %ebx
22751 CFI_RESTORE ebx
22752 popl_cfi %esi
22753@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
22754 popl_cfi %ecx # equivalent to addl $4,%esp
22755 ret
22756 CFI_ENDPROC
22757-ENDPROC(csum_partial_copy_generic)
22758+ENDPROC(csum_partial_copy_generic_to_user)
22759
22760 #else
22761
22762 /* Version for PentiumII/PPro */
22763
22764 #define ROUND1(x) \
22765+ nop; nop; nop; \
22766 SRC(movl x(%esi), %ebx ) ; \
22767 addl %ebx, %eax ; \
22768- DST(movl %ebx, x(%edi) ) ;
22769+ DST(movl %ebx, %es:x(%edi)) ;
22770
22771 #define ROUND(x) \
22772+ nop; nop; nop; \
22773 SRC(movl x(%esi), %ebx ) ; \
22774 adcl %ebx, %eax ; \
22775- DST(movl %ebx, x(%edi) ) ;
22776+ DST(movl %ebx, %es:x(%edi)) ;
22777
22778 #define ARGBASE 12
22779-
22780-ENTRY(csum_partial_copy_generic)
22781+
22782+ENTRY(csum_partial_copy_generic_to_user)
22783 CFI_STARTPROC
22784+
22785+#ifdef CONFIG_PAX_MEMORY_UDEREF
22786+ pushl_cfi %gs
22787+ popl_cfi %es
22788+ jmp csum_partial_copy_generic
22789+#endif
22790+
22791+ENTRY(csum_partial_copy_generic_from_user)
22792+
22793+#ifdef CONFIG_PAX_MEMORY_UDEREF
22794+ pushl_cfi %gs
22795+ popl_cfi %ds
22796+#endif
22797+
22798+ENTRY(csum_partial_copy_generic)
22799 pushl_cfi %ebx
22800 CFI_REL_OFFSET ebx, 0
22801 pushl_cfi %edi
22802@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
22803 subl %ebx, %edi
22804 lea -1(%esi),%edx
22805 andl $-32,%edx
22806- lea 3f(%ebx,%ebx), %ebx
22807+ lea 3f(%ebx,%ebx,2), %ebx
22808 testl %esi, %esi
22809 jmp *%ebx
22810 1: addl $64,%esi
22811@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
22812 jb 5f
22813 SRC( movw (%esi), %dx )
22814 leal 2(%esi), %esi
22815-DST( movw %dx, (%edi) )
22816+DST( movw %dx, %es:(%edi) )
22817 leal 2(%edi), %edi
22818 je 6f
22819 shll $16,%edx
22820 5:
22821 SRC( movb (%esi), %dl )
22822-DST( movb %dl, (%edi) )
22823+DST( movb %dl, %es:(%edi) )
22824 6: addl %edx, %eax
22825 adcl $0, %eax
22826 7:
22827 .section .fixup, "ax"
22828 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
22829- movl $-EFAULT, (%ebx)
22830+ movl $-EFAULT, %ss:(%ebx)
22831 # zero the complete destination (computing the rest is too much work)
22832 movl ARGBASE+8(%esp),%edi # dst
22833 movl ARGBASE+12(%esp),%ecx # len
22834@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
22835 rep; stosb
22836 jmp 7b
22837 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
22838- movl $-EFAULT, (%ebx)
22839+ movl $-EFAULT, %ss:(%ebx)
22840 jmp 7b
22841 .previous
22842
22843+#ifdef CONFIG_PAX_MEMORY_UDEREF
22844+ pushl_cfi %ss
22845+ popl_cfi %ds
22846+ pushl_cfi %ss
22847+ popl_cfi %es
22848+#endif
22849+
22850 popl_cfi %esi
22851 CFI_RESTORE esi
22852 popl_cfi %edi
22853@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
22854 CFI_RESTORE ebx
22855 ret
22856 CFI_ENDPROC
22857-ENDPROC(csum_partial_copy_generic)
22858+ENDPROC(csum_partial_copy_generic_to_user)
22859
22860 #undef ROUND
22861 #undef ROUND1
22862diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
22863index f2145cf..cea889d 100644
22864--- a/arch/x86/lib/clear_page_64.S
22865+++ b/arch/x86/lib/clear_page_64.S
22866@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
22867 movl $4096/8,%ecx
22868 xorl %eax,%eax
22869 rep stosq
22870+ pax_force_retaddr
22871 ret
22872 CFI_ENDPROC
22873 ENDPROC(clear_page_c)
22874@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
22875 movl $4096,%ecx
22876 xorl %eax,%eax
22877 rep stosb
22878+ pax_force_retaddr
22879 ret
22880 CFI_ENDPROC
22881 ENDPROC(clear_page_c_e)
22882@@ -43,6 +45,7 @@ ENTRY(clear_page)
22883 leaq 64(%rdi),%rdi
22884 jnz .Lloop
22885 nop
22886+ pax_force_retaddr
22887 ret
22888 CFI_ENDPROC
22889 .Lclear_page_end:
22890@@ -58,7 +61,7 @@ ENDPROC(clear_page)
22891
22892 #include <asm/cpufeature.h>
22893
22894- .section .altinstr_replacement,"ax"
22895+ .section .altinstr_replacement,"a"
22896 1: .byte 0xeb /* jmp <disp8> */
22897 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
22898 2: .byte 0xeb /* jmp <disp8> */
22899diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
22900index 1e572c5..2a162cd 100644
22901--- a/arch/x86/lib/cmpxchg16b_emu.S
22902+++ b/arch/x86/lib/cmpxchg16b_emu.S
22903@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
22904
22905 popf
22906 mov $1, %al
22907+ pax_force_retaddr
22908 ret
22909
22910 not_same:
22911 popf
22912 xor %al,%al
22913+ pax_force_retaddr
22914 ret
22915
22916 CFI_ENDPROC
22917diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
22918index 6b34d04..dccb07f 100644
22919--- a/arch/x86/lib/copy_page_64.S
22920+++ b/arch/x86/lib/copy_page_64.S
22921@@ -9,6 +9,7 @@ copy_page_c:
22922 CFI_STARTPROC
22923 movl $4096/8,%ecx
22924 rep movsq
22925+ pax_force_retaddr
22926 ret
22927 CFI_ENDPROC
22928 ENDPROC(copy_page_c)
22929@@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
22930
22931 ENTRY(copy_page)
22932 CFI_STARTPROC
22933- subq $2*8,%rsp
22934- CFI_ADJUST_CFA_OFFSET 2*8
22935+ subq $3*8,%rsp
22936+ CFI_ADJUST_CFA_OFFSET 3*8
22937 movq %rbx,(%rsp)
22938 CFI_REL_OFFSET rbx, 0
22939 movq %r12,1*8(%rsp)
22940 CFI_REL_OFFSET r12, 1*8
22941+ movq %r13,2*8(%rsp)
22942+ CFI_REL_OFFSET r13, 2*8
22943
22944 movl $(4096/64)-5,%ecx
22945 .p2align 4
22946@@ -37,7 +40,7 @@ ENTRY(copy_page)
22947 movq 16 (%rsi), %rdx
22948 movq 24 (%rsi), %r8
22949 movq 32 (%rsi), %r9
22950- movq 40 (%rsi), %r10
22951+ movq 40 (%rsi), %r13
22952 movq 48 (%rsi), %r11
22953 movq 56 (%rsi), %r12
22954
22955@@ -48,7 +51,7 @@ ENTRY(copy_page)
22956 movq %rdx, 16 (%rdi)
22957 movq %r8, 24 (%rdi)
22958 movq %r9, 32 (%rdi)
22959- movq %r10, 40 (%rdi)
22960+ movq %r13, 40 (%rdi)
22961 movq %r11, 48 (%rdi)
22962 movq %r12, 56 (%rdi)
22963
22964@@ -67,7 +70,7 @@ ENTRY(copy_page)
22965 movq 16 (%rsi), %rdx
22966 movq 24 (%rsi), %r8
22967 movq 32 (%rsi), %r9
22968- movq 40 (%rsi), %r10
22969+ movq 40 (%rsi), %r13
22970 movq 48 (%rsi), %r11
22971 movq 56 (%rsi), %r12
22972
22973@@ -76,7 +79,7 @@ ENTRY(copy_page)
22974 movq %rdx, 16 (%rdi)
22975 movq %r8, 24 (%rdi)
22976 movq %r9, 32 (%rdi)
22977- movq %r10, 40 (%rdi)
22978+ movq %r13, 40 (%rdi)
22979 movq %r11, 48 (%rdi)
22980 movq %r12, 56 (%rdi)
22981
22982@@ -89,8 +92,11 @@ ENTRY(copy_page)
22983 CFI_RESTORE rbx
22984 movq 1*8(%rsp),%r12
22985 CFI_RESTORE r12
22986- addq $2*8,%rsp
22987- CFI_ADJUST_CFA_OFFSET -2*8
22988+ movq 2*8(%rsp),%r13
22989+ CFI_RESTORE r13
22990+ addq $3*8,%rsp
22991+ CFI_ADJUST_CFA_OFFSET -3*8
22992+ pax_force_retaddr
22993 ret
22994 .Lcopy_page_end:
22995 CFI_ENDPROC
22996@@ -101,7 +107,7 @@ ENDPROC(copy_page)
22997
22998 #include <asm/cpufeature.h>
22999
23000- .section .altinstr_replacement,"ax"
23001+ .section .altinstr_replacement,"a"
23002 1: .byte 0xeb /* jmp <disp8> */
23003 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
23004 2:
23005diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
23006index a30ca15..d25fab6 100644
23007--- a/arch/x86/lib/copy_user_64.S
23008+++ b/arch/x86/lib/copy_user_64.S
23009@@ -18,6 +18,7 @@
23010 #include <asm/alternative-asm.h>
23011 #include <asm/asm.h>
23012 #include <asm/smap.h>
23013+#include <asm/pgtable.h>
23014
23015 /*
23016 * By placing feature2 after feature1 in altinstructions section, we logically
23017@@ -31,7 +32,7 @@
23018 .byte 0xe9 /* 32bit jump */
23019 .long \orig-1f /* by default jump to orig */
23020 1:
23021- .section .altinstr_replacement,"ax"
23022+ .section .altinstr_replacement,"a"
23023 2: .byte 0xe9 /* near jump with 32bit immediate */
23024 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
23025 3: .byte 0xe9 /* near jump with 32bit immediate */
23026@@ -70,47 +71,20 @@
23027 #endif
23028 .endm
23029
23030-/* Standard copy_to_user with segment limit checking */
23031-ENTRY(_copy_to_user)
23032- CFI_STARTPROC
23033- GET_THREAD_INFO(%rax)
23034- movq %rdi,%rcx
23035- addq %rdx,%rcx
23036- jc bad_to_user
23037- cmpq TI_addr_limit(%rax),%rcx
23038- ja bad_to_user
23039- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23040- copy_user_generic_unrolled,copy_user_generic_string, \
23041- copy_user_enhanced_fast_string
23042- CFI_ENDPROC
23043-ENDPROC(_copy_to_user)
23044-
23045-/* Standard copy_from_user with segment limit checking */
23046-ENTRY(_copy_from_user)
23047- CFI_STARTPROC
23048- GET_THREAD_INFO(%rax)
23049- movq %rsi,%rcx
23050- addq %rdx,%rcx
23051- jc bad_from_user
23052- cmpq TI_addr_limit(%rax),%rcx
23053- ja bad_from_user
23054- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
23055- copy_user_generic_unrolled,copy_user_generic_string, \
23056- copy_user_enhanced_fast_string
23057- CFI_ENDPROC
23058-ENDPROC(_copy_from_user)
23059-
23060 .section .fixup,"ax"
23061 /* must zero dest */
23062 ENTRY(bad_from_user)
23063 bad_from_user:
23064 CFI_STARTPROC
23065+ testl %edx,%edx
23066+ js bad_to_user
23067 movl %edx,%ecx
23068 xorl %eax,%eax
23069 rep
23070 stosb
23071 bad_to_user:
23072 movl %edx,%eax
23073+ pax_force_retaddr
23074 ret
23075 CFI_ENDPROC
23076 ENDPROC(bad_from_user)
23077@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
23078 jz 17f
23079 1: movq (%rsi),%r8
23080 2: movq 1*8(%rsi),%r9
23081-3: movq 2*8(%rsi),%r10
23082+3: movq 2*8(%rsi),%rax
23083 4: movq 3*8(%rsi),%r11
23084 5: movq %r8,(%rdi)
23085 6: movq %r9,1*8(%rdi)
23086-7: movq %r10,2*8(%rdi)
23087+7: movq %rax,2*8(%rdi)
23088 8: movq %r11,3*8(%rdi)
23089 9: movq 4*8(%rsi),%r8
23090 10: movq 5*8(%rsi),%r9
23091-11: movq 6*8(%rsi),%r10
23092+11: movq 6*8(%rsi),%rax
23093 12: movq 7*8(%rsi),%r11
23094 13: movq %r8,4*8(%rdi)
23095 14: movq %r9,5*8(%rdi)
23096-15: movq %r10,6*8(%rdi)
23097+15: movq %rax,6*8(%rdi)
23098 16: movq %r11,7*8(%rdi)
23099 leaq 64(%rsi),%rsi
23100 leaq 64(%rdi),%rdi
23101@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
23102 jnz 21b
23103 23: xor %eax,%eax
23104 ASM_CLAC
23105+ pax_force_retaddr
23106 ret
23107
23108 .section .fixup,"ax"
23109@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
23110 movsb
23111 4: xorl %eax,%eax
23112 ASM_CLAC
23113+ pax_force_retaddr
23114 ret
23115
23116 .section .fixup,"ax"
23117@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
23118 movsb
23119 2: xorl %eax,%eax
23120 ASM_CLAC
23121+ pax_force_retaddr
23122 ret
23123
23124 .section .fixup,"ax"
23125diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
23126index 6a4f43c..f5f9e26 100644
23127--- a/arch/x86/lib/copy_user_nocache_64.S
23128+++ b/arch/x86/lib/copy_user_nocache_64.S
23129@@ -8,6 +8,7 @@
23130
23131 #include <linux/linkage.h>
23132 #include <asm/dwarf2.h>
23133+#include <asm/alternative-asm.h>
23134
23135 #define FIX_ALIGNMENT 1
23136
23137@@ -16,6 +17,7 @@
23138 #include <asm/thread_info.h>
23139 #include <asm/asm.h>
23140 #include <asm/smap.h>
23141+#include <asm/pgtable.h>
23142
23143 .macro ALIGN_DESTINATION
23144 #ifdef FIX_ALIGNMENT
23145@@ -49,6 +51,15 @@
23146 */
23147 ENTRY(__copy_user_nocache)
23148 CFI_STARTPROC
23149+
23150+#ifdef CONFIG_PAX_MEMORY_UDEREF
23151+ mov $PAX_USER_SHADOW_BASE,%rcx
23152+ cmp %rcx,%rsi
23153+ jae 1f
23154+ add %rcx,%rsi
23155+1:
23156+#endif
23157+
23158 ASM_STAC
23159 cmpl $8,%edx
23160 jb 20f /* less then 8 bytes, go to byte copy loop */
23161@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
23162 jz 17f
23163 1: movq (%rsi),%r8
23164 2: movq 1*8(%rsi),%r9
23165-3: movq 2*8(%rsi),%r10
23166+3: movq 2*8(%rsi),%rax
23167 4: movq 3*8(%rsi),%r11
23168 5: movnti %r8,(%rdi)
23169 6: movnti %r9,1*8(%rdi)
23170-7: movnti %r10,2*8(%rdi)
23171+7: movnti %rax,2*8(%rdi)
23172 8: movnti %r11,3*8(%rdi)
23173 9: movq 4*8(%rsi),%r8
23174 10: movq 5*8(%rsi),%r9
23175-11: movq 6*8(%rsi),%r10
23176+11: movq 6*8(%rsi),%rax
23177 12: movq 7*8(%rsi),%r11
23178 13: movnti %r8,4*8(%rdi)
23179 14: movnti %r9,5*8(%rdi)
23180-15: movnti %r10,6*8(%rdi)
23181+15: movnti %rax,6*8(%rdi)
23182 16: movnti %r11,7*8(%rdi)
23183 leaq 64(%rsi),%rsi
23184 leaq 64(%rdi),%rdi
23185@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
23186 23: xorl %eax,%eax
23187 ASM_CLAC
23188 sfence
23189+ pax_force_retaddr
23190 ret
23191
23192 .section .fixup,"ax"
23193diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
23194index 2419d5f..953ee51 100644
23195--- a/arch/x86/lib/csum-copy_64.S
23196+++ b/arch/x86/lib/csum-copy_64.S
23197@@ -9,6 +9,7 @@
23198 #include <asm/dwarf2.h>
23199 #include <asm/errno.h>
23200 #include <asm/asm.h>
23201+#include <asm/alternative-asm.h>
23202
23203 /*
23204 * Checksum copy with exception handling.
23205@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
23206 CFI_RESTORE rbp
23207 addq $7*8, %rsp
23208 CFI_ADJUST_CFA_OFFSET -7*8
23209+ pax_force_retaddr 0, 1
23210 ret
23211 CFI_RESTORE_STATE
23212
23213diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
23214index 25b7ae8..169fafc 100644
23215--- a/arch/x86/lib/csum-wrappers_64.c
23216+++ b/arch/x86/lib/csum-wrappers_64.c
23217@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
23218 len -= 2;
23219 }
23220 }
23221- isum = csum_partial_copy_generic((__force const void *)src,
23222+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
23223 dst, len, isum, errp, NULL);
23224 if (unlikely(*errp))
23225 goto out_err;
23226@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
23227 }
23228
23229 *errp = 0;
23230- return csum_partial_copy_generic(src, (void __force *)dst,
23231+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
23232 len, isum, NULL, errp);
23233 }
23234 EXPORT_SYMBOL(csum_partial_copy_to_user);
23235diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
23236index 156b9c8..b144132 100644
23237--- a/arch/x86/lib/getuser.S
23238+++ b/arch/x86/lib/getuser.S
23239@@ -34,17 +34,40 @@
23240 #include <asm/thread_info.h>
23241 #include <asm/asm.h>
23242 #include <asm/smap.h>
23243+#include <asm/segment.h>
23244+#include <asm/pgtable.h>
23245+#include <asm/alternative-asm.h>
23246+
23247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
23248+#define __copyuser_seg gs;
23249+#else
23250+#define __copyuser_seg
23251+#endif
23252
23253 .text
23254 ENTRY(__get_user_1)
23255 CFI_STARTPROC
23256+
23257+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23258 GET_THREAD_INFO(%_ASM_DX)
23259 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23260 jae bad_get_user
23261 ASM_STAC
23262-1: movzb (%_ASM_AX),%edx
23263+
23264+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23265+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23266+ cmp %_ASM_DX,%_ASM_AX
23267+ jae 1234f
23268+ add %_ASM_DX,%_ASM_AX
23269+1234:
23270+#endif
23271+
23272+#endif
23273+
23274+1: __copyuser_seg movzb (%_ASM_AX),%edx
23275 xor %eax,%eax
23276 ASM_CLAC
23277+ pax_force_retaddr
23278 ret
23279 CFI_ENDPROC
23280 ENDPROC(__get_user_1)
23281@@ -52,14 +75,28 @@ ENDPROC(__get_user_1)
23282 ENTRY(__get_user_2)
23283 CFI_STARTPROC
23284 add $1,%_ASM_AX
23285+
23286+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23287 jc bad_get_user
23288 GET_THREAD_INFO(%_ASM_DX)
23289 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23290 jae bad_get_user
23291 ASM_STAC
23292-2: movzwl -1(%_ASM_AX),%edx
23293+
23294+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23295+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23296+ cmp %_ASM_DX,%_ASM_AX
23297+ jae 1234f
23298+ add %_ASM_DX,%_ASM_AX
23299+1234:
23300+#endif
23301+
23302+#endif
23303+
23304+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
23305 xor %eax,%eax
23306 ASM_CLAC
23307+ pax_force_retaddr
23308 ret
23309 CFI_ENDPROC
23310 ENDPROC(__get_user_2)
23311@@ -67,14 +104,28 @@ ENDPROC(__get_user_2)
23312 ENTRY(__get_user_4)
23313 CFI_STARTPROC
23314 add $3,%_ASM_AX
23315+
23316+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
23317 jc bad_get_user
23318 GET_THREAD_INFO(%_ASM_DX)
23319 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23320 jae bad_get_user
23321 ASM_STAC
23322-3: mov -3(%_ASM_AX),%edx
23323+
23324+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23325+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23326+ cmp %_ASM_DX,%_ASM_AX
23327+ jae 1234f
23328+ add %_ASM_DX,%_ASM_AX
23329+1234:
23330+#endif
23331+
23332+#endif
23333+
23334+3: __copyuser_seg mov -3(%_ASM_AX),%edx
23335 xor %eax,%eax
23336 ASM_CLAC
23337+ pax_force_retaddr
23338 ret
23339 CFI_ENDPROC
23340 ENDPROC(__get_user_4)
23341@@ -87,10 +138,20 @@ ENTRY(__get_user_8)
23342 GET_THREAD_INFO(%_ASM_DX)
23343 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
23344 jae bad_get_user
23345+
23346+#ifdef CONFIG_PAX_MEMORY_UDEREF
23347+ mov $PAX_USER_SHADOW_BASE,%_ASM_DX
23348+ cmp %_ASM_DX,%_ASM_AX
23349+ jae 1234f
23350+ add %_ASM_DX,%_ASM_AX
23351+1234:
23352+#endif
23353+
23354 ASM_STAC
23355 4: movq -7(%_ASM_AX),%_ASM_DX
23356 xor %eax,%eax
23357 ASM_CLAC
23358+ pax_force_retaddr
23359 ret
23360 CFI_ENDPROC
23361 ENDPROC(__get_user_8)
23362@@ -101,6 +162,7 @@ bad_get_user:
23363 xor %edx,%edx
23364 mov $(-EFAULT),%_ASM_AX
23365 ASM_CLAC
23366+ pax_force_retaddr
23367 ret
23368 CFI_ENDPROC
23369 END(bad_get_user)
23370diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
23371index 54fcffe..7be149e 100644
23372--- a/arch/x86/lib/insn.c
23373+++ b/arch/x86/lib/insn.c
23374@@ -20,8 +20,10 @@
23375
23376 #ifdef __KERNEL__
23377 #include <linux/string.h>
23378+#include <asm/pgtable_types.h>
23379 #else
23380 #include <string.h>
23381+#define ktla_ktva(addr) addr
23382 #endif
23383 #include <asm/inat.h>
23384 #include <asm/insn.h>
23385@@ -53,8 +55,8 @@
23386 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
23387 {
23388 memset(insn, 0, sizeof(*insn));
23389- insn->kaddr = kaddr;
23390- insn->next_byte = kaddr;
23391+ insn->kaddr = ktla_ktva(kaddr);
23392+ insn->next_byte = ktla_ktva(kaddr);
23393 insn->x86_64 = x86_64 ? 1 : 0;
23394 insn->opnd_bytes = 4;
23395 if (x86_64)
23396diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
23397index 05a95e7..326f2fa 100644
23398--- a/arch/x86/lib/iomap_copy_64.S
23399+++ b/arch/x86/lib/iomap_copy_64.S
23400@@ -17,6 +17,7 @@
23401
23402 #include <linux/linkage.h>
23403 #include <asm/dwarf2.h>
23404+#include <asm/alternative-asm.h>
23405
23406 /*
23407 * override generic version in lib/iomap_copy.c
23408@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
23409 CFI_STARTPROC
23410 movl %edx,%ecx
23411 rep movsd
23412+ pax_force_retaddr
23413 ret
23414 CFI_ENDPROC
23415 ENDPROC(__iowrite32_copy)
23416diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
23417index 1c273be..da9cc0e 100644
23418--- a/arch/x86/lib/memcpy_64.S
23419+++ b/arch/x86/lib/memcpy_64.S
23420@@ -33,6 +33,7 @@
23421 rep movsq
23422 movl %edx, %ecx
23423 rep movsb
23424+ pax_force_retaddr
23425 ret
23426 .Lmemcpy_e:
23427 .previous
23428@@ -49,6 +50,7 @@
23429 movq %rdi, %rax
23430 movq %rdx, %rcx
23431 rep movsb
23432+ pax_force_retaddr
23433 ret
23434 .Lmemcpy_e_e:
23435 .previous
23436@@ -76,13 +78,13 @@ ENTRY(memcpy)
23437 */
23438 movq 0*8(%rsi), %r8
23439 movq 1*8(%rsi), %r9
23440- movq 2*8(%rsi), %r10
23441+ movq 2*8(%rsi), %rcx
23442 movq 3*8(%rsi), %r11
23443 leaq 4*8(%rsi), %rsi
23444
23445 movq %r8, 0*8(%rdi)
23446 movq %r9, 1*8(%rdi)
23447- movq %r10, 2*8(%rdi)
23448+ movq %rcx, 2*8(%rdi)
23449 movq %r11, 3*8(%rdi)
23450 leaq 4*8(%rdi), %rdi
23451 jae .Lcopy_forward_loop
23452@@ -105,12 +107,12 @@ ENTRY(memcpy)
23453 subq $0x20, %rdx
23454 movq -1*8(%rsi), %r8
23455 movq -2*8(%rsi), %r9
23456- movq -3*8(%rsi), %r10
23457+ movq -3*8(%rsi), %rcx
23458 movq -4*8(%rsi), %r11
23459 leaq -4*8(%rsi), %rsi
23460 movq %r8, -1*8(%rdi)
23461 movq %r9, -2*8(%rdi)
23462- movq %r10, -3*8(%rdi)
23463+ movq %rcx, -3*8(%rdi)
23464 movq %r11, -4*8(%rdi)
23465 leaq -4*8(%rdi), %rdi
23466 jae .Lcopy_backward_loop
23467@@ -130,12 +132,13 @@ ENTRY(memcpy)
23468 */
23469 movq 0*8(%rsi), %r8
23470 movq 1*8(%rsi), %r9
23471- movq -2*8(%rsi, %rdx), %r10
23472+ movq -2*8(%rsi, %rdx), %rcx
23473 movq -1*8(%rsi, %rdx), %r11
23474 movq %r8, 0*8(%rdi)
23475 movq %r9, 1*8(%rdi)
23476- movq %r10, -2*8(%rdi, %rdx)
23477+ movq %rcx, -2*8(%rdi, %rdx)
23478 movq %r11, -1*8(%rdi, %rdx)
23479+ pax_force_retaddr
23480 retq
23481 .p2align 4
23482 .Lless_16bytes:
23483@@ -148,6 +151,7 @@ ENTRY(memcpy)
23484 movq -1*8(%rsi, %rdx), %r9
23485 movq %r8, 0*8(%rdi)
23486 movq %r9, -1*8(%rdi, %rdx)
23487+ pax_force_retaddr
23488 retq
23489 .p2align 4
23490 .Lless_8bytes:
23491@@ -161,6 +165,7 @@ ENTRY(memcpy)
23492 movl -4(%rsi, %rdx), %r8d
23493 movl %ecx, (%rdi)
23494 movl %r8d, -4(%rdi, %rdx)
23495+ pax_force_retaddr
23496 retq
23497 .p2align 4
23498 .Lless_3bytes:
23499@@ -179,6 +184,7 @@ ENTRY(memcpy)
23500 movb %cl, (%rdi)
23501
23502 .Lend:
23503+ pax_force_retaddr
23504 retq
23505 CFI_ENDPROC
23506 ENDPROC(memcpy)
23507diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
23508index ee16461..c39c199 100644
23509--- a/arch/x86/lib/memmove_64.S
23510+++ b/arch/x86/lib/memmove_64.S
23511@@ -61,13 +61,13 @@ ENTRY(memmove)
23512 5:
23513 sub $0x20, %rdx
23514 movq 0*8(%rsi), %r11
23515- movq 1*8(%rsi), %r10
23516+ movq 1*8(%rsi), %rcx
23517 movq 2*8(%rsi), %r9
23518 movq 3*8(%rsi), %r8
23519 leaq 4*8(%rsi), %rsi
23520
23521 movq %r11, 0*8(%rdi)
23522- movq %r10, 1*8(%rdi)
23523+ movq %rcx, 1*8(%rdi)
23524 movq %r9, 2*8(%rdi)
23525 movq %r8, 3*8(%rdi)
23526 leaq 4*8(%rdi), %rdi
23527@@ -81,10 +81,10 @@ ENTRY(memmove)
23528 4:
23529 movq %rdx, %rcx
23530 movq -8(%rsi, %rdx), %r11
23531- lea -8(%rdi, %rdx), %r10
23532+ lea -8(%rdi, %rdx), %r9
23533 shrq $3, %rcx
23534 rep movsq
23535- movq %r11, (%r10)
23536+ movq %r11, (%r9)
23537 jmp 13f
23538 .Lmemmove_end_forward:
23539
23540@@ -95,14 +95,14 @@ ENTRY(memmove)
23541 7:
23542 movq %rdx, %rcx
23543 movq (%rsi), %r11
23544- movq %rdi, %r10
23545+ movq %rdi, %r9
23546 leaq -8(%rsi, %rdx), %rsi
23547 leaq -8(%rdi, %rdx), %rdi
23548 shrq $3, %rcx
23549 std
23550 rep movsq
23551 cld
23552- movq %r11, (%r10)
23553+ movq %r11, (%r9)
23554 jmp 13f
23555
23556 /*
23557@@ -127,13 +127,13 @@ ENTRY(memmove)
23558 8:
23559 subq $0x20, %rdx
23560 movq -1*8(%rsi), %r11
23561- movq -2*8(%rsi), %r10
23562+ movq -2*8(%rsi), %rcx
23563 movq -3*8(%rsi), %r9
23564 movq -4*8(%rsi), %r8
23565 leaq -4*8(%rsi), %rsi
23566
23567 movq %r11, -1*8(%rdi)
23568- movq %r10, -2*8(%rdi)
23569+ movq %rcx, -2*8(%rdi)
23570 movq %r9, -3*8(%rdi)
23571 movq %r8, -4*8(%rdi)
23572 leaq -4*8(%rdi), %rdi
23573@@ -151,11 +151,11 @@ ENTRY(memmove)
23574 * Move data from 16 bytes to 31 bytes.
23575 */
23576 movq 0*8(%rsi), %r11
23577- movq 1*8(%rsi), %r10
23578+ movq 1*8(%rsi), %rcx
23579 movq -2*8(%rsi, %rdx), %r9
23580 movq -1*8(%rsi, %rdx), %r8
23581 movq %r11, 0*8(%rdi)
23582- movq %r10, 1*8(%rdi)
23583+ movq %rcx, 1*8(%rdi)
23584 movq %r9, -2*8(%rdi, %rdx)
23585 movq %r8, -1*8(%rdi, %rdx)
23586 jmp 13f
23587@@ -167,9 +167,9 @@ ENTRY(memmove)
23588 * Move data from 8 bytes to 15 bytes.
23589 */
23590 movq 0*8(%rsi), %r11
23591- movq -1*8(%rsi, %rdx), %r10
23592+ movq -1*8(%rsi, %rdx), %r9
23593 movq %r11, 0*8(%rdi)
23594- movq %r10, -1*8(%rdi, %rdx)
23595+ movq %r9, -1*8(%rdi, %rdx)
23596 jmp 13f
23597 10:
23598 cmpq $4, %rdx
23599@@ -178,9 +178,9 @@ ENTRY(memmove)
23600 * Move data from 4 bytes to 7 bytes.
23601 */
23602 movl (%rsi), %r11d
23603- movl -4(%rsi, %rdx), %r10d
23604+ movl -4(%rsi, %rdx), %r9d
23605 movl %r11d, (%rdi)
23606- movl %r10d, -4(%rdi, %rdx)
23607+ movl %r9d, -4(%rdi, %rdx)
23608 jmp 13f
23609 11:
23610 cmp $2, %rdx
23611@@ -189,9 +189,9 @@ ENTRY(memmove)
23612 * Move data from 2 bytes to 3 bytes.
23613 */
23614 movw (%rsi), %r11w
23615- movw -2(%rsi, %rdx), %r10w
23616+ movw -2(%rsi, %rdx), %r9w
23617 movw %r11w, (%rdi)
23618- movw %r10w, -2(%rdi, %rdx)
23619+ movw %r9w, -2(%rdi, %rdx)
23620 jmp 13f
23621 12:
23622 cmp $1, %rdx
23623@@ -202,6 +202,7 @@ ENTRY(memmove)
23624 movb (%rsi), %r11b
23625 movb %r11b, (%rdi)
23626 13:
23627+ pax_force_retaddr
23628 retq
23629 CFI_ENDPROC
23630
23631@@ -210,6 +211,7 @@ ENTRY(memmove)
23632 /* Forward moving data. */
23633 movq %rdx, %rcx
23634 rep movsb
23635+ pax_force_retaddr
23636 retq
23637 .Lmemmove_end_forward_efs:
23638 .previous
23639diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
23640index 2dcb380..963660a 100644
23641--- a/arch/x86/lib/memset_64.S
23642+++ b/arch/x86/lib/memset_64.S
23643@@ -30,6 +30,7 @@
23644 movl %edx,%ecx
23645 rep stosb
23646 movq %r9,%rax
23647+ pax_force_retaddr
23648 ret
23649 .Lmemset_e:
23650 .previous
23651@@ -52,6 +53,7 @@
23652 movq %rdx,%rcx
23653 rep stosb
23654 movq %r9,%rax
23655+ pax_force_retaddr
23656 ret
23657 .Lmemset_e_e:
23658 .previous
23659@@ -59,7 +61,7 @@
23660 ENTRY(memset)
23661 ENTRY(__memset)
23662 CFI_STARTPROC
23663- movq %rdi,%r10
23664+ movq %rdi,%r11
23665
23666 /* expand byte value */
23667 movzbl %sil,%ecx
23668@@ -117,7 +119,8 @@ ENTRY(__memset)
23669 jnz .Lloop_1
23670
23671 .Lende:
23672- movq %r10,%rax
23673+ movq %r11,%rax
23674+ pax_force_retaddr
23675 ret
23676
23677 CFI_RESTORE_STATE
23678diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
23679index c9f2d9b..e7fd2c0 100644
23680--- a/arch/x86/lib/mmx_32.c
23681+++ b/arch/x86/lib/mmx_32.c
23682@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23683 {
23684 void *p;
23685 int i;
23686+ unsigned long cr0;
23687
23688 if (unlikely(in_interrupt()))
23689 return __memcpy(to, from, len);
23690@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
23691 kernel_fpu_begin();
23692
23693 __asm__ __volatile__ (
23694- "1: prefetch (%0)\n" /* This set is 28 bytes */
23695- " prefetch 64(%0)\n"
23696- " prefetch 128(%0)\n"
23697- " prefetch 192(%0)\n"
23698- " prefetch 256(%0)\n"
23699+ "1: prefetch (%1)\n" /* This set is 28 bytes */
23700+ " prefetch 64(%1)\n"
23701+ " prefetch 128(%1)\n"
23702+ " prefetch 192(%1)\n"
23703+ " prefetch 256(%1)\n"
23704 "2: \n"
23705 ".section .fixup, \"ax\"\n"
23706- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23707+ "3: \n"
23708+
23709+#ifdef CONFIG_PAX_KERNEXEC
23710+ " movl %%cr0, %0\n"
23711+ " movl %0, %%eax\n"
23712+ " andl $0xFFFEFFFF, %%eax\n"
23713+ " movl %%eax, %%cr0\n"
23714+#endif
23715+
23716+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23717+
23718+#ifdef CONFIG_PAX_KERNEXEC
23719+ " movl %0, %%cr0\n"
23720+#endif
23721+
23722 " jmp 2b\n"
23723 ".previous\n"
23724 _ASM_EXTABLE(1b, 3b)
23725- : : "r" (from));
23726+ : "=&r" (cr0) : "r" (from) : "ax");
23727
23728 for ( ; i > 5; i--) {
23729 __asm__ __volatile__ (
23730- "1: prefetch 320(%0)\n"
23731- "2: movq (%0), %%mm0\n"
23732- " movq 8(%0), %%mm1\n"
23733- " movq 16(%0), %%mm2\n"
23734- " movq 24(%0), %%mm3\n"
23735- " movq %%mm0, (%1)\n"
23736- " movq %%mm1, 8(%1)\n"
23737- " movq %%mm2, 16(%1)\n"
23738- " movq %%mm3, 24(%1)\n"
23739- " movq 32(%0), %%mm0\n"
23740- " movq 40(%0), %%mm1\n"
23741- " movq 48(%0), %%mm2\n"
23742- " movq 56(%0), %%mm3\n"
23743- " movq %%mm0, 32(%1)\n"
23744- " movq %%mm1, 40(%1)\n"
23745- " movq %%mm2, 48(%1)\n"
23746- " movq %%mm3, 56(%1)\n"
23747+ "1: prefetch 320(%1)\n"
23748+ "2: movq (%1), %%mm0\n"
23749+ " movq 8(%1), %%mm1\n"
23750+ " movq 16(%1), %%mm2\n"
23751+ " movq 24(%1), %%mm3\n"
23752+ " movq %%mm0, (%2)\n"
23753+ " movq %%mm1, 8(%2)\n"
23754+ " movq %%mm2, 16(%2)\n"
23755+ " movq %%mm3, 24(%2)\n"
23756+ " movq 32(%1), %%mm0\n"
23757+ " movq 40(%1), %%mm1\n"
23758+ " movq 48(%1), %%mm2\n"
23759+ " movq 56(%1), %%mm3\n"
23760+ " movq %%mm0, 32(%2)\n"
23761+ " movq %%mm1, 40(%2)\n"
23762+ " movq %%mm2, 48(%2)\n"
23763+ " movq %%mm3, 56(%2)\n"
23764 ".section .fixup, \"ax\"\n"
23765- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23766+ "3:\n"
23767+
23768+#ifdef CONFIG_PAX_KERNEXEC
23769+ " movl %%cr0, %0\n"
23770+ " movl %0, %%eax\n"
23771+ " andl $0xFFFEFFFF, %%eax\n"
23772+ " movl %%eax, %%cr0\n"
23773+#endif
23774+
23775+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23776+
23777+#ifdef CONFIG_PAX_KERNEXEC
23778+ " movl %0, %%cr0\n"
23779+#endif
23780+
23781 " jmp 2b\n"
23782 ".previous\n"
23783 _ASM_EXTABLE(1b, 3b)
23784- : : "r" (from), "r" (to) : "memory");
23785+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23786
23787 from += 64;
23788 to += 64;
23789@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
23790 static void fast_copy_page(void *to, void *from)
23791 {
23792 int i;
23793+ unsigned long cr0;
23794
23795 kernel_fpu_begin();
23796
23797@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
23798 * but that is for later. -AV
23799 */
23800 __asm__ __volatile__(
23801- "1: prefetch (%0)\n"
23802- " prefetch 64(%0)\n"
23803- " prefetch 128(%0)\n"
23804- " prefetch 192(%0)\n"
23805- " prefetch 256(%0)\n"
23806+ "1: prefetch (%1)\n"
23807+ " prefetch 64(%1)\n"
23808+ " prefetch 128(%1)\n"
23809+ " prefetch 192(%1)\n"
23810+ " prefetch 256(%1)\n"
23811 "2: \n"
23812 ".section .fixup, \"ax\"\n"
23813- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23814+ "3: \n"
23815+
23816+#ifdef CONFIG_PAX_KERNEXEC
23817+ " movl %%cr0, %0\n"
23818+ " movl %0, %%eax\n"
23819+ " andl $0xFFFEFFFF, %%eax\n"
23820+ " movl %%eax, %%cr0\n"
23821+#endif
23822+
23823+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23824+
23825+#ifdef CONFIG_PAX_KERNEXEC
23826+ " movl %0, %%cr0\n"
23827+#endif
23828+
23829 " jmp 2b\n"
23830 ".previous\n"
23831- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23832+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23833
23834 for (i = 0; i < (4096-320)/64; i++) {
23835 __asm__ __volatile__ (
23836- "1: prefetch 320(%0)\n"
23837- "2: movq (%0), %%mm0\n"
23838- " movntq %%mm0, (%1)\n"
23839- " movq 8(%0), %%mm1\n"
23840- " movntq %%mm1, 8(%1)\n"
23841- " movq 16(%0), %%mm2\n"
23842- " movntq %%mm2, 16(%1)\n"
23843- " movq 24(%0), %%mm3\n"
23844- " movntq %%mm3, 24(%1)\n"
23845- " movq 32(%0), %%mm4\n"
23846- " movntq %%mm4, 32(%1)\n"
23847- " movq 40(%0), %%mm5\n"
23848- " movntq %%mm5, 40(%1)\n"
23849- " movq 48(%0), %%mm6\n"
23850- " movntq %%mm6, 48(%1)\n"
23851- " movq 56(%0), %%mm7\n"
23852- " movntq %%mm7, 56(%1)\n"
23853+ "1: prefetch 320(%1)\n"
23854+ "2: movq (%1), %%mm0\n"
23855+ " movntq %%mm0, (%2)\n"
23856+ " movq 8(%1), %%mm1\n"
23857+ " movntq %%mm1, 8(%2)\n"
23858+ " movq 16(%1), %%mm2\n"
23859+ " movntq %%mm2, 16(%2)\n"
23860+ " movq 24(%1), %%mm3\n"
23861+ " movntq %%mm3, 24(%2)\n"
23862+ " movq 32(%1), %%mm4\n"
23863+ " movntq %%mm4, 32(%2)\n"
23864+ " movq 40(%1), %%mm5\n"
23865+ " movntq %%mm5, 40(%2)\n"
23866+ " movq 48(%1), %%mm6\n"
23867+ " movntq %%mm6, 48(%2)\n"
23868+ " movq 56(%1), %%mm7\n"
23869+ " movntq %%mm7, 56(%2)\n"
23870 ".section .fixup, \"ax\"\n"
23871- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23872+ "3:\n"
23873+
23874+#ifdef CONFIG_PAX_KERNEXEC
23875+ " movl %%cr0, %0\n"
23876+ " movl %0, %%eax\n"
23877+ " andl $0xFFFEFFFF, %%eax\n"
23878+ " movl %%eax, %%cr0\n"
23879+#endif
23880+
23881+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23882+
23883+#ifdef CONFIG_PAX_KERNEXEC
23884+ " movl %0, %%cr0\n"
23885+#endif
23886+
23887 " jmp 2b\n"
23888 ".previous\n"
23889- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
23890+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23891
23892 from += 64;
23893 to += 64;
23894@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
23895 static void fast_copy_page(void *to, void *from)
23896 {
23897 int i;
23898+ unsigned long cr0;
23899
23900 kernel_fpu_begin();
23901
23902 __asm__ __volatile__ (
23903- "1: prefetch (%0)\n"
23904- " prefetch 64(%0)\n"
23905- " prefetch 128(%0)\n"
23906- " prefetch 192(%0)\n"
23907- " prefetch 256(%0)\n"
23908+ "1: prefetch (%1)\n"
23909+ " prefetch 64(%1)\n"
23910+ " prefetch 128(%1)\n"
23911+ " prefetch 192(%1)\n"
23912+ " prefetch 256(%1)\n"
23913 "2: \n"
23914 ".section .fixup, \"ax\"\n"
23915- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23916+ "3: \n"
23917+
23918+#ifdef CONFIG_PAX_KERNEXEC
23919+ " movl %%cr0, %0\n"
23920+ " movl %0, %%eax\n"
23921+ " andl $0xFFFEFFFF, %%eax\n"
23922+ " movl %%eax, %%cr0\n"
23923+#endif
23924+
23925+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
23926+
23927+#ifdef CONFIG_PAX_KERNEXEC
23928+ " movl %0, %%cr0\n"
23929+#endif
23930+
23931 " jmp 2b\n"
23932 ".previous\n"
23933- _ASM_EXTABLE(1b, 3b) : : "r" (from));
23934+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
23935
23936 for (i = 0; i < 4096/64; i++) {
23937 __asm__ __volatile__ (
23938- "1: prefetch 320(%0)\n"
23939- "2: movq (%0), %%mm0\n"
23940- " movq 8(%0), %%mm1\n"
23941- " movq 16(%0), %%mm2\n"
23942- " movq 24(%0), %%mm3\n"
23943- " movq %%mm0, (%1)\n"
23944- " movq %%mm1, 8(%1)\n"
23945- " movq %%mm2, 16(%1)\n"
23946- " movq %%mm3, 24(%1)\n"
23947- " movq 32(%0), %%mm0\n"
23948- " movq 40(%0), %%mm1\n"
23949- " movq 48(%0), %%mm2\n"
23950- " movq 56(%0), %%mm3\n"
23951- " movq %%mm0, 32(%1)\n"
23952- " movq %%mm1, 40(%1)\n"
23953- " movq %%mm2, 48(%1)\n"
23954- " movq %%mm3, 56(%1)\n"
23955+ "1: prefetch 320(%1)\n"
23956+ "2: movq (%1), %%mm0\n"
23957+ " movq 8(%1), %%mm1\n"
23958+ " movq 16(%1), %%mm2\n"
23959+ " movq 24(%1), %%mm3\n"
23960+ " movq %%mm0, (%2)\n"
23961+ " movq %%mm1, 8(%2)\n"
23962+ " movq %%mm2, 16(%2)\n"
23963+ " movq %%mm3, 24(%2)\n"
23964+ " movq 32(%1), %%mm0\n"
23965+ " movq 40(%1), %%mm1\n"
23966+ " movq 48(%1), %%mm2\n"
23967+ " movq 56(%1), %%mm3\n"
23968+ " movq %%mm0, 32(%2)\n"
23969+ " movq %%mm1, 40(%2)\n"
23970+ " movq %%mm2, 48(%2)\n"
23971+ " movq %%mm3, 56(%2)\n"
23972 ".section .fixup, \"ax\"\n"
23973- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23974+ "3:\n"
23975+
23976+#ifdef CONFIG_PAX_KERNEXEC
23977+ " movl %%cr0, %0\n"
23978+ " movl %0, %%eax\n"
23979+ " andl $0xFFFEFFFF, %%eax\n"
23980+ " movl %%eax, %%cr0\n"
23981+#endif
23982+
23983+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
23984+
23985+#ifdef CONFIG_PAX_KERNEXEC
23986+ " movl %0, %%cr0\n"
23987+#endif
23988+
23989 " jmp 2b\n"
23990 ".previous\n"
23991 _ASM_EXTABLE(1b, 3b)
23992- : : "r" (from), "r" (to) : "memory");
23993+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
23994
23995 from += 64;
23996 to += 64;
23997diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
23998index f6d13ee..aca5f0b 100644
23999--- a/arch/x86/lib/msr-reg.S
24000+++ b/arch/x86/lib/msr-reg.S
24001@@ -3,6 +3,7 @@
24002 #include <asm/dwarf2.h>
24003 #include <asm/asm.h>
24004 #include <asm/msr.h>
24005+#include <asm/alternative-asm.h>
24006
24007 #ifdef CONFIG_X86_64
24008 /*
24009@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
24010 CFI_STARTPROC
24011 pushq_cfi %rbx
24012 pushq_cfi %rbp
24013- movq %rdi, %r10 /* Save pointer */
24014+ movq %rdi, %r9 /* Save pointer */
24015 xorl %r11d, %r11d /* Return value */
24016 movl (%rdi), %eax
24017 movl 4(%rdi), %ecx
24018@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
24019 movl 28(%rdi), %edi
24020 CFI_REMEMBER_STATE
24021 1: \op
24022-2: movl %eax, (%r10)
24023+2: movl %eax, (%r9)
24024 movl %r11d, %eax /* Return value */
24025- movl %ecx, 4(%r10)
24026- movl %edx, 8(%r10)
24027- movl %ebx, 12(%r10)
24028- movl %ebp, 20(%r10)
24029- movl %esi, 24(%r10)
24030- movl %edi, 28(%r10)
24031+ movl %ecx, 4(%r9)
24032+ movl %edx, 8(%r9)
24033+ movl %ebx, 12(%r9)
24034+ movl %ebp, 20(%r9)
24035+ movl %esi, 24(%r9)
24036+ movl %edi, 28(%r9)
24037 popq_cfi %rbp
24038 popq_cfi %rbx
24039+ pax_force_retaddr
24040 ret
24041 3:
24042 CFI_RESTORE_STATE
24043diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
24044index fc6ba17..04471c5 100644
24045--- a/arch/x86/lib/putuser.S
24046+++ b/arch/x86/lib/putuser.S
24047@@ -16,7 +16,9 @@
24048 #include <asm/errno.h>
24049 #include <asm/asm.h>
24050 #include <asm/smap.h>
24051-
24052+#include <asm/segment.h>
24053+#include <asm/pgtable.h>
24054+#include <asm/alternative-asm.h>
24055
24056 /*
24057 * __put_user_X
24058@@ -30,57 +32,125 @@
24059 * as they get called from within inline assembly.
24060 */
24061
24062-#define ENTER CFI_STARTPROC ; \
24063- GET_THREAD_INFO(%_ASM_BX)
24064-#define EXIT ASM_CLAC ; \
24065- ret ; \
24066+#define ENTER CFI_STARTPROC
24067+#define EXIT ASM_CLAC ; \
24068+ pax_force_retaddr ; \
24069+ ret ; \
24070 CFI_ENDPROC
24071
24072+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24073+#define _DEST %_ASM_CX,%_ASM_BX
24074+#else
24075+#define _DEST %_ASM_CX
24076+#endif
24077+
24078+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24079+#define __copyuser_seg gs;
24080+#else
24081+#define __copyuser_seg
24082+#endif
24083+
24084 .text
24085 ENTRY(__put_user_1)
24086 ENTER
24087+
24088+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24089+ GET_THREAD_INFO(%_ASM_BX)
24090 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
24091 jae bad_put_user
24092 ASM_STAC
24093-1: movb %al,(%_ASM_CX)
24094+
24095+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24096+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24097+ cmp %_ASM_BX,%_ASM_CX
24098+ jb 1234f
24099+ xor %ebx,%ebx
24100+1234:
24101+#endif
24102+
24103+#endif
24104+
24105+1: __copyuser_seg movb %al,(_DEST)
24106 xor %eax,%eax
24107 EXIT
24108 ENDPROC(__put_user_1)
24109
24110 ENTRY(__put_user_2)
24111 ENTER
24112+
24113+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24114+ GET_THREAD_INFO(%_ASM_BX)
24115 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24116 sub $1,%_ASM_BX
24117 cmp %_ASM_BX,%_ASM_CX
24118 jae bad_put_user
24119 ASM_STAC
24120-2: movw %ax,(%_ASM_CX)
24121+
24122+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24123+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24124+ cmp %_ASM_BX,%_ASM_CX
24125+ jb 1234f
24126+ xor %ebx,%ebx
24127+1234:
24128+#endif
24129+
24130+#endif
24131+
24132+2: __copyuser_seg movw %ax,(_DEST)
24133 xor %eax,%eax
24134 EXIT
24135 ENDPROC(__put_user_2)
24136
24137 ENTRY(__put_user_4)
24138 ENTER
24139+
24140+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24141+ GET_THREAD_INFO(%_ASM_BX)
24142 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24143 sub $3,%_ASM_BX
24144 cmp %_ASM_BX,%_ASM_CX
24145 jae bad_put_user
24146 ASM_STAC
24147-3: movl %eax,(%_ASM_CX)
24148+
24149+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24150+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24151+ cmp %_ASM_BX,%_ASM_CX
24152+ jb 1234f
24153+ xor %ebx,%ebx
24154+1234:
24155+#endif
24156+
24157+#endif
24158+
24159+3: __copyuser_seg movl %eax,(_DEST)
24160 xor %eax,%eax
24161 EXIT
24162 ENDPROC(__put_user_4)
24163
24164 ENTRY(__put_user_8)
24165 ENTER
24166+
24167+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
24168+ GET_THREAD_INFO(%_ASM_BX)
24169 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
24170 sub $7,%_ASM_BX
24171 cmp %_ASM_BX,%_ASM_CX
24172 jae bad_put_user
24173 ASM_STAC
24174-4: mov %_ASM_AX,(%_ASM_CX)
24175+
24176+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
24177+ mov $PAX_USER_SHADOW_BASE,%_ASM_BX
24178+ cmp %_ASM_BX,%_ASM_CX
24179+ jb 1234f
24180+ xor %ebx,%ebx
24181+1234:
24182+#endif
24183+
24184+#endif
24185+
24186+4: __copyuser_seg mov %_ASM_AX,(_DEST)
24187 #ifdef CONFIG_X86_32
24188-5: movl %edx,4(%_ASM_CX)
24189+5: __copyuser_seg movl %edx,4(_DEST)
24190 #endif
24191 xor %eax,%eax
24192 EXIT
24193diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
24194index 1cad221..de671ee 100644
24195--- a/arch/x86/lib/rwlock.S
24196+++ b/arch/x86/lib/rwlock.S
24197@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
24198 FRAME
24199 0: LOCK_PREFIX
24200 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24201+
24202+#ifdef CONFIG_PAX_REFCOUNT
24203+ jno 1234f
24204+ LOCK_PREFIX
24205+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24206+ int $4
24207+1234:
24208+ _ASM_EXTABLE(1234b, 1234b)
24209+#endif
24210+
24211 1: rep; nop
24212 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
24213 jne 1b
24214 LOCK_PREFIX
24215 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
24216+
24217+#ifdef CONFIG_PAX_REFCOUNT
24218+ jno 1234f
24219+ LOCK_PREFIX
24220+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
24221+ int $4
24222+1234:
24223+ _ASM_EXTABLE(1234b, 1234b)
24224+#endif
24225+
24226 jnz 0b
24227 ENDFRAME
24228+ pax_force_retaddr
24229 ret
24230 CFI_ENDPROC
24231 END(__write_lock_failed)
24232@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
24233 FRAME
24234 0: LOCK_PREFIX
24235 READ_LOCK_SIZE(inc) (%__lock_ptr)
24236+
24237+#ifdef CONFIG_PAX_REFCOUNT
24238+ jno 1234f
24239+ LOCK_PREFIX
24240+ READ_LOCK_SIZE(dec) (%__lock_ptr)
24241+ int $4
24242+1234:
24243+ _ASM_EXTABLE(1234b, 1234b)
24244+#endif
24245+
24246 1: rep; nop
24247 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
24248 js 1b
24249 LOCK_PREFIX
24250 READ_LOCK_SIZE(dec) (%__lock_ptr)
24251+
24252+#ifdef CONFIG_PAX_REFCOUNT
24253+ jno 1234f
24254+ LOCK_PREFIX
24255+ READ_LOCK_SIZE(inc) (%__lock_ptr)
24256+ int $4
24257+1234:
24258+ _ASM_EXTABLE(1234b, 1234b)
24259+#endif
24260+
24261 js 0b
24262 ENDFRAME
24263+ pax_force_retaddr
24264 ret
24265 CFI_ENDPROC
24266 END(__read_lock_failed)
24267diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
24268index 5dff5f0..cadebf4 100644
24269--- a/arch/x86/lib/rwsem.S
24270+++ b/arch/x86/lib/rwsem.S
24271@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
24272 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24273 CFI_RESTORE __ASM_REG(dx)
24274 restore_common_regs
24275+ pax_force_retaddr
24276 ret
24277 CFI_ENDPROC
24278 ENDPROC(call_rwsem_down_read_failed)
24279@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
24280 movq %rax,%rdi
24281 call rwsem_down_write_failed
24282 restore_common_regs
24283+ pax_force_retaddr
24284 ret
24285 CFI_ENDPROC
24286 ENDPROC(call_rwsem_down_write_failed)
24287@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
24288 movq %rax,%rdi
24289 call rwsem_wake
24290 restore_common_regs
24291-1: ret
24292+1: pax_force_retaddr
24293+ ret
24294 CFI_ENDPROC
24295 ENDPROC(call_rwsem_wake)
24296
24297@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
24298 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
24299 CFI_RESTORE __ASM_REG(dx)
24300 restore_common_regs
24301+ pax_force_retaddr
24302 ret
24303 CFI_ENDPROC
24304 ENDPROC(call_rwsem_downgrade_wake)
24305diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
24306index a63efd6..ccecad8 100644
24307--- a/arch/x86/lib/thunk_64.S
24308+++ b/arch/x86/lib/thunk_64.S
24309@@ -8,6 +8,7 @@
24310 #include <linux/linkage.h>
24311 #include <asm/dwarf2.h>
24312 #include <asm/calling.h>
24313+#include <asm/alternative-asm.h>
24314
24315 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
24316 .macro THUNK name, func, put_ret_addr_in_rdi=0
24317@@ -41,5 +42,6 @@
24318 SAVE_ARGS
24319 restore:
24320 RESTORE_ARGS
24321+ pax_force_retaddr
24322 ret
24323 CFI_ENDPROC
24324diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
24325index 98f6d6b6..d27f045 100644
24326--- a/arch/x86/lib/usercopy_32.c
24327+++ b/arch/x86/lib/usercopy_32.c
24328@@ -42,11 +42,13 @@ do { \
24329 int __d0; \
24330 might_fault(); \
24331 __asm__ __volatile__( \
24332+ __COPYUSER_SET_ES \
24333 ASM_STAC "\n" \
24334 "0: rep; stosl\n" \
24335 " movl %2,%0\n" \
24336 "1: rep; stosb\n" \
24337 "2: " ASM_CLAC "\n" \
24338+ __COPYUSER_RESTORE_ES \
24339 ".section .fixup,\"ax\"\n" \
24340 "3: lea 0(%2,%0,4),%0\n" \
24341 " jmp 2b\n" \
24342@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
24343
24344 #ifdef CONFIG_X86_INTEL_USERCOPY
24345 static unsigned long
24346-__copy_user_intel(void __user *to, const void *from, unsigned long size)
24347+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
24348 {
24349 int d0, d1;
24350 __asm__ __volatile__(
24351@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24352 " .align 2,0x90\n"
24353 "3: movl 0(%4), %%eax\n"
24354 "4: movl 4(%4), %%edx\n"
24355- "5: movl %%eax, 0(%3)\n"
24356- "6: movl %%edx, 4(%3)\n"
24357+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
24358+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
24359 "7: movl 8(%4), %%eax\n"
24360 "8: movl 12(%4),%%edx\n"
24361- "9: movl %%eax, 8(%3)\n"
24362- "10: movl %%edx, 12(%3)\n"
24363+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
24364+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
24365 "11: movl 16(%4), %%eax\n"
24366 "12: movl 20(%4), %%edx\n"
24367- "13: movl %%eax, 16(%3)\n"
24368- "14: movl %%edx, 20(%3)\n"
24369+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
24370+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
24371 "15: movl 24(%4), %%eax\n"
24372 "16: movl 28(%4), %%edx\n"
24373- "17: movl %%eax, 24(%3)\n"
24374- "18: movl %%edx, 28(%3)\n"
24375+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
24376+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
24377 "19: movl 32(%4), %%eax\n"
24378 "20: movl 36(%4), %%edx\n"
24379- "21: movl %%eax, 32(%3)\n"
24380- "22: movl %%edx, 36(%3)\n"
24381+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
24382+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
24383 "23: movl 40(%4), %%eax\n"
24384 "24: movl 44(%4), %%edx\n"
24385- "25: movl %%eax, 40(%3)\n"
24386- "26: movl %%edx, 44(%3)\n"
24387+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
24388+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
24389 "27: movl 48(%4), %%eax\n"
24390 "28: movl 52(%4), %%edx\n"
24391- "29: movl %%eax, 48(%3)\n"
24392- "30: movl %%edx, 52(%3)\n"
24393+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
24394+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
24395 "31: movl 56(%4), %%eax\n"
24396 "32: movl 60(%4), %%edx\n"
24397- "33: movl %%eax, 56(%3)\n"
24398- "34: movl %%edx, 60(%3)\n"
24399+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
24400+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
24401 " addl $-64, %0\n"
24402 " addl $64, %4\n"
24403 " addl $64, %3\n"
24404@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24405 " shrl $2, %0\n"
24406 " andl $3, %%eax\n"
24407 " cld\n"
24408+ __COPYUSER_SET_ES
24409 "99: rep; movsl\n"
24410 "36: movl %%eax, %0\n"
24411 "37: rep; movsb\n"
24412 "100:\n"
24413+ __COPYUSER_RESTORE_ES
24414 ".section .fixup,\"ax\"\n"
24415 "101: lea 0(%%eax,%0,4),%0\n"
24416 " jmp 100b\n"
24417@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
24418 }
24419
24420 static unsigned long
24421+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
24422+{
24423+ int d0, d1;
24424+ __asm__ __volatile__(
24425+ " .align 2,0x90\n"
24426+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
24427+ " cmpl $67, %0\n"
24428+ " jbe 3f\n"
24429+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
24430+ " .align 2,0x90\n"
24431+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
24432+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
24433+ "5: movl %%eax, 0(%3)\n"
24434+ "6: movl %%edx, 4(%3)\n"
24435+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
24436+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
24437+ "9: movl %%eax, 8(%3)\n"
24438+ "10: movl %%edx, 12(%3)\n"
24439+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
24440+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
24441+ "13: movl %%eax, 16(%3)\n"
24442+ "14: movl %%edx, 20(%3)\n"
24443+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
24444+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
24445+ "17: movl %%eax, 24(%3)\n"
24446+ "18: movl %%edx, 28(%3)\n"
24447+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
24448+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
24449+ "21: movl %%eax, 32(%3)\n"
24450+ "22: movl %%edx, 36(%3)\n"
24451+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
24452+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
24453+ "25: movl %%eax, 40(%3)\n"
24454+ "26: movl %%edx, 44(%3)\n"
24455+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
24456+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
24457+ "29: movl %%eax, 48(%3)\n"
24458+ "30: movl %%edx, 52(%3)\n"
24459+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
24460+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
24461+ "33: movl %%eax, 56(%3)\n"
24462+ "34: movl %%edx, 60(%3)\n"
24463+ " addl $-64, %0\n"
24464+ " addl $64, %4\n"
24465+ " addl $64, %3\n"
24466+ " cmpl $63, %0\n"
24467+ " ja 1b\n"
24468+ "35: movl %0, %%eax\n"
24469+ " shrl $2, %0\n"
24470+ " andl $3, %%eax\n"
24471+ " cld\n"
24472+ "99: rep; "__copyuser_seg" movsl\n"
24473+ "36: movl %%eax, %0\n"
24474+ "37: rep; "__copyuser_seg" movsb\n"
24475+ "100:\n"
24476+ ".section .fixup,\"ax\"\n"
24477+ "101: lea 0(%%eax,%0,4),%0\n"
24478+ " jmp 100b\n"
24479+ ".previous\n"
24480+ _ASM_EXTABLE(1b,100b)
24481+ _ASM_EXTABLE(2b,100b)
24482+ _ASM_EXTABLE(3b,100b)
24483+ _ASM_EXTABLE(4b,100b)
24484+ _ASM_EXTABLE(5b,100b)
24485+ _ASM_EXTABLE(6b,100b)
24486+ _ASM_EXTABLE(7b,100b)
24487+ _ASM_EXTABLE(8b,100b)
24488+ _ASM_EXTABLE(9b,100b)
24489+ _ASM_EXTABLE(10b,100b)
24490+ _ASM_EXTABLE(11b,100b)
24491+ _ASM_EXTABLE(12b,100b)
24492+ _ASM_EXTABLE(13b,100b)
24493+ _ASM_EXTABLE(14b,100b)
24494+ _ASM_EXTABLE(15b,100b)
24495+ _ASM_EXTABLE(16b,100b)
24496+ _ASM_EXTABLE(17b,100b)
24497+ _ASM_EXTABLE(18b,100b)
24498+ _ASM_EXTABLE(19b,100b)
24499+ _ASM_EXTABLE(20b,100b)
24500+ _ASM_EXTABLE(21b,100b)
24501+ _ASM_EXTABLE(22b,100b)
24502+ _ASM_EXTABLE(23b,100b)
24503+ _ASM_EXTABLE(24b,100b)
24504+ _ASM_EXTABLE(25b,100b)
24505+ _ASM_EXTABLE(26b,100b)
24506+ _ASM_EXTABLE(27b,100b)
24507+ _ASM_EXTABLE(28b,100b)
24508+ _ASM_EXTABLE(29b,100b)
24509+ _ASM_EXTABLE(30b,100b)
24510+ _ASM_EXTABLE(31b,100b)
24511+ _ASM_EXTABLE(32b,100b)
24512+ _ASM_EXTABLE(33b,100b)
24513+ _ASM_EXTABLE(34b,100b)
24514+ _ASM_EXTABLE(35b,100b)
24515+ _ASM_EXTABLE(36b,100b)
24516+ _ASM_EXTABLE(37b,100b)
24517+ _ASM_EXTABLE(99b,101b)
24518+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
24519+ : "1"(to), "2"(from), "0"(size)
24520+ : "eax", "edx", "memory");
24521+ return size;
24522+}
24523+
24524+static unsigned long __size_overflow(3)
24525 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24526 {
24527 int d0, d1;
24528 __asm__ __volatile__(
24529 " .align 2,0x90\n"
24530- "0: movl 32(%4), %%eax\n"
24531+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24532 " cmpl $67, %0\n"
24533 " jbe 2f\n"
24534- "1: movl 64(%4), %%eax\n"
24535+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24536 " .align 2,0x90\n"
24537- "2: movl 0(%4), %%eax\n"
24538- "21: movl 4(%4), %%edx\n"
24539+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24540+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24541 " movl %%eax, 0(%3)\n"
24542 " movl %%edx, 4(%3)\n"
24543- "3: movl 8(%4), %%eax\n"
24544- "31: movl 12(%4),%%edx\n"
24545+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24546+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24547 " movl %%eax, 8(%3)\n"
24548 " movl %%edx, 12(%3)\n"
24549- "4: movl 16(%4), %%eax\n"
24550- "41: movl 20(%4), %%edx\n"
24551+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24552+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24553 " movl %%eax, 16(%3)\n"
24554 " movl %%edx, 20(%3)\n"
24555- "10: movl 24(%4), %%eax\n"
24556- "51: movl 28(%4), %%edx\n"
24557+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24558+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24559 " movl %%eax, 24(%3)\n"
24560 " movl %%edx, 28(%3)\n"
24561- "11: movl 32(%4), %%eax\n"
24562- "61: movl 36(%4), %%edx\n"
24563+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24564+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24565 " movl %%eax, 32(%3)\n"
24566 " movl %%edx, 36(%3)\n"
24567- "12: movl 40(%4), %%eax\n"
24568- "71: movl 44(%4), %%edx\n"
24569+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24570+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24571 " movl %%eax, 40(%3)\n"
24572 " movl %%edx, 44(%3)\n"
24573- "13: movl 48(%4), %%eax\n"
24574- "81: movl 52(%4), %%edx\n"
24575+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24576+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24577 " movl %%eax, 48(%3)\n"
24578 " movl %%edx, 52(%3)\n"
24579- "14: movl 56(%4), %%eax\n"
24580- "91: movl 60(%4), %%edx\n"
24581+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24582+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24583 " movl %%eax, 56(%3)\n"
24584 " movl %%edx, 60(%3)\n"
24585 " addl $-64, %0\n"
24586@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24587 " shrl $2, %0\n"
24588 " andl $3, %%eax\n"
24589 " cld\n"
24590- "6: rep; movsl\n"
24591+ "6: rep; "__copyuser_seg" movsl\n"
24592 " movl %%eax,%0\n"
24593- "7: rep; movsb\n"
24594+ "7: rep; "__copyuser_seg" movsb\n"
24595 "8:\n"
24596 ".section .fixup,\"ax\"\n"
24597 "9: lea 0(%%eax,%0,4),%0\n"
24598@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
24599 * hyoshiok@miraclelinux.com
24600 */
24601
24602-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24603+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
24604 const void __user *from, unsigned long size)
24605 {
24606 int d0, d1;
24607
24608 __asm__ __volatile__(
24609 " .align 2,0x90\n"
24610- "0: movl 32(%4), %%eax\n"
24611+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24612 " cmpl $67, %0\n"
24613 " jbe 2f\n"
24614- "1: movl 64(%4), %%eax\n"
24615+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24616 " .align 2,0x90\n"
24617- "2: movl 0(%4), %%eax\n"
24618- "21: movl 4(%4), %%edx\n"
24619+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24620+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24621 " movnti %%eax, 0(%3)\n"
24622 " movnti %%edx, 4(%3)\n"
24623- "3: movl 8(%4), %%eax\n"
24624- "31: movl 12(%4),%%edx\n"
24625+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24626+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24627 " movnti %%eax, 8(%3)\n"
24628 " movnti %%edx, 12(%3)\n"
24629- "4: movl 16(%4), %%eax\n"
24630- "41: movl 20(%4), %%edx\n"
24631+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24632+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24633 " movnti %%eax, 16(%3)\n"
24634 " movnti %%edx, 20(%3)\n"
24635- "10: movl 24(%4), %%eax\n"
24636- "51: movl 28(%4), %%edx\n"
24637+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24638+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24639 " movnti %%eax, 24(%3)\n"
24640 " movnti %%edx, 28(%3)\n"
24641- "11: movl 32(%4), %%eax\n"
24642- "61: movl 36(%4), %%edx\n"
24643+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24644+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24645 " movnti %%eax, 32(%3)\n"
24646 " movnti %%edx, 36(%3)\n"
24647- "12: movl 40(%4), %%eax\n"
24648- "71: movl 44(%4), %%edx\n"
24649+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24650+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24651 " movnti %%eax, 40(%3)\n"
24652 " movnti %%edx, 44(%3)\n"
24653- "13: movl 48(%4), %%eax\n"
24654- "81: movl 52(%4), %%edx\n"
24655+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24656+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24657 " movnti %%eax, 48(%3)\n"
24658 " movnti %%edx, 52(%3)\n"
24659- "14: movl 56(%4), %%eax\n"
24660- "91: movl 60(%4), %%edx\n"
24661+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24662+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24663 " movnti %%eax, 56(%3)\n"
24664 " movnti %%edx, 60(%3)\n"
24665 " addl $-64, %0\n"
24666@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24667 " shrl $2, %0\n"
24668 " andl $3, %%eax\n"
24669 " cld\n"
24670- "6: rep; movsl\n"
24671+ "6: rep; "__copyuser_seg" movsl\n"
24672 " movl %%eax,%0\n"
24673- "7: rep; movsb\n"
24674+ "7: rep; "__copyuser_seg" movsb\n"
24675 "8:\n"
24676 ".section .fixup,\"ax\"\n"
24677 "9: lea 0(%%eax,%0,4),%0\n"
24678@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
24679 return size;
24680 }
24681
24682-static unsigned long __copy_user_intel_nocache(void *to,
24683+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
24684 const void __user *from, unsigned long size)
24685 {
24686 int d0, d1;
24687
24688 __asm__ __volatile__(
24689 " .align 2,0x90\n"
24690- "0: movl 32(%4), %%eax\n"
24691+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
24692 " cmpl $67, %0\n"
24693 " jbe 2f\n"
24694- "1: movl 64(%4), %%eax\n"
24695+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
24696 " .align 2,0x90\n"
24697- "2: movl 0(%4), %%eax\n"
24698- "21: movl 4(%4), %%edx\n"
24699+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
24700+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
24701 " movnti %%eax, 0(%3)\n"
24702 " movnti %%edx, 4(%3)\n"
24703- "3: movl 8(%4), %%eax\n"
24704- "31: movl 12(%4),%%edx\n"
24705+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
24706+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
24707 " movnti %%eax, 8(%3)\n"
24708 " movnti %%edx, 12(%3)\n"
24709- "4: movl 16(%4), %%eax\n"
24710- "41: movl 20(%4), %%edx\n"
24711+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
24712+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
24713 " movnti %%eax, 16(%3)\n"
24714 " movnti %%edx, 20(%3)\n"
24715- "10: movl 24(%4), %%eax\n"
24716- "51: movl 28(%4), %%edx\n"
24717+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
24718+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
24719 " movnti %%eax, 24(%3)\n"
24720 " movnti %%edx, 28(%3)\n"
24721- "11: movl 32(%4), %%eax\n"
24722- "61: movl 36(%4), %%edx\n"
24723+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
24724+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
24725 " movnti %%eax, 32(%3)\n"
24726 " movnti %%edx, 36(%3)\n"
24727- "12: movl 40(%4), %%eax\n"
24728- "71: movl 44(%4), %%edx\n"
24729+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
24730+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
24731 " movnti %%eax, 40(%3)\n"
24732 " movnti %%edx, 44(%3)\n"
24733- "13: movl 48(%4), %%eax\n"
24734- "81: movl 52(%4), %%edx\n"
24735+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
24736+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
24737 " movnti %%eax, 48(%3)\n"
24738 " movnti %%edx, 52(%3)\n"
24739- "14: movl 56(%4), %%eax\n"
24740- "91: movl 60(%4), %%edx\n"
24741+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
24742+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
24743 " movnti %%eax, 56(%3)\n"
24744 " movnti %%edx, 60(%3)\n"
24745 " addl $-64, %0\n"
24746@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
24747 " shrl $2, %0\n"
24748 " andl $3, %%eax\n"
24749 " cld\n"
24750- "6: rep; movsl\n"
24751+ "6: rep; "__copyuser_seg" movsl\n"
24752 " movl %%eax,%0\n"
24753- "7: rep; movsb\n"
24754+ "7: rep; "__copyuser_seg" movsb\n"
24755 "8:\n"
24756 ".section .fixup,\"ax\"\n"
24757 "9: lea 0(%%eax,%0,4),%0\n"
24758@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
24759 */
24760 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
24761 unsigned long size);
24762-unsigned long __copy_user_intel(void __user *to, const void *from,
24763+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
24764+ unsigned long size);
24765+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
24766 unsigned long size);
24767 unsigned long __copy_user_zeroing_intel_nocache(void *to,
24768 const void __user *from, unsigned long size);
24769 #endif /* CONFIG_X86_INTEL_USERCOPY */
24770
24771 /* Generic arbitrary sized copy. */
24772-#define __copy_user(to, from, size) \
24773+#define __copy_user(to, from, size, prefix, set, restore) \
24774 do { \
24775 int __d0, __d1, __d2; \
24776 __asm__ __volatile__( \
24777+ set \
24778 " cmp $7,%0\n" \
24779 " jbe 1f\n" \
24780 " movl %1,%0\n" \
24781 " negl %0\n" \
24782 " andl $7,%0\n" \
24783 " subl %0,%3\n" \
24784- "4: rep; movsb\n" \
24785+ "4: rep; "prefix"movsb\n" \
24786 " movl %3,%0\n" \
24787 " shrl $2,%0\n" \
24788 " andl $3,%3\n" \
24789 " .align 2,0x90\n" \
24790- "0: rep; movsl\n" \
24791+ "0: rep; "prefix"movsl\n" \
24792 " movl %3,%0\n" \
24793- "1: rep; movsb\n" \
24794+ "1: rep; "prefix"movsb\n" \
24795 "2:\n" \
24796+ restore \
24797 ".section .fixup,\"ax\"\n" \
24798 "5: addl %3,%0\n" \
24799 " jmp 2b\n" \
24800@@ -538,14 +650,14 @@ do { \
24801 " negl %0\n" \
24802 " andl $7,%0\n" \
24803 " subl %0,%3\n" \
24804- "4: rep; movsb\n" \
24805+ "4: rep; "__copyuser_seg"movsb\n" \
24806 " movl %3,%0\n" \
24807 " shrl $2,%0\n" \
24808 " andl $3,%3\n" \
24809 " .align 2,0x90\n" \
24810- "0: rep; movsl\n" \
24811+ "0: rep; "__copyuser_seg"movsl\n" \
24812 " movl %3,%0\n" \
24813- "1: rep; movsb\n" \
24814+ "1: rep; "__copyuser_seg"movsb\n" \
24815 "2:\n" \
24816 ".section .fixup,\"ax\"\n" \
24817 "5: addl %3,%0\n" \
24818@@ -629,9 +741,9 @@ survive:
24819 #endif
24820 stac();
24821 if (movsl_is_ok(to, from, n))
24822- __copy_user(to, from, n);
24823+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
24824 else
24825- n = __copy_user_intel(to, from, n);
24826+ n = __generic_copy_to_user_intel(to, from, n);
24827 clac();
24828 return n;
24829 }
24830@@ -655,10 +767,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
24831 {
24832 stac();
24833 if (movsl_is_ok(to, from, n))
24834- __copy_user(to, from, n);
24835+ __copy_user(to, from, n, __copyuser_seg, "", "");
24836 else
24837- n = __copy_user_intel((void __user *)to,
24838- (const void *)from, n);
24839+ n = __generic_copy_from_user_intel(to, from, n);
24840 clac();
24841 return n;
24842 }
24843@@ -689,66 +800,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
24844 if (n > 64 && cpu_has_xmm2)
24845 n = __copy_user_intel_nocache(to, from, n);
24846 else
24847- __copy_user(to, from, n);
24848+ __copy_user(to, from, n, __copyuser_seg, "", "");
24849 #else
24850- __copy_user(to, from, n);
24851+ __copy_user(to, from, n, __copyuser_seg, "", "");
24852 #endif
24853 clac();
24854 return n;
24855 }
24856 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
24857
24858-/**
24859- * copy_to_user: - Copy a block of data into user space.
24860- * @to: Destination address, in user space.
24861- * @from: Source address, in kernel space.
24862- * @n: Number of bytes to copy.
24863- *
24864- * Context: User context only. This function may sleep.
24865- *
24866- * Copy data from kernel space to user space.
24867- *
24868- * Returns number of bytes that could not be copied.
24869- * On success, this will be zero.
24870- */
24871-unsigned long
24872-copy_to_user(void __user *to, const void *from, unsigned long n)
24873-{
24874- if (access_ok(VERIFY_WRITE, to, n))
24875- n = __copy_to_user(to, from, n);
24876- return n;
24877-}
24878-EXPORT_SYMBOL(copy_to_user);
24879-
24880-/**
24881- * copy_from_user: - Copy a block of data from user space.
24882- * @to: Destination address, in kernel space.
24883- * @from: Source address, in user space.
24884- * @n: Number of bytes to copy.
24885- *
24886- * Context: User context only. This function may sleep.
24887- *
24888- * Copy data from user space to kernel space.
24889- *
24890- * Returns number of bytes that could not be copied.
24891- * On success, this will be zero.
24892- *
24893- * If some data could not be copied, this function will pad the copied
24894- * data to the requested size using zero bytes.
24895- */
24896-unsigned long
24897-_copy_from_user(void *to, const void __user *from, unsigned long n)
24898-{
24899- if (access_ok(VERIFY_READ, from, n))
24900- n = __copy_from_user(to, from, n);
24901- else
24902- memset(to, 0, n);
24903- return n;
24904-}
24905-EXPORT_SYMBOL(_copy_from_user);
24906-
24907 void copy_from_user_overflow(void)
24908 {
24909 WARN(1, "Buffer overflow detected!\n");
24910 }
24911 EXPORT_SYMBOL(copy_from_user_overflow);
24912+
24913+void copy_to_user_overflow(void)
24914+{
24915+ WARN(1, "Buffer overflow detected!\n");
24916+}
24917+EXPORT_SYMBOL(copy_to_user_overflow);
24918+
24919+#ifdef CONFIG_PAX_MEMORY_UDEREF
24920+void __set_fs(mm_segment_t x)
24921+{
24922+ switch (x.seg) {
24923+ case 0:
24924+ loadsegment(gs, 0);
24925+ break;
24926+ case TASK_SIZE_MAX:
24927+ loadsegment(gs, __USER_DS);
24928+ break;
24929+ case -1UL:
24930+ loadsegment(gs, __KERNEL_DS);
24931+ break;
24932+ default:
24933+ BUG();
24934+ }
24935+ return;
24936+}
24937+EXPORT_SYMBOL(__set_fs);
24938+
24939+void set_fs(mm_segment_t x)
24940+{
24941+ current_thread_info()->addr_limit = x;
24942+ __set_fs(x);
24943+}
24944+EXPORT_SYMBOL(set_fs);
24945+#endif
24946diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
24947index 05928aa..b33dea1 100644
24948--- a/arch/x86/lib/usercopy_64.c
24949+++ b/arch/x86/lib/usercopy_64.c
24950@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
24951 _ASM_EXTABLE(0b,3b)
24952 _ASM_EXTABLE(1b,2b)
24953 : [size8] "=&c"(size), [dst] "=&D" (__d0)
24954- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
24955+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
24956 [zero] "r" (0UL), [eight] "r" (8UL));
24957 clac();
24958 return size;
24959@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
24960 }
24961 EXPORT_SYMBOL(clear_user);
24962
24963-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
24964+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
24965 {
24966- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
24967- return copy_user_generic((__force void *)to, (__force void *)from, len);
24968- }
24969- return len;
24970+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
24971+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
24972+ return len;
24973 }
24974 EXPORT_SYMBOL(copy_in_user);
24975
24976@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
24977 * it is not necessary to optimize tail handling.
24978 */
24979 unsigned long
24980-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24981+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
24982 {
24983 char c;
24984 unsigned zero_len;
24985@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
24986 clac();
24987 return len;
24988 }
24989+
24990+void copy_from_user_overflow(void)
24991+{
24992+ WARN(1, "Buffer overflow detected!\n");
24993+}
24994+EXPORT_SYMBOL(copy_from_user_overflow);
24995+
24996+void copy_to_user_overflow(void)
24997+{
24998+ WARN(1, "Buffer overflow detected!\n");
24999+}
25000+EXPORT_SYMBOL(copy_to_user_overflow);
25001diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
25002index 903ec1e..c4166b2 100644
25003--- a/arch/x86/mm/extable.c
25004+++ b/arch/x86/mm/extable.c
25005@@ -6,12 +6,24 @@
25006 static inline unsigned long
25007 ex_insn_addr(const struct exception_table_entry *x)
25008 {
25009- return (unsigned long)&x->insn + x->insn;
25010+ unsigned long reloc = 0;
25011+
25012+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25013+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25014+#endif
25015+
25016+ return (unsigned long)&x->insn + x->insn + reloc;
25017 }
25018 static inline unsigned long
25019 ex_fixup_addr(const struct exception_table_entry *x)
25020 {
25021- return (unsigned long)&x->fixup + x->fixup;
25022+ unsigned long reloc = 0;
25023+
25024+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25025+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25026+#endif
25027+
25028+ return (unsigned long)&x->fixup + x->fixup + reloc;
25029 }
25030
25031 int fixup_exception(struct pt_regs *regs)
25032@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
25033 unsigned long new_ip;
25034
25035 #ifdef CONFIG_PNPBIOS
25036- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
25037+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
25038 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
25039 extern u32 pnp_bios_is_utter_crap;
25040 pnp_bios_is_utter_crap = 1;
25041@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
25042 i += 4;
25043 p->fixup -= i;
25044 i += 4;
25045+
25046+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25047+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
25048+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25049+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
25050+#endif
25051+
25052 }
25053 }
25054
25055diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
25056index 8e13ecb..831f2d0 100644
25057--- a/arch/x86/mm/fault.c
25058+++ b/arch/x86/mm/fault.c
25059@@ -13,12 +13,19 @@
25060 #include <linux/perf_event.h> /* perf_sw_event */
25061 #include <linux/hugetlb.h> /* hstate_index_to_shift */
25062 #include <linux/prefetch.h> /* prefetchw */
25063+#include <linux/unistd.h>
25064+#include <linux/compiler.h>
25065
25066 #include <asm/traps.h> /* dotraplinkage, ... */
25067 #include <asm/pgalloc.h> /* pgd_*(), ... */
25068 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
25069 #include <asm/fixmap.h> /* VSYSCALL_START */
25070 #include <asm/rcu.h> /* exception_enter(), ... */
25071+#include <asm/tlbflush.h>
25072+
25073+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25074+#include <asm/stacktrace.h>
25075+#endif
25076
25077 /*
25078 * Page fault error code bits:
25079@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
25080 int ret = 0;
25081
25082 /* kprobe_running() needs smp_processor_id() */
25083- if (kprobes_built_in() && !user_mode_vm(regs)) {
25084+ if (kprobes_built_in() && !user_mode(regs)) {
25085 preempt_disable();
25086 if (kprobe_running() && kprobe_fault_handler(regs, 14))
25087 ret = 1;
25088@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
25089 return !instr_lo || (instr_lo>>1) == 1;
25090 case 0x00:
25091 /* Prefetch instruction is 0x0F0D or 0x0F18 */
25092- if (probe_kernel_address(instr, opcode))
25093+ if (user_mode(regs)) {
25094+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25095+ return 0;
25096+ } else if (probe_kernel_address(instr, opcode))
25097 return 0;
25098
25099 *prefetch = (instr_lo == 0xF) &&
25100@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
25101 while (instr < max_instr) {
25102 unsigned char opcode;
25103
25104- if (probe_kernel_address(instr, opcode))
25105+ if (user_mode(regs)) {
25106+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
25107+ break;
25108+ } else if (probe_kernel_address(instr, opcode))
25109 break;
25110
25111 instr++;
25112@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
25113 force_sig_info(si_signo, &info, tsk);
25114 }
25115
25116+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25117+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
25118+#endif
25119+
25120+#ifdef CONFIG_PAX_EMUTRAMP
25121+static int pax_handle_fetch_fault(struct pt_regs *regs);
25122+#endif
25123+
25124+#ifdef CONFIG_PAX_PAGEEXEC
25125+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
25126+{
25127+ pgd_t *pgd;
25128+ pud_t *pud;
25129+ pmd_t *pmd;
25130+
25131+ pgd = pgd_offset(mm, address);
25132+ if (!pgd_present(*pgd))
25133+ return NULL;
25134+ pud = pud_offset(pgd, address);
25135+ if (!pud_present(*pud))
25136+ return NULL;
25137+ pmd = pmd_offset(pud, address);
25138+ if (!pmd_present(*pmd))
25139+ return NULL;
25140+ return pmd;
25141+}
25142+#endif
25143+
25144 DEFINE_SPINLOCK(pgd_lock);
25145 LIST_HEAD(pgd_list);
25146
25147@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
25148 for (address = VMALLOC_START & PMD_MASK;
25149 address >= TASK_SIZE && address < FIXADDR_TOP;
25150 address += PMD_SIZE) {
25151+
25152+#ifdef CONFIG_PAX_PER_CPU_PGD
25153+ unsigned long cpu;
25154+#else
25155 struct page *page;
25156+#endif
25157
25158 spin_lock(&pgd_lock);
25159+
25160+#ifdef CONFIG_PAX_PER_CPU_PGD
25161+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25162+ pgd_t *pgd = get_cpu_pgd(cpu);
25163+ pmd_t *ret;
25164+#else
25165 list_for_each_entry(page, &pgd_list, lru) {
25166+ pgd_t *pgd = page_address(page);
25167 spinlock_t *pgt_lock;
25168 pmd_t *ret;
25169
25170@@ -243,8 +296,13 @@ void vmalloc_sync_all(void)
25171 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25172
25173 spin_lock(pgt_lock);
25174- ret = vmalloc_sync_one(page_address(page), address);
25175+#endif
25176+
25177+ ret = vmalloc_sync_one(pgd, address);
25178+
25179+#ifndef CONFIG_PAX_PER_CPU_PGD
25180 spin_unlock(pgt_lock);
25181+#endif
25182
25183 if (!ret)
25184 break;
25185@@ -278,6 +336,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25186 * an interrupt in the middle of a task switch..
25187 */
25188 pgd_paddr = read_cr3();
25189+
25190+#ifdef CONFIG_PAX_PER_CPU_PGD
25191+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
25192+#endif
25193+
25194 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
25195 if (!pmd_k)
25196 return -1;
25197@@ -373,7 +436,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
25198 * happen within a race in page table update. In the later
25199 * case just flush:
25200 */
25201+
25202+#ifdef CONFIG_PAX_PER_CPU_PGD
25203+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
25204+ pgd = pgd_offset_cpu(smp_processor_id(), address);
25205+#else
25206 pgd = pgd_offset(current->active_mm, address);
25207+#endif
25208+
25209 pgd_ref = pgd_offset_k(address);
25210 if (pgd_none(*pgd_ref))
25211 return -1;
25212@@ -541,7 +611,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
25213 static int is_errata100(struct pt_regs *regs, unsigned long address)
25214 {
25215 #ifdef CONFIG_X86_64
25216- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
25217+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
25218 return 1;
25219 #endif
25220 return 0;
25221@@ -568,7 +638,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
25222 }
25223
25224 static const char nx_warning[] = KERN_CRIT
25225-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
25226+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
25227
25228 static void
25229 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25230@@ -577,15 +647,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
25231 if (!oops_may_print())
25232 return;
25233
25234- if (error_code & PF_INSTR) {
25235+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
25236 unsigned int level;
25237
25238 pte_t *pte = lookup_address(address, &level);
25239
25240 if (pte && pte_present(*pte) && !pte_exec(*pte))
25241- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
25242+ printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
25243 }
25244
25245+#ifdef CONFIG_PAX_KERNEXEC
25246+ if (init_mm.start_code <= address && address < init_mm.end_code) {
25247+ if (current->signal->curr_ip)
25248+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25249+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
25250+ else
25251+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
25252+ current->comm, task_pid_nr(current), current_uid(), current_euid());
25253+ }
25254+#endif
25255+
25256 printk(KERN_ALERT "BUG: unable to handle kernel ");
25257 if (address < PAGE_SIZE)
25258 printk(KERN_CONT "NULL pointer dereference");
25259@@ -749,6 +830,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
25260 }
25261 #endif
25262
25263+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25264+ if (pax_is_fetch_fault(regs, error_code, address)) {
25265+
25266+#ifdef CONFIG_PAX_EMUTRAMP
25267+ switch (pax_handle_fetch_fault(regs)) {
25268+ case 2:
25269+ return;
25270+ }
25271+#endif
25272+
25273+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25274+ do_group_exit(SIGKILL);
25275+ }
25276+#endif
25277+
25278 if (unlikely(show_unhandled_signals))
25279 show_signal_msg(regs, error_code, address, tsk);
25280
25281@@ -845,7 +941,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
25282 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
25283 printk(KERN_ERR
25284 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
25285- tsk->comm, tsk->pid, address);
25286+ tsk->comm, task_pid_nr(tsk), address);
25287 code = BUS_MCEERR_AR;
25288 }
25289 #endif
25290@@ -901,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
25291 return 1;
25292 }
25293
25294+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25295+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
25296+{
25297+ pte_t *pte;
25298+ pmd_t *pmd;
25299+ spinlock_t *ptl;
25300+ unsigned char pte_mask;
25301+
25302+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
25303+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
25304+ return 0;
25305+
25306+ /* PaX: it's our fault, let's handle it if we can */
25307+
25308+ /* PaX: take a look at read faults before acquiring any locks */
25309+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
25310+ /* instruction fetch attempt from a protected page in user mode */
25311+ up_read(&mm->mmap_sem);
25312+
25313+#ifdef CONFIG_PAX_EMUTRAMP
25314+ switch (pax_handle_fetch_fault(regs)) {
25315+ case 2:
25316+ return 1;
25317+ }
25318+#endif
25319+
25320+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
25321+ do_group_exit(SIGKILL);
25322+ }
25323+
25324+ pmd = pax_get_pmd(mm, address);
25325+ if (unlikely(!pmd))
25326+ return 0;
25327+
25328+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
25329+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
25330+ pte_unmap_unlock(pte, ptl);
25331+ return 0;
25332+ }
25333+
25334+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
25335+ /* write attempt to a protected page in user mode */
25336+ pte_unmap_unlock(pte, ptl);
25337+ return 0;
25338+ }
25339+
25340+#ifdef CONFIG_SMP
25341+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
25342+#else
25343+ if (likely(address > get_limit(regs->cs)))
25344+#endif
25345+ {
25346+ set_pte(pte, pte_mkread(*pte));
25347+ __flush_tlb_one(address);
25348+ pte_unmap_unlock(pte, ptl);
25349+ up_read(&mm->mmap_sem);
25350+ return 1;
25351+ }
25352+
25353+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
25354+
25355+ /*
25356+ * PaX: fill DTLB with user rights and retry
25357+ */
25358+ __asm__ __volatile__ (
25359+ "orb %2,(%1)\n"
25360+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
25361+/*
25362+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
25363+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
25364+ * page fault when examined during a TLB load attempt. this is true not only
25365+ * for PTEs holding a non-present entry but also present entries that will
25366+ * raise a page fault (such as those set up by PaX, or the copy-on-write
25367+ * mechanism). in effect it means that we do *not* need to flush the TLBs
25368+ * for our target pages since their PTEs are simply not in the TLBs at all.
25369+
25370+ * the best thing in omitting it is that we gain around 15-20% speed in the
25371+ * fast path of the page fault handler and can get rid of tracing since we
25372+ * can no longer flush unintended entries.
25373+ */
25374+ "invlpg (%0)\n"
25375+#endif
25376+ __copyuser_seg"testb $0,(%0)\n"
25377+ "xorb %3,(%1)\n"
25378+ :
25379+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
25380+ : "memory", "cc");
25381+ pte_unmap_unlock(pte, ptl);
25382+ up_read(&mm->mmap_sem);
25383+ return 1;
25384+}
25385+#endif
25386+
25387 /*
25388 * Handle a spurious fault caused by a stale TLB entry.
25389 *
25390@@ -973,6 +1162,9 @@ int show_unhandled_signals = 1;
25391 static inline int
25392 access_error(unsigned long error_code, struct vm_area_struct *vma)
25393 {
25394+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
25395+ return 1;
25396+
25397 if (error_code & PF_WRITE) {
25398 /* write, present and write, not present: */
25399 if (unlikely(!(vma->vm_flags & VM_WRITE)))
25400@@ -1001,7 +1193,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
25401 if (error_code & PF_USER)
25402 return false;
25403
25404- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
25405+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
25406 return false;
25407
25408 return true;
25409@@ -1017,18 +1209,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25410 {
25411 struct vm_area_struct *vma;
25412 struct task_struct *tsk;
25413- unsigned long address;
25414 struct mm_struct *mm;
25415 int fault;
25416 int write = error_code & PF_WRITE;
25417 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
25418 (write ? FAULT_FLAG_WRITE : 0);
25419
25420- tsk = current;
25421- mm = tsk->mm;
25422-
25423 /* Get the faulting address: */
25424- address = read_cr2();
25425+ unsigned long address = read_cr2();
25426+
25427+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25428+ if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
25429+ if (!search_exception_tables(regs->ip)) {
25430+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25431+ bad_area_nosemaphore(regs, error_code, address);
25432+ return;
25433+ }
25434+ if (address < PAX_USER_SHADOW_BASE) {
25435+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
25436+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
25437+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
25438+ } else
25439+ address -= PAX_USER_SHADOW_BASE;
25440+ }
25441+#endif
25442+
25443+ tsk = current;
25444+ mm = tsk->mm;
25445
25446 /*
25447 * Detect and handle instructions that would cause a page fault for
25448@@ -1089,7 +1296,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
25449 * User-mode registers count as a user access even for any
25450 * potential system fault or CPU buglet:
25451 */
25452- if (user_mode_vm(regs)) {
25453+ if (user_mode(regs)) {
25454 local_irq_enable();
25455 error_code |= PF_USER;
25456 } else {
25457@@ -1151,6 +1358,11 @@ retry:
25458 might_sleep();
25459 }
25460
25461+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25462+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
25463+ return;
25464+#endif
25465+
25466 vma = find_vma(mm, address);
25467 if (unlikely(!vma)) {
25468 bad_area(regs, error_code, address);
25469@@ -1162,18 +1374,24 @@ retry:
25470 bad_area(regs, error_code, address);
25471 return;
25472 }
25473- if (error_code & PF_USER) {
25474- /*
25475- * Accessing the stack below %sp is always a bug.
25476- * The large cushion allows instructions like enter
25477- * and pusha to work. ("enter $65535, $31" pushes
25478- * 32 pointers and then decrements %sp by 65535.)
25479- */
25480- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
25481- bad_area(regs, error_code, address);
25482- return;
25483- }
25484+ /*
25485+ * Accessing the stack below %sp is always a bug.
25486+ * The large cushion allows instructions like enter
25487+ * and pusha to work. ("enter $65535, $31" pushes
25488+ * 32 pointers and then decrements %sp by 65535.)
25489+ */
25490+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
25491+ bad_area(regs, error_code, address);
25492+ return;
25493 }
25494+
25495+#ifdef CONFIG_PAX_SEGMEXEC
25496+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
25497+ bad_area(regs, error_code, address);
25498+ return;
25499+ }
25500+#endif
25501+
25502 if (unlikely(expand_stack(vma, address))) {
25503 bad_area(regs, error_code, address);
25504 return;
25505@@ -1237,3 +1455,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
25506 __do_page_fault(regs, error_code);
25507 exception_exit(regs);
25508 }
25509+
25510+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25511+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
25512+{
25513+ struct mm_struct *mm = current->mm;
25514+ unsigned long ip = regs->ip;
25515+
25516+ if (v8086_mode(regs))
25517+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
25518+
25519+#ifdef CONFIG_PAX_PAGEEXEC
25520+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
25521+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
25522+ return true;
25523+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
25524+ return true;
25525+ return false;
25526+ }
25527+#endif
25528+
25529+#ifdef CONFIG_PAX_SEGMEXEC
25530+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
25531+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
25532+ return true;
25533+ return false;
25534+ }
25535+#endif
25536+
25537+ return false;
25538+}
25539+#endif
25540+
25541+#ifdef CONFIG_PAX_EMUTRAMP
25542+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
25543+{
25544+ int err;
25545+
25546+ do { /* PaX: libffi trampoline emulation */
25547+ unsigned char mov, jmp;
25548+ unsigned int addr1, addr2;
25549+
25550+#ifdef CONFIG_X86_64
25551+ if ((regs->ip + 9) >> 32)
25552+ break;
25553+#endif
25554+
25555+ err = get_user(mov, (unsigned char __user *)regs->ip);
25556+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25557+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25558+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25559+
25560+ if (err)
25561+ break;
25562+
25563+ if (mov == 0xB8 && jmp == 0xE9) {
25564+ regs->ax = addr1;
25565+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25566+ return 2;
25567+ }
25568+ } while (0);
25569+
25570+ do { /* PaX: gcc trampoline emulation #1 */
25571+ unsigned char mov1, mov2;
25572+ unsigned short jmp;
25573+ unsigned int addr1, addr2;
25574+
25575+#ifdef CONFIG_X86_64
25576+ if ((regs->ip + 11) >> 32)
25577+ break;
25578+#endif
25579+
25580+ err = get_user(mov1, (unsigned char __user *)regs->ip);
25581+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25582+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
25583+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25584+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
25585+
25586+ if (err)
25587+ break;
25588+
25589+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
25590+ regs->cx = addr1;
25591+ regs->ax = addr2;
25592+ regs->ip = addr2;
25593+ return 2;
25594+ }
25595+ } while (0);
25596+
25597+ do { /* PaX: gcc trampoline emulation #2 */
25598+ unsigned char mov, jmp;
25599+ unsigned int addr1, addr2;
25600+
25601+#ifdef CONFIG_X86_64
25602+ if ((regs->ip + 9) >> 32)
25603+ break;
25604+#endif
25605+
25606+ err = get_user(mov, (unsigned char __user *)regs->ip);
25607+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
25608+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
25609+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
25610+
25611+ if (err)
25612+ break;
25613+
25614+ if (mov == 0xB9 && jmp == 0xE9) {
25615+ regs->cx = addr1;
25616+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
25617+ return 2;
25618+ }
25619+ } while (0);
25620+
25621+ return 1; /* PaX in action */
25622+}
25623+
25624+#ifdef CONFIG_X86_64
25625+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
25626+{
25627+ int err;
25628+
25629+ do { /* PaX: libffi trampoline emulation */
25630+ unsigned short mov1, mov2, jmp1;
25631+ unsigned char stcclc, jmp2;
25632+ unsigned long addr1, addr2;
25633+
25634+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25635+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25636+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25637+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25638+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
25639+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
25640+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
25641+
25642+ if (err)
25643+ break;
25644+
25645+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25646+ regs->r11 = addr1;
25647+ regs->r10 = addr2;
25648+ if (stcclc == 0xF8)
25649+ regs->flags &= ~X86_EFLAGS_CF;
25650+ else
25651+ regs->flags |= X86_EFLAGS_CF;
25652+ regs->ip = addr1;
25653+ return 2;
25654+ }
25655+ } while (0);
25656+
25657+ do { /* PaX: gcc trampoline emulation #1 */
25658+ unsigned short mov1, mov2, jmp1;
25659+ unsigned char jmp2;
25660+ unsigned int addr1;
25661+ unsigned long addr2;
25662+
25663+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25664+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
25665+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
25666+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
25667+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
25668+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
25669+
25670+ if (err)
25671+ break;
25672+
25673+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25674+ regs->r11 = addr1;
25675+ regs->r10 = addr2;
25676+ regs->ip = addr1;
25677+ return 2;
25678+ }
25679+ } while (0);
25680+
25681+ do { /* PaX: gcc trampoline emulation #2 */
25682+ unsigned short mov1, mov2, jmp1;
25683+ unsigned char jmp2;
25684+ unsigned long addr1, addr2;
25685+
25686+ err = get_user(mov1, (unsigned short __user *)regs->ip);
25687+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
25688+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
25689+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
25690+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
25691+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
25692+
25693+ if (err)
25694+ break;
25695+
25696+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
25697+ regs->r11 = addr1;
25698+ regs->r10 = addr2;
25699+ regs->ip = addr1;
25700+ return 2;
25701+ }
25702+ } while (0);
25703+
25704+ return 1; /* PaX in action */
25705+}
25706+#endif
25707+
25708+/*
25709+ * PaX: decide what to do with offenders (regs->ip = fault address)
25710+ *
25711+ * returns 1 when task should be killed
25712+ * 2 when gcc trampoline was detected
25713+ */
25714+static int pax_handle_fetch_fault(struct pt_regs *regs)
25715+{
25716+ if (v8086_mode(regs))
25717+ return 1;
25718+
25719+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
25720+ return 1;
25721+
25722+#ifdef CONFIG_X86_32
25723+ return pax_handle_fetch_fault_32(regs);
25724+#else
25725+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
25726+ return pax_handle_fetch_fault_32(regs);
25727+ else
25728+ return pax_handle_fetch_fault_64(regs);
25729+#endif
25730+}
25731+#endif
25732+
25733+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25734+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
25735+{
25736+ long i;
25737+
25738+ printk(KERN_ERR "PAX: bytes at PC: ");
25739+ for (i = 0; i < 20; i++) {
25740+ unsigned char c;
25741+ if (get_user(c, (unsigned char __force_user *)pc+i))
25742+ printk(KERN_CONT "?? ");
25743+ else
25744+ printk(KERN_CONT "%02x ", c);
25745+ }
25746+ printk("\n");
25747+
25748+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
25749+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
25750+ unsigned long c;
25751+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
25752+#ifdef CONFIG_X86_32
25753+ printk(KERN_CONT "???????? ");
25754+#else
25755+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
25756+ printk(KERN_CONT "???????? ???????? ");
25757+ else
25758+ printk(KERN_CONT "???????????????? ");
25759+#endif
25760+ } else {
25761+#ifdef CONFIG_X86_64
25762+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
25763+ printk(KERN_CONT "%08x ", (unsigned int)c);
25764+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
25765+ } else
25766+#endif
25767+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
25768+ }
25769+ }
25770+ printk("\n");
25771+}
25772+#endif
25773+
25774+/**
25775+ * probe_kernel_write(): safely attempt to write to a location
25776+ * @dst: address to write to
25777+ * @src: pointer to the data that shall be written
25778+ * @size: size of the data chunk
25779+ *
25780+ * Safely write to address @dst from the buffer at @src. If a kernel fault
25781+ * happens, handle that and return -EFAULT.
25782+ */
25783+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
25784+{
25785+ long ret;
25786+ mm_segment_t old_fs = get_fs();
25787+
25788+ set_fs(KERNEL_DS);
25789+ pagefault_disable();
25790+ pax_open_kernel();
25791+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
25792+ pax_close_kernel();
25793+ pagefault_enable();
25794+ set_fs(old_fs);
25795+
25796+ return ret ? -EFAULT : 0;
25797+}
25798diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
25799index dd74e46..7d26398 100644
25800--- a/arch/x86/mm/gup.c
25801+++ b/arch/x86/mm/gup.c
25802@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
25803 addr = start;
25804 len = (unsigned long) nr_pages << PAGE_SHIFT;
25805 end = start + len;
25806- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25807+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
25808 (void __user *)start, len)))
25809 return 0;
25810
25811diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
25812index 6f31ee5..8ee4164 100644
25813--- a/arch/x86/mm/highmem_32.c
25814+++ b/arch/x86/mm/highmem_32.c
25815@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
25816 idx = type + KM_TYPE_NR*smp_processor_id();
25817 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25818 BUG_ON(!pte_none(*(kmap_pte-idx)));
25819+
25820+ pax_open_kernel();
25821 set_pte(kmap_pte-idx, mk_pte(page, prot));
25822+ pax_close_kernel();
25823+
25824 arch_flush_lazy_mmu_mode();
25825
25826 return (void *)vaddr;
25827diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
25828index 937bff5..a354c44 100644
25829--- a/arch/x86/mm/hugetlbpage.c
25830+++ b/arch/x86/mm/hugetlbpage.c
25831@@ -276,13 +276,21 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
25832 struct hstate *h = hstate_file(file);
25833 struct mm_struct *mm = current->mm;
25834 struct vm_area_struct *vma;
25835- unsigned long start_addr;
25836+ unsigned long start_addr, pax_task_size = TASK_SIZE;
25837+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25838+
25839+#ifdef CONFIG_PAX_SEGMEXEC
25840+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25841+ pax_task_size = SEGMEXEC_TASK_SIZE;
25842+#endif
25843+
25844+ pax_task_size -= PAGE_SIZE;
25845
25846 if (len > mm->cached_hole_size) {
25847- start_addr = mm->free_area_cache;
25848+ start_addr = mm->free_area_cache;
25849 } else {
25850- start_addr = TASK_UNMAPPED_BASE;
25851- mm->cached_hole_size = 0;
25852+ start_addr = mm->mmap_base;
25853+ mm->cached_hole_size = 0;
25854 }
25855
25856 full_search:
25857@@ -290,26 +298,27 @@ full_search:
25858
25859 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
25860 /* At this point: (!vma || addr < vma->vm_end). */
25861- if (TASK_SIZE - len < addr) {
25862+ if (pax_task_size - len < addr) {
25863 /*
25864 * Start a new search - just in case we missed
25865 * some holes.
25866 */
25867- if (start_addr != TASK_UNMAPPED_BASE) {
25868- start_addr = TASK_UNMAPPED_BASE;
25869+ if (start_addr != mm->mmap_base) {
25870+ start_addr = mm->mmap_base;
25871 mm->cached_hole_size = 0;
25872 goto full_search;
25873 }
25874 return -ENOMEM;
25875 }
25876- if (!vma || addr + len <= vma->vm_start) {
25877- mm->free_area_cache = addr + len;
25878- return addr;
25879- }
25880+ if (check_heap_stack_gap(vma, addr, len, offset))
25881+ break;
25882 if (addr + mm->cached_hole_size < vma->vm_start)
25883 mm->cached_hole_size = vma->vm_start - addr;
25884 addr = ALIGN(vma->vm_end, huge_page_size(h));
25885 }
25886+
25887+ mm->free_area_cache = addr + len;
25888+ return addr;
25889 }
25890
25891 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25892@@ -320,9 +329,9 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25893 struct mm_struct *mm = current->mm;
25894 struct vm_area_struct *vma;
25895 unsigned long base = mm->mmap_base;
25896- unsigned long addr = addr0;
25897+ unsigned long addr;
25898 unsigned long largest_hole = mm->cached_hole_size;
25899- unsigned long start_addr;
25900+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25901
25902 /* don't allow allocations above current base */
25903 if (mm->free_area_cache > base)
25904@@ -332,16 +341,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
25905 largest_hole = 0;
25906 mm->free_area_cache = base;
25907 }
25908-try_again:
25909- start_addr = mm->free_area_cache;
25910
25911 /* make sure it can fit in the remaining address space */
25912 if (mm->free_area_cache < len)
25913 goto fail;
25914
25915 /* either no address requested or can't fit in requested address hole */
25916- addr = (mm->free_area_cache - len) & huge_page_mask(h);
25917+ addr = mm->free_area_cache - len;
25918 do {
25919+ addr &= huge_page_mask(h);
25920 /*
25921 * Lookup failure means no vma is above this address,
25922 * i.e. return with success:
25923@@ -350,10 +358,10 @@ try_again:
25924 if (!vma)
25925 return addr;
25926
25927- if (addr + len <= vma->vm_start) {
25928+ if (check_heap_stack_gap(vma, addr, len, offset)) {
25929 /* remember the address as a hint for next time */
25930- mm->cached_hole_size = largest_hole;
25931- return (mm->free_area_cache = addr);
25932+ mm->cached_hole_size = largest_hole;
25933+ return (mm->free_area_cache = addr);
25934 } else if (mm->free_area_cache == vma->vm_end) {
25935 /* pull free_area_cache down to the first hole */
25936 mm->free_area_cache = vma->vm_start;
25937@@ -362,29 +370,34 @@ try_again:
25938
25939 /* remember the largest hole we saw so far */
25940 if (addr + largest_hole < vma->vm_start)
25941- largest_hole = vma->vm_start - addr;
25942+ largest_hole = vma->vm_start - addr;
25943
25944 /* try just below the current vma->vm_start */
25945- addr = (vma->vm_start - len) & huge_page_mask(h);
25946- } while (len <= vma->vm_start);
25947+ addr = skip_heap_stack_gap(vma, len, offset);
25948+ } while (!IS_ERR_VALUE(addr));
25949
25950 fail:
25951 /*
25952- * if hint left us with no space for the requested
25953- * mapping then try again:
25954- */
25955- if (start_addr != base) {
25956- mm->free_area_cache = base;
25957- largest_hole = 0;
25958- goto try_again;
25959- }
25960- /*
25961 * A failed mmap() very likely causes application failure,
25962 * so fall back to the bottom-up function here. This scenario
25963 * can happen with large stack limits and large mmap()
25964 * allocations.
25965 */
25966- mm->free_area_cache = TASK_UNMAPPED_BASE;
25967+
25968+#ifdef CONFIG_PAX_SEGMEXEC
25969+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25970+ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
25971+ else
25972+#endif
25973+
25974+ mm->mmap_base = TASK_UNMAPPED_BASE;
25975+
25976+#ifdef CONFIG_PAX_RANDMMAP
25977+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25978+ mm->mmap_base += mm->delta_mmap;
25979+#endif
25980+
25981+ mm->free_area_cache = mm->mmap_base;
25982 mm->cached_hole_size = ~0UL;
25983 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
25984 len, pgoff, flags);
25985@@ -392,6 +405,7 @@ fail:
25986 /*
25987 * Restore the topdown base:
25988 */
25989+ mm->mmap_base = base;
25990 mm->free_area_cache = base;
25991 mm->cached_hole_size = ~0UL;
25992
25993@@ -405,10 +419,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
25994 struct hstate *h = hstate_file(file);
25995 struct mm_struct *mm = current->mm;
25996 struct vm_area_struct *vma;
25997+ unsigned long pax_task_size = TASK_SIZE;
25998+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
25999
26000 if (len & ~huge_page_mask(h))
26001 return -EINVAL;
26002- if (len > TASK_SIZE)
26003+
26004+#ifdef CONFIG_PAX_SEGMEXEC
26005+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26006+ pax_task_size = SEGMEXEC_TASK_SIZE;
26007+#endif
26008+
26009+ pax_task_size -= PAGE_SIZE;
26010+
26011+ if (len > pax_task_size)
26012 return -ENOMEM;
26013
26014 if (flags & MAP_FIXED) {
26015@@ -420,8 +444,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
26016 if (addr) {
26017 addr = ALIGN(addr, huge_page_size(h));
26018 vma = find_vma(mm, addr);
26019- if (TASK_SIZE - len >= addr &&
26020- (!vma || addr + len <= vma->vm_start))
26021+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26022 return addr;
26023 }
26024 if (mm->get_unmapped_area == arch_get_unmapped_area)
26025diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
26026index d7aea41..0fc945b 100644
26027--- a/arch/x86/mm/init.c
26028+++ b/arch/x86/mm/init.c
26029@@ -4,6 +4,7 @@
26030 #include <linux/swap.h>
26031 #include <linux/memblock.h>
26032 #include <linux/bootmem.h> /* for max_low_pfn */
26033+#include <linux/tboot.h>
26034
26035 #include <asm/cacheflush.h>
26036 #include <asm/e820.h>
26037@@ -16,6 +17,8 @@
26038 #include <asm/tlb.h>
26039 #include <asm/proto.h>
26040 #include <asm/dma.h> /* for MAX_DMA_PFN */
26041+#include <asm/desc.h>
26042+#include <asm/bios_ebda.h>
26043
26044 unsigned long __initdata pgt_buf_start;
26045 unsigned long __meminitdata pgt_buf_end;
26046@@ -44,7 +47,7 @@ static void __init find_early_table_space(struct map_range *mr, int nr_range)
26047 {
26048 int i;
26049 unsigned long puds = 0, pmds = 0, ptes = 0, tables;
26050- unsigned long start = 0, good_end;
26051+ unsigned long start = 0x100000, good_end;
26052 phys_addr_t base;
26053
26054 for (i = 0; i < nr_range; i++) {
26055@@ -321,10 +324,40 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
26056 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
26057 * mmio resources as well as potential bios/acpi data regions.
26058 */
26059+
26060+#ifdef CONFIG_GRKERNSEC_KMEM
26061+static unsigned int ebda_start __read_only;
26062+static unsigned int ebda_end __read_only;
26063+#endif
26064+
26065 int devmem_is_allowed(unsigned long pagenr)
26066 {
26067- if (pagenr < 256)
26068+#ifdef CONFIG_GRKERNSEC_KMEM
26069+ /* allow BDA */
26070+ if (!pagenr)
26071 return 1;
26072+ /* allow EBDA */
26073+ if (pagenr >= ebda_start && pagenr < ebda_end)
26074+ return 1;
26075+ /* if tboot is in use, allow access to its hardcoded serial log range */
26076+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
26077+ return 1;
26078+#else
26079+ if (!pagenr)
26080+ return 1;
26081+#ifdef CONFIG_VM86
26082+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
26083+ return 1;
26084+#endif
26085+#endif
26086+
26087+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
26088+ return 1;
26089+#ifdef CONFIG_GRKERNSEC_KMEM
26090+ /* throw out everything else below 1MB */
26091+ if (pagenr <= 256)
26092+ return 0;
26093+#endif
26094 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
26095 return 0;
26096 if (!page_is_ram(pagenr))
26097@@ -381,8 +414,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
26098 #endif
26099 }
26100
26101+#ifdef CONFIG_GRKERNSEC_KMEM
26102+static inline void gr_init_ebda(void)
26103+{
26104+ unsigned int ebda_addr;
26105+ unsigned int ebda_size = 0;
26106+
26107+ ebda_addr = get_bios_ebda();
26108+ if (ebda_addr) {
26109+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
26110+ ebda_size <<= 10;
26111+ }
26112+ if (ebda_addr && ebda_size) {
26113+ ebda_start = ebda_addr >> PAGE_SHIFT;
26114+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
26115+ } else {
26116+ ebda_start = 0x9f000 >> PAGE_SHIFT;
26117+ ebda_end = 0xa0000 >> PAGE_SHIFT;
26118+ }
26119+}
26120+#else
26121+static inline void gr_init_ebda(void) { }
26122+#endif
26123+
26124 void free_initmem(void)
26125 {
26126+#ifdef CONFIG_PAX_KERNEXEC
26127+#ifdef CONFIG_X86_32
26128+ /* PaX: limit KERNEL_CS to actual size */
26129+ unsigned long addr, limit;
26130+ struct desc_struct d;
26131+ int cpu;
26132+#else
26133+ pgd_t *pgd;
26134+ pud_t *pud;
26135+ pmd_t *pmd;
26136+ unsigned long addr, end;
26137+#endif
26138+#endif
26139+
26140+ gr_init_ebda();
26141+
26142+#ifdef CONFIG_PAX_KERNEXEC
26143+#ifdef CONFIG_X86_32
26144+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
26145+ limit = (limit - 1UL) >> PAGE_SHIFT;
26146+
26147+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
26148+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26149+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
26150+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
26151+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
26152+ }
26153+
26154+ /* PaX: make KERNEL_CS read-only */
26155+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
26156+ if (!paravirt_enabled())
26157+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
26158+/*
26159+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
26160+ pgd = pgd_offset_k(addr);
26161+ pud = pud_offset(pgd, addr);
26162+ pmd = pmd_offset(pud, addr);
26163+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26164+ }
26165+*/
26166+#ifdef CONFIG_X86_PAE
26167+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
26168+/*
26169+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
26170+ pgd = pgd_offset_k(addr);
26171+ pud = pud_offset(pgd, addr);
26172+ pmd = pmd_offset(pud, addr);
26173+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26174+ }
26175+*/
26176+#endif
26177+
26178+#ifdef CONFIG_MODULES
26179+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
26180+#endif
26181+
26182+#else
26183+ /* PaX: make kernel code/rodata read-only, rest non-executable */
26184+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
26185+ pgd = pgd_offset_k(addr);
26186+ pud = pud_offset(pgd, addr);
26187+ pmd = pmd_offset(pud, addr);
26188+ if (!pmd_present(*pmd))
26189+ continue;
26190+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
26191+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26192+ else
26193+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
26194+ }
26195+
26196+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
26197+ end = addr + KERNEL_IMAGE_SIZE;
26198+ for (; addr < end; addr += PMD_SIZE) {
26199+ pgd = pgd_offset_k(addr);
26200+ pud = pud_offset(pgd, addr);
26201+ pmd = pmd_offset(pud, addr);
26202+ if (!pmd_present(*pmd))
26203+ continue;
26204+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
26205+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
26206+ }
26207+#endif
26208+
26209+ flush_tlb_all();
26210+#endif
26211+
26212 free_init_pages("unused kernel memory",
26213 (unsigned long)(&__init_begin),
26214 (unsigned long)(&__init_end));
26215diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
26216index 11a5800..4bd9977 100644
26217--- a/arch/x86/mm/init_32.c
26218+++ b/arch/x86/mm/init_32.c
26219@@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
26220 }
26221
26222 /*
26223- * Creates a middle page table and puts a pointer to it in the
26224- * given global directory entry. This only returns the gd entry
26225- * in non-PAE compilation mode, since the middle layer is folded.
26226- */
26227-static pmd_t * __init one_md_table_init(pgd_t *pgd)
26228-{
26229- pud_t *pud;
26230- pmd_t *pmd_table;
26231-
26232-#ifdef CONFIG_X86_PAE
26233- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
26234- if (after_bootmem)
26235- pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
26236- else
26237- pmd_table = (pmd_t *)alloc_low_page();
26238- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
26239- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
26240- pud = pud_offset(pgd, 0);
26241- BUG_ON(pmd_table != pmd_offset(pud, 0));
26242-
26243- return pmd_table;
26244- }
26245-#endif
26246- pud = pud_offset(pgd, 0);
26247- pmd_table = pmd_offset(pud, 0);
26248-
26249- return pmd_table;
26250-}
26251-
26252-/*
26253 * Create a page table and place a pointer to it in a middle page
26254 * directory entry:
26255 */
26256@@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
26257 page_table = (pte_t *)alloc_low_page();
26258
26259 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
26260+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26261+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
26262+#else
26263 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
26264+#endif
26265 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
26266 }
26267
26268 return pte_offset_kernel(pmd, 0);
26269 }
26270
26271+static pmd_t * __init one_md_table_init(pgd_t *pgd)
26272+{
26273+ pud_t *pud;
26274+ pmd_t *pmd_table;
26275+
26276+ pud = pud_offset(pgd, 0);
26277+ pmd_table = pmd_offset(pud, 0);
26278+
26279+ return pmd_table;
26280+}
26281+
26282 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
26283 {
26284 int pgd_idx = pgd_index(vaddr);
26285@@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26286 int pgd_idx, pmd_idx;
26287 unsigned long vaddr;
26288 pgd_t *pgd;
26289+ pud_t *pud;
26290 pmd_t *pmd;
26291 pte_t *pte = NULL;
26292
26293@@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26294 pgd = pgd_base + pgd_idx;
26295
26296 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
26297- pmd = one_md_table_init(pgd);
26298- pmd = pmd + pmd_index(vaddr);
26299+ pud = pud_offset(pgd, vaddr);
26300+ pmd = pmd_offset(pud, vaddr);
26301+
26302+#ifdef CONFIG_X86_PAE
26303+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26304+#endif
26305+
26306 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
26307 pmd++, pmd_idx++) {
26308 pte = page_table_kmap_check(one_page_table_init(pmd),
26309@@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
26310 }
26311 }
26312
26313-static inline int is_kernel_text(unsigned long addr)
26314+static inline int is_kernel_text(unsigned long start, unsigned long end)
26315 {
26316- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
26317- return 1;
26318- return 0;
26319+ if ((start > ktla_ktva((unsigned long)_etext) ||
26320+ end <= ktla_ktva((unsigned long)_stext)) &&
26321+ (start > ktla_ktva((unsigned long)_einittext) ||
26322+ end <= ktla_ktva((unsigned long)_sinittext)) &&
26323+
26324+#ifdef CONFIG_ACPI_SLEEP
26325+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
26326+#endif
26327+
26328+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
26329+ return 0;
26330+ return 1;
26331 }
26332
26333 /*
26334@@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
26335 unsigned long last_map_addr = end;
26336 unsigned long start_pfn, end_pfn;
26337 pgd_t *pgd_base = swapper_pg_dir;
26338- int pgd_idx, pmd_idx, pte_ofs;
26339+ unsigned int pgd_idx, pmd_idx, pte_ofs;
26340 unsigned long pfn;
26341 pgd_t *pgd;
26342+ pud_t *pud;
26343 pmd_t *pmd;
26344 pte_t *pte;
26345 unsigned pages_2m, pages_4k;
26346@@ -280,8 +281,13 @@ repeat:
26347 pfn = start_pfn;
26348 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26349 pgd = pgd_base + pgd_idx;
26350- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
26351- pmd = one_md_table_init(pgd);
26352+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
26353+ pud = pud_offset(pgd, 0);
26354+ pmd = pmd_offset(pud, 0);
26355+
26356+#ifdef CONFIG_X86_PAE
26357+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
26358+#endif
26359
26360 if (pfn >= end_pfn)
26361 continue;
26362@@ -293,14 +299,13 @@ repeat:
26363 #endif
26364 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
26365 pmd++, pmd_idx++) {
26366- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
26367+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
26368
26369 /*
26370 * Map with big pages if possible, otherwise
26371 * create normal page tables:
26372 */
26373 if (use_pse) {
26374- unsigned int addr2;
26375 pgprot_t prot = PAGE_KERNEL_LARGE;
26376 /*
26377 * first pass will use the same initial
26378@@ -310,11 +315,7 @@ repeat:
26379 __pgprot(PTE_IDENT_ATTR |
26380 _PAGE_PSE);
26381
26382- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
26383- PAGE_OFFSET + PAGE_SIZE-1;
26384-
26385- if (is_kernel_text(addr) ||
26386- is_kernel_text(addr2))
26387+ if (is_kernel_text(address, address + PMD_SIZE))
26388 prot = PAGE_KERNEL_LARGE_EXEC;
26389
26390 pages_2m++;
26391@@ -331,7 +332,7 @@ repeat:
26392 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
26393 pte += pte_ofs;
26394 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
26395- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
26396+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
26397 pgprot_t prot = PAGE_KERNEL;
26398 /*
26399 * first pass will use the same initial
26400@@ -339,7 +340,7 @@ repeat:
26401 */
26402 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
26403
26404- if (is_kernel_text(addr))
26405+ if (is_kernel_text(address, address + PAGE_SIZE))
26406 prot = PAGE_KERNEL_EXEC;
26407
26408 pages_4k++;
26409@@ -465,7 +466,7 @@ void __init native_pagetable_init(void)
26410
26411 pud = pud_offset(pgd, va);
26412 pmd = pmd_offset(pud, va);
26413- if (!pmd_present(*pmd))
26414+ if (!pmd_present(*pmd) || pmd_huge(*pmd))
26415 break;
26416
26417 pte = pte_offset_kernel(pmd, va);
26418@@ -514,12 +515,10 @@ void __init early_ioremap_page_table_range_init(void)
26419
26420 static void __init pagetable_init(void)
26421 {
26422- pgd_t *pgd_base = swapper_pg_dir;
26423-
26424- permanent_kmaps_init(pgd_base);
26425+ permanent_kmaps_init(swapper_pg_dir);
26426 }
26427
26428-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26429+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
26430 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26431
26432 /* user-defined highmem size */
26433@@ -731,6 +730,12 @@ void __init mem_init(void)
26434
26435 pci_iommu_alloc();
26436
26437+#ifdef CONFIG_PAX_PER_CPU_PGD
26438+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26439+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26440+ KERNEL_PGD_PTRS);
26441+#endif
26442+
26443 #ifdef CONFIG_FLATMEM
26444 BUG_ON(!mem_map);
26445 #endif
26446@@ -757,7 +762,7 @@ void __init mem_init(void)
26447 reservedpages++;
26448
26449 codesize = (unsigned long) &_etext - (unsigned long) &_text;
26450- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
26451+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
26452 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
26453
26454 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
26455@@ -798,10 +803,10 @@ void __init mem_init(void)
26456 ((unsigned long)&__init_end -
26457 (unsigned long)&__init_begin) >> 10,
26458
26459- (unsigned long)&_etext, (unsigned long)&_edata,
26460- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
26461+ (unsigned long)&_sdata, (unsigned long)&_edata,
26462+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
26463
26464- (unsigned long)&_text, (unsigned long)&_etext,
26465+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
26466 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
26467
26468 /*
26469@@ -879,6 +884,7 @@ void set_kernel_text_rw(void)
26470 if (!kernel_set_to_readonly)
26471 return;
26472
26473+ start = ktla_ktva(start);
26474 pr_debug("Set kernel text: %lx - %lx for read write\n",
26475 start, start+size);
26476
26477@@ -893,6 +899,7 @@ void set_kernel_text_ro(void)
26478 if (!kernel_set_to_readonly)
26479 return;
26480
26481+ start = ktla_ktva(start);
26482 pr_debug("Set kernel text: %lx - %lx for read only\n",
26483 start, start+size);
26484
26485@@ -921,6 +928,7 @@ void mark_rodata_ro(void)
26486 unsigned long start = PFN_ALIGN(_text);
26487 unsigned long size = PFN_ALIGN(_etext) - start;
26488
26489+ start = ktla_ktva(start);
26490 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
26491 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
26492 size >> 10);
26493diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
26494index 3baff25..8b37564 100644
26495--- a/arch/x86/mm/init_64.c
26496+++ b/arch/x86/mm/init_64.c
26497@@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
26498 * around without checking the pgd every time.
26499 */
26500
26501-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
26502+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
26503 EXPORT_SYMBOL_GPL(__supported_pte_mask);
26504
26505 int force_personality32;
26506@@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26507
26508 for (address = start; address <= end; address += PGDIR_SIZE) {
26509 const pgd_t *pgd_ref = pgd_offset_k(address);
26510+
26511+#ifdef CONFIG_PAX_PER_CPU_PGD
26512+ unsigned long cpu;
26513+#else
26514 struct page *page;
26515+#endif
26516
26517 if (pgd_none(*pgd_ref))
26518 continue;
26519
26520 spin_lock(&pgd_lock);
26521+
26522+#ifdef CONFIG_PAX_PER_CPU_PGD
26523+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26524+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
26525+#else
26526 list_for_each_entry(page, &pgd_list, lru) {
26527 pgd_t *pgd;
26528 spinlock_t *pgt_lock;
26529@@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26530 /* the pgt_lock only for Xen */
26531 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
26532 spin_lock(pgt_lock);
26533+#endif
26534
26535 if (pgd_none(*pgd))
26536 set_pgd(pgd, *pgd_ref);
26537@@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
26538 BUG_ON(pgd_page_vaddr(*pgd)
26539 != pgd_page_vaddr(*pgd_ref));
26540
26541+#ifndef CONFIG_PAX_PER_CPU_PGD
26542 spin_unlock(pgt_lock);
26543+#endif
26544+
26545 }
26546 spin_unlock(&pgd_lock);
26547 }
26548@@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
26549 {
26550 if (pgd_none(*pgd)) {
26551 pud_t *pud = (pud_t *)spp_getpage();
26552- pgd_populate(&init_mm, pgd, pud);
26553+ pgd_populate_kernel(&init_mm, pgd, pud);
26554 if (pud != pud_offset(pgd, 0))
26555 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
26556 pud, pud_offset(pgd, 0));
26557@@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
26558 {
26559 if (pud_none(*pud)) {
26560 pmd_t *pmd = (pmd_t *) spp_getpage();
26561- pud_populate(&init_mm, pud, pmd);
26562+ pud_populate_kernel(&init_mm, pud, pmd);
26563 if (pmd != pmd_offset(pud, 0))
26564 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
26565 pmd, pmd_offset(pud, 0));
26566@@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
26567 pmd = fill_pmd(pud, vaddr);
26568 pte = fill_pte(pmd, vaddr);
26569
26570+ pax_open_kernel();
26571 set_pte(pte, new_pte);
26572+ pax_close_kernel();
26573
26574 /*
26575 * It's enough to flush this one mapping.
26576@@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
26577 pgd = pgd_offset_k((unsigned long)__va(phys));
26578 if (pgd_none(*pgd)) {
26579 pud = (pud_t *) spp_getpage();
26580- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
26581- _PAGE_USER));
26582+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
26583 }
26584 pud = pud_offset(pgd, (unsigned long)__va(phys));
26585 if (pud_none(*pud)) {
26586 pmd = (pmd_t *) spp_getpage();
26587- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
26588- _PAGE_USER));
26589+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
26590 }
26591 pmd = pmd_offset(pud, phys);
26592 BUG_ON(!pmd_none(*pmd));
26593@@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
26594 if (pfn >= pgt_buf_top)
26595 panic("alloc_low_page: ran out of memory");
26596
26597- adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26598+ adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
26599 clear_page(adr);
26600 *phys = pfn * PAGE_SIZE;
26601 return adr;
26602@@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
26603
26604 phys = __pa(virt);
26605 left = phys & (PAGE_SIZE - 1);
26606- adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26607+ adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
26608 adr = (void *)(((unsigned long)adr) | left);
26609
26610 return adr;
26611@@ -553,7 +567,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
26612 unmap_low_page(pmd);
26613
26614 spin_lock(&init_mm.page_table_lock);
26615- pud_populate(&init_mm, pud, __va(pmd_phys));
26616+ pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
26617 spin_unlock(&init_mm.page_table_lock);
26618 }
26619 __flush_tlb_all();
26620@@ -599,7 +613,7 @@ kernel_physical_mapping_init(unsigned long start,
26621 unmap_low_page(pud);
26622
26623 spin_lock(&init_mm.page_table_lock);
26624- pgd_populate(&init_mm, pgd, __va(pud_phys));
26625+ pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
26626 spin_unlock(&init_mm.page_table_lock);
26627 pgd_changed = true;
26628 }
26629@@ -691,6 +705,12 @@ void __init mem_init(void)
26630
26631 pci_iommu_alloc();
26632
26633+#ifdef CONFIG_PAX_PER_CPU_PGD
26634+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
26635+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26636+ KERNEL_PGD_PTRS);
26637+#endif
26638+
26639 /* clear_bss() already clear the empty_zero_page */
26640
26641 reservedpages = 0;
26642@@ -851,8 +871,8 @@ int kern_addr_valid(unsigned long addr)
26643 static struct vm_area_struct gate_vma = {
26644 .vm_start = VSYSCALL_START,
26645 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
26646- .vm_page_prot = PAGE_READONLY_EXEC,
26647- .vm_flags = VM_READ | VM_EXEC
26648+ .vm_page_prot = PAGE_READONLY,
26649+ .vm_flags = VM_READ
26650 };
26651
26652 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
26653@@ -886,7 +906,7 @@ int in_gate_area_no_mm(unsigned long addr)
26654
26655 const char *arch_vma_name(struct vm_area_struct *vma)
26656 {
26657- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
26658+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
26659 return "[vdso]";
26660 if (vma == &gate_vma)
26661 return "[vsyscall]";
26662diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
26663index 7b179b4..6bd1777 100644
26664--- a/arch/x86/mm/iomap_32.c
26665+++ b/arch/x86/mm/iomap_32.c
26666@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
26667 type = kmap_atomic_idx_push();
26668 idx = type + KM_TYPE_NR * smp_processor_id();
26669 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
26670+
26671+ pax_open_kernel();
26672 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
26673+ pax_close_kernel();
26674+
26675 arch_flush_lazy_mmu_mode();
26676
26677 return (void *)vaddr;
26678diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
26679index 78fe3f1..2f9433c 100644
26680--- a/arch/x86/mm/ioremap.c
26681+++ b/arch/x86/mm/ioremap.c
26682@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
26683 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
26684 int is_ram = page_is_ram(pfn);
26685
26686- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
26687+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
26688 return NULL;
26689 WARN_ON_ONCE(is_ram);
26690 }
26691@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
26692 *
26693 * Caller must ensure there is only one unmapping for the same pointer.
26694 */
26695-void iounmap(volatile void __iomem *addr)
26696+void iounmap(const volatile void __iomem *addr)
26697 {
26698 struct vm_struct *p, *o;
26699
26700@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
26701
26702 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
26703 if (page_is_ram(start >> PAGE_SHIFT))
26704+#ifdef CONFIG_HIGHMEM
26705+ if ((start >> PAGE_SHIFT) < max_low_pfn)
26706+#endif
26707 return __va(phys);
26708
26709 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
26710@@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
26711 early_param("early_ioremap_debug", early_ioremap_debug_setup);
26712
26713 static __initdata int after_paging_init;
26714-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
26715+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
26716
26717 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
26718 {
26719@@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
26720 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
26721
26722 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
26723- memset(bm_pte, 0, sizeof(bm_pte));
26724- pmd_populate_kernel(&init_mm, pmd, bm_pte);
26725+ pmd_populate_user(&init_mm, pmd, bm_pte);
26726
26727 /*
26728 * The boot-ioremap range spans multiple pmds, for which
26729diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
26730index d87dd6d..bf3fa66 100644
26731--- a/arch/x86/mm/kmemcheck/kmemcheck.c
26732+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
26733@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
26734 * memory (e.g. tracked pages)? For now, we need this to avoid
26735 * invoking kmemcheck for PnP BIOS calls.
26736 */
26737- if (regs->flags & X86_VM_MASK)
26738+ if (v8086_mode(regs))
26739 return false;
26740- if (regs->cs != __KERNEL_CS)
26741+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
26742 return false;
26743
26744 pte = kmemcheck_pte_lookup(address);
26745diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
26746index 845df68..1d8d29f 100644
26747--- a/arch/x86/mm/mmap.c
26748+++ b/arch/x86/mm/mmap.c
26749@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
26750 * Leave an at least ~128 MB hole with possible stack randomization.
26751 */
26752 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
26753-#define MAX_GAP (TASK_SIZE/6*5)
26754+#define MAX_GAP (pax_task_size/6*5)
26755
26756 static int mmap_is_legacy(void)
26757 {
26758@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
26759 return rnd << PAGE_SHIFT;
26760 }
26761
26762-static unsigned long mmap_base(void)
26763+static unsigned long mmap_base(struct mm_struct *mm)
26764 {
26765 unsigned long gap = rlimit(RLIMIT_STACK);
26766+ unsigned long pax_task_size = TASK_SIZE;
26767+
26768+#ifdef CONFIG_PAX_SEGMEXEC
26769+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26770+ pax_task_size = SEGMEXEC_TASK_SIZE;
26771+#endif
26772
26773 if (gap < MIN_GAP)
26774 gap = MIN_GAP;
26775 else if (gap > MAX_GAP)
26776 gap = MAX_GAP;
26777
26778- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
26779+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
26780 }
26781
26782 /*
26783 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
26784 * does, but not when emulating X86_32
26785 */
26786-static unsigned long mmap_legacy_base(void)
26787+static unsigned long mmap_legacy_base(struct mm_struct *mm)
26788 {
26789- if (mmap_is_ia32())
26790+ if (mmap_is_ia32()) {
26791+
26792+#ifdef CONFIG_PAX_SEGMEXEC
26793+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
26794+ return SEGMEXEC_TASK_UNMAPPED_BASE;
26795+ else
26796+#endif
26797+
26798 return TASK_UNMAPPED_BASE;
26799- else
26800+ } else
26801 return TASK_UNMAPPED_BASE + mmap_rnd();
26802 }
26803
26804@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
26805 void arch_pick_mmap_layout(struct mm_struct *mm)
26806 {
26807 if (mmap_is_legacy()) {
26808- mm->mmap_base = mmap_legacy_base();
26809+ mm->mmap_base = mmap_legacy_base(mm);
26810+
26811+#ifdef CONFIG_PAX_RANDMMAP
26812+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26813+ mm->mmap_base += mm->delta_mmap;
26814+#endif
26815+
26816 mm->get_unmapped_area = arch_get_unmapped_area;
26817 mm->unmap_area = arch_unmap_area;
26818 } else {
26819- mm->mmap_base = mmap_base();
26820+ mm->mmap_base = mmap_base(mm);
26821+
26822+#ifdef CONFIG_PAX_RANDMMAP
26823+ if (mm->pax_flags & MF_PAX_RANDMMAP)
26824+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
26825+#endif
26826+
26827 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
26828 mm->unmap_area = arch_unmap_area_topdown;
26829 }
26830diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
26831index dc0b727..f612039 100644
26832--- a/arch/x86/mm/mmio-mod.c
26833+++ b/arch/x86/mm/mmio-mod.c
26834@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
26835 break;
26836 default:
26837 {
26838- unsigned char *ip = (unsigned char *)instptr;
26839+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
26840 my_trace->opcode = MMIO_UNKNOWN_OP;
26841 my_trace->width = 0;
26842 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
26843@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
26844 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26845 void __iomem *addr)
26846 {
26847- static atomic_t next_id;
26848+ static atomic_unchecked_t next_id;
26849 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
26850 /* These are page-unaligned. */
26851 struct mmiotrace_map map = {
26852@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
26853 .private = trace
26854 },
26855 .phys = offset,
26856- .id = atomic_inc_return(&next_id)
26857+ .id = atomic_inc_return_unchecked(&next_id)
26858 };
26859 map.map_id = trace->id;
26860
26861@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
26862 ioremap_trace_core(offset, size, addr);
26863 }
26864
26865-static void iounmap_trace_core(volatile void __iomem *addr)
26866+static void iounmap_trace_core(const volatile void __iomem *addr)
26867 {
26868 struct mmiotrace_map map = {
26869 .phys = 0,
26870@@ -328,7 +328,7 @@ not_enabled:
26871 }
26872 }
26873
26874-void mmiotrace_iounmap(volatile void __iomem *addr)
26875+void mmiotrace_iounmap(const volatile void __iomem *addr)
26876 {
26877 might_sleep();
26878 if (is_enabled()) /* recheck and proper locking in *_core() */
26879diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
26880index b008656..773eac2 100644
26881--- a/arch/x86/mm/pageattr-test.c
26882+++ b/arch/x86/mm/pageattr-test.c
26883@@ -36,7 +36,7 @@ enum {
26884
26885 static int pte_testbit(pte_t pte)
26886 {
26887- return pte_flags(pte) & _PAGE_UNUSED1;
26888+ return pte_flags(pte) & _PAGE_CPA_TEST;
26889 }
26890
26891 struct split_state {
26892diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
26893index a718e0d..77419bc 100644
26894--- a/arch/x86/mm/pageattr.c
26895+++ b/arch/x86/mm/pageattr.c
26896@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26897 */
26898 #ifdef CONFIG_PCI_BIOS
26899 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
26900- pgprot_val(forbidden) |= _PAGE_NX;
26901+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26902 #endif
26903
26904 /*
26905@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26906 * Does not cover __inittext since that is gone later on. On
26907 * 64bit we do not enforce !NX on the low mapping
26908 */
26909- if (within(address, (unsigned long)_text, (unsigned long)_etext))
26910- pgprot_val(forbidden) |= _PAGE_NX;
26911+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
26912+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26913
26914+#ifdef CONFIG_DEBUG_RODATA
26915 /*
26916 * The .rodata section needs to be read-only. Using the pfn
26917 * catches all aliases.
26918@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26919 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
26920 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
26921 pgprot_val(forbidden) |= _PAGE_RW;
26922+#endif
26923
26924 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
26925 /*
26926@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
26927 }
26928 #endif
26929
26930+#ifdef CONFIG_PAX_KERNEXEC
26931+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
26932+ pgprot_val(forbidden) |= _PAGE_RW;
26933+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
26934+ }
26935+#endif
26936+
26937 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
26938
26939 return prot;
26940@@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
26941 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
26942 {
26943 /* change init_mm */
26944+ pax_open_kernel();
26945 set_pte_atomic(kpte, pte);
26946+
26947 #ifdef CONFIG_X86_32
26948 if (!SHARED_KERNEL_PMD) {
26949+
26950+#ifdef CONFIG_PAX_PER_CPU_PGD
26951+ unsigned long cpu;
26952+#else
26953 struct page *page;
26954+#endif
26955
26956+#ifdef CONFIG_PAX_PER_CPU_PGD
26957+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
26958+ pgd_t *pgd = get_cpu_pgd(cpu);
26959+#else
26960 list_for_each_entry(page, &pgd_list, lru) {
26961- pgd_t *pgd;
26962+ pgd_t *pgd = (pgd_t *)page_address(page);
26963+#endif
26964+
26965 pud_t *pud;
26966 pmd_t *pmd;
26967
26968- pgd = (pgd_t *)page_address(page) + pgd_index(address);
26969+ pgd += pgd_index(address);
26970 pud = pud_offset(pgd, address);
26971 pmd = pmd_offset(pud, address);
26972 set_pte_atomic((pte_t *)pmd, pte);
26973 }
26974 }
26975 #endif
26976+ pax_close_kernel();
26977 }
26978
26979 static int
26980diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
26981index 0eb572e..92f5c1e 100644
26982--- a/arch/x86/mm/pat.c
26983+++ b/arch/x86/mm/pat.c
26984@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
26985
26986 if (!entry) {
26987 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
26988- current->comm, current->pid, start, end - 1);
26989+ current->comm, task_pid_nr(current), start, end - 1);
26990 return -EINVAL;
26991 }
26992
26993@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
26994
26995 while (cursor < to) {
26996 if (!devmem_is_allowed(pfn)) {
26997- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
26998- current->comm, from, to - 1);
26999+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
27000+ current->comm, from, to - 1, cursor);
27001 return 0;
27002 }
27003 cursor += PAGE_SIZE;
27004@@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
27005 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
27006 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
27007 "for [mem %#010Lx-%#010Lx]\n",
27008- current->comm, current->pid,
27009+ current->comm, task_pid_nr(current),
27010 cattr_name(flags),
27011 base, (unsigned long long)(base + size-1));
27012 return -EINVAL;
27013@@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27014 flags = lookup_memtype(paddr);
27015 if (want_flags != flags) {
27016 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
27017- current->comm, current->pid,
27018+ current->comm, task_pid_nr(current),
27019 cattr_name(want_flags),
27020 (unsigned long long)paddr,
27021 (unsigned long long)(paddr + size - 1),
27022@@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
27023 free_memtype(paddr, paddr + size);
27024 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
27025 " for [mem %#010Lx-%#010Lx], got %s\n",
27026- current->comm, current->pid,
27027+ current->comm, task_pid_nr(current),
27028 cattr_name(want_flags),
27029 (unsigned long long)paddr,
27030 (unsigned long long)(paddr + size - 1),
27031diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
27032index 9f0614d..92ae64a 100644
27033--- a/arch/x86/mm/pf_in.c
27034+++ b/arch/x86/mm/pf_in.c
27035@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
27036 int i;
27037 enum reason_type rv = OTHERS;
27038
27039- p = (unsigned char *)ins_addr;
27040+ p = (unsigned char *)ktla_ktva(ins_addr);
27041 p += skip_prefix(p, &prf);
27042 p += get_opcode(p, &opcode);
27043
27044@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
27045 struct prefix_bits prf;
27046 int i;
27047
27048- p = (unsigned char *)ins_addr;
27049+ p = (unsigned char *)ktla_ktva(ins_addr);
27050 p += skip_prefix(p, &prf);
27051 p += get_opcode(p, &opcode);
27052
27053@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
27054 struct prefix_bits prf;
27055 int i;
27056
27057- p = (unsigned char *)ins_addr;
27058+ p = (unsigned char *)ktla_ktva(ins_addr);
27059 p += skip_prefix(p, &prf);
27060 p += get_opcode(p, &opcode);
27061
27062@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
27063 struct prefix_bits prf;
27064 int i;
27065
27066- p = (unsigned char *)ins_addr;
27067+ p = (unsigned char *)ktla_ktva(ins_addr);
27068 p += skip_prefix(p, &prf);
27069 p += get_opcode(p, &opcode);
27070 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
27071@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
27072 struct prefix_bits prf;
27073 int i;
27074
27075- p = (unsigned char *)ins_addr;
27076+ p = (unsigned char *)ktla_ktva(ins_addr);
27077 p += skip_prefix(p, &prf);
27078 p += get_opcode(p, &opcode);
27079 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
27080diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
27081index 8573b83..4f3ed7e 100644
27082--- a/arch/x86/mm/pgtable.c
27083+++ b/arch/x86/mm/pgtable.c
27084@@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
27085 list_del(&page->lru);
27086 }
27087
27088-#define UNSHARED_PTRS_PER_PGD \
27089- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27090+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27091+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
27092
27093+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
27094+{
27095+ unsigned int count = USER_PGD_PTRS;
27096
27097+ while (count--)
27098+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
27099+}
27100+#endif
27101+
27102+#ifdef CONFIG_PAX_PER_CPU_PGD
27103+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
27104+{
27105+ unsigned int count = USER_PGD_PTRS;
27106+
27107+ while (count--) {
27108+ pgd_t pgd;
27109+
27110+#ifdef CONFIG_X86_64
27111+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
27112+#else
27113+ pgd = *src++;
27114+#endif
27115+
27116+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27117+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
27118+#endif
27119+
27120+ *dst++ = pgd;
27121+ }
27122+
27123+}
27124+#endif
27125+
27126+#ifdef CONFIG_X86_64
27127+#define pxd_t pud_t
27128+#define pyd_t pgd_t
27129+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
27130+#define pxd_free(mm, pud) pud_free((mm), (pud))
27131+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
27132+#define pyd_offset(mm, address) pgd_offset((mm), (address))
27133+#define PYD_SIZE PGDIR_SIZE
27134+#else
27135+#define pxd_t pmd_t
27136+#define pyd_t pud_t
27137+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
27138+#define pxd_free(mm, pud) pmd_free((mm), (pud))
27139+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
27140+#define pyd_offset(mm, address) pud_offset((mm), (address))
27141+#define PYD_SIZE PUD_SIZE
27142+#endif
27143+
27144+#ifdef CONFIG_PAX_PER_CPU_PGD
27145+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
27146+static inline void pgd_dtor(pgd_t *pgd) {}
27147+#else
27148 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
27149 {
27150 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
27151@@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
27152 pgd_list_del(pgd);
27153 spin_unlock(&pgd_lock);
27154 }
27155+#endif
27156
27157 /*
27158 * List of all pgd's needed for non-PAE so it can invalidate entries
27159@@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
27160 * -- wli
27161 */
27162
27163-#ifdef CONFIG_X86_PAE
27164+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
27165 /*
27166 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
27167 * updating the top-level pagetable entries to guarantee the
27168@@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
27169 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
27170 * and initialize the kernel pmds here.
27171 */
27172-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
27173+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
27174
27175 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27176 {
27177@@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
27178 */
27179 flush_tlb_mm(mm);
27180 }
27181+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
27182+#define PREALLOCATED_PXDS USER_PGD_PTRS
27183 #else /* !CONFIG_X86_PAE */
27184
27185 /* No need to prepopulate any pagetable entries in non-PAE modes. */
27186-#define PREALLOCATED_PMDS 0
27187+#define PREALLOCATED_PXDS 0
27188
27189 #endif /* CONFIG_X86_PAE */
27190
27191-static void free_pmds(pmd_t *pmds[])
27192+static void free_pxds(pxd_t *pxds[])
27193 {
27194 int i;
27195
27196- for(i = 0; i < PREALLOCATED_PMDS; i++)
27197- if (pmds[i])
27198- free_page((unsigned long)pmds[i]);
27199+ for(i = 0; i < PREALLOCATED_PXDS; i++)
27200+ if (pxds[i])
27201+ free_page((unsigned long)pxds[i]);
27202 }
27203
27204-static int preallocate_pmds(pmd_t *pmds[])
27205+static int preallocate_pxds(pxd_t *pxds[])
27206 {
27207 int i;
27208 bool failed = false;
27209
27210- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27211- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
27212- if (pmd == NULL)
27213+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27214+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
27215+ if (pxd == NULL)
27216 failed = true;
27217- pmds[i] = pmd;
27218+ pxds[i] = pxd;
27219 }
27220
27221 if (failed) {
27222- free_pmds(pmds);
27223+ free_pxds(pxds);
27224 return -ENOMEM;
27225 }
27226
27227@@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
27228 * preallocate which never got a corresponding vma will need to be
27229 * freed manually.
27230 */
27231-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
27232+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
27233 {
27234 int i;
27235
27236- for(i = 0; i < PREALLOCATED_PMDS; i++) {
27237+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
27238 pgd_t pgd = pgdp[i];
27239
27240 if (pgd_val(pgd) != 0) {
27241- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
27242+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
27243
27244- pgdp[i] = native_make_pgd(0);
27245+ set_pgd(pgdp + i, native_make_pgd(0));
27246
27247- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
27248- pmd_free(mm, pmd);
27249+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
27250+ pxd_free(mm, pxd);
27251 }
27252 }
27253 }
27254
27255-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
27256+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
27257 {
27258- pud_t *pud;
27259+ pyd_t *pyd;
27260 unsigned long addr;
27261 int i;
27262
27263- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
27264+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
27265 return;
27266
27267- pud = pud_offset(pgd, 0);
27268+#ifdef CONFIG_X86_64
27269+ pyd = pyd_offset(mm, 0L);
27270+#else
27271+ pyd = pyd_offset(pgd, 0L);
27272+#endif
27273
27274- for (addr = i = 0; i < PREALLOCATED_PMDS;
27275- i++, pud++, addr += PUD_SIZE) {
27276- pmd_t *pmd = pmds[i];
27277+ for (addr = i = 0; i < PREALLOCATED_PXDS;
27278+ i++, pyd++, addr += PYD_SIZE) {
27279+ pxd_t *pxd = pxds[i];
27280
27281 if (i >= KERNEL_PGD_BOUNDARY)
27282- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27283- sizeof(pmd_t) * PTRS_PER_PMD);
27284+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
27285+ sizeof(pxd_t) * PTRS_PER_PMD);
27286
27287- pud_populate(mm, pud, pmd);
27288+ pyd_populate(mm, pyd, pxd);
27289 }
27290 }
27291
27292 pgd_t *pgd_alloc(struct mm_struct *mm)
27293 {
27294 pgd_t *pgd;
27295- pmd_t *pmds[PREALLOCATED_PMDS];
27296+ pxd_t *pxds[PREALLOCATED_PXDS];
27297
27298 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
27299
27300@@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27301
27302 mm->pgd = pgd;
27303
27304- if (preallocate_pmds(pmds) != 0)
27305+ if (preallocate_pxds(pxds) != 0)
27306 goto out_free_pgd;
27307
27308 if (paravirt_pgd_alloc(mm) != 0)
27309- goto out_free_pmds;
27310+ goto out_free_pxds;
27311
27312 /*
27313 * Make sure that pre-populating the pmds is atomic with
27314@@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
27315 spin_lock(&pgd_lock);
27316
27317 pgd_ctor(mm, pgd);
27318- pgd_prepopulate_pmd(mm, pgd, pmds);
27319+ pgd_prepopulate_pxd(mm, pgd, pxds);
27320
27321 spin_unlock(&pgd_lock);
27322
27323 return pgd;
27324
27325-out_free_pmds:
27326- free_pmds(pmds);
27327+out_free_pxds:
27328+ free_pxds(pxds);
27329 out_free_pgd:
27330 free_page((unsigned long)pgd);
27331 out:
27332@@ -295,7 +356,7 @@ out:
27333
27334 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
27335 {
27336- pgd_mop_up_pmds(mm, pgd);
27337+ pgd_mop_up_pxds(mm, pgd);
27338 pgd_dtor(pgd);
27339 paravirt_pgd_free(mm, pgd);
27340 free_page((unsigned long)pgd);
27341diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
27342index a69bcb8..19068ab 100644
27343--- a/arch/x86/mm/pgtable_32.c
27344+++ b/arch/x86/mm/pgtable_32.c
27345@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
27346 return;
27347 }
27348 pte = pte_offset_kernel(pmd, vaddr);
27349+
27350+ pax_open_kernel();
27351 if (pte_val(pteval))
27352 set_pte_at(&init_mm, vaddr, pte, pteval);
27353 else
27354 pte_clear(&init_mm, vaddr, pte);
27355+ pax_close_kernel();
27356
27357 /*
27358 * It's enough to flush this one mapping.
27359diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
27360index 410531d..0f16030 100644
27361--- a/arch/x86/mm/setup_nx.c
27362+++ b/arch/x86/mm/setup_nx.c
27363@@ -5,8 +5,10 @@
27364 #include <asm/pgtable.h>
27365 #include <asm/proto.h>
27366
27367+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27368 static int disable_nx __cpuinitdata;
27369
27370+#ifndef CONFIG_PAX_PAGEEXEC
27371 /*
27372 * noexec = on|off
27373 *
27374@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
27375 return 0;
27376 }
27377 early_param("noexec", noexec_setup);
27378+#endif
27379+
27380+#endif
27381
27382 void __cpuinit x86_configure_nx(void)
27383 {
27384+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27385 if (cpu_has_nx && !disable_nx)
27386 __supported_pte_mask |= _PAGE_NX;
27387 else
27388+#endif
27389 __supported_pte_mask &= ~_PAGE_NX;
27390 }
27391
27392diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
27393index 60f926c..a710970 100644
27394--- a/arch/x86/mm/tlb.c
27395+++ b/arch/x86/mm/tlb.c
27396@@ -48,7 +48,11 @@ void leave_mm(int cpu)
27397 BUG();
27398 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
27399 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
27400+
27401+#ifndef CONFIG_PAX_PER_CPU_PGD
27402 load_cr3(swapper_pg_dir);
27403+#endif
27404+
27405 }
27406 }
27407 EXPORT_SYMBOL_GPL(leave_mm);
27408diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
27409index 877b9a1..a8ecf42 100644
27410--- a/arch/x86/net/bpf_jit.S
27411+++ b/arch/x86/net/bpf_jit.S
27412@@ -9,6 +9,7 @@
27413 */
27414 #include <linux/linkage.h>
27415 #include <asm/dwarf2.h>
27416+#include <asm/alternative-asm.h>
27417
27418 /*
27419 * Calling convention :
27420@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
27421 jle bpf_slow_path_word
27422 mov (SKBDATA,%rsi),%eax
27423 bswap %eax /* ntohl() */
27424+ pax_force_retaddr
27425 ret
27426
27427 sk_load_half:
27428@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
27429 jle bpf_slow_path_half
27430 movzwl (SKBDATA,%rsi),%eax
27431 rol $8,%ax # ntohs()
27432+ pax_force_retaddr
27433 ret
27434
27435 sk_load_byte:
27436@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
27437 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
27438 jle bpf_slow_path_byte
27439 movzbl (SKBDATA,%rsi),%eax
27440+ pax_force_retaddr
27441 ret
27442
27443 /**
27444@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
27445 movzbl (SKBDATA,%rsi),%ebx
27446 and $15,%bl
27447 shl $2,%bl
27448+ pax_force_retaddr
27449 ret
27450
27451 /* rsi contains offset and can be scratched */
27452@@ -109,6 +114,7 @@ bpf_slow_path_word:
27453 js bpf_error
27454 mov -12(%rbp),%eax
27455 bswap %eax
27456+ pax_force_retaddr
27457 ret
27458
27459 bpf_slow_path_half:
27460@@ -117,12 +123,14 @@ bpf_slow_path_half:
27461 mov -12(%rbp),%ax
27462 rol $8,%ax
27463 movzwl %ax,%eax
27464+ pax_force_retaddr
27465 ret
27466
27467 bpf_slow_path_byte:
27468 bpf_slow_path_common(1)
27469 js bpf_error
27470 movzbl -12(%rbp),%eax
27471+ pax_force_retaddr
27472 ret
27473
27474 bpf_slow_path_byte_msh:
27475@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
27476 and $15,%al
27477 shl $2,%al
27478 xchg %eax,%ebx
27479+ pax_force_retaddr
27480 ret
27481
27482 #define sk_negative_common(SIZE) \
27483@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
27484 sk_negative_common(4)
27485 mov (%rax), %eax
27486 bswap %eax
27487+ pax_force_retaddr
27488 ret
27489
27490 bpf_slow_path_half_neg:
27491@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
27492 mov (%rax),%ax
27493 rol $8,%ax
27494 movzwl %ax,%eax
27495+ pax_force_retaddr
27496 ret
27497
27498 bpf_slow_path_byte_neg:
27499@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
27500 .globl sk_load_byte_negative_offset
27501 sk_negative_common(1)
27502 movzbl (%rax), %eax
27503+ pax_force_retaddr
27504 ret
27505
27506 bpf_slow_path_byte_msh_neg:
27507@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
27508 and $15,%al
27509 shl $2,%al
27510 xchg %eax,%ebx
27511+ pax_force_retaddr
27512 ret
27513
27514 bpf_error:
27515@@ -197,4 +210,5 @@ bpf_error:
27516 xor %eax,%eax
27517 mov -8(%rbp),%rbx
27518 leaveq
27519+ pax_force_retaddr
27520 ret
27521diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
27522index 520d2bd..b895ef4 100644
27523--- a/arch/x86/net/bpf_jit_comp.c
27524+++ b/arch/x86/net/bpf_jit_comp.c
27525@@ -11,6 +11,7 @@
27526 #include <asm/cacheflush.h>
27527 #include <linux/netdevice.h>
27528 #include <linux/filter.h>
27529+#include <linux/random.h>
27530
27531 /*
27532 * Conventions :
27533@@ -48,13 +49,87 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
27534 return ptr + len;
27535 }
27536
27537+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27538+#define MAX_INSTR_CODE_SIZE 96
27539+#else
27540+#define MAX_INSTR_CODE_SIZE 64
27541+#endif
27542+
27543 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
27544
27545 #define EMIT1(b1) EMIT(b1, 1)
27546 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
27547 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
27548 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
27549+
27550+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27551+/* original constant will appear in ecx */
27552+#define DILUTE_CONST_SEQUENCE(_off, _key) \
27553+do { \
27554+ /* mov ecx, randkey */ \
27555+ EMIT1(0xb9); \
27556+ EMIT(_key, 4); \
27557+ /* xor ecx, randkey ^ off */ \
27558+ EMIT2(0x81, 0xf1); \
27559+ EMIT((_key) ^ (_off), 4); \
27560+} while (0)
27561+
27562+#define EMIT1_off32(b1, _off) \
27563+do { \
27564+ switch (b1) { \
27565+ case 0x05: /* add eax, imm32 */ \
27566+ case 0x2d: /* sub eax, imm32 */ \
27567+ case 0x25: /* and eax, imm32 */ \
27568+ case 0x0d: /* or eax, imm32 */ \
27569+ case 0xb8: /* mov eax, imm32 */ \
27570+ case 0x3d: /* cmp eax, imm32 */ \
27571+ case 0xa9: /* test eax, imm32 */ \
27572+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27573+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
27574+ break; \
27575+ case 0xbb: /* mov ebx, imm32 */ \
27576+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27577+ /* mov ebx, ecx */ \
27578+ EMIT2(0x89, 0xcb); \
27579+ break; \
27580+ case 0xbe: /* mov esi, imm32 */ \
27581+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27582+ /* mov esi, ecx */ \
27583+ EMIT2(0x89, 0xce); \
27584+ break; \
27585+ case 0xe9: /* jmp rel imm32 */ \
27586+ EMIT1(b1); \
27587+ EMIT(_off, 4); \
27588+ /* prevent fall-through, we're not called if off = 0 */ \
27589+ EMIT(0xcccccccc, 4); \
27590+ EMIT(0xcccccccc, 4); \
27591+ break; \
27592+ default: \
27593+ EMIT1(b1); \
27594+ EMIT(_off, 4); \
27595+ } \
27596+} while (0)
27597+
27598+#define EMIT2_off32(b1, b2, _off) \
27599+do { \
27600+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
27601+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
27602+ EMIT(randkey, 4); \
27603+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
27604+ EMIT((_off) - randkey, 4); \
27605+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
27606+ DILUTE_CONST_SEQUENCE(_off, randkey); \
27607+ /* imul eax, ecx */ \
27608+ EMIT3(0x0f, 0xaf, 0xc1); \
27609+ } else { \
27610+ EMIT2(b1, b2); \
27611+ EMIT(_off, 4); \
27612+ } \
27613+} while (0)
27614+#else
27615 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
27616+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
27617+#endif
27618
27619 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
27620 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
27621@@ -89,6 +164,24 @@ do { \
27622 #define X86_JBE 0x76
27623 #define X86_JA 0x77
27624
27625+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27626+#define APPEND_FLOW_VERIFY() \
27627+do { \
27628+ /* mov ecx, randkey */ \
27629+ EMIT1(0xb9); \
27630+ EMIT(randkey, 4); \
27631+ /* cmp ecx, randkey */ \
27632+ EMIT2(0x81, 0xf9); \
27633+ EMIT(randkey, 4); \
27634+ /* jz after 8 int 3s */ \
27635+ EMIT2(0x74, 0x08); \
27636+ EMIT(0xcccccccc, 4); \
27637+ EMIT(0xcccccccc, 4); \
27638+} while (0)
27639+#else
27640+#define APPEND_FLOW_VERIFY() do { } while (0)
27641+#endif
27642+
27643 #define EMIT_COND_JMP(op, offset) \
27644 do { \
27645 if (is_near(offset)) \
27646@@ -96,6 +189,7 @@ do { \
27647 else { \
27648 EMIT2(0x0f, op + 0x10); \
27649 EMIT(offset, 4); /* jxx .+off32 */ \
27650+ APPEND_FLOW_VERIFY(); \
27651 } \
27652 } while (0)
27653
27654@@ -120,12 +214,17 @@ static inline void bpf_flush_icache(void *start, void *end)
27655 set_fs(old_fs);
27656 }
27657
27658+struct bpf_jit_work {
27659+ struct work_struct work;
27660+ void *image;
27661+};
27662+
27663 #define CHOOSE_LOAD_FUNC(K, func) \
27664 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
27665
27666 void bpf_jit_compile(struct sk_filter *fp)
27667 {
27668- u8 temp[64];
27669+ u8 temp[MAX_INSTR_CODE_SIZE];
27670 u8 *prog;
27671 unsigned int proglen, oldproglen = 0;
27672 int ilen, i;
27673@@ -138,6 +237,9 @@ void bpf_jit_compile(struct sk_filter *fp)
27674 unsigned int *addrs;
27675 const struct sock_filter *filter = fp->insns;
27676 int flen = fp->len;
27677+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27678+ unsigned int randkey;
27679+#endif
27680
27681 if (!bpf_jit_enable)
27682 return;
27683@@ -146,11 +248,19 @@ void bpf_jit_compile(struct sk_filter *fp)
27684 if (addrs == NULL)
27685 return;
27686
27687+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
27688+ if (!fp->work)
27689+ goto out;
27690+
27691+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27692+ randkey = get_random_int();
27693+#endif
27694+
27695 /* Before first pass, make a rough estimation of addrs[]
27696- * each bpf instruction is translated to less than 64 bytes
27697+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
27698 */
27699 for (proglen = 0, i = 0; i < flen; i++) {
27700- proglen += 64;
27701+ proglen += MAX_INSTR_CODE_SIZE;
27702 addrs[i] = proglen;
27703 }
27704 cleanup_addr = proglen; /* epilogue address */
27705@@ -258,10 +368,8 @@ void bpf_jit_compile(struct sk_filter *fp)
27706 case BPF_S_ALU_MUL_K: /* A *= K */
27707 if (is_imm8(K))
27708 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
27709- else {
27710- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
27711- EMIT(K, 4);
27712- }
27713+ else
27714+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
27715 break;
27716 case BPF_S_ALU_DIV_X: /* A /= X; */
27717 seen |= SEEN_XREG;
27718@@ -301,13 +409,23 @@ void bpf_jit_compile(struct sk_filter *fp)
27719 break;
27720 case BPF_S_ALU_MOD_K: /* A %= K; */
27721 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
27722+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27723+ DILUTE_CONST_SEQUENCE(K, randkey);
27724+#else
27725 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
27726+#endif
27727 EMIT2(0xf7, 0xf1); /* div %ecx */
27728 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
27729 break;
27730 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
27731+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
27732+ DILUTE_CONST_SEQUENCE(K, randkey);
27733+ // imul rax, rcx
27734+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
27735+#else
27736 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
27737 EMIT(K, 4);
27738+#endif
27739 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
27740 break;
27741 case BPF_S_ALU_AND_X:
27742@@ -543,8 +661,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
27743 if (is_imm8(K)) {
27744 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
27745 } else {
27746- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
27747- EMIT(K, 4);
27748+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
27749 }
27750 } else {
27751 EMIT2(0x89,0xde); /* mov %ebx,%esi */
27752@@ -627,17 +744,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27753 break;
27754 default:
27755 /* hmm, too complex filter, give up with jit compiler */
27756- goto out;
27757+ goto error;
27758 }
27759 ilen = prog - temp;
27760 if (image) {
27761 if (unlikely(proglen + ilen > oldproglen)) {
27762 pr_err("bpb_jit_compile fatal error\n");
27763- kfree(addrs);
27764- module_free(NULL, image);
27765- return;
27766+ module_free_exec(NULL, image);
27767+ goto error;
27768 }
27769+ pax_open_kernel();
27770 memcpy(image + proglen, temp, ilen);
27771+ pax_close_kernel();
27772 }
27773 proglen += ilen;
27774 addrs[i] = proglen;
27775@@ -658,11 +776,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27776 break;
27777 }
27778 if (proglen == oldproglen) {
27779- image = module_alloc(max_t(unsigned int,
27780- proglen,
27781- sizeof(struct work_struct)));
27782+ image = module_alloc_exec(proglen);
27783 if (!image)
27784- goto out;
27785+ goto error;
27786 }
27787 oldproglen = proglen;
27788 }
27789@@ -678,7 +794,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
27790 bpf_flush_icache(image, image + proglen);
27791
27792 fp->bpf_func = (void *)image;
27793- }
27794+ } else
27795+error:
27796+ kfree(fp->work);
27797+
27798 out:
27799 kfree(addrs);
27800 return;
27801@@ -686,18 +805,20 @@ out:
27802
27803 static void jit_free_defer(struct work_struct *arg)
27804 {
27805- module_free(NULL, arg);
27806+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
27807+ kfree(arg);
27808 }
27809
27810 /* run from softirq, we must use a work_struct to call
27811- * module_free() from process context
27812+ * module_free_exec() from process context
27813 */
27814 void bpf_jit_free(struct sk_filter *fp)
27815 {
27816 if (fp->bpf_func != sk_run_filter) {
27817- struct work_struct *work = (struct work_struct *)fp->bpf_func;
27818+ struct work_struct *work = &fp->work->work;
27819
27820 INIT_WORK(work, jit_free_defer);
27821+ fp->work->image = fp->bpf_func;
27822 schedule_work(work);
27823 }
27824 }
27825diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
27826index d6aa6e8..266395a 100644
27827--- a/arch/x86/oprofile/backtrace.c
27828+++ b/arch/x86/oprofile/backtrace.c
27829@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
27830 struct stack_frame_ia32 *fp;
27831 unsigned long bytes;
27832
27833- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27834+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27835 if (bytes != sizeof(bufhead))
27836 return NULL;
27837
27838- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
27839+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
27840
27841 oprofile_add_trace(bufhead[0].return_address);
27842
27843@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
27844 struct stack_frame bufhead[2];
27845 unsigned long bytes;
27846
27847- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
27848+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
27849 if (bytes != sizeof(bufhead))
27850 return NULL;
27851
27852@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
27853 {
27854 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
27855
27856- if (!user_mode_vm(regs)) {
27857+ if (!user_mode(regs)) {
27858 unsigned long stack = kernel_stack_pointer(regs);
27859 if (depth)
27860 dump_trace(NULL, regs, (unsigned long *)stack, 0,
27861diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c
27862index 192397c..5ba6f9e 100644
27863--- a/arch/x86/pci/acpi.c
27864+++ b/arch/x86/pci/acpi.c
27865@@ -568,7 +568,7 @@ int __init pci_acpi_init(void)
27866 acpi_irq_penalty_init();
27867 pcibios_enable_irq = acpi_pci_irq_enable;
27868 pcibios_disable_irq = acpi_pci_irq_disable;
27869- x86_init.pci.init_irq = x86_init_noop;
27870+ *(void **)&x86_init.pci.init_irq = x86_init_noop;
27871
27872 if (pci_routeirq) {
27873 /*
27874diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
27875index e14a2ff..3fd6b58 100644
27876--- a/arch/x86/pci/mrst.c
27877+++ b/arch/x86/pci/mrst.c
27878@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
27879 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
27880 pci_mmcfg_late_init();
27881 pcibios_enable_irq = mrst_pci_irq_enable;
27882- pci_root_ops = pci_mrst_ops;
27883+ pax_open_kernel();
27884+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
27885+ pax_close_kernel();
27886 pci_soc_mode = 1;
27887 /* Continue with standard init */
27888 return 1;
27889diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
27890index da8fe05..7ee6704 100644
27891--- a/arch/x86/pci/pcbios.c
27892+++ b/arch/x86/pci/pcbios.c
27893@@ -79,50 +79,93 @@ union bios32 {
27894 static struct {
27895 unsigned long address;
27896 unsigned short segment;
27897-} bios32_indirect = { 0, __KERNEL_CS };
27898+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
27899
27900 /*
27901 * Returns the entry point for the given service, NULL on error
27902 */
27903
27904-static unsigned long bios32_service(unsigned long service)
27905+static unsigned long __devinit bios32_service(unsigned long service)
27906 {
27907 unsigned char return_code; /* %al */
27908 unsigned long address; /* %ebx */
27909 unsigned long length; /* %ecx */
27910 unsigned long entry; /* %edx */
27911 unsigned long flags;
27912+ struct desc_struct d, *gdt;
27913
27914 local_irq_save(flags);
27915- __asm__("lcall *(%%edi); cld"
27916+
27917+ gdt = get_cpu_gdt_table(smp_processor_id());
27918+
27919+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
27920+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27921+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
27922+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27923+
27924+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
27925 : "=a" (return_code),
27926 "=b" (address),
27927 "=c" (length),
27928 "=d" (entry)
27929 : "0" (service),
27930 "1" (0),
27931- "D" (&bios32_indirect));
27932+ "D" (&bios32_indirect),
27933+ "r"(__PCIBIOS_DS)
27934+ : "memory");
27935+
27936+ pax_open_kernel();
27937+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
27938+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
27939+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
27940+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
27941+ pax_close_kernel();
27942+
27943 local_irq_restore(flags);
27944
27945 switch (return_code) {
27946- case 0:
27947- return address + entry;
27948- case 0x80: /* Not present */
27949- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27950- return 0;
27951- default: /* Shouldn't happen */
27952- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27953- service, return_code);
27954+ case 0: {
27955+ int cpu;
27956+ unsigned char flags;
27957+
27958+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
27959+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
27960+ printk(KERN_WARNING "bios32_service: not valid\n");
27961 return 0;
27962+ }
27963+ address = address + PAGE_OFFSET;
27964+ length += 16UL; /* some BIOSs underreport this... */
27965+ flags = 4;
27966+ if (length >= 64*1024*1024) {
27967+ length >>= PAGE_SHIFT;
27968+ flags |= 8;
27969+ }
27970+
27971+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
27972+ gdt = get_cpu_gdt_table(cpu);
27973+ pack_descriptor(&d, address, length, 0x9b, flags);
27974+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
27975+ pack_descriptor(&d, address, length, 0x93, flags);
27976+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
27977+ }
27978+ return entry;
27979+ }
27980+ case 0x80: /* Not present */
27981+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
27982+ return 0;
27983+ default: /* Shouldn't happen */
27984+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
27985+ service, return_code);
27986+ return 0;
27987 }
27988 }
27989
27990 static struct {
27991 unsigned long address;
27992 unsigned short segment;
27993-} pci_indirect = { 0, __KERNEL_CS };
27994+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
27995
27996-static int pci_bios_present;
27997+static int pci_bios_present __read_only;
27998
27999 static int __devinit check_pcibios(void)
28000 {
28001@@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
28002 unsigned long flags, pcibios_entry;
28003
28004 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
28005- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
28006+ pci_indirect.address = pcibios_entry;
28007
28008 local_irq_save(flags);
28009- __asm__(
28010- "lcall *(%%edi); cld\n\t"
28011+ __asm__("movw %w6, %%ds\n\t"
28012+ "lcall *%%ss:(%%edi); cld\n\t"
28013+ "push %%ss\n\t"
28014+ "pop %%ds\n\t"
28015 "jc 1f\n\t"
28016 "xor %%ah, %%ah\n"
28017 "1:"
28018@@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
28019 "=b" (ebx),
28020 "=c" (ecx)
28021 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
28022- "D" (&pci_indirect)
28023+ "D" (&pci_indirect),
28024+ "r" (__PCIBIOS_DS)
28025 : "memory");
28026 local_irq_restore(flags);
28027
28028@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28029
28030 switch (len) {
28031 case 1:
28032- __asm__("lcall *(%%esi); cld\n\t"
28033+ __asm__("movw %w6, %%ds\n\t"
28034+ "lcall *%%ss:(%%esi); cld\n\t"
28035+ "push %%ss\n\t"
28036+ "pop %%ds\n\t"
28037 "jc 1f\n\t"
28038 "xor %%ah, %%ah\n"
28039 "1:"
28040@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28041 : "1" (PCIBIOS_READ_CONFIG_BYTE),
28042 "b" (bx),
28043 "D" ((long)reg),
28044- "S" (&pci_indirect));
28045+ "S" (&pci_indirect),
28046+ "r" (__PCIBIOS_DS));
28047 /*
28048 * Zero-extend the result beyond 8 bits, do not trust the
28049 * BIOS having done it:
28050@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28051 *value &= 0xff;
28052 break;
28053 case 2:
28054- __asm__("lcall *(%%esi); cld\n\t"
28055+ __asm__("movw %w6, %%ds\n\t"
28056+ "lcall *%%ss:(%%esi); cld\n\t"
28057+ "push %%ss\n\t"
28058+ "pop %%ds\n\t"
28059 "jc 1f\n\t"
28060 "xor %%ah, %%ah\n"
28061 "1:"
28062@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28063 : "1" (PCIBIOS_READ_CONFIG_WORD),
28064 "b" (bx),
28065 "D" ((long)reg),
28066- "S" (&pci_indirect));
28067+ "S" (&pci_indirect),
28068+ "r" (__PCIBIOS_DS));
28069 /*
28070 * Zero-extend the result beyond 16 bits, do not trust the
28071 * BIOS having done it:
28072@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28073 *value &= 0xffff;
28074 break;
28075 case 4:
28076- __asm__("lcall *(%%esi); cld\n\t"
28077+ __asm__("movw %w6, %%ds\n\t"
28078+ "lcall *%%ss:(%%esi); cld\n\t"
28079+ "push %%ss\n\t"
28080+ "pop %%ds\n\t"
28081 "jc 1f\n\t"
28082 "xor %%ah, %%ah\n"
28083 "1:"
28084@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
28085 : "1" (PCIBIOS_READ_CONFIG_DWORD),
28086 "b" (bx),
28087 "D" ((long)reg),
28088- "S" (&pci_indirect));
28089+ "S" (&pci_indirect),
28090+ "r" (__PCIBIOS_DS));
28091 break;
28092 }
28093
28094@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28095
28096 switch (len) {
28097 case 1:
28098- __asm__("lcall *(%%esi); cld\n\t"
28099+ __asm__("movw %w6, %%ds\n\t"
28100+ "lcall *%%ss:(%%esi); cld\n\t"
28101+ "push %%ss\n\t"
28102+ "pop %%ds\n\t"
28103 "jc 1f\n\t"
28104 "xor %%ah, %%ah\n"
28105 "1:"
28106@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28107 "c" (value),
28108 "b" (bx),
28109 "D" ((long)reg),
28110- "S" (&pci_indirect));
28111+ "S" (&pci_indirect),
28112+ "r" (__PCIBIOS_DS));
28113 break;
28114 case 2:
28115- __asm__("lcall *(%%esi); cld\n\t"
28116+ __asm__("movw %w6, %%ds\n\t"
28117+ "lcall *%%ss:(%%esi); cld\n\t"
28118+ "push %%ss\n\t"
28119+ "pop %%ds\n\t"
28120 "jc 1f\n\t"
28121 "xor %%ah, %%ah\n"
28122 "1:"
28123@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28124 "c" (value),
28125 "b" (bx),
28126 "D" ((long)reg),
28127- "S" (&pci_indirect));
28128+ "S" (&pci_indirect),
28129+ "r" (__PCIBIOS_DS));
28130 break;
28131 case 4:
28132- __asm__("lcall *(%%esi); cld\n\t"
28133+ __asm__("movw %w6, %%ds\n\t"
28134+ "lcall *%%ss:(%%esi); cld\n\t"
28135+ "push %%ss\n\t"
28136+ "pop %%ds\n\t"
28137 "jc 1f\n\t"
28138 "xor %%ah, %%ah\n"
28139 "1:"
28140@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
28141 "c" (value),
28142 "b" (bx),
28143 "D" ((long)reg),
28144- "S" (&pci_indirect));
28145+ "S" (&pci_indirect),
28146+ "r" (__PCIBIOS_DS));
28147 break;
28148 }
28149
28150@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28151
28152 DBG("PCI: Fetching IRQ routing table... ");
28153 __asm__("push %%es\n\t"
28154+ "movw %w8, %%ds\n\t"
28155 "push %%ds\n\t"
28156 "pop %%es\n\t"
28157- "lcall *(%%esi); cld\n\t"
28158+ "lcall *%%ss:(%%esi); cld\n\t"
28159 "pop %%es\n\t"
28160+ "push %%ss\n\t"
28161+ "pop %%ds\n"
28162 "jc 1f\n\t"
28163 "xor %%ah, %%ah\n"
28164 "1:"
28165@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
28166 "1" (0),
28167 "D" ((long) &opt),
28168 "S" (&pci_indirect),
28169- "m" (opt)
28170+ "m" (opt),
28171+ "r" (__PCIBIOS_DS)
28172 : "memory");
28173 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
28174 if (ret & 0xff00)
28175@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28176 {
28177 int ret;
28178
28179- __asm__("lcall *(%%esi); cld\n\t"
28180+ __asm__("movw %w5, %%ds\n\t"
28181+ "lcall *%%ss:(%%esi); cld\n\t"
28182+ "push %%ss\n\t"
28183+ "pop %%ds\n"
28184 "jc 1f\n\t"
28185 "xor %%ah, %%ah\n"
28186 "1:"
28187@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
28188 : "0" (PCIBIOS_SET_PCI_HW_INT),
28189 "b" ((dev->bus->number << 8) | dev->devfn),
28190 "c" ((irq << 8) | (pin + 10)),
28191- "S" (&pci_indirect));
28192+ "S" (&pci_indirect),
28193+ "r" (__PCIBIOS_DS));
28194 return !(ret & 0xff00);
28195 }
28196 EXPORT_SYMBOL(pcibios_set_irq_routing);
28197diff --git a/arch/x86/pci/xen.c b/arch/x86/pci/xen.c
28198index 56ab749..3cb792a 100644
28199--- a/arch/x86/pci/xen.c
28200+++ b/arch/x86/pci/xen.c
28201@@ -395,9 +395,9 @@ int __init pci_xen_init(void)
28202 #endif
28203
28204 #ifdef CONFIG_PCI_MSI
28205- x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28206- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28207- x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28208+ *(void **)&x86_msi.setup_msi_irqs = xen_setup_msi_irqs;
28209+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28210+ *(void **)&x86_msi.teardown_msi_irqs = xen_teardown_msi_irqs;
28211 #endif
28212 return 0;
28213 }
28214@@ -416,8 +416,8 @@ int __init pci_xen_hvm_init(void)
28215 #endif
28216
28217 #ifdef CONFIG_PCI_MSI
28218- x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28219- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28220+ *(void **)&x86_msi.setup_msi_irqs = xen_hvm_setup_msi_irqs;
28221+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28222 #endif
28223 return 0;
28224 }
28225@@ -474,9 +474,9 @@ int __init pci_xen_initial_domain(void)
28226 int irq;
28227
28228 #ifdef CONFIG_PCI_MSI
28229- x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28230- x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28231- x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28232+ *(void **)&x86_msi.setup_msi_irqs = xen_initdom_setup_msi_irqs;
28233+ *(void **)&x86_msi.teardown_msi_irq = xen_teardown_msi_irq;
28234+ *(void **)&x86_msi.restore_msi_irqs = xen_initdom_restore_msi_irqs;
28235 #endif
28236 xen_setup_acpi_sci();
28237 __acpi_register_gsi = acpi_register_gsi_xen;
28238diff --git a/arch/x86/platform/efi/efi.c b/arch/x86/platform/efi/efi.c
28239index ad44391..acef4b5 100644
28240--- a/arch/x86/platform/efi/efi.c
28241+++ b/arch/x86/platform/efi/efi.c
28242@@ -738,8 +738,8 @@ void __init efi_init(void)
28243 }
28244 #ifdef CONFIG_X86_32
28245 if (efi_is_native()) {
28246- x86_platform.get_wallclock = efi_get_time;
28247- x86_platform.set_wallclock = efi_set_rtc_mmss;
28248+ *(void **)&x86_platform.get_wallclock = efi_get_time;
28249+ *(void **)&x86_platform.set_wallclock = efi_set_rtc_mmss;
28250 }
28251 #endif
28252
28253diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
28254index 40e4469..1ab536e 100644
28255--- a/arch/x86/platform/efi/efi_32.c
28256+++ b/arch/x86/platform/efi/efi_32.c
28257@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
28258 {
28259 struct desc_ptr gdt_descr;
28260
28261+#ifdef CONFIG_PAX_KERNEXEC
28262+ struct desc_struct d;
28263+#endif
28264+
28265 local_irq_save(efi_rt_eflags);
28266
28267 load_cr3(initial_page_table);
28268 __flush_tlb_all();
28269
28270+#ifdef CONFIG_PAX_KERNEXEC
28271+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
28272+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28273+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
28274+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28275+#endif
28276+
28277 gdt_descr.address = __pa(get_cpu_gdt_table(0));
28278 gdt_descr.size = GDT_SIZE - 1;
28279 load_gdt(&gdt_descr);
28280@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
28281 {
28282 struct desc_ptr gdt_descr;
28283
28284+#ifdef CONFIG_PAX_KERNEXEC
28285+ struct desc_struct d;
28286+
28287+ memset(&d, 0, sizeof d);
28288+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
28289+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
28290+#endif
28291+
28292 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
28293 gdt_descr.size = GDT_SIZE - 1;
28294 load_gdt(&gdt_descr);
28295diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
28296index fbe66e6..eae5e38 100644
28297--- a/arch/x86/platform/efi/efi_stub_32.S
28298+++ b/arch/x86/platform/efi/efi_stub_32.S
28299@@ -6,7 +6,9 @@
28300 */
28301
28302 #include <linux/linkage.h>
28303+#include <linux/init.h>
28304 #include <asm/page_types.h>
28305+#include <asm/segment.h>
28306
28307 /*
28308 * efi_call_phys(void *, ...) is a function with variable parameters.
28309@@ -20,7 +22,7 @@
28310 * service functions will comply with gcc calling convention, too.
28311 */
28312
28313-.text
28314+__INIT
28315 ENTRY(efi_call_phys)
28316 /*
28317 * 0. The function can only be called in Linux kernel. So CS has been
28318@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
28319 * The mapping of lower virtual memory has been created in prelog and
28320 * epilog.
28321 */
28322- movl $1f, %edx
28323- subl $__PAGE_OFFSET, %edx
28324- jmp *%edx
28325+#ifdef CONFIG_PAX_KERNEXEC
28326+ movl $(__KERNEXEC_EFI_DS), %edx
28327+ mov %edx, %ds
28328+ mov %edx, %es
28329+ mov %edx, %ss
28330+ addl $2f,(1f)
28331+ ljmp *(1f)
28332+
28333+__INITDATA
28334+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
28335+.previous
28336+
28337+2:
28338+ subl $2b,(1b)
28339+#else
28340+ jmp 1f-__PAGE_OFFSET
28341 1:
28342+#endif
28343
28344 /*
28345 * 2. Now on the top of stack is the return
28346@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
28347 * parameter 2, ..., param n. To make things easy, we save the return
28348 * address of efi_call_phys in a global variable.
28349 */
28350- popl %edx
28351- movl %edx, saved_return_addr
28352- /* get the function pointer into ECX*/
28353- popl %ecx
28354- movl %ecx, efi_rt_function_ptr
28355- movl $2f, %edx
28356- subl $__PAGE_OFFSET, %edx
28357- pushl %edx
28358+ popl (saved_return_addr)
28359+ popl (efi_rt_function_ptr)
28360
28361 /*
28362 * 3. Clear PG bit in %CR0.
28363@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
28364 /*
28365 * 5. Call the physical function.
28366 */
28367- jmp *%ecx
28368+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
28369
28370-2:
28371 /*
28372 * 6. After EFI runtime service returns, control will return to
28373 * following instruction. We'd better readjust stack pointer first.
28374@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
28375 movl %cr0, %edx
28376 orl $0x80000000, %edx
28377 movl %edx, %cr0
28378- jmp 1f
28379-1:
28380+
28381 /*
28382 * 8. Now restore the virtual mode from flat mode by
28383 * adding EIP with PAGE_OFFSET.
28384 */
28385- movl $1f, %edx
28386- jmp *%edx
28387+#ifdef CONFIG_PAX_KERNEXEC
28388+ movl $(__KERNEL_DS), %edx
28389+ mov %edx, %ds
28390+ mov %edx, %es
28391+ mov %edx, %ss
28392+ ljmp $(__KERNEL_CS),$1f
28393+#else
28394+ jmp 1f+__PAGE_OFFSET
28395+#endif
28396 1:
28397
28398 /*
28399 * 9. Balance the stack. And because EAX contain the return value,
28400 * we'd better not clobber it.
28401 */
28402- leal efi_rt_function_ptr, %edx
28403- movl (%edx), %ecx
28404- pushl %ecx
28405+ pushl (efi_rt_function_ptr)
28406
28407 /*
28408- * 10. Push the saved return address onto the stack and return.
28409+ * 10. Return to the saved return address.
28410 */
28411- leal saved_return_addr, %edx
28412- movl (%edx), %ecx
28413- pushl %ecx
28414- ret
28415+ jmpl *(saved_return_addr)
28416 ENDPROC(efi_call_phys)
28417 .previous
28418
28419-.data
28420+__INITDATA
28421 saved_return_addr:
28422 .long 0
28423 efi_rt_function_ptr:
28424diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
28425index 4c07cca..2c8427d 100644
28426--- a/arch/x86/platform/efi/efi_stub_64.S
28427+++ b/arch/x86/platform/efi/efi_stub_64.S
28428@@ -7,6 +7,7 @@
28429 */
28430
28431 #include <linux/linkage.h>
28432+#include <asm/alternative-asm.h>
28433
28434 #define SAVE_XMM \
28435 mov %rsp, %rax; \
28436@@ -40,6 +41,7 @@ ENTRY(efi_call0)
28437 call *%rdi
28438 addq $32, %rsp
28439 RESTORE_XMM
28440+ pax_force_retaddr 0, 1
28441 ret
28442 ENDPROC(efi_call0)
28443
28444@@ -50,6 +52,7 @@ ENTRY(efi_call1)
28445 call *%rdi
28446 addq $32, %rsp
28447 RESTORE_XMM
28448+ pax_force_retaddr 0, 1
28449 ret
28450 ENDPROC(efi_call1)
28451
28452@@ -60,6 +63,7 @@ ENTRY(efi_call2)
28453 call *%rdi
28454 addq $32, %rsp
28455 RESTORE_XMM
28456+ pax_force_retaddr 0, 1
28457 ret
28458 ENDPROC(efi_call2)
28459
28460@@ -71,6 +75,7 @@ ENTRY(efi_call3)
28461 call *%rdi
28462 addq $32, %rsp
28463 RESTORE_XMM
28464+ pax_force_retaddr 0, 1
28465 ret
28466 ENDPROC(efi_call3)
28467
28468@@ -83,6 +88,7 @@ ENTRY(efi_call4)
28469 call *%rdi
28470 addq $32, %rsp
28471 RESTORE_XMM
28472+ pax_force_retaddr 0, 1
28473 ret
28474 ENDPROC(efi_call4)
28475
28476@@ -96,6 +102,7 @@ ENTRY(efi_call5)
28477 call *%rdi
28478 addq $48, %rsp
28479 RESTORE_XMM
28480+ pax_force_retaddr 0, 1
28481 ret
28482 ENDPROC(efi_call5)
28483
28484@@ -112,5 +119,6 @@ ENTRY(efi_call6)
28485 call *%rdi
28486 addq $48, %rsp
28487 RESTORE_XMM
28488+ pax_force_retaddr 0, 1
28489 ret
28490 ENDPROC(efi_call6)
28491diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
28492index fd41a92..bc8091d 100644
28493--- a/arch/x86/platform/mrst/mrst.c
28494+++ b/arch/x86/platform/mrst/mrst.c
28495@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
28496 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
28497 int sfi_mrtc_num;
28498
28499-static void mrst_power_off(void)
28500+static __noreturn void mrst_power_off(void)
28501 {
28502+ BUG();
28503 }
28504
28505-static void mrst_reboot(void)
28506+static __noreturn void mrst_reboot(void)
28507 {
28508 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
28509+ BUG();
28510 }
28511
28512 /* parse all the mtimer info to a static mtimer array */
28513@@ -233,14 +235,14 @@ static void __init mrst_time_init(void)
28514 case MRST_TIMER_APBT_ONLY:
28515 break;
28516 case MRST_TIMER_LAPIC_APBT:
28517- x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28518- x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28519+ *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28520+ *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28521 break;
28522 default:
28523 if (!boot_cpu_has(X86_FEATURE_ARAT))
28524 break;
28525- x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28526- x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28527+ *(void **)&x86_init.timers.setup_percpu_clockev = setup_boot_APIC_clock;
28528+ *(void **)&x86_cpuinit.setup_percpu_clockev = setup_secondary_APIC_clock;
28529 return;
28530 }
28531 /* we need at least one APB timer */
28532@@ -282,35 +284,35 @@ static unsigned char mrst_get_nmi_reason(void)
28533 */
28534 void __init x86_mrst_early_setup(void)
28535 {
28536- x86_init.resources.probe_roms = x86_init_noop;
28537- x86_init.resources.reserve_resources = x86_init_noop;
28538+ *(void **)&x86_init.resources.probe_roms = x86_init_noop;
28539+ *(void **)&x86_init.resources.reserve_resources = x86_init_noop;
28540
28541- x86_init.timers.timer_init = mrst_time_init;
28542- x86_init.timers.setup_percpu_clockev = x86_init_noop;
28543+ *(void **)&x86_init.timers.timer_init = mrst_time_init;
28544+ *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
28545
28546- x86_init.irqs.pre_vector_init = x86_init_noop;
28547+ *(void **)&x86_init.irqs.pre_vector_init = x86_init_noop;
28548
28549- x86_init.oem.arch_setup = mrst_arch_setup;
28550+ *(void **)&x86_init.oem.arch_setup = mrst_arch_setup;
28551
28552- x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28553+ *(void **)&x86_cpuinit.setup_percpu_clockev = apbt_setup_secondary_clock;
28554
28555- x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28556- x86_platform.i8042_detect = mrst_i8042_detect;
28557- x86_init.timers.wallclock_init = mrst_rtc_init;
28558- x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28559+ *(void **)&x86_platform.calibrate_tsc = mrst_calibrate_tsc;
28560+ *(void **)&x86_platform.i8042_detect = mrst_i8042_detect;
28561+ *(void **)&x86_init.timers.wallclock_init = mrst_rtc_init;
28562+ *(void **)&x86_platform.get_nmi_reason = mrst_get_nmi_reason;
28563
28564- x86_init.pci.init = pci_mrst_init;
28565- x86_init.pci.fixup_irqs = x86_init_noop;
28566+ *(void **)&x86_init.pci.init = pci_mrst_init;
28567+ *(void **)&x86_init.pci.fixup_irqs = x86_init_noop;
28568
28569 legacy_pic = &null_legacy_pic;
28570
28571 /* Moorestown specific power_off/restart method */
28572 pm_power_off = mrst_power_off;
28573- machine_ops.emergency_restart = mrst_reboot;
28574+ *(void **)&machine_ops.emergency_restart = mrst_reboot;
28575
28576 /* Avoid searching for BIOS MP tables */
28577- x86_init.mpparse.find_smp_config = x86_init_noop;
28578- x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28579+ *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
28580+ *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
28581 set_bit(MP_BUS_ISA, mp_bus_not_pci);
28582 }
28583
28584diff --git a/arch/x86/platform/mrst/vrtc.c b/arch/x86/platform/mrst/vrtc.c
28585index 225bd0f..22e8086 100644
28586--- a/arch/x86/platform/mrst/vrtc.c
28587+++ b/arch/x86/platform/mrst/vrtc.c
28588@@ -120,8 +120,8 @@ void __init mrst_rtc_init(void)
28589
28590 vrtc_virt_base = (void __iomem *)set_fixmap_offset_nocache(FIX_LNW_VRTC,
28591 vrtc_paddr);
28592- x86_platform.get_wallclock = vrtc_get_time;
28593- x86_platform.set_wallclock = vrtc_set_mmss;
28594+ *(void **)&x86_platform.get_wallclock = vrtc_get_time;
28595+ *(void **)&x86_platform.set_wallclock = vrtc_set_mmss;
28596 }
28597
28598 /*
28599diff --git a/arch/x86/platform/olpc/olpc.c b/arch/x86/platform/olpc/olpc.c
28600index 2737608..0d62cc2 100644
28601--- a/arch/x86/platform/olpc/olpc.c
28602+++ b/arch/x86/platform/olpc/olpc.c
28603@@ -395,7 +395,7 @@ static int __init olpc_init(void)
28604 * XO-1 only. */
28605 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0) &&
28606 !cs5535_has_vsa2())
28607- x86_init.pci.arch_init = pci_olpc_init;
28608+ *(void **)&x86_init.pci.arch_init = pci_olpc_init;
28609 #endif
28610
28611 if (olpc_platform_info.boardrev < olpc_board_pre(0xd0)) { /* XO-1 */
28612diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
28613index d6ee929..3637cb5 100644
28614--- a/arch/x86/platform/olpc/olpc_dt.c
28615+++ b/arch/x86/platform/olpc/olpc_dt.c
28616@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
28617 return res;
28618 }
28619
28620-static struct of_pdt_ops prom_olpc_ops __initdata = {
28621+static struct of_pdt_ops prom_olpc_ops __initconst = {
28622 .nextprop = olpc_dt_nextprop,
28623 .getproplen = olpc_dt_getproplen,
28624 .getproperty = olpc_dt_getproperty,
28625diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
28626index 218cdb1..c1178eb 100644
28627--- a/arch/x86/power/cpu.c
28628+++ b/arch/x86/power/cpu.c
28629@@ -132,7 +132,7 @@ static void do_fpu_end(void)
28630 static void fix_processor_context(void)
28631 {
28632 int cpu = smp_processor_id();
28633- struct tss_struct *t = &per_cpu(init_tss, cpu);
28634+ struct tss_struct *t = init_tss + cpu;
28635
28636 set_tss_desc(cpu, t); /*
28637 * This just modifies memory; should not be
28638@@ -142,8 +142,6 @@ static void fix_processor_context(void)
28639 */
28640
28641 #ifdef CONFIG_X86_64
28642- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
28643-
28644 syscall_init(); /* This sets MSR_*STAR and related */
28645 #endif
28646 load_TR_desc(); /* This does ltr */
28647diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
28648index cbca565..bae7133 100644
28649--- a/arch/x86/realmode/init.c
28650+++ b/arch/x86/realmode/init.c
28651@@ -62,7 +62,13 @@ void __init setup_real_mode(void)
28652 __va(real_mode_header->trampoline_header);
28653
28654 #ifdef CONFIG_X86_32
28655- trampoline_header->start = __pa(startup_32_smp);
28656+ trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
28657+
28658+#ifdef CONFIG_PAX_KERNEXEC
28659+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
28660+#endif
28661+
28662+ trampoline_header->boot_cs = __BOOT_CS;
28663 trampoline_header->gdt_limit = __BOOT_DS + 7;
28664 trampoline_header->gdt_base = __pa(boot_gdt);
28665 #else
28666diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
28667index 8869287..d577672 100644
28668--- a/arch/x86/realmode/rm/Makefile
28669+++ b/arch/x86/realmode/rm/Makefile
28670@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
28671 $(call cc-option, -fno-unit-at-a-time)) \
28672 $(call cc-option, -fno-stack-protector) \
28673 $(call cc-option, -mpreferred-stack-boundary=2)
28674+ifdef CONSTIFY_PLUGIN
28675+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
28676+endif
28677 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
28678 GCOV_PROFILE := n
28679diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
28680index a28221d..93c40f1 100644
28681--- a/arch/x86/realmode/rm/header.S
28682+++ b/arch/x86/realmode/rm/header.S
28683@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
28684 #endif
28685 /* APM/BIOS reboot */
28686 .long pa_machine_real_restart_asm
28687-#ifdef CONFIG_X86_64
28688+#ifdef CONFIG_X86_32
28689+ .long __KERNEL_CS
28690+#else
28691 .long __KERNEL32_CS
28692 #endif
28693 END(real_mode_header)
28694diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
28695index c1b2791..f9e31c7 100644
28696--- a/arch/x86/realmode/rm/trampoline_32.S
28697+++ b/arch/x86/realmode/rm/trampoline_32.S
28698@@ -25,6 +25,12 @@
28699 #include <asm/page_types.h>
28700 #include "realmode.h"
28701
28702+#ifdef CONFIG_PAX_KERNEXEC
28703+#define ta(X) (X)
28704+#else
28705+#define ta(X) (pa_ ## X)
28706+#endif
28707+
28708 .text
28709 .code16
28710
28711@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
28712
28713 cli # We should be safe anyway
28714
28715- movl tr_start, %eax # where we need to go
28716-
28717 movl $0xA5A5A5A5, trampoline_status
28718 # write marker for master knows we're running
28719
28720@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
28721 movw $1, %dx # protected mode (PE) bit
28722 lmsw %dx # into protected mode
28723
28724- ljmpl $__BOOT_CS, $pa_startup_32
28725+ ljmpl *(trampoline_header)
28726
28727 .section ".text32","ax"
28728 .code32
28729@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
28730 .balign 8
28731 GLOBAL(trampoline_header)
28732 tr_start: .space 4
28733- tr_gdt_pad: .space 2
28734+ tr_boot_cs: .space 2
28735 tr_gdt: .space 6
28736 END(trampoline_header)
28737
28738diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
28739index bb360dc..3e5945f 100644
28740--- a/arch/x86/realmode/rm/trampoline_64.S
28741+++ b/arch/x86/realmode/rm/trampoline_64.S
28742@@ -107,7 +107,7 @@ ENTRY(startup_32)
28743 wrmsr
28744
28745 # Enable paging and in turn activate Long Mode
28746- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
28747+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
28748 movl %eax, %cr0
28749
28750 /*
28751diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
28752index 5a1847d..deccb30 100644
28753--- a/arch/x86/tools/relocs.c
28754+++ b/arch/x86/tools/relocs.c
28755@@ -12,10 +12,13 @@
28756 #include <regex.h>
28757 #include <tools/le_byteshift.h>
28758
28759+#include "../../../include/generated/autoconf.h"
28760+
28761 static void die(char *fmt, ...);
28762
28763 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
28764 static Elf32_Ehdr ehdr;
28765+static Elf32_Phdr *phdr;
28766 static unsigned long reloc_count, reloc_idx;
28767 static unsigned long *relocs;
28768 static unsigned long reloc16_count, reloc16_idx;
28769@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
28770 }
28771 }
28772
28773+static void read_phdrs(FILE *fp)
28774+{
28775+ unsigned int i;
28776+
28777+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
28778+ if (!phdr) {
28779+ die("Unable to allocate %d program headers\n",
28780+ ehdr.e_phnum);
28781+ }
28782+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
28783+ die("Seek to %d failed: %s\n",
28784+ ehdr.e_phoff, strerror(errno));
28785+ }
28786+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
28787+ die("Cannot read ELF program headers: %s\n",
28788+ strerror(errno));
28789+ }
28790+ for(i = 0; i < ehdr.e_phnum; i++) {
28791+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
28792+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
28793+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
28794+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
28795+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
28796+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
28797+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
28798+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
28799+ }
28800+
28801+}
28802+
28803 static void read_shdrs(FILE *fp)
28804 {
28805- int i;
28806+ unsigned int i;
28807 Elf32_Shdr shdr;
28808
28809 secs = calloc(ehdr.e_shnum, sizeof(struct section));
28810@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
28811
28812 static void read_strtabs(FILE *fp)
28813 {
28814- int i;
28815+ unsigned int i;
28816 for (i = 0; i < ehdr.e_shnum; i++) {
28817 struct section *sec = &secs[i];
28818 if (sec->shdr.sh_type != SHT_STRTAB) {
28819@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
28820
28821 static void read_symtabs(FILE *fp)
28822 {
28823- int i,j;
28824+ unsigned int i,j;
28825 for (i = 0; i < ehdr.e_shnum; i++) {
28826 struct section *sec = &secs[i];
28827 if (sec->shdr.sh_type != SHT_SYMTAB) {
28828@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
28829 }
28830
28831
28832-static void read_relocs(FILE *fp)
28833+static void read_relocs(FILE *fp, int use_real_mode)
28834 {
28835- int i,j;
28836+ unsigned int i,j;
28837+ uint32_t base;
28838+
28839 for (i = 0; i < ehdr.e_shnum; i++) {
28840 struct section *sec = &secs[i];
28841 if (sec->shdr.sh_type != SHT_REL) {
28842@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
28843 die("Cannot read symbol table: %s\n",
28844 strerror(errno));
28845 }
28846+ base = 0;
28847+
28848+#ifdef CONFIG_X86_32
28849+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
28850+ if (phdr[j].p_type != PT_LOAD )
28851+ continue;
28852+ 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)
28853+ continue;
28854+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
28855+ break;
28856+ }
28857+#endif
28858+
28859 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
28860 Elf32_Rel *rel = &sec->reltab[j];
28861- rel->r_offset = elf32_to_cpu(rel->r_offset);
28862+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
28863 rel->r_info = elf32_to_cpu(rel->r_info);
28864 }
28865 }
28866@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
28867
28868 static void print_absolute_symbols(void)
28869 {
28870- int i;
28871+ unsigned int i;
28872 printf("Absolute symbols\n");
28873 printf(" Num: Value Size Type Bind Visibility Name\n");
28874 for (i = 0; i < ehdr.e_shnum; i++) {
28875 struct section *sec = &secs[i];
28876 char *sym_strtab;
28877- int j;
28878+ unsigned int j;
28879
28880 if (sec->shdr.sh_type != SHT_SYMTAB) {
28881 continue;
28882@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
28883
28884 static void print_absolute_relocs(void)
28885 {
28886- int i, printed = 0;
28887+ unsigned int i, printed = 0;
28888
28889 for (i = 0; i < ehdr.e_shnum; i++) {
28890 struct section *sec = &secs[i];
28891 struct section *sec_applies, *sec_symtab;
28892 char *sym_strtab;
28893 Elf32_Sym *sh_symtab;
28894- int j;
28895+ unsigned int j;
28896 if (sec->shdr.sh_type != SHT_REL) {
28897 continue;
28898 }
28899@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
28900 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28901 int use_real_mode)
28902 {
28903- int i;
28904+ unsigned int i;
28905 /* Walk through the relocations */
28906 for (i = 0; i < ehdr.e_shnum; i++) {
28907 char *sym_strtab;
28908 Elf32_Sym *sh_symtab;
28909 struct section *sec_applies, *sec_symtab;
28910- int j;
28911+ unsigned int j;
28912 struct section *sec = &secs[i];
28913
28914 if (sec->shdr.sh_type != SHT_REL) {
28915@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
28916 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
28917 r_type = ELF32_R_TYPE(rel->r_info);
28918
28919+ if (!use_real_mode) {
28920+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
28921+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
28922+ continue;
28923+
28924+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
28925+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
28926+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
28927+ continue;
28928+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
28929+ continue;
28930+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
28931+ continue;
28932+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
28933+ continue;
28934+#endif
28935+ }
28936+
28937 shn_abs = sym->st_shndx == SHN_ABS;
28938
28939 switch (r_type) {
28940@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
28941
28942 static void emit_relocs(int as_text, int use_real_mode)
28943 {
28944- int i;
28945+ unsigned int i;
28946 /* Count how many relocations I have and allocate space for them. */
28947 reloc_count = 0;
28948 walk_relocs(count_reloc, use_real_mode);
28949@@ -808,10 +874,11 @@ int main(int argc, char **argv)
28950 fname, strerror(errno));
28951 }
28952 read_ehdr(fp);
28953+ read_phdrs(fp);
28954 read_shdrs(fp);
28955 read_strtabs(fp);
28956 read_symtabs(fp);
28957- read_relocs(fp);
28958+ read_relocs(fp, use_real_mode);
28959 if (show_absolute_syms) {
28960 print_absolute_symbols();
28961 return 0;
28962diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
28963index fd14be1..e3c79c0 100644
28964--- a/arch/x86/vdso/Makefile
28965+++ b/arch/x86/vdso/Makefile
28966@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
28967 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
28968 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
28969
28970-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28971+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
28972 GCOV_PROFILE := n
28973
28974 #
28975diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
28976index 0faad64..39ef157 100644
28977--- a/arch/x86/vdso/vdso32-setup.c
28978+++ b/arch/x86/vdso/vdso32-setup.c
28979@@ -25,6 +25,7 @@
28980 #include <asm/tlbflush.h>
28981 #include <asm/vdso.h>
28982 #include <asm/proto.h>
28983+#include <asm/mman.h>
28984
28985 enum {
28986 VDSO_DISABLED = 0,
28987@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
28988 void enable_sep_cpu(void)
28989 {
28990 int cpu = get_cpu();
28991- struct tss_struct *tss = &per_cpu(init_tss, cpu);
28992+ struct tss_struct *tss = init_tss + cpu;
28993
28994 if (!boot_cpu_has(X86_FEATURE_SEP)) {
28995 put_cpu();
28996@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
28997 gate_vma.vm_start = FIXADDR_USER_START;
28998 gate_vma.vm_end = FIXADDR_USER_END;
28999 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
29000- gate_vma.vm_page_prot = __P101;
29001+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
29002
29003 return 0;
29004 }
29005@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29006 if (compat)
29007 addr = VDSO_HIGH_BASE;
29008 else {
29009- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
29010+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
29011 if (IS_ERR_VALUE(addr)) {
29012 ret = addr;
29013 goto up_fail;
29014 }
29015 }
29016
29017- current->mm->context.vdso = (void *)addr;
29018+ current->mm->context.vdso = addr;
29019
29020 if (compat_uses_vma || !compat) {
29021 /*
29022@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29023 }
29024
29025 current_thread_info()->sysenter_return =
29026- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29027+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
29028
29029 up_fail:
29030 if (ret)
29031- current->mm->context.vdso = NULL;
29032+ current->mm->context.vdso = 0;
29033
29034 up_write(&mm->mmap_sem);
29035
29036@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
29037
29038 const char *arch_vma_name(struct vm_area_struct *vma)
29039 {
29040- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
29041+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
29042 return "[vdso]";
29043+
29044+#ifdef CONFIG_PAX_SEGMEXEC
29045+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
29046+ return "[vdso]";
29047+#endif
29048+
29049 return NULL;
29050 }
29051
29052@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
29053 * Check to see if the corresponding task was created in compat vdso
29054 * mode.
29055 */
29056- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
29057+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
29058 return &gate_vma;
29059 return NULL;
29060 }
29061diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
29062index 00aaf04..4a26505 100644
29063--- a/arch/x86/vdso/vma.c
29064+++ b/arch/x86/vdso/vma.c
29065@@ -16,8 +16,6 @@
29066 #include <asm/vdso.h>
29067 #include <asm/page.h>
29068
29069-unsigned int __read_mostly vdso_enabled = 1;
29070-
29071 extern char vdso_start[], vdso_end[];
29072 extern unsigned short vdso_sync_cpuid;
29073
29074@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
29075 * unaligned here as a result of stack start randomization.
29076 */
29077 addr = PAGE_ALIGN(addr);
29078- addr = align_addr(addr, NULL, ALIGN_VDSO);
29079
29080 return addr;
29081 }
29082@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
29083 unsigned size)
29084 {
29085 struct mm_struct *mm = current->mm;
29086- unsigned long addr;
29087+ unsigned long addr = 0;
29088 int ret;
29089
29090- if (!vdso_enabled)
29091- return 0;
29092-
29093 down_write(&mm->mmap_sem);
29094+
29095+#ifdef CONFIG_PAX_RANDMMAP
29096+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
29097+#endif
29098+
29099 addr = vdso_addr(mm->start_stack, size);
29100+ addr = align_addr(addr, NULL, ALIGN_VDSO);
29101 addr = get_unmapped_area(NULL, addr, size, 0, 0);
29102 if (IS_ERR_VALUE(addr)) {
29103 ret = addr;
29104 goto up_fail;
29105 }
29106
29107- current->mm->context.vdso = (void *)addr;
29108+ mm->context.vdso = addr;
29109
29110 ret = install_special_mapping(mm, addr, size,
29111 VM_READ|VM_EXEC|
29112 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
29113 pages);
29114- if (ret) {
29115- current->mm->context.vdso = NULL;
29116- goto up_fail;
29117- }
29118+ if (ret)
29119+ mm->context.vdso = 0;
29120
29121 up_fail:
29122 up_write(&mm->mmap_sem);
29123@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
29124 vdsox32_size);
29125 }
29126 #endif
29127-
29128-static __init int vdso_setup(char *s)
29129-{
29130- vdso_enabled = simple_strtoul(s, NULL, 0);
29131- return 0;
29132-}
29133-__setup("vdso=", vdso_setup);
29134diff --git a/arch/x86/xen/apic.c b/arch/x86/xen/apic.c
29135index 7005ced..530d6eb 100644
29136--- a/arch/x86/xen/apic.c
29137+++ b/arch/x86/xen/apic.c
29138@@ -30,5 +30,5 @@ static unsigned int xen_io_apic_read(unsigned apic, unsigned reg)
29139
29140 void __init xen_init_apic(void)
29141 {
29142- x86_io_apic_ops.read = xen_io_apic_read;
29143+ *(void **)&x86_io_apic_ops.read = xen_io_apic_read;
29144 }
29145diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
29146index 586d838..9181904 100644
29147--- a/arch/x86/xen/enlighten.c
29148+++ b/arch/x86/xen/enlighten.c
29149@@ -99,8 +99,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
29150
29151 struct shared_info xen_dummy_shared_info;
29152
29153-void *xen_initial_gdt;
29154-
29155 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
29156 __read_mostly int xen_have_vector_callback;
29157 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
29158@@ -473,8 +471,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
29159 {
29160 unsigned long va = dtr->address;
29161 unsigned int size = dtr->size + 1;
29162- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29163- unsigned long frames[pages];
29164+ unsigned long frames[65536 / PAGE_SIZE];
29165 int f;
29166
29167 /*
29168@@ -522,8 +519,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
29169 {
29170 unsigned long va = dtr->address;
29171 unsigned int size = dtr->size + 1;
29172- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
29173- unsigned long frames[pages];
29174+ unsigned long frames[65536 / PAGE_SIZE];
29175 int f;
29176
29177 /*
29178@@ -918,21 +914,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
29179
29180 static void set_xen_basic_apic_ops(void)
29181 {
29182- apic->read = xen_apic_read;
29183- apic->write = xen_apic_write;
29184- apic->icr_read = xen_apic_icr_read;
29185- apic->icr_write = xen_apic_icr_write;
29186- apic->wait_icr_idle = xen_apic_wait_icr_idle;
29187- apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29188- apic->set_apic_id = xen_set_apic_id;
29189- apic->get_apic_id = xen_get_apic_id;
29190+ *(void **)&apic->read = xen_apic_read;
29191+ *(void **)&apic->write = xen_apic_write;
29192+ *(void **)&apic->icr_read = xen_apic_icr_read;
29193+ *(void **)&apic->icr_write = xen_apic_icr_write;
29194+ *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
29195+ *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
29196+ *(void **)&apic->set_apic_id = xen_set_apic_id;
29197+ *(void **)&apic->get_apic_id = xen_get_apic_id;
29198
29199 #ifdef CONFIG_SMP
29200- apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29201- apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29202- apic->send_IPI_mask = xen_send_IPI_mask;
29203- apic->send_IPI_all = xen_send_IPI_all;
29204- apic->send_IPI_self = xen_send_IPI_self;
29205+ *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
29206+ *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
29207+ *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
29208+ *(void **)&apic->send_IPI_all = xen_send_IPI_all;
29209+ *(void **)&apic->send_IPI_self = xen_send_IPI_self;
29210 #endif
29211 }
29212
29213@@ -1222,30 +1218,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
29214 #endif
29215 };
29216
29217-static void xen_reboot(int reason)
29218+static __noreturn void xen_reboot(int reason)
29219 {
29220 struct sched_shutdown r = { .reason = reason };
29221
29222- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
29223- BUG();
29224+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
29225+ BUG();
29226 }
29227
29228-static void xen_restart(char *msg)
29229+static __noreturn void xen_restart(char *msg)
29230 {
29231 xen_reboot(SHUTDOWN_reboot);
29232 }
29233
29234-static void xen_emergency_restart(void)
29235+static __noreturn void xen_emergency_restart(void)
29236 {
29237 xen_reboot(SHUTDOWN_reboot);
29238 }
29239
29240-static void xen_machine_halt(void)
29241+static __noreturn void xen_machine_halt(void)
29242 {
29243 xen_reboot(SHUTDOWN_poweroff);
29244 }
29245
29246-static void xen_machine_power_off(void)
29247+static __noreturn void xen_machine_power_off(void)
29248 {
29249 if (pm_power_off)
29250 pm_power_off();
29251@@ -1290,14 +1286,14 @@ static const struct machine_ops xen_machine_ops __initconst = {
29252 */
29253 static void __init xen_setup_stackprotector(void)
29254 {
29255- pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29256- pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29257+ *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry_boot;
29258+ *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt_boot;
29259
29260 setup_stack_canary_segment(0);
29261 switch_to_new_gdt(0);
29262
29263- pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29264- pv_cpu_ops.load_gdt = xen_load_gdt;
29265+ *(void **)&pv_cpu_ops.write_gdt_entry = xen_write_gdt_entry;
29266+ *(void **)&pv_cpu_ops.load_gdt = xen_load_gdt;
29267 }
29268
29269 /* First C function to be called on Xen boot */
29270@@ -1315,13 +1311,13 @@ asmlinkage void __init xen_start_kernel(void)
29271
29272 /* Install Xen paravirt ops */
29273 pv_info = xen_info;
29274- pv_init_ops = xen_init_ops;
29275- pv_cpu_ops = xen_cpu_ops;
29276- pv_apic_ops = xen_apic_ops;
29277+ memcpy((void *)&pv_init_ops, &xen_init_ops, sizeof pv_init_ops);
29278+ memcpy((void *)&pv_cpu_ops, &xen_cpu_ops, sizeof pv_cpu_ops);
29279+ memcpy((void *)&pv_apic_ops, &xen_apic_ops, sizeof pv_apic_ops);
29280
29281- x86_init.resources.memory_setup = xen_memory_setup;
29282- x86_init.oem.arch_setup = xen_arch_setup;
29283- x86_init.oem.banner = xen_banner;
29284+ *(void **)&x86_init.resources.memory_setup = xen_memory_setup;
29285+ *(void **)&x86_init.oem.arch_setup = xen_arch_setup;
29286+ *(void **)&x86_init.oem.banner = xen_banner;
29287
29288 xen_init_time_ops();
29289
29290@@ -1347,7 +1343,17 @@ asmlinkage void __init xen_start_kernel(void)
29291 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
29292
29293 /* Work out if we support NX */
29294- x86_configure_nx();
29295+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29296+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
29297+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
29298+ unsigned l, h;
29299+
29300+ __supported_pte_mask |= _PAGE_NX;
29301+ rdmsr(MSR_EFER, l, h);
29302+ l |= EFER_NX;
29303+ wrmsr(MSR_EFER, l, h);
29304+ }
29305+#endif
29306
29307 xen_setup_features();
29308
29309@@ -1376,14 +1382,7 @@ asmlinkage void __init xen_start_kernel(void)
29310 pv_mmu_ops.ptep_modify_prot_commit = xen_ptep_modify_prot_commit;
29311 }
29312
29313- machine_ops = xen_machine_ops;
29314-
29315- /*
29316- * The only reliable way to retain the initial address of the
29317- * percpu gdt_page is to remember it here, so we can go and
29318- * mark it RW later, when the initial percpu area is freed.
29319- */
29320- xen_initial_gdt = &per_cpu(gdt_page, 0);
29321+ memcpy((void *)&machine_ops, &xen_machine_ops, sizeof machine_ops);
29322
29323 xen_smp_init();
29324
29325@@ -1450,7 +1449,7 @@ asmlinkage void __init xen_start_kernel(void)
29326 add_preferred_console("tty", 0, NULL);
29327 add_preferred_console("hvc", 0, NULL);
29328 if (pci_xen)
29329- x86_init.pci.arch_init = pci_xen_init;
29330+ *(void **)&x86_init.pci.arch_init = pci_xen_init;
29331 } else {
29332 const struct dom0_vga_console_info *info =
29333 (void *)((char *)xen_start_info +
29334@@ -1476,8 +1475,8 @@ asmlinkage void __init xen_start_kernel(void)
29335 xen_acpi_sleep_register();
29336
29337 /* Avoid searching for BIOS MP tables */
29338- x86_init.mpparse.find_smp_config = x86_init_noop;
29339- x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29340+ *(void **)&x86_init.mpparse.find_smp_config = x86_init_noop;
29341+ *(void **)&x86_init.mpparse.get_smp_config = x86_init_uint_noop;
29342 }
29343 #ifdef CONFIG_PCI
29344 /* PCI BIOS service won't work from a PV guest. */
29345@@ -1583,7 +1582,7 @@ static void __init xen_hvm_guest_init(void)
29346 xen_hvm_smp_init();
29347 register_cpu_notifier(&xen_hvm_cpu_notifier);
29348 xen_unplug_emulated_devices();
29349- x86_init.irqs.intr_init = xen_init_IRQ;
29350+ *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29351 xen_hvm_init_time_ops();
29352 xen_hvm_init_mmu_ops();
29353 }
29354diff --git a/arch/x86/xen/irq.c b/arch/x86/xen/irq.c
29355index 01a4dc0..3ca0cc9 100644
29356--- a/arch/x86/xen/irq.c
29357+++ b/arch/x86/xen/irq.c
29358@@ -130,5 +130,5 @@ static const struct pv_irq_ops xen_irq_ops __initconst = {
29359 void __init xen_init_irq_ops(void)
29360 {
29361 pv_irq_ops = xen_irq_ops;
29362- x86_init.irqs.intr_init = xen_init_IRQ;
29363+ *(void **)&x86_init.irqs.intr_init = xen_init_IRQ;
29364 }
29365diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
29366index dcf5f2d..5f72fe7 100644
29367--- a/arch/x86/xen/mmu.c
29368+++ b/arch/x86/xen/mmu.c
29369@@ -1881,6 +1881,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29370 /* L3_k[510] -> level2_kernel_pgt
29371 * L3_i[511] -> level2_fixmap_pgt */
29372 convert_pfn_mfn(level3_kernel_pgt);
29373+ convert_pfn_mfn(level3_vmalloc_start_pgt);
29374+ convert_pfn_mfn(level3_vmalloc_end_pgt);
29375+ convert_pfn_mfn(level3_vmemmap_pgt);
29376
29377 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
29378 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
29379@@ -1910,8 +1913,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
29380 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
29381 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
29382 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
29383+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
29384+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
29385+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
29386 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
29387 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
29388+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
29389 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
29390 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
29391
29392@@ -2097,6 +2104,7 @@ static void __init xen_post_allocator_init(void)
29393 pv_mmu_ops.set_pud = xen_set_pud;
29394 #if PAGETABLE_LEVELS == 4
29395 pv_mmu_ops.set_pgd = xen_set_pgd;
29396+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
29397 #endif
29398
29399 /* This will work as long as patching hasn't happened yet
29400@@ -2178,6 +2186,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29401 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
29402 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
29403 .set_pgd = xen_set_pgd_hyper,
29404+ .set_pgd_batched = xen_set_pgd_hyper,
29405
29406 .alloc_pud = xen_alloc_pmd_init,
29407 .release_pud = xen_release_pmd_init,
29408@@ -2197,8 +2206,8 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
29409
29410 void __init xen_init_mmu_ops(void)
29411 {
29412- x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29413- x86_init.paging.pagetable_init = xen_pagetable_init;
29414+ *(void **)&x86_init.mapping.pagetable_reserve = xen_mapping_pagetable_reserve;
29415+ *(void **)&x86_init.paging.pagetable_init = xen_pagetable_init;
29416 pv_mmu_ops = xen_mmu_ops;
29417
29418 memset(dummy_mapping, 0xff, PAGE_SIZE);
29419diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
29420index 353c50f..a0b9b0d 100644
29421--- a/arch/x86/xen/smp.c
29422+++ b/arch/x86/xen/smp.c
29423@@ -229,11 +229,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
29424 {
29425 BUG_ON(smp_processor_id() != 0);
29426 native_smp_prepare_boot_cpu();
29427-
29428- /* We've switched to the "real" per-cpu gdt, so make sure the
29429- old memory can be recycled */
29430- make_lowmem_page_readwrite(xen_initial_gdt);
29431-
29432 xen_filter_cpu_maps();
29433 xen_setup_vcpu_info_placement();
29434 }
29435@@ -300,12 +295,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
29436 gdt = get_cpu_gdt_table(cpu);
29437
29438 ctxt->flags = VGCF_IN_KERNEL;
29439- ctxt->user_regs.ds = __USER_DS;
29440- ctxt->user_regs.es = __USER_DS;
29441+ ctxt->user_regs.ds = __KERNEL_DS;
29442+ ctxt->user_regs.es = __KERNEL_DS;
29443 ctxt->user_regs.ss = __KERNEL_DS;
29444 #ifdef CONFIG_X86_32
29445 ctxt->user_regs.fs = __KERNEL_PERCPU;
29446- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
29447+ savesegment(gs, ctxt->user_regs.gs);
29448 #else
29449 ctxt->gs_base_kernel = per_cpu_offset(cpu);
29450 #endif
29451@@ -355,13 +350,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
29452 int rc;
29453
29454 per_cpu(current_task, cpu) = idle;
29455+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
29456 #ifdef CONFIG_X86_32
29457 irq_ctx_init(cpu);
29458 #else
29459 clear_tsk_thread_flag(idle, TIF_FORK);
29460- per_cpu(kernel_stack, cpu) =
29461- (unsigned long)task_stack_page(idle) -
29462- KERNEL_STACK_OFFSET + THREAD_SIZE;
29463+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
29464 #endif
29465 xen_setup_runstate_info(cpu);
29466 xen_setup_timer(cpu);
29467@@ -637,7 +631,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
29468
29469 void __init xen_smp_init(void)
29470 {
29471- smp_ops = xen_smp_ops;
29472+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
29473 xen_fill_possible_map();
29474 xen_init_spinlocks();
29475 }
29476@@ -672,10 +666,10 @@ void __init xen_hvm_smp_init(void)
29477 {
29478 if (!xen_have_vector_callback)
29479 return;
29480- smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29481- smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29482- smp_ops.cpu_up = xen_hvm_cpu_up;
29483- smp_ops.cpu_die = xen_hvm_cpu_die;
29484- smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29485- smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29486+ *(void **)&smp_ops.smp_prepare_cpus = xen_hvm_smp_prepare_cpus;
29487+ *(void **)&smp_ops.smp_send_reschedule = xen_smp_send_reschedule;
29488+ *(void **)&smp_ops.cpu_up = xen_hvm_cpu_up;
29489+ *(void **)&smp_ops.cpu_die = xen_hvm_cpu_die;
29490+ *(void **)&smp_ops.send_call_func_ipi = xen_smp_send_call_function_ipi;
29491+ *(void **)&smp_ops.send_call_func_single_ipi = xen_smp_send_call_function_single_ipi;
29492 }
29493diff --git a/arch/x86/xen/spinlock.c b/arch/x86/xen/spinlock.c
29494index 83e866d..ef60385 100644
29495--- a/arch/x86/xen/spinlock.c
29496+++ b/arch/x86/xen/spinlock.c
29497@@ -390,12 +390,12 @@ void __init xen_init_spinlocks(void)
29498 {
29499 BUILD_BUG_ON(sizeof(struct xen_spinlock) > sizeof(arch_spinlock_t));
29500
29501- pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29502- pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29503- pv_lock_ops.spin_lock = xen_spin_lock;
29504- pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29505- pv_lock_ops.spin_trylock = xen_spin_trylock;
29506- pv_lock_ops.spin_unlock = xen_spin_unlock;
29507+ *(void **)&pv_lock_ops.spin_is_locked = xen_spin_is_locked;
29508+ *(void **)&pv_lock_ops.spin_is_contended = xen_spin_is_contended;
29509+ *(void **)&pv_lock_ops.spin_lock = xen_spin_lock;
29510+ *(void **)&pv_lock_ops.spin_lock_flags = xen_spin_lock_flags;
29511+ *(void **)&pv_lock_ops.spin_trylock = xen_spin_trylock;
29512+ *(void **)&pv_lock_ops.spin_unlock = xen_spin_unlock;
29513 }
29514
29515 #ifdef CONFIG_XEN_DEBUG_FS
29516diff --git a/arch/x86/xen/time.c b/arch/x86/xen/time.c
29517index 0296a95..3c51a2d 100644
29518--- a/arch/x86/xen/time.c
29519+++ b/arch/x86/xen/time.c
29520@@ -481,15 +481,15 @@ static void __init xen_time_init(void)
29521
29522 void __init xen_init_time_ops(void)
29523 {
29524- pv_time_ops = xen_time_ops;
29525+ memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29526
29527- x86_init.timers.timer_init = xen_time_init;
29528- x86_init.timers.setup_percpu_clockev = x86_init_noop;
29529- x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29530+ *(void **)&x86_init.timers.timer_init = xen_time_init;
29531+ *(void **)&x86_init.timers.setup_percpu_clockev = x86_init_noop;
29532+ *(void **)&x86_cpuinit.setup_percpu_clockev = x86_init_noop;
29533
29534- x86_platform.calibrate_tsc = xen_tsc_khz;
29535- x86_platform.get_wallclock = xen_get_wallclock;
29536- x86_platform.set_wallclock = xen_set_wallclock;
29537+ *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29538+ *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29539+ *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29540 }
29541
29542 #ifdef CONFIG_XEN_PVHVM
29543@@ -514,12 +514,12 @@ void __init xen_hvm_init_time_ops(void)
29544 return;
29545 }
29546
29547- pv_time_ops = xen_time_ops;
29548- x86_init.timers.setup_percpu_clockev = xen_time_init;
29549- x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29550+ memcpy((void *)&pv_time_ops, &xen_time_ops, sizeof pv_time_ops);
29551+ *(void **)&x86_init.timers.setup_percpu_clockev = xen_time_init;
29552+ *(void **)&x86_cpuinit.setup_percpu_clockev = xen_hvm_setup_cpu_clockevents;
29553
29554- x86_platform.calibrate_tsc = xen_tsc_khz;
29555- x86_platform.get_wallclock = xen_get_wallclock;
29556- x86_platform.set_wallclock = xen_set_wallclock;
29557+ *(void **)&x86_platform.calibrate_tsc = xen_tsc_khz;
29558+ *(void **)&x86_platform.get_wallclock = xen_get_wallclock;
29559+ *(void **)&x86_platform.set_wallclock = xen_set_wallclock;
29560 }
29561 #endif
29562diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
29563index f9643fc..602e8af 100644
29564--- a/arch/x86/xen/xen-asm_32.S
29565+++ b/arch/x86/xen/xen-asm_32.S
29566@@ -84,14 +84,14 @@ ENTRY(xen_iret)
29567 ESP_OFFSET=4 # bytes pushed onto stack
29568
29569 /*
29570- * Store vcpu_info pointer for easy access. Do it this way to
29571- * avoid having to reload %fs
29572+ * Store vcpu_info pointer for easy access.
29573 */
29574 #ifdef CONFIG_SMP
29575- GET_THREAD_INFO(%eax)
29576- movl TI_cpu(%eax), %eax
29577- movl __per_cpu_offset(,%eax,4), %eax
29578- mov xen_vcpu(%eax), %eax
29579+ push %fs
29580+ mov $(__KERNEL_PERCPU), %eax
29581+ mov %eax, %fs
29582+ mov PER_CPU_VAR(xen_vcpu), %eax
29583+ pop %fs
29584 #else
29585 movl xen_vcpu, %eax
29586 #endif
29587diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
29588index 7faed58..ba4427c 100644
29589--- a/arch/x86/xen/xen-head.S
29590+++ b/arch/x86/xen/xen-head.S
29591@@ -19,6 +19,17 @@ ENTRY(startup_xen)
29592 #ifdef CONFIG_X86_32
29593 mov %esi,xen_start_info
29594 mov $init_thread_union+THREAD_SIZE,%esp
29595+#ifdef CONFIG_SMP
29596+ movl $cpu_gdt_table,%edi
29597+ movl $__per_cpu_load,%eax
29598+ movw %ax,__KERNEL_PERCPU + 2(%edi)
29599+ rorl $16,%eax
29600+ movb %al,__KERNEL_PERCPU + 4(%edi)
29601+ movb %ah,__KERNEL_PERCPU + 7(%edi)
29602+ movl $__per_cpu_end - 1,%eax
29603+ subl $__per_cpu_start,%eax
29604+ movw %ax,__KERNEL_PERCPU + 0(%edi)
29605+#endif
29606 #else
29607 mov %rsi,xen_start_info
29608 mov $init_thread_union+THREAD_SIZE,%rsp
29609diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
29610index a95b417..b6dbd0b 100644
29611--- a/arch/x86/xen/xen-ops.h
29612+++ b/arch/x86/xen/xen-ops.h
29613@@ -10,8 +10,6 @@
29614 extern const char xen_hypervisor_callback[];
29615 extern const char xen_failsafe_callback[];
29616
29617-extern void *xen_initial_gdt;
29618-
29619 struct trap_info;
29620 void xen_copy_trap_info(struct trap_info *traps);
29621
29622diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
29623index 525bd3d..ef888b1 100644
29624--- a/arch/xtensa/variants/dc232b/include/variant/core.h
29625+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
29626@@ -119,9 +119,9 @@
29627 ----------------------------------------------------------------------*/
29628
29629 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
29630-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
29631 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
29632 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
29633+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29634
29635 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
29636 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
29637diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
29638index 2f33760..835e50a 100644
29639--- a/arch/xtensa/variants/fsf/include/variant/core.h
29640+++ b/arch/xtensa/variants/fsf/include/variant/core.h
29641@@ -11,6 +11,7 @@
29642 #ifndef _XTENSA_CORE_H
29643 #define _XTENSA_CORE_H
29644
29645+#include <linux/const.h>
29646
29647 /****************************************************************************
29648 Parameters Useful for Any Code, USER or PRIVILEGED
29649@@ -112,9 +113,9 @@
29650 ----------------------------------------------------------------------*/
29651
29652 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29653-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29654 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29655 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29656+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29657
29658 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
29659 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
29660diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
29661index af00795..2bb8105 100644
29662--- a/arch/xtensa/variants/s6000/include/variant/core.h
29663+++ b/arch/xtensa/variants/s6000/include/variant/core.h
29664@@ -11,6 +11,7 @@
29665 #ifndef _XTENSA_CORE_CONFIGURATION_H
29666 #define _XTENSA_CORE_CONFIGURATION_H
29667
29668+#include <linux/const.h>
29669
29670 /****************************************************************************
29671 Parameters Useful for Any Code, USER or PRIVILEGED
29672@@ -118,9 +119,9 @@
29673 ----------------------------------------------------------------------*/
29674
29675 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
29676-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
29677 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
29678 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
29679+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
29680
29681 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
29682 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
29683diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
29684index 58916af..9cb880b 100644
29685--- a/block/blk-iopoll.c
29686+++ b/block/blk-iopoll.c
29687@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
29688 }
29689 EXPORT_SYMBOL(blk_iopoll_complete);
29690
29691-static void blk_iopoll_softirq(struct softirq_action *h)
29692+static void blk_iopoll_softirq(void)
29693 {
29694 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
29695 int rearm = 0, budget = blk_iopoll_budget;
29696diff --git a/block/blk-map.c b/block/blk-map.c
29697index 623e1cd..ca1e109 100644
29698--- a/block/blk-map.c
29699+++ b/block/blk-map.c
29700@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
29701 if (!len || !kbuf)
29702 return -EINVAL;
29703
29704- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
29705+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
29706 if (do_copy)
29707 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
29708 else
29709diff --git a/block/blk-softirq.c b/block/blk-softirq.c
29710index 467c8de..4bddc6d 100644
29711--- a/block/blk-softirq.c
29712+++ b/block/blk-softirq.c
29713@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
29714 * Softirq action handler - move entries to local list and loop over them
29715 * while passing them to the queue registered handler.
29716 */
29717-static void blk_done_softirq(struct softirq_action *h)
29718+static void blk_done_softirq(void)
29719 {
29720 struct list_head *cpu_list, local_list;
29721
29722diff --git a/block/bsg.c b/block/bsg.c
29723index ff64ae3..593560c 100644
29724--- a/block/bsg.c
29725+++ b/block/bsg.c
29726@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
29727 struct sg_io_v4 *hdr, struct bsg_device *bd,
29728 fmode_t has_write_perm)
29729 {
29730+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29731+ unsigned char *cmdptr;
29732+
29733 if (hdr->request_len > BLK_MAX_CDB) {
29734 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
29735 if (!rq->cmd)
29736 return -ENOMEM;
29737- }
29738+ cmdptr = rq->cmd;
29739+ } else
29740+ cmdptr = tmpcmd;
29741
29742- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
29743+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
29744 hdr->request_len))
29745 return -EFAULT;
29746
29747+ if (cmdptr != rq->cmd)
29748+ memcpy(rq->cmd, cmdptr, hdr->request_len);
29749+
29750 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
29751 if (blk_verify_command(rq->cmd, has_write_perm))
29752 return -EPERM;
29753diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
29754index 7c668c8..db3521c 100644
29755--- a/block/compat_ioctl.c
29756+++ b/block/compat_ioctl.c
29757@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
29758 err |= __get_user(f->spec1, &uf->spec1);
29759 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
29760 err |= __get_user(name, &uf->name);
29761- f->name = compat_ptr(name);
29762+ f->name = (void __force_kernel *)compat_ptr(name);
29763 if (err) {
29764 err = -EFAULT;
29765 goto out;
29766diff --git a/block/partitions/efi.c b/block/partitions/efi.c
29767index 6296b40..417c00f 100644
29768--- a/block/partitions/efi.c
29769+++ b/block/partitions/efi.c
29770@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
29771 if (!gpt)
29772 return NULL;
29773
29774+ if (!le32_to_cpu(gpt->num_partition_entries))
29775+ return NULL;
29776+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
29777+ if (!pte)
29778+ return NULL;
29779+
29780 count = le32_to_cpu(gpt->num_partition_entries) *
29781 le32_to_cpu(gpt->sizeof_partition_entry);
29782- if (!count)
29783- return NULL;
29784- pte = kzalloc(count, GFP_KERNEL);
29785- if (!pte)
29786- return NULL;
29787-
29788 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
29789 (u8 *) pte,
29790 count) < count) {
29791diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
29792index 9a87daa..fb17486 100644
29793--- a/block/scsi_ioctl.c
29794+++ b/block/scsi_ioctl.c
29795@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
29796 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
29797 struct sg_io_hdr *hdr, fmode_t mode)
29798 {
29799- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
29800+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29801+ unsigned char *cmdptr;
29802+
29803+ if (rq->cmd != rq->__cmd)
29804+ cmdptr = rq->cmd;
29805+ else
29806+ cmdptr = tmpcmd;
29807+
29808+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
29809 return -EFAULT;
29810+
29811+ if (cmdptr != rq->cmd)
29812+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
29813+
29814 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
29815 return -EPERM;
29816
29817@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29818 int err;
29819 unsigned int in_len, out_len, bytes, opcode, cmdlen;
29820 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
29821+ unsigned char tmpcmd[sizeof(rq->__cmd)];
29822+ unsigned char *cmdptr;
29823
29824 if (!sic)
29825 return -EINVAL;
29826@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
29827 */
29828 err = -EFAULT;
29829 rq->cmd_len = cmdlen;
29830- if (copy_from_user(rq->cmd, sic->data, cmdlen))
29831+
29832+ if (rq->cmd != rq->__cmd)
29833+ cmdptr = rq->cmd;
29834+ else
29835+ cmdptr = tmpcmd;
29836+
29837+ if (copy_from_user(cmdptr, sic->data, cmdlen))
29838 goto error;
29839
29840+ if (rq->cmd != cmdptr)
29841+ memcpy(rq->cmd, cmdptr, cmdlen);
29842+
29843 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
29844 goto error;
29845
29846diff --git a/crypto/cryptd.c b/crypto/cryptd.c
29847index 7bdd61b..afec999 100644
29848--- a/crypto/cryptd.c
29849+++ b/crypto/cryptd.c
29850@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
29851
29852 struct cryptd_blkcipher_request_ctx {
29853 crypto_completion_t complete;
29854-};
29855+} __no_const;
29856
29857 struct cryptd_hash_ctx {
29858 struct crypto_shash *child;
29859@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
29860
29861 struct cryptd_aead_request_ctx {
29862 crypto_completion_t complete;
29863-};
29864+} __no_const;
29865
29866 static void cryptd_queue_worker(struct work_struct *work);
29867
29868diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
29869index e6defd8..c26a225 100644
29870--- a/drivers/acpi/apei/cper.c
29871+++ b/drivers/acpi/apei/cper.c
29872@@ -38,12 +38,12 @@
29873 */
29874 u64 cper_next_record_id(void)
29875 {
29876- static atomic64_t seq;
29877+ static atomic64_unchecked_t seq;
29878
29879- if (!atomic64_read(&seq))
29880- atomic64_set(&seq, ((u64)get_seconds()) << 32);
29881+ if (!atomic64_read_unchecked(&seq))
29882+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
29883
29884- return atomic64_inc_return(&seq);
29885+ return atomic64_inc_return_unchecked(&seq);
29886 }
29887 EXPORT_SYMBOL_GPL(cper_next_record_id);
29888
29889diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
29890index 7586544..636a2f0 100644
29891--- a/drivers/acpi/ec_sys.c
29892+++ b/drivers/acpi/ec_sys.c
29893@@ -12,6 +12,7 @@
29894 #include <linux/acpi.h>
29895 #include <linux/debugfs.h>
29896 #include <linux/module.h>
29897+#include <linux/uaccess.h>
29898 #include "internal.h"
29899
29900 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
29901@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29902 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
29903 */
29904 unsigned int size = EC_SPACE_SIZE;
29905- u8 *data = (u8 *) buf;
29906+ u8 data;
29907 loff_t init_off = *off;
29908 int err = 0;
29909
29910@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
29911 size = count;
29912
29913 while (size) {
29914- err = ec_read(*off, &data[*off - init_off]);
29915+ err = ec_read(*off, &data);
29916 if (err)
29917 return err;
29918+ if (put_user(data, &buf[*off - init_off]))
29919+ return -EFAULT;
29920 *off += 1;
29921 size--;
29922 }
29923@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29924
29925 unsigned int size = count;
29926 loff_t init_off = *off;
29927- u8 *data = (u8 *) buf;
29928 int err = 0;
29929
29930 if (*off >= EC_SPACE_SIZE)
29931@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
29932 }
29933
29934 while (size) {
29935- u8 byte_write = data[*off - init_off];
29936+ u8 byte_write;
29937+ if (get_user(byte_write, &buf[*off - init_off]))
29938+ return -EFAULT;
29939 err = ec_write(*off, byte_write);
29940 if (err)
29941 return err;
29942diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
29943index 27adb09..1ed412d 100644
29944--- a/drivers/acpi/proc.c
29945+++ b/drivers/acpi/proc.c
29946@@ -360,19 +360,13 @@ acpi_system_write_wakeup_device(struct file *file,
29947 size_t count, loff_t * ppos)
29948 {
29949 struct list_head *node, *next;
29950- char strbuf[5];
29951- char str[5] = "";
29952- unsigned int len = count;
29953+ char strbuf[5] = {0};
29954
29955- if (len > 4)
29956- len = 4;
29957- if (len < 0)
29958+ if (count > 4)
29959+ count = 4;
29960+ if (copy_from_user(strbuf, buffer, count))
29961 return -EFAULT;
29962-
29963- if (copy_from_user(strbuf, buffer, len))
29964- return -EFAULT;
29965- strbuf[len] = '\0';
29966- sscanf(strbuf, "%s", str);
29967+ strbuf[count] = '\0';
29968
29969 mutex_lock(&acpi_device_lock);
29970 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
29971@@ -381,7 +375,7 @@ acpi_system_write_wakeup_device(struct file *file,
29972 if (!dev->wakeup.flags.valid)
29973 continue;
29974
29975- if (!strncmp(dev->pnp.bus_id, str, 4)) {
29976+ if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
29977 if (device_can_wakeup(&dev->dev)) {
29978 bool enable = !device_may_wakeup(&dev->dev);
29979 device_set_wakeup_enable(&dev->dev, enable);
29980diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
29981index bd4e5dc..0497b66 100644
29982--- a/drivers/acpi/processor_driver.c
29983+++ b/drivers/acpi/processor_driver.c
29984@@ -552,7 +552,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
29985 return 0;
29986 #endif
29987
29988- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
29989+ BUG_ON(pr->id >= nr_cpu_ids);
29990
29991 /*
29992 * Buggy BIOS check
29993diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
29994index c8ac4fe..631818e 100644
29995--- a/drivers/ata/libata-core.c
29996+++ b/drivers/ata/libata-core.c
29997@@ -4779,7 +4779,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
29998 struct ata_port *ap;
29999 unsigned int tag;
30000
30001- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30002+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30003 ap = qc->ap;
30004
30005 qc->flags = 0;
30006@@ -4795,7 +4795,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
30007 struct ata_port *ap;
30008 struct ata_link *link;
30009
30010- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30011+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
30012 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
30013 ap = qc->ap;
30014 link = qc->dev->link;
30015@@ -5891,6 +5891,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30016 return;
30017
30018 spin_lock(&lock);
30019+ pax_open_kernel();
30020
30021 for (cur = ops->inherits; cur; cur = cur->inherits) {
30022 void **inherit = (void **)cur;
30023@@ -5904,8 +5905,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
30024 if (IS_ERR(*pp))
30025 *pp = NULL;
30026
30027- ops->inherits = NULL;
30028+ *(struct ata_port_operations **)&ops->inherits = NULL;
30029
30030+ pax_close_kernel();
30031 spin_unlock(&lock);
30032 }
30033
30034diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
30035index 371fd2c..0836c78 100644
30036--- a/drivers/ata/pata_arasan_cf.c
30037+++ b/drivers/ata/pata_arasan_cf.c
30038@@ -861,7 +861,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
30039 /* Handle platform specific quirks */
30040 if (pdata->quirk) {
30041 if (pdata->quirk & CF_BROKEN_PIO) {
30042- ap->ops->set_piomode = NULL;
30043+ pax_open_kernel();
30044+ *(void **)&ap->ops->set_piomode = NULL;
30045+ pax_close_kernel();
30046 ap->pio_mask = 0;
30047 }
30048 if (pdata->quirk & CF_BROKEN_MWDMA)
30049diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
30050index f9b983a..887b9d8 100644
30051--- a/drivers/atm/adummy.c
30052+++ b/drivers/atm/adummy.c
30053@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
30054 vcc->pop(vcc, skb);
30055 else
30056 dev_kfree_skb_any(skb);
30057- atomic_inc(&vcc->stats->tx);
30058+ atomic_inc_unchecked(&vcc->stats->tx);
30059
30060 return 0;
30061 }
30062diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
30063index ff7bb8a..568fc0b 100644
30064--- a/drivers/atm/ambassador.c
30065+++ b/drivers/atm/ambassador.c
30066@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
30067 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
30068
30069 // VC layer stats
30070- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30071+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30072
30073 // free the descriptor
30074 kfree (tx_descr);
30075@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30076 dump_skb ("<<<", vc, skb);
30077
30078 // VC layer stats
30079- atomic_inc(&atm_vcc->stats->rx);
30080+ atomic_inc_unchecked(&atm_vcc->stats->rx);
30081 __net_timestamp(skb);
30082 // end of our responsibility
30083 atm_vcc->push (atm_vcc, skb);
30084@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
30085 } else {
30086 PRINTK (KERN_INFO, "dropped over-size frame");
30087 // should we count this?
30088- atomic_inc(&atm_vcc->stats->rx_drop);
30089+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30090 }
30091
30092 } else {
30093@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
30094 }
30095
30096 if (check_area (skb->data, skb->len)) {
30097- atomic_inc(&atm_vcc->stats->tx_err);
30098+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
30099 return -ENOMEM; // ?
30100 }
30101
30102diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
30103index b22d71c..d6e1049 100644
30104--- a/drivers/atm/atmtcp.c
30105+++ b/drivers/atm/atmtcp.c
30106@@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30107 if (vcc->pop) vcc->pop(vcc,skb);
30108 else dev_kfree_skb(skb);
30109 if (dev_data) return 0;
30110- atomic_inc(&vcc->stats->tx_err);
30111+ atomic_inc_unchecked(&vcc->stats->tx_err);
30112 return -ENOLINK;
30113 }
30114 size = skb->len+sizeof(struct atmtcp_hdr);
30115@@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30116 if (!new_skb) {
30117 if (vcc->pop) vcc->pop(vcc,skb);
30118 else dev_kfree_skb(skb);
30119- atomic_inc(&vcc->stats->tx_err);
30120+ atomic_inc_unchecked(&vcc->stats->tx_err);
30121 return -ENOBUFS;
30122 }
30123 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
30124@@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
30125 if (vcc->pop) vcc->pop(vcc,skb);
30126 else dev_kfree_skb(skb);
30127 out_vcc->push(out_vcc,new_skb);
30128- atomic_inc(&vcc->stats->tx);
30129- atomic_inc(&out_vcc->stats->rx);
30130+ atomic_inc_unchecked(&vcc->stats->tx);
30131+ atomic_inc_unchecked(&out_vcc->stats->rx);
30132 return 0;
30133 }
30134
30135@@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30136 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
30137 read_unlock(&vcc_sklist_lock);
30138 if (!out_vcc) {
30139- atomic_inc(&vcc->stats->tx_err);
30140+ atomic_inc_unchecked(&vcc->stats->tx_err);
30141 goto done;
30142 }
30143 skb_pull(skb,sizeof(struct atmtcp_hdr));
30144@@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
30145 __net_timestamp(new_skb);
30146 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
30147 out_vcc->push(out_vcc,new_skb);
30148- atomic_inc(&vcc->stats->tx);
30149- atomic_inc(&out_vcc->stats->rx);
30150+ atomic_inc_unchecked(&vcc->stats->tx);
30151+ atomic_inc_unchecked(&out_vcc->stats->rx);
30152 done:
30153 if (vcc->pop) vcc->pop(vcc,skb);
30154 else dev_kfree_skb(skb);
30155diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
30156index 81e44f7..498ea36 100644
30157--- a/drivers/atm/eni.c
30158+++ b/drivers/atm/eni.c
30159@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
30160 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
30161 vcc->dev->number);
30162 length = 0;
30163- atomic_inc(&vcc->stats->rx_err);
30164+ atomic_inc_unchecked(&vcc->stats->rx_err);
30165 }
30166 else {
30167 length = ATM_CELL_SIZE-1; /* no HEC */
30168@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30169 size);
30170 }
30171 eff = length = 0;
30172- atomic_inc(&vcc->stats->rx_err);
30173+ atomic_inc_unchecked(&vcc->stats->rx_err);
30174 }
30175 else {
30176 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
30177@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
30178 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
30179 vcc->dev->number,vcc->vci,length,size << 2,descr);
30180 length = eff = 0;
30181- atomic_inc(&vcc->stats->rx_err);
30182+ atomic_inc_unchecked(&vcc->stats->rx_err);
30183 }
30184 }
30185 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
30186@@ -767,7 +767,7 @@ rx_dequeued++;
30187 vcc->push(vcc,skb);
30188 pushed++;
30189 }
30190- atomic_inc(&vcc->stats->rx);
30191+ atomic_inc_unchecked(&vcc->stats->rx);
30192 }
30193 wake_up(&eni_dev->rx_wait);
30194 }
30195@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
30196 PCI_DMA_TODEVICE);
30197 if (vcc->pop) vcc->pop(vcc,skb);
30198 else dev_kfree_skb_irq(skb);
30199- atomic_inc(&vcc->stats->tx);
30200+ atomic_inc_unchecked(&vcc->stats->tx);
30201 wake_up(&eni_dev->tx_wait);
30202 dma_complete++;
30203 }
30204diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
30205index 86fed1b..6dc4721 100644
30206--- a/drivers/atm/firestream.c
30207+++ b/drivers/atm/firestream.c
30208@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
30209 }
30210 }
30211
30212- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30213+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30214
30215 fs_dprintk (FS_DEBUG_TXMEM, "i");
30216 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
30217@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30218 #endif
30219 skb_put (skb, qe->p1 & 0xffff);
30220 ATM_SKB(skb)->vcc = atm_vcc;
30221- atomic_inc(&atm_vcc->stats->rx);
30222+ atomic_inc_unchecked(&atm_vcc->stats->rx);
30223 __net_timestamp(skb);
30224 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
30225 atm_vcc->push (atm_vcc, skb);
30226@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
30227 kfree (pe);
30228 }
30229 if (atm_vcc)
30230- atomic_inc(&atm_vcc->stats->rx_drop);
30231+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30232 break;
30233 case 0x1f: /* Reassembly abort: no buffers. */
30234 /* Silently increment error counter. */
30235 if (atm_vcc)
30236- atomic_inc(&atm_vcc->stats->rx_drop);
30237+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
30238 break;
30239 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
30240 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
30241diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
30242index 361f5ae..7fc552d 100644
30243--- a/drivers/atm/fore200e.c
30244+++ b/drivers/atm/fore200e.c
30245@@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
30246 #endif
30247 /* check error condition */
30248 if (*entry->status & STATUS_ERROR)
30249- atomic_inc(&vcc->stats->tx_err);
30250+ atomic_inc_unchecked(&vcc->stats->tx_err);
30251 else
30252- atomic_inc(&vcc->stats->tx);
30253+ atomic_inc_unchecked(&vcc->stats->tx);
30254 }
30255 }
30256
30257@@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30258 if (skb == NULL) {
30259 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
30260
30261- atomic_inc(&vcc->stats->rx_drop);
30262+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30263 return -ENOMEM;
30264 }
30265
30266@@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
30267
30268 dev_kfree_skb_any(skb);
30269
30270- atomic_inc(&vcc->stats->rx_drop);
30271+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30272 return -ENOMEM;
30273 }
30274
30275 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30276
30277 vcc->push(vcc, skb);
30278- atomic_inc(&vcc->stats->rx);
30279+ atomic_inc_unchecked(&vcc->stats->rx);
30280
30281 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
30282
30283@@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
30284 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
30285 fore200e->atm_dev->number,
30286 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
30287- atomic_inc(&vcc->stats->rx_err);
30288+ atomic_inc_unchecked(&vcc->stats->rx_err);
30289 }
30290 }
30291
30292@@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
30293 goto retry_here;
30294 }
30295
30296- atomic_inc(&vcc->stats->tx_err);
30297+ atomic_inc_unchecked(&vcc->stats->tx_err);
30298
30299 fore200e->tx_sat++;
30300 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
30301diff --git a/drivers/atm/he.c b/drivers/atm/he.c
30302index b182c2f..1c6fa8a 100644
30303--- a/drivers/atm/he.c
30304+++ b/drivers/atm/he.c
30305@@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30306
30307 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
30308 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
30309- atomic_inc(&vcc->stats->rx_drop);
30310+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30311 goto return_host_buffers;
30312 }
30313
30314@@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30315 RBRQ_LEN_ERR(he_dev->rbrq_head)
30316 ? "LEN_ERR" : "",
30317 vcc->vpi, vcc->vci);
30318- atomic_inc(&vcc->stats->rx_err);
30319+ atomic_inc_unchecked(&vcc->stats->rx_err);
30320 goto return_host_buffers;
30321 }
30322
30323@@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
30324 vcc->push(vcc, skb);
30325 spin_lock(&he_dev->global_lock);
30326
30327- atomic_inc(&vcc->stats->rx);
30328+ atomic_inc_unchecked(&vcc->stats->rx);
30329
30330 return_host_buffers:
30331 ++pdus_assembled;
30332@@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
30333 tpd->vcc->pop(tpd->vcc, tpd->skb);
30334 else
30335 dev_kfree_skb_any(tpd->skb);
30336- atomic_inc(&tpd->vcc->stats->tx_err);
30337+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
30338 }
30339 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
30340 return;
30341@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30342 vcc->pop(vcc, skb);
30343 else
30344 dev_kfree_skb_any(skb);
30345- atomic_inc(&vcc->stats->tx_err);
30346+ atomic_inc_unchecked(&vcc->stats->tx_err);
30347 return -EINVAL;
30348 }
30349
30350@@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30351 vcc->pop(vcc, skb);
30352 else
30353 dev_kfree_skb_any(skb);
30354- atomic_inc(&vcc->stats->tx_err);
30355+ atomic_inc_unchecked(&vcc->stats->tx_err);
30356 return -EINVAL;
30357 }
30358 #endif
30359@@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30360 vcc->pop(vcc, skb);
30361 else
30362 dev_kfree_skb_any(skb);
30363- atomic_inc(&vcc->stats->tx_err);
30364+ atomic_inc_unchecked(&vcc->stats->tx_err);
30365 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30366 return -ENOMEM;
30367 }
30368@@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30369 vcc->pop(vcc, skb);
30370 else
30371 dev_kfree_skb_any(skb);
30372- atomic_inc(&vcc->stats->tx_err);
30373+ atomic_inc_unchecked(&vcc->stats->tx_err);
30374 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30375 return -ENOMEM;
30376 }
30377@@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
30378 __enqueue_tpd(he_dev, tpd, cid);
30379 spin_unlock_irqrestore(&he_dev->global_lock, flags);
30380
30381- atomic_inc(&vcc->stats->tx);
30382+ atomic_inc_unchecked(&vcc->stats->tx);
30383
30384 return 0;
30385 }
30386diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
30387index 7d01c2a..4e3ac01 100644
30388--- a/drivers/atm/horizon.c
30389+++ b/drivers/atm/horizon.c
30390@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
30391 {
30392 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
30393 // VC layer stats
30394- atomic_inc(&vcc->stats->rx);
30395+ atomic_inc_unchecked(&vcc->stats->rx);
30396 __net_timestamp(skb);
30397 // end of our responsibility
30398 vcc->push (vcc, skb);
30399@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
30400 dev->tx_iovec = NULL;
30401
30402 // VC layer stats
30403- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
30404+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
30405
30406 // free the skb
30407 hrz_kfree_skb (skb);
30408diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
30409index 8974bd2..b856f85 100644
30410--- a/drivers/atm/idt77252.c
30411+++ b/drivers/atm/idt77252.c
30412@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
30413 else
30414 dev_kfree_skb(skb);
30415
30416- atomic_inc(&vcc->stats->tx);
30417+ atomic_inc_unchecked(&vcc->stats->tx);
30418 }
30419
30420 atomic_dec(&scq->used);
30421@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30422 if ((sb = dev_alloc_skb(64)) == NULL) {
30423 printk("%s: Can't allocate buffers for aal0.\n",
30424 card->name);
30425- atomic_add(i, &vcc->stats->rx_drop);
30426+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30427 break;
30428 }
30429 if (!atm_charge(vcc, sb->truesize)) {
30430 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
30431 card->name);
30432- atomic_add(i - 1, &vcc->stats->rx_drop);
30433+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
30434 dev_kfree_skb(sb);
30435 break;
30436 }
30437@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30438 ATM_SKB(sb)->vcc = vcc;
30439 __net_timestamp(sb);
30440 vcc->push(vcc, sb);
30441- atomic_inc(&vcc->stats->rx);
30442+ atomic_inc_unchecked(&vcc->stats->rx);
30443
30444 cell += ATM_CELL_PAYLOAD;
30445 }
30446@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30447 "(CDC: %08x)\n",
30448 card->name, len, rpp->len, readl(SAR_REG_CDC));
30449 recycle_rx_pool_skb(card, rpp);
30450- atomic_inc(&vcc->stats->rx_err);
30451+ atomic_inc_unchecked(&vcc->stats->rx_err);
30452 return;
30453 }
30454 if (stat & SAR_RSQE_CRC) {
30455 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
30456 recycle_rx_pool_skb(card, rpp);
30457- atomic_inc(&vcc->stats->rx_err);
30458+ atomic_inc_unchecked(&vcc->stats->rx_err);
30459 return;
30460 }
30461 if (skb_queue_len(&rpp->queue) > 1) {
30462@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30463 RXPRINTK("%s: Can't alloc RX skb.\n",
30464 card->name);
30465 recycle_rx_pool_skb(card, rpp);
30466- atomic_inc(&vcc->stats->rx_err);
30467+ atomic_inc_unchecked(&vcc->stats->rx_err);
30468 return;
30469 }
30470 if (!atm_charge(vcc, skb->truesize)) {
30471@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30472 __net_timestamp(skb);
30473
30474 vcc->push(vcc, skb);
30475- atomic_inc(&vcc->stats->rx);
30476+ atomic_inc_unchecked(&vcc->stats->rx);
30477
30478 return;
30479 }
30480@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
30481 __net_timestamp(skb);
30482
30483 vcc->push(vcc, skb);
30484- atomic_inc(&vcc->stats->rx);
30485+ atomic_inc_unchecked(&vcc->stats->rx);
30486
30487 if (skb->truesize > SAR_FB_SIZE_3)
30488 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
30489@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
30490 if (vcc->qos.aal != ATM_AAL0) {
30491 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
30492 card->name, vpi, vci);
30493- atomic_inc(&vcc->stats->rx_drop);
30494+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30495 goto drop;
30496 }
30497
30498 if ((sb = dev_alloc_skb(64)) == NULL) {
30499 printk("%s: Can't allocate buffers for AAL0.\n",
30500 card->name);
30501- atomic_inc(&vcc->stats->rx_err);
30502+ atomic_inc_unchecked(&vcc->stats->rx_err);
30503 goto drop;
30504 }
30505
30506@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
30507 ATM_SKB(sb)->vcc = vcc;
30508 __net_timestamp(sb);
30509 vcc->push(vcc, sb);
30510- atomic_inc(&vcc->stats->rx);
30511+ atomic_inc_unchecked(&vcc->stats->rx);
30512
30513 drop:
30514 skb_pull(queue, 64);
30515@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30516
30517 if (vc == NULL) {
30518 printk("%s: NULL connection in send().\n", card->name);
30519- atomic_inc(&vcc->stats->tx_err);
30520+ atomic_inc_unchecked(&vcc->stats->tx_err);
30521 dev_kfree_skb(skb);
30522 return -EINVAL;
30523 }
30524 if (!test_bit(VCF_TX, &vc->flags)) {
30525 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
30526- atomic_inc(&vcc->stats->tx_err);
30527+ atomic_inc_unchecked(&vcc->stats->tx_err);
30528 dev_kfree_skb(skb);
30529 return -EINVAL;
30530 }
30531@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30532 break;
30533 default:
30534 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
30535- atomic_inc(&vcc->stats->tx_err);
30536+ atomic_inc_unchecked(&vcc->stats->tx_err);
30537 dev_kfree_skb(skb);
30538 return -EINVAL;
30539 }
30540
30541 if (skb_shinfo(skb)->nr_frags != 0) {
30542 printk("%s: No scatter-gather yet.\n", card->name);
30543- atomic_inc(&vcc->stats->tx_err);
30544+ atomic_inc_unchecked(&vcc->stats->tx_err);
30545 dev_kfree_skb(skb);
30546 return -EINVAL;
30547 }
30548@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
30549
30550 err = queue_skb(card, vc, skb, oam);
30551 if (err) {
30552- atomic_inc(&vcc->stats->tx_err);
30553+ atomic_inc_unchecked(&vcc->stats->tx_err);
30554 dev_kfree_skb(skb);
30555 return err;
30556 }
30557@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
30558 skb = dev_alloc_skb(64);
30559 if (!skb) {
30560 printk("%s: Out of memory in send_oam().\n", card->name);
30561- atomic_inc(&vcc->stats->tx_err);
30562+ atomic_inc_unchecked(&vcc->stats->tx_err);
30563 return -ENOMEM;
30564 }
30565 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
30566diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
30567index 96cce6d..62c3ec5 100644
30568--- a/drivers/atm/iphase.c
30569+++ b/drivers/atm/iphase.c
30570@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
30571 status = (u_short) (buf_desc_ptr->desc_mode);
30572 if (status & (RX_CER | RX_PTE | RX_OFL))
30573 {
30574- atomic_inc(&vcc->stats->rx_err);
30575+ atomic_inc_unchecked(&vcc->stats->rx_err);
30576 IF_ERR(printk("IA: bad packet, dropping it");)
30577 if (status & RX_CER) {
30578 IF_ERR(printk(" cause: packet CRC error\n");)
30579@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
30580 len = dma_addr - buf_addr;
30581 if (len > iadev->rx_buf_sz) {
30582 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
30583- atomic_inc(&vcc->stats->rx_err);
30584+ atomic_inc_unchecked(&vcc->stats->rx_err);
30585 goto out_free_desc;
30586 }
30587
30588@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30589 ia_vcc = INPH_IA_VCC(vcc);
30590 if (ia_vcc == NULL)
30591 {
30592- atomic_inc(&vcc->stats->rx_err);
30593+ atomic_inc_unchecked(&vcc->stats->rx_err);
30594 atm_return(vcc, skb->truesize);
30595 dev_kfree_skb_any(skb);
30596 goto INCR_DLE;
30597@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30598 if ((length > iadev->rx_buf_sz) || (length >
30599 (skb->len - sizeof(struct cpcs_trailer))))
30600 {
30601- atomic_inc(&vcc->stats->rx_err);
30602+ atomic_inc_unchecked(&vcc->stats->rx_err);
30603 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
30604 length, skb->len);)
30605 atm_return(vcc, skb->truesize);
30606@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
30607
30608 IF_RX(printk("rx_dle_intr: skb push");)
30609 vcc->push(vcc,skb);
30610- atomic_inc(&vcc->stats->rx);
30611+ atomic_inc_unchecked(&vcc->stats->rx);
30612 iadev->rx_pkt_cnt++;
30613 }
30614 INCR_DLE:
30615@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
30616 {
30617 struct k_sonet_stats *stats;
30618 stats = &PRIV(_ia_dev[board])->sonet_stats;
30619- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
30620- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
30621- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
30622- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
30623- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
30624- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
30625- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
30626- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
30627- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
30628+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
30629+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
30630+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
30631+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
30632+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
30633+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
30634+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
30635+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
30636+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
30637 }
30638 ia_cmds.status = 0;
30639 break;
30640@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30641 if ((desc == 0) || (desc > iadev->num_tx_desc))
30642 {
30643 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
30644- atomic_inc(&vcc->stats->tx);
30645+ atomic_inc_unchecked(&vcc->stats->tx);
30646 if (vcc->pop)
30647 vcc->pop(vcc, skb);
30648 else
30649@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
30650 ATM_DESC(skb) = vcc->vci;
30651 skb_queue_tail(&iadev->tx_dma_q, skb);
30652
30653- atomic_inc(&vcc->stats->tx);
30654+ atomic_inc_unchecked(&vcc->stats->tx);
30655 iadev->tx_pkt_cnt++;
30656 /* Increment transaction counter */
30657 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
30658
30659 #if 0
30660 /* add flow control logic */
30661- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
30662+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
30663 if (iavcc->vc_desc_cnt > 10) {
30664 vcc->tx_quota = vcc->tx_quota * 3 / 4;
30665 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
30666diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
30667index 68c7588..7036683 100644
30668--- a/drivers/atm/lanai.c
30669+++ b/drivers/atm/lanai.c
30670@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
30671 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
30672 lanai_endtx(lanai, lvcc);
30673 lanai_free_skb(lvcc->tx.atmvcc, skb);
30674- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
30675+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
30676 }
30677
30678 /* Try to fill the buffer - don't call unless there is backlog */
30679@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
30680 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
30681 __net_timestamp(skb);
30682 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
30683- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
30684+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
30685 out:
30686 lvcc->rx.buf.ptr = end;
30687 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
30688@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30689 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
30690 "vcc %d\n", lanai->number, (unsigned int) s, vci);
30691 lanai->stats.service_rxnotaal5++;
30692- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30693+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30694 return 0;
30695 }
30696 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
30697@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30698 int bytes;
30699 read_unlock(&vcc_sklist_lock);
30700 DPRINTK("got trashed rx pdu on vci %d\n", vci);
30701- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30702+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30703 lvcc->stats.x.aal5.service_trash++;
30704 bytes = (SERVICE_GET_END(s) * 16) -
30705 (((unsigned long) lvcc->rx.buf.ptr) -
30706@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30707 }
30708 if (s & SERVICE_STREAM) {
30709 read_unlock(&vcc_sklist_lock);
30710- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30711+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30712 lvcc->stats.x.aal5.service_stream++;
30713 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
30714 "PDU on VCI %d!\n", lanai->number, vci);
30715@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
30716 return 0;
30717 }
30718 DPRINTK("got rx crc error on vci %d\n", vci);
30719- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
30720+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
30721 lvcc->stats.x.aal5.service_rxcrc++;
30722 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
30723 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
30724diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
30725index 1c70c45..300718d 100644
30726--- a/drivers/atm/nicstar.c
30727+++ b/drivers/atm/nicstar.c
30728@@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30729 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
30730 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
30731 card->index);
30732- atomic_inc(&vcc->stats->tx_err);
30733+ atomic_inc_unchecked(&vcc->stats->tx_err);
30734 dev_kfree_skb_any(skb);
30735 return -EINVAL;
30736 }
30737@@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30738 if (!vc->tx) {
30739 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
30740 card->index);
30741- atomic_inc(&vcc->stats->tx_err);
30742+ atomic_inc_unchecked(&vcc->stats->tx_err);
30743 dev_kfree_skb_any(skb);
30744 return -EINVAL;
30745 }
30746@@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30747 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
30748 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
30749 card->index);
30750- atomic_inc(&vcc->stats->tx_err);
30751+ atomic_inc_unchecked(&vcc->stats->tx_err);
30752 dev_kfree_skb_any(skb);
30753 return -EINVAL;
30754 }
30755
30756 if (skb_shinfo(skb)->nr_frags != 0) {
30757 printk("nicstar%d: No scatter-gather yet.\n", card->index);
30758- atomic_inc(&vcc->stats->tx_err);
30759+ atomic_inc_unchecked(&vcc->stats->tx_err);
30760 dev_kfree_skb_any(skb);
30761 return -EINVAL;
30762 }
30763@@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
30764 }
30765
30766 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
30767- atomic_inc(&vcc->stats->tx_err);
30768+ atomic_inc_unchecked(&vcc->stats->tx_err);
30769 dev_kfree_skb_any(skb);
30770 return -EIO;
30771 }
30772- atomic_inc(&vcc->stats->tx);
30773+ atomic_inc_unchecked(&vcc->stats->tx);
30774
30775 return 0;
30776 }
30777@@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30778 printk
30779 ("nicstar%d: Can't allocate buffers for aal0.\n",
30780 card->index);
30781- atomic_add(i, &vcc->stats->rx_drop);
30782+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
30783 break;
30784 }
30785 if (!atm_charge(vcc, sb->truesize)) {
30786 RXPRINTK
30787 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
30788 card->index);
30789- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30790+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
30791 dev_kfree_skb_any(sb);
30792 break;
30793 }
30794@@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30795 ATM_SKB(sb)->vcc = vcc;
30796 __net_timestamp(sb);
30797 vcc->push(vcc, sb);
30798- atomic_inc(&vcc->stats->rx);
30799+ atomic_inc_unchecked(&vcc->stats->rx);
30800 cell += ATM_CELL_PAYLOAD;
30801 }
30802
30803@@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30804 if (iovb == NULL) {
30805 printk("nicstar%d: Out of iovec buffers.\n",
30806 card->index);
30807- atomic_inc(&vcc->stats->rx_drop);
30808+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30809 recycle_rx_buf(card, skb);
30810 return;
30811 }
30812@@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30813 small or large buffer itself. */
30814 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
30815 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
30816- atomic_inc(&vcc->stats->rx_err);
30817+ atomic_inc_unchecked(&vcc->stats->rx_err);
30818 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30819 NS_MAX_IOVECS);
30820 NS_PRV_IOVCNT(iovb) = 0;
30821@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30822 ("nicstar%d: Expected a small buffer, and this is not one.\n",
30823 card->index);
30824 which_list(card, skb);
30825- atomic_inc(&vcc->stats->rx_err);
30826+ atomic_inc_unchecked(&vcc->stats->rx_err);
30827 recycle_rx_buf(card, skb);
30828 vc->rx_iov = NULL;
30829 recycle_iov_buf(card, iovb);
30830@@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30831 ("nicstar%d: Expected a large buffer, and this is not one.\n",
30832 card->index);
30833 which_list(card, skb);
30834- atomic_inc(&vcc->stats->rx_err);
30835+ atomic_inc_unchecked(&vcc->stats->rx_err);
30836 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30837 NS_PRV_IOVCNT(iovb));
30838 vc->rx_iov = NULL;
30839@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30840 printk(" - PDU size mismatch.\n");
30841 else
30842 printk(".\n");
30843- atomic_inc(&vcc->stats->rx_err);
30844+ atomic_inc_unchecked(&vcc->stats->rx_err);
30845 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
30846 NS_PRV_IOVCNT(iovb));
30847 vc->rx_iov = NULL;
30848@@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30849 /* skb points to a small buffer */
30850 if (!atm_charge(vcc, skb->truesize)) {
30851 push_rxbufs(card, skb);
30852- atomic_inc(&vcc->stats->rx_drop);
30853+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30854 } else {
30855 skb_put(skb, len);
30856 dequeue_sm_buf(card, skb);
30857@@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30858 ATM_SKB(skb)->vcc = vcc;
30859 __net_timestamp(skb);
30860 vcc->push(vcc, skb);
30861- atomic_inc(&vcc->stats->rx);
30862+ atomic_inc_unchecked(&vcc->stats->rx);
30863 }
30864 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
30865 struct sk_buff *sb;
30866@@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30867 if (len <= NS_SMBUFSIZE) {
30868 if (!atm_charge(vcc, sb->truesize)) {
30869 push_rxbufs(card, sb);
30870- atomic_inc(&vcc->stats->rx_drop);
30871+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30872 } else {
30873 skb_put(sb, len);
30874 dequeue_sm_buf(card, sb);
30875@@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30876 ATM_SKB(sb)->vcc = vcc;
30877 __net_timestamp(sb);
30878 vcc->push(vcc, sb);
30879- atomic_inc(&vcc->stats->rx);
30880+ atomic_inc_unchecked(&vcc->stats->rx);
30881 }
30882
30883 push_rxbufs(card, skb);
30884@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30885
30886 if (!atm_charge(vcc, skb->truesize)) {
30887 push_rxbufs(card, skb);
30888- atomic_inc(&vcc->stats->rx_drop);
30889+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30890 } else {
30891 dequeue_lg_buf(card, skb);
30892 #ifdef NS_USE_DESTRUCTORS
30893@@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30894 ATM_SKB(skb)->vcc = vcc;
30895 __net_timestamp(skb);
30896 vcc->push(vcc, skb);
30897- atomic_inc(&vcc->stats->rx);
30898+ atomic_inc_unchecked(&vcc->stats->rx);
30899 }
30900
30901 push_rxbufs(card, sb);
30902@@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30903 printk
30904 ("nicstar%d: Out of huge buffers.\n",
30905 card->index);
30906- atomic_inc(&vcc->stats->rx_drop);
30907+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30908 recycle_iovec_rx_bufs(card,
30909 (struct iovec *)
30910 iovb->data,
30911@@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30912 card->hbpool.count++;
30913 } else
30914 dev_kfree_skb_any(hb);
30915- atomic_inc(&vcc->stats->rx_drop);
30916+ atomic_inc_unchecked(&vcc->stats->rx_drop);
30917 } else {
30918 /* Copy the small buffer to the huge buffer */
30919 sb = (struct sk_buff *)iov->iov_base;
30920@@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
30921 #endif /* NS_USE_DESTRUCTORS */
30922 __net_timestamp(hb);
30923 vcc->push(vcc, hb);
30924- atomic_inc(&vcc->stats->rx);
30925+ atomic_inc_unchecked(&vcc->stats->rx);
30926 }
30927 }
30928
30929diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
30930index 1853a45..cf2426d 100644
30931--- a/drivers/atm/solos-pci.c
30932+++ b/drivers/atm/solos-pci.c
30933@@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
30934 }
30935 atm_charge(vcc, skb->truesize);
30936 vcc->push(vcc, skb);
30937- atomic_inc(&vcc->stats->rx);
30938+ atomic_inc_unchecked(&vcc->stats->rx);
30939 break;
30940
30941 case PKT_STATUS:
30942@@ -1010,7 +1010,7 @@ static uint32_t fpga_tx(struct solos_card *card)
30943 vcc = SKB_CB(oldskb)->vcc;
30944
30945 if (vcc) {
30946- atomic_inc(&vcc->stats->tx);
30947+ atomic_inc_unchecked(&vcc->stats->tx);
30948 solos_pop(vcc, oldskb);
30949 } else
30950 dev_kfree_skb_irq(oldskb);
30951diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
30952index 0215934..ce9f5b1 100644
30953--- a/drivers/atm/suni.c
30954+++ b/drivers/atm/suni.c
30955@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
30956
30957
30958 #define ADD_LIMITED(s,v) \
30959- atomic_add((v),&stats->s); \
30960- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
30961+ atomic_add_unchecked((v),&stats->s); \
30962+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
30963
30964
30965 static void suni_hz(unsigned long from_timer)
30966diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
30967index 5120a96..e2572bd 100644
30968--- a/drivers/atm/uPD98402.c
30969+++ b/drivers/atm/uPD98402.c
30970@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
30971 struct sonet_stats tmp;
30972 int error = 0;
30973
30974- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30975+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
30976 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
30977 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
30978 if (zero && !error) {
30979@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
30980
30981
30982 #define ADD_LIMITED(s,v) \
30983- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
30984- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
30985- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30986+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
30987+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
30988+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
30989
30990
30991 static void stat_event(struct atm_dev *dev)
30992@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
30993 if (reason & uPD98402_INT_PFM) stat_event(dev);
30994 if (reason & uPD98402_INT_PCO) {
30995 (void) GET(PCOCR); /* clear interrupt cause */
30996- atomic_add(GET(HECCT),
30997+ atomic_add_unchecked(GET(HECCT),
30998 &PRIV(dev)->sonet_stats.uncorr_hcs);
30999 }
31000 if ((reason & uPD98402_INT_RFO) &&
31001@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
31002 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
31003 uPD98402_INT_LOS),PIMR); /* enable them */
31004 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
31005- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31006- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
31007- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
31008+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
31009+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
31010+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
31011 return 0;
31012 }
31013
31014diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
31015index abe4e20..83c4727 100644
31016--- a/drivers/atm/zatm.c
31017+++ b/drivers/atm/zatm.c
31018@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31019 }
31020 if (!size) {
31021 dev_kfree_skb_irq(skb);
31022- if (vcc) atomic_inc(&vcc->stats->rx_err);
31023+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
31024 continue;
31025 }
31026 if (!atm_charge(vcc,skb->truesize)) {
31027@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
31028 skb->len = size;
31029 ATM_SKB(skb)->vcc = vcc;
31030 vcc->push(vcc,skb);
31031- atomic_inc(&vcc->stats->rx);
31032+ atomic_inc_unchecked(&vcc->stats->rx);
31033 }
31034 zout(pos & 0xffff,MTA(mbx));
31035 #if 0 /* probably a stupid idea */
31036@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
31037 skb_queue_head(&zatm_vcc->backlog,skb);
31038 break;
31039 }
31040- atomic_inc(&vcc->stats->tx);
31041+ atomic_inc_unchecked(&vcc->stats->tx);
31042 wake_up(&zatm_vcc->tx_wait);
31043 }
31044
31045diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
31046index 147d1a4..d0fd4b0 100644
31047--- a/drivers/base/devtmpfs.c
31048+++ b/drivers/base/devtmpfs.c
31049@@ -347,7 +347,7 @@ int devtmpfs_mount(const char *mntdir)
31050 if (!thread)
31051 return 0;
31052
31053- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
31054+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
31055 if (err)
31056 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
31057 else
31058diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
31059index e6ee5e8..98ad7fc 100644
31060--- a/drivers/base/power/wakeup.c
31061+++ b/drivers/base/power/wakeup.c
31062@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
31063 * They need to be modified together atomically, so it's better to use one
31064 * atomic variable to hold them both.
31065 */
31066-static atomic_t combined_event_count = ATOMIC_INIT(0);
31067+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
31068
31069 #define IN_PROGRESS_BITS (sizeof(int) * 4)
31070 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
31071
31072 static void split_counters(unsigned int *cnt, unsigned int *inpr)
31073 {
31074- unsigned int comb = atomic_read(&combined_event_count);
31075+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
31076
31077 *cnt = (comb >> IN_PROGRESS_BITS);
31078 *inpr = comb & MAX_IN_PROGRESS;
31079@@ -389,7 +389,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
31080 ws->start_prevent_time = ws->last_time;
31081
31082 /* Increment the counter of events in progress. */
31083- cec = atomic_inc_return(&combined_event_count);
31084+ cec = atomic_inc_return_unchecked(&combined_event_count);
31085
31086 trace_wakeup_source_activate(ws->name, cec);
31087 }
31088@@ -515,7 +515,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
31089 * Increment the counter of registered wakeup events and decrement the
31090 * couter of wakeup events in progress simultaneously.
31091 */
31092- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
31093+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
31094 trace_wakeup_source_deactivate(ws->name, cec);
31095
31096 split_counters(&cnt, &inpr);
31097diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
31098index ca83f96..69d4ea9 100644
31099--- a/drivers/block/cciss.c
31100+++ b/drivers/block/cciss.c
31101@@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
31102 int err;
31103 u32 cp;
31104
31105+ memset(&arg64, 0, sizeof(arg64));
31106+
31107 err = 0;
31108 err |=
31109 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
31110@@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
31111 while (!list_empty(&h->reqQ)) {
31112 c = list_entry(h->reqQ.next, CommandList_struct, list);
31113 /* can't do anything if fifo is full */
31114- if ((h->access.fifo_full(h))) {
31115+ if ((h->access->fifo_full(h))) {
31116 dev_warn(&h->pdev->dev, "fifo full\n");
31117 break;
31118 }
31119@@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
31120 h->Qdepth--;
31121
31122 /* Tell the controller execute command */
31123- h->access.submit_command(h, c);
31124+ h->access->submit_command(h, c);
31125
31126 /* Put job onto the completed Q */
31127 addQ(&h->cmpQ, c);
31128@@ -3443,17 +3445,17 @@ startio:
31129
31130 static inline unsigned long get_next_completion(ctlr_info_t *h)
31131 {
31132- return h->access.command_completed(h);
31133+ return h->access->command_completed(h);
31134 }
31135
31136 static inline int interrupt_pending(ctlr_info_t *h)
31137 {
31138- return h->access.intr_pending(h);
31139+ return h->access->intr_pending(h);
31140 }
31141
31142 static inline long interrupt_not_for_us(ctlr_info_t *h)
31143 {
31144- return ((h->access.intr_pending(h) == 0) ||
31145+ return ((h->access->intr_pending(h) == 0) ||
31146 (h->interrupts_enabled == 0));
31147 }
31148
31149@@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
31150 u32 a;
31151
31152 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
31153- return h->access.command_completed(h);
31154+ return h->access->command_completed(h);
31155
31156 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
31157 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
31158@@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
31159 trans_support & CFGTBL_Trans_use_short_tags);
31160
31161 /* Change the access methods to the performant access methods */
31162- h->access = SA5_performant_access;
31163+ h->access = &SA5_performant_access;
31164 h->transMethod = CFGTBL_Trans_Performant;
31165
31166 return;
31167@@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
31168 if (prod_index < 0)
31169 return -ENODEV;
31170 h->product_name = products[prod_index].product_name;
31171- h->access = *(products[prod_index].access);
31172+ h->access = products[prod_index].access;
31173
31174 if (cciss_board_disabled(h)) {
31175 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
31176@@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
31177 }
31178
31179 /* make sure the board interrupts are off */
31180- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31181+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31182 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
31183 if (rc)
31184 goto clean2;
31185@@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
31186 * fake ones to scoop up any residual completions.
31187 */
31188 spin_lock_irqsave(&h->lock, flags);
31189- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31190+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31191 spin_unlock_irqrestore(&h->lock, flags);
31192 free_irq(h->intr[h->intr_mode], h);
31193 rc = cciss_request_irq(h, cciss_msix_discard_completions,
31194@@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
31195 dev_info(&h->pdev->dev, "Board READY.\n");
31196 dev_info(&h->pdev->dev,
31197 "Waiting for stale completions to drain.\n");
31198- h->access.set_intr_mask(h, CCISS_INTR_ON);
31199+ h->access->set_intr_mask(h, CCISS_INTR_ON);
31200 msleep(10000);
31201- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31202+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31203
31204 rc = controller_reset_failed(h->cfgtable);
31205 if (rc)
31206@@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
31207 cciss_scsi_setup(h);
31208
31209 /* Turn the interrupts on so we can service requests */
31210- h->access.set_intr_mask(h, CCISS_INTR_ON);
31211+ h->access->set_intr_mask(h, CCISS_INTR_ON);
31212
31213 /* Get the firmware version */
31214 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
31215@@ -5210,7 +5212,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
31216 kfree(flush_buf);
31217 if (return_code != IO_OK)
31218 dev_warn(&h->pdev->dev, "Error flushing cache\n");
31219- h->access.set_intr_mask(h, CCISS_INTR_OFF);
31220+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
31221 free_irq(h->intr[h->intr_mode], h);
31222 }
31223
31224diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
31225index 7fda30e..eb5dfe0 100644
31226--- a/drivers/block/cciss.h
31227+++ b/drivers/block/cciss.h
31228@@ -101,7 +101,7 @@ struct ctlr_info
31229 /* information about each logical volume */
31230 drive_info_struct *drv[CISS_MAX_LUN];
31231
31232- struct access_method access;
31233+ struct access_method *access;
31234
31235 /* queue and queue Info */
31236 struct list_head reqQ;
31237diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
31238index 9125bbe..eede5c8 100644
31239--- a/drivers/block/cpqarray.c
31240+++ b/drivers/block/cpqarray.c
31241@@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31242 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
31243 goto Enomem4;
31244 }
31245- hba[i]->access.set_intr_mask(hba[i], 0);
31246+ hba[i]->access->set_intr_mask(hba[i], 0);
31247 if (request_irq(hba[i]->intr, do_ida_intr,
31248 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
31249 {
31250@@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
31251 add_timer(&hba[i]->timer);
31252
31253 /* Enable IRQ now that spinlock and rate limit timer are set up */
31254- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31255+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
31256
31257 for(j=0; j<NWD; j++) {
31258 struct gendisk *disk = ida_gendisk[i][j];
31259@@ -694,7 +694,7 @@ DBGINFO(
31260 for(i=0; i<NR_PRODUCTS; i++) {
31261 if (board_id == products[i].board_id) {
31262 c->product_name = products[i].product_name;
31263- c->access = *(products[i].access);
31264+ c->access = products[i].access;
31265 break;
31266 }
31267 }
31268@@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
31269 hba[ctlr]->intr = intr;
31270 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
31271 hba[ctlr]->product_name = products[j].product_name;
31272- hba[ctlr]->access = *(products[j].access);
31273+ hba[ctlr]->access = products[j].access;
31274 hba[ctlr]->ctlr = ctlr;
31275 hba[ctlr]->board_id = board_id;
31276 hba[ctlr]->pci_dev = NULL; /* not PCI */
31277@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
31278
31279 while((c = h->reqQ) != NULL) {
31280 /* Can't do anything if we're busy */
31281- if (h->access.fifo_full(h) == 0)
31282+ if (h->access->fifo_full(h) == 0)
31283 return;
31284
31285 /* Get the first entry from the request Q */
31286@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
31287 h->Qdepth--;
31288
31289 /* Tell the controller to do our bidding */
31290- h->access.submit_command(h, c);
31291+ h->access->submit_command(h, c);
31292
31293 /* Get onto the completion Q */
31294 addQ(&h->cmpQ, c);
31295@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31296 unsigned long flags;
31297 __u32 a,a1;
31298
31299- istat = h->access.intr_pending(h);
31300+ istat = h->access->intr_pending(h);
31301 /* Is this interrupt for us? */
31302 if (istat == 0)
31303 return IRQ_NONE;
31304@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
31305 */
31306 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
31307 if (istat & FIFO_NOT_EMPTY) {
31308- while((a = h->access.command_completed(h))) {
31309+ while((a = h->access->command_completed(h))) {
31310 a1 = a; a &= ~3;
31311 if ((c = h->cmpQ) == NULL)
31312 {
31313@@ -1449,11 +1449,11 @@ static int sendcmd(
31314 /*
31315 * Disable interrupt
31316 */
31317- info_p->access.set_intr_mask(info_p, 0);
31318+ info_p->access->set_intr_mask(info_p, 0);
31319 /* Make sure there is room in the command FIFO */
31320 /* Actually it should be completely empty at this time. */
31321 for (i = 200000; i > 0; i--) {
31322- temp = info_p->access.fifo_full(info_p);
31323+ temp = info_p->access->fifo_full(info_p);
31324 if (temp != 0) {
31325 break;
31326 }
31327@@ -1466,7 +1466,7 @@ DBG(
31328 /*
31329 * Send the cmd
31330 */
31331- info_p->access.submit_command(info_p, c);
31332+ info_p->access->submit_command(info_p, c);
31333 complete = pollcomplete(ctlr);
31334
31335 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
31336@@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
31337 * we check the new geometry. Then turn interrupts back on when
31338 * we're done.
31339 */
31340- host->access.set_intr_mask(host, 0);
31341+ host->access->set_intr_mask(host, 0);
31342 getgeometry(ctlr);
31343- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
31344+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
31345
31346 for(i=0; i<NWD; i++) {
31347 struct gendisk *disk = ida_gendisk[ctlr][i];
31348@@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
31349 /* Wait (up to 2 seconds) for a command to complete */
31350
31351 for (i = 200000; i > 0; i--) {
31352- done = hba[ctlr]->access.command_completed(hba[ctlr]);
31353+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
31354 if (done == 0) {
31355 udelay(10); /* a short fixed delay */
31356 } else
31357diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
31358index be73e9d..7fbf140 100644
31359--- a/drivers/block/cpqarray.h
31360+++ b/drivers/block/cpqarray.h
31361@@ -99,7 +99,7 @@ struct ctlr_info {
31362 drv_info_t drv[NWD];
31363 struct proc_dir_entry *proc;
31364
31365- struct access_method access;
31366+ struct access_method *access;
31367
31368 cmdlist_t *reqQ;
31369 cmdlist_t *cmpQ;
31370diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
31371index b953cc7..e3dc580 100644
31372--- a/drivers/block/drbd/drbd_int.h
31373+++ b/drivers/block/drbd/drbd_int.h
31374@@ -735,7 +735,7 @@ struct drbd_request;
31375 struct drbd_epoch {
31376 struct list_head list;
31377 unsigned int barrier_nr;
31378- atomic_t epoch_size; /* increased on every request added. */
31379+ atomic_unchecked_t epoch_size; /* increased on every request added. */
31380 atomic_t active; /* increased on every req. added, and dec on every finished. */
31381 unsigned long flags;
31382 };
31383@@ -1116,7 +1116,7 @@ struct drbd_conf {
31384 void *int_dig_in;
31385 void *int_dig_vv;
31386 wait_queue_head_t seq_wait;
31387- atomic_t packet_seq;
31388+ atomic_unchecked_t packet_seq;
31389 unsigned int peer_seq;
31390 spinlock_t peer_seq_lock;
31391 unsigned int minor;
31392@@ -1658,30 +1658,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
31393
31394 static inline void drbd_tcp_cork(struct socket *sock)
31395 {
31396- int __user val = 1;
31397+ int val = 1;
31398 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31399- (char __user *)&val, sizeof(val));
31400+ (char __force_user *)&val, sizeof(val));
31401 }
31402
31403 static inline void drbd_tcp_uncork(struct socket *sock)
31404 {
31405- int __user val = 0;
31406+ int val = 0;
31407 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
31408- (char __user *)&val, sizeof(val));
31409+ (char __force_user *)&val, sizeof(val));
31410 }
31411
31412 static inline void drbd_tcp_nodelay(struct socket *sock)
31413 {
31414- int __user val = 1;
31415+ int val = 1;
31416 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
31417- (char __user *)&val, sizeof(val));
31418+ (char __force_user *)&val, sizeof(val));
31419 }
31420
31421 static inline void drbd_tcp_quickack(struct socket *sock)
31422 {
31423- int __user val = 2;
31424+ int val = 2;
31425 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
31426- (char __user *)&val, sizeof(val));
31427+ (char __force_user *)&val, sizeof(val));
31428 }
31429
31430 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
31431diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
31432index f55683a..2101b96 100644
31433--- a/drivers/block/drbd/drbd_main.c
31434+++ b/drivers/block/drbd/drbd_main.c
31435@@ -2556,7 +2556,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
31436 p.sector = sector;
31437 p.block_id = block_id;
31438 p.blksize = blksize;
31439- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31440+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31441
31442 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
31443 return false;
31444@@ -2854,7 +2854,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
31445
31446 p.sector = cpu_to_be64(req->sector);
31447 p.block_id = (unsigned long)req;
31448- p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
31449+ p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
31450
31451 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
31452
31453@@ -3139,7 +3139,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
31454 atomic_set(&mdev->unacked_cnt, 0);
31455 atomic_set(&mdev->local_cnt, 0);
31456 atomic_set(&mdev->net_cnt, 0);
31457- atomic_set(&mdev->packet_seq, 0);
31458+ atomic_set_unchecked(&mdev->packet_seq, 0);
31459 atomic_set(&mdev->pp_in_use, 0);
31460 atomic_set(&mdev->pp_in_use_by_net, 0);
31461 atomic_set(&mdev->rs_sect_in, 0);
31462@@ -3221,8 +3221,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
31463 mdev->receiver.t_state);
31464
31465 /* no need to lock it, I'm the only thread alive */
31466- if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
31467- dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
31468+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
31469+ dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
31470 mdev->al_writ_cnt =
31471 mdev->bm_writ_cnt =
31472 mdev->read_cnt =
31473diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
31474index edb490a..ecd69da 100644
31475--- a/drivers/block/drbd/drbd_nl.c
31476+++ b/drivers/block/drbd/drbd_nl.c
31477@@ -2407,7 +2407,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
31478 module_put(THIS_MODULE);
31479 }
31480
31481-static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31482+static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
31483
31484 static unsigned short *
31485 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
31486@@ -2478,7 +2478,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
31487 cn_reply->id.idx = CN_IDX_DRBD;
31488 cn_reply->id.val = CN_VAL_DRBD;
31489
31490- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31491+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31492 cn_reply->ack = 0; /* not used here. */
31493 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31494 (int)((char *)tl - (char *)reply->tag_list);
31495@@ -2510,7 +2510,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
31496 cn_reply->id.idx = CN_IDX_DRBD;
31497 cn_reply->id.val = CN_VAL_DRBD;
31498
31499- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31500+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31501 cn_reply->ack = 0; /* not used here. */
31502 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31503 (int)((char *)tl - (char *)reply->tag_list);
31504@@ -2588,7 +2588,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
31505 cn_reply->id.idx = CN_IDX_DRBD;
31506 cn_reply->id.val = CN_VAL_DRBD;
31507
31508- cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
31509+ cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
31510 cn_reply->ack = 0; // not used here.
31511 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31512 (int)((char*)tl - (char*)reply->tag_list);
31513@@ -2627,7 +2627,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
31514 cn_reply->id.idx = CN_IDX_DRBD;
31515 cn_reply->id.val = CN_VAL_DRBD;
31516
31517- cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
31518+ cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
31519 cn_reply->ack = 0; /* not used here. */
31520 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
31521 (int)((char *)tl - (char *)reply->tag_list);
31522diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
31523index c74ca2d..860c819 100644
31524--- a/drivers/block/drbd/drbd_receiver.c
31525+++ b/drivers/block/drbd/drbd_receiver.c
31526@@ -898,7 +898,7 @@ retry:
31527 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
31528 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
31529
31530- atomic_set(&mdev->packet_seq, 0);
31531+ atomic_set_unchecked(&mdev->packet_seq, 0);
31532 mdev->peer_seq = 0;
31533
31534 if (drbd_send_protocol(mdev) == -1)
31535@@ -999,7 +999,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31536 do {
31537 next_epoch = NULL;
31538
31539- epoch_size = atomic_read(&epoch->epoch_size);
31540+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
31541
31542 switch (ev & ~EV_CLEANUP) {
31543 case EV_PUT:
31544@@ -1035,7 +1035,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
31545 rv = FE_DESTROYED;
31546 } else {
31547 epoch->flags = 0;
31548- atomic_set(&epoch->epoch_size, 0);
31549+ atomic_set_unchecked(&epoch->epoch_size, 0);
31550 /* atomic_set(&epoch->active, 0); is already zero */
31551 if (rv == FE_STILL_LIVE)
31552 rv = FE_RECYCLED;
31553@@ -1210,14 +1210,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31554 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
31555 drbd_flush(mdev);
31556
31557- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31558+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31559 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
31560 if (epoch)
31561 break;
31562 }
31563
31564 epoch = mdev->current_epoch;
31565- wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
31566+ wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
31567
31568 D_ASSERT(atomic_read(&epoch->active) == 0);
31569 D_ASSERT(epoch->flags == 0);
31570@@ -1229,11 +1229,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
31571 }
31572
31573 epoch->flags = 0;
31574- atomic_set(&epoch->epoch_size, 0);
31575+ atomic_set_unchecked(&epoch->epoch_size, 0);
31576 atomic_set(&epoch->active, 0);
31577
31578 spin_lock(&mdev->epoch_lock);
31579- if (atomic_read(&mdev->current_epoch->epoch_size)) {
31580+ if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
31581 list_add(&epoch->list, &mdev->current_epoch->list);
31582 mdev->current_epoch = epoch;
31583 mdev->epochs++;
31584@@ -1702,7 +1702,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31585 spin_unlock(&mdev->peer_seq_lock);
31586
31587 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
31588- atomic_inc(&mdev->current_epoch->epoch_size);
31589+ atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
31590 return drbd_drain_block(mdev, data_size);
31591 }
31592
31593@@ -1732,7 +1732,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
31594
31595 spin_lock(&mdev->epoch_lock);
31596 e->epoch = mdev->current_epoch;
31597- atomic_inc(&e->epoch->epoch_size);
31598+ atomic_inc_unchecked(&e->epoch->epoch_size);
31599 atomic_inc(&e->epoch->active);
31600 spin_unlock(&mdev->epoch_lock);
31601
31602@@ -3954,7 +3954,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
31603 D_ASSERT(list_empty(&mdev->done_ee));
31604
31605 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
31606- atomic_set(&mdev->current_epoch->epoch_size, 0);
31607+ atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
31608 D_ASSERT(list_empty(&mdev->current_epoch->list));
31609 }
31610
31611diff --git a/drivers/block/loop.c b/drivers/block/loop.c
31612index 54046e5..7759c55 100644
31613--- a/drivers/block/loop.c
31614+++ b/drivers/block/loop.c
31615@@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
31616 mm_segment_t old_fs = get_fs();
31617
31618 set_fs(get_ds());
31619- bw = file->f_op->write(file, buf, len, &pos);
31620+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
31621 set_fs(old_fs);
31622 if (likely(bw == len))
31623 return 0;
31624diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
31625index d620b44..587561e 100644
31626--- a/drivers/cdrom/cdrom.c
31627+++ b/drivers/cdrom/cdrom.c
31628@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
31629 ENSURE(reset, CDC_RESET);
31630 ENSURE(generic_packet, CDC_GENERIC_PACKET);
31631 cdi->mc_flags = 0;
31632- cdo->n_minors = 0;
31633 cdi->options = CDO_USE_FFLAGS;
31634
31635 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
31636@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
31637 else
31638 cdi->cdda_method = CDDA_OLD;
31639
31640- if (!cdo->generic_packet)
31641- cdo->generic_packet = cdrom_dummy_generic_packet;
31642+ if (!cdo->generic_packet) {
31643+ pax_open_kernel();
31644+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
31645+ pax_close_kernel();
31646+ }
31647
31648 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
31649 mutex_lock(&cdrom_mutex);
31650@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
31651 if (cdi->exit)
31652 cdi->exit(cdi);
31653
31654- cdi->ops->n_minors--;
31655 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
31656 }
31657
31658diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
31659index 75d485a..2809958 100644
31660--- a/drivers/cdrom/gdrom.c
31661+++ b/drivers/cdrom/gdrom.c
31662@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
31663 .audio_ioctl = gdrom_audio_ioctl,
31664 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
31665 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
31666- .n_minors = 1,
31667 };
31668
31669 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
31670diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
31671index 72bedad..8181ce1 100644
31672--- a/drivers/char/Kconfig
31673+++ b/drivers/char/Kconfig
31674@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
31675
31676 config DEVKMEM
31677 bool "/dev/kmem virtual device support"
31678- default y
31679+ default n
31680+ depends on !GRKERNSEC_KMEM
31681 help
31682 Say Y here if you want to support the /dev/kmem device. The
31683 /dev/kmem device is rarely used, but can be used for certain
31684@@ -581,6 +582,7 @@ config DEVPORT
31685 bool
31686 depends on !M68K
31687 depends on ISA || PCI
31688+ depends on !GRKERNSEC_KMEM
31689 default y
31690
31691 source "drivers/s390/char/Kconfig"
31692diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
31693index 2e04433..22afc64 100644
31694--- a/drivers/char/agp/frontend.c
31695+++ b/drivers/char/agp/frontend.c
31696@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
31697 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
31698 return -EFAULT;
31699
31700- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
31701+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
31702 return -EFAULT;
31703
31704 client = agp_find_client_by_pid(reserve.pid);
31705diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
31706index 21cb980..f15107c 100644
31707--- a/drivers/char/genrtc.c
31708+++ b/drivers/char/genrtc.c
31709@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
31710 switch (cmd) {
31711
31712 case RTC_PLL_GET:
31713+ memset(&pll, 0, sizeof(pll));
31714 if (get_rtc_pll(&pll))
31715 return -EINVAL;
31716 else
31717diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
31718index dfd7876..c0b0885 100644
31719--- a/drivers/char/hpet.c
31720+++ b/drivers/char/hpet.c
31721@@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
31722 }
31723
31724 static int
31725-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
31726+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
31727 struct hpet_info *info)
31728 {
31729 struct hpet_timer __iomem *timer;
31730diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
31731index a0c84bb..9edcf60 100644
31732--- a/drivers/char/ipmi/ipmi_msghandler.c
31733+++ b/drivers/char/ipmi/ipmi_msghandler.c
31734@@ -420,7 +420,7 @@ struct ipmi_smi {
31735 struct proc_dir_entry *proc_dir;
31736 char proc_dir_name[10];
31737
31738- atomic_t stats[IPMI_NUM_STATS];
31739+ atomic_unchecked_t stats[IPMI_NUM_STATS];
31740
31741 /*
31742 * run_to_completion duplicate of smb_info, smi_info
31743@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
31744
31745
31746 #define ipmi_inc_stat(intf, stat) \
31747- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
31748+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
31749 #define ipmi_get_stat(intf, stat) \
31750- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
31751+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
31752
31753 static int is_lan_addr(struct ipmi_addr *addr)
31754 {
31755@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
31756 INIT_LIST_HEAD(&intf->cmd_rcvrs);
31757 init_waitqueue_head(&intf->waitq);
31758 for (i = 0; i < IPMI_NUM_STATS; i++)
31759- atomic_set(&intf->stats[i], 0);
31760+ atomic_set_unchecked(&intf->stats[i], 0);
31761
31762 intf->proc_dir = NULL;
31763
31764diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
31765index 32a6c7e..f6966a9 100644
31766--- a/drivers/char/ipmi/ipmi_si_intf.c
31767+++ b/drivers/char/ipmi/ipmi_si_intf.c
31768@@ -275,7 +275,7 @@ struct smi_info {
31769 unsigned char slave_addr;
31770
31771 /* Counters and things for the proc filesystem. */
31772- atomic_t stats[SI_NUM_STATS];
31773+ atomic_unchecked_t stats[SI_NUM_STATS];
31774
31775 struct task_struct *thread;
31776
31777@@ -284,9 +284,9 @@ struct smi_info {
31778 };
31779
31780 #define smi_inc_stat(smi, stat) \
31781- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
31782+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
31783 #define smi_get_stat(smi, stat) \
31784- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
31785+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
31786
31787 #define SI_MAX_PARMS 4
31788
31789@@ -3225,7 +3225,7 @@ static int try_smi_init(struct smi_info *new_smi)
31790 atomic_set(&new_smi->req_events, 0);
31791 new_smi->run_to_completion = 0;
31792 for (i = 0; i < SI_NUM_STATS; i++)
31793- atomic_set(&new_smi->stats[i], 0);
31794+ atomic_set_unchecked(&new_smi->stats[i], 0);
31795
31796 new_smi->interrupt_disabled = 1;
31797 atomic_set(&new_smi->stop_operation, 0);
31798diff --git a/drivers/char/mem.c b/drivers/char/mem.c
31799index 0537903..121c699 100644
31800--- a/drivers/char/mem.c
31801+++ b/drivers/char/mem.c
31802@@ -18,6 +18,7 @@
31803 #include <linux/raw.h>
31804 #include <linux/tty.h>
31805 #include <linux/capability.h>
31806+#include <linux/security.h>
31807 #include <linux/ptrace.h>
31808 #include <linux/device.h>
31809 #include <linux/highmem.h>
31810@@ -37,6 +38,10 @@
31811
31812 #define DEVPORT_MINOR 4
31813
31814+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31815+extern const struct file_operations grsec_fops;
31816+#endif
31817+
31818 static inline unsigned long size_inside_page(unsigned long start,
31819 unsigned long size)
31820 {
31821@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31822
31823 while (cursor < to) {
31824 if (!devmem_is_allowed(pfn)) {
31825+#ifdef CONFIG_GRKERNSEC_KMEM
31826+ gr_handle_mem_readwrite(from, to);
31827+#else
31828 printk(KERN_INFO
31829 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
31830 current->comm, from, to);
31831+#endif
31832 return 0;
31833 }
31834 cursor += PAGE_SIZE;
31835@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31836 }
31837 return 1;
31838 }
31839+#elif defined(CONFIG_GRKERNSEC_KMEM)
31840+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31841+{
31842+ return 0;
31843+}
31844 #else
31845 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31846 {
31847@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31848
31849 while (count > 0) {
31850 unsigned long remaining;
31851+ char *temp;
31852
31853 sz = size_inside_page(p, count);
31854
31855@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
31856 if (!ptr)
31857 return -EFAULT;
31858
31859- remaining = copy_to_user(buf, ptr, sz);
31860+#ifdef CONFIG_PAX_USERCOPY
31861+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31862+ if (!temp) {
31863+ unxlate_dev_mem_ptr(p, ptr);
31864+ return -ENOMEM;
31865+ }
31866+ memcpy(temp, ptr, sz);
31867+#else
31868+ temp = ptr;
31869+#endif
31870+
31871+ remaining = copy_to_user(buf, temp, sz);
31872+
31873+#ifdef CONFIG_PAX_USERCOPY
31874+ kfree(temp);
31875+#endif
31876+
31877 unxlate_dev_mem_ptr(p, ptr);
31878 if (remaining)
31879 return -EFAULT;
31880@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31881 size_t count, loff_t *ppos)
31882 {
31883 unsigned long p = *ppos;
31884- ssize_t low_count, read, sz;
31885+ ssize_t low_count, read, sz, err = 0;
31886 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
31887- int err = 0;
31888
31889 read = 0;
31890 if (p < (unsigned long) high_memory) {
31891@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31892 }
31893 #endif
31894 while (low_count > 0) {
31895+ char *temp;
31896+
31897 sz = size_inside_page(p, low_count);
31898
31899 /*
31900@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
31901 */
31902 kbuf = xlate_dev_kmem_ptr((char *)p);
31903
31904- if (copy_to_user(buf, kbuf, sz))
31905+#ifdef CONFIG_PAX_USERCOPY
31906+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
31907+ if (!temp)
31908+ return -ENOMEM;
31909+ memcpy(temp, kbuf, sz);
31910+#else
31911+ temp = kbuf;
31912+#endif
31913+
31914+ err = copy_to_user(buf, temp, sz);
31915+
31916+#ifdef CONFIG_PAX_USERCOPY
31917+ kfree(temp);
31918+#endif
31919+
31920+ if (err)
31921 return -EFAULT;
31922 buf += sz;
31923 p += sz;
31924@@ -833,6 +880,9 @@ static const struct memdev {
31925 #ifdef CONFIG_CRASH_DUMP
31926 [12] = { "oldmem", 0, &oldmem_fops, NULL },
31927 #endif
31928+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
31929+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
31930+#endif
31931 };
31932
31933 static int memory_open(struct inode *inode, struct file *filp)
31934diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
31935index 9df78e2..01ba9ae 100644
31936--- a/drivers/char/nvram.c
31937+++ b/drivers/char/nvram.c
31938@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
31939
31940 spin_unlock_irq(&rtc_lock);
31941
31942- if (copy_to_user(buf, contents, tmp - contents))
31943+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
31944 return -EFAULT;
31945
31946 *ppos = i;
31947diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
31948index 21721d2..4e98777 100644
31949--- a/drivers/char/pcmcia/synclink_cs.c
31950+++ b/drivers/char/pcmcia/synclink_cs.c
31951@@ -2346,9 +2346,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31952
31953 if (debug_level >= DEBUG_LEVEL_INFO)
31954 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
31955- __FILE__,__LINE__, info->device_name, port->count);
31956+ __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
31957
31958- WARN_ON(!port->count);
31959+ WARN_ON(!atomic_read(&port->count));
31960
31961 if (tty_port_close_start(port, tty, filp) == 0)
31962 goto cleanup;
31963@@ -2366,7 +2366,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
31964 cleanup:
31965 if (debug_level >= DEBUG_LEVEL_INFO)
31966 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
31967- tty->driver->name, port->count);
31968+ tty->driver->name, atomic_read(&port->count));
31969 }
31970
31971 /* Wait until the transmitter is empty.
31972@@ -2508,7 +2508,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31973
31974 if (debug_level >= DEBUG_LEVEL_INFO)
31975 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
31976- __FILE__,__LINE__,tty->driver->name, port->count);
31977+ __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
31978
31979 /* If port is closing, signal caller to try again */
31980 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
31981@@ -2528,11 +2528,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
31982 goto cleanup;
31983 }
31984 spin_lock(&port->lock);
31985- port->count++;
31986+ atomic_inc(&port->count);
31987 spin_unlock(&port->lock);
31988 spin_unlock_irqrestore(&info->netlock, flags);
31989
31990- if (port->count == 1) {
31991+ if (atomic_read(&port->count) == 1) {
31992 /* 1st open on this device, init hardware */
31993 retval = startup(info, tty);
31994 if (retval < 0)
31995@@ -3886,7 +3886,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
31996 unsigned short new_crctype;
31997
31998 /* return error if TTY interface open */
31999- if (info->port.count)
32000+ if (atomic_read(&info->port.count))
32001 return -EBUSY;
32002
32003 switch (encoding)
32004@@ -3989,7 +3989,7 @@ static int hdlcdev_open(struct net_device *dev)
32005
32006 /* arbitrate between network and tty opens */
32007 spin_lock_irqsave(&info->netlock, flags);
32008- if (info->port.count != 0 || info->netcount != 0) {
32009+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
32010 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
32011 spin_unlock_irqrestore(&info->netlock, flags);
32012 return -EBUSY;
32013@@ -4078,7 +4078,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
32014 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
32015
32016 /* return error if TTY interface open */
32017- if (info->port.count)
32018+ if (atomic_read(&info->port.count))
32019 return -EBUSY;
32020
32021 if (cmd != SIOCWANDEV)
32022diff --git a/drivers/char/random.c b/drivers/char/random.c
32023index b86eae9..b9c2ed7 100644
32024--- a/drivers/char/random.c
32025+++ b/drivers/char/random.c
32026@@ -272,8 +272,13 @@
32027 /*
32028 * Configuration information
32029 */
32030+#ifdef CONFIG_GRKERNSEC_RANDNET
32031+#define INPUT_POOL_WORDS 512
32032+#define OUTPUT_POOL_WORDS 128
32033+#else
32034 #define INPUT_POOL_WORDS 128
32035 #define OUTPUT_POOL_WORDS 32
32036+#endif
32037 #define SEC_XFER_SIZE 512
32038 #define EXTRACT_SIZE 10
32039
32040@@ -313,10 +318,17 @@ static struct poolinfo {
32041 int poolwords;
32042 int tap1, tap2, tap3, tap4, tap5;
32043 } poolinfo_table[] = {
32044+#ifdef CONFIG_GRKERNSEC_RANDNET
32045+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
32046+ { 512, 411, 308, 208, 104, 1 },
32047+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
32048+ { 128, 103, 76, 51, 25, 1 },
32049+#else
32050 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
32051 { 128, 103, 76, 51, 25, 1 },
32052 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
32053 { 32, 26, 20, 14, 7, 1 },
32054+#endif
32055 #if 0
32056 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
32057 { 2048, 1638, 1231, 819, 411, 1 },
32058@@ -437,6 +449,7 @@ struct entropy_store {
32059 int entropy_count;
32060 int entropy_total;
32061 unsigned int initialized:1;
32062+ bool last_data_init;
32063 __u8 last_data[EXTRACT_SIZE];
32064 };
32065
32066@@ -527,8 +540,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
32067 input_rotate += i ? 7 : 14;
32068 }
32069
32070- ACCESS_ONCE(r->input_rotate) = input_rotate;
32071- ACCESS_ONCE(r->add_ptr) = i;
32072+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
32073+ ACCESS_ONCE_RW(r->add_ptr) = i;
32074 smp_wmb();
32075
32076 if (out)
32077@@ -957,6 +970,10 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32078 ssize_t ret = 0, i;
32079 __u8 tmp[EXTRACT_SIZE];
32080
32081+ /* if last_data isn't primed, we need EXTRACT_SIZE extra bytes */
32082+ if (fips_enabled && !r->last_data_init)
32083+ nbytes += EXTRACT_SIZE;
32084+
32085 trace_extract_entropy(r->name, nbytes, r->entropy_count, _RET_IP_);
32086 xfer_secondary_pool(r, nbytes);
32087 nbytes = account(r, nbytes, min, reserved);
32088@@ -967,6 +984,17 @@ static ssize_t extract_entropy(struct entropy_store *r, void *buf,
32089 if (fips_enabled) {
32090 unsigned long flags;
32091
32092+
32093+ /* prime last_data value if need be, per fips 140-2 */
32094+ if (!r->last_data_init) {
32095+ spin_lock_irqsave(&r->lock, flags);
32096+ memcpy(r->last_data, tmp, EXTRACT_SIZE);
32097+ r->last_data_init = true;
32098+ nbytes -= EXTRACT_SIZE;
32099+ spin_unlock_irqrestore(&r->lock, flags);
32100+ extract_buf(r, tmp);
32101+ }
32102+
32103 spin_lock_irqsave(&r->lock, flags);
32104 if (!memcmp(tmp, r->last_data, EXTRACT_SIZE))
32105 panic("Hardware RNG duplicated output!\n");
32106@@ -1008,7 +1036,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
32107
32108 extract_buf(r, tmp);
32109 i = min_t(int, nbytes, EXTRACT_SIZE);
32110- if (copy_to_user(buf, tmp, i)) {
32111+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
32112 ret = -EFAULT;
32113 break;
32114 }
32115@@ -1086,6 +1114,7 @@ static void init_std_data(struct entropy_store *r)
32116
32117 r->entropy_count = 0;
32118 r->entropy_total = 0;
32119+ r->last_data_init = false;
32120 mix_pool_bytes(r, &now, sizeof(now), NULL);
32121 for (i = r->poolinfo->POOLBYTES; i > 0; i -= sizeof(rv)) {
32122 if (!arch_get_random_long(&rv))
32123@@ -1342,7 +1371,7 @@ EXPORT_SYMBOL(generate_random_uuid);
32124 #include <linux/sysctl.h>
32125
32126 static int min_read_thresh = 8, min_write_thresh;
32127-static int max_read_thresh = INPUT_POOL_WORDS * 32;
32128+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
32129 static int max_write_thresh = INPUT_POOL_WORDS * 32;
32130 static char sysctl_bootid[16];
32131
32132diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
32133index 9b4f011..b7e0a1a 100644
32134--- a/drivers/char/sonypi.c
32135+++ b/drivers/char/sonypi.c
32136@@ -54,6 +54,7 @@
32137
32138 #include <asm/uaccess.h>
32139 #include <asm/io.h>
32140+#include <asm/local.h>
32141
32142 #include <linux/sonypi.h>
32143
32144@@ -490,7 +491,7 @@ static struct sonypi_device {
32145 spinlock_t fifo_lock;
32146 wait_queue_head_t fifo_proc_list;
32147 struct fasync_struct *fifo_async;
32148- int open_count;
32149+ local_t open_count;
32150 int model;
32151 struct input_dev *input_jog_dev;
32152 struct input_dev *input_key_dev;
32153@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
32154 static int sonypi_misc_release(struct inode *inode, struct file *file)
32155 {
32156 mutex_lock(&sonypi_device.lock);
32157- sonypi_device.open_count--;
32158+ local_dec(&sonypi_device.open_count);
32159 mutex_unlock(&sonypi_device.lock);
32160 return 0;
32161 }
32162@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
32163 {
32164 mutex_lock(&sonypi_device.lock);
32165 /* Flush input queue on first open */
32166- if (!sonypi_device.open_count)
32167+ if (!local_read(&sonypi_device.open_count))
32168 kfifo_reset(&sonypi_device.fifo);
32169- sonypi_device.open_count++;
32170+ local_inc(&sonypi_device.open_count);
32171 mutex_unlock(&sonypi_device.lock);
32172
32173 return 0;
32174diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
32175index 93211df..c7805f7 100644
32176--- a/drivers/char/tpm/tpm.c
32177+++ b/drivers/char/tpm/tpm.c
32178@@ -410,7 +410,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
32179 chip->vendor.req_complete_val)
32180 goto out_recv;
32181
32182- if ((status == chip->vendor.req_canceled)) {
32183+ if (status == chip->vendor.req_canceled) {
32184 dev_err(chip->dev, "Operation Canceled\n");
32185 rc = -ECANCELED;
32186 goto out;
32187diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
32188index 56051d0..11cf3b7 100644
32189--- a/drivers/char/tpm/tpm_acpi.c
32190+++ b/drivers/char/tpm/tpm_acpi.c
32191@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
32192 virt = acpi_os_map_memory(start, len);
32193 if (!virt) {
32194 kfree(log->bios_event_log);
32195+ log->bios_event_log = NULL;
32196 printk("%s: ERROR - Unable to map memory\n", __func__);
32197 return -EIO;
32198 }
32199
32200- memcpy_fromio(log->bios_event_log, virt, len);
32201+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
32202
32203 acpi_os_unmap_memory(virt, len);
32204 return 0;
32205diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
32206index 84ddc55..1d32f1e 100644
32207--- a/drivers/char/tpm/tpm_eventlog.c
32208+++ b/drivers/char/tpm/tpm_eventlog.c
32209@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
32210 event = addr;
32211
32212 if ((event->event_type == 0 && event->event_size == 0) ||
32213- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
32214+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
32215 return NULL;
32216
32217 return addr;
32218@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
32219 return NULL;
32220
32221 if ((event->event_type == 0 && event->event_size == 0) ||
32222- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
32223+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
32224 return NULL;
32225
32226 (*pos)++;
32227@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
32228 int i;
32229
32230 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
32231- seq_putc(m, data[i]);
32232+ if (!seq_putc(m, data[i]))
32233+ return -EFAULT;
32234
32235 return 0;
32236 }
32237diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
32238index 8ab9c3d..c3e65d3 100644
32239--- a/drivers/char/virtio_console.c
32240+++ b/drivers/char/virtio_console.c
32241@@ -622,7 +622,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
32242 if (to_user) {
32243 ssize_t ret;
32244
32245- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
32246+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
32247 if (ret)
32248 return -EFAULT;
32249 } else {
32250@@ -721,7 +721,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
32251 if (!port_has_data(port) && !port->host_connected)
32252 return 0;
32253
32254- return fill_readbuf(port, ubuf, count, true);
32255+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
32256 }
32257
32258 static int wait_port_writable(struct port *port, bool nonblock)
32259diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
32260index e164c55..3aabb50 100644
32261--- a/drivers/edac/edac_pci_sysfs.c
32262+++ b/drivers/edac/edac_pci_sysfs.c
32263@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
32264 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
32265 static int edac_pci_poll_msec = 1000; /* one second workq period */
32266
32267-static atomic_t pci_parity_count = ATOMIC_INIT(0);
32268-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
32269+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
32270+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
32271
32272 static struct kobject *edac_pci_top_main_kobj;
32273 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
32274@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32275 edac_printk(KERN_CRIT, EDAC_PCI,
32276 "Signaled System Error on %s\n",
32277 pci_name(dev));
32278- atomic_inc(&pci_nonparity_count);
32279+ atomic_inc_unchecked(&pci_nonparity_count);
32280 }
32281
32282 if (status & (PCI_STATUS_PARITY)) {
32283@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32284 "Master Data Parity Error on %s\n",
32285 pci_name(dev));
32286
32287- atomic_inc(&pci_parity_count);
32288+ atomic_inc_unchecked(&pci_parity_count);
32289 }
32290
32291 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32292@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32293 "Detected Parity Error on %s\n",
32294 pci_name(dev));
32295
32296- atomic_inc(&pci_parity_count);
32297+ atomic_inc_unchecked(&pci_parity_count);
32298 }
32299 }
32300
32301@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32302 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
32303 "Signaled System Error on %s\n",
32304 pci_name(dev));
32305- atomic_inc(&pci_nonparity_count);
32306+ atomic_inc_unchecked(&pci_nonparity_count);
32307 }
32308
32309 if (status & (PCI_STATUS_PARITY)) {
32310@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32311 "Master Data Parity Error on "
32312 "%s\n", pci_name(dev));
32313
32314- atomic_inc(&pci_parity_count);
32315+ atomic_inc_unchecked(&pci_parity_count);
32316 }
32317
32318 if (status & (PCI_STATUS_DETECTED_PARITY)) {
32319@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
32320 "Detected Parity Error on %s\n",
32321 pci_name(dev));
32322
32323- atomic_inc(&pci_parity_count);
32324+ atomic_inc_unchecked(&pci_parity_count);
32325 }
32326 }
32327 }
32328@@ -676,7 +676,7 @@ void edac_pci_do_parity_check(void)
32329 if (!check_pci_errors)
32330 return;
32331
32332- before_count = atomic_read(&pci_parity_count);
32333+ before_count = atomic_read_unchecked(&pci_parity_count);
32334
32335 /* scan all PCI devices looking for a Parity Error on devices and
32336 * bridges.
32337@@ -688,7 +688,7 @@ void edac_pci_do_parity_check(void)
32338 /* Only if operator has selected panic on PCI Error */
32339 if (edac_pci_get_panic_on_pe()) {
32340 /* If the count is different 'after' from 'before' */
32341- if (before_count != atomic_read(&pci_parity_count))
32342+ if (before_count != atomic_read_unchecked(&pci_parity_count))
32343 panic("EDAC: PCI Parity Error");
32344 }
32345 }
32346diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
32347index 8c87a5e..a19cbd7 100644
32348--- a/drivers/edac/mce_amd.h
32349+++ b/drivers/edac/mce_amd.h
32350@@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
32351 struct amd_decoder_ops {
32352 bool (*dc_mce)(u16, u8);
32353 bool (*ic_mce)(u16, u8);
32354-};
32355+} __no_const;
32356
32357 void amd_report_gart_errors(bool);
32358 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
32359diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
32360index 57ea7f4..789e3c3 100644
32361--- a/drivers/firewire/core-card.c
32362+++ b/drivers/firewire/core-card.c
32363@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
32364
32365 void fw_core_remove_card(struct fw_card *card)
32366 {
32367- struct fw_card_driver dummy_driver = dummy_driver_template;
32368+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
32369
32370 card->driver->update_phy_reg(card, 4,
32371 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
32372diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
32373index f8d2287..5aaf4db 100644
32374--- a/drivers/firewire/core-cdev.c
32375+++ b/drivers/firewire/core-cdev.c
32376@@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
32377 int ret;
32378
32379 if ((request->channels == 0 && request->bandwidth == 0) ||
32380- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
32381- request->bandwidth < 0)
32382+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
32383 return -EINVAL;
32384
32385 r = kmalloc(sizeof(*r), GFP_KERNEL);
32386diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
32387index 28a94c7..58da63a 100644
32388--- a/drivers/firewire/core-transaction.c
32389+++ b/drivers/firewire/core-transaction.c
32390@@ -38,6 +38,7 @@
32391 #include <linux/timer.h>
32392 #include <linux/types.h>
32393 #include <linux/workqueue.h>
32394+#include <linux/sched.h>
32395
32396 #include <asm/byteorder.h>
32397
32398diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
32399index 515a42c..5ecf3ba 100644
32400--- a/drivers/firewire/core.h
32401+++ b/drivers/firewire/core.h
32402@@ -111,6 +111,7 @@ struct fw_card_driver {
32403
32404 int (*stop_iso)(struct fw_iso_context *ctx);
32405 };
32406+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
32407
32408 void fw_card_initialize(struct fw_card *card,
32409 const struct fw_card_driver *driver, struct device *device);
32410diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
32411index fd3ae62..669efe3 100644
32412--- a/drivers/firmware/dmi_scan.c
32413+++ b/drivers/firmware/dmi_scan.c
32414@@ -491,11 +491,6 @@ void __init dmi_scan_machine(void)
32415 }
32416 }
32417 else {
32418- /*
32419- * no iounmap() for that ioremap(); it would be a no-op, but
32420- * it's so early in setup that sucker gets confused into doing
32421- * what it shouldn't if we actually call it.
32422- */
32423 p = dmi_ioremap(0xF0000, 0x10000);
32424 if (p == NULL)
32425 goto error;
32426@@ -770,7 +765,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
32427 if (buf == NULL)
32428 return -1;
32429
32430- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
32431+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
32432
32433 iounmap(buf);
32434 return 0;
32435diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
32436index d10c987..ebe5400 100644
32437--- a/drivers/firmware/efivars.c
32438+++ b/drivers/firmware/efivars.c
32439@@ -1234,9 +1234,9 @@ efivars_init(void)
32440 return -ENOMEM;
32441 }
32442
32443- ops.get_variable = efi.get_variable;
32444- ops.set_variable = efi.set_variable;
32445- ops.get_next_variable = efi.get_next_variable;
32446+ *(void **)&ops.get_variable = efi.get_variable;
32447+ *(void **)&ops.set_variable = efi.set_variable;
32448+ *(void **)&ops.get_next_variable = efi.get_next_variable;
32449 error = register_efivars(&__efivars, &ops, efi_kobj);
32450 if (error)
32451 goto err_put;
32452diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
32453index 82d5c20..44a7177 100644
32454--- a/drivers/gpio/gpio-vr41xx.c
32455+++ b/drivers/gpio/gpio-vr41xx.c
32456@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
32457 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
32458 maskl, pendl, maskh, pendh);
32459
32460- atomic_inc(&irq_err_count);
32461+ atomic_inc_unchecked(&irq_err_count);
32462
32463 return -EINVAL;
32464 }
32465diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
32466index 1227adf..f2301c2 100644
32467--- a/drivers/gpu/drm/drm_crtc_helper.c
32468+++ b/drivers/gpu/drm/drm_crtc_helper.c
32469@@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
32470 struct drm_crtc *tmp;
32471 int crtc_mask = 1;
32472
32473- WARN(!crtc, "checking null crtc?\n");
32474+ BUG_ON(!crtc);
32475
32476 dev = crtc->dev;
32477
32478diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
32479index be174ca..0bcbb71 100644
32480--- a/drivers/gpu/drm/drm_drv.c
32481+++ b/drivers/gpu/drm/drm_drv.c
32482@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
32483 /**
32484 * Copy and IOCTL return string to user space
32485 */
32486-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
32487+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
32488 {
32489 int len;
32490
32491@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
32492 return -ENODEV;
32493
32494 atomic_inc(&dev->ioctl_count);
32495- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
32496+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
32497 ++file_priv->ioctl_count;
32498
32499 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
32500diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
32501index 133b413..fd68225 100644
32502--- a/drivers/gpu/drm/drm_fops.c
32503+++ b/drivers/gpu/drm/drm_fops.c
32504@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
32505 }
32506
32507 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
32508- atomic_set(&dev->counts[i], 0);
32509+ atomic_set_unchecked(&dev->counts[i], 0);
32510
32511 dev->sigdata.lock = NULL;
32512
32513@@ -134,7 +134,7 @@ int drm_open(struct inode *inode, struct file *filp)
32514 if (drm_device_is_unplugged(dev))
32515 return -ENODEV;
32516
32517- if (!dev->open_count++)
32518+ if (local_inc_return(&dev->open_count) == 1)
32519 need_setup = 1;
32520 mutex_lock(&dev->struct_mutex);
32521 old_mapping = dev->dev_mapping;
32522@@ -149,7 +149,7 @@ int drm_open(struct inode *inode, struct file *filp)
32523 retcode = drm_open_helper(inode, filp, dev);
32524 if (retcode)
32525 goto err_undo;
32526- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
32527+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
32528 if (need_setup) {
32529 retcode = drm_setup(dev);
32530 if (retcode)
32531@@ -164,7 +164,7 @@ err_undo:
32532 iput(container_of(dev->dev_mapping, struct inode, i_data));
32533 dev->dev_mapping = old_mapping;
32534 mutex_unlock(&dev->struct_mutex);
32535- dev->open_count--;
32536+ local_dec(&dev->open_count);
32537 return retcode;
32538 }
32539 EXPORT_SYMBOL(drm_open);
32540@@ -438,7 +438,7 @@ int drm_release(struct inode *inode, struct file *filp)
32541
32542 mutex_lock(&drm_global_mutex);
32543
32544- DRM_DEBUG("open_count = %d\n", dev->open_count);
32545+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
32546
32547 if (dev->driver->preclose)
32548 dev->driver->preclose(dev, file_priv);
32549@@ -447,10 +447,10 @@ int drm_release(struct inode *inode, struct file *filp)
32550 * Begin inline drm_release
32551 */
32552
32553- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
32554+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
32555 task_pid_nr(current),
32556 (long)old_encode_dev(file_priv->minor->device),
32557- dev->open_count);
32558+ local_read(&dev->open_count));
32559
32560 /* Release any auth tokens that might point to this file_priv,
32561 (do that under the drm_global_mutex) */
32562@@ -547,8 +547,8 @@ int drm_release(struct inode *inode, struct file *filp)
32563 * End inline drm_release
32564 */
32565
32566- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
32567- if (!--dev->open_count) {
32568+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
32569+ if (local_dec_and_test(&dev->open_count)) {
32570 if (atomic_read(&dev->ioctl_count)) {
32571 DRM_ERROR("Device busy: %d\n",
32572 atomic_read(&dev->ioctl_count));
32573diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
32574index f731116..629842c 100644
32575--- a/drivers/gpu/drm/drm_global.c
32576+++ b/drivers/gpu/drm/drm_global.c
32577@@ -36,7 +36,7 @@
32578 struct drm_global_item {
32579 struct mutex mutex;
32580 void *object;
32581- int refcount;
32582+ atomic_t refcount;
32583 };
32584
32585 static struct drm_global_item glob[DRM_GLOBAL_NUM];
32586@@ -49,7 +49,7 @@ void drm_global_init(void)
32587 struct drm_global_item *item = &glob[i];
32588 mutex_init(&item->mutex);
32589 item->object = NULL;
32590- item->refcount = 0;
32591+ atomic_set(&item->refcount, 0);
32592 }
32593 }
32594
32595@@ -59,7 +59,7 @@ void drm_global_release(void)
32596 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
32597 struct drm_global_item *item = &glob[i];
32598 BUG_ON(item->object != NULL);
32599- BUG_ON(item->refcount != 0);
32600+ BUG_ON(atomic_read(&item->refcount) != 0);
32601 }
32602 }
32603
32604@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32605 void *object;
32606
32607 mutex_lock(&item->mutex);
32608- if (item->refcount == 0) {
32609+ if (atomic_read(&item->refcount) == 0) {
32610 item->object = kzalloc(ref->size, GFP_KERNEL);
32611 if (unlikely(item->object == NULL)) {
32612 ret = -ENOMEM;
32613@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
32614 goto out_err;
32615
32616 }
32617- ++item->refcount;
32618+ atomic_inc(&item->refcount);
32619 ref->object = item->object;
32620 object = item->object;
32621 mutex_unlock(&item->mutex);
32622@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
32623 struct drm_global_item *item = &glob[ref->global_type];
32624
32625 mutex_lock(&item->mutex);
32626- BUG_ON(item->refcount == 0);
32627+ BUG_ON(atomic_read(&item->refcount) == 0);
32628 BUG_ON(ref->object != item->object);
32629- if (--item->refcount == 0) {
32630+ if (atomic_dec_and_test(&item->refcount)) {
32631 ref->release(ref);
32632 item->object = NULL;
32633 }
32634diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
32635index d4b20ce..77a8d41 100644
32636--- a/drivers/gpu/drm/drm_info.c
32637+++ b/drivers/gpu/drm/drm_info.c
32638@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
32639 struct drm_local_map *map;
32640 struct drm_map_list *r_list;
32641
32642- /* Hardcoded from _DRM_FRAME_BUFFER,
32643- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
32644- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
32645- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
32646+ static const char * const types[] = {
32647+ [_DRM_FRAME_BUFFER] = "FB",
32648+ [_DRM_REGISTERS] = "REG",
32649+ [_DRM_SHM] = "SHM",
32650+ [_DRM_AGP] = "AGP",
32651+ [_DRM_SCATTER_GATHER] = "SG",
32652+ [_DRM_CONSISTENT] = "PCI",
32653+ [_DRM_GEM] = "GEM" };
32654 const char *type;
32655 int i;
32656
32657@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
32658 map = r_list->map;
32659 if (!map)
32660 continue;
32661- if (map->type < 0 || map->type > 5)
32662+ if (map->type >= ARRAY_SIZE(types))
32663 type = "??";
32664 else
32665 type = types[map->type];
32666@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
32667 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
32668 vma->vm_flags & VM_LOCKED ? 'l' : '-',
32669 vma->vm_flags & VM_IO ? 'i' : '-',
32670+#ifdef CONFIG_GRKERNSEC_HIDESYM
32671+ 0);
32672+#else
32673 vma->vm_pgoff);
32674+#endif
32675
32676 #if defined(__i386__)
32677 pgprot = pgprot_val(vma->vm_page_prot);
32678diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
32679index 2f4c434..764794b 100644
32680--- a/drivers/gpu/drm/drm_ioc32.c
32681+++ b/drivers/gpu/drm/drm_ioc32.c
32682@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
32683 request = compat_alloc_user_space(nbytes);
32684 if (!access_ok(VERIFY_WRITE, request, nbytes))
32685 return -EFAULT;
32686- list = (struct drm_buf_desc *) (request + 1);
32687+ list = (struct drm_buf_desc __user *) (request + 1);
32688
32689 if (__put_user(count, &request->count)
32690 || __put_user(list, &request->list))
32691@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
32692 request = compat_alloc_user_space(nbytes);
32693 if (!access_ok(VERIFY_WRITE, request, nbytes))
32694 return -EFAULT;
32695- list = (struct drm_buf_pub *) (request + 1);
32696+ list = (struct drm_buf_pub __user *) (request + 1);
32697
32698 if (__put_user(count, &request->count)
32699 || __put_user(list, &request->list))
32700diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
32701index 23dd975..63e9801 100644
32702--- a/drivers/gpu/drm/drm_ioctl.c
32703+++ b/drivers/gpu/drm/drm_ioctl.c
32704@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
32705 stats->data[i].value =
32706 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
32707 else
32708- stats->data[i].value = atomic_read(&dev->counts[i]);
32709+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
32710 stats->data[i].type = dev->types[i];
32711 }
32712
32713diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
32714index d752c96..fe08455 100644
32715--- a/drivers/gpu/drm/drm_lock.c
32716+++ b/drivers/gpu/drm/drm_lock.c
32717@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32718 if (drm_lock_take(&master->lock, lock->context)) {
32719 master->lock.file_priv = file_priv;
32720 master->lock.lock_time = jiffies;
32721- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
32722+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
32723 break; /* Got lock */
32724 }
32725
32726@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
32727 return -EINVAL;
32728 }
32729
32730- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
32731+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
32732
32733 if (drm_lock_free(&master->lock, lock->context)) {
32734 /* FIXME: Should really bail out here. */
32735diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
32736index c236fd2..6b5f2e7 100644
32737--- a/drivers/gpu/drm/drm_stub.c
32738+++ b/drivers/gpu/drm/drm_stub.c
32739@@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
32740
32741 drm_device_set_unplugged(dev);
32742
32743- if (dev->open_count == 0) {
32744+ if (local_read(&dev->open_count) == 0) {
32745 drm_put_dev(dev);
32746 }
32747 mutex_unlock(&drm_global_mutex);
32748diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
32749index 004ecdf..db1f6e0 100644
32750--- a/drivers/gpu/drm/i810/i810_dma.c
32751+++ b/drivers/gpu/drm/i810/i810_dma.c
32752@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
32753 dma->buflist[vertex->idx],
32754 vertex->discard, vertex->used);
32755
32756- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32757- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32758+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
32759+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32760 sarea_priv->last_enqueue = dev_priv->counter - 1;
32761 sarea_priv->last_dispatch = (int)hw_status[5];
32762
32763@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
32764 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
32765 mc->last_render);
32766
32767- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32768- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
32769+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
32770+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
32771 sarea_priv->last_enqueue = dev_priv->counter - 1;
32772 sarea_priv->last_dispatch = (int)hw_status[5];
32773
32774diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
32775index 6e0acad..93c8289 100644
32776--- a/drivers/gpu/drm/i810/i810_drv.h
32777+++ b/drivers/gpu/drm/i810/i810_drv.h
32778@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
32779 int page_flipping;
32780
32781 wait_queue_head_t irq_queue;
32782- atomic_t irq_received;
32783- atomic_t irq_emitted;
32784+ atomic_unchecked_t irq_received;
32785+ atomic_unchecked_t irq_emitted;
32786
32787 int front_offset;
32788 } drm_i810_private_t;
32789diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
32790index da21b11..14c8749 100644
32791--- a/drivers/gpu/drm/i915/i915_debugfs.c
32792+++ b/drivers/gpu/drm/i915/i915_debugfs.c
32793@@ -495,7 +495,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
32794 I915_READ(GTIMR));
32795 }
32796 seq_printf(m, "Interrupts received: %d\n",
32797- atomic_read(&dev_priv->irq_received));
32798+ atomic_read_unchecked(&dev_priv->irq_received));
32799 for_each_ring(ring, dev_priv, i) {
32800 if (IS_GEN6(dev) || IS_GEN7(dev)) {
32801 seq_printf(m,
32802diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
32803index 61ae104..f8a4bc1 100644
32804--- a/drivers/gpu/drm/i915/i915_dma.c
32805+++ b/drivers/gpu/drm/i915/i915_dma.c
32806@@ -1274,7 +1274,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
32807 bool can_switch;
32808
32809 spin_lock(&dev->count_lock);
32810- can_switch = (dev->open_count == 0);
32811+ can_switch = (local_read(&dev->open_count) == 0);
32812 spin_unlock(&dev->count_lock);
32813 return can_switch;
32814 }
32815diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
32816index 92f1750..3beba74 100644
32817--- a/drivers/gpu/drm/i915/i915_drv.h
32818+++ b/drivers/gpu/drm/i915/i915_drv.h
32819@@ -430,7 +430,7 @@ typedef struct drm_i915_private {
32820
32821 struct resource mch_res;
32822
32823- atomic_t irq_received;
32824+ atomic_unchecked_t irq_received;
32825
32826 /* protects the irq masks */
32827 spinlock_t irq_lock;
32828@@ -1055,7 +1055,7 @@ struct drm_i915_gem_object {
32829 * will be page flipped away on the next vblank. When it
32830 * reaches 0, dev_priv->pending_flip_queue will be woken up.
32831 */
32832- atomic_t pending_flip;
32833+ atomic_unchecked_t pending_flip;
32834 };
32835
32836 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
32837@@ -1558,7 +1558,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
32838 struct drm_i915_private *dev_priv, unsigned port);
32839 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
32840 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
32841-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32842+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
32843 {
32844 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
32845 }
32846diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32847index 67036e9..b9f1357 100644
32848--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32849+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
32850@@ -681,7 +681,7 @@ i915_gem_execbuffer_move_to_gpu(struct intel_ring_buffer *ring,
32851 i915_gem_clflush_object(obj);
32852
32853 if (obj->base.pending_write_domain)
32854- flips |= atomic_read(&obj->pending_flip);
32855+ flips |= atomic_read_unchecked(&obj->pending_flip);
32856
32857 flush_domains |= obj->base.write_domain;
32858 }
32859@@ -712,9 +712,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
32860
32861 static int
32862 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
32863- int count)
32864+ unsigned int count)
32865 {
32866- int i;
32867+ unsigned int i;
32868
32869 for (i = 0; i < count; i++) {
32870 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
32871diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
32872index dc29ace..137d83a 100644
32873--- a/drivers/gpu/drm/i915/i915_irq.c
32874+++ b/drivers/gpu/drm/i915/i915_irq.c
32875@@ -531,7 +531,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
32876 u32 pipe_stats[I915_MAX_PIPES];
32877 bool blc_event;
32878
32879- atomic_inc(&dev_priv->irq_received);
32880+ atomic_inc_unchecked(&dev_priv->irq_received);
32881
32882 while (true) {
32883 iir = I915_READ(VLV_IIR);
32884@@ -678,7 +678,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
32885 irqreturn_t ret = IRQ_NONE;
32886 int i;
32887
32888- atomic_inc(&dev_priv->irq_received);
32889+ atomic_inc_unchecked(&dev_priv->irq_received);
32890
32891 /* disable master interrupt before clearing iir */
32892 de_ier = I915_READ(DEIER);
32893@@ -753,7 +753,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
32894 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
32895 u32 hotplug_mask;
32896
32897- atomic_inc(&dev_priv->irq_received);
32898+ atomic_inc_unchecked(&dev_priv->irq_received);
32899
32900 /* disable master interrupt before clearing iir */
32901 de_ier = I915_READ(DEIER);
32902@@ -1762,7 +1762,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
32903 {
32904 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32905
32906- atomic_set(&dev_priv->irq_received, 0);
32907+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32908
32909 I915_WRITE(HWSTAM, 0xeffe);
32910
32911@@ -1788,7 +1788,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
32912 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32913 int pipe;
32914
32915- atomic_set(&dev_priv->irq_received, 0);
32916+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32917
32918 /* VLV magic */
32919 I915_WRITE(VLV_IMR, 0);
32920@@ -2093,7 +2093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
32921 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32922 int pipe;
32923
32924- atomic_set(&dev_priv->irq_received, 0);
32925+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32926
32927 for_each_pipe(pipe)
32928 I915_WRITE(PIPESTAT(pipe), 0);
32929@@ -2144,7 +2144,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
32930 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
32931 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
32932
32933- atomic_inc(&dev_priv->irq_received);
32934+ atomic_inc_unchecked(&dev_priv->irq_received);
32935
32936 iir = I915_READ16(IIR);
32937 if (iir == 0)
32938@@ -2229,7 +2229,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
32939 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32940 int pipe;
32941
32942- atomic_set(&dev_priv->irq_received, 0);
32943+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32944
32945 if (I915_HAS_HOTPLUG(dev)) {
32946 I915_WRITE(PORT_HOTPLUG_EN, 0);
32947@@ -2324,7 +2324,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
32948 };
32949 int pipe, ret = IRQ_NONE;
32950
32951- atomic_inc(&dev_priv->irq_received);
32952+ atomic_inc_unchecked(&dev_priv->irq_received);
32953
32954 iir = I915_READ(IIR);
32955 do {
32956@@ -2450,7 +2450,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
32957 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
32958 int pipe;
32959
32960- atomic_set(&dev_priv->irq_received, 0);
32961+ atomic_set_unchecked(&dev_priv->irq_received, 0);
32962
32963 I915_WRITE(PORT_HOTPLUG_EN, 0);
32964 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
32965@@ -2557,7 +2557,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
32966 int irq_received;
32967 int ret = IRQ_NONE, pipe;
32968
32969- atomic_inc(&dev_priv->irq_received);
32970+ atomic_inc_unchecked(&dev_priv->irq_received);
32971
32972 iir = I915_READ(IIR);
32973
32974diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
32975index 4d3c7c6..eaac87b 100644
32976--- a/drivers/gpu/drm/i915/intel_display.c
32977+++ b/drivers/gpu/drm/i915/intel_display.c
32978@@ -2131,7 +2131,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
32979
32980 wait_event(dev_priv->pending_flip_queue,
32981 atomic_read(&dev_priv->mm.wedged) ||
32982- atomic_read(&obj->pending_flip) == 0);
32983+ atomic_read_unchecked(&obj->pending_flip) == 0);
32984
32985 /* Big Hammer, we also need to ensure that any pending
32986 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
32987@@ -6221,8 +6221,7 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
32988
32989 obj = work->old_fb_obj;
32990
32991- atomic_clear_mask(1 << intel_crtc->plane,
32992- &obj->pending_flip.counter);
32993+ atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
32994 wake_up(&dev_priv->pending_flip_queue);
32995
32996 queue_work(dev_priv->wq, &work->work);
32997@@ -6589,7 +6588,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
32998 /* Block clients from rendering to the new back buffer until
32999 * the flip occurs and the object is no longer visible.
33000 */
33001- atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33002+ atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33003 atomic_inc(&intel_crtc->unpin_work_count);
33004
33005 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
33006@@ -6606,7 +6605,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
33007
33008 cleanup_pending:
33009 atomic_dec(&intel_crtc->unpin_work_count);
33010- atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33011+ atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
33012 drm_gem_object_unreference(&work->old_fb_obj->base);
33013 drm_gem_object_unreference(&obj->base);
33014 mutex_unlock(&dev->struct_mutex);
33015diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
33016index 54558a0..2d97005 100644
33017--- a/drivers/gpu/drm/mga/mga_drv.h
33018+++ b/drivers/gpu/drm/mga/mga_drv.h
33019@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
33020 u32 clear_cmd;
33021 u32 maccess;
33022
33023- atomic_t vbl_received; /**< Number of vblanks received. */
33024+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
33025 wait_queue_head_t fence_queue;
33026- atomic_t last_fence_retired;
33027+ atomic_unchecked_t last_fence_retired;
33028 u32 next_fence_to_post;
33029
33030 unsigned int fb_cpp;
33031diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
33032index 598c281..60d590e 100644
33033--- a/drivers/gpu/drm/mga/mga_irq.c
33034+++ b/drivers/gpu/drm/mga/mga_irq.c
33035@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
33036 if (crtc != 0)
33037 return 0;
33038
33039- return atomic_read(&dev_priv->vbl_received);
33040+ return atomic_read_unchecked(&dev_priv->vbl_received);
33041 }
33042
33043
33044@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33045 /* VBLANK interrupt */
33046 if (status & MGA_VLINEPEN) {
33047 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
33048- atomic_inc(&dev_priv->vbl_received);
33049+ atomic_inc_unchecked(&dev_priv->vbl_received);
33050 drm_handle_vblank(dev, 0);
33051 handled = 1;
33052 }
33053@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
33054 if ((prim_start & ~0x03) != (prim_end & ~0x03))
33055 MGA_WRITE(MGA_PRIMEND, prim_end);
33056
33057- atomic_inc(&dev_priv->last_fence_retired);
33058+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
33059 DRM_WAKEUP(&dev_priv->fence_queue);
33060 handled = 1;
33061 }
33062@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
33063 * using fences.
33064 */
33065 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
33066- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
33067+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
33068 - *sequence) <= (1 << 23)));
33069
33070 *sequence = cur_fence;
33071diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
33072index 09fdef2..57f5c3b 100644
33073--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
33074+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
33075@@ -1240,7 +1240,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
33076 struct bit_table {
33077 const char id;
33078 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
33079-};
33080+} __no_const;
33081
33082 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
33083
33084diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
33085index a101699..a163f0a 100644
33086--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
33087+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
33088@@ -80,7 +80,7 @@ struct nouveau_drm {
33089 struct drm_global_reference mem_global_ref;
33090 struct ttm_bo_global_ref bo_global_ref;
33091 struct ttm_bo_device bdev;
33092- atomic_t validate_sequence;
33093+ atomic_unchecked_t validate_sequence;
33094 int (*move)(struct nouveau_channel *,
33095 struct ttm_buffer_object *,
33096 struct ttm_mem_reg *, struct ttm_mem_reg *);
33097diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.h b/drivers/gpu/drm/nouveau/nouveau_fence.h
33098index cdb83ac..27f0a16 100644
33099--- a/drivers/gpu/drm/nouveau/nouveau_fence.h
33100+++ b/drivers/gpu/drm/nouveau/nouveau_fence.h
33101@@ -43,7 +43,7 @@ struct nouveau_fence_priv {
33102 int (*sync)(struct nouveau_fence *, struct nouveau_channel *,
33103 struct nouveau_channel *);
33104 u32 (*read)(struct nouveau_channel *);
33105-};
33106+} __no_const;
33107
33108 #define nouveau_fence(drm) ((struct nouveau_fence_priv *)(drm)->fence)
33109
33110diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
33111index 5e2f521..0d21436 100644
33112--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
33113+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
33114@@ -321,7 +321,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
33115 int trycnt = 0;
33116 int ret, i;
33117
33118- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
33119+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
33120 retry:
33121 if (++trycnt > 100000) {
33122 NV_ERROR(drm, "%s failed and gave up.\n", __func__);
33123diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
33124index 6f0ac64..9c2dfb4 100644
33125--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
33126+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
33127@@ -63,7 +63,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
33128 bool can_switch;
33129
33130 spin_lock(&dev->count_lock);
33131- can_switch = (dev->open_count == 0);
33132+ can_switch = (local_read(&dev->open_count) == 0);
33133 spin_unlock(&dev->count_lock);
33134 return can_switch;
33135 }
33136diff --git a/drivers/gpu/drm/nouveau/nv50_evo.c b/drivers/gpu/drm/nouveau/nv50_evo.c
33137index 9f6f55c..30e3a29 100644
33138--- a/drivers/gpu/drm/nouveau/nv50_evo.c
33139+++ b/drivers/gpu/drm/nouveau/nv50_evo.c
33140@@ -152,9 +152,9 @@ nv50_evo_channel_new(struct drm_device *dev, int chid,
33141 kzalloc(sizeof(*evo->object->oclass), GFP_KERNEL);
33142 evo->object->oclass->ofuncs =
33143 kzalloc(sizeof(*evo->object->oclass->ofuncs), GFP_KERNEL);
33144- evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33145- evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33146- evo->object->oclass->ofuncs->rd08 =
33147+ *(void**)&evo->object->oclass->ofuncs->rd32 = nv50_evo_rd32;
33148+ *(void**)&evo->object->oclass->ofuncs->wr32 = nv50_evo_wr32;
33149+ *(void**)&evo->object->oclass->ofuncs->rd08 =
33150 ioremap(pci_resource_start(dev->pdev, 0) +
33151 NV50_PDISPLAY_USER(evo->handle), PAGE_SIZE);
33152 return 0;
33153diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
33154index b562b59..9d725a8 100644
33155--- a/drivers/gpu/drm/nouveau/nv50_sor.c
33156+++ b/drivers/gpu/drm/nouveau/nv50_sor.c
33157@@ -317,7 +317,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
33158 }
33159
33160 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33161- struct dp_train_func func = {
33162+ static struct dp_train_func func = {
33163 .link_set = nv50_sor_dp_link_set,
33164 .train_set = nv50_sor_dp_train_set,
33165 .train_adj = nv50_sor_dp_train_adj
33166diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
33167index c402fca..f1d694b 100644
33168--- a/drivers/gpu/drm/nouveau/nvd0_display.c
33169+++ b/drivers/gpu/drm/nouveau/nvd0_display.c
33170@@ -1389,7 +1389,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
33171 nv_wait(device, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
33172
33173 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
33174- struct dp_train_func func = {
33175+ static struct dp_train_func func = {
33176 .link_set = nvd0_sor_dp_link_set,
33177 .train_set = nvd0_sor_dp_train_set,
33178 .train_adj = nvd0_sor_dp_train_adj
33179diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
33180index d4660cf..70dbe65 100644
33181--- a/drivers/gpu/drm/r128/r128_cce.c
33182+++ b/drivers/gpu/drm/r128/r128_cce.c
33183@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
33184
33185 /* GH: Simple idle check.
33186 */
33187- atomic_set(&dev_priv->idle_count, 0);
33188+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33189
33190 /* We don't support anything other than bus-mastering ring mode,
33191 * but the ring can be in either AGP or PCI space for the ring
33192diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
33193index 930c71b..499aded 100644
33194--- a/drivers/gpu/drm/r128/r128_drv.h
33195+++ b/drivers/gpu/drm/r128/r128_drv.h
33196@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
33197 int is_pci;
33198 unsigned long cce_buffers_offset;
33199
33200- atomic_t idle_count;
33201+ atomic_unchecked_t idle_count;
33202
33203 int page_flipping;
33204 int current_page;
33205 u32 crtc_offset;
33206 u32 crtc_offset_cntl;
33207
33208- atomic_t vbl_received;
33209+ atomic_unchecked_t vbl_received;
33210
33211 u32 color_fmt;
33212 unsigned int front_offset;
33213diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
33214index 2ea4f09..d391371 100644
33215--- a/drivers/gpu/drm/r128/r128_irq.c
33216+++ b/drivers/gpu/drm/r128/r128_irq.c
33217@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
33218 if (crtc != 0)
33219 return 0;
33220
33221- return atomic_read(&dev_priv->vbl_received);
33222+ return atomic_read_unchecked(&dev_priv->vbl_received);
33223 }
33224
33225 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33226@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
33227 /* VBLANK interrupt */
33228 if (status & R128_CRTC_VBLANK_INT) {
33229 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
33230- atomic_inc(&dev_priv->vbl_received);
33231+ atomic_inc_unchecked(&dev_priv->vbl_received);
33232 drm_handle_vblank(dev, 0);
33233 return IRQ_HANDLED;
33234 }
33235diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
33236index 19bb7e6..de7e2a2 100644
33237--- a/drivers/gpu/drm/r128/r128_state.c
33238+++ b/drivers/gpu/drm/r128/r128_state.c
33239@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
33240
33241 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
33242 {
33243- if (atomic_read(&dev_priv->idle_count) == 0)
33244+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
33245 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
33246 else
33247- atomic_set(&dev_priv->idle_count, 0);
33248+ atomic_set_unchecked(&dev_priv->idle_count, 0);
33249 }
33250
33251 #endif
33252diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
33253index 5a82b6b..9e69c73 100644
33254--- a/drivers/gpu/drm/radeon/mkregtable.c
33255+++ b/drivers/gpu/drm/radeon/mkregtable.c
33256@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
33257 regex_t mask_rex;
33258 regmatch_t match[4];
33259 char buf[1024];
33260- size_t end;
33261+ long end;
33262 int len;
33263 int done = 0;
33264 int r;
33265 unsigned o;
33266 struct offset *offset;
33267 char last_reg_s[10];
33268- int last_reg;
33269+ unsigned long last_reg;
33270
33271 if (regcomp
33272 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
33273diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
33274index ad4c973..aa27bcb 100644
33275--- a/drivers/gpu/drm/radeon/radeon_device.c
33276+++ b/drivers/gpu/drm/radeon/radeon_device.c
33277@@ -940,7 +940,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
33278 bool can_switch;
33279
33280 spin_lock(&dev->count_lock);
33281- can_switch = (dev->open_count == 0);
33282+ can_switch = (local_read(&dev->open_count) == 0);
33283 spin_unlock(&dev->count_lock);
33284 return can_switch;
33285 }
33286diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
33287index a1b59ca..86f2d44 100644
33288--- a/drivers/gpu/drm/radeon/radeon_drv.h
33289+++ b/drivers/gpu/drm/radeon/radeon_drv.h
33290@@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
33291
33292 /* SW interrupt */
33293 wait_queue_head_t swi_queue;
33294- atomic_t swi_emitted;
33295+ atomic_unchecked_t swi_emitted;
33296 int vblank_crtc;
33297 uint32_t irq_enable_reg;
33298 uint32_t r500_disp_irq_reg;
33299diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
33300index c180df8..cd80dd2d 100644
33301--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
33302+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
33303@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
33304 request = compat_alloc_user_space(sizeof(*request));
33305 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
33306 || __put_user(req32.param, &request->param)
33307- || __put_user((void __user *)(unsigned long)req32.value,
33308+ || __put_user((unsigned long)req32.value,
33309 &request->value))
33310 return -EFAULT;
33311
33312diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
33313index e771033..a0bc6b3 100644
33314--- a/drivers/gpu/drm/radeon/radeon_irq.c
33315+++ b/drivers/gpu/drm/radeon/radeon_irq.c
33316@@ -224,8 +224,8 @@ static int radeon_emit_irq(struct drm_device * dev)
33317 unsigned int ret;
33318 RING_LOCALS;
33319
33320- atomic_inc(&dev_priv->swi_emitted);
33321- ret = atomic_read(&dev_priv->swi_emitted);
33322+ atomic_inc_unchecked(&dev_priv->swi_emitted);
33323+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
33324
33325 BEGIN_RING(4);
33326 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
33327@@ -351,7 +351,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
33328 drm_radeon_private_t *dev_priv =
33329 (drm_radeon_private_t *) dev->dev_private;
33330
33331- atomic_set(&dev_priv->swi_emitted, 0);
33332+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
33333 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
33334
33335 dev->max_vblank_count = 0x001fffff;
33336diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
33337index 8e9057b..af6dacb 100644
33338--- a/drivers/gpu/drm/radeon/radeon_state.c
33339+++ b/drivers/gpu/drm/radeon/radeon_state.c
33340@@ -2166,7 +2166,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
33341 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
33342 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
33343
33344- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33345+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
33346 sarea_priv->nbox * sizeof(depth_boxes[0])))
33347 return -EFAULT;
33348
33349@@ -3029,7 +3029,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
33350 {
33351 drm_radeon_private_t *dev_priv = dev->dev_private;
33352 drm_radeon_getparam_t *param = data;
33353- int value;
33354+ int value = 0;
33355
33356 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
33357
33358diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
33359index 5ebe1b3..1ed9426 100644
33360--- a/drivers/gpu/drm/radeon/radeon_ttm.c
33361+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
33362@@ -822,8 +822,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
33363 }
33364 if (unlikely(ttm_vm_ops == NULL)) {
33365 ttm_vm_ops = vma->vm_ops;
33366- radeon_ttm_vm_ops = *ttm_vm_ops;
33367- radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33368+ pax_open_kernel();
33369+ memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
33370+ *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
33371+ pax_close_kernel();
33372 }
33373 vma->vm_ops = &radeon_ttm_vm_ops;
33374 return 0;
33375diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
33376index 5706d2a..17aedaa 100644
33377--- a/drivers/gpu/drm/radeon/rs690.c
33378+++ b/drivers/gpu/drm/radeon/rs690.c
33379@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
33380 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
33381 rdev->pm.sideport_bandwidth.full)
33382 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
33383- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
33384+ read_delay_latency.full = dfixed_const(800 * 1000);
33385 read_delay_latency.full = dfixed_div(read_delay_latency,
33386 rdev->pm.igp_sideport_mclk);
33387+ a.full = dfixed_const(370);
33388+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
33389 } else {
33390 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
33391 rdev->pm.k8_bandwidth.full)
33392diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33393index bd2a3b4..122d9ad 100644
33394--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
33395+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
33396@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
33397 static int ttm_pool_mm_shrink(struct shrinker *shrink,
33398 struct shrink_control *sc)
33399 {
33400- static atomic_t start_pool = ATOMIC_INIT(0);
33401+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
33402 unsigned i;
33403- unsigned pool_offset = atomic_add_return(1, &start_pool);
33404+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
33405 struct ttm_page_pool *pool;
33406 int shrink_pages = sc->nr_to_scan;
33407
33408diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
33409index 893a650..6190d3b 100644
33410--- a/drivers/gpu/drm/via/via_drv.h
33411+++ b/drivers/gpu/drm/via/via_drv.h
33412@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
33413 typedef uint32_t maskarray_t[5];
33414
33415 typedef struct drm_via_irq {
33416- atomic_t irq_received;
33417+ atomic_unchecked_t irq_received;
33418 uint32_t pending_mask;
33419 uint32_t enable_mask;
33420 wait_queue_head_t irq_queue;
33421@@ -75,7 +75,7 @@ typedef struct drm_via_private {
33422 struct timeval last_vblank;
33423 int last_vblank_valid;
33424 unsigned usec_per_vblank;
33425- atomic_t vbl_received;
33426+ atomic_unchecked_t vbl_received;
33427 drm_via_state_t hc_state;
33428 char pci_buf[VIA_PCI_BUF_SIZE];
33429 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
33430diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
33431index ac98964..5dbf512 100644
33432--- a/drivers/gpu/drm/via/via_irq.c
33433+++ b/drivers/gpu/drm/via/via_irq.c
33434@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
33435 if (crtc != 0)
33436 return 0;
33437
33438- return atomic_read(&dev_priv->vbl_received);
33439+ return atomic_read_unchecked(&dev_priv->vbl_received);
33440 }
33441
33442 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33443@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33444
33445 status = VIA_READ(VIA_REG_INTERRUPT);
33446 if (status & VIA_IRQ_VBLANK_PENDING) {
33447- atomic_inc(&dev_priv->vbl_received);
33448- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
33449+ atomic_inc_unchecked(&dev_priv->vbl_received);
33450+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
33451 do_gettimeofday(&cur_vblank);
33452 if (dev_priv->last_vblank_valid) {
33453 dev_priv->usec_per_vblank =
33454@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33455 dev_priv->last_vblank = cur_vblank;
33456 dev_priv->last_vblank_valid = 1;
33457 }
33458- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
33459+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
33460 DRM_DEBUG("US per vblank is: %u\n",
33461 dev_priv->usec_per_vblank);
33462 }
33463@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
33464
33465 for (i = 0; i < dev_priv->num_irqs; ++i) {
33466 if (status & cur_irq->pending_mask) {
33467- atomic_inc(&cur_irq->irq_received);
33468+ atomic_inc_unchecked(&cur_irq->irq_received);
33469 DRM_WAKEUP(&cur_irq->irq_queue);
33470 handled = 1;
33471 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
33472@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
33473 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33474 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
33475 masks[irq][4]));
33476- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
33477+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
33478 } else {
33479 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
33480 (((cur_irq_sequence =
33481- atomic_read(&cur_irq->irq_received)) -
33482+ atomic_read_unchecked(&cur_irq->irq_received)) -
33483 *sequence) <= (1 << 23)));
33484 }
33485 *sequence = cur_irq_sequence;
33486@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
33487 }
33488
33489 for (i = 0; i < dev_priv->num_irqs; ++i) {
33490- atomic_set(&cur_irq->irq_received, 0);
33491+ atomic_set_unchecked(&cur_irq->irq_received, 0);
33492 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
33493 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
33494 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
33495@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
33496 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
33497 case VIA_IRQ_RELATIVE:
33498 irqwait->request.sequence +=
33499- atomic_read(&cur_irq->irq_received);
33500+ atomic_read_unchecked(&cur_irq->irq_received);
33501 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
33502 case VIA_IRQ_ABSOLUTE:
33503 break;
33504diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33505index 88a179e..57fe50481c 100644
33506--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33507+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
33508@@ -263,7 +263,7 @@ struct vmw_private {
33509 * Fencing and IRQs.
33510 */
33511
33512- atomic_t marker_seq;
33513+ atomic_unchecked_t marker_seq;
33514 wait_queue_head_t fence_queue;
33515 wait_queue_head_t fifo_queue;
33516 int fence_queue_waiters; /* Protected by hw_mutex */
33517diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33518index 3eb1486..0a47ee9 100644
33519--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33520+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
33521@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
33522 (unsigned int) min,
33523 (unsigned int) fifo->capabilities);
33524
33525- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33526+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
33527 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
33528 vmw_marker_queue_init(&fifo->marker_queue);
33529 return vmw_fifo_send_fence(dev_priv, &dummy);
33530@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
33531 if (reserveable)
33532 iowrite32(bytes, fifo_mem +
33533 SVGA_FIFO_RESERVED);
33534- return fifo_mem + (next_cmd >> 2);
33535+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
33536 } else {
33537 need_bounce = true;
33538 }
33539@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33540
33541 fm = vmw_fifo_reserve(dev_priv, bytes);
33542 if (unlikely(fm == NULL)) {
33543- *seqno = atomic_read(&dev_priv->marker_seq);
33544+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33545 ret = -ENOMEM;
33546 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
33547 false, 3*HZ);
33548@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
33549 }
33550
33551 do {
33552- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
33553+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
33554 } while (*seqno == 0);
33555
33556 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
33557diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33558index 4640adb..e1384ed 100644
33559--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33560+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
33561@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
33562 * emitted. Then the fence is stale and signaled.
33563 */
33564
33565- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
33566+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
33567 > VMW_FENCE_WRAP);
33568
33569 return ret;
33570@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
33571
33572 if (fifo_idle)
33573 down_read(&fifo_state->rwsem);
33574- signal_seq = atomic_read(&dev_priv->marker_seq);
33575+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
33576 ret = 0;
33577
33578 for (;;) {
33579diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33580index 8a8725c..afed796 100644
33581--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33582+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
33583@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
33584 while (!vmw_lag_lt(queue, us)) {
33585 spin_lock(&queue->lock);
33586 if (list_empty(&queue->head))
33587- seqno = atomic_read(&dev_priv->marker_seq);
33588+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
33589 else {
33590 marker = list_first_entry(&queue->head,
33591 struct vmw_marker, head);
33592diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
33593index 52146db..ae33762 100644
33594--- a/drivers/hid/hid-core.c
33595+++ b/drivers/hid/hid-core.c
33596@@ -2201,7 +2201,7 @@ static bool hid_ignore(struct hid_device *hdev)
33597
33598 int hid_add_device(struct hid_device *hdev)
33599 {
33600- static atomic_t id = ATOMIC_INIT(0);
33601+ static atomic_unchecked_t id = ATOMIC_INIT(0);
33602 int ret;
33603
33604 if (WARN_ON(hdev->status & HID_STAT_ADDED))
33605@@ -2236,7 +2236,7 @@ int hid_add_device(struct hid_device *hdev)
33606 /* XXX hack, any other cleaner solution after the driver core
33607 * is converted to allow more than 20 bytes as the device name? */
33608 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
33609- hdev->vendor, hdev->product, atomic_inc_return(&id));
33610+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
33611
33612 hid_debug_register(hdev, dev_name(&hdev->dev));
33613 ret = device_add(&hdev->dev);
33614diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
33615index eec3291..8ed706b 100644
33616--- a/drivers/hid/hid-wiimote-debug.c
33617+++ b/drivers/hid/hid-wiimote-debug.c
33618@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
33619 else if (size == 0)
33620 return -EIO;
33621
33622- if (copy_to_user(u, buf, size))
33623+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
33624 return -EFAULT;
33625
33626 *off += size;
33627diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
33628index 14599e2..711c965 100644
33629--- a/drivers/hid/usbhid/hiddev.c
33630+++ b/drivers/hid/usbhid/hiddev.c
33631@@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
33632 break;
33633
33634 case HIDIOCAPPLICATION:
33635- if (arg < 0 || arg >= hid->maxapplication)
33636+ if (arg >= hid->maxapplication)
33637 break;
33638
33639 for (i = 0; i < hid->maxcollection; i++)
33640diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
33641index f4c3d28..82f45a9 100644
33642--- a/drivers/hv/channel.c
33643+++ b/drivers/hv/channel.c
33644@@ -402,8 +402,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
33645 int ret = 0;
33646 int t;
33647
33648- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
33649- atomic_inc(&vmbus_connection.next_gpadl_handle);
33650+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
33651+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
33652
33653 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
33654 if (ret)
33655diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
33656index 3648f8f..30ef30d 100644
33657--- a/drivers/hv/hv.c
33658+++ b/drivers/hv/hv.c
33659@@ -111,7 +111,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
33660 u64 output_address = (output) ? virt_to_phys(output) : 0;
33661 u32 output_address_hi = output_address >> 32;
33662 u32 output_address_lo = output_address & 0xFFFFFFFF;
33663- void *hypercall_page = hv_context.hypercall_page;
33664+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
33665
33666 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
33667 "=a"(hv_status_lo) : "d" (control_hi),
33668diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
33669index d8d1fad..b91caf7 100644
33670--- a/drivers/hv/hyperv_vmbus.h
33671+++ b/drivers/hv/hyperv_vmbus.h
33672@@ -594,7 +594,7 @@ enum vmbus_connect_state {
33673 struct vmbus_connection {
33674 enum vmbus_connect_state conn_state;
33675
33676- atomic_t next_gpadl_handle;
33677+ atomic_unchecked_t next_gpadl_handle;
33678
33679 /*
33680 * Represents channel interrupts. Each bit position represents a
33681diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
33682index 8e1a9ec..4687821 100644
33683--- a/drivers/hv/vmbus_drv.c
33684+++ b/drivers/hv/vmbus_drv.c
33685@@ -629,10 +629,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
33686 {
33687 int ret = 0;
33688
33689- static atomic_t device_num = ATOMIC_INIT(0);
33690+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
33691
33692 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
33693- atomic_inc_return(&device_num));
33694+ atomic_inc_return_unchecked(&device_num));
33695
33696 child_device_obj->device.bus = &hv_bus;
33697 child_device_obj->device.parent = &hv_acpi_dev->dev;
33698diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
33699index 07a0c1a..0cac334 100644
33700--- a/drivers/hwmon/sht15.c
33701+++ b/drivers/hwmon/sht15.c
33702@@ -169,7 +169,7 @@ struct sht15_data {
33703 int supply_uV;
33704 bool supply_uV_valid;
33705 struct work_struct update_supply_work;
33706- atomic_t interrupt_handled;
33707+ atomic_unchecked_t interrupt_handled;
33708 };
33709
33710 /**
33711@@ -512,13 +512,13 @@ static int sht15_measurement(struct sht15_data *data,
33712 return ret;
33713
33714 gpio_direction_input(data->pdata->gpio_data);
33715- atomic_set(&data->interrupt_handled, 0);
33716+ atomic_set_unchecked(&data->interrupt_handled, 0);
33717
33718 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33719 if (gpio_get_value(data->pdata->gpio_data) == 0) {
33720 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
33721 /* Only relevant if the interrupt hasn't occurred. */
33722- if (!atomic_read(&data->interrupt_handled))
33723+ if (!atomic_read_unchecked(&data->interrupt_handled))
33724 schedule_work(&data->read_work);
33725 }
33726 ret = wait_event_timeout(data->wait_queue,
33727@@ -785,7 +785,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
33728
33729 /* First disable the interrupt */
33730 disable_irq_nosync(irq);
33731- atomic_inc(&data->interrupt_handled);
33732+ atomic_inc_unchecked(&data->interrupt_handled);
33733 /* Then schedule a reading work struct */
33734 if (data->state != SHT15_READING_NOTHING)
33735 schedule_work(&data->read_work);
33736@@ -807,11 +807,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
33737 * If not, then start the interrupt again - care here as could
33738 * have gone low in meantime so verify it hasn't!
33739 */
33740- atomic_set(&data->interrupt_handled, 0);
33741+ atomic_set_unchecked(&data->interrupt_handled, 0);
33742 enable_irq(gpio_to_irq(data->pdata->gpio_data));
33743 /* If still not occurred or another handler was scheduled */
33744 if (gpio_get_value(data->pdata->gpio_data)
33745- || atomic_read(&data->interrupt_handled))
33746+ || atomic_read_unchecked(&data->interrupt_handled))
33747 return;
33748 }
33749
33750diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
33751index 378fcb5..5e91fa8 100644
33752--- a/drivers/i2c/busses/i2c-amd756-s4882.c
33753+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
33754@@ -43,7 +43,7 @@
33755 extern struct i2c_adapter amd756_smbus;
33756
33757 static struct i2c_adapter *s4882_adapter;
33758-static struct i2c_algorithm *s4882_algo;
33759+static i2c_algorithm_no_const *s4882_algo;
33760
33761 /* Wrapper access functions for multiplexed SMBus */
33762 static DEFINE_MUTEX(amd756_lock);
33763diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
33764index 29015eb..af2d8e9 100644
33765--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
33766+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
33767@@ -41,7 +41,7 @@
33768 extern struct i2c_adapter *nforce2_smbus;
33769
33770 static struct i2c_adapter *s4985_adapter;
33771-static struct i2c_algorithm *s4985_algo;
33772+static i2c_algorithm_no_const *s4985_algo;
33773
33774 /* Wrapper access functions for multiplexed SMBus */
33775 static DEFINE_MUTEX(nforce2_lock);
33776diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
33777index 8126824..55a2798 100644
33778--- a/drivers/ide/ide-cd.c
33779+++ b/drivers/ide/ide-cd.c
33780@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
33781 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
33782 if ((unsigned long)buf & alignment
33783 || blk_rq_bytes(rq) & q->dma_pad_mask
33784- || object_is_on_stack(buf))
33785+ || object_starts_on_stack(buf))
33786 drive->dma = 0;
33787 }
33788 }
33789diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
33790index 394fea2..c833880 100644
33791--- a/drivers/infiniband/core/cm.c
33792+++ b/drivers/infiniband/core/cm.c
33793@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
33794
33795 struct cm_counter_group {
33796 struct kobject obj;
33797- atomic_long_t counter[CM_ATTR_COUNT];
33798+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
33799 };
33800
33801 struct cm_counter_attribute {
33802@@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
33803 struct ib_mad_send_buf *msg = NULL;
33804 int ret;
33805
33806- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33807+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33808 counter[CM_REQ_COUNTER]);
33809
33810 /* Quick state check to discard duplicate REQs. */
33811@@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
33812 if (!cm_id_priv)
33813 return;
33814
33815- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33816+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33817 counter[CM_REP_COUNTER]);
33818 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
33819 if (ret)
33820@@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
33821 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
33822 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
33823 spin_unlock_irq(&cm_id_priv->lock);
33824- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33825+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33826 counter[CM_RTU_COUNTER]);
33827 goto out;
33828 }
33829@@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
33830 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
33831 dreq_msg->local_comm_id);
33832 if (!cm_id_priv) {
33833- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33834+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33835 counter[CM_DREQ_COUNTER]);
33836 cm_issue_drep(work->port, work->mad_recv_wc);
33837 return -EINVAL;
33838@@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
33839 case IB_CM_MRA_REP_RCVD:
33840 break;
33841 case IB_CM_TIMEWAIT:
33842- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33843+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33844 counter[CM_DREQ_COUNTER]);
33845 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33846 goto unlock;
33847@@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
33848 cm_free_msg(msg);
33849 goto deref;
33850 case IB_CM_DREQ_RCVD:
33851- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33852+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33853 counter[CM_DREQ_COUNTER]);
33854 goto unlock;
33855 default:
33856@@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
33857 ib_modify_mad(cm_id_priv->av.port->mad_agent,
33858 cm_id_priv->msg, timeout)) {
33859 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
33860- atomic_long_inc(&work->port->
33861+ atomic_long_inc_unchecked(&work->port->
33862 counter_group[CM_RECV_DUPLICATES].
33863 counter[CM_MRA_COUNTER]);
33864 goto out;
33865@@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
33866 break;
33867 case IB_CM_MRA_REQ_RCVD:
33868 case IB_CM_MRA_REP_RCVD:
33869- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33870+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33871 counter[CM_MRA_COUNTER]);
33872 /* fall through */
33873 default:
33874@@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
33875 case IB_CM_LAP_IDLE:
33876 break;
33877 case IB_CM_MRA_LAP_SENT:
33878- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33879+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33880 counter[CM_LAP_COUNTER]);
33881 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
33882 goto unlock;
33883@@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
33884 cm_free_msg(msg);
33885 goto deref;
33886 case IB_CM_LAP_RCVD:
33887- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33888+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33889 counter[CM_LAP_COUNTER]);
33890 goto unlock;
33891 default:
33892@@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
33893 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
33894 if (cur_cm_id_priv) {
33895 spin_unlock_irq(&cm.lock);
33896- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
33897+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
33898 counter[CM_SIDR_REQ_COUNTER]);
33899 goto out; /* Duplicate message. */
33900 }
33901@@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
33902 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
33903 msg->retries = 1;
33904
33905- atomic_long_add(1 + msg->retries,
33906+ atomic_long_add_unchecked(1 + msg->retries,
33907 &port->counter_group[CM_XMIT].counter[attr_index]);
33908 if (msg->retries)
33909- atomic_long_add(msg->retries,
33910+ atomic_long_add_unchecked(msg->retries,
33911 &port->counter_group[CM_XMIT_RETRIES].
33912 counter[attr_index]);
33913
33914@@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
33915 }
33916
33917 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
33918- atomic_long_inc(&port->counter_group[CM_RECV].
33919+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
33920 counter[attr_id - CM_ATTR_ID_OFFSET]);
33921
33922 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
33923@@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
33924 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
33925
33926 return sprintf(buf, "%ld\n",
33927- atomic_long_read(&group->counter[cm_attr->index]));
33928+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
33929 }
33930
33931 static const struct sysfs_ops cm_counter_ops = {
33932diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
33933index 176c8f9..2627b62 100644
33934--- a/drivers/infiniband/core/fmr_pool.c
33935+++ b/drivers/infiniband/core/fmr_pool.c
33936@@ -98,8 +98,8 @@ struct ib_fmr_pool {
33937
33938 struct task_struct *thread;
33939
33940- atomic_t req_ser;
33941- atomic_t flush_ser;
33942+ atomic_unchecked_t req_ser;
33943+ atomic_unchecked_t flush_ser;
33944
33945 wait_queue_head_t force_wait;
33946 };
33947@@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33948 struct ib_fmr_pool *pool = pool_ptr;
33949
33950 do {
33951- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
33952+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
33953 ib_fmr_batch_release(pool);
33954
33955- atomic_inc(&pool->flush_ser);
33956+ atomic_inc_unchecked(&pool->flush_ser);
33957 wake_up_interruptible(&pool->force_wait);
33958
33959 if (pool->flush_function)
33960@@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
33961 }
33962
33963 set_current_state(TASK_INTERRUPTIBLE);
33964- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
33965+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
33966 !kthread_should_stop())
33967 schedule();
33968 __set_current_state(TASK_RUNNING);
33969@@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
33970 pool->dirty_watermark = params->dirty_watermark;
33971 pool->dirty_len = 0;
33972 spin_lock_init(&pool->pool_lock);
33973- atomic_set(&pool->req_ser, 0);
33974- atomic_set(&pool->flush_ser, 0);
33975+ atomic_set_unchecked(&pool->req_ser, 0);
33976+ atomic_set_unchecked(&pool->flush_ser, 0);
33977 init_waitqueue_head(&pool->force_wait);
33978
33979 pool->thread = kthread_run(ib_fmr_cleanup_thread,
33980@@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
33981 }
33982 spin_unlock_irq(&pool->pool_lock);
33983
33984- serial = atomic_inc_return(&pool->req_ser);
33985+ serial = atomic_inc_return_unchecked(&pool->req_ser);
33986 wake_up_process(pool->thread);
33987
33988 if (wait_event_interruptible(pool->force_wait,
33989- atomic_read(&pool->flush_ser) - serial >= 0))
33990+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
33991 return -EINTR;
33992
33993 return 0;
33994@@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
33995 } else {
33996 list_add_tail(&fmr->list, &pool->dirty_list);
33997 if (++pool->dirty_len >= pool->dirty_watermark) {
33998- atomic_inc(&pool->req_ser);
33999+ atomic_inc_unchecked(&pool->req_ser);
34000 wake_up_process(pool->thread);
34001 }
34002 }
34003diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
34004index afd8179..598063f 100644
34005--- a/drivers/infiniband/hw/cxgb4/mem.c
34006+++ b/drivers/infiniband/hw/cxgb4/mem.c
34007@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34008 int err;
34009 struct fw_ri_tpte tpt;
34010 u32 stag_idx;
34011- static atomic_t key;
34012+ static atomic_unchecked_t key;
34013
34014 if (c4iw_fatal_error(rdev))
34015 return -EIO;
34016@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
34017 if (rdev->stats.stag.cur > rdev->stats.stag.max)
34018 rdev->stats.stag.max = rdev->stats.stag.cur;
34019 mutex_unlock(&rdev->stats.lock);
34020- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
34021+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
34022 }
34023 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
34024 __func__, stag_state, type, pdid, stag_idx);
34025diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
34026index 79b3dbc..96e5fcc 100644
34027--- a/drivers/infiniband/hw/ipath/ipath_rc.c
34028+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
34029@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34030 struct ib_atomic_eth *ateth;
34031 struct ipath_ack_entry *e;
34032 u64 vaddr;
34033- atomic64_t *maddr;
34034+ atomic64_unchecked_t *maddr;
34035 u64 sdata;
34036 u32 rkey;
34037 u8 next;
34038@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
34039 IB_ACCESS_REMOTE_ATOMIC)))
34040 goto nack_acc_unlck;
34041 /* Perform atomic OP and save result. */
34042- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34043+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34044 sdata = be64_to_cpu(ateth->swap_data);
34045 e = &qp->s_ack_queue[qp->r_head_ack_queue];
34046 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
34047- (u64) atomic64_add_return(sdata, maddr) - sdata :
34048+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34049 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34050 be64_to_cpu(ateth->compare_data),
34051 sdata);
34052diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
34053index 1f95bba..9530f87 100644
34054--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
34055+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
34056@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
34057 unsigned long flags;
34058 struct ib_wc wc;
34059 u64 sdata;
34060- atomic64_t *maddr;
34061+ atomic64_unchecked_t *maddr;
34062 enum ib_wc_status send_status;
34063
34064 /*
34065@@ -382,11 +382,11 @@ again:
34066 IB_ACCESS_REMOTE_ATOMIC)))
34067 goto acc_err;
34068 /* Perform atomic OP and save result. */
34069- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
34070+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
34071 sdata = wqe->wr.wr.atomic.compare_add;
34072 *(u64 *) sqp->s_sge.sge.vaddr =
34073 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
34074- (u64) atomic64_add_return(sdata, maddr) - sdata :
34075+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
34076 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
34077 sdata, wqe->wr.wr.atomic.swap);
34078 goto send_comp;
34079diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
34080index 748db2d..5f75cc3 100644
34081--- a/drivers/infiniband/hw/nes/nes.c
34082+++ b/drivers/infiniband/hw/nes/nes.c
34083@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
34084 LIST_HEAD(nes_adapter_list);
34085 static LIST_HEAD(nes_dev_list);
34086
34087-atomic_t qps_destroyed;
34088+atomic_unchecked_t qps_destroyed;
34089
34090 static unsigned int ee_flsh_adapter;
34091 static unsigned int sysfs_nonidx_addr;
34092@@ -267,7 +267,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
34093 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
34094 struct nes_adapter *nesadapter = nesdev->nesadapter;
34095
34096- atomic_inc(&qps_destroyed);
34097+ atomic_inc_unchecked(&qps_destroyed);
34098
34099 /* Free the control structures */
34100
34101diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
34102index 33cc589..3bd6538 100644
34103--- a/drivers/infiniband/hw/nes/nes.h
34104+++ b/drivers/infiniband/hw/nes/nes.h
34105@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
34106 extern unsigned int wqm_quanta;
34107 extern struct list_head nes_adapter_list;
34108
34109-extern atomic_t cm_connects;
34110-extern atomic_t cm_accepts;
34111-extern atomic_t cm_disconnects;
34112-extern atomic_t cm_closes;
34113-extern atomic_t cm_connecteds;
34114-extern atomic_t cm_connect_reqs;
34115-extern atomic_t cm_rejects;
34116-extern atomic_t mod_qp_timouts;
34117-extern atomic_t qps_created;
34118-extern atomic_t qps_destroyed;
34119-extern atomic_t sw_qps_destroyed;
34120+extern atomic_unchecked_t cm_connects;
34121+extern atomic_unchecked_t cm_accepts;
34122+extern atomic_unchecked_t cm_disconnects;
34123+extern atomic_unchecked_t cm_closes;
34124+extern atomic_unchecked_t cm_connecteds;
34125+extern atomic_unchecked_t cm_connect_reqs;
34126+extern atomic_unchecked_t cm_rejects;
34127+extern atomic_unchecked_t mod_qp_timouts;
34128+extern atomic_unchecked_t qps_created;
34129+extern atomic_unchecked_t qps_destroyed;
34130+extern atomic_unchecked_t sw_qps_destroyed;
34131 extern u32 mh_detected;
34132 extern u32 mh_pauses_sent;
34133 extern u32 cm_packets_sent;
34134@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
34135 extern u32 cm_packets_received;
34136 extern u32 cm_packets_dropped;
34137 extern u32 cm_packets_retrans;
34138-extern atomic_t cm_listens_created;
34139-extern atomic_t cm_listens_destroyed;
34140+extern atomic_unchecked_t cm_listens_created;
34141+extern atomic_unchecked_t cm_listens_destroyed;
34142 extern u32 cm_backlog_drops;
34143-extern atomic_t cm_loopbacks;
34144-extern atomic_t cm_nodes_created;
34145-extern atomic_t cm_nodes_destroyed;
34146-extern atomic_t cm_accel_dropped_pkts;
34147-extern atomic_t cm_resets_recvd;
34148-extern atomic_t pau_qps_created;
34149-extern atomic_t pau_qps_destroyed;
34150+extern atomic_unchecked_t cm_loopbacks;
34151+extern atomic_unchecked_t cm_nodes_created;
34152+extern atomic_unchecked_t cm_nodes_destroyed;
34153+extern atomic_unchecked_t cm_accel_dropped_pkts;
34154+extern atomic_unchecked_t cm_resets_recvd;
34155+extern atomic_unchecked_t pau_qps_created;
34156+extern atomic_unchecked_t pau_qps_destroyed;
34157
34158 extern u32 int_mod_timer_init;
34159 extern u32 int_mod_cq_depth_256;
34160diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
34161index cfaacaf..fa0722e 100644
34162--- a/drivers/infiniband/hw/nes/nes_cm.c
34163+++ b/drivers/infiniband/hw/nes/nes_cm.c
34164@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
34165 u32 cm_packets_retrans;
34166 u32 cm_packets_created;
34167 u32 cm_packets_received;
34168-atomic_t cm_listens_created;
34169-atomic_t cm_listens_destroyed;
34170+atomic_unchecked_t cm_listens_created;
34171+atomic_unchecked_t cm_listens_destroyed;
34172 u32 cm_backlog_drops;
34173-atomic_t cm_loopbacks;
34174-atomic_t cm_nodes_created;
34175-atomic_t cm_nodes_destroyed;
34176-atomic_t cm_accel_dropped_pkts;
34177-atomic_t cm_resets_recvd;
34178+atomic_unchecked_t cm_loopbacks;
34179+atomic_unchecked_t cm_nodes_created;
34180+atomic_unchecked_t cm_nodes_destroyed;
34181+atomic_unchecked_t cm_accel_dropped_pkts;
34182+atomic_unchecked_t cm_resets_recvd;
34183
34184 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
34185 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
34186@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
34187
34188 static struct nes_cm_core *g_cm_core;
34189
34190-atomic_t cm_connects;
34191-atomic_t cm_accepts;
34192-atomic_t cm_disconnects;
34193-atomic_t cm_closes;
34194-atomic_t cm_connecteds;
34195-atomic_t cm_connect_reqs;
34196-atomic_t cm_rejects;
34197+atomic_unchecked_t cm_connects;
34198+atomic_unchecked_t cm_accepts;
34199+atomic_unchecked_t cm_disconnects;
34200+atomic_unchecked_t cm_closes;
34201+atomic_unchecked_t cm_connecteds;
34202+atomic_unchecked_t cm_connect_reqs;
34203+atomic_unchecked_t cm_rejects;
34204
34205 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
34206 {
34207@@ -1281,7 +1281,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
34208 kfree(listener);
34209 listener = NULL;
34210 ret = 0;
34211- atomic_inc(&cm_listens_destroyed);
34212+ atomic_inc_unchecked(&cm_listens_destroyed);
34213 } else {
34214 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
34215 }
34216@@ -1480,7 +1480,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
34217 cm_node->rem_mac);
34218
34219 add_hte_node(cm_core, cm_node);
34220- atomic_inc(&cm_nodes_created);
34221+ atomic_inc_unchecked(&cm_nodes_created);
34222
34223 return cm_node;
34224 }
34225@@ -1538,7 +1538,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
34226 }
34227
34228 atomic_dec(&cm_core->node_cnt);
34229- atomic_inc(&cm_nodes_destroyed);
34230+ atomic_inc_unchecked(&cm_nodes_destroyed);
34231 nesqp = cm_node->nesqp;
34232 if (nesqp) {
34233 nesqp->cm_node = NULL;
34234@@ -1602,7 +1602,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
34235
34236 static void drop_packet(struct sk_buff *skb)
34237 {
34238- atomic_inc(&cm_accel_dropped_pkts);
34239+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34240 dev_kfree_skb_any(skb);
34241 }
34242
34243@@ -1665,7 +1665,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
34244 {
34245
34246 int reset = 0; /* whether to send reset in case of err.. */
34247- atomic_inc(&cm_resets_recvd);
34248+ atomic_inc_unchecked(&cm_resets_recvd);
34249 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
34250 " refcnt=%d\n", cm_node, cm_node->state,
34251 atomic_read(&cm_node->ref_count));
34252@@ -2306,7 +2306,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
34253 rem_ref_cm_node(cm_node->cm_core, cm_node);
34254 return NULL;
34255 }
34256- atomic_inc(&cm_loopbacks);
34257+ atomic_inc_unchecked(&cm_loopbacks);
34258 loopbackremotenode->loopbackpartner = cm_node;
34259 loopbackremotenode->tcp_cntxt.rcv_wscale =
34260 NES_CM_DEFAULT_RCV_WND_SCALE;
34261@@ -2581,7 +2581,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
34262 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
34263 else {
34264 rem_ref_cm_node(cm_core, cm_node);
34265- atomic_inc(&cm_accel_dropped_pkts);
34266+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
34267 dev_kfree_skb_any(skb);
34268 }
34269 break;
34270@@ -2889,7 +2889,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34271
34272 if ((cm_id) && (cm_id->event_handler)) {
34273 if (issue_disconn) {
34274- atomic_inc(&cm_disconnects);
34275+ atomic_inc_unchecked(&cm_disconnects);
34276 cm_event.event = IW_CM_EVENT_DISCONNECT;
34277 cm_event.status = disconn_status;
34278 cm_event.local_addr = cm_id->local_addr;
34279@@ -2911,7 +2911,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
34280 }
34281
34282 if (issue_close) {
34283- atomic_inc(&cm_closes);
34284+ atomic_inc_unchecked(&cm_closes);
34285 nes_disconnect(nesqp, 1);
34286
34287 cm_id->provider_data = nesqp;
34288@@ -3047,7 +3047,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34289
34290 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
34291 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
34292- atomic_inc(&cm_accepts);
34293+ atomic_inc_unchecked(&cm_accepts);
34294
34295 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
34296 netdev_refcnt_read(nesvnic->netdev));
34297@@ -3242,7 +3242,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
34298 struct nes_cm_core *cm_core;
34299 u8 *start_buff;
34300
34301- atomic_inc(&cm_rejects);
34302+ atomic_inc_unchecked(&cm_rejects);
34303 cm_node = (struct nes_cm_node *)cm_id->provider_data;
34304 loopback = cm_node->loopbackpartner;
34305 cm_core = cm_node->cm_core;
34306@@ -3302,7 +3302,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
34307 ntohl(cm_id->local_addr.sin_addr.s_addr),
34308 ntohs(cm_id->local_addr.sin_port));
34309
34310- atomic_inc(&cm_connects);
34311+ atomic_inc_unchecked(&cm_connects);
34312 nesqp->active_conn = 1;
34313
34314 /* cache the cm_id in the qp */
34315@@ -3412,7 +3412,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
34316 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
34317 return err;
34318 }
34319- atomic_inc(&cm_listens_created);
34320+ atomic_inc_unchecked(&cm_listens_created);
34321 }
34322
34323 cm_id->add_ref(cm_id);
34324@@ -3513,7 +3513,7 @@ static void cm_event_connected(struct nes_cm_event *event)
34325
34326 if (nesqp->destroyed)
34327 return;
34328- atomic_inc(&cm_connecteds);
34329+ atomic_inc_unchecked(&cm_connecteds);
34330 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
34331 " local port 0x%04X. jiffies = %lu.\n",
34332 nesqp->hwqp.qp_id,
34333@@ -3693,7 +3693,7 @@ static void cm_event_reset(struct nes_cm_event *event)
34334
34335 cm_id->add_ref(cm_id);
34336 ret = cm_id->event_handler(cm_id, &cm_event);
34337- atomic_inc(&cm_closes);
34338+ atomic_inc_unchecked(&cm_closes);
34339 cm_event.event = IW_CM_EVENT_CLOSE;
34340 cm_event.status = 0;
34341 cm_event.provider_data = cm_id->provider_data;
34342@@ -3729,7 +3729,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
34343 return;
34344 cm_id = cm_node->cm_id;
34345
34346- atomic_inc(&cm_connect_reqs);
34347+ atomic_inc_unchecked(&cm_connect_reqs);
34348 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34349 cm_node, cm_id, jiffies);
34350
34351@@ -3769,7 +3769,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
34352 return;
34353 cm_id = cm_node->cm_id;
34354
34355- atomic_inc(&cm_connect_reqs);
34356+ atomic_inc_unchecked(&cm_connect_reqs);
34357 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
34358 cm_node, cm_id, jiffies);
34359
34360diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
34361index 3ba7be3..c81f6ff 100644
34362--- a/drivers/infiniband/hw/nes/nes_mgt.c
34363+++ b/drivers/infiniband/hw/nes/nes_mgt.c
34364@@ -40,8 +40,8 @@
34365 #include "nes.h"
34366 #include "nes_mgt.h"
34367
34368-atomic_t pau_qps_created;
34369-atomic_t pau_qps_destroyed;
34370+atomic_unchecked_t pau_qps_created;
34371+atomic_unchecked_t pau_qps_destroyed;
34372
34373 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
34374 {
34375@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
34376 {
34377 struct sk_buff *skb;
34378 unsigned long flags;
34379- atomic_inc(&pau_qps_destroyed);
34380+ atomic_inc_unchecked(&pau_qps_destroyed);
34381
34382 /* Free packets that have not yet been forwarded */
34383 /* Lock is acquired by skb_dequeue when removing the skb */
34384@@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
34385 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
34386 skb_queue_head_init(&nesqp->pau_list);
34387 spin_lock_init(&nesqp->pau_lock);
34388- atomic_inc(&pau_qps_created);
34389+ atomic_inc_unchecked(&pau_qps_created);
34390 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
34391 }
34392
34393diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
34394index 0564be7..f68b0f1 100644
34395--- a/drivers/infiniband/hw/nes/nes_nic.c
34396+++ b/drivers/infiniband/hw/nes/nes_nic.c
34397@@ -1272,39 +1272,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
34398 target_stat_values[++index] = mh_detected;
34399 target_stat_values[++index] = mh_pauses_sent;
34400 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
34401- target_stat_values[++index] = atomic_read(&cm_connects);
34402- target_stat_values[++index] = atomic_read(&cm_accepts);
34403- target_stat_values[++index] = atomic_read(&cm_disconnects);
34404- target_stat_values[++index] = atomic_read(&cm_connecteds);
34405- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
34406- target_stat_values[++index] = atomic_read(&cm_rejects);
34407- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
34408- target_stat_values[++index] = atomic_read(&qps_created);
34409- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
34410- target_stat_values[++index] = atomic_read(&qps_destroyed);
34411- target_stat_values[++index] = atomic_read(&cm_closes);
34412+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
34413+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
34414+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
34415+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
34416+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
34417+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
34418+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
34419+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
34420+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
34421+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
34422+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
34423 target_stat_values[++index] = cm_packets_sent;
34424 target_stat_values[++index] = cm_packets_bounced;
34425 target_stat_values[++index] = cm_packets_created;
34426 target_stat_values[++index] = cm_packets_received;
34427 target_stat_values[++index] = cm_packets_dropped;
34428 target_stat_values[++index] = cm_packets_retrans;
34429- target_stat_values[++index] = atomic_read(&cm_listens_created);
34430- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
34431+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
34432+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
34433 target_stat_values[++index] = cm_backlog_drops;
34434- target_stat_values[++index] = atomic_read(&cm_loopbacks);
34435- target_stat_values[++index] = atomic_read(&cm_nodes_created);
34436- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
34437- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
34438- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
34439+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
34440+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
34441+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
34442+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
34443+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
34444 target_stat_values[++index] = nesadapter->free_4kpbl;
34445 target_stat_values[++index] = nesadapter->free_256pbl;
34446 target_stat_values[++index] = int_mod_timer_init;
34447 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
34448 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
34449 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
34450- target_stat_values[++index] = atomic_read(&pau_qps_created);
34451- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
34452+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
34453+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
34454 }
34455
34456 /**
34457diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
34458index 07e4fba..685f041 100644
34459--- a/drivers/infiniband/hw/nes/nes_verbs.c
34460+++ b/drivers/infiniband/hw/nes/nes_verbs.c
34461@@ -46,9 +46,9 @@
34462
34463 #include <rdma/ib_umem.h>
34464
34465-atomic_t mod_qp_timouts;
34466-atomic_t qps_created;
34467-atomic_t sw_qps_destroyed;
34468+atomic_unchecked_t mod_qp_timouts;
34469+atomic_unchecked_t qps_created;
34470+atomic_unchecked_t sw_qps_destroyed;
34471
34472 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
34473
34474@@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
34475 if (init_attr->create_flags)
34476 return ERR_PTR(-EINVAL);
34477
34478- atomic_inc(&qps_created);
34479+ atomic_inc_unchecked(&qps_created);
34480 switch (init_attr->qp_type) {
34481 case IB_QPT_RC:
34482 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
34483@@ -1462,7 +1462,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
34484 struct iw_cm_event cm_event;
34485 int ret = 0;
34486
34487- atomic_inc(&sw_qps_destroyed);
34488+ atomic_inc_unchecked(&sw_qps_destroyed);
34489 nesqp->destroyed = 1;
34490
34491 /* Blow away the connection if it exists. */
34492diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
34493index 4d11575..3e890e5 100644
34494--- a/drivers/infiniband/hw/qib/qib.h
34495+++ b/drivers/infiniband/hw/qib/qib.h
34496@@ -51,6 +51,7 @@
34497 #include <linux/completion.h>
34498 #include <linux/kref.h>
34499 #include <linux/sched.h>
34500+#include <linux/slab.h>
34501
34502 #include "qib_common.h"
34503 #include "qib_verbs.h"
34504diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
34505index da739d9..da1c7f4 100644
34506--- a/drivers/input/gameport/gameport.c
34507+++ b/drivers/input/gameport/gameport.c
34508@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
34509 */
34510 static void gameport_init_port(struct gameport *gameport)
34511 {
34512- static atomic_t gameport_no = ATOMIC_INIT(0);
34513+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
34514
34515 __module_get(THIS_MODULE);
34516
34517 mutex_init(&gameport->drv_mutex);
34518 device_initialize(&gameport->dev);
34519 dev_set_name(&gameport->dev, "gameport%lu",
34520- (unsigned long)atomic_inc_return(&gameport_no) - 1);
34521+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
34522 gameport->dev.bus = &gameport_bus;
34523 gameport->dev.release = gameport_release_port;
34524 if (gameport->parent)
34525diff --git a/drivers/input/input.c b/drivers/input/input.c
34526index 53a0dde..abffda7 100644
34527--- a/drivers/input/input.c
34528+++ b/drivers/input/input.c
34529@@ -1902,7 +1902,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
34530 */
34531 int input_register_device(struct input_dev *dev)
34532 {
34533- static atomic_t input_no = ATOMIC_INIT(0);
34534+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
34535 struct input_handler *handler;
34536 unsigned int packet_size;
34537 const char *path;
34538@@ -1945,7 +1945,7 @@ int input_register_device(struct input_dev *dev)
34539 dev->setkeycode = input_default_setkeycode;
34540
34541 dev_set_name(&dev->dev, "input%ld",
34542- (unsigned long) atomic_inc_return(&input_no) - 1);
34543+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
34544
34545 error = device_add(&dev->dev);
34546 if (error)
34547diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
34548index 04c69af..5f92d00 100644
34549--- a/drivers/input/joystick/sidewinder.c
34550+++ b/drivers/input/joystick/sidewinder.c
34551@@ -30,6 +30,7 @@
34552 #include <linux/kernel.h>
34553 #include <linux/module.h>
34554 #include <linux/slab.h>
34555+#include <linux/sched.h>
34556 #include <linux/init.h>
34557 #include <linux/input.h>
34558 #include <linux/gameport.h>
34559diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
34560index 83811e4..0822b90 100644
34561--- a/drivers/input/joystick/xpad.c
34562+++ b/drivers/input/joystick/xpad.c
34563@@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
34564
34565 static int xpad_led_probe(struct usb_xpad *xpad)
34566 {
34567- static atomic_t led_seq = ATOMIC_INIT(0);
34568+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
34569 long led_no;
34570 struct xpad_led *led;
34571 struct led_classdev *led_cdev;
34572@@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
34573 if (!led)
34574 return -ENOMEM;
34575
34576- led_no = (long)atomic_inc_return(&led_seq) - 1;
34577+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
34578
34579 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
34580 led->xpad = xpad;
34581diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
34582index 4c842c3..590b0bf 100644
34583--- a/drivers/input/mousedev.c
34584+++ b/drivers/input/mousedev.c
34585@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
34586
34587 spin_unlock_irq(&client->packet_lock);
34588
34589- if (copy_to_user(buffer, data, count))
34590+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
34591 return -EFAULT;
34592
34593 return count;
34594diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
34595index d0f7533..fb8215b 100644
34596--- a/drivers/input/serio/serio.c
34597+++ b/drivers/input/serio/serio.c
34598@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
34599 */
34600 static void serio_init_port(struct serio *serio)
34601 {
34602- static atomic_t serio_no = ATOMIC_INIT(0);
34603+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
34604
34605 __module_get(THIS_MODULE);
34606
34607@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
34608 mutex_init(&serio->drv_mutex);
34609 device_initialize(&serio->dev);
34610 dev_set_name(&serio->dev, "serio%ld",
34611- (long)atomic_inc_return(&serio_no) - 1);
34612+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
34613 serio->dev.bus = &serio_bus;
34614 serio->dev.release = serio_release_port;
34615 serio->dev.groups = serio_device_attr_groups;
34616diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
34617index 81837b0..d7470e8 100644
34618--- a/drivers/iommu/amd_iommu_init.c
34619+++ b/drivers/iommu/amd_iommu_init.c
34620@@ -1888,7 +1888,7 @@ static int __init state_next(void)
34621 case IOMMU_ACPI_FINISHED:
34622 early_enable_iommus();
34623 register_syscore_ops(&amd_iommu_syscore_ops);
34624- x86_platform.iommu_shutdown = disable_iommus;
34625+ *(void **)&x86_platform.iommu_shutdown = disable_iommus;
34626 init_state = IOMMU_ENABLED;
34627 break;
34628 case IOMMU_ENABLED:
34629@@ -2030,7 +2030,7 @@ int __init amd_iommu_detect(void)
34630
34631 amd_iommu_detected = true;
34632 iommu_detected = 1;
34633- x86_init.iommu.iommu_init = amd_iommu_init;
34634+ *(void **)&x86_init.iommu.iommu_init = amd_iommu_init;
34635
34636 return 0;
34637 }
34638diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
34639index 86e2f4a..d1cec5d 100644
34640--- a/drivers/iommu/dmar.c
34641+++ b/drivers/iommu/dmar.c
34642@@ -555,7 +555,7 @@ int __init detect_intel_iommu(void)
34643
34644 #ifdef CONFIG_X86
34645 if (ret)
34646- x86_init.iommu.iommu_init = intel_iommu_init;
34647+ *(void **)&x86_init.iommu.iommu_init = intel_iommu_init;
34648 #endif
34649 }
34650 early_acpi_os_unmap_memory(dmar_tbl, dmar_tbl_size);
34651diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
34652index c679867..6e2e34d 100644
34653--- a/drivers/isdn/capi/capi.c
34654+++ b/drivers/isdn/capi/capi.c
34655@@ -83,8 +83,8 @@ struct capiminor {
34656
34657 struct capi20_appl *ap;
34658 u32 ncci;
34659- atomic_t datahandle;
34660- atomic_t msgid;
34661+ atomic_unchecked_t datahandle;
34662+ atomic_unchecked_t msgid;
34663
34664 struct tty_port port;
34665 int ttyinstop;
34666@@ -393,7 +393,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
34667 capimsg_setu16(s, 2, mp->ap->applid);
34668 capimsg_setu8 (s, 4, CAPI_DATA_B3);
34669 capimsg_setu8 (s, 5, CAPI_RESP);
34670- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
34671+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
34672 capimsg_setu32(s, 8, mp->ncci);
34673 capimsg_setu16(s, 12, datahandle);
34674 }
34675@@ -514,14 +514,14 @@ static void handle_minor_send(struct capiminor *mp)
34676 mp->outbytes -= len;
34677 spin_unlock_bh(&mp->outlock);
34678
34679- datahandle = atomic_inc_return(&mp->datahandle);
34680+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
34681 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
34682 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34683 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
34684 capimsg_setu16(skb->data, 2, mp->ap->applid);
34685 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
34686 capimsg_setu8 (skb->data, 5, CAPI_REQ);
34687- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
34688+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
34689 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
34690 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
34691 capimsg_setu16(skb->data, 16, len); /* Data length */
34692diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
34693index 67abf3f..076b3a6 100644
34694--- a/drivers/isdn/gigaset/interface.c
34695+++ b/drivers/isdn/gigaset/interface.c
34696@@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
34697 }
34698 tty->driver_data = cs;
34699
34700- ++cs->port.count;
34701+ atomic_inc(&cs->port.count);
34702
34703- if (cs->port.count == 1) {
34704+ if (atomic_read(&cs->port.count) == 1) {
34705 tty_port_tty_set(&cs->port, tty);
34706 tty->low_latency = 1;
34707 }
34708@@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
34709
34710 if (!cs->connected)
34711 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
34712- else if (!cs->port.count)
34713+ else if (!atomic_read(&cs->port.count))
34714 dev_warn(cs->dev, "%s: device not opened\n", __func__);
34715- else if (!--cs->port.count)
34716+ else if (!atomic_dec_return(&cs->port.count))
34717 tty_port_tty_set(&cs->port, NULL);
34718
34719 mutex_unlock(&cs->mutex);
34720diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
34721index 821f7ac..28d4030 100644
34722--- a/drivers/isdn/hardware/avm/b1.c
34723+++ b/drivers/isdn/hardware/avm/b1.c
34724@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
34725 }
34726 if (left) {
34727 if (t4file->user) {
34728- if (copy_from_user(buf, dp, left))
34729+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34730 return -EFAULT;
34731 } else {
34732 memcpy(buf, dp, left);
34733@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
34734 }
34735 if (left) {
34736 if (config->user) {
34737- if (copy_from_user(buf, dp, left))
34738+ if (left > sizeof buf || copy_from_user(buf, dp, left))
34739 return -EFAULT;
34740 } else {
34741 memcpy(buf, dp, left);
34742diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
34743index b817809..409caff 100644
34744--- a/drivers/isdn/i4l/isdn_tty.c
34745+++ b/drivers/isdn/i4l/isdn_tty.c
34746@@ -1513,9 +1513,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
34747
34748 #ifdef ISDN_DEBUG_MODEM_OPEN
34749 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
34750- port->count);
34751+ atomic_read(&port->count));
34752 #endif
34753- port->count++;
34754+ atomic_inc(&port->count);
34755 port->tty = tty;
34756 /*
34757 * Start up serial port
34758@@ -1559,7 +1559,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34759 #endif
34760 return;
34761 }
34762- if ((tty->count == 1) && (port->count != 1)) {
34763+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
34764 /*
34765 * Uh, oh. tty->count is 1, which means that the tty
34766 * structure will be freed. Info->count should always
34767@@ -1568,15 +1568,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
34768 * serial port won't be shutdown.
34769 */
34770 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
34771- "info->count is %d\n", port->count);
34772- port->count = 1;
34773+ "info->count is %d\n", atomic_read(&port->count));
34774+ atomic_set(&port->count, 1);
34775 }
34776- if (--port->count < 0) {
34777+ if (atomic_dec_return(&port->count) < 0) {
34778 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
34779- info->line, port->count);
34780- port->count = 0;
34781+ info->line, atomic_read(&port->count));
34782+ atomic_set(&port->count, 0);
34783 }
34784- if (port->count) {
34785+ if (atomic_read(&port->count)) {
34786 #ifdef ISDN_DEBUG_MODEM_OPEN
34787 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
34788 #endif
34789@@ -1630,7 +1630,7 @@ isdn_tty_hangup(struct tty_struct *tty)
34790 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
34791 return;
34792 isdn_tty_shutdown(info);
34793- port->count = 0;
34794+ atomic_set(&port->count, 0);
34795 port->flags &= ~ASYNC_NORMAL_ACTIVE;
34796 port->tty = NULL;
34797 wake_up_interruptible(&port->open_wait);
34798@@ -1971,7 +1971,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
34799 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
34800 modem_info *info = &dev->mdm.info[i];
34801
34802- if (info->port.count == 0)
34803+ if (atomic_read(&info->port.count) == 0)
34804 continue;
34805 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
34806 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
34807diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
34808index e74df7c..03a03ba 100644
34809--- a/drivers/isdn/icn/icn.c
34810+++ b/drivers/isdn/icn/icn.c
34811@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
34812 if (count > len)
34813 count = len;
34814 if (user) {
34815- if (copy_from_user(msg, buf, count))
34816+ if (count > sizeof msg || copy_from_user(msg, buf, count))
34817 return -EFAULT;
34818 } else
34819 memcpy(msg, buf, count);
34820diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
34821index b5fdcb7..5b6c59f 100644
34822--- a/drivers/lguest/core.c
34823+++ b/drivers/lguest/core.c
34824@@ -92,9 +92,17 @@ static __init int map_switcher(void)
34825 * it's worked so far. The end address needs +1 because __get_vm_area
34826 * allocates an extra guard page, so we need space for that.
34827 */
34828+
34829+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
34830+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34831+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
34832+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34833+#else
34834 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
34835 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
34836 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
34837+#endif
34838+
34839 if (!switcher_vma) {
34840 err = -ENOMEM;
34841 printk("lguest: could not map switcher pages high\n");
34842@@ -119,7 +127,7 @@ static __init int map_switcher(void)
34843 * Now the Switcher is mapped at the right address, we can't fail!
34844 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
34845 */
34846- memcpy(switcher_vma->addr, start_switcher_text,
34847+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
34848 end_switcher_text - start_switcher_text);
34849
34850 printk(KERN_INFO "lguest: mapped switcher at %p\n",
34851diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
34852index 4af12e1..0e89afe 100644
34853--- a/drivers/lguest/x86/core.c
34854+++ b/drivers/lguest/x86/core.c
34855@@ -59,7 +59,7 @@ static struct {
34856 /* Offset from where switcher.S was compiled to where we've copied it */
34857 static unsigned long switcher_offset(void)
34858 {
34859- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
34860+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
34861 }
34862
34863 /* This cpu's struct lguest_pages. */
34864@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
34865 * These copies are pretty cheap, so we do them unconditionally: */
34866 /* Save the current Host top-level page directory.
34867 */
34868+
34869+#ifdef CONFIG_PAX_PER_CPU_PGD
34870+ pages->state.host_cr3 = read_cr3();
34871+#else
34872 pages->state.host_cr3 = __pa(current->mm->pgd);
34873+#endif
34874+
34875 /*
34876 * Set up the Guest's page tables to see this CPU's pages (and no
34877 * other CPU's pages).
34878@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
34879 * compiled-in switcher code and the high-mapped copy we just made.
34880 */
34881 for (i = 0; i < IDT_ENTRIES; i++)
34882- default_idt_entries[i] += switcher_offset();
34883+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
34884
34885 /*
34886 * Set up the Switcher's per-cpu areas.
34887@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
34888 * it will be undisturbed when we switch. To change %cs and jump we
34889 * need this structure to feed to Intel's "lcall" instruction.
34890 */
34891- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
34892+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
34893 lguest_entry.segment = LGUEST_CS;
34894
34895 /*
34896diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
34897index 40634b0..4f5855e 100644
34898--- a/drivers/lguest/x86/switcher_32.S
34899+++ b/drivers/lguest/x86/switcher_32.S
34900@@ -87,6 +87,7 @@
34901 #include <asm/page.h>
34902 #include <asm/segment.h>
34903 #include <asm/lguest.h>
34904+#include <asm/processor-flags.h>
34905
34906 // We mark the start of the code to copy
34907 // It's placed in .text tho it's never run here
34908@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
34909 // Changes type when we load it: damn Intel!
34910 // For after we switch over our page tables
34911 // That entry will be read-only: we'd crash.
34912+
34913+#ifdef CONFIG_PAX_KERNEXEC
34914+ mov %cr0, %edx
34915+ xor $X86_CR0_WP, %edx
34916+ mov %edx, %cr0
34917+#endif
34918+
34919 movl $(GDT_ENTRY_TSS*8), %edx
34920 ltr %dx
34921
34922@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
34923 // Let's clear it again for our return.
34924 // The GDT descriptor of the Host
34925 // Points to the table after two "size" bytes
34926- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
34927+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
34928 // Clear "used" from type field (byte 5, bit 2)
34929- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
34930+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
34931+
34932+#ifdef CONFIG_PAX_KERNEXEC
34933+ mov %cr0, %eax
34934+ xor $X86_CR0_WP, %eax
34935+ mov %eax, %cr0
34936+#endif
34937
34938 // Once our page table's switched, the Guest is live!
34939 // The Host fades as we run this final step.
34940@@ -295,13 +309,12 @@ deliver_to_host:
34941 // I consulted gcc, and it gave
34942 // These instructions, which I gladly credit:
34943 leal (%edx,%ebx,8), %eax
34944- movzwl (%eax),%edx
34945- movl 4(%eax), %eax
34946- xorw %ax, %ax
34947- orl %eax, %edx
34948+ movl 4(%eax), %edx
34949+ movw (%eax), %dx
34950 // Now the address of the handler's in %edx
34951 // We call it now: its "iret" drops us home.
34952- jmp *%edx
34953+ ljmp $__KERNEL_CS, $1f
34954+1: jmp *%edx
34955
34956 // Every interrupt can come to us here
34957 // But we must truly tell each apart.
34958diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
34959index 7155945..4bcc562 100644
34960--- a/drivers/md/bitmap.c
34961+++ b/drivers/md/bitmap.c
34962@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
34963 chunk_kb ? "KB" : "B");
34964 if (bitmap->storage.file) {
34965 seq_printf(seq, ", file: ");
34966- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
34967+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
34968 }
34969
34970 seq_printf(seq, "\n");
34971diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
34972index a651d52..82f8a95 100644
34973--- a/drivers/md/dm-ioctl.c
34974+++ b/drivers/md/dm-ioctl.c
34975@@ -1601,7 +1601,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
34976 cmd == DM_LIST_VERSIONS_CMD)
34977 return 0;
34978
34979- if ((cmd == DM_DEV_CREATE_CMD)) {
34980+ if (cmd == DM_DEV_CREATE_CMD) {
34981 if (!*param->name) {
34982 DMWARN("name not supplied when creating device");
34983 return -EINVAL;
34984diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
34985index fd61f98..8050783 100644
34986--- a/drivers/md/dm-raid1.c
34987+++ b/drivers/md/dm-raid1.c
34988@@ -40,7 +40,7 @@ enum dm_raid1_error {
34989
34990 struct mirror {
34991 struct mirror_set *ms;
34992- atomic_t error_count;
34993+ atomic_unchecked_t error_count;
34994 unsigned long error_type;
34995 struct dm_dev *dev;
34996 sector_t offset;
34997@@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
34998 struct mirror *m;
34999
35000 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
35001- if (!atomic_read(&m->error_count))
35002+ if (!atomic_read_unchecked(&m->error_count))
35003 return m;
35004
35005 return NULL;
35006@@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
35007 * simple way to tell if a device has encountered
35008 * errors.
35009 */
35010- atomic_inc(&m->error_count);
35011+ atomic_inc_unchecked(&m->error_count);
35012
35013 if (test_and_set_bit(error_type, &m->error_type))
35014 return;
35015@@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
35016 struct mirror *m = get_default_mirror(ms);
35017
35018 do {
35019- if (likely(!atomic_read(&m->error_count)))
35020+ if (likely(!atomic_read_unchecked(&m->error_count)))
35021 return m;
35022
35023 if (m-- == ms->mirror)
35024@@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
35025 {
35026 struct mirror *default_mirror = get_default_mirror(m->ms);
35027
35028- return !atomic_read(&default_mirror->error_count);
35029+ return !atomic_read_unchecked(&default_mirror->error_count);
35030 }
35031
35032 static int mirror_available(struct mirror_set *ms, struct bio *bio)
35033@@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
35034 */
35035 if (likely(region_in_sync(ms, region, 1)))
35036 m = choose_mirror(ms, bio->bi_sector);
35037- else if (m && atomic_read(&m->error_count))
35038+ else if (m && atomic_read_unchecked(&m->error_count))
35039 m = NULL;
35040
35041 if (likely(m))
35042@@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
35043 }
35044
35045 ms->mirror[mirror].ms = ms;
35046- atomic_set(&(ms->mirror[mirror].error_count), 0);
35047+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
35048 ms->mirror[mirror].error_type = 0;
35049 ms->mirror[mirror].offset = offset;
35050
35051@@ -1356,7 +1356,7 @@ static void mirror_resume(struct dm_target *ti)
35052 */
35053 static char device_status_char(struct mirror *m)
35054 {
35055- if (!atomic_read(&(m->error_count)))
35056+ if (!atomic_read_unchecked(&(m->error_count)))
35057 return 'A';
35058
35059 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
35060diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
35061index e2f87653..f279abe 100644
35062--- a/drivers/md/dm-stripe.c
35063+++ b/drivers/md/dm-stripe.c
35064@@ -20,7 +20,7 @@ struct stripe {
35065 struct dm_dev *dev;
35066 sector_t physical_start;
35067
35068- atomic_t error_count;
35069+ atomic_unchecked_t error_count;
35070 };
35071
35072 struct stripe_c {
35073@@ -183,7 +183,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
35074 kfree(sc);
35075 return r;
35076 }
35077- atomic_set(&(sc->stripe[i].error_count), 0);
35078+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
35079 }
35080
35081 ti->private = sc;
35082@@ -324,7 +324,7 @@ static int stripe_status(struct dm_target *ti, status_type_t type,
35083 DMEMIT("%d ", sc->stripes);
35084 for (i = 0; i < sc->stripes; i++) {
35085 DMEMIT("%s ", sc->stripe[i].dev->name);
35086- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
35087+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
35088 'D' : 'A';
35089 }
35090 buffer[i] = '\0';
35091@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
35092 */
35093 for (i = 0; i < sc->stripes; i++)
35094 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
35095- atomic_inc(&(sc->stripe[i].error_count));
35096- if (atomic_read(&(sc->stripe[i].error_count)) <
35097+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
35098+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
35099 DM_IO_ERROR_THRESHOLD)
35100 schedule_work(&sc->trigger_event);
35101 }
35102diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
35103index fa29557..d24a5b7 100644
35104--- a/drivers/md/dm-table.c
35105+++ b/drivers/md/dm-table.c
35106@@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
35107 if (!dev_size)
35108 return 0;
35109
35110- if ((start >= dev_size) || (start + len > dev_size)) {
35111+ if ((start >= dev_size) || (len > dev_size - start)) {
35112 DMWARN("%s: %s too small for target: "
35113 "start=%llu, len=%llu, dev_size=%llu",
35114 dm_device_name(ti->table->md), bdevname(bdev, b),
35115diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
35116index 693e149..b7e0fde 100644
35117--- a/drivers/md/dm-thin-metadata.c
35118+++ b/drivers/md/dm-thin-metadata.c
35119@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35120 {
35121 pmd->info.tm = pmd->tm;
35122 pmd->info.levels = 2;
35123- pmd->info.value_type.context = pmd->data_sm;
35124+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35125 pmd->info.value_type.size = sizeof(__le64);
35126 pmd->info.value_type.inc = data_block_inc;
35127 pmd->info.value_type.dec = data_block_dec;
35128@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
35129
35130 pmd->bl_info.tm = pmd->tm;
35131 pmd->bl_info.levels = 1;
35132- pmd->bl_info.value_type.context = pmd->data_sm;
35133+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
35134 pmd->bl_info.value_type.size = sizeof(__le64);
35135 pmd->bl_info.value_type.inc = data_block_inc;
35136 pmd->bl_info.value_type.dec = data_block_dec;
35137diff --git a/drivers/md/dm.c b/drivers/md/dm.c
35138index 77e6eff..913d695 100644
35139--- a/drivers/md/dm.c
35140+++ b/drivers/md/dm.c
35141@@ -182,9 +182,9 @@ struct mapped_device {
35142 /*
35143 * Event handling.
35144 */
35145- atomic_t event_nr;
35146+ atomic_unchecked_t event_nr;
35147 wait_queue_head_t eventq;
35148- atomic_t uevent_seq;
35149+ atomic_unchecked_t uevent_seq;
35150 struct list_head uevent_list;
35151 spinlock_t uevent_lock; /* Protect access to uevent_list */
35152
35153@@ -1847,8 +1847,8 @@ static struct mapped_device *alloc_dev(int minor)
35154 rwlock_init(&md->map_lock);
35155 atomic_set(&md->holders, 1);
35156 atomic_set(&md->open_count, 0);
35157- atomic_set(&md->event_nr, 0);
35158- atomic_set(&md->uevent_seq, 0);
35159+ atomic_set_unchecked(&md->event_nr, 0);
35160+ atomic_set_unchecked(&md->uevent_seq, 0);
35161 INIT_LIST_HEAD(&md->uevent_list);
35162 spin_lock_init(&md->uevent_lock);
35163
35164@@ -1982,7 +1982,7 @@ static void event_callback(void *context)
35165
35166 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
35167
35168- atomic_inc(&md->event_nr);
35169+ atomic_inc_unchecked(&md->event_nr);
35170 wake_up(&md->eventq);
35171 }
35172
35173@@ -2637,18 +2637,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
35174
35175 uint32_t dm_next_uevent_seq(struct mapped_device *md)
35176 {
35177- return atomic_add_return(1, &md->uevent_seq);
35178+ return atomic_add_return_unchecked(1, &md->uevent_seq);
35179 }
35180
35181 uint32_t dm_get_event_nr(struct mapped_device *md)
35182 {
35183- return atomic_read(&md->event_nr);
35184+ return atomic_read_unchecked(&md->event_nr);
35185 }
35186
35187 int dm_wait_event(struct mapped_device *md, int event_nr)
35188 {
35189 return wait_event_interruptible(md->eventq,
35190- (event_nr != atomic_read(&md->event_nr)));
35191+ (event_nr != atomic_read_unchecked(&md->event_nr)));
35192 }
35193
35194 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
35195diff --git a/drivers/md/md.c b/drivers/md/md.c
35196index 6120071..31d9be2 100644
35197--- a/drivers/md/md.c
35198+++ b/drivers/md/md.c
35199@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
35200 * start build, activate spare
35201 */
35202 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
35203-static atomic_t md_event_count;
35204+static atomic_unchecked_t md_event_count;
35205 void md_new_event(struct mddev *mddev)
35206 {
35207- atomic_inc(&md_event_count);
35208+ atomic_inc_unchecked(&md_event_count);
35209 wake_up(&md_event_waiters);
35210 }
35211 EXPORT_SYMBOL_GPL(md_new_event);
35212@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
35213 */
35214 static void md_new_event_inintr(struct mddev *mddev)
35215 {
35216- atomic_inc(&md_event_count);
35217+ atomic_inc_unchecked(&md_event_count);
35218 wake_up(&md_event_waiters);
35219 }
35220
35221@@ -1504,7 +1504,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
35222 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
35223 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
35224 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
35225- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35226+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
35227
35228 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
35229 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
35230@@ -1748,7 +1748,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
35231 else
35232 sb->resync_offset = cpu_to_le64(0);
35233
35234- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
35235+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
35236
35237 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
35238 sb->size = cpu_to_le64(mddev->dev_sectors);
35239@@ -2748,7 +2748,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
35240 static ssize_t
35241 errors_show(struct md_rdev *rdev, char *page)
35242 {
35243- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
35244+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
35245 }
35246
35247 static ssize_t
35248@@ -2757,7 +2757,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
35249 char *e;
35250 unsigned long n = simple_strtoul(buf, &e, 10);
35251 if (*buf && (*e == 0 || *e == '\n')) {
35252- atomic_set(&rdev->corrected_errors, n);
35253+ atomic_set_unchecked(&rdev->corrected_errors, n);
35254 return len;
35255 }
35256 return -EINVAL;
35257@@ -3204,8 +3204,8 @@ int md_rdev_init(struct md_rdev *rdev)
35258 rdev->sb_loaded = 0;
35259 rdev->bb_page = NULL;
35260 atomic_set(&rdev->nr_pending, 0);
35261- atomic_set(&rdev->read_errors, 0);
35262- atomic_set(&rdev->corrected_errors, 0);
35263+ atomic_set_unchecked(&rdev->read_errors, 0);
35264+ atomic_set_unchecked(&rdev->corrected_errors, 0);
35265
35266 INIT_LIST_HEAD(&rdev->same_set);
35267 init_waitqueue_head(&rdev->blocked_wait);
35268@@ -6984,7 +6984,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
35269
35270 spin_unlock(&pers_lock);
35271 seq_printf(seq, "\n");
35272- seq->poll_event = atomic_read(&md_event_count);
35273+ seq->poll_event = atomic_read_unchecked(&md_event_count);
35274 return 0;
35275 }
35276 if (v == (void*)2) {
35277@@ -7087,7 +7087,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
35278 return error;
35279
35280 seq = file->private_data;
35281- seq->poll_event = atomic_read(&md_event_count);
35282+ seq->poll_event = atomic_read_unchecked(&md_event_count);
35283 return error;
35284 }
35285
35286@@ -7101,7 +7101,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
35287 /* always allow read */
35288 mask = POLLIN | POLLRDNORM;
35289
35290- if (seq->poll_event != atomic_read(&md_event_count))
35291+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
35292 mask |= POLLERR | POLLPRI;
35293 return mask;
35294 }
35295@@ -7145,7 +7145,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
35296 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
35297 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
35298 (int)part_stat_read(&disk->part0, sectors[1]) -
35299- atomic_read(&disk->sync_io);
35300+ atomic_read_unchecked(&disk->sync_io);
35301 /* sync IO will cause sync_io to increase before the disk_stats
35302 * as sync_io is counted when a request starts, and
35303 * disk_stats is counted when it completes.
35304diff --git a/drivers/md/md.h b/drivers/md/md.h
35305index af443ab..0f93be3 100644
35306--- a/drivers/md/md.h
35307+++ b/drivers/md/md.h
35308@@ -94,13 +94,13 @@ struct md_rdev {
35309 * only maintained for arrays that
35310 * support hot removal
35311 */
35312- atomic_t read_errors; /* number of consecutive read errors that
35313+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
35314 * we have tried to ignore.
35315 */
35316 struct timespec last_read_error; /* monotonic time since our
35317 * last read error
35318 */
35319- atomic_t corrected_errors; /* number of corrected read errors,
35320+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
35321 * for reporting to userspace and storing
35322 * in superblock.
35323 */
35324@@ -432,7 +432,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
35325
35326 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
35327 {
35328- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35329+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
35330 }
35331
35332 struct md_personality
35333diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
35334index 1cbfc6b..56e1dbb 100644
35335--- a/drivers/md/persistent-data/dm-space-map.h
35336+++ b/drivers/md/persistent-data/dm-space-map.h
35337@@ -60,6 +60,7 @@ struct dm_space_map {
35338 int (*root_size)(struct dm_space_map *sm, size_t *result);
35339 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
35340 };
35341+typedef struct dm_space_map __no_const dm_space_map_no_const;
35342
35343 /*----------------------------------------------------------------*/
35344
35345diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
35346index a0f7309..5599dbc 100644
35347--- a/drivers/md/raid1.c
35348+++ b/drivers/md/raid1.c
35349@@ -1819,7 +1819,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
35350 if (r1_sync_page_io(rdev, sect, s,
35351 bio->bi_io_vec[idx].bv_page,
35352 READ) != 0)
35353- atomic_add(s, &rdev->corrected_errors);
35354+ atomic_add_unchecked(s, &rdev->corrected_errors);
35355 }
35356 sectors -= s;
35357 sect += s;
35358@@ -2041,7 +2041,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
35359 test_bit(In_sync, &rdev->flags)) {
35360 if (r1_sync_page_io(rdev, sect, s,
35361 conf->tmppage, READ)) {
35362- atomic_add(s, &rdev->corrected_errors);
35363+ atomic_add_unchecked(s, &rdev->corrected_errors);
35364 printk(KERN_INFO
35365 "md/raid1:%s: read error corrected "
35366 "(%d sectors at %llu on %s)\n",
35367diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
35368index c9acbd7..386cd3e 100644
35369--- a/drivers/md/raid10.c
35370+++ b/drivers/md/raid10.c
35371@@ -1878,7 +1878,7 @@ static void end_sync_read(struct bio *bio, int error)
35372 /* The write handler will notice the lack of
35373 * R10BIO_Uptodate and record any errors etc
35374 */
35375- atomic_add(r10_bio->sectors,
35376+ atomic_add_unchecked(r10_bio->sectors,
35377 &conf->mirrors[d].rdev->corrected_errors);
35378
35379 /* for reconstruct, we always reschedule after a read.
35380@@ -2227,7 +2227,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35381 {
35382 struct timespec cur_time_mon;
35383 unsigned long hours_since_last;
35384- unsigned int read_errors = atomic_read(&rdev->read_errors);
35385+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
35386
35387 ktime_get_ts(&cur_time_mon);
35388
35389@@ -2249,9 +2249,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
35390 * overflowing the shift of read_errors by hours_since_last.
35391 */
35392 if (hours_since_last >= 8 * sizeof(read_errors))
35393- atomic_set(&rdev->read_errors, 0);
35394+ atomic_set_unchecked(&rdev->read_errors, 0);
35395 else
35396- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
35397+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
35398 }
35399
35400 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
35401@@ -2305,8 +2305,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35402 return;
35403
35404 check_decay_read_errors(mddev, rdev);
35405- atomic_inc(&rdev->read_errors);
35406- if (atomic_read(&rdev->read_errors) > max_read_errors) {
35407+ atomic_inc_unchecked(&rdev->read_errors);
35408+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
35409 char b[BDEVNAME_SIZE];
35410 bdevname(rdev->bdev, b);
35411
35412@@ -2314,7 +2314,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35413 "md/raid10:%s: %s: Raid device exceeded "
35414 "read_error threshold [cur %d:max %d]\n",
35415 mdname(mddev), b,
35416- atomic_read(&rdev->read_errors), max_read_errors);
35417+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
35418 printk(KERN_NOTICE
35419 "md/raid10:%s: %s: Failing raid device\n",
35420 mdname(mddev), b);
35421@@ -2469,7 +2469,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
35422 sect +
35423 choose_data_offset(r10_bio, rdev)),
35424 bdevname(rdev->bdev, b));
35425- atomic_add(s, &rdev->corrected_errors);
35426+ atomic_add_unchecked(s, &rdev->corrected_errors);
35427 }
35428
35429 rdev_dec_pending(rdev, mddev);
35430diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
35431index a450268..c4168a9 100644
35432--- a/drivers/md/raid5.c
35433+++ b/drivers/md/raid5.c
35434@@ -1789,21 +1789,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
35435 mdname(conf->mddev), STRIPE_SECTORS,
35436 (unsigned long long)s,
35437 bdevname(rdev->bdev, b));
35438- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
35439+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
35440 clear_bit(R5_ReadError, &sh->dev[i].flags);
35441 clear_bit(R5_ReWrite, &sh->dev[i].flags);
35442 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
35443 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
35444
35445- if (atomic_read(&rdev->read_errors))
35446- atomic_set(&rdev->read_errors, 0);
35447+ if (atomic_read_unchecked(&rdev->read_errors))
35448+ atomic_set_unchecked(&rdev->read_errors, 0);
35449 } else {
35450 const char *bdn = bdevname(rdev->bdev, b);
35451 int retry = 0;
35452 int set_bad = 0;
35453
35454 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
35455- atomic_inc(&rdev->read_errors);
35456+ atomic_inc_unchecked(&rdev->read_errors);
35457 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
35458 printk_ratelimited(
35459 KERN_WARNING
35460@@ -1831,7 +1831,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
35461 mdname(conf->mddev),
35462 (unsigned long long)s,
35463 bdn);
35464- } else if (atomic_read(&rdev->read_errors)
35465+ } else if (atomic_read_unchecked(&rdev->read_errors)
35466 > conf->max_nr_stripes)
35467 printk(KERN_WARNING
35468 "md/raid:%s: Too many read errors, failing device %s.\n",
35469diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
35470index d33101a..6b13069 100644
35471--- a/drivers/media/dvb-core/dvbdev.c
35472+++ b/drivers/media/dvb-core/dvbdev.c
35473@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
35474 const struct dvb_device *template, void *priv, int type)
35475 {
35476 struct dvb_device *dvbdev;
35477- struct file_operations *dvbdevfops;
35478+ file_operations_no_const *dvbdevfops;
35479 struct device *clsdev;
35480 int minor;
35481 int id;
35482diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
35483index 404f63a..4796533 100644
35484--- a/drivers/media/dvb-frontends/dib3000.h
35485+++ b/drivers/media/dvb-frontends/dib3000.h
35486@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
35487 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
35488 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
35489 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
35490-};
35491+} __no_const;
35492
35493 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
35494 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
35495diff --git a/drivers/media/pci/cx88/cx88-alsa.c b/drivers/media/pci/cx88/cx88-alsa.c
35496index 3aa6856..435ad25 100644
35497--- a/drivers/media/pci/cx88/cx88-alsa.c
35498+++ b/drivers/media/pci/cx88/cx88-alsa.c
35499@@ -749,7 +749,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
35500 * Only boards with eeprom and byte 1 at eeprom=1 have it
35501 */
35502
35503-static const struct pci_device_id cx88_audio_pci_tbl[] __devinitdata = {
35504+static const struct pci_device_id cx88_audio_pci_tbl[] __devinitconst = {
35505 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35506 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
35507 {0, }
35508diff --git a/drivers/media/pci/ddbridge/ddbridge-core.c b/drivers/media/pci/ddbridge/ddbridge-core.c
35509index feff57e..66a2c67 100644
35510--- a/drivers/media/pci/ddbridge/ddbridge-core.c
35511+++ b/drivers/media/pci/ddbridge/ddbridge-core.c
35512@@ -1679,7 +1679,7 @@ static struct ddb_info ddb_v6 = {
35513 .subvendor = _subvend, .subdevice = _subdev, \
35514 .driver_data = (unsigned long)&_driverdata }
35515
35516-static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
35517+static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
35518 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
35519 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
35520 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
35521diff --git a/drivers/media/pci/ngene/ngene-cards.c b/drivers/media/pci/ngene/ngene-cards.c
35522index 96a13ed..6df45b4 100644
35523--- a/drivers/media/pci/ngene/ngene-cards.c
35524+++ b/drivers/media/pci/ngene/ngene-cards.c
35525@@ -741,7 +741,7 @@ static struct ngene_info ngene_info_terratec = {
35526
35527 /****************************************************************************/
35528
35529-static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
35530+static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
35531 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
35532 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
35533 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
35534diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
35535index a3b1a34..71ce0e3 100644
35536--- a/drivers/media/platform/omap/omap_vout.c
35537+++ b/drivers/media/platform/omap/omap_vout.c
35538@@ -65,7 +65,6 @@ enum omap_vout_channels {
35539 OMAP_VIDEO2,
35540 };
35541
35542-static struct videobuf_queue_ops video_vbq_ops;
35543 /* Variables configurable through module params*/
35544 static u32 video1_numbuffers = 3;
35545 static u32 video2_numbuffers = 3;
35546@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
35547 {
35548 struct videobuf_queue *q;
35549 struct omap_vout_device *vout = NULL;
35550+ static struct videobuf_queue_ops video_vbq_ops = {
35551+ .buf_setup = omap_vout_buffer_setup,
35552+ .buf_prepare = omap_vout_buffer_prepare,
35553+ .buf_release = omap_vout_buffer_release,
35554+ .buf_queue = omap_vout_buffer_queue,
35555+ };
35556
35557 vout = video_drvdata(file);
35558 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
35559@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
35560 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
35561
35562 q = &vout->vbq;
35563- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
35564- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
35565- video_vbq_ops.buf_release = omap_vout_buffer_release;
35566- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
35567 spin_lock_init(&vout->vbq_lock);
35568
35569 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
35570diff --git a/drivers/media/platform/timblogiw.c b/drivers/media/platform/timblogiw.c
35571index 02194c0..36d69c1 100644
35572--- a/drivers/media/platform/timblogiw.c
35573+++ b/drivers/media/platform/timblogiw.c
35574@@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
35575
35576 /* Platform device functions */
35577
35578-static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35579+static struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35580 .vidioc_querycap = timblogiw_querycap,
35581 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
35582 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
35583@@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
35584 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
35585 };
35586
35587-static __devinitconst struct v4l2_file_operations timblogiw_fops = {
35588+static struct v4l2_file_operations timblogiw_fops = {
35589 .owner = THIS_MODULE,
35590 .open = timblogiw_open,
35591 .release = timblogiw_close,
35592diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
35593index 697a421..16c5a5f 100644
35594--- a/drivers/media/radio/radio-cadet.c
35595+++ b/drivers/media/radio/radio-cadet.c
35596@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35597 unsigned char readbuf[RDS_BUFFER];
35598 int i = 0;
35599
35600+ if (count > RDS_BUFFER)
35601+ return -EFAULT;
35602 mutex_lock(&dev->lock);
35603 if (dev->rdsstat == 0)
35604 cadet_start_rds(dev);
35605@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
35606 while (i < count && dev->rdsin != dev->rdsout)
35607 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
35608
35609- if (i && copy_to_user(data, readbuf, i))
35610+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
35611 i = -EFAULT;
35612 unlock:
35613 mutex_unlock(&dev->lock);
35614diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
35615index 3940bb0..fb3952a 100644
35616--- a/drivers/media/usb/dvb-usb/cxusb.c
35617+++ b/drivers/media/usb/dvb-usb/cxusb.c
35618@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
35619
35620 struct dib0700_adapter_state {
35621 int (*set_param_save) (struct dvb_frontend *);
35622-};
35623+} __no_const;
35624
35625 static int dib7070_set_param_override(struct dvb_frontend *fe)
35626 {
35627diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
35628index 9382895..ac8093c 100644
35629--- a/drivers/media/usb/dvb-usb/dw2102.c
35630+++ b/drivers/media/usb/dvb-usb/dw2102.c
35631@@ -95,7 +95,7 @@ struct su3000_state {
35632
35633 struct s6x0_state {
35634 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
35635-};
35636+} __no_const;
35637
35638 /* debug */
35639 static int dvb_usb_dw2102_debug;
35640diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
35641index fb69baa..cf7ad22 100644
35642--- a/drivers/message/fusion/mptbase.c
35643+++ b/drivers/message/fusion/mptbase.c
35644@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
35645 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
35646 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
35647
35648+#ifdef CONFIG_GRKERNSEC_HIDESYM
35649+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
35650+#else
35651 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
35652 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
35653+#endif
35654+
35655 /*
35656 * Rounding UP to nearest 4-kB boundary here...
35657 */
35658diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
35659index 551262e..7551198 100644
35660--- a/drivers/message/fusion/mptsas.c
35661+++ b/drivers/message/fusion/mptsas.c
35662@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
35663 return 0;
35664 }
35665
35666+static inline void
35667+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35668+{
35669+ if (phy_info->port_details) {
35670+ phy_info->port_details->rphy = rphy;
35671+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35672+ ioc->name, rphy));
35673+ }
35674+
35675+ if (rphy) {
35676+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35677+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35678+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35679+ ioc->name, rphy, rphy->dev.release));
35680+ }
35681+}
35682+
35683 /* no mutex */
35684 static void
35685 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
35686@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
35687 return NULL;
35688 }
35689
35690-static inline void
35691-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
35692-{
35693- if (phy_info->port_details) {
35694- phy_info->port_details->rphy = rphy;
35695- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
35696- ioc->name, rphy));
35697- }
35698-
35699- if (rphy) {
35700- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
35701- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
35702- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
35703- ioc->name, rphy, rphy->dev.release));
35704- }
35705-}
35706-
35707 static inline struct sas_port *
35708 mptsas_get_port(struct mptsas_phyinfo *phy_info)
35709 {
35710diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
35711index 0c3ced7..1fe34ec 100644
35712--- a/drivers/message/fusion/mptscsih.c
35713+++ b/drivers/message/fusion/mptscsih.c
35714@@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
35715
35716 h = shost_priv(SChost);
35717
35718- if (h) {
35719- if (h->info_kbuf == NULL)
35720- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35721- return h->info_kbuf;
35722- h->info_kbuf[0] = '\0';
35723+ if (!h)
35724+ return NULL;
35725
35726- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35727- h->info_kbuf[size-1] = '\0';
35728- }
35729+ if (h->info_kbuf == NULL)
35730+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
35731+ return h->info_kbuf;
35732+ h->info_kbuf[0] = '\0';
35733+
35734+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
35735+ h->info_kbuf[size-1] = '\0';
35736
35737 return h->info_kbuf;
35738 }
35739diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
35740index 8001aa6..b137580 100644
35741--- a/drivers/message/i2o/i2o_proc.c
35742+++ b/drivers/message/i2o/i2o_proc.c
35743@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
35744 "Array Controller Device"
35745 };
35746
35747-static char *chtostr(char *tmp, u8 *chars, int n)
35748-{
35749- tmp[0] = 0;
35750- return strncat(tmp, (char *)chars, n);
35751-}
35752-
35753 static int i2o_report_query_status(struct seq_file *seq, int block_status,
35754 char *group)
35755 {
35756@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35757 } *result;
35758
35759 i2o_exec_execute_ddm_table ddm_table;
35760- char tmp[28 + 1];
35761
35762 result = kmalloc(sizeof(*result), GFP_KERNEL);
35763 if (!result)
35764@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
35765
35766 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
35767 seq_printf(seq, "%-#8x", ddm_table.module_id);
35768- seq_printf(seq, "%-29s",
35769- chtostr(tmp, ddm_table.module_name_version, 28));
35770+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
35771 seq_printf(seq, "%9d ", ddm_table.data_size);
35772 seq_printf(seq, "%8d", ddm_table.code_size);
35773
35774@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35775
35776 i2o_driver_result_table *result;
35777 i2o_driver_store_table *dst;
35778- char tmp[28 + 1];
35779
35780 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
35781 if (result == NULL)
35782@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
35783
35784 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
35785 seq_printf(seq, "%-#8x", dst->module_id);
35786- seq_printf(seq, "%-29s",
35787- chtostr(tmp, dst->module_name_version, 28));
35788- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
35789+ seq_printf(seq, "%-.28s", dst->module_name_version);
35790+ seq_printf(seq, "%-.8s", dst->date);
35791 seq_printf(seq, "%8d ", dst->module_size);
35792 seq_printf(seq, "%8d ", dst->mpb_size);
35793 seq_printf(seq, "0x%04x", dst->module_flags);
35794@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35795 // == (allow) 512d bytes (max)
35796 static u16 *work16 = (u16 *) work32;
35797 int token;
35798- char tmp[16 + 1];
35799
35800 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
35801
35802@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
35803 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
35804 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
35805 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
35806- seq_printf(seq, "Vendor info : %s\n",
35807- chtostr(tmp, (u8 *) (work32 + 2), 16));
35808- seq_printf(seq, "Product info : %s\n",
35809- chtostr(tmp, (u8 *) (work32 + 6), 16));
35810- seq_printf(seq, "Description : %s\n",
35811- chtostr(tmp, (u8 *) (work32 + 10), 16));
35812- seq_printf(seq, "Product rev. : %s\n",
35813- chtostr(tmp, (u8 *) (work32 + 14), 8));
35814+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
35815+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
35816+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
35817+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
35818
35819 seq_printf(seq, "Serial number : ");
35820 print_serial_number(seq, (u8 *) (work32 + 16),
35821@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35822 u8 pad[256]; // allow up to 256 byte (max) serial number
35823 } result;
35824
35825- char tmp[24 + 1];
35826-
35827 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
35828
35829 if (token < 0) {
35830@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
35831 }
35832
35833 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
35834- seq_printf(seq, "Module name : %s\n",
35835- chtostr(tmp, result.module_name, 24));
35836- seq_printf(seq, "Module revision : %s\n",
35837- chtostr(tmp, result.module_rev, 8));
35838+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
35839+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
35840
35841 seq_printf(seq, "Serial number : ");
35842 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
35843@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35844 u8 instance_number[4];
35845 } result;
35846
35847- char tmp[64 + 1];
35848-
35849 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
35850
35851 if (token < 0) {
35852@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
35853 return 0;
35854 }
35855
35856- seq_printf(seq, "Device name : %s\n",
35857- chtostr(tmp, result.device_name, 64));
35858- seq_printf(seq, "Service name : %s\n",
35859- chtostr(tmp, result.service_name, 64));
35860- seq_printf(seq, "Physical name : %s\n",
35861- chtostr(tmp, result.physical_location, 64));
35862- seq_printf(seq, "Instance number : %s\n",
35863- chtostr(tmp, result.instance_number, 4));
35864+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
35865+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
35866+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
35867+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
35868
35869 return 0;
35870 }
35871diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
35872index a8c08f3..155fe3d 100644
35873--- a/drivers/message/i2o/iop.c
35874+++ b/drivers/message/i2o/iop.c
35875@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
35876
35877 spin_lock_irqsave(&c->context_list_lock, flags);
35878
35879- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
35880- atomic_inc(&c->context_list_counter);
35881+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
35882+ atomic_inc_unchecked(&c->context_list_counter);
35883
35884- entry->context = atomic_read(&c->context_list_counter);
35885+ entry->context = atomic_read_unchecked(&c->context_list_counter);
35886
35887 list_add(&entry->list, &c->context_list);
35888
35889@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
35890
35891 #if BITS_PER_LONG == 64
35892 spin_lock_init(&c->context_list_lock);
35893- atomic_set(&c->context_list_counter, 0);
35894+ atomic_set_unchecked(&c->context_list_counter, 0);
35895 INIT_LIST_HEAD(&c->context_list);
35896 #endif
35897
35898diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
35899index 965c480..71f2db9 100644
35900--- a/drivers/mfd/janz-cmodio.c
35901+++ b/drivers/mfd/janz-cmodio.c
35902@@ -13,6 +13,7 @@
35903
35904 #include <linux/kernel.h>
35905 #include <linux/module.h>
35906+#include <linux/slab.h>
35907 #include <linux/init.h>
35908 #include <linux/pci.h>
35909 #include <linux/interrupt.h>
35910diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
35911index 3aa9a96..59cf685 100644
35912--- a/drivers/misc/kgdbts.c
35913+++ b/drivers/misc/kgdbts.c
35914@@ -832,7 +832,7 @@ static void run_plant_and_detach_test(int is_early)
35915 char before[BREAK_INSTR_SIZE];
35916 char after[BREAK_INSTR_SIZE];
35917
35918- probe_kernel_read(before, (char *)kgdbts_break_test,
35919+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
35920 BREAK_INSTR_SIZE);
35921 init_simple_test();
35922 ts.tst = plant_and_detach_test;
35923@@ -840,7 +840,7 @@ static void run_plant_and_detach_test(int is_early)
35924 /* Activate test with initial breakpoint */
35925 if (!is_early)
35926 kgdb_breakpoint();
35927- probe_kernel_read(after, (char *)kgdbts_break_test,
35928+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
35929 BREAK_INSTR_SIZE);
35930 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
35931 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
35932diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
35933index 4a87e5c..76bdf5c 100644
35934--- a/drivers/misc/lis3lv02d/lis3lv02d.c
35935+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
35936@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
35937 * the lid is closed. This leads to interrupts as soon as a little move
35938 * is done.
35939 */
35940- atomic_inc(&lis3->count);
35941+ atomic_inc_unchecked(&lis3->count);
35942
35943 wake_up_interruptible(&lis3->misc_wait);
35944 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
35945@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
35946 if (lis3->pm_dev)
35947 pm_runtime_get_sync(lis3->pm_dev);
35948
35949- atomic_set(&lis3->count, 0);
35950+ atomic_set_unchecked(&lis3->count, 0);
35951 return 0;
35952 }
35953
35954@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
35955 add_wait_queue(&lis3->misc_wait, &wait);
35956 while (true) {
35957 set_current_state(TASK_INTERRUPTIBLE);
35958- data = atomic_xchg(&lis3->count, 0);
35959+ data = atomic_xchg_unchecked(&lis3->count, 0);
35960 if (data)
35961 break;
35962
35963@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
35964 struct lis3lv02d, miscdev);
35965
35966 poll_wait(file, &lis3->misc_wait, wait);
35967- if (atomic_read(&lis3->count))
35968+ if (atomic_read_unchecked(&lis3->count))
35969 return POLLIN | POLLRDNORM;
35970 return 0;
35971 }
35972diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
35973index c439c82..1f20f57 100644
35974--- a/drivers/misc/lis3lv02d/lis3lv02d.h
35975+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
35976@@ -297,7 +297,7 @@ struct lis3lv02d {
35977 struct input_polled_dev *idev; /* input device */
35978 struct platform_device *pdev; /* platform device */
35979 struct regulator_bulk_data regulators[2];
35980- atomic_t count; /* interrupt count after last read */
35981+ atomic_unchecked_t count; /* interrupt count after last read */
35982 union axis_conversion ac; /* hw -> logical axis */
35983 int mapped_btns[3];
35984
35985diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
35986index 2f30bad..c4c13d0 100644
35987--- a/drivers/misc/sgi-gru/gruhandles.c
35988+++ b/drivers/misc/sgi-gru/gruhandles.c
35989@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
35990 unsigned long nsec;
35991
35992 nsec = CLKS2NSEC(clks);
35993- atomic_long_inc(&mcs_op_statistics[op].count);
35994- atomic_long_add(nsec, &mcs_op_statistics[op].total);
35995+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
35996+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
35997 if (mcs_op_statistics[op].max < nsec)
35998 mcs_op_statistics[op].max = nsec;
35999 }
36000diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
36001index 950dbe9..eeef0f8 100644
36002--- a/drivers/misc/sgi-gru/gruprocfs.c
36003+++ b/drivers/misc/sgi-gru/gruprocfs.c
36004@@ -32,9 +32,9 @@
36005
36006 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
36007
36008-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
36009+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
36010 {
36011- unsigned long val = atomic_long_read(v);
36012+ unsigned long val = atomic_long_read_unchecked(v);
36013
36014 seq_printf(s, "%16lu %s\n", val, id);
36015 }
36016@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
36017
36018 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
36019 for (op = 0; op < mcsop_last; op++) {
36020- count = atomic_long_read(&mcs_op_statistics[op].count);
36021- total = atomic_long_read(&mcs_op_statistics[op].total);
36022+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
36023+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
36024 max = mcs_op_statistics[op].max;
36025 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
36026 count ? total / count : 0, max);
36027diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
36028index 5c3ce24..4915ccb 100644
36029--- a/drivers/misc/sgi-gru/grutables.h
36030+++ b/drivers/misc/sgi-gru/grutables.h
36031@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
36032 * GRU statistics.
36033 */
36034 struct gru_stats_s {
36035- atomic_long_t vdata_alloc;
36036- atomic_long_t vdata_free;
36037- atomic_long_t gts_alloc;
36038- atomic_long_t gts_free;
36039- atomic_long_t gms_alloc;
36040- atomic_long_t gms_free;
36041- atomic_long_t gts_double_allocate;
36042- atomic_long_t assign_context;
36043- atomic_long_t assign_context_failed;
36044- atomic_long_t free_context;
36045- atomic_long_t load_user_context;
36046- atomic_long_t load_kernel_context;
36047- atomic_long_t lock_kernel_context;
36048- atomic_long_t unlock_kernel_context;
36049- atomic_long_t steal_user_context;
36050- atomic_long_t steal_kernel_context;
36051- atomic_long_t steal_context_failed;
36052- atomic_long_t nopfn;
36053- atomic_long_t asid_new;
36054- atomic_long_t asid_next;
36055- atomic_long_t asid_wrap;
36056- atomic_long_t asid_reuse;
36057- atomic_long_t intr;
36058- atomic_long_t intr_cbr;
36059- atomic_long_t intr_tfh;
36060- atomic_long_t intr_spurious;
36061- atomic_long_t intr_mm_lock_failed;
36062- atomic_long_t call_os;
36063- atomic_long_t call_os_wait_queue;
36064- atomic_long_t user_flush_tlb;
36065- atomic_long_t user_unload_context;
36066- atomic_long_t user_exception;
36067- atomic_long_t set_context_option;
36068- atomic_long_t check_context_retarget_intr;
36069- atomic_long_t check_context_unload;
36070- atomic_long_t tlb_dropin;
36071- atomic_long_t tlb_preload_page;
36072- atomic_long_t tlb_dropin_fail_no_asid;
36073- atomic_long_t tlb_dropin_fail_upm;
36074- atomic_long_t tlb_dropin_fail_invalid;
36075- atomic_long_t tlb_dropin_fail_range_active;
36076- atomic_long_t tlb_dropin_fail_idle;
36077- atomic_long_t tlb_dropin_fail_fmm;
36078- atomic_long_t tlb_dropin_fail_no_exception;
36079- atomic_long_t tfh_stale_on_fault;
36080- atomic_long_t mmu_invalidate_range;
36081- atomic_long_t mmu_invalidate_page;
36082- atomic_long_t flush_tlb;
36083- atomic_long_t flush_tlb_gru;
36084- atomic_long_t flush_tlb_gru_tgh;
36085- atomic_long_t flush_tlb_gru_zero_asid;
36086+ atomic_long_unchecked_t vdata_alloc;
36087+ atomic_long_unchecked_t vdata_free;
36088+ atomic_long_unchecked_t gts_alloc;
36089+ atomic_long_unchecked_t gts_free;
36090+ atomic_long_unchecked_t gms_alloc;
36091+ atomic_long_unchecked_t gms_free;
36092+ atomic_long_unchecked_t gts_double_allocate;
36093+ atomic_long_unchecked_t assign_context;
36094+ atomic_long_unchecked_t assign_context_failed;
36095+ atomic_long_unchecked_t free_context;
36096+ atomic_long_unchecked_t load_user_context;
36097+ atomic_long_unchecked_t load_kernel_context;
36098+ atomic_long_unchecked_t lock_kernel_context;
36099+ atomic_long_unchecked_t unlock_kernel_context;
36100+ atomic_long_unchecked_t steal_user_context;
36101+ atomic_long_unchecked_t steal_kernel_context;
36102+ atomic_long_unchecked_t steal_context_failed;
36103+ atomic_long_unchecked_t nopfn;
36104+ atomic_long_unchecked_t asid_new;
36105+ atomic_long_unchecked_t asid_next;
36106+ atomic_long_unchecked_t asid_wrap;
36107+ atomic_long_unchecked_t asid_reuse;
36108+ atomic_long_unchecked_t intr;
36109+ atomic_long_unchecked_t intr_cbr;
36110+ atomic_long_unchecked_t intr_tfh;
36111+ atomic_long_unchecked_t intr_spurious;
36112+ atomic_long_unchecked_t intr_mm_lock_failed;
36113+ atomic_long_unchecked_t call_os;
36114+ atomic_long_unchecked_t call_os_wait_queue;
36115+ atomic_long_unchecked_t user_flush_tlb;
36116+ atomic_long_unchecked_t user_unload_context;
36117+ atomic_long_unchecked_t user_exception;
36118+ atomic_long_unchecked_t set_context_option;
36119+ atomic_long_unchecked_t check_context_retarget_intr;
36120+ atomic_long_unchecked_t check_context_unload;
36121+ atomic_long_unchecked_t tlb_dropin;
36122+ atomic_long_unchecked_t tlb_preload_page;
36123+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
36124+ atomic_long_unchecked_t tlb_dropin_fail_upm;
36125+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
36126+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
36127+ atomic_long_unchecked_t tlb_dropin_fail_idle;
36128+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
36129+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
36130+ atomic_long_unchecked_t tfh_stale_on_fault;
36131+ atomic_long_unchecked_t mmu_invalidate_range;
36132+ atomic_long_unchecked_t mmu_invalidate_page;
36133+ atomic_long_unchecked_t flush_tlb;
36134+ atomic_long_unchecked_t flush_tlb_gru;
36135+ atomic_long_unchecked_t flush_tlb_gru_tgh;
36136+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
36137
36138- atomic_long_t copy_gpa;
36139- atomic_long_t read_gpa;
36140+ atomic_long_unchecked_t copy_gpa;
36141+ atomic_long_unchecked_t read_gpa;
36142
36143- atomic_long_t mesq_receive;
36144- atomic_long_t mesq_receive_none;
36145- atomic_long_t mesq_send;
36146- atomic_long_t mesq_send_failed;
36147- atomic_long_t mesq_noop;
36148- atomic_long_t mesq_send_unexpected_error;
36149- atomic_long_t mesq_send_lb_overflow;
36150- atomic_long_t mesq_send_qlimit_reached;
36151- atomic_long_t mesq_send_amo_nacked;
36152- atomic_long_t mesq_send_put_nacked;
36153- atomic_long_t mesq_page_overflow;
36154- atomic_long_t mesq_qf_locked;
36155- atomic_long_t mesq_qf_noop_not_full;
36156- atomic_long_t mesq_qf_switch_head_failed;
36157- atomic_long_t mesq_qf_unexpected_error;
36158- atomic_long_t mesq_noop_unexpected_error;
36159- atomic_long_t mesq_noop_lb_overflow;
36160- atomic_long_t mesq_noop_qlimit_reached;
36161- atomic_long_t mesq_noop_amo_nacked;
36162- atomic_long_t mesq_noop_put_nacked;
36163- atomic_long_t mesq_noop_page_overflow;
36164+ atomic_long_unchecked_t mesq_receive;
36165+ atomic_long_unchecked_t mesq_receive_none;
36166+ atomic_long_unchecked_t mesq_send;
36167+ atomic_long_unchecked_t mesq_send_failed;
36168+ atomic_long_unchecked_t mesq_noop;
36169+ atomic_long_unchecked_t mesq_send_unexpected_error;
36170+ atomic_long_unchecked_t mesq_send_lb_overflow;
36171+ atomic_long_unchecked_t mesq_send_qlimit_reached;
36172+ atomic_long_unchecked_t mesq_send_amo_nacked;
36173+ atomic_long_unchecked_t mesq_send_put_nacked;
36174+ atomic_long_unchecked_t mesq_page_overflow;
36175+ atomic_long_unchecked_t mesq_qf_locked;
36176+ atomic_long_unchecked_t mesq_qf_noop_not_full;
36177+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
36178+ atomic_long_unchecked_t mesq_qf_unexpected_error;
36179+ atomic_long_unchecked_t mesq_noop_unexpected_error;
36180+ atomic_long_unchecked_t mesq_noop_lb_overflow;
36181+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
36182+ atomic_long_unchecked_t mesq_noop_amo_nacked;
36183+ atomic_long_unchecked_t mesq_noop_put_nacked;
36184+ atomic_long_unchecked_t mesq_noop_page_overflow;
36185
36186 };
36187
36188@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
36189 tghop_invalidate, mcsop_last};
36190
36191 struct mcs_op_statistic {
36192- atomic_long_t count;
36193- atomic_long_t total;
36194+ atomic_long_unchecked_t count;
36195+ atomic_long_unchecked_t total;
36196 unsigned long max;
36197 };
36198
36199@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
36200
36201 #define STAT(id) do { \
36202 if (gru_options & OPT_STATS) \
36203- atomic_long_inc(&gru_stats.id); \
36204+ atomic_long_inc_unchecked(&gru_stats.id); \
36205 } while (0)
36206
36207 #ifdef CONFIG_SGI_GRU_DEBUG
36208diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
36209index c862cd4..0d176fe 100644
36210--- a/drivers/misc/sgi-xp/xp.h
36211+++ b/drivers/misc/sgi-xp/xp.h
36212@@ -288,7 +288,7 @@ struct xpc_interface {
36213 xpc_notify_func, void *);
36214 void (*received) (short, int, void *);
36215 enum xp_retval (*partid_to_nasids) (short, void *);
36216-};
36217+} __no_const;
36218
36219 extern struct xpc_interface xpc_interface;
36220
36221diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
36222index b94d5f7..7f494c5 100644
36223--- a/drivers/misc/sgi-xp/xpc.h
36224+++ b/drivers/misc/sgi-xp/xpc.h
36225@@ -835,6 +835,7 @@ struct xpc_arch_operations {
36226 void (*received_payload) (struct xpc_channel *, void *);
36227 void (*notify_senders_of_disconnect) (struct xpc_channel *);
36228 };
36229+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
36230
36231 /* struct xpc_partition act_state values (for XPC HB) */
36232
36233@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
36234 /* found in xpc_main.c */
36235 extern struct device *xpc_part;
36236 extern struct device *xpc_chan;
36237-extern struct xpc_arch_operations xpc_arch_ops;
36238+extern xpc_arch_operations_no_const xpc_arch_ops;
36239 extern int xpc_disengage_timelimit;
36240 extern int xpc_disengage_timedout;
36241 extern int xpc_activate_IRQ_rcvd;
36242diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
36243index d971817..33bdca5 100644
36244--- a/drivers/misc/sgi-xp/xpc_main.c
36245+++ b/drivers/misc/sgi-xp/xpc_main.c
36246@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
36247 .notifier_call = xpc_system_die,
36248 };
36249
36250-struct xpc_arch_operations xpc_arch_ops;
36251+xpc_arch_operations_no_const xpc_arch_ops;
36252
36253 /*
36254 * Timer function to enforce the timelimit on the partition disengage.
36255@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
36256
36257 if (((die_args->trapnr == X86_TRAP_MF) ||
36258 (die_args->trapnr == X86_TRAP_XF)) &&
36259- !user_mode_vm(die_args->regs))
36260+ !user_mode(die_args->regs))
36261 xpc_die_deactivate();
36262
36263 break;
36264diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
36265index a0e1720..ee63d0b 100644
36266--- a/drivers/mmc/core/mmc_ops.c
36267+++ b/drivers/mmc/core/mmc_ops.c
36268@@ -245,7 +245,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
36269 void *data_buf;
36270 int is_on_stack;
36271
36272- is_on_stack = object_is_on_stack(buf);
36273+ is_on_stack = object_starts_on_stack(buf);
36274 if (is_on_stack) {
36275 /*
36276 * dma onto stack is unsafe/nonportable, but callers to this
36277diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
36278index 53b8fd9..615b462 100644
36279--- a/drivers/mmc/host/dw_mmc.h
36280+++ b/drivers/mmc/host/dw_mmc.h
36281@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
36282 int (*parse_dt)(struct dw_mci *host);
36283 int (*setup_bus)(struct dw_mci *host,
36284 struct device_node *slot_np, u8 bus_width);
36285-};
36286+} __do_const;
36287 #endif /* _DW_MMC_H_ */
36288diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
36289index a4eb8b5..8c0628f 100644
36290--- a/drivers/mtd/devices/doc2000.c
36291+++ b/drivers/mtd/devices/doc2000.c
36292@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
36293
36294 /* The ECC will not be calculated correctly if less than 512 is written */
36295 /* DBB-
36296- if (len != 0x200 && eccbuf)
36297+ if (len != 0x200)
36298 printk(KERN_WARNING
36299 "ECC needs a full sector write (adr: %lx size %lx)\n",
36300 (long) to, (long) len);
36301diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
36302index e706a23..b3d262f 100644
36303--- a/drivers/mtd/nand/denali.c
36304+++ b/drivers/mtd/nand/denali.c
36305@@ -26,6 +26,7 @@
36306 #include <linux/pci.h>
36307 #include <linux/mtd/mtd.h>
36308 #include <linux/module.h>
36309+#include <linux/slab.h>
36310
36311 #include "denali.h"
36312
36313diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
36314index 51b9d6a..52af9a7 100644
36315--- a/drivers/mtd/nftlmount.c
36316+++ b/drivers/mtd/nftlmount.c
36317@@ -24,6 +24,7 @@
36318 #include <asm/errno.h>
36319 #include <linux/delay.h>
36320 #include <linux/slab.h>
36321+#include <linux/sched.h>
36322 #include <linux/mtd/mtd.h>
36323 #include <linux/mtd/nand.h>
36324 #include <linux/mtd/nftl.h>
36325diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
36326index 203ff9d..0968ca8 100644
36327--- a/drivers/net/ethernet/8390/ax88796.c
36328+++ b/drivers/net/ethernet/8390/ax88796.c
36329@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
36330 if (ax->plat->reg_offsets)
36331 ei_local->reg_offset = ax->plat->reg_offsets;
36332 else {
36333+ resource_size_t _mem_size = mem_size;
36334+ do_div(_mem_size, 0x18);
36335 ei_local->reg_offset = ax->reg_offsets;
36336 for (ret = 0; ret < 0x18; ret++)
36337- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
36338+ ax->reg_offsets[ret] = _mem_size * ret;
36339 }
36340
36341 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
36342diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36343index 9c5ea6c..eaad276 100644
36344--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36345+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
36346@@ -1046,7 +1046,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
36347 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
36348 {
36349 /* RX_MODE controlling object */
36350- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
36351+ bnx2x_init_rx_mode_obj(bp);
36352
36353 /* multicast configuration controlling object */
36354 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
36355diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36356index 614981c..11216c7 100644
36357--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36358+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
36359@@ -2375,15 +2375,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
36360 return rc;
36361 }
36362
36363-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36364- struct bnx2x_rx_mode_obj *o)
36365+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
36366 {
36367 if (CHIP_IS_E1x(bp)) {
36368- o->wait_comp = bnx2x_empty_rx_mode_wait;
36369- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
36370+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
36371+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
36372 } else {
36373- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
36374- o->config_rx_mode = bnx2x_set_rx_mode_e2;
36375+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
36376+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
36377 }
36378 }
36379
36380diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36381index acf2fe4..efb96df 100644
36382--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36383+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
36384@@ -1281,8 +1281,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
36385
36386 /********************* RX MODE ****************/
36387
36388-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
36389- struct bnx2x_rx_mode_obj *o);
36390+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
36391
36392 /**
36393 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
36394diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
36395index d9308c32..d87b824 100644
36396--- a/drivers/net/ethernet/broadcom/tg3.h
36397+++ b/drivers/net/ethernet/broadcom/tg3.h
36398@@ -140,6 +140,7 @@
36399 #define CHIPREV_ID_5750_A0 0x4000
36400 #define CHIPREV_ID_5750_A1 0x4001
36401 #define CHIPREV_ID_5750_A3 0x4003
36402+#define CHIPREV_ID_5750_C1 0x4201
36403 #define CHIPREV_ID_5750_C2 0x4202
36404 #define CHIPREV_ID_5752_A0_HW 0x5000
36405 #define CHIPREV_ID_5752_A0 0x6000
36406diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36407index 8cffcdf..aadf043 100644
36408--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36409+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
36410@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
36411 */
36412 struct l2t_skb_cb {
36413 arp_failure_handler_func arp_failure_handler;
36414-};
36415+} __no_const;
36416
36417 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
36418
36419diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
36420index f879e92..726f20f 100644
36421--- a/drivers/net/ethernet/dec/tulip/de4x5.c
36422+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
36423@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36424 for (i=0; i<ETH_ALEN; i++) {
36425 tmp.addr[i] = dev->dev_addr[i];
36426 }
36427- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36428+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
36429 break;
36430
36431 case DE4X5_SET_HWADDR: /* Set the hardware address */
36432@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
36433 spin_lock_irqsave(&lp->lock, flags);
36434 memcpy(&statbuf, &lp->pktStats, ioc->len);
36435 spin_unlock_irqrestore(&lp->lock, flags);
36436- if (copy_to_user(ioc->data, &statbuf, ioc->len))
36437+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
36438 return -EFAULT;
36439 break;
36440 }
36441diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
36442index d1b6cc5..cde0d97 100644
36443--- a/drivers/net/ethernet/emulex/benet/be_main.c
36444+++ b/drivers/net/ethernet/emulex/benet/be_main.c
36445@@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
36446
36447 if (wrapped)
36448 newacc += 65536;
36449- ACCESS_ONCE(*acc) = newacc;
36450+ ACCESS_ONCE_RW(*acc) = newacc;
36451 }
36452
36453 void be_parse_stats(struct be_adapter *adapter)
36454diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
36455index 74d749e..eefb1bd 100644
36456--- a/drivers/net/ethernet/faraday/ftgmac100.c
36457+++ b/drivers/net/ethernet/faraday/ftgmac100.c
36458@@ -31,6 +31,8 @@
36459 #include <linux/netdevice.h>
36460 #include <linux/phy.h>
36461 #include <linux/platform_device.h>
36462+#include <linux/interrupt.h>
36463+#include <linux/irqreturn.h>
36464 #include <net/ip.h>
36465
36466 #include "ftgmac100.h"
36467diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
36468index b901a01..1ff32ee 100644
36469--- a/drivers/net/ethernet/faraday/ftmac100.c
36470+++ b/drivers/net/ethernet/faraday/ftmac100.c
36471@@ -31,6 +31,8 @@
36472 #include <linux/module.h>
36473 #include <linux/netdevice.h>
36474 #include <linux/platform_device.h>
36475+#include <linux/interrupt.h>
36476+#include <linux/irqreturn.h>
36477
36478 #include "ftmac100.h"
36479
36480diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36481index d929131..aed108f 100644
36482--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36483+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
36484@@ -865,7 +865,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
36485 /* store the new cycle speed */
36486 adapter->cycle_speed = cycle_speed;
36487
36488- ACCESS_ONCE(adapter->base_incval) = incval;
36489+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
36490 smp_mb();
36491
36492 /* grab the ptp lock */
36493diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36494index c2e420a..26a75e0 100644
36495--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
36496+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
36497@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36498 struct __vxge_hw_fifo *fifo;
36499 struct vxge_hw_fifo_config *config;
36500 u32 txdl_size, txdl_per_memblock;
36501- struct vxge_hw_mempool_cbs fifo_mp_callback;
36502+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
36503+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
36504+ };
36505+
36506 struct __vxge_hw_virtualpath *vpath;
36507
36508 if ((vp == NULL) || (attr == NULL)) {
36509@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
36510 goto exit;
36511 }
36512
36513- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
36514-
36515 fifo->mempool =
36516 __vxge_hw_mempool_create(vpath->hldev,
36517 fifo->config->memblock_size,
36518diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
36519index 927aa33..a6c2518 100644
36520--- a/drivers/net/ethernet/realtek/r8169.c
36521+++ b/drivers/net/ethernet/realtek/r8169.c
36522@@ -747,22 +747,22 @@ struct rtl8169_private {
36523 struct mdio_ops {
36524 void (*write)(struct rtl8169_private *, int, int);
36525 int (*read)(struct rtl8169_private *, int);
36526- } mdio_ops;
36527+ } __no_const mdio_ops;
36528
36529 struct pll_power_ops {
36530 void (*down)(struct rtl8169_private *);
36531 void (*up)(struct rtl8169_private *);
36532- } pll_power_ops;
36533+ } __no_const pll_power_ops;
36534
36535 struct jumbo_ops {
36536 void (*enable)(struct rtl8169_private *);
36537 void (*disable)(struct rtl8169_private *);
36538- } jumbo_ops;
36539+ } __no_const jumbo_ops;
36540
36541 struct csi_ops {
36542 void (*write)(struct rtl8169_private *, int, int);
36543 u32 (*read)(struct rtl8169_private *, int);
36544- } csi_ops;
36545+ } __no_const csi_ops;
36546
36547 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
36548 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
36549diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
36550index 0767043f..08c2553 100644
36551--- a/drivers/net/ethernet/sfc/ptp.c
36552+++ b/drivers/net/ethernet/sfc/ptp.c
36553@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
36554 (u32)((u64)ptp->start.dma_addr >> 32));
36555
36556 /* Clear flag that signals MC ready */
36557- ACCESS_ONCE(*start) = 0;
36558+ ACCESS_ONCE_RW(*start) = 0;
36559 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
36560 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
36561
36562diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36563index 0c74a70..3bc6f68 100644
36564--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36565+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
36566@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
36567
36568 writel(value, ioaddr + MMC_CNTRL);
36569
36570- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36571- MMC_CNTRL, value);
36572+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
36573+// MMC_CNTRL, value);
36574 }
36575
36576 /* To mask all all interrupts.*/
36577diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
36578index 5fd6f46..ee1f265 100644
36579--- a/drivers/net/hyperv/hyperv_net.h
36580+++ b/drivers/net/hyperv/hyperv_net.h
36581@@ -101,7 +101,7 @@ struct rndis_device {
36582
36583 enum rndis_device_state state;
36584 bool link_state;
36585- atomic_t new_req_id;
36586+ atomic_unchecked_t new_req_id;
36587
36588 spinlock_t request_lock;
36589 struct list_head req_list;
36590diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
36591index 928148c..d83298e 100644
36592--- a/drivers/net/hyperv/rndis_filter.c
36593+++ b/drivers/net/hyperv/rndis_filter.c
36594@@ -107,7 +107,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
36595 * template
36596 */
36597 set = &rndis_msg->msg.set_req;
36598- set->req_id = atomic_inc_return(&dev->new_req_id);
36599+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36600
36601 /* Add to the request list */
36602 spin_lock_irqsave(&dev->request_lock, flags);
36603@@ -760,7 +760,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
36604
36605 /* Setup the rndis set */
36606 halt = &request->request_msg.msg.halt_req;
36607- halt->req_id = atomic_inc_return(&dev->new_req_id);
36608+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
36609
36610 /* Ignore return since this msg is optional. */
36611 rndis_filter_send_request(dev, request);
36612diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
36613index 7d39add..037e1da 100644
36614--- a/drivers/net/ieee802154/fakehard.c
36615+++ b/drivers/net/ieee802154/fakehard.c
36616@@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
36617 phy->transmit_power = 0xbf;
36618
36619 dev->netdev_ops = &fake_ops;
36620- dev->ml_priv = &fake_mlme;
36621+ dev->ml_priv = (void *)&fake_mlme;
36622
36623 priv = netdev_priv(dev);
36624 priv->phy = phy;
36625diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
36626index 0f0f9ce..0ca5819 100644
36627--- a/drivers/net/macvtap.c
36628+++ b/drivers/net/macvtap.c
36629@@ -1100,7 +1100,7 @@ static int macvtap_device_event(struct notifier_block *unused,
36630 return NOTIFY_DONE;
36631 }
36632
36633-static struct notifier_block macvtap_notifier_block __read_mostly = {
36634+static struct notifier_block macvtap_notifier_block = {
36635 .notifier_call = macvtap_device_event,
36636 };
36637
36638diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
36639index daec9b0..6428fcb 100644
36640--- a/drivers/net/phy/mdio-bitbang.c
36641+++ b/drivers/net/phy/mdio-bitbang.c
36642@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
36643 struct mdiobb_ctrl *ctrl = bus->priv;
36644
36645 module_put(ctrl->ops->owner);
36646+ mdiobus_unregister(bus);
36647 mdiobus_free(bus);
36648 }
36649 EXPORT_SYMBOL(free_mdio_bitbang);
36650diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
36651index eb3f5ce..d773730 100644
36652--- a/drivers/net/ppp/ppp_generic.c
36653+++ b/drivers/net/ppp/ppp_generic.c
36654@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36655 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
36656 struct ppp_stats stats;
36657 struct ppp_comp_stats cstats;
36658- char *vers;
36659
36660 switch (cmd) {
36661 case SIOCGPPPSTATS:
36662@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36663 break;
36664
36665 case SIOCGPPPVER:
36666- vers = PPP_VERSION;
36667- if (copy_to_user(addr, vers, strlen(vers) + 1))
36668+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
36669 break;
36670 err = 0;
36671 break;
36672diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
36673index ad86660..9fd0884 100644
36674--- a/drivers/net/team/team.c
36675+++ b/drivers/net/team/team.c
36676@@ -2601,7 +2601,7 @@ static int team_device_event(struct notifier_block *unused,
36677 return NOTIFY_DONE;
36678 }
36679
36680-static struct notifier_block team_notifier_block __read_mostly = {
36681+static struct notifier_block team_notifier_block = {
36682 .notifier_call = team_device_event,
36683 };
36684
36685diff --git a/drivers/net/tun.c b/drivers/net/tun.c
36686index 0873cdc..ddb178e 100644
36687--- a/drivers/net/tun.c
36688+++ b/drivers/net/tun.c
36689@@ -1374,7 +1374,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
36690 }
36691
36692 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36693- unsigned long arg, int ifreq_len)
36694+ unsigned long arg, size_t ifreq_len)
36695 {
36696 struct tun_file *tfile = file->private_data;
36697 struct tun_struct *tun;
36698@@ -1387,6 +1387,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
36699 int vnet_hdr_sz;
36700 int ret;
36701
36702+ if (ifreq_len > sizeof ifr)
36703+ return -EFAULT;
36704+
36705 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
36706 if (copy_from_user(&ifr, argp, ifreq_len))
36707 return -EFAULT;
36708diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
36709index 605a4ba..a883dd1 100644
36710--- a/drivers/net/usb/hso.c
36711+++ b/drivers/net/usb/hso.c
36712@@ -71,7 +71,7 @@
36713 #include <asm/byteorder.h>
36714 #include <linux/serial_core.h>
36715 #include <linux/serial.h>
36716-
36717+#include <asm/local.h>
36718
36719 #define MOD_AUTHOR "Option Wireless"
36720 #define MOD_DESCRIPTION "USB High Speed Option driver"
36721@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
36722 struct urb *urb;
36723
36724 urb = serial->rx_urb[0];
36725- if (serial->port.count > 0) {
36726+ if (atomic_read(&serial->port.count) > 0) {
36727 count = put_rxbuf_data(urb, serial);
36728 if (count == -1)
36729 return;
36730@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
36731 DUMP1(urb->transfer_buffer, urb->actual_length);
36732
36733 /* Anyone listening? */
36734- if (serial->port.count == 0)
36735+ if (atomic_read(&serial->port.count) == 0)
36736 return;
36737
36738 if (status == 0) {
36739@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36740 tty_port_tty_set(&serial->port, tty);
36741
36742 /* check for port already opened, if not set the termios */
36743- serial->port.count++;
36744- if (serial->port.count == 1) {
36745+ if (atomic_inc_return(&serial->port.count) == 1) {
36746 serial->rx_state = RX_IDLE;
36747 /* Force default termio settings */
36748 _hso_serial_set_termios(tty, NULL);
36749@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
36750 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
36751 if (result) {
36752 hso_stop_serial_device(serial->parent);
36753- serial->port.count--;
36754+ atomic_dec(&serial->port.count);
36755 kref_put(&serial->parent->ref, hso_serial_ref_free);
36756 }
36757 } else {
36758@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
36759
36760 /* reset the rts and dtr */
36761 /* do the actual close */
36762- serial->port.count--;
36763+ atomic_dec(&serial->port.count);
36764
36765- if (serial->port.count <= 0) {
36766- serial->port.count = 0;
36767+ if (atomic_read(&serial->port.count) <= 0) {
36768+ atomic_set(&serial->port.count, 0);
36769 tty_port_tty_set(&serial->port, NULL);
36770 if (!usb_gone)
36771 hso_stop_serial_device(serial->parent);
36772@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
36773
36774 /* the actual setup */
36775 spin_lock_irqsave(&serial->serial_lock, flags);
36776- if (serial->port.count)
36777+ if (atomic_read(&serial->port.count))
36778 _hso_serial_set_termios(tty, old);
36779 else
36780 tty->termios = *old;
36781@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
36782 D1("Pending read interrupt on port %d\n", i);
36783 spin_lock(&serial->serial_lock);
36784 if (serial->rx_state == RX_IDLE &&
36785- serial->port.count > 0) {
36786+ atomic_read(&serial->port.count) > 0) {
36787 /* Setup and send a ctrl req read on
36788 * port i */
36789 if (!serial->rx_urb_filled[0]) {
36790@@ -3078,7 +3077,7 @@ static int hso_resume(struct usb_interface *iface)
36791 /* Start all serial ports */
36792 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
36793 if (serial_table[i] && (serial_table[i]->interface == iface)) {
36794- if (dev2ser(serial_table[i])->port.count) {
36795+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
36796 result =
36797 hso_start_serial_device(serial_table[i], GFP_NOIO);
36798 hso_kick_transmit(dev2ser(serial_table[i]));
36799diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36800index 8d78253..bebbb68 100644
36801--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36802+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
36803@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36804 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
36805 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
36806
36807- ACCESS_ONCE(ads->ds_link) = i->link;
36808- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
36809+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
36810+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
36811
36812 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
36813 ctl6 = SM(i->keytype, AR_EncrType);
36814@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36815
36816 if ((i->is_first || i->is_last) &&
36817 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
36818- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
36819+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
36820 | set11nTries(i->rates, 1)
36821 | set11nTries(i->rates, 2)
36822 | set11nTries(i->rates, 3)
36823 | (i->dur_update ? AR_DurUpdateEna : 0)
36824 | SM(0, AR_BurstDur);
36825
36826- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
36827+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
36828 | set11nRate(i->rates, 1)
36829 | set11nRate(i->rates, 2)
36830 | set11nRate(i->rates, 3);
36831 } else {
36832- ACCESS_ONCE(ads->ds_ctl2) = 0;
36833- ACCESS_ONCE(ads->ds_ctl3) = 0;
36834+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
36835+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
36836 }
36837
36838 if (!i->is_first) {
36839- ACCESS_ONCE(ads->ds_ctl0) = 0;
36840- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36841- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36842+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
36843+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36844+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36845 return;
36846 }
36847
36848@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36849 break;
36850 }
36851
36852- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36853+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
36854 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36855 | SM(i->txpower, AR_XmitPower)
36856 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36857@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36858 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
36859 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
36860
36861- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
36862- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
36863+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
36864+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
36865
36866 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
36867 return;
36868
36869- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36870+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
36871 | set11nPktDurRTSCTS(i->rates, 1);
36872
36873- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36874+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
36875 | set11nPktDurRTSCTS(i->rates, 3);
36876
36877- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36878+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
36879 | set11nRateFlags(i->rates, 1)
36880 | set11nRateFlags(i->rates, 2)
36881 | set11nRateFlags(i->rates, 3)
36882diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36883index 301bf72..3f5654f 100644
36884--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36885+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
36886@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36887 (i->qcu << AR_TxQcuNum_S) | desc_len;
36888
36889 checksum += val;
36890- ACCESS_ONCE(ads->info) = val;
36891+ ACCESS_ONCE_RW(ads->info) = val;
36892
36893 checksum += i->link;
36894- ACCESS_ONCE(ads->link) = i->link;
36895+ ACCESS_ONCE_RW(ads->link) = i->link;
36896
36897 checksum += i->buf_addr[0];
36898- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
36899+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
36900 checksum += i->buf_addr[1];
36901- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
36902+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
36903 checksum += i->buf_addr[2];
36904- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
36905+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
36906 checksum += i->buf_addr[3];
36907- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
36908+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
36909
36910 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
36911- ACCESS_ONCE(ads->ctl3) = val;
36912+ ACCESS_ONCE_RW(ads->ctl3) = val;
36913 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
36914- ACCESS_ONCE(ads->ctl5) = val;
36915+ ACCESS_ONCE_RW(ads->ctl5) = val;
36916 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
36917- ACCESS_ONCE(ads->ctl7) = val;
36918+ ACCESS_ONCE_RW(ads->ctl7) = val;
36919 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
36920- ACCESS_ONCE(ads->ctl9) = val;
36921+ ACCESS_ONCE_RW(ads->ctl9) = val;
36922
36923 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
36924- ACCESS_ONCE(ads->ctl10) = checksum;
36925+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
36926
36927 if (i->is_first || i->is_last) {
36928- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
36929+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
36930 | set11nTries(i->rates, 1)
36931 | set11nTries(i->rates, 2)
36932 | set11nTries(i->rates, 3)
36933 | (i->dur_update ? AR_DurUpdateEna : 0)
36934 | SM(0, AR_BurstDur);
36935
36936- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
36937+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
36938 | set11nRate(i->rates, 1)
36939 | set11nRate(i->rates, 2)
36940 | set11nRate(i->rates, 3);
36941 } else {
36942- ACCESS_ONCE(ads->ctl13) = 0;
36943- ACCESS_ONCE(ads->ctl14) = 0;
36944+ ACCESS_ONCE_RW(ads->ctl13) = 0;
36945+ ACCESS_ONCE_RW(ads->ctl14) = 0;
36946 }
36947
36948 ads->ctl20 = 0;
36949@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36950
36951 ctl17 = SM(i->keytype, AR_EncrType);
36952 if (!i->is_first) {
36953- ACCESS_ONCE(ads->ctl11) = 0;
36954- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36955- ACCESS_ONCE(ads->ctl15) = 0;
36956- ACCESS_ONCE(ads->ctl16) = 0;
36957- ACCESS_ONCE(ads->ctl17) = ctl17;
36958- ACCESS_ONCE(ads->ctl18) = 0;
36959- ACCESS_ONCE(ads->ctl19) = 0;
36960+ ACCESS_ONCE_RW(ads->ctl11) = 0;
36961+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
36962+ ACCESS_ONCE_RW(ads->ctl15) = 0;
36963+ ACCESS_ONCE_RW(ads->ctl16) = 0;
36964+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36965+ ACCESS_ONCE_RW(ads->ctl18) = 0;
36966+ ACCESS_ONCE_RW(ads->ctl19) = 0;
36967 return;
36968 }
36969
36970- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36971+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
36972 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
36973 | SM(i->txpower, AR_XmitPower)
36974 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
36975@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
36976 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
36977 ctl12 |= SM(val, AR_PAPRDChainMask);
36978
36979- ACCESS_ONCE(ads->ctl12) = ctl12;
36980- ACCESS_ONCE(ads->ctl17) = ctl17;
36981+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
36982+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
36983
36984- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36985+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
36986 | set11nPktDurRTSCTS(i->rates, 1);
36987
36988- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36989+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
36990 | set11nPktDurRTSCTS(i->rates, 3);
36991
36992- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
36993+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
36994 | set11nRateFlags(i->rates, 1)
36995 | set11nRateFlags(i->rates, 2)
36996 | set11nRateFlags(i->rates, 3)
36997 | SM(i->rtscts_rate, AR_RTSCTSRate);
36998
36999- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
37000+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
37001 }
37002
37003 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
37004diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
37005index dbc1b7a..67e2ca2 100644
37006--- a/drivers/net/wireless/ath/ath9k/hw.h
37007+++ b/drivers/net/wireless/ath/ath9k/hw.h
37008@@ -657,7 +657,7 @@ struct ath_hw_private_ops {
37009
37010 /* ANI */
37011 void (*ani_cache_ini_regs)(struct ath_hw *ah);
37012-};
37013+} __no_const;
37014
37015 /**
37016 * struct ath_hw_ops - callbacks used by hardware code and driver code
37017@@ -687,7 +687,7 @@ struct ath_hw_ops {
37018 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
37019 struct ath_hw_antcomb_conf *antconf);
37020 void (*antctrl_shared_chain_lnadiv)(struct ath_hw *hw, bool enable);
37021-};
37022+} __no_const;
37023
37024 struct ath_nf_limits {
37025 s16 max;
37026diff --git a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37027index 71ced17..cd82b12 100644
37028--- a/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37029+++ b/drivers/net/wireless/brcm80211/brcmfmac/wl_cfg80211.h
37030@@ -184,7 +184,7 @@ struct brcmf_cfg80211_event_loop {
37031 struct net_device *ndev,
37032 const struct brcmf_event_msg *e,
37033 void *data);
37034-};
37035+} __no_const;
37036
37037 /* basic structure of scan request */
37038 struct brcmf_cfg80211_scan_req {
37039@@ -239,7 +239,7 @@ struct brcmf_cfg80211_profile {
37040 struct brcmf_cfg80211_iscan_eloop {
37041 s32 (*handler[WL_SCAN_ERSULTS_LAST])
37042 (struct brcmf_cfg80211_info *cfg);
37043-};
37044+} __no_const;
37045
37046 /* dongle iscan controller */
37047 struct brcmf_cfg80211_iscan_ctrl {
37048diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
37049index e252acb..6ad1e65 100644
37050--- a/drivers/net/wireless/iwlegacy/3945-mac.c
37051+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
37052@@ -3615,7 +3615,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
37053 */
37054 if (il3945_mod_params.disable_hw_scan) {
37055 D_INFO("Disabling hw_scan\n");
37056- il3945_mac_ops.hw_scan = NULL;
37057+ pax_open_kernel();
37058+ *(void **)&il3945_mac_ops.hw_scan = NULL;
37059+ pax_close_kernel();
37060 }
37061
37062 D_INFO("*** LOAD DRIVER ***\n");
37063diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37064index 1a98fa3..51e6661 100644
37065--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37066+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
37067@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
37068 {
37069 struct iwl_priv *priv = file->private_data;
37070 char buf[64];
37071- int buf_size;
37072+ size_t buf_size;
37073 u32 offset, len;
37074
37075 memset(buf, 0, sizeof(buf));
37076@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
37077 struct iwl_priv *priv = file->private_data;
37078
37079 char buf[8];
37080- int buf_size;
37081+ size_t buf_size;
37082 u32 reset_flag;
37083
37084 memset(buf, 0, sizeof(buf));
37085@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
37086 {
37087 struct iwl_priv *priv = file->private_data;
37088 char buf[8];
37089- int buf_size;
37090+ size_t buf_size;
37091 int ht40;
37092
37093 memset(buf, 0, sizeof(buf));
37094@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
37095 {
37096 struct iwl_priv *priv = file->private_data;
37097 char buf[8];
37098- int buf_size;
37099+ size_t buf_size;
37100 int value;
37101
37102 memset(buf, 0, sizeof(buf));
37103@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
37104 {
37105 struct iwl_priv *priv = file->private_data;
37106 char buf[8];
37107- int buf_size;
37108+ size_t buf_size;
37109 int clear;
37110
37111 memset(buf, 0, sizeof(buf));
37112@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
37113 {
37114 struct iwl_priv *priv = file->private_data;
37115 char buf[8];
37116- int buf_size;
37117+ size_t buf_size;
37118 int trace;
37119
37120 memset(buf, 0, sizeof(buf));
37121@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
37122 {
37123 struct iwl_priv *priv = file->private_data;
37124 char buf[8];
37125- int buf_size;
37126+ size_t buf_size;
37127 int missed;
37128
37129 memset(buf, 0, sizeof(buf));
37130@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
37131
37132 struct iwl_priv *priv = file->private_data;
37133 char buf[8];
37134- int buf_size;
37135+ size_t buf_size;
37136 int plcp;
37137
37138 memset(buf, 0, sizeof(buf));
37139@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
37140
37141 struct iwl_priv *priv = file->private_data;
37142 char buf[8];
37143- int buf_size;
37144+ size_t buf_size;
37145 int flush;
37146
37147 memset(buf, 0, sizeof(buf));
37148@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
37149
37150 struct iwl_priv *priv = file->private_data;
37151 char buf[8];
37152- int buf_size;
37153+ size_t buf_size;
37154 int rts;
37155
37156 if (!priv->cfg->ht_params)
37157@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
37158 {
37159 struct iwl_priv *priv = file->private_data;
37160 char buf[8];
37161- int buf_size;
37162+ size_t buf_size;
37163
37164 memset(buf, 0, sizeof(buf));
37165 buf_size = min(count, sizeof(buf) - 1);
37166@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
37167 struct iwl_priv *priv = file->private_data;
37168 u32 event_log_flag;
37169 char buf[8];
37170- int buf_size;
37171+ size_t buf_size;
37172
37173 /* check that the interface is up */
37174 if (!iwl_is_ready(priv))
37175@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
37176 struct iwl_priv *priv = file->private_data;
37177 char buf[8];
37178 u32 calib_disabled;
37179- int buf_size;
37180+ size_t buf_size;
37181
37182 memset(buf, 0, sizeof(buf));
37183 buf_size = min(count, sizeof(buf) - 1);
37184diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
37185index fe0fffd..b4c5724 100644
37186--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
37187+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
37188@@ -1967,7 +1967,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
37189 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
37190
37191 char buf[8];
37192- int buf_size;
37193+ size_t buf_size;
37194 u32 reset_flag;
37195
37196 memset(buf, 0, sizeof(buf));
37197@@ -1988,7 +1988,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
37198 {
37199 struct iwl_trans *trans = file->private_data;
37200 char buf[8];
37201- int buf_size;
37202+ size_t buf_size;
37203 int csr;
37204
37205 memset(buf, 0, sizeof(buf));
37206diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
37207index 429ca32..f86236b 100644
37208--- a/drivers/net/wireless/mac80211_hwsim.c
37209+++ b/drivers/net/wireless/mac80211_hwsim.c
37210@@ -1751,9 +1751,11 @@ static int __init init_mac80211_hwsim(void)
37211 return -EINVAL;
37212
37213 if (fake_hw_scan) {
37214- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37215- mac80211_hwsim_ops.sw_scan_start = NULL;
37216- mac80211_hwsim_ops.sw_scan_complete = NULL;
37217+ pax_open_kernel();
37218+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
37219+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
37220+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
37221+ pax_close_kernel();
37222 }
37223
37224 spin_lock_init(&hwsim_radio_lock);
37225diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
37226index bd1f0cb..db85ab0 100644
37227--- a/drivers/net/wireless/rndis_wlan.c
37228+++ b/drivers/net/wireless/rndis_wlan.c
37229@@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
37230
37231 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
37232
37233- if (rts_threshold < 0 || rts_threshold > 2347)
37234+ if (rts_threshold > 2347)
37235 rts_threshold = 2347;
37236
37237 tmp = cpu_to_le32(rts_threshold);
37238diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
37239index 0751b35..246ba3e 100644
37240--- a/drivers/net/wireless/rt2x00/rt2x00.h
37241+++ b/drivers/net/wireless/rt2x00/rt2x00.h
37242@@ -398,7 +398,7 @@ struct rt2x00_intf {
37243 * for hardware which doesn't support hardware
37244 * sequence counting.
37245 */
37246- atomic_t seqno;
37247+ atomic_unchecked_t seqno;
37248 };
37249
37250 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
37251diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
37252index e488b94..14b6a0c 100644
37253--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
37254+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
37255@@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
37256 * sequence counter given by mac80211.
37257 */
37258 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
37259- seqno = atomic_add_return(0x10, &intf->seqno);
37260+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
37261 else
37262- seqno = atomic_read(&intf->seqno);
37263+ seqno = atomic_read_unchecked(&intf->seqno);
37264
37265 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
37266 hdr->seq_ctrl |= cpu_to_le16(seqno);
37267diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
37268index e2750a1..797e179 100644
37269--- a/drivers/net/wireless/ti/wl1251/sdio.c
37270+++ b/drivers/net/wireless/ti/wl1251/sdio.c
37271@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
37272
37273 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
37274
37275- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37276- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37277+ pax_open_kernel();
37278+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
37279+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
37280+ pax_close_kernel();
37281
37282 wl1251_info("using dedicated interrupt line");
37283 } else {
37284- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37285- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37286+ pax_open_kernel();
37287+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
37288+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
37289+ pax_close_kernel();
37290
37291 wl1251_info("using SDIO interrupt");
37292 }
37293diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
37294index dadf1db..d9db7a7 100644
37295--- a/drivers/net/wireless/ti/wl12xx/main.c
37296+++ b/drivers/net/wireless/ti/wl12xx/main.c
37297@@ -644,7 +644,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37298 sizeof(wl->conf.mem));
37299
37300 /* read data preparation is only needed by wl127x */
37301- wl->ops->prepare_read = wl127x_prepare_read;
37302+ pax_open_kernel();
37303+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37304+ pax_close_kernel();
37305
37306 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37307 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37308@@ -665,7 +667,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
37309 sizeof(wl->conf.mem));
37310
37311 /* read data preparation is only needed by wl127x */
37312- wl->ops->prepare_read = wl127x_prepare_read;
37313+ pax_open_kernel();
37314+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
37315+ pax_close_kernel();
37316
37317 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER, WL127X_IFTYPE_VER,
37318 WL127X_MAJOR_VER, WL127X_SUBTYPE_VER,
37319diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
37320index a39682a..1e8220c 100644
37321--- a/drivers/net/wireless/ti/wl18xx/main.c
37322+++ b/drivers/net/wireless/ti/wl18xx/main.c
37323@@ -1489,8 +1489,10 @@ static int wl18xx_setup(struct wl1271 *wl)
37324 }
37325
37326 if (!checksum_param) {
37327- wl18xx_ops.set_rx_csum = NULL;
37328- wl18xx_ops.init_vif = NULL;
37329+ pax_open_kernel();
37330+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
37331+ *(void **)&wl18xx_ops.init_vif = NULL;
37332+ pax_close_kernel();
37333 }
37334
37335 /* Enable 11a Band only if we have 5G antennas */
37336diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
37337index d93b2b6..ae50401 100644
37338--- a/drivers/oprofile/buffer_sync.c
37339+++ b/drivers/oprofile/buffer_sync.c
37340@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
37341 if (cookie == NO_COOKIE)
37342 offset = pc;
37343 if (cookie == INVALID_COOKIE) {
37344- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37345+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37346 offset = pc;
37347 }
37348 if (cookie != last_cookie) {
37349@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
37350 /* add userspace sample */
37351
37352 if (!mm) {
37353- atomic_inc(&oprofile_stats.sample_lost_no_mm);
37354+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
37355 return 0;
37356 }
37357
37358 cookie = lookup_dcookie(mm, s->eip, &offset);
37359
37360 if (cookie == INVALID_COOKIE) {
37361- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
37362+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
37363 return 0;
37364 }
37365
37366@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
37367 /* ignore backtraces if failed to add a sample */
37368 if (state == sb_bt_start) {
37369 state = sb_bt_ignore;
37370- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
37371+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
37372 }
37373 }
37374 release_mm(mm);
37375diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
37376index c0cc4e7..44d4e54 100644
37377--- a/drivers/oprofile/event_buffer.c
37378+++ b/drivers/oprofile/event_buffer.c
37379@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
37380 }
37381
37382 if (buffer_pos == buffer_size) {
37383- atomic_inc(&oprofile_stats.event_lost_overflow);
37384+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
37385 return;
37386 }
37387
37388diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
37389index ed2c3ec..deda85a 100644
37390--- a/drivers/oprofile/oprof.c
37391+++ b/drivers/oprofile/oprof.c
37392@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
37393 if (oprofile_ops.switch_events())
37394 return;
37395
37396- atomic_inc(&oprofile_stats.multiplex_counter);
37397+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
37398 start_switch_worker();
37399 }
37400
37401diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
37402index 917d28e..d62d981 100644
37403--- a/drivers/oprofile/oprofile_stats.c
37404+++ b/drivers/oprofile/oprofile_stats.c
37405@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
37406 cpu_buf->sample_invalid_eip = 0;
37407 }
37408
37409- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
37410- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37411- atomic_set(&oprofile_stats.event_lost_overflow, 0);
37412- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
37413- atomic_set(&oprofile_stats.multiplex_counter, 0);
37414+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
37415+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
37416+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
37417+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
37418+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
37419 }
37420
37421
37422diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
37423index 38b6fc0..b5cbfce 100644
37424--- a/drivers/oprofile/oprofile_stats.h
37425+++ b/drivers/oprofile/oprofile_stats.h
37426@@ -13,11 +13,11 @@
37427 #include <linux/atomic.h>
37428
37429 struct oprofile_stat_struct {
37430- atomic_t sample_lost_no_mm;
37431- atomic_t sample_lost_no_mapping;
37432- atomic_t bt_lost_no_mapping;
37433- atomic_t event_lost_overflow;
37434- atomic_t multiplex_counter;
37435+ atomic_unchecked_t sample_lost_no_mm;
37436+ atomic_unchecked_t sample_lost_no_mapping;
37437+ atomic_unchecked_t bt_lost_no_mapping;
37438+ atomic_unchecked_t event_lost_overflow;
37439+ atomic_unchecked_t multiplex_counter;
37440 };
37441
37442 extern struct oprofile_stat_struct oprofile_stats;
37443diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
37444index 849357c..b83c1e0 100644
37445--- a/drivers/oprofile/oprofilefs.c
37446+++ b/drivers/oprofile/oprofilefs.c
37447@@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
37448
37449
37450 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
37451- char const *name, atomic_t *val)
37452+ char const *name, atomic_unchecked_t *val)
37453 {
37454 return __oprofilefs_create_file(sb, root, name,
37455 &atomic_ro_fops, 0444, val);
37456diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
37457index 3f56bc0..707d642 100644
37458--- a/drivers/parport/procfs.c
37459+++ b/drivers/parport/procfs.c
37460@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
37461
37462 *ppos += len;
37463
37464- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
37465+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
37466 }
37467
37468 #ifdef CONFIG_PARPORT_1284
37469@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
37470
37471 *ppos += len;
37472
37473- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
37474+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
37475 }
37476 #endif /* IEEE1284.3 support. */
37477
37478diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
37479index a6a71c4..c91097b 100644
37480--- a/drivers/pci/hotplug/cpcihp_generic.c
37481+++ b/drivers/pci/hotplug/cpcihp_generic.c
37482@@ -73,7 +73,6 @@ static u16 port;
37483 static unsigned int enum_bit;
37484 static u8 enum_mask;
37485
37486-static struct cpci_hp_controller_ops generic_hpc_ops;
37487 static struct cpci_hp_controller generic_hpc;
37488
37489 static int __init validate_parameters(void)
37490@@ -139,6 +138,10 @@ static int query_enum(void)
37491 return ((value & enum_mask) == enum_mask);
37492 }
37493
37494+static struct cpci_hp_controller_ops generic_hpc_ops = {
37495+ .query_enum = query_enum,
37496+};
37497+
37498 static int __init cpcihp_generic_init(void)
37499 {
37500 int status;
37501@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
37502 pci_dev_put(dev);
37503
37504 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
37505- generic_hpc_ops.query_enum = query_enum;
37506 generic_hpc.ops = &generic_hpc_ops;
37507
37508 status = cpci_hp_register_controller(&generic_hpc);
37509diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
37510index 6bf8d2a..9711ce0 100644
37511--- a/drivers/pci/hotplug/cpcihp_zt5550.c
37512+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
37513@@ -59,7 +59,6 @@
37514 /* local variables */
37515 static bool debug;
37516 static bool poll;
37517-static struct cpci_hp_controller_ops zt5550_hpc_ops;
37518 static struct cpci_hp_controller zt5550_hpc;
37519
37520 /* Primary cPCI bus bridge device */
37521@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
37522 return 0;
37523 }
37524
37525+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
37526+ .query_enum = zt5550_hc_query_enum,
37527+};
37528+
37529 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
37530 {
37531 int status;
37532@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
37533 dbg("returned from zt5550_hc_config");
37534
37535 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
37536- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
37537 zt5550_hpc.ops = &zt5550_hpc_ops;
37538 if(!poll) {
37539 zt5550_hpc.irq = hc_dev->irq;
37540 zt5550_hpc.irq_flags = IRQF_SHARED;
37541 zt5550_hpc.dev_id = hc_dev;
37542
37543- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37544- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37545- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37546+ pax_open_kernel();
37547+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
37548+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
37549+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
37550+ pax_open_kernel();
37551 } else {
37552 info("using ENUM# polling mode");
37553 }
37554diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
37555index 76ba8a1..20ca857 100644
37556--- a/drivers/pci/hotplug/cpqphp_nvram.c
37557+++ b/drivers/pci/hotplug/cpqphp_nvram.c
37558@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
37559
37560 void compaq_nvram_init (void __iomem *rom_start)
37561 {
37562+
37563+#ifndef CONFIG_PAX_KERNEXEC
37564 if (rom_start) {
37565 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
37566 }
37567+#endif
37568+
37569 dbg("int15 entry = %p\n", compaq_int15_entry_point);
37570
37571 /* initialize our int15 lock */
37572diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
37573index 449f257..0731e96 100644
37574--- a/drivers/pci/pcie/aspm.c
37575+++ b/drivers/pci/pcie/aspm.c
37576@@ -27,9 +27,9 @@
37577 #define MODULE_PARAM_PREFIX "pcie_aspm."
37578
37579 /* Note: those are not register definitions */
37580-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
37581-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
37582-#define ASPM_STATE_L1 (4) /* L1 state */
37583+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
37584+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
37585+#define ASPM_STATE_L1 (4U) /* L1 state */
37586 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
37587 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
37588
37589diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
37590index ec909af..e7517f3 100644
37591--- a/drivers/pci/probe.c
37592+++ b/drivers/pci/probe.c
37593@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
37594 struct pci_bus_region region;
37595 bool bar_too_big = false, bar_disabled = false;
37596
37597- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
37598+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
37599
37600 /* No printks while decoding is disabled! */
37601 if (!dev->mmio_always_on) {
37602diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
37603index 9b8505c..f00870a 100644
37604--- a/drivers/pci/proc.c
37605+++ b/drivers/pci/proc.c
37606@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
37607 static int __init pci_proc_init(void)
37608 {
37609 struct pci_dev *dev = NULL;
37610+
37611+#ifdef CONFIG_GRKERNSEC_PROC_ADD
37612+#ifdef CONFIG_GRKERNSEC_PROC_USER
37613+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
37614+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
37615+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
37616+#endif
37617+#else
37618 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
37619+#endif
37620 proc_create("devices", 0, proc_bus_pci_dir,
37621 &proc_bus_pci_dev_operations);
37622 proc_initialized = 1;
37623diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
37624index 75dd651..2af4c9a 100644
37625--- a/drivers/platform/x86/thinkpad_acpi.c
37626+++ b/drivers/platform/x86/thinkpad_acpi.c
37627@@ -2097,7 +2097,7 @@ static int hotkey_mask_get(void)
37628 return 0;
37629 }
37630
37631-void static hotkey_mask_warn_incomplete_mask(void)
37632+static void hotkey_mask_warn_incomplete_mask(void)
37633 {
37634 /* log only what the user can fix... */
37635 const u32 wantedmask = hotkey_driver_mask &
37636@@ -2328,11 +2328,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
37637 }
37638 }
37639
37640-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37641- struct tp_nvram_state *newn,
37642- const u32 event_mask)
37643-{
37644-
37645 #define TPACPI_COMPARE_KEY(__scancode, __member) \
37646 do { \
37647 if ((event_mask & (1 << __scancode)) && \
37648@@ -2346,36 +2341,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37649 tpacpi_hotkey_send_key(__scancode); \
37650 } while (0)
37651
37652- void issue_volchange(const unsigned int oldvol,
37653- const unsigned int newvol)
37654- {
37655- unsigned int i = oldvol;
37656+static void issue_volchange(const unsigned int oldvol,
37657+ const unsigned int newvol,
37658+ const u32 event_mask)
37659+{
37660+ unsigned int i = oldvol;
37661
37662- while (i > newvol) {
37663- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37664- i--;
37665- }
37666- while (i < newvol) {
37667- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37668- i++;
37669- }
37670+ while (i > newvol) {
37671+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
37672+ i--;
37673 }
37674+ while (i < newvol) {
37675+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37676+ i++;
37677+ }
37678+}
37679
37680- void issue_brightnesschange(const unsigned int oldbrt,
37681- const unsigned int newbrt)
37682- {
37683- unsigned int i = oldbrt;
37684+static void issue_brightnesschange(const unsigned int oldbrt,
37685+ const unsigned int newbrt,
37686+ const u32 event_mask)
37687+{
37688+ unsigned int i = oldbrt;
37689
37690- while (i > newbrt) {
37691- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37692- i--;
37693- }
37694- while (i < newbrt) {
37695- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37696- i++;
37697- }
37698+ while (i > newbrt) {
37699+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
37700+ i--;
37701+ }
37702+ while (i < newbrt) {
37703+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37704+ i++;
37705 }
37706+}
37707
37708+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37709+ struct tp_nvram_state *newn,
37710+ const u32 event_mask)
37711+{
37712 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
37713 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
37714 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
37715@@ -2409,7 +2410,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37716 oldn->volume_level != newn->volume_level) {
37717 /* recently muted, or repeated mute keypress, or
37718 * multiple presses ending in mute */
37719- issue_volchange(oldn->volume_level, newn->volume_level);
37720+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37721 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
37722 }
37723 } else {
37724@@ -2419,7 +2420,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37725 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
37726 }
37727 if (oldn->volume_level != newn->volume_level) {
37728- issue_volchange(oldn->volume_level, newn->volume_level);
37729+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
37730 } else if (oldn->volume_toggle != newn->volume_toggle) {
37731 /* repeated vol up/down keypress at end of scale ? */
37732 if (newn->volume_level == 0)
37733@@ -2432,7 +2433,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37734 /* handle brightness */
37735 if (oldn->brightness_level != newn->brightness_level) {
37736 issue_brightnesschange(oldn->brightness_level,
37737- newn->brightness_level);
37738+ newn->brightness_level,
37739+ event_mask);
37740 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
37741 /* repeated key presses that didn't change state */
37742 if (newn->brightness_level == 0)
37743@@ -2441,10 +2443,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
37744 && !tp_features.bright_unkfw)
37745 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
37746 }
37747+}
37748
37749 #undef TPACPI_COMPARE_KEY
37750 #undef TPACPI_MAY_SEND_KEY
37751-}
37752
37753 /*
37754 * Polling driver
37755diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
37756index 769d265..a3a05ca 100644
37757--- a/drivers/pnp/pnpbios/bioscalls.c
37758+++ b/drivers/pnp/pnpbios/bioscalls.c
37759@@ -58,7 +58,7 @@ do { \
37760 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
37761 } while(0)
37762
37763-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
37764+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
37765 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
37766
37767 /*
37768@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37769
37770 cpu = get_cpu();
37771 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
37772+
37773+ pax_open_kernel();
37774 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
37775+ pax_close_kernel();
37776
37777 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
37778 spin_lock_irqsave(&pnp_bios_lock, flags);
37779@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
37780 :"memory");
37781 spin_unlock_irqrestore(&pnp_bios_lock, flags);
37782
37783+ pax_open_kernel();
37784 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
37785+ pax_close_kernel();
37786+
37787 put_cpu();
37788
37789 /* If we get here and this is set then the PnP BIOS faulted on us. */
37790@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
37791 return status;
37792 }
37793
37794-void pnpbios_calls_init(union pnp_bios_install_struct *header)
37795+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
37796 {
37797 int i;
37798
37799@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37800 pnp_bios_callpoint.offset = header->fields.pm16offset;
37801 pnp_bios_callpoint.segment = PNP_CS16;
37802
37803+ pax_open_kernel();
37804+
37805 for_each_possible_cpu(i) {
37806 struct desc_struct *gdt = get_cpu_gdt_table(i);
37807 if (!gdt)
37808@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
37809 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
37810 (unsigned long)__va(header->fields.pm16dseg));
37811 }
37812+
37813+ pax_close_kernel();
37814 }
37815diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
37816index b0ecacb..7c9da2e 100644
37817--- a/drivers/pnp/resource.c
37818+++ b/drivers/pnp/resource.c
37819@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
37820 return 1;
37821
37822 /* check if the resource is valid */
37823- if (*irq < 0 || *irq > 15)
37824+ if (*irq > 15)
37825 return 0;
37826
37827 /* check if the resource is reserved */
37828@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
37829 return 1;
37830
37831 /* check if the resource is valid */
37832- if (*dma < 0 || *dma == 4 || *dma > 7)
37833+ if (*dma == 4 || *dma > 7)
37834 return 0;
37835
37836 /* check if the resource is reserved */
37837diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
37838index 7df7c5f..bd48c47 100644
37839--- a/drivers/power/pda_power.c
37840+++ b/drivers/power/pda_power.c
37841@@ -37,7 +37,11 @@ static int polling;
37842
37843 #ifdef CONFIG_USB_OTG_UTILS
37844 static struct usb_phy *transceiver;
37845-static struct notifier_block otg_nb;
37846+static int otg_handle_notification(struct notifier_block *nb,
37847+ unsigned long event, void *unused);
37848+static struct notifier_block otg_nb = {
37849+ .notifier_call = otg_handle_notification
37850+};
37851 #endif
37852
37853 static struct regulator *ac_draw;
37854@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
37855
37856 #ifdef CONFIG_USB_OTG_UTILS
37857 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
37858- otg_nb.notifier_call = otg_handle_notification;
37859 ret = usb_register_notifier(transceiver, &otg_nb);
37860 if (ret) {
37861 dev_err(dev, "failure to register otg notifier\n");
37862diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
37863index 8d53174..04c65de 100644
37864--- a/drivers/regulator/max8660.c
37865+++ b/drivers/regulator/max8660.c
37866@@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
37867 max8660->shadow_regs[MAX8660_OVER1] = 5;
37868 } else {
37869 /* Otherwise devices can be toggled via software */
37870- max8660_dcdc_ops.enable = max8660_dcdc_enable;
37871- max8660_dcdc_ops.disable = max8660_dcdc_disable;
37872+ pax_open_kernel();
37873+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
37874+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
37875+ pax_close_kernel();
37876 }
37877
37878 /*
37879diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
37880index 1fa6381..f58834e 100644
37881--- a/drivers/regulator/mc13892-regulator.c
37882+++ b/drivers/regulator/mc13892-regulator.c
37883@@ -540,10 +540,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
37884 }
37885 mc13xxx_unlock(mc13892);
37886
37887- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37888+ pax_open_kernel();
37889+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
37890 = mc13892_vcam_set_mode;
37891- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37892+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
37893 = mc13892_vcam_get_mode;
37894+ pax_close_kernel();
37895
37896 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
37897 ARRAY_SIZE(mc13892_regulators));
37898diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
37899index cace6d3..f623fda 100644
37900--- a/drivers/rtc/rtc-dev.c
37901+++ b/drivers/rtc/rtc-dev.c
37902@@ -14,6 +14,7 @@
37903 #include <linux/module.h>
37904 #include <linux/rtc.h>
37905 #include <linux/sched.h>
37906+#include <linux/grsecurity.h>
37907 #include "rtc-core.h"
37908
37909 static dev_t rtc_devt;
37910@@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
37911 if (copy_from_user(&tm, uarg, sizeof(tm)))
37912 return -EFAULT;
37913
37914+ gr_log_timechange();
37915+
37916 return rtc_set_time(rtc, &tm);
37917
37918 case RTC_PIE_ON:
37919diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
37920index 4ad7e36..d004679 100644
37921--- a/drivers/scsi/bfa/bfa.h
37922+++ b/drivers/scsi/bfa/bfa.h
37923@@ -196,7 +196,7 @@ struct bfa_hwif_s {
37924 u32 *end);
37925 int cpe_vec_q0;
37926 int rme_vec_q0;
37927-};
37928+} __no_const;
37929 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
37930
37931 struct bfa_faa_cbfn_s {
37932diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
37933index e693af6..2e525b6 100644
37934--- a/drivers/scsi/bfa/bfa_fcpim.h
37935+++ b/drivers/scsi/bfa/bfa_fcpim.h
37936@@ -36,7 +36,7 @@ struct bfa_iotag_s {
37937
37938 struct bfa_itn_s {
37939 bfa_isr_func_t isr;
37940-};
37941+} __no_const;
37942
37943 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
37944 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
37945diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
37946index 23a90e7..9cf04ee 100644
37947--- a/drivers/scsi/bfa/bfa_ioc.h
37948+++ b/drivers/scsi/bfa/bfa_ioc.h
37949@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
37950 bfa_ioc_disable_cbfn_t disable_cbfn;
37951 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
37952 bfa_ioc_reset_cbfn_t reset_cbfn;
37953-};
37954+} __no_const;
37955
37956 /*
37957 * IOC event notification mechanism.
37958@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
37959 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
37960 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
37961 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
37962-};
37963+} __no_const;
37964
37965 /*
37966 * Queue element to wait for room in request queue. FIFO order is
37967diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
37968index 593085a..47aa999 100644
37969--- a/drivers/scsi/hosts.c
37970+++ b/drivers/scsi/hosts.c
37971@@ -42,7 +42,7 @@
37972 #include "scsi_logging.h"
37973
37974
37975-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37976+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
37977
37978
37979 static void scsi_host_cls_release(struct device *dev)
37980@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
37981 * subtract one because we increment first then return, but we need to
37982 * know what the next host number was before increment
37983 */
37984- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
37985+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
37986 shost->dma_channel = 0xff;
37987
37988 /* These three are default values which can be overridden */
37989diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
37990index 4217e49..9c77e3e 100644
37991--- a/drivers/scsi/hpsa.c
37992+++ b/drivers/scsi/hpsa.c
37993@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
37994 unsigned long flags;
37995
37996 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37997- return h->access.command_completed(h, q);
37998+ return h->access->command_completed(h, q);
37999
38000 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
38001 a = rq->head[rq->current_entry];
38002@@ -3374,7 +3374,7 @@ static void start_io(struct ctlr_info *h)
38003 while (!list_empty(&h->reqQ)) {
38004 c = list_entry(h->reqQ.next, struct CommandList, list);
38005 /* can't do anything if fifo is full */
38006- if ((h->access.fifo_full(h))) {
38007+ if ((h->access->fifo_full(h))) {
38008 dev_warn(&h->pdev->dev, "fifo full\n");
38009 break;
38010 }
38011@@ -3396,7 +3396,7 @@ static void start_io(struct ctlr_info *h)
38012
38013 /* Tell the controller execute command */
38014 spin_unlock_irqrestore(&h->lock, flags);
38015- h->access.submit_command(h, c);
38016+ h->access->submit_command(h, c);
38017 spin_lock_irqsave(&h->lock, flags);
38018 }
38019 spin_unlock_irqrestore(&h->lock, flags);
38020@@ -3404,17 +3404,17 @@ static void start_io(struct ctlr_info *h)
38021
38022 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
38023 {
38024- return h->access.command_completed(h, q);
38025+ return h->access->command_completed(h, q);
38026 }
38027
38028 static inline bool interrupt_pending(struct ctlr_info *h)
38029 {
38030- return h->access.intr_pending(h);
38031+ return h->access->intr_pending(h);
38032 }
38033
38034 static inline long interrupt_not_for_us(struct ctlr_info *h)
38035 {
38036- return (h->access.intr_pending(h) == 0) ||
38037+ return (h->access->intr_pending(h) == 0) ||
38038 (h->interrupts_enabled == 0);
38039 }
38040
38041@@ -4318,7 +4318,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
38042 if (prod_index < 0)
38043 return -ENODEV;
38044 h->product_name = products[prod_index].product_name;
38045- h->access = *(products[prod_index].access);
38046+ h->access = products[prod_index].access;
38047
38048 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
38049 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
38050@@ -4600,7 +4600,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
38051
38052 assert_spin_locked(&lockup_detector_lock);
38053 remove_ctlr_from_lockup_detector_list(h);
38054- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38055+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38056 spin_lock_irqsave(&h->lock, flags);
38057 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
38058 spin_unlock_irqrestore(&h->lock, flags);
38059@@ -4778,7 +4778,7 @@ reinit_after_soft_reset:
38060 }
38061
38062 /* make sure the board interrupts are off */
38063- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38064+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38065
38066 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
38067 goto clean2;
38068@@ -4812,7 +4812,7 @@ reinit_after_soft_reset:
38069 * fake ones to scoop up any residual completions.
38070 */
38071 spin_lock_irqsave(&h->lock, flags);
38072- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38073+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38074 spin_unlock_irqrestore(&h->lock, flags);
38075 free_irqs(h);
38076 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
38077@@ -4831,9 +4831,9 @@ reinit_after_soft_reset:
38078 dev_info(&h->pdev->dev, "Board READY.\n");
38079 dev_info(&h->pdev->dev,
38080 "Waiting for stale completions to drain.\n");
38081- h->access.set_intr_mask(h, HPSA_INTR_ON);
38082+ h->access->set_intr_mask(h, HPSA_INTR_ON);
38083 msleep(10000);
38084- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38085+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38086
38087 rc = controller_reset_failed(h->cfgtable);
38088 if (rc)
38089@@ -4854,7 +4854,7 @@ reinit_after_soft_reset:
38090 }
38091
38092 /* Turn the interrupts on so we can service requests */
38093- h->access.set_intr_mask(h, HPSA_INTR_ON);
38094+ h->access->set_intr_mask(h, HPSA_INTR_ON);
38095
38096 hpsa_hba_inquiry(h);
38097 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
38098@@ -4906,7 +4906,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
38099 * To write all data in the battery backed cache to disks
38100 */
38101 hpsa_flush_cache(h);
38102- h->access.set_intr_mask(h, HPSA_INTR_OFF);
38103+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
38104 hpsa_free_irqs_and_disable_msix(h);
38105 }
38106
38107@@ -5075,7 +5075,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
38108 return;
38109 }
38110 /* Change the access methods to the performant access methods */
38111- h->access = SA5_performant_access;
38112+ h->access = &SA5_performant_access;
38113 h->transMethod = CFGTBL_Trans_Performant;
38114 }
38115
38116diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
38117index 9816479..c5d4e97 100644
38118--- a/drivers/scsi/hpsa.h
38119+++ b/drivers/scsi/hpsa.h
38120@@ -79,7 +79,7 @@ struct ctlr_info {
38121 unsigned int msix_vector;
38122 unsigned int msi_vector;
38123 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
38124- struct access_method access;
38125+ struct access_method *access;
38126
38127 /* queue and queue Info */
38128 struct list_head reqQ;
38129diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
38130index c772d8d..35c362c 100644
38131--- a/drivers/scsi/libfc/fc_exch.c
38132+++ b/drivers/scsi/libfc/fc_exch.c
38133@@ -100,12 +100,12 @@ struct fc_exch_mgr {
38134 u16 pool_max_index;
38135
38136 struct {
38137- atomic_t no_free_exch;
38138- atomic_t no_free_exch_xid;
38139- atomic_t xid_not_found;
38140- atomic_t xid_busy;
38141- atomic_t seq_not_found;
38142- atomic_t non_bls_resp;
38143+ atomic_unchecked_t no_free_exch;
38144+ atomic_unchecked_t no_free_exch_xid;
38145+ atomic_unchecked_t xid_not_found;
38146+ atomic_unchecked_t xid_busy;
38147+ atomic_unchecked_t seq_not_found;
38148+ atomic_unchecked_t non_bls_resp;
38149 } stats;
38150 };
38151
38152@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
38153 /* allocate memory for exchange */
38154 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
38155 if (!ep) {
38156- atomic_inc(&mp->stats.no_free_exch);
38157+ atomic_inc_unchecked(&mp->stats.no_free_exch);
38158 goto out;
38159 }
38160 memset(ep, 0, sizeof(*ep));
38161@@ -786,7 +786,7 @@ out:
38162 return ep;
38163 err:
38164 spin_unlock_bh(&pool->lock);
38165- atomic_inc(&mp->stats.no_free_exch_xid);
38166+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
38167 mempool_free(ep, mp->ep_pool);
38168 return NULL;
38169 }
38170@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38171 xid = ntohs(fh->fh_ox_id); /* we originated exch */
38172 ep = fc_exch_find(mp, xid);
38173 if (!ep) {
38174- atomic_inc(&mp->stats.xid_not_found);
38175+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38176 reject = FC_RJT_OX_ID;
38177 goto out;
38178 }
38179@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38180 ep = fc_exch_find(mp, xid);
38181 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
38182 if (ep) {
38183- atomic_inc(&mp->stats.xid_busy);
38184+ atomic_inc_unchecked(&mp->stats.xid_busy);
38185 reject = FC_RJT_RX_ID;
38186 goto rel;
38187 }
38188@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38189 }
38190 xid = ep->xid; /* get our XID */
38191 } else if (!ep) {
38192- atomic_inc(&mp->stats.xid_not_found);
38193+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38194 reject = FC_RJT_RX_ID; /* XID not found */
38195 goto out;
38196 }
38197@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
38198 } else {
38199 sp = &ep->seq;
38200 if (sp->id != fh->fh_seq_id) {
38201- atomic_inc(&mp->stats.seq_not_found);
38202+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38203 if (f_ctl & FC_FC_END_SEQ) {
38204 /*
38205 * Update sequence_id based on incoming last
38206@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38207
38208 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
38209 if (!ep) {
38210- atomic_inc(&mp->stats.xid_not_found);
38211+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38212 goto out;
38213 }
38214 if (ep->esb_stat & ESB_ST_COMPLETE) {
38215- atomic_inc(&mp->stats.xid_not_found);
38216+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38217 goto rel;
38218 }
38219 if (ep->rxid == FC_XID_UNKNOWN)
38220 ep->rxid = ntohs(fh->fh_rx_id);
38221 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
38222- atomic_inc(&mp->stats.xid_not_found);
38223+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38224 goto rel;
38225 }
38226 if (ep->did != ntoh24(fh->fh_s_id) &&
38227 ep->did != FC_FID_FLOGI) {
38228- atomic_inc(&mp->stats.xid_not_found);
38229+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38230 goto rel;
38231 }
38232 sof = fr_sof(fp);
38233@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38234 sp->ssb_stat |= SSB_ST_RESP;
38235 sp->id = fh->fh_seq_id;
38236 } else if (sp->id != fh->fh_seq_id) {
38237- atomic_inc(&mp->stats.seq_not_found);
38238+ atomic_inc_unchecked(&mp->stats.seq_not_found);
38239 goto rel;
38240 }
38241
38242@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
38243 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
38244
38245 if (!sp)
38246- atomic_inc(&mp->stats.xid_not_found);
38247+ atomic_inc_unchecked(&mp->stats.xid_not_found);
38248 else
38249- atomic_inc(&mp->stats.non_bls_resp);
38250+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
38251
38252 fc_frame_free(fp);
38253 }
38254@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
38255
38256 list_for_each_entry(ema, &lport->ema_list, ema_list) {
38257 mp = ema->mp;
38258- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
38259+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
38260 st->fc_no_free_exch_xid +=
38261- atomic_read(&mp->stats.no_free_exch_xid);
38262- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
38263- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
38264- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
38265- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
38266+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
38267+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
38268+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
38269+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
38270+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
38271 }
38272 }
38273 EXPORT_SYMBOL(fc_exch_update_stats);
38274diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
38275index bdb81cd..d3c7c2c 100644
38276--- a/drivers/scsi/libsas/sas_ata.c
38277+++ b/drivers/scsi/libsas/sas_ata.c
38278@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
38279 .postreset = ata_std_postreset,
38280 .error_handler = ata_std_error_handler,
38281 .post_internal_cmd = sas_ata_post_internal,
38282- .qc_defer = ata_std_qc_defer,
38283+ .qc_defer = ata_std_qc_defer,
38284 .qc_prep = ata_noop_qc_prep,
38285 .qc_issue = sas_ata_qc_issue,
38286 .qc_fill_rtf = sas_ata_qc_fill_rtf,
38287diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
38288index 69b5993..1ac9dce 100644
38289--- a/drivers/scsi/lpfc/lpfc.h
38290+++ b/drivers/scsi/lpfc/lpfc.h
38291@@ -424,7 +424,7 @@ struct lpfc_vport {
38292 struct dentry *debug_nodelist;
38293 struct dentry *vport_debugfs_root;
38294 struct lpfc_debugfs_trc *disc_trc;
38295- atomic_t disc_trc_cnt;
38296+ atomic_unchecked_t disc_trc_cnt;
38297 #endif
38298 uint8_t stat_data_enabled;
38299 uint8_t stat_data_blocked;
38300@@ -840,8 +840,8 @@ struct lpfc_hba {
38301 struct timer_list fabric_block_timer;
38302 unsigned long bit_flags;
38303 #define FABRIC_COMANDS_BLOCKED 0
38304- atomic_t num_rsrc_err;
38305- atomic_t num_cmd_success;
38306+ atomic_unchecked_t num_rsrc_err;
38307+ atomic_unchecked_t num_cmd_success;
38308 unsigned long last_rsrc_error_time;
38309 unsigned long last_ramp_down_time;
38310 unsigned long last_ramp_up_time;
38311@@ -877,7 +877,7 @@ struct lpfc_hba {
38312
38313 struct dentry *debug_slow_ring_trc;
38314 struct lpfc_debugfs_trc *slow_ring_trc;
38315- atomic_t slow_ring_trc_cnt;
38316+ atomic_unchecked_t slow_ring_trc_cnt;
38317 /* iDiag debugfs sub-directory */
38318 struct dentry *idiag_root;
38319 struct dentry *idiag_pci_cfg;
38320diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
38321index f63f5ff..de29189 100644
38322--- a/drivers/scsi/lpfc/lpfc_debugfs.c
38323+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
38324@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
38325
38326 #include <linux/debugfs.h>
38327
38328-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38329+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
38330 static unsigned long lpfc_debugfs_start_time = 0L;
38331
38332 /* iDiag */
38333@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
38334 lpfc_debugfs_enable = 0;
38335
38336 len = 0;
38337- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
38338+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
38339 (lpfc_debugfs_max_disc_trc - 1);
38340 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
38341 dtp = vport->disc_trc + i;
38342@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
38343 lpfc_debugfs_enable = 0;
38344
38345 len = 0;
38346- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
38347+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
38348 (lpfc_debugfs_max_slow_ring_trc - 1);
38349 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
38350 dtp = phba->slow_ring_trc + i;
38351@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
38352 !vport || !vport->disc_trc)
38353 return;
38354
38355- index = atomic_inc_return(&vport->disc_trc_cnt) &
38356+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
38357 (lpfc_debugfs_max_disc_trc - 1);
38358 dtp = vport->disc_trc + index;
38359 dtp->fmt = fmt;
38360 dtp->data1 = data1;
38361 dtp->data2 = data2;
38362 dtp->data3 = data3;
38363- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38364+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38365 dtp->jif = jiffies;
38366 #endif
38367 return;
38368@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
38369 !phba || !phba->slow_ring_trc)
38370 return;
38371
38372- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
38373+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
38374 (lpfc_debugfs_max_slow_ring_trc - 1);
38375 dtp = phba->slow_ring_trc + index;
38376 dtp->fmt = fmt;
38377 dtp->data1 = data1;
38378 dtp->data2 = data2;
38379 dtp->data3 = data3;
38380- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
38381+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
38382 dtp->jif = jiffies;
38383 #endif
38384 return;
38385@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38386 "slow_ring buffer\n");
38387 goto debug_failed;
38388 }
38389- atomic_set(&phba->slow_ring_trc_cnt, 0);
38390+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
38391 memset(phba->slow_ring_trc, 0,
38392 (sizeof(struct lpfc_debugfs_trc) *
38393 lpfc_debugfs_max_slow_ring_trc));
38394@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
38395 "buffer\n");
38396 goto debug_failed;
38397 }
38398- atomic_set(&vport->disc_trc_cnt, 0);
38399+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
38400
38401 snprintf(name, sizeof(name), "discovery_trace");
38402 vport->debug_disc_trc =
38403diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
38404index 7dc4218..3436f08 100644
38405--- a/drivers/scsi/lpfc/lpfc_init.c
38406+++ b/drivers/scsi/lpfc/lpfc_init.c
38407@@ -10589,8 +10589,10 @@ lpfc_init(void)
38408 "misc_register returned with status %d", error);
38409
38410 if (lpfc_enable_npiv) {
38411- lpfc_transport_functions.vport_create = lpfc_vport_create;
38412- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38413+ pax_open_kernel();
38414+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
38415+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
38416+ pax_close_kernel();
38417 }
38418 lpfc_transport_template =
38419 fc_attach_transport(&lpfc_transport_functions);
38420diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
38421index 7f45ac9..cf62eda 100644
38422--- a/drivers/scsi/lpfc/lpfc_scsi.c
38423+++ b/drivers/scsi/lpfc/lpfc_scsi.c
38424@@ -305,7 +305,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
38425 uint32_t evt_posted;
38426
38427 spin_lock_irqsave(&phba->hbalock, flags);
38428- atomic_inc(&phba->num_rsrc_err);
38429+ atomic_inc_unchecked(&phba->num_rsrc_err);
38430 phba->last_rsrc_error_time = jiffies;
38431
38432 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
38433@@ -346,7 +346,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
38434 unsigned long flags;
38435 struct lpfc_hba *phba = vport->phba;
38436 uint32_t evt_posted;
38437- atomic_inc(&phba->num_cmd_success);
38438+ atomic_inc_unchecked(&phba->num_cmd_success);
38439
38440 if (vport->cfg_lun_queue_depth <= queue_depth)
38441 return;
38442@@ -390,8 +390,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38443 unsigned long num_rsrc_err, num_cmd_success;
38444 int i;
38445
38446- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
38447- num_cmd_success = atomic_read(&phba->num_cmd_success);
38448+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
38449+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
38450
38451 /*
38452 * The error and success command counters are global per
38453@@ -419,8 +419,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
38454 }
38455 }
38456 lpfc_destroy_vport_work_array(phba, vports);
38457- atomic_set(&phba->num_rsrc_err, 0);
38458- atomic_set(&phba->num_cmd_success, 0);
38459+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38460+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38461 }
38462
38463 /**
38464@@ -454,8 +454,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
38465 }
38466 }
38467 lpfc_destroy_vport_work_array(phba, vports);
38468- atomic_set(&phba->num_rsrc_err, 0);
38469- atomic_set(&phba->num_cmd_success, 0);
38470+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
38471+ atomic_set_unchecked(&phba->num_cmd_success, 0);
38472 }
38473
38474 /**
38475diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
38476index af763ea..41904f7 100644
38477--- a/drivers/scsi/pmcraid.c
38478+++ b/drivers/scsi/pmcraid.c
38479@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
38480 res->scsi_dev = scsi_dev;
38481 scsi_dev->hostdata = res;
38482 res->change_detected = 0;
38483- atomic_set(&res->read_failures, 0);
38484- atomic_set(&res->write_failures, 0);
38485+ atomic_set_unchecked(&res->read_failures, 0);
38486+ atomic_set_unchecked(&res->write_failures, 0);
38487 rc = 0;
38488 }
38489 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
38490@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
38491
38492 /* If this was a SCSI read/write command keep count of errors */
38493 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
38494- atomic_inc(&res->read_failures);
38495+ atomic_inc_unchecked(&res->read_failures);
38496 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
38497- atomic_inc(&res->write_failures);
38498+ atomic_inc_unchecked(&res->write_failures);
38499
38500 if (!RES_IS_GSCSI(res->cfg_entry) &&
38501 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
38502@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
38503 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38504 * hrrq_id assigned here in queuecommand
38505 */
38506- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38507+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38508 pinstance->num_hrrq;
38509 cmd->cmd_done = pmcraid_io_done;
38510
38511@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
38512 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
38513 * hrrq_id assigned here in queuecommand
38514 */
38515- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
38516+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
38517 pinstance->num_hrrq;
38518
38519 if (request_size) {
38520@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
38521
38522 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
38523 /* add resources only after host is added into system */
38524- if (!atomic_read(&pinstance->expose_resources))
38525+ if (!atomic_read_unchecked(&pinstance->expose_resources))
38526 return;
38527
38528 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
38529@@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
38530 init_waitqueue_head(&pinstance->reset_wait_q);
38531
38532 atomic_set(&pinstance->outstanding_cmds, 0);
38533- atomic_set(&pinstance->last_message_id, 0);
38534- atomic_set(&pinstance->expose_resources, 0);
38535+ atomic_set_unchecked(&pinstance->last_message_id, 0);
38536+ atomic_set_unchecked(&pinstance->expose_resources, 0);
38537
38538 INIT_LIST_HEAD(&pinstance->free_res_q);
38539 INIT_LIST_HEAD(&pinstance->used_res_q);
38540@@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
38541 /* Schedule worker thread to handle CCN and take care of adding and
38542 * removing devices to OS
38543 */
38544- atomic_set(&pinstance->expose_resources, 1);
38545+ atomic_set_unchecked(&pinstance->expose_resources, 1);
38546 schedule_work(&pinstance->worker_q);
38547 return rc;
38548
38549diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
38550index e1d150f..6c6df44 100644
38551--- a/drivers/scsi/pmcraid.h
38552+++ b/drivers/scsi/pmcraid.h
38553@@ -748,7 +748,7 @@ struct pmcraid_instance {
38554 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
38555
38556 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
38557- atomic_t last_message_id;
38558+ atomic_unchecked_t last_message_id;
38559
38560 /* configuration table */
38561 struct pmcraid_config_table *cfg_table;
38562@@ -777,7 +777,7 @@ struct pmcraid_instance {
38563 atomic_t outstanding_cmds;
38564
38565 /* should add/delete resources to mid-layer now ?*/
38566- atomic_t expose_resources;
38567+ atomic_unchecked_t expose_resources;
38568
38569
38570
38571@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
38572 struct pmcraid_config_table_entry_ext cfg_entry_ext;
38573 };
38574 struct scsi_device *scsi_dev; /* Link scsi_device structure */
38575- atomic_t read_failures; /* count of failed READ commands */
38576- atomic_t write_failures; /* count of failed WRITE commands */
38577+ atomic_unchecked_t read_failures; /* count of failed READ commands */
38578+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
38579
38580 /* To indicate add/delete/modify during CCN */
38581 u8 change_detected;
38582diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
38583index 83d7984..a27d947 100644
38584--- a/drivers/scsi/qla2xxx/qla_attr.c
38585+++ b/drivers/scsi/qla2xxx/qla_attr.c
38586@@ -1969,7 +1969,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
38587 return 0;
38588 }
38589
38590-struct fc_function_template qla2xxx_transport_functions = {
38591+fc_function_template_no_const qla2xxx_transport_functions = {
38592
38593 .show_host_node_name = 1,
38594 .show_host_port_name = 1,
38595@@ -2016,7 +2016,7 @@ struct fc_function_template qla2xxx_transport_functions = {
38596 .bsg_timeout = qla24xx_bsg_timeout,
38597 };
38598
38599-struct fc_function_template qla2xxx_transport_vport_functions = {
38600+fc_function_template_no_const qla2xxx_transport_vport_functions = {
38601
38602 .show_host_node_name = 1,
38603 .show_host_port_name = 1,
38604diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
38605index 6acb397..d86e3e0 100644
38606--- a/drivers/scsi/qla2xxx/qla_gbl.h
38607+++ b/drivers/scsi/qla2xxx/qla_gbl.h
38608@@ -515,8 +515,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
38609 struct device_attribute;
38610 extern struct device_attribute *qla2x00_host_attrs[];
38611 struct fc_function_template;
38612-extern struct fc_function_template qla2xxx_transport_functions;
38613-extern struct fc_function_template qla2xxx_transport_vport_functions;
38614+extern fc_function_template_no_const qla2xxx_transport_functions;
38615+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
38616 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
38617 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
38618 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
38619diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
38620index f4b1fc8..a1ce4dd 100644
38621--- a/drivers/scsi/qla2xxx/qla_os.c
38622+++ b/drivers/scsi/qla2xxx/qla_os.c
38623@@ -1462,8 +1462,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
38624 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
38625 /* Ok, a 64bit DMA mask is applicable. */
38626 ha->flags.enable_64bit_addressing = 1;
38627- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38628- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38629+ pax_open_kernel();
38630+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
38631+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
38632+ pax_close_kernel();
38633 return;
38634 }
38635 }
38636diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
38637index 329d553..f20d31d 100644
38638--- a/drivers/scsi/qla4xxx/ql4_def.h
38639+++ b/drivers/scsi/qla4xxx/ql4_def.h
38640@@ -273,7 +273,7 @@ struct ddb_entry {
38641 * (4000 only) */
38642 atomic_t relogin_timer; /* Max Time to wait for
38643 * relogin to complete */
38644- atomic_t relogin_retry_count; /* Num of times relogin has been
38645+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
38646 * retried */
38647 uint32_t default_time2wait; /* Default Min time between
38648 * relogins (+aens) */
38649diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
38650index fbc546e..c7d1b48 100644
38651--- a/drivers/scsi/qla4xxx/ql4_os.c
38652+++ b/drivers/scsi/qla4xxx/ql4_os.c
38653@@ -2621,12 +2621,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
38654 */
38655 if (!iscsi_is_session_online(cls_sess)) {
38656 /* Reset retry relogin timer */
38657- atomic_inc(&ddb_entry->relogin_retry_count);
38658+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
38659 DEBUG2(ql4_printk(KERN_INFO, ha,
38660 "%s: index[%d] relogin timed out-retrying"
38661 " relogin (%d), retry (%d)\n", __func__,
38662 ddb_entry->fw_ddb_index,
38663- atomic_read(&ddb_entry->relogin_retry_count),
38664+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
38665 ddb_entry->default_time2wait + 4));
38666 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
38667 atomic_set(&ddb_entry->retry_relogin_timer,
38668@@ -4738,7 +4738,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
38669
38670 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
38671 atomic_set(&ddb_entry->relogin_timer, 0);
38672- atomic_set(&ddb_entry->relogin_retry_count, 0);
38673+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
38674 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
38675 ddb_entry->default_relogin_timeout =
38676 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
38677diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
38678index 2c0d0ec..4e8681a 100644
38679--- a/drivers/scsi/scsi.c
38680+++ b/drivers/scsi/scsi.c
38681@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
38682 unsigned long timeout;
38683 int rtn = 0;
38684
38685- atomic_inc(&cmd->device->iorequest_cnt);
38686+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38687
38688 /* check if the device is still usable */
38689 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
38690diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
38691index 9032e91..7a805d0 100644
38692--- a/drivers/scsi/scsi_lib.c
38693+++ b/drivers/scsi/scsi_lib.c
38694@@ -1454,7 +1454,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
38695 shost = sdev->host;
38696 scsi_init_cmd_errh(cmd);
38697 cmd->result = DID_NO_CONNECT << 16;
38698- atomic_inc(&cmd->device->iorequest_cnt);
38699+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
38700
38701 /*
38702 * SCSI request completion path will do scsi_device_unbusy(),
38703@@ -1480,9 +1480,9 @@ static void scsi_softirq_done(struct request *rq)
38704
38705 INIT_LIST_HEAD(&cmd->eh_entry);
38706
38707- atomic_inc(&cmd->device->iodone_cnt);
38708+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
38709 if (cmd->result)
38710- atomic_inc(&cmd->device->ioerr_cnt);
38711+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
38712
38713 disposition = scsi_decide_disposition(cmd);
38714 if (disposition != SUCCESS &&
38715diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
38716index 931a7d9..0c2a754 100644
38717--- a/drivers/scsi/scsi_sysfs.c
38718+++ b/drivers/scsi/scsi_sysfs.c
38719@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
38720 char *buf) \
38721 { \
38722 struct scsi_device *sdev = to_scsi_device(dev); \
38723- unsigned long long count = atomic_read(&sdev->field); \
38724+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
38725 return snprintf(buf, 20, "0x%llx\n", count); \
38726 } \
38727 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
38728diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
38729index 84a1fdf..693b0d6 100644
38730--- a/drivers/scsi/scsi_tgt_lib.c
38731+++ b/drivers/scsi/scsi_tgt_lib.c
38732@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
38733 int err;
38734
38735 dprintk("%lx %u\n", uaddr, len);
38736- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
38737+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
38738 if (err) {
38739 /*
38740 * TODO: need to fixup sg_tablesize, max_segment_size,
38741diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
38742index e894ca7..de9d7660 100644
38743--- a/drivers/scsi/scsi_transport_fc.c
38744+++ b/drivers/scsi/scsi_transport_fc.c
38745@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
38746 * Netlink Infrastructure
38747 */
38748
38749-static atomic_t fc_event_seq;
38750+static atomic_unchecked_t fc_event_seq;
38751
38752 /**
38753 * fc_get_event_number - Obtain the next sequential FC event number
38754@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
38755 u32
38756 fc_get_event_number(void)
38757 {
38758- return atomic_add_return(1, &fc_event_seq);
38759+ return atomic_add_return_unchecked(1, &fc_event_seq);
38760 }
38761 EXPORT_SYMBOL(fc_get_event_number);
38762
38763@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
38764 {
38765 int error;
38766
38767- atomic_set(&fc_event_seq, 0);
38768+ atomic_set_unchecked(&fc_event_seq, 0);
38769
38770 error = transport_class_register(&fc_host_class);
38771 if (error)
38772@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
38773 char *cp;
38774
38775 *val = simple_strtoul(buf, &cp, 0);
38776- if ((*cp && (*cp != '\n')) || (*val < 0))
38777+ if (*cp && (*cp != '\n'))
38778 return -EINVAL;
38779 /*
38780 * Check for overflow; dev_loss_tmo is u32
38781diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
38782index 31969f2..2b348f0 100644
38783--- a/drivers/scsi/scsi_transport_iscsi.c
38784+++ b/drivers/scsi/scsi_transport_iscsi.c
38785@@ -79,7 +79,7 @@ struct iscsi_internal {
38786 struct transport_container session_cont;
38787 };
38788
38789-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
38790+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
38791 static struct workqueue_struct *iscsi_eh_timer_workq;
38792
38793 static DEFINE_IDA(iscsi_sess_ida);
38794@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
38795 int err;
38796
38797 ihost = shost->shost_data;
38798- session->sid = atomic_add_return(1, &iscsi_session_nr);
38799+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
38800
38801 if (target_id == ISCSI_MAX_TARGET) {
38802 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
38803@@ -2943,7 +2943,7 @@ static __init int iscsi_transport_init(void)
38804 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
38805 ISCSI_TRANSPORT_VERSION);
38806
38807- atomic_set(&iscsi_session_nr, 0);
38808+ atomic_set_unchecked(&iscsi_session_nr, 0);
38809
38810 err = class_register(&iscsi_transport_class);
38811 if (err)
38812diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
38813index 21a045e..ec89e03 100644
38814--- a/drivers/scsi/scsi_transport_srp.c
38815+++ b/drivers/scsi/scsi_transport_srp.c
38816@@ -33,7 +33,7 @@
38817 #include "scsi_transport_srp_internal.h"
38818
38819 struct srp_host_attrs {
38820- atomic_t next_port_id;
38821+ atomic_unchecked_t next_port_id;
38822 };
38823 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
38824
38825@@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
38826 struct Scsi_Host *shost = dev_to_shost(dev);
38827 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
38828
38829- atomic_set(&srp_host->next_port_id, 0);
38830+ atomic_set_unchecked(&srp_host->next_port_id, 0);
38831 return 0;
38832 }
38833
38834@@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
38835 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
38836 rport->roles = ids->roles;
38837
38838- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
38839+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
38840 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
38841
38842 transport_setup_device(&rport->dev);
38843diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
38844index a45e12a..d9120cb 100644
38845--- a/drivers/scsi/sd.c
38846+++ b/drivers/scsi/sd.c
38847@@ -2899,7 +2899,7 @@ static int sd_probe(struct device *dev)
38848 sdkp->disk = gd;
38849 sdkp->index = index;
38850 atomic_set(&sdkp->openers, 0);
38851- atomic_set(&sdkp->device->ioerr_cnt, 0);
38852+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
38853
38854 if (!sdp->request_queue->rq_timeout) {
38855 if (sdp->type != TYPE_MOD)
38856diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
38857index be2c9a6..275525c 100644
38858--- a/drivers/scsi/sg.c
38859+++ b/drivers/scsi/sg.c
38860@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
38861 sdp->disk->disk_name,
38862 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
38863 NULL,
38864- (char *)arg);
38865+ (char __user *)arg);
38866 case BLKTRACESTART:
38867 return blk_trace_startstop(sdp->device->request_queue, 1);
38868 case BLKTRACESTOP:
38869diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
38870index 84c2861..ece0a31 100644
38871--- a/drivers/spi/spi.c
38872+++ b/drivers/spi/spi.c
38873@@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
38874 EXPORT_SYMBOL_GPL(spi_bus_unlock);
38875
38876 /* portable code must never pass more than 32 bytes */
38877-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
38878+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
38879
38880 static u8 *buf;
38881
38882diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
38883index 34afc16..ffe44dd 100644
38884--- a/drivers/staging/octeon/ethernet-rx.c
38885+++ b/drivers/staging/octeon/ethernet-rx.c
38886@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38887 /* Increment RX stats for virtual ports */
38888 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
38889 #ifdef CONFIG_64BIT
38890- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
38891- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
38892+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
38893+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
38894 #else
38895- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
38896- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
38897+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
38898+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
38899 #endif
38900 }
38901 netif_receive_skb(skb);
38902@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
38903 dev->name);
38904 */
38905 #ifdef CONFIG_64BIT
38906- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
38907+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38908 #else
38909- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
38910+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
38911 #endif
38912 dev_kfree_skb_irq(skb);
38913 }
38914diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
38915index 683bedc..86dba9a 100644
38916--- a/drivers/staging/octeon/ethernet.c
38917+++ b/drivers/staging/octeon/ethernet.c
38918@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
38919 * since the RX tasklet also increments it.
38920 */
38921 #ifdef CONFIG_64BIT
38922- atomic64_add(rx_status.dropped_packets,
38923- (atomic64_t *)&priv->stats.rx_dropped);
38924+ atomic64_add_unchecked(rx_status.dropped_packets,
38925+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
38926 #else
38927- atomic_add(rx_status.dropped_packets,
38928- (atomic_t *)&priv->stats.rx_dropped);
38929+ atomic_add_unchecked(rx_status.dropped_packets,
38930+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
38931 #endif
38932 }
38933
38934diff --git a/drivers/staging/ramster/tmem.c b/drivers/staging/ramster/tmem.c
38935index a2b7e03..aaf3630 100644
38936--- a/drivers/staging/ramster/tmem.c
38937+++ b/drivers/staging/ramster/tmem.c
38938@@ -50,25 +50,25 @@
38939 * A tmem host implementation must use this function to register callbacks
38940 * for memory allocation.
38941 */
38942-static struct tmem_hostops tmem_hostops;
38943+static struct tmem_hostops *tmem_hostops;
38944
38945 static void tmem_objnode_tree_init(void);
38946
38947 void tmem_register_hostops(struct tmem_hostops *m)
38948 {
38949 tmem_objnode_tree_init();
38950- tmem_hostops = *m;
38951+ tmem_hostops = m;
38952 }
38953
38954 /*
38955 * A tmem host implementation must use this function to register
38956 * callbacks for a page-accessible memory (PAM) implementation.
38957 */
38958-static struct tmem_pamops tmem_pamops;
38959+static struct tmem_pamops *tmem_pamops;
38960
38961 void tmem_register_pamops(struct tmem_pamops *m)
38962 {
38963- tmem_pamops = *m;
38964+ tmem_pamops = m;
38965 }
38966
38967 /*
38968@@ -174,7 +174,7 @@ static void tmem_obj_init(struct tmem_obj *obj, struct tmem_hashbucket *hb,
38969 obj->pampd_count = 0;
38970 #ifdef CONFIG_RAMSTER
38971 if (tmem_pamops.new_obj != NULL)
38972- (*tmem_pamops.new_obj)(obj);
38973+ (tmem_pamops->new_obj)(obj);
38974 #endif
38975 SET_SENTINEL(obj, OBJ);
38976
38977@@ -210,7 +210,7 @@ static void tmem_pool_flush(struct tmem_pool *pool, bool destroy)
38978 rbnode = rb_next(rbnode);
38979 tmem_pampd_destroy_all_in_obj(obj, true);
38980 tmem_obj_free(obj, hb);
38981- (*tmem_hostops.obj_free)(obj, pool);
38982+ (tmem_hostops->obj_free)(obj, pool);
38983 }
38984 spin_unlock(&hb->lock);
38985 }
38986@@ -261,7 +261,7 @@ static struct tmem_objnode *tmem_objnode_alloc(struct tmem_obj *obj)
38987 ASSERT_SENTINEL(obj, OBJ);
38988 BUG_ON(obj->pool == NULL);
38989 ASSERT_SENTINEL(obj->pool, POOL);
38990- objnode = (*tmem_hostops.objnode_alloc)(obj->pool);
38991+ objnode = (tmem_hostops->objnode_alloc)(obj->pool);
38992 if (unlikely(objnode == NULL))
38993 goto out;
38994 objnode->obj = obj;
38995@@ -290,7 +290,7 @@ static void tmem_objnode_free(struct tmem_objnode *objnode)
38996 ASSERT_SENTINEL(pool, POOL);
38997 objnode->obj->objnode_count--;
38998 objnode->obj = NULL;
38999- (*tmem_hostops.objnode_free)(objnode, pool);
39000+ (tmem_hostops->objnode_free)(objnode, pool);
39001 }
39002
39003 /*
39004@@ -348,7 +348,7 @@ static void *tmem_pampd_replace_in_obj(struct tmem_obj *obj, uint32_t index,
39005 void *old_pampd = *(void **)slot;
39006 *(void **)slot = new_pampd;
39007 if (!no_free)
39008- (*tmem_pamops.free)(old_pampd, obj->pool,
39009+ (tmem_pamops->free)(old_pampd, obj->pool,
39010 NULL, 0, false);
39011 ret = new_pampd;
39012 }
39013@@ -505,7 +505,7 @@ static void tmem_objnode_node_destroy(struct tmem_obj *obj,
39014 if (objnode->slots[i]) {
39015 if (ht == 1) {
39016 obj->pampd_count--;
39017- (*tmem_pamops.free)(objnode->slots[i],
39018+ (tmem_pamops->free)(objnode->slots[i],
39019 obj->pool, NULL, 0, true);
39020 objnode->slots[i] = NULL;
39021 continue;
39022@@ -524,7 +524,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39023 return;
39024 if (obj->objnode_tree_height == 0) {
39025 obj->pampd_count--;
39026- (*tmem_pamops.free)(obj->objnode_tree_root,
39027+ (tmem_pamops->free)(obj->objnode_tree_root,
39028 obj->pool, NULL, 0, true);
39029 } else {
39030 tmem_objnode_node_destroy(obj, obj->objnode_tree_root,
39031@@ -535,7 +535,7 @@ static void tmem_pampd_destroy_all_in_obj(struct tmem_obj *obj,
39032 obj->objnode_tree_root = NULL;
39033 #ifdef CONFIG_RAMSTER
39034 if (tmem_pamops.free_obj != NULL)
39035- (*tmem_pamops.free_obj)(obj->pool, obj, pool_destroy);
39036+ (tmem_pamops->free_obj)(obj->pool, obj, pool_destroy);
39037 #endif
39038 }
39039
39040@@ -574,7 +574,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39041 /* if found, is a dup put, flush the old one */
39042 pampd_del = tmem_pampd_delete_from_obj(obj, index);
39043 BUG_ON(pampd_del != pampd);
39044- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39045+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
39046 if (obj->pampd_count == 0) {
39047 objnew = obj;
39048 objfound = NULL;
39049@@ -582,7 +582,7 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39050 pampd = NULL;
39051 }
39052 } else {
39053- obj = objnew = (*tmem_hostops.obj_alloc)(pool);
39054+ obj = objnew = (tmem_hostops->obj_alloc)(pool);
39055 if (unlikely(obj == NULL)) {
39056 ret = -ENOMEM;
39057 goto out;
39058@@ -597,16 +597,16 @@ int tmem_put(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39059 if (unlikely(ret == -ENOMEM))
39060 /* may have partially built objnode tree ("stump") */
39061 goto delete_and_free;
39062- (*tmem_pamops.create_finish)(pampd, is_ephemeral(pool));
39063+ (tmem_pamops->create_finish)(pampd, is_ephemeral(pool));
39064 goto out;
39065
39066 delete_and_free:
39067 (void)tmem_pampd_delete_from_obj(obj, index);
39068 if (pampd)
39069- (*tmem_pamops.free)(pampd, pool, NULL, 0, true);
39070+ (tmem_pamops->free)(pampd, pool, NULL, 0, true);
39071 if (objnew) {
39072 tmem_obj_free(objnew, hb);
39073- (*tmem_hostops.obj_free)(objnew, pool);
39074+ (tmem_hostops->obj_free)(objnew, pool);
39075 }
39076 out:
39077 spin_unlock(&hb->lock);
39078@@ -651,7 +651,7 @@ void tmem_localify_finish(struct tmem_obj *obj, uint32_t index,
39079 if (pampd != NULL) {
39080 BUG_ON(obj == NULL);
39081 (void)tmem_pampd_replace_in_obj(obj, index, pampd, 1);
39082- (*tmem_pamops.create_finish)(pampd, is_ephemeral(obj->pool));
39083+ (tmem_pamops->create_finish)(pampd, is_ephemeral(obj->pool));
39084 } else if (delete) {
39085 BUG_ON(obj == NULL);
39086 (void)tmem_pampd_delete_from_obj(obj, index);
39087@@ -671,7 +671,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39088 int ret = 0;
39089
39090 if (!is_ephemeral(pool))
39091- new_pampd = (*tmem_pamops.repatriate_preload)(
39092+ new_pampd = (tmem_pamops->repatriate_preload)(
39093 old_pampd, pool, oidp, index, &intransit);
39094 if (intransit)
39095 ret = -EAGAIN;
39096@@ -680,7 +680,7 @@ static int tmem_repatriate(void **ppampd, struct tmem_hashbucket *hb,
39097 /* must release the hb->lock else repatriate can't sleep */
39098 spin_unlock(&hb->lock);
39099 if (!intransit)
39100- ret = (*tmem_pamops.repatriate)(old_pampd, new_pampd, pool,
39101+ ret = (tmem_pamops->repatriate)(old_pampd, new_pampd, pool,
39102 oidp, index, free, data);
39103 if (ret == -EAGAIN) {
39104 /* rare I think, but should cond_resched()??? */
39105@@ -714,7 +714,7 @@ int tmem_replace(struct tmem_pool *pool, struct tmem_oid *oidp,
39106 new_pampd = tmem_pampd_replace_in_obj(obj, index, new_pampd, 0);
39107 /* if we bug here, pamops wasn't properly set up for ramster */
39108 BUG_ON(tmem_pamops.replace_in_obj == NULL);
39109- ret = (*tmem_pamops.replace_in_obj)(new_pampd, obj);
39110+ ret = (tmem_pamops->replace_in_obj)(new_pampd, obj);
39111 out:
39112 spin_unlock(&hb->lock);
39113 return ret;
39114@@ -776,15 +776,15 @@ int tmem_get(struct tmem_pool *pool, struct tmem_oid *oidp, uint32_t index,
39115 if (free) {
39116 if (obj->pampd_count == 0) {
39117 tmem_obj_free(obj, hb);
39118- (*tmem_hostops.obj_free)(obj, pool);
39119+ (tmem_hostops->obj_free)(obj, pool);
39120 obj = NULL;
39121 }
39122 }
39123 if (free)
39124- ret = (*tmem_pamops.get_data_and_free)(
39125+ ret = (tmem_pamops->get_data_and_free)(
39126 data, sizep, raw, pampd, pool, oidp, index);
39127 else
39128- ret = (*tmem_pamops.get_data)(
39129+ ret = (tmem_pamops->get_data)(
39130 data, sizep, raw, pampd, pool, oidp, index);
39131 if (ret < 0)
39132 goto out;
39133@@ -816,10 +816,10 @@ int tmem_flush_page(struct tmem_pool *pool,
39134 pampd = tmem_pampd_delete_from_obj(obj, index);
39135 if (pampd == NULL)
39136 goto out;
39137- (*tmem_pamops.free)(pampd, pool, oidp, index, true);
39138+ (tmem_pamops->free)(pampd, pool, oidp, index, true);
39139 if (obj->pampd_count == 0) {
39140 tmem_obj_free(obj, hb);
39141- (*tmem_hostops.obj_free)(obj, pool);
39142+ (tmem_hostops->obj_free)(obj, pool);
39143 }
39144 ret = 0;
39145
39146@@ -844,7 +844,7 @@ int tmem_flush_object(struct tmem_pool *pool, struct tmem_oid *oidp)
39147 goto out;
39148 tmem_pampd_destroy_all_in_obj(obj, false);
39149 tmem_obj_free(obj, hb);
39150- (*tmem_hostops.obj_free)(obj, pool);
39151+ (tmem_hostops->obj_free)(obj, pool);
39152 ret = 0;
39153
39154 out:
39155diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
39156index dc23395..cf7e9b1 100644
39157--- a/drivers/staging/rtl8712/rtl871x_io.h
39158+++ b/drivers/staging/rtl8712/rtl871x_io.h
39159@@ -108,7 +108,7 @@ struct _io_ops {
39160 u8 *pmem);
39161 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
39162 u8 *pmem);
39163-};
39164+} __no_const;
39165
39166 struct io_req {
39167 struct list_head list;
39168diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
39169index 180c963..1f18377 100644
39170--- a/drivers/staging/sbe-2t3e3/netdev.c
39171+++ b/drivers/staging/sbe-2t3e3/netdev.c
39172@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39173 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
39174
39175 if (rlen)
39176- if (copy_to_user(data, &resp, rlen))
39177+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
39178 return -EFAULT;
39179
39180 return 0;
39181diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
39182index c66b8b3..a4a035b 100644
39183--- a/drivers/staging/usbip/vhci.h
39184+++ b/drivers/staging/usbip/vhci.h
39185@@ -83,7 +83,7 @@ struct vhci_hcd {
39186 unsigned resuming:1;
39187 unsigned long re_timeout;
39188
39189- atomic_t seqnum;
39190+ atomic_unchecked_t seqnum;
39191
39192 /*
39193 * NOTE:
39194diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
39195index 620d1be..1cd6711 100644
39196--- a/drivers/staging/usbip/vhci_hcd.c
39197+++ b/drivers/staging/usbip/vhci_hcd.c
39198@@ -471,7 +471,7 @@ static void vhci_tx_urb(struct urb *urb)
39199 return;
39200 }
39201
39202- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
39203+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39204 if (priv->seqnum == 0xffff)
39205 dev_info(&urb->dev->dev, "seqnum max\n");
39206
39207@@ -723,7 +723,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
39208 return -ENOMEM;
39209 }
39210
39211- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
39212+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
39213 if (unlink->seqnum == 0xffff)
39214 pr_info("seqnum max\n");
39215
39216@@ -924,7 +924,7 @@ static int vhci_start(struct usb_hcd *hcd)
39217 vdev->rhport = rhport;
39218 }
39219
39220- atomic_set(&vhci->seqnum, 0);
39221+ atomic_set_unchecked(&vhci->seqnum, 0);
39222 spin_lock_init(&vhci->lock);
39223
39224 hcd->power_budget = 0; /* no limit */
39225diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
39226index f0eaf04..5a82e06 100644
39227--- a/drivers/staging/usbip/vhci_rx.c
39228+++ b/drivers/staging/usbip/vhci_rx.c
39229@@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
39230 if (!urb) {
39231 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
39232 pr_info("max seqnum %d\n",
39233- atomic_read(&the_controller->seqnum));
39234+ atomic_read_unchecked(&the_controller->seqnum));
39235 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
39236 return;
39237 }
39238diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
39239index 67b1b88..6392fe9 100644
39240--- a/drivers/staging/vt6655/hostap.c
39241+++ b/drivers/staging/vt6655/hostap.c
39242@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
39243 *
39244 */
39245
39246+static net_device_ops_no_const apdev_netdev_ops;
39247+
39248 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39249 {
39250 PSDevice apdev_priv;
39251 struct net_device *dev = pDevice->dev;
39252 int ret;
39253- const struct net_device_ops apdev_netdev_ops = {
39254- .ndo_start_xmit = pDevice->tx_80211,
39255- };
39256
39257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39258
39259@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39260 *apdev_priv = *pDevice;
39261 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39262
39263+ /* only half broken now */
39264+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39265 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39266
39267 pDevice->apdev->type = ARPHRD_IEEE80211;
39268diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
39269index 0a73d40..6fda560 100644
39270--- a/drivers/staging/vt6656/hostap.c
39271+++ b/drivers/staging/vt6656/hostap.c
39272@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
39273 *
39274 */
39275
39276+static net_device_ops_no_const apdev_netdev_ops;
39277+
39278 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39279 {
39280 PSDevice apdev_priv;
39281 struct net_device *dev = pDevice->dev;
39282 int ret;
39283- const struct net_device_ops apdev_netdev_ops = {
39284- .ndo_start_xmit = pDevice->tx_80211,
39285- };
39286
39287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
39288
39289@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
39290 *apdev_priv = *pDevice;
39291 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
39292
39293+ /* only half broken now */
39294+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
39295 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
39296
39297 pDevice->apdev->type = ARPHRD_IEEE80211;
39298diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
39299index 56c8e60..1920c63 100644
39300--- a/drivers/staging/zcache/tmem.c
39301+++ b/drivers/staging/zcache/tmem.c
39302@@ -39,7 +39,7 @@
39303 * A tmem host implementation must use this function to register callbacks
39304 * for memory allocation.
39305 */
39306-static struct tmem_hostops tmem_hostops;
39307+static tmem_hostops_no_const tmem_hostops;
39308
39309 static void tmem_objnode_tree_init(void);
39310
39311@@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
39312 * A tmem host implementation must use this function to register
39313 * callbacks for a page-accessible memory (PAM) implementation
39314 */
39315-static struct tmem_pamops tmem_pamops;
39316+static tmem_pamops_no_const tmem_pamops;
39317
39318 void tmem_register_pamops(struct tmem_pamops *m)
39319 {
39320diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
39321index 0d4aa82..f7832d4 100644
39322--- a/drivers/staging/zcache/tmem.h
39323+++ b/drivers/staging/zcache/tmem.h
39324@@ -180,6 +180,7 @@ struct tmem_pamops {
39325 void (*new_obj)(struct tmem_obj *);
39326 int (*replace_in_obj)(void *, struct tmem_obj *);
39327 };
39328+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
39329 extern void tmem_register_pamops(struct tmem_pamops *m);
39330
39331 /* memory allocation methods provided by the host implementation */
39332@@ -189,6 +190,7 @@ struct tmem_hostops {
39333 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
39334 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
39335 };
39336+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
39337 extern void tmem_register_hostops(struct tmem_hostops *m);
39338
39339 /* core tmem accessor functions */
39340diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
39341index 13fe16c..cbdc39a 100644
39342--- a/drivers/target/target_core_transport.c
39343+++ b/drivers/target/target_core_transport.c
39344@@ -1085,7 +1085,7 @@ struct se_device *transport_add_device_to_core_hba(
39345 spin_lock_init(&dev->se_port_lock);
39346 spin_lock_init(&dev->se_tmr_lock);
39347 spin_lock_init(&dev->qf_cmd_lock);
39348- atomic_set(&dev->dev_ordered_id, 0);
39349+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
39350
39351 se_dev_set_default_attribs(dev, dev_limits);
39352
39353@@ -1275,7 +1275,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
39354 * Used to determine when ORDERED commands should go from
39355 * Dormant to Active status.
39356 */
39357- cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
39358+ cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
39359 smp_mb__after_atomic_inc();
39360 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
39361 cmd->se_ordered_id, cmd->sam_task_attr,
39362diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
39363index 0a6a0bc..5501b06 100644
39364--- a/drivers/tty/cyclades.c
39365+++ b/drivers/tty/cyclades.c
39366@@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
39367 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
39368 info->port.count);
39369 #endif
39370- info->port.count++;
39371+ atomic_inc(&info->port.count);
39372 #ifdef CY_DEBUG_COUNT
39373 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
39374- current->pid, info->port.count);
39375+ current->pid, atomic_read(&info->port.count));
39376 #endif
39377
39378 /*
39379@@ -3989,7 +3989,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
39380 for (j = 0; j < cy_card[i].nports; j++) {
39381 info = &cy_card[i].ports[j];
39382
39383- if (info->port.count) {
39384+ if (atomic_read(&info->port.count)) {
39385 /* XXX is the ldisc num worth this? */
39386 struct tty_struct *tty;
39387 struct tty_ldisc *ld;
39388diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
39389index 13ee53b..418d164 100644
39390--- a/drivers/tty/hvc/hvc_console.c
39391+++ b/drivers/tty/hvc/hvc_console.c
39392@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
39393
39394 spin_lock_irqsave(&hp->port.lock, flags);
39395 /* Check and then increment for fast path open. */
39396- if (hp->port.count++ > 0) {
39397+ if (atomic_inc_return(&hp->port.count) > 1) {
39398 spin_unlock_irqrestore(&hp->port.lock, flags);
39399 hvc_kick();
39400 return 0;
39401@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39402
39403 spin_lock_irqsave(&hp->port.lock, flags);
39404
39405- if (--hp->port.count == 0) {
39406+ if (atomic_dec_return(&hp->port.count) == 0) {
39407 spin_unlock_irqrestore(&hp->port.lock, flags);
39408 /* We are done with the tty pointer now. */
39409 tty_port_tty_set(&hp->port, NULL);
39410@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
39411 */
39412 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
39413 } else {
39414- if (hp->port.count < 0)
39415+ if (atomic_read(&hp->port.count) < 0)
39416 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
39417- hp->vtermno, hp->port.count);
39418+ hp->vtermno, atomic_read(&hp->port.count));
39419 spin_unlock_irqrestore(&hp->port.lock, flags);
39420 }
39421 }
39422@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
39423 * open->hangup case this can be called after the final close so prevent
39424 * that from happening for now.
39425 */
39426- if (hp->port.count <= 0) {
39427+ if (atomic_read(&hp->port.count) <= 0) {
39428 spin_unlock_irqrestore(&hp->port.lock, flags);
39429 return;
39430 }
39431
39432- hp->port.count = 0;
39433+ atomic_set(&hp->port.count, 0);
39434 spin_unlock_irqrestore(&hp->port.lock, flags);
39435 tty_port_tty_set(&hp->port, NULL);
39436
39437@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
39438 return -EPIPE;
39439
39440 /* FIXME what's this (unprotected) check for? */
39441- if (hp->port.count <= 0)
39442+ if (atomic_read(&hp->port.count) <= 0)
39443 return -EIO;
39444
39445 spin_lock_irqsave(&hp->lock, flags);
39446diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
39447index cab5c7a..4cc66ea 100644
39448--- a/drivers/tty/hvc/hvcs.c
39449+++ b/drivers/tty/hvc/hvcs.c
39450@@ -83,6 +83,7 @@
39451 #include <asm/hvcserver.h>
39452 #include <asm/uaccess.h>
39453 #include <asm/vio.h>
39454+#include <asm/local.h>
39455
39456 /*
39457 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
39458@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
39459
39460 spin_lock_irqsave(&hvcsd->lock, flags);
39461
39462- if (hvcsd->port.count > 0) {
39463+ if (atomic_read(&hvcsd->port.count) > 0) {
39464 spin_unlock_irqrestore(&hvcsd->lock, flags);
39465 printk(KERN_INFO "HVCS: vterm state unchanged. "
39466 "The hvcs device node is still in use.\n");
39467@@ -1132,7 +1133,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
39468 }
39469 }
39470
39471- hvcsd->port.count = 0;
39472+ atomic_set(&hvcsd->port.count, 0);
39473 hvcsd->port.tty = tty;
39474 tty->driver_data = hvcsd;
39475
39476@@ -1185,7 +1186,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
39477 unsigned long flags;
39478
39479 spin_lock_irqsave(&hvcsd->lock, flags);
39480- hvcsd->port.count++;
39481+ atomic_inc(&hvcsd->port.count);
39482 hvcsd->todo_mask |= HVCS_SCHED_READ;
39483 spin_unlock_irqrestore(&hvcsd->lock, flags);
39484
39485@@ -1221,7 +1222,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39486 hvcsd = tty->driver_data;
39487
39488 spin_lock_irqsave(&hvcsd->lock, flags);
39489- if (--hvcsd->port.count == 0) {
39490+ if (atomic_dec_and_test(&hvcsd->port.count)) {
39491
39492 vio_disable_interrupts(hvcsd->vdev);
39493
39494@@ -1246,10 +1247,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
39495
39496 free_irq(irq, hvcsd);
39497 return;
39498- } else if (hvcsd->port.count < 0) {
39499+ } else if (atomic_read(&hvcsd->port.count) < 0) {
39500 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
39501 " is missmanaged.\n",
39502- hvcsd->vdev->unit_address, hvcsd->port.count);
39503+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
39504 }
39505
39506 spin_unlock_irqrestore(&hvcsd->lock, flags);
39507@@ -1271,7 +1272,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39508
39509 spin_lock_irqsave(&hvcsd->lock, flags);
39510 /* Preserve this so that we know how many kref refs to put */
39511- temp_open_count = hvcsd->port.count;
39512+ temp_open_count = atomic_read(&hvcsd->port.count);
39513
39514 /*
39515 * Don't kref put inside the spinlock because the destruction
39516@@ -1286,7 +1287,7 @@ static void hvcs_hangup(struct tty_struct * tty)
39517 tty->driver_data = NULL;
39518 hvcsd->port.tty = NULL;
39519
39520- hvcsd->port.count = 0;
39521+ atomic_set(&hvcsd->port.count, 0);
39522
39523 /* This will drop any buffered data on the floor which is OK in a hangup
39524 * scenario. */
39525@@ -1357,7 +1358,7 @@ static int hvcs_write(struct tty_struct *tty,
39526 * the middle of a write operation? This is a crummy place to do this
39527 * but we want to keep it all in the spinlock.
39528 */
39529- if (hvcsd->port.count <= 0) {
39530+ if (atomic_read(&hvcsd->port.count) <= 0) {
39531 spin_unlock_irqrestore(&hvcsd->lock, flags);
39532 return -ENODEV;
39533 }
39534@@ -1431,7 +1432,7 @@ static int hvcs_write_room(struct tty_struct *tty)
39535 {
39536 struct hvcs_struct *hvcsd = tty->driver_data;
39537
39538- if (!hvcsd || hvcsd->port.count <= 0)
39539+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
39540 return 0;
39541
39542 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
39543diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
39544index 160f0ad..588b853 100644
39545--- a/drivers/tty/ipwireless/tty.c
39546+++ b/drivers/tty/ipwireless/tty.c
39547@@ -29,6 +29,7 @@
39548 #include <linux/tty_driver.h>
39549 #include <linux/tty_flip.h>
39550 #include <linux/uaccess.h>
39551+#include <asm/local.h>
39552
39553 #include "tty.h"
39554 #include "network.h"
39555@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39556 mutex_unlock(&tty->ipw_tty_mutex);
39557 return -ENODEV;
39558 }
39559- if (tty->port.count == 0)
39560+ if (atomic_read(&tty->port.count) == 0)
39561 tty->tx_bytes_queued = 0;
39562
39563- tty->port.count++;
39564+ atomic_inc(&tty->port.count);
39565
39566 tty->port.tty = linux_tty;
39567 linux_tty->driver_data = tty;
39568@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
39569
39570 static void do_ipw_close(struct ipw_tty *tty)
39571 {
39572- tty->port.count--;
39573-
39574- if (tty->port.count == 0) {
39575+ if (atomic_dec_return(&tty->port.count) == 0) {
39576 struct tty_struct *linux_tty = tty->port.tty;
39577
39578 if (linux_tty != NULL) {
39579@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
39580 return;
39581
39582 mutex_lock(&tty->ipw_tty_mutex);
39583- if (tty->port.count == 0) {
39584+ if (atomic_read(&tty->port.count) == 0) {
39585 mutex_unlock(&tty->ipw_tty_mutex);
39586 return;
39587 }
39588@@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
39589 return;
39590 }
39591
39592- if (!tty->port.count) {
39593+ if (!atomic_read(&tty->port.count)) {
39594 mutex_unlock(&tty->ipw_tty_mutex);
39595 return;
39596 }
39597@@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
39598 return -ENODEV;
39599
39600 mutex_lock(&tty->ipw_tty_mutex);
39601- if (!tty->port.count) {
39602+ if (!atomic_read(&tty->port.count)) {
39603 mutex_unlock(&tty->ipw_tty_mutex);
39604 return -EINVAL;
39605 }
39606@@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
39607 if (!tty)
39608 return -ENODEV;
39609
39610- if (!tty->port.count)
39611+ if (!atomic_read(&tty->port.count))
39612 return -EINVAL;
39613
39614 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
39615@@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
39616 if (!tty)
39617 return 0;
39618
39619- if (!tty->port.count)
39620+ if (!atomic_read(&tty->port.count))
39621 return 0;
39622
39623 return tty->tx_bytes_queued;
39624@@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
39625 if (!tty)
39626 return -ENODEV;
39627
39628- if (!tty->port.count)
39629+ if (!atomic_read(&tty->port.count))
39630 return -EINVAL;
39631
39632 return get_control_lines(tty);
39633@@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
39634 if (!tty)
39635 return -ENODEV;
39636
39637- if (!tty->port.count)
39638+ if (!atomic_read(&tty->port.count))
39639 return -EINVAL;
39640
39641 return set_control_lines(tty, set, clear);
39642@@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
39643 if (!tty)
39644 return -ENODEV;
39645
39646- if (!tty->port.count)
39647+ if (!atomic_read(&tty->port.count))
39648 return -EINVAL;
39649
39650 /* FIXME: Exactly how is the tty object locked here .. */
39651@@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
39652 * are gone */
39653 mutex_lock(&ttyj->ipw_tty_mutex);
39654 }
39655- while (ttyj->port.count)
39656+ while (atomic_read(&ttyj->port.count))
39657 do_ipw_close(ttyj);
39658 ipwireless_disassociate_network_ttys(network,
39659 ttyj->channel_idx);
39660diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
39661index 56e616b..9d9f10a 100644
39662--- a/drivers/tty/moxa.c
39663+++ b/drivers/tty/moxa.c
39664@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
39665 }
39666
39667 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
39668- ch->port.count++;
39669+ atomic_inc(&ch->port.count);
39670 tty->driver_data = ch;
39671 tty_port_tty_set(&ch->port, tty);
39672 mutex_lock(&ch->port.mutex);
39673diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
39674index 1e8e8ce..a9efc93 100644
39675--- a/drivers/tty/n_gsm.c
39676+++ b/drivers/tty/n_gsm.c
39677@@ -1638,7 +1638,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
39678 kref_init(&dlci->ref);
39679 mutex_init(&dlci->mutex);
39680 dlci->fifo = &dlci->_fifo;
39681- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
39682+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
39683 kfree(dlci);
39684 return NULL;
39685 }
39686@@ -2925,7 +2925,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
39687 struct gsm_dlci *dlci = tty->driver_data;
39688 struct tty_port *port = &dlci->port;
39689
39690- port->count++;
39691+ atomic_inc(&port->count);
39692 dlci_get(dlci);
39693 dlci_get(dlci->gsm->dlci[0]);
39694 mux_get(dlci->gsm);
39695diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
39696index 8c0b7b4..e88f052 100644
39697--- a/drivers/tty/n_tty.c
39698+++ b/drivers/tty/n_tty.c
39699@@ -2142,6 +2142,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
39700 {
39701 *ops = tty_ldisc_N_TTY;
39702 ops->owner = NULL;
39703- ops->refcount = ops->flags = 0;
39704+ atomic_set(&ops->refcount, 0);
39705+ ops->flags = 0;
39706 }
39707 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
39708diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
39709index 8cf8d0a..4ef9ed0 100644
39710--- a/drivers/tty/pty.c
39711+++ b/drivers/tty/pty.c
39712@@ -730,8 +730,10 @@ static void __init unix98_pty_init(void)
39713 panic("Couldn't register Unix98 pts driver");
39714
39715 /* Now create the /dev/ptmx special device */
39716+ pax_open_kernel();
39717 tty_default_fops(&ptmx_fops);
39718- ptmx_fops.open = ptmx_open;
39719+ *(void **)&ptmx_fops.open = ptmx_open;
39720+ pax_close_kernel();
39721
39722 cdev_init(&ptmx_cdev, &ptmx_fops);
39723 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
39724diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
39725index 9700d34..df7520c 100644
39726--- a/drivers/tty/rocket.c
39727+++ b/drivers/tty/rocket.c
39728@@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39729 tty->driver_data = info;
39730 tty_port_tty_set(port, tty);
39731
39732- if (port->count++ == 0) {
39733+ if (atomic_inc_return(&port->count) == 1) {
39734 atomic_inc(&rp_num_ports_open);
39735
39736 #ifdef ROCKET_DEBUG_OPEN
39737@@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
39738 #endif
39739 }
39740 #ifdef ROCKET_DEBUG_OPEN
39741- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
39742+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
39743 #endif
39744
39745 /*
39746@@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
39747 spin_unlock_irqrestore(&info->port.lock, flags);
39748 return;
39749 }
39750- if (info->port.count)
39751+ if (atomic_read(&info->port.count))
39752 atomic_dec(&rp_num_ports_open);
39753 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
39754 spin_unlock_irqrestore(&info->port.lock, flags);
39755diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
39756index 1002054..dd644a8 100644
39757--- a/drivers/tty/serial/kgdboc.c
39758+++ b/drivers/tty/serial/kgdboc.c
39759@@ -24,8 +24,9 @@
39760 #define MAX_CONFIG_LEN 40
39761
39762 static struct kgdb_io kgdboc_io_ops;
39763+static struct kgdb_io kgdboc_io_ops_console;
39764
39765-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
39766+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
39767 static int configured = -1;
39768
39769 static char config[MAX_CONFIG_LEN];
39770@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
39771 kgdboc_unregister_kbd();
39772 if (configured == 1)
39773 kgdb_unregister_io_module(&kgdboc_io_ops);
39774+ else if (configured == 2)
39775+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
39776 }
39777
39778 static int configure_kgdboc(void)
39779@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
39780 int err;
39781 char *cptr = config;
39782 struct console *cons;
39783+ int is_console = 0;
39784
39785 err = kgdboc_option_setup(config);
39786 if (err || !strlen(config) || isspace(config[0]))
39787 goto noconfig;
39788
39789 err = -ENODEV;
39790- kgdboc_io_ops.is_console = 0;
39791 kgdb_tty_driver = NULL;
39792
39793 kgdboc_use_kms = 0;
39794@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
39795 int idx;
39796 if (cons->device && cons->device(cons, &idx) == p &&
39797 idx == tty_line) {
39798- kgdboc_io_ops.is_console = 1;
39799+ is_console = 1;
39800 break;
39801 }
39802 cons = cons->next;
39803@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
39804 kgdb_tty_line = tty_line;
39805
39806 do_register:
39807- err = kgdb_register_io_module(&kgdboc_io_ops);
39808+ if (is_console) {
39809+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
39810+ configured = 2;
39811+ } else {
39812+ err = kgdb_register_io_module(&kgdboc_io_ops);
39813+ configured = 1;
39814+ }
39815 if (err)
39816 goto noconfig;
39817
39818@@ -205,8 +214,6 @@ do_register:
39819 if (err)
39820 goto nmi_con_failed;
39821
39822- configured = 1;
39823-
39824 return 0;
39825
39826 nmi_con_failed:
39827@@ -223,7 +230,7 @@ noconfig:
39828 static int __init init_kgdboc(void)
39829 {
39830 /* Already configured? */
39831- if (configured == 1)
39832+ if (configured >= 1)
39833 return 0;
39834
39835 return configure_kgdboc();
39836@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
39837 if (config[len - 1] == '\n')
39838 config[len - 1] = '\0';
39839
39840- if (configured == 1)
39841+ if (configured >= 1)
39842 cleanup_kgdboc();
39843
39844 /* Go and configure with the new params. */
39845@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
39846 .post_exception = kgdboc_post_exp_handler,
39847 };
39848
39849+static struct kgdb_io kgdboc_io_ops_console = {
39850+ .name = "kgdboc",
39851+ .read_char = kgdboc_get_char,
39852+ .write_char = kgdboc_put_char,
39853+ .pre_exception = kgdboc_pre_exp_handler,
39854+ .post_exception = kgdboc_post_exp_handler,
39855+ .is_console = 1
39856+};
39857+
39858 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
39859 /* This is only available if kgdboc is a built in for early debugging */
39860 static int __init kgdboc_early_init(char *opt)
39861diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
39862index 7f04717..0f3794f 100644
39863--- a/drivers/tty/serial/samsung.c
39864+++ b/drivers/tty/serial/samsung.c
39865@@ -445,11 +445,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
39866 }
39867 }
39868
39869+static int s3c64xx_serial_startup(struct uart_port *port);
39870 static int s3c24xx_serial_startup(struct uart_port *port)
39871 {
39872 struct s3c24xx_uart_port *ourport = to_ourport(port);
39873 int ret;
39874
39875+ /* Startup sequence is different for s3c64xx and higher SoC's */
39876+ if (s3c24xx_serial_has_interrupt_mask(port))
39877+ return s3c64xx_serial_startup(port);
39878+
39879 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
39880 port->mapbase, port->membase);
39881
39882@@ -1115,10 +1120,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
39883 /* setup info for port */
39884 port->dev = &platdev->dev;
39885
39886- /* Startup sequence is different for s3c64xx and higher SoC's */
39887- if (s3c24xx_serial_has_interrupt_mask(port))
39888- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
39889-
39890 port->uartclk = 1;
39891
39892 if (cfg->uart_flags & UPF_CONS_FLOW) {
39893diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
39894index 0fcfd98..8244fce 100644
39895--- a/drivers/tty/serial/serial_core.c
39896+++ b/drivers/tty/serial/serial_core.c
39897@@ -1408,7 +1408,7 @@ static void uart_hangup(struct tty_struct *tty)
39898 uart_flush_buffer(tty);
39899 uart_shutdown(tty, state);
39900 spin_lock_irqsave(&port->lock, flags);
39901- port->count = 0;
39902+ atomic_set(&port->count, 0);
39903 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
39904 spin_unlock_irqrestore(&port->lock, flags);
39905 tty_port_tty_set(port, NULL);
39906@@ -1504,7 +1504,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39907 goto end;
39908 }
39909
39910- port->count++;
39911+ atomic_inc(&port->count);
39912 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
39913 retval = -ENXIO;
39914 goto err_dec_count;
39915@@ -1531,7 +1531,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39916 /*
39917 * Make sure the device is in D0 state.
39918 */
39919- if (port->count == 1)
39920+ if (atomic_read(&port->count) == 1)
39921 uart_change_pm(state, 0);
39922
39923 /*
39924@@ -1549,7 +1549,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
39925 end:
39926 return retval;
39927 err_dec_count:
39928- port->count--;
39929+ atomic_inc(&port->count);
39930 mutex_unlock(&port->mutex);
39931 goto end;
39932 }
39933diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
39934index 70e3a52..5742052 100644
39935--- a/drivers/tty/synclink.c
39936+++ b/drivers/tty/synclink.c
39937@@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39938
39939 if (debug_level >= DEBUG_LEVEL_INFO)
39940 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
39941- __FILE__,__LINE__, info->device_name, info->port.count);
39942+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
39943
39944 if (tty_port_close_start(&info->port, tty, filp) == 0)
39945 goto cleanup;
39946@@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
39947 cleanup:
39948 if (debug_level >= DEBUG_LEVEL_INFO)
39949 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
39950- tty->driver->name, info->port.count);
39951+ tty->driver->name, atomic_read(&info->port.count));
39952
39953 } /* end of mgsl_close() */
39954
39955@@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
39956
39957 mgsl_flush_buffer(tty);
39958 shutdown(info);
39959-
39960- info->port.count = 0;
39961+
39962+ atomic_set(&info->port.count, 0);
39963 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
39964 info->port.tty = NULL;
39965
39966@@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39967
39968 if (debug_level >= DEBUG_LEVEL_INFO)
39969 printk("%s(%d):block_til_ready before block on %s count=%d\n",
39970- __FILE__,__LINE__, tty->driver->name, port->count );
39971+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39972
39973 spin_lock_irqsave(&info->irq_spinlock, flags);
39974 if (!tty_hung_up_p(filp)) {
39975 extra_count = true;
39976- port->count--;
39977+ atomic_dec(&port->count);
39978 }
39979 spin_unlock_irqrestore(&info->irq_spinlock, flags);
39980 port->blocked_open++;
39981@@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39982
39983 if (debug_level >= DEBUG_LEVEL_INFO)
39984 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
39985- __FILE__,__LINE__, tty->driver->name, port->count );
39986+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
39987
39988 tty_unlock(tty);
39989 schedule();
39990@@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
39991
39992 /* FIXME: Racy on hangup during close wait */
39993 if (extra_count)
39994- port->count++;
39995+ atomic_inc(&port->count);
39996 port->blocked_open--;
39997
39998 if (debug_level >= DEBUG_LEVEL_INFO)
39999 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
40000- __FILE__,__LINE__, tty->driver->name, port->count );
40001+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40002
40003 if (!retval)
40004 port->flags |= ASYNC_NORMAL_ACTIVE;
40005@@ -3405,7 +3405,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40006
40007 if (debug_level >= DEBUG_LEVEL_INFO)
40008 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
40009- __FILE__,__LINE__,tty->driver->name, info->port.count);
40010+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40011
40012 /* If port is closing, signal caller to try again */
40013 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40014@@ -3424,10 +3424,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
40015 spin_unlock_irqrestore(&info->netlock, flags);
40016 goto cleanup;
40017 }
40018- info->port.count++;
40019+ atomic_inc(&info->port.count);
40020 spin_unlock_irqrestore(&info->netlock, flags);
40021
40022- if (info->port.count == 1) {
40023+ if (atomic_read(&info->port.count) == 1) {
40024 /* 1st open on this device, init hardware */
40025 retval = startup(info);
40026 if (retval < 0)
40027@@ -3451,8 +3451,8 @@ cleanup:
40028 if (retval) {
40029 if (tty->count == 1)
40030 info->port.tty = NULL; /* tty layer will release tty struct */
40031- if(info->port.count)
40032- info->port.count--;
40033+ if (atomic_read(&info->port.count))
40034+ atomic_dec(&info->port.count);
40035 }
40036
40037 return retval;
40038@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40039 unsigned short new_crctype;
40040
40041 /* return error if TTY interface open */
40042- if (info->port.count)
40043+ if (atomic_read(&info->port.count))
40044 return -EBUSY;
40045
40046 switch (encoding)
40047@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
40048
40049 /* arbitrate between network and tty opens */
40050 spin_lock_irqsave(&info->netlock, flags);
40051- if (info->port.count != 0 || info->netcount != 0) {
40052+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40053 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40054 spin_unlock_irqrestore(&info->netlock, flags);
40055 return -EBUSY;
40056@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40057 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40058
40059 /* return error if TTY interface open */
40060- if (info->port.count)
40061+ if (atomic_read(&info->port.count))
40062 return -EBUSY;
40063
40064 if (cmd != SIOCWANDEV)
40065diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
40066index b38e954..ce45b38 100644
40067--- a/drivers/tty/synclink_gt.c
40068+++ b/drivers/tty/synclink_gt.c
40069@@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40070 tty->driver_data = info;
40071 info->port.tty = tty;
40072
40073- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
40074+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
40075
40076 /* If port is closing, signal caller to try again */
40077 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40078@@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40079 mutex_unlock(&info->port.mutex);
40080 goto cleanup;
40081 }
40082- info->port.count++;
40083+ atomic_inc(&info->port.count);
40084 spin_unlock_irqrestore(&info->netlock, flags);
40085
40086- if (info->port.count == 1) {
40087+ if (atomic_read(&info->port.count) == 1) {
40088 /* 1st open on this device, init hardware */
40089 retval = startup(info);
40090 if (retval < 0) {
40091@@ -716,8 +716,8 @@ cleanup:
40092 if (retval) {
40093 if (tty->count == 1)
40094 info->port.tty = NULL; /* tty layer will release tty struct */
40095- if(info->port.count)
40096- info->port.count--;
40097+ if(atomic_read(&info->port.count))
40098+ atomic_dec(&info->port.count);
40099 }
40100
40101 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
40102@@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40103
40104 if (sanity_check(info, tty->name, "close"))
40105 return;
40106- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
40107+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
40108
40109 if (tty_port_close_start(&info->port, tty, filp) == 0)
40110 goto cleanup;
40111@@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40112 tty_port_close_end(&info->port, tty);
40113 info->port.tty = NULL;
40114 cleanup:
40115- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
40116+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
40117 }
40118
40119 static void hangup(struct tty_struct *tty)
40120@@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
40121 shutdown(info);
40122
40123 spin_lock_irqsave(&info->port.lock, flags);
40124- info->port.count = 0;
40125+ atomic_set(&info->port.count, 0);
40126 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40127 info->port.tty = NULL;
40128 spin_unlock_irqrestore(&info->port.lock, flags);
40129@@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40130 unsigned short new_crctype;
40131
40132 /* return error if TTY interface open */
40133- if (info->port.count)
40134+ if (atomic_read(&info->port.count))
40135 return -EBUSY;
40136
40137 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
40138@@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
40139
40140 /* arbitrate between network and tty opens */
40141 spin_lock_irqsave(&info->netlock, flags);
40142- if (info->port.count != 0 || info->netcount != 0) {
40143+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40144 DBGINFO(("%s hdlc_open busy\n", dev->name));
40145 spin_unlock_irqrestore(&info->netlock, flags);
40146 return -EBUSY;
40147@@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40148 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
40149
40150 /* return error if TTY interface open */
40151- if (info->port.count)
40152+ if (atomic_read(&info->port.count))
40153 return -EBUSY;
40154
40155 if (cmd != SIOCWANDEV)
40156@@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
40157 if (port == NULL)
40158 continue;
40159 spin_lock(&port->lock);
40160- if ((port->port.count || port->netcount) &&
40161+ if ((atomic_read(&port->port.count) || port->netcount) &&
40162 port->pending_bh && !port->bh_running &&
40163 !port->bh_requested) {
40164 DBGISR(("%s bh queued\n", port->device_name));
40165@@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40166 spin_lock_irqsave(&info->lock, flags);
40167 if (!tty_hung_up_p(filp)) {
40168 extra_count = true;
40169- port->count--;
40170+ atomic_dec(&port->count);
40171 }
40172 spin_unlock_irqrestore(&info->lock, flags);
40173 port->blocked_open++;
40174@@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40175 remove_wait_queue(&port->open_wait, &wait);
40176
40177 if (extra_count)
40178- port->count++;
40179+ atomic_inc(&port->count);
40180 port->blocked_open--;
40181
40182 if (!retval)
40183diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
40184index f17d9f3..27a041b 100644
40185--- a/drivers/tty/synclinkmp.c
40186+++ b/drivers/tty/synclinkmp.c
40187@@ -751,7 +751,7 @@ static int open(struct tty_struct *tty, struct file *filp)
40188
40189 if (debug_level >= DEBUG_LEVEL_INFO)
40190 printk("%s(%d):%s open(), old ref count = %d\n",
40191- __FILE__,__LINE__,tty->driver->name, info->port.count);
40192+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
40193
40194 /* If port is closing, signal caller to try again */
40195 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
40196@@ -770,10 +770,10 @@ static int open(struct tty_struct *tty, struct file *filp)
40197 spin_unlock_irqrestore(&info->netlock, flags);
40198 goto cleanup;
40199 }
40200- info->port.count++;
40201+ atomic_inc(&info->port.count);
40202 spin_unlock_irqrestore(&info->netlock, flags);
40203
40204- if (info->port.count == 1) {
40205+ if (atomic_read(&info->port.count) == 1) {
40206 /* 1st open on this device, init hardware */
40207 retval = startup(info);
40208 if (retval < 0)
40209@@ -797,8 +797,8 @@ cleanup:
40210 if (retval) {
40211 if (tty->count == 1)
40212 info->port.tty = NULL; /* tty layer will release tty struct */
40213- if(info->port.count)
40214- info->port.count--;
40215+ if(atomic_read(&info->port.count))
40216+ atomic_dec(&info->port.count);
40217 }
40218
40219 return retval;
40220@@ -816,7 +816,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40221
40222 if (debug_level >= DEBUG_LEVEL_INFO)
40223 printk("%s(%d):%s close() entry, count=%d\n",
40224- __FILE__,__LINE__, info->device_name, info->port.count);
40225+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
40226
40227 if (tty_port_close_start(&info->port, tty, filp) == 0)
40228 goto cleanup;
40229@@ -835,7 +835,7 @@ static void close(struct tty_struct *tty, struct file *filp)
40230 cleanup:
40231 if (debug_level >= DEBUG_LEVEL_INFO)
40232 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
40233- tty->driver->name, info->port.count);
40234+ tty->driver->name, atomic_read(&info->port.count));
40235 }
40236
40237 /* Called by tty_hangup() when a hangup is signaled.
40238@@ -858,7 +858,7 @@ static void hangup(struct tty_struct *tty)
40239 shutdown(info);
40240
40241 spin_lock_irqsave(&info->port.lock, flags);
40242- info->port.count = 0;
40243+ atomic_set(&info->port.count, 0);
40244 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
40245 info->port.tty = NULL;
40246 spin_unlock_irqrestore(&info->port.lock, flags);
40247@@ -1566,7 +1566,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
40248 unsigned short new_crctype;
40249
40250 /* return error if TTY interface open */
40251- if (info->port.count)
40252+ if (atomic_read(&info->port.count))
40253 return -EBUSY;
40254
40255 switch (encoding)
40256@@ -1661,7 +1661,7 @@ static int hdlcdev_open(struct net_device *dev)
40257
40258 /* arbitrate between network and tty opens */
40259 spin_lock_irqsave(&info->netlock, flags);
40260- if (info->port.count != 0 || info->netcount != 0) {
40261+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
40262 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
40263 spin_unlock_irqrestore(&info->netlock, flags);
40264 return -EBUSY;
40265@@ -1747,7 +1747,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40266 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
40267
40268 /* return error if TTY interface open */
40269- if (info->port.count)
40270+ if (atomic_read(&info->port.count))
40271 return -EBUSY;
40272
40273 if (cmd != SIOCWANDEV)
40274@@ -2632,7 +2632,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
40275 * do not request bottom half processing if the
40276 * device is not open in a normal mode.
40277 */
40278- if ( port && (port->port.count || port->netcount) &&
40279+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
40280 port->pending_bh && !port->bh_running &&
40281 !port->bh_requested ) {
40282 if ( debug_level >= DEBUG_LEVEL_ISR )
40283@@ -3330,12 +3330,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40284
40285 if (debug_level >= DEBUG_LEVEL_INFO)
40286 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
40287- __FILE__,__LINE__, tty->driver->name, port->count );
40288+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40289
40290 spin_lock_irqsave(&info->lock, flags);
40291 if (!tty_hung_up_p(filp)) {
40292 extra_count = true;
40293- port->count--;
40294+ atomic_dec(&port->count);
40295 }
40296 spin_unlock_irqrestore(&info->lock, flags);
40297 port->blocked_open++;
40298@@ -3364,7 +3364,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40299
40300 if (debug_level >= DEBUG_LEVEL_INFO)
40301 printk("%s(%d):%s block_til_ready() count=%d\n",
40302- __FILE__,__LINE__, tty->driver->name, port->count );
40303+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40304
40305 tty_unlock(tty);
40306 schedule();
40307@@ -3375,12 +3375,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
40308 remove_wait_queue(&port->open_wait, &wait);
40309
40310 if (extra_count)
40311- port->count++;
40312+ atomic_inc(&port->count);
40313 port->blocked_open--;
40314
40315 if (debug_level >= DEBUG_LEVEL_INFO)
40316 printk("%s(%d):%s block_til_ready() after, count=%d\n",
40317- __FILE__,__LINE__, tty->driver->name, port->count );
40318+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
40319
40320 if (!retval)
40321 port->flags |= ASYNC_NORMAL_ACTIVE;
40322diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
40323index 16ee6ce..bfcac57 100644
40324--- a/drivers/tty/sysrq.c
40325+++ b/drivers/tty/sysrq.c
40326@@ -866,7 +866,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
40327 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
40328 size_t count, loff_t *ppos)
40329 {
40330- if (count) {
40331+ if (count && capable(CAP_SYS_ADMIN)) {
40332 char c;
40333
40334 if (get_user(c, buf))
40335diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
40336index 2ea176b..2877bc8 100644
40337--- a/drivers/tty/tty_io.c
40338+++ b/drivers/tty/tty_io.c
40339@@ -3395,7 +3395,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
40340
40341 void tty_default_fops(struct file_operations *fops)
40342 {
40343- *fops = tty_fops;
40344+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
40345 }
40346
40347 /*
40348diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
40349index 0f2a2c5..471e228 100644
40350--- a/drivers/tty/tty_ldisc.c
40351+++ b/drivers/tty/tty_ldisc.c
40352@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
40353 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
40354 struct tty_ldisc_ops *ldo = ld->ops;
40355
40356- ldo->refcount--;
40357+ atomic_dec(&ldo->refcount);
40358 module_put(ldo->owner);
40359 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40360
40361@@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
40362 spin_lock_irqsave(&tty_ldisc_lock, flags);
40363 tty_ldiscs[disc] = new_ldisc;
40364 new_ldisc->num = disc;
40365- new_ldisc->refcount = 0;
40366+ atomic_set(&new_ldisc->refcount, 0);
40367 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40368
40369 return ret;
40370@@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
40371 return -EINVAL;
40372
40373 spin_lock_irqsave(&tty_ldisc_lock, flags);
40374- if (tty_ldiscs[disc]->refcount)
40375+ if (atomic_read(&tty_ldiscs[disc]->refcount))
40376 ret = -EBUSY;
40377 else
40378 tty_ldiscs[disc] = NULL;
40379@@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
40380 if (ldops) {
40381 ret = ERR_PTR(-EAGAIN);
40382 if (try_module_get(ldops->owner)) {
40383- ldops->refcount++;
40384+ atomic_inc(&ldops->refcount);
40385 ret = ldops;
40386 }
40387 }
40388@@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
40389 unsigned long flags;
40390
40391 spin_lock_irqsave(&tty_ldisc_lock, flags);
40392- ldops->refcount--;
40393+ atomic_dec(&ldops->refcount);
40394 module_put(ldops->owner);
40395 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
40396 }
40397diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
40398index d7bdd8d..feaef30 100644
40399--- a/drivers/tty/tty_port.c
40400+++ b/drivers/tty/tty_port.c
40401@@ -202,7 +202,7 @@ void tty_port_hangup(struct tty_port *port)
40402 unsigned long flags;
40403
40404 spin_lock_irqsave(&port->lock, flags);
40405- port->count = 0;
40406+ atomic_set(&port->count, 0);
40407 port->flags &= ~ASYNC_NORMAL_ACTIVE;
40408 if (port->tty) {
40409 set_bit(TTY_IO_ERROR, &port->tty->flags);
40410@@ -328,7 +328,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40411 /* The port lock protects the port counts */
40412 spin_lock_irqsave(&port->lock, flags);
40413 if (!tty_hung_up_p(filp))
40414- port->count--;
40415+ atomic_dec(&port->count);
40416 port->blocked_open++;
40417 spin_unlock_irqrestore(&port->lock, flags);
40418
40419@@ -370,7 +370,7 @@ int tty_port_block_til_ready(struct tty_port *port,
40420 we must not mess that up further */
40421 spin_lock_irqsave(&port->lock, flags);
40422 if (!tty_hung_up_p(filp))
40423- port->count++;
40424+ atomic_inc(&port->count);
40425 port->blocked_open--;
40426 if (retval == 0)
40427 port->flags |= ASYNC_NORMAL_ACTIVE;
40428@@ -390,19 +390,19 @@ int tty_port_close_start(struct tty_port *port,
40429 return 0;
40430 }
40431
40432- if (tty->count == 1 && port->count != 1) {
40433+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
40434 printk(KERN_WARNING
40435 "tty_port_close_start: tty->count = 1 port count = %d.\n",
40436- port->count);
40437- port->count = 1;
40438+ atomic_read(&port->count));
40439+ atomic_set(&port->count, 1);
40440 }
40441- if (--port->count < 0) {
40442+ if (atomic_dec_return(&port->count) < 0) {
40443 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
40444- port->count);
40445- port->count = 0;
40446+ atomic_read(&port->count));
40447+ atomic_set(&port->count, 0);
40448 }
40449
40450- if (port->count) {
40451+ if (atomic_read(&port->count)) {
40452 spin_unlock_irqrestore(&port->lock, flags);
40453 if (port->ops->drop)
40454 port->ops->drop(port);
40455@@ -500,7 +500,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
40456 {
40457 spin_lock_irq(&port->lock);
40458 if (!tty_hung_up_p(filp))
40459- ++port->count;
40460+ atomic_inc(&port->count);
40461 spin_unlock_irq(&port->lock);
40462 tty_port_tty_set(port, tty);
40463
40464diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
40465index 681765b..d3ccdf2 100644
40466--- a/drivers/tty/vt/keyboard.c
40467+++ b/drivers/tty/vt/keyboard.c
40468@@ -660,6 +660,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
40469 kbd->kbdmode == VC_OFF) &&
40470 value != KVAL(K_SAK))
40471 return; /* SAK is allowed even in raw mode */
40472+
40473+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
40474+ {
40475+ void *func = fn_handler[value];
40476+ if (func == fn_show_state || func == fn_show_ptregs ||
40477+ func == fn_show_mem)
40478+ return;
40479+ }
40480+#endif
40481+
40482 fn_handler[value](vc);
40483 }
40484
40485@@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40486 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
40487 return -EFAULT;
40488
40489- if (!capable(CAP_SYS_TTY_CONFIG))
40490- perm = 0;
40491-
40492 switch (cmd) {
40493 case KDGKBENT:
40494 /* Ensure another thread doesn't free it under us */
40495@@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
40496 spin_unlock_irqrestore(&kbd_event_lock, flags);
40497 return put_user(val, &user_kbe->kb_value);
40498 case KDSKBENT:
40499+ if (!capable(CAP_SYS_TTY_CONFIG))
40500+ perm = 0;
40501+
40502 if (!perm)
40503 return -EPERM;
40504 if (!i && v == K_NOSUCHMAP) {
40505@@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40506 int i, j, k;
40507 int ret;
40508
40509- if (!capable(CAP_SYS_TTY_CONFIG))
40510- perm = 0;
40511-
40512 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
40513 if (!kbs) {
40514 ret = -ENOMEM;
40515@@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
40516 kfree(kbs);
40517 return ((p && *p) ? -EOVERFLOW : 0);
40518 case KDSKBSENT:
40519+ if (!capable(CAP_SYS_TTY_CONFIG))
40520+ perm = 0;
40521+
40522 if (!perm) {
40523 ret = -EPERM;
40524 goto reterr;
40525diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
40526index 5110f36..8dc0a74 100644
40527--- a/drivers/uio/uio.c
40528+++ b/drivers/uio/uio.c
40529@@ -25,6 +25,7 @@
40530 #include <linux/kobject.h>
40531 #include <linux/cdev.h>
40532 #include <linux/uio_driver.h>
40533+#include <asm/local.h>
40534
40535 #define UIO_MAX_DEVICES (1U << MINORBITS)
40536
40537@@ -32,10 +33,10 @@ struct uio_device {
40538 struct module *owner;
40539 struct device *dev;
40540 int minor;
40541- atomic_t event;
40542+ atomic_unchecked_t event;
40543 struct fasync_struct *async_queue;
40544 wait_queue_head_t wait;
40545- int vma_count;
40546+ local_t vma_count;
40547 struct uio_info *info;
40548 struct kobject *map_dir;
40549 struct kobject *portio_dir;
40550@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
40551 struct device_attribute *attr, char *buf)
40552 {
40553 struct uio_device *idev = dev_get_drvdata(dev);
40554- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
40555+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
40556 }
40557
40558 static struct device_attribute uio_class_attributes[] = {
40559@@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
40560 {
40561 struct uio_device *idev = info->uio_dev;
40562
40563- atomic_inc(&idev->event);
40564+ atomic_inc_unchecked(&idev->event);
40565 wake_up_interruptible(&idev->wait);
40566 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
40567 }
40568@@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
40569 }
40570
40571 listener->dev = idev;
40572- listener->event_count = atomic_read(&idev->event);
40573+ listener->event_count = atomic_read_unchecked(&idev->event);
40574 filep->private_data = listener;
40575
40576 if (idev->info->open) {
40577@@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
40578 return -EIO;
40579
40580 poll_wait(filep, &idev->wait, wait);
40581- if (listener->event_count != atomic_read(&idev->event))
40582+ if (listener->event_count != atomic_read_unchecked(&idev->event))
40583 return POLLIN | POLLRDNORM;
40584 return 0;
40585 }
40586@@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
40587 do {
40588 set_current_state(TASK_INTERRUPTIBLE);
40589
40590- event_count = atomic_read(&idev->event);
40591+ event_count = atomic_read_unchecked(&idev->event);
40592 if (event_count != listener->event_count) {
40593 if (copy_to_user(buf, &event_count, count))
40594 retval = -EFAULT;
40595@@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
40596 static void uio_vma_open(struct vm_area_struct *vma)
40597 {
40598 struct uio_device *idev = vma->vm_private_data;
40599- idev->vma_count++;
40600+ local_inc(&idev->vma_count);
40601 }
40602
40603 static void uio_vma_close(struct vm_area_struct *vma)
40604 {
40605 struct uio_device *idev = vma->vm_private_data;
40606- idev->vma_count--;
40607+ local_dec(&idev->vma_count);
40608 }
40609
40610 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40611@@ -819,7 +820,7 @@ int __uio_register_device(struct module *owner,
40612 idev->owner = owner;
40613 idev->info = info;
40614 init_waitqueue_head(&idev->wait);
40615- atomic_set(&idev->event, 0);
40616+ atomic_set_unchecked(&idev->event, 0);
40617
40618 ret = uio_get_minor(idev);
40619 if (ret)
40620diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
40621index b7eb86a..36d28af 100644
40622--- a/drivers/usb/atm/cxacru.c
40623+++ b/drivers/usb/atm/cxacru.c
40624@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
40625 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
40626 if (ret < 2)
40627 return -EINVAL;
40628- if (index < 0 || index > 0x7f)
40629+ if (index > 0x7f)
40630 return -EINVAL;
40631 pos += tmp;
40632
40633diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
40634index 35f10bf..6a38a0b 100644
40635--- a/drivers/usb/atm/usbatm.c
40636+++ b/drivers/usb/atm/usbatm.c
40637@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40638 if (printk_ratelimit())
40639 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
40640 __func__, vpi, vci);
40641- atomic_inc(&vcc->stats->rx_err);
40642+ atomic_inc_unchecked(&vcc->stats->rx_err);
40643 return;
40644 }
40645
40646@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40647 if (length > ATM_MAX_AAL5_PDU) {
40648 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
40649 __func__, length, vcc);
40650- atomic_inc(&vcc->stats->rx_err);
40651+ atomic_inc_unchecked(&vcc->stats->rx_err);
40652 goto out;
40653 }
40654
40655@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40656 if (sarb->len < pdu_length) {
40657 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
40658 __func__, pdu_length, sarb->len, vcc);
40659- atomic_inc(&vcc->stats->rx_err);
40660+ atomic_inc_unchecked(&vcc->stats->rx_err);
40661 goto out;
40662 }
40663
40664 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
40665 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
40666 __func__, vcc);
40667- atomic_inc(&vcc->stats->rx_err);
40668+ atomic_inc_unchecked(&vcc->stats->rx_err);
40669 goto out;
40670 }
40671
40672@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40673 if (printk_ratelimit())
40674 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
40675 __func__, length);
40676- atomic_inc(&vcc->stats->rx_drop);
40677+ atomic_inc_unchecked(&vcc->stats->rx_drop);
40678 goto out;
40679 }
40680
40681@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
40682
40683 vcc->push(vcc, skb);
40684
40685- atomic_inc(&vcc->stats->rx);
40686+ atomic_inc_unchecked(&vcc->stats->rx);
40687 out:
40688 skb_trim(sarb, 0);
40689 }
40690@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
40691 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
40692
40693 usbatm_pop(vcc, skb);
40694- atomic_inc(&vcc->stats->tx);
40695+ atomic_inc_unchecked(&vcc->stats->tx);
40696
40697 skb = skb_dequeue(&instance->sndqueue);
40698 }
40699@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
40700 if (!left--)
40701 return sprintf(page,
40702 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
40703- atomic_read(&atm_dev->stats.aal5.tx),
40704- atomic_read(&atm_dev->stats.aal5.tx_err),
40705- atomic_read(&atm_dev->stats.aal5.rx),
40706- atomic_read(&atm_dev->stats.aal5.rx_err),
40707- atomic_read(&atm_dev->stats.aal5.rx_drop));
40708+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
40709+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
40710+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
40711+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
40712+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
40713
40714 if (!left--) {
40715 if (instance->disconnected)
40716diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
40717index f460de3..95ba1f6 100644
40718--- a/drivers/usb/core/devices.c
40719+++ b/drivers/usb/core/devices.c
40720@@ -126,7 +126,7 @@ static const char format_endpt[] =
40721 * time it gets called.
40722 */
40723 static struct device_connect_event {
40724- atomic_t count;
40725+ atomic_unchecked_t count;
40726 wait_queue_head_t wait;
40727 } device_event = {
40728 .count = ATOMIC_INIT(1),
40729@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
40730
40731 void usbfs_conn_disc_event(void)
40732 {
40733- atomic_add(2, &device_event.count);
40734+ atomic_add_unchecked(2, &device_event.count);
40735 wake_up(&device_event.wait);
40736 }
40737
40738@@ -647,7 +647,7 @@ static unsigned int usb_device_poll(struct file *file,
40739
40740 poll_wait(file, &device_event.wait, wait);
40741
40742- event_count = atomic_read(&device_event.count);
40743+ event_count = atomic_read_unchecked(&device_event.count);
40744 if (file->f_version != event_count) {
40745 file->f_version = event_count;
40746 return POLLIN | POLLRDNORM;
40747diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
40748index f034716..aed0368 100644
40749--- a/drivers/usb/core/hcd.c
40750+++ b/drivers/usb/core/hcd.c
40751@@ -1478,7 +1478,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40752 */
40753 usb_get_urb(urb);
40754 atomic_inc(&urb->use_count);
40755- atomic_inc(&urb->dev->urbnum);
40756+ atomic_inc_unchecked(&urb->dev->urbnum);
40757 usbmon_urb_submit(&hcd->self, urb);
40758
40759 /* NOTE requirements on root-hub callers (usbfs and the hub
40760@@ -1505,7 +1505,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
40761 urb->hcpriv = NULL;
40762 INIT_LIST_HEAD(&urb->urb_list);
40763 atomic_dec(&urb->use_count);
40764- atomic_dec(&urb->dev->urbnum);
40765+ atomic_dec_unchecked(&urb->dev->urbnum);
40766 if (atomic_read(&urb->reject))
40767 wake_up(&usb_kill_urb_queue);
40768 usb_put_urb(urb);
40769diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
40770index 818e4a0..0fc9589 100644
40771--- a/drivers/usb/core/sysfs.c
40772+++ b/drivers/usb/core/sysfs.c
40773@@ -226,7 +226,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
40774 struct usb_device *udev;
40775
40776 udev = to_usb_device(dev);
40777- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
40778+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
40779 }
40780 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
40781
40782diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
40783index cd8fb44..17fbe0c 100644
40784--- a/drivers/usb/core/usb.c
40785+++ b/drivers/usb/core/usb.c
40786@@ -397,7 +397,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
40787 set_dev_node(&dev->dev, dev_to_node(bus->controller));
40788 dev->state = USB_STATE_ATTACHED;
40789 dev->lpm_disable_count = 1;
40790- atomic_set(&dev->urbnum, 0);
40791+ atomic_set_unchecked(&dev->urbnum, 0);
40792
40793 INIT_LIST_HEAD(&dev->ep0.urb_list);
40794 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
40795diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
40796index 4bfa78a..902bfbd 100644
40797--- a/drivers/usb/early/ehci-dbgp.c
40798+++ b/drivers/usb/early/ehci-dbgp.c
40799@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
40800
40801 #ifdef CONFIG_KGDB
40802 static struct kgdb_io kgdbdbgp_io_ops;
40803-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
40804+static struct kgdb_io kgdbdbgp_io_ops_console;
40805+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
40806 #else
40807 #define dbgp_kgdb_mode (0)
40808 #endif
40809@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
40810 .write_char = kgdbdbgp_write_char,
40811 };
40812
40813+static struct kgdb_io kgdbdbgp_io_ops_console = {
40814+ .name = "kgdbdbgp",
40815+ .read_char = kgdbdbgp_read_char,
40816+ .write_char = kgdbdbgp_write_char,
40817+ .is_console = 1
40818+};
40819+
40820 static int kgdbdbgp_wait_time;
40821
40822 static int __init kgdbdbgp_parse_config(char *str)
40823@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
40824 ptr++;
40825 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
40826 }
40827- kgdb_register_io_module(&kgdbdbgp_io_ops);
40828- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
40829+ if (early_dbgp_console.index != -1)
40830+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
40831+ else
40832+ kgdb_register_io_module(&kgdbdbgp_io_ops);
40833
40834 return 0;
40835 }
40836diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
40837index f173952..83d6ec0 100644
40838--- a/drivers/usb/gadget/u_serial.c
40839+++ b/drivers/usb/gadget/u_serial.c
40840@@ -735,9 +735,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40841 spin_lock_irq(&port->port_lock);
40842
40843 /* already open? Great. */
40844- if (port->port.count) {
40845+ if (atomic_read(&port->port.count)) {
40846 status = 0;
40847- port->port.count++;
40848+ atomic_inc(&port->port.count);
40849
40850 /* currently opening/closing? wait ... */
40851 } else if (port->openclose) {
40852@@ -796,7 +796,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
40853 tty->driver_data = port;
40854 port->port.tty = tty;
40855
40856- port->port.count = 1;
40857+ atomic_set(&port->port.count, 1);
40858 port->openclose = false;
40859
40860 /* if connected, start the I/O stream */
40861@@ -838,11 +838,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40862
40863 spin_lock_irq(&port->port_lock);
40864
40865- if (port->port.count != 1) {
40866- if (port->port.count == 0)
40867+ if (atomic_read(&port->port.count) != 1) {
40868+ if (atomic_read(&port->port.count) == 0)
40869 WARN_ON(1);
40870 else
40871- --port->port.count;
40872+ atomic_dec(&port->port.count);
40873 goto exit;
40874 }
40875
40876@@ -852,7 +852,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
40877 * and sleep if necessary
40878 */
40879 port->openclose = true;
40880- port->port.count = 0;
40881+ atomic_set(&port->port.count, 0);
40882
40883 gser = port->port_usb;
40884 if (gser && gser->disconnect)
40885@@ -1157,7 +1157,7 @@ static int gs_closed(struct gs_port *port)
40886 int cond;
40887
40888 spin_lock_irq(&port->port_lock);
40889- cond = (port->port.count == 0) && !port->openclose;
40890+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
40891 spin_unlock_irq(&port->port_lock);
40892 return cond;
40893 }
40894@@ -1270,7 +1270,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
40895 /* if it's already open, start I/O ... and notify the serial
40896 * protocol about open/close status (connect/disconnect).
40897 */
40898- if (port->port.count) {
40899+ if (atomic_read(&port->port.count)) {
40900 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
40901 gs_start_io(port);
40902 if (gser->connect)
40903@@ -1317,7 +1317,7 @@ void gserial_disconnect(struct gserial *gser)
40904
40905 port->port_usb = NULL;
40906 gser->ioport = NULL;
40907- if (port->port.count > 0 || port->openclose) {
40908+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
40909 wake_up_interruptible(&port->drain_wait);
40910 if (port->port.tty)
40911 tty_hangup(port->port.tty);
40912@@ -1333,7 +1333,7 @@ void gserial_disconnect(struct gserial *gser)
40913
40914 /* finally, free any unused/unusable I/O buffers */
40915 spin_lock_irqsave(&port->port_lock, flags);
40916- if (port->port.count == 0 && !port->openclose)
40917+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
40918 gs_buf_free(&port->port_write_buf);
40919 gs_free_requests(gser->out, &port->read_pool, NULL);
40920 gs_free_requests(gser->out, &port->read_queue, NULL);
40921diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
40922index 5f3bcd3..bfca43f 100644
40923--- a/drivers/usb/serial/console.c
40924+++ b/drivers/usb/serial/console.c
40925@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
40926
40927 info->port = port;
40928
40929- ++port->port.count;
40930+ atomic_inc(&port->port.count);
40931 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
40932 if (serial->type->set_termios) {
40933 /*
40934@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
40935 }
40936 /* Now that any required fake tty operations are completed restore
40937 * the tty port count */
40938- --port->port.count;
40939+ atomic_dec(&port->port.count);
40940 /* The console is special in terms of closing the device so
40941 * indicate this port is now acting as a system console. */
40942 port->port.console = 1;
40943@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
40944 free_tty:
40945 kfree(tty);
40946 reset_open_count:
40947- port->port.count = 0;
40948+ atomic_set(&port->port.count, 0);
40949 usb_autopm_put_interface(serial->interface);
40950 error_get_interface:
40951 usb_serial_put(serial);
40952diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
40953index d6bea3e..60b250e 100644
40954--- a/drivers/usb/wusbcore/wa-hc.h
40955+++ b/drivers/usb/wusbcore/wa-hc.h
40956@@ -192,7 +192,7 @@ struct wahc {
40957 struct list_head xfer_delayed_list;
40958 spinlock_t xfer_list_lock;
40959 struct work_struct xfer_work;
40960- atomic_t xfer_id_count;
40961+ atomic_unchecked_t xfer_id_count;
40962 };
40963
40964
40965@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
40966 INIT_LIST_HEAD(&wa->xfer_delayed_list);
40967 spin_lock_init(&wa->xfer_list_lock);
40968 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
40969- atomic_set(&wa->xfer_id_count, 1);
40970+ atomic_set_unchecked(&wa->xfer_id_count, 1);
40971 }
40972
40973 /**
40974diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
40975index 57c01ab..8a05959 100644
40976--- a/drivers/usb/wusbcore/wa-xfer.c
40977+++ b/drivers/usb/wusbcore/wa-xfer.c
40978@@ -296,7 +296,7 @@ out:
40979 */
40980 static void wa_xfer_id_init(struct wa_xfer *xfer)
40981 {
40982- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
40983+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
40984 }
40985
40986 /*
40987diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
40988index dedaf81..b0f11ab 100644
40989--- a/drivers/vhost/vhost.c
40990+++ b/drivers/vhost/vhost.c
40991@@ -634,7 +634,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
40992 return 0;
40993 }
40994
40995-static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
40996+static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
40997 {
40998 struct file *eventfp, *filep = NULL;
40999 bool pollstart = false, pollstop = false;
41000diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
41001index 0fefa84..7a9d581 100644
41002--- a/drivers/video/aty/aty128fb.c
41003+++ b/drivers/video/aty/aty128fb.c
41004@@ -149,7 +149,7 @@ enum {
41005 };
41006
41007 /* Must match above enum */
41008-static char * const r128_family[] __devinitconst = {
41009+static const char * const r128_family[] __devinitconst = {
41010 "AGP",
41011 "PCI",
41012 "PRO AGP",
41013diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
41014index 5c3960d..15cf8fc 100644
41015--- a/drivers/video/fbcmap.c
41016+++ b/drivers/video/fbcmap.c
41017@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
41018 rc = -ENODEV;
41019 goto out;
41020 }
41021- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
41022- !info->fbops->fb_setcmap)) {
41023+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
41024 rc = -EINVAL;
41025 goto out1;
41026 }
41027diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
41028index 3ff0105..7589d98 100644
41029--- a/drivers/video/fbmem.c
41030+++ b/drivers/video/fbmem.c
41031@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41032 image->dx += image->width + 8;
41033 }
41034 } else if (rotate == FB_ROTATE_UD) {
41035- for (x = 0; x < num && image->dx >= 0; x++) {
41036+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
41037 info->fbops->fb_imageblit(info, image);
41038 image->dx -= image->width + 8;
41039 }
41040@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
41041 image->dy += image->height + 8;
41042 }
41043 } else if (rotate == FB_ROTATE_CCW) {
41044- for (x = 0; x < num && image->dy >= 0; x++) {
41045+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
41046 info->fbops->fb_imageblit(info, image);
41047 image->dy -= image->height + 8;
41048 }
41049@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
41050 return -EFAULT;
41051 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
41052 return -EINVAL;
41053- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
41054+ if (con2fb.framebuffer >= FB_MAX)
41055 return -EINVAL;
41056 if (!registered_fb[con2fb.framebuffer])
41057 request_module("fb%d", con2fb.framebuffer);
41058diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
41059index 7672d2e..b56437f 100644
41060--- a/drivers/video/i810/i810_accel.c
41061+++ b/drivers/video/i810/i810_accel.c
41062@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
41063 }
41064 }
41065 printk("ringbuffer lockup!!!\n");
41066+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
41067 i810_report_error(mmio);
41068 par->dev_flags |= LOCKUP;
41069 info->pixmap.scan_align = 1;
41070diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
41071index 3c14e43..eafa544 100644
41072--- a/drivers/video/logo/logo_linux_clut224.ppm
41073+++ b/drivers/video/logo/logo_linux_clut224.ppm
41074@@ -1,1604 +1,1123 @@
41075 P3
41076-# Standard 224-color Linux logo
41077 80 80
41078 255
41079- 0 0 0 0 0 0 0 0 0 0 0 0
41080- 0 0 0 0 0 0 0 0 0 0 0 0
41081- 0 0 0 0 0 0 0 0 0 0 0 0
41082- 0 0 0 0 0 0 0 0 0 0 0 0
41083- 0 0 0 0 0 0 0 0 0 0 0 0
41084- 0 0 0 0 0 0 0 0 0 0 0 0
41085- 0 0 0 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- 6 6 6 6 6 6 10 10 10 10 10 10
41089- 10 10 10 6 6 6 6 6 6 6 6 6
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 0 0 0 0 0 0 0 0 0 0
41094- 0 0 0 0 0 0 0 0 0 0 0 0
41095- 0 0 0 0 0 0 0 0 0 0 0 0
41096- 0 0 0 0 0 0 0 0 0 0 0 0
41097- 0 0 0 0 0 0 0 0 0 0 0 0
41098- 0 0 0 0 0 0 0 0 0 0 0 0
41099- 0 0 0 0 0 0 0 0 0 0 0 0
41100- 0 0 0 0 0 0 0 0 0 0 0 0
41101- 0 0 0 0 0 0 0 0 0 0 0 0
41102- 0 0 0 0 0 0 0 0 0 0 0 0
41103- 0 0 0 0 0 0 0 0 0 0 0 0
41104- 0 0 0 0 0 0 0 0 0 0 0 0
41105- 0 0 0 0 0 0 0 0 0 0 0 0
41106- 0 0 0 0 0 0 0 0 0 0 0 0
41107- 0 0 0 6 6 6 10 10 10 14 14 14
41108- 22 22 22 26 26 26 30 30 30 34 34 34
41109- 30 30 30 30 30 30 26 26 26 18 18 18
41110- 14 14 14 10 10 10 6 6 6 0 0 0
41111- 0 0 0 0 0 0 0 0 0 0 0 0
41112- 0 0 0 0 0 0 0 0 0 0 0 0
41113- 0 0 0 0 0 0 0 0 0 0 0 0
41114- 0 0 0 0 0 0 0 0 0 0 0 0
41115- 0 0 0 0 0 0 0 0 0 0 0 0
41116- 0 0 0 0 0 0 0 0 0 0 0 0
41117- 0 0 0 0 0 0 0 0 0 0 0 0
41118- 0 0 0 0 0 0 0 0 0 0 0 0
41119- 0 0 0 0 0 0 0 0 0 0 0 0
41120- 0 0 0 0 0 1 0 0 1 0 0 0
41121- 0 0 0 0 0 0 0 0 0 0 0 0
41122- 0 0 0 0 0 0 0 0 0 0 0 0
41123- 0 0 0 0 0 0 0 0 0 0 0 0
41124- 0 0 0 0 0 0 0 0 0 0 0 0
41125- 0 0 0 0 0 0 0 0 0 0 0 0
41126- 0 0 0 0 0 0 0 0 0 0 0 0
41127- 6 6 6 14 14 14 26 26 26 42 42 42
41128- 54 54 54 66 66 66 78 78 78 78 78 78
41129- 78 78 78 74 74 74 66 66 66 54 54 54
41130- 42 42 42 26 26 26 18 18 18 10 10 10
41131- 6 6 6 0 0 0 0 0 0 0 0 0
41132- 0 0 0 0 0 0 0 0 0 0 0 0
41133- 0 0 0 0 0 0 0 0 0 0 0 0
41134- 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
41140- 0 0 1 0 0 0 0 0 0 0 0 0
41141- 0 0 0 0 0 0 0 0 0 0 0 0
41142- 0 0 0 0 0 0 0 0 0 0 0 0
41143- 0 0 0 0 0 0 0 0 0 0 0 0
41144- 0 0 0 0 0 0 0 0 0 0 0 0
41145- 0 0 0 0 0 0 0 0 0 0 0 0
41146- 0 0 0 0 0 0 0 0 0 10 10 10
41147- 22 22 22 42 42 42 66 66 66 86 86 86
41148- 66 66 66 38 38 38 38 38 38 22 22 22
41149- 26 26 26 34 34 34 54 54 54 66 66 66
41150- 86 86 86 70 70 70 46 46 46 26 26 26
41151- 14 14 14 6 6 6 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 0 0 0
41159- 0 0 0 0 0 0 0 0 0 0 0 0
41160- 0 0 1 0 0 1 0 0 1 0 0 0
41161- 0 0 0 0 0 0 0 0 0 0 0 0
41162- 0 0 0 0 0 0 0 0 0 0 0 0
41163- 0 0 0 0 0 0 0 0 0 0 0 0
41164- 0 0 0 0 0 0 0 0 0 0 0 0
41165- 0 0 0 0 0 0 0 0 0 0 0 0
41166- 0 0 0 0 0 0 10 10 10 26 26 26
41167- 50 50 50 82 82 82 58 58 58 6 6 6
41168- 2 2 6 2 2 6 2 2 6 2 2 6
41169- 2 2 6 2 2 6 2 2 6 2 2 6
41170- 6 6 6 54 54 54 86 86 86 66 66 66
41171- 38 38 38 18 18 18 6 6 6 0 0 0
41172- 0 0 0 0 0 0 0 0 0 0 0 0
41173- 0 0 0 0 0 0 0 0 0 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 0 0 0
41179- 0 0 0 0 0 0 0 0 0 0 0 0
41180- 0 0 0 0 0 0 0 0 0 0 0 0
41181- 0 0 0 0 0 0 0 0 0 0 0 0
41182- 0 0 0 0 0 0 0 0 0 0 0 0
41183- 0 0 0 0 0 0 0 0 0 0 0 0
41184- 0 0 0 0 0 0 0 0 0 0 0 0
41185- 0 0 0 0 0 0 0 0 0 0 0 0
41186- 0 0 0 6 6 6 22 22 22 50 50 50
41187- 78 78 78 34 34 34 2 2 6 2 2 6
41188- 2 2 6 2 2 6 2 2 6 2 2 6
41189- 2 2 6 2 2 6 2 2 6 2 2 6
41190- 2 2 6 2 2 6 6 6 6 70 70 70
41191- 78 78 78 46 46 46 22 22 22 6 6 6
41192- 0 0 0 0 0 0 0 0 0 0 0 0
41193- 0 0 0 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 0 0 0
41199- 0 0 0 0 0 0 0 0 0 0 0 0
41200- 0 0 1 0 0 1 0 0 1 0 0 0
41201- 0 0 0 0 0 0 0 0 0 0 0 0
41202- 0 0 0 0 0 0 0 0 0 0 0 0
41203- 0 0 0 0 0 0 0 0 0 0 0 0
41204- 0 0 0 0 0 0 0 0 0 0 0 0
41205- 0 0 0 0 0 0 0 0 0 0 0 0
41206- 6 6 6 18 18 18 42 42 42 82 82 82
41207- 26 26 26 2 2 6 2 2 6 2 2 6
41208- 2 2 6 2 2 6 2 2 6 2 2 6
41209- 2 2 6 2 2 6 2 2 6 14 14 14
41210- 46 46 46 34 34 34 6 6 6 2 2 6
41211- 42 42 42 78 78 78 42 42 42 18 18 18
41212- 6 6 6 0 0 0 0 0 0 0 0 0
41213- 0 0 0 0 0 0 0 0 0 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 0 0 0
41219- 0 0 0 0 0 0 0 0 0 0 0 0
41220- 0 0 1 0 0 0 0 0 1 0 0 0
41221- 0 0 0 0 0 0 0 0 0 0 0 0
41222- 0 0 0 0 0 0 0 0 0 0 0 0
41223- 0 0 0 0 0 0 0 0 0 0 0 0
41224- 0 0 0 0 0 0 0 0 0 0 0 0
41225- 0 0 0 0 0 0 0 0 0 0 0 0
41226- 10 10 10 30 30 30 66 66 66 58 58 58
41227- 2 2 6 2 2 6 2 2 6 2 2 6
41228- 2 2 6 2 2 6 2 2 6 2 2 6
41229- 2 2 6 2 2 6 2 2 6 26 26 26
41230- 86 86 86 101 101 101 46 46 46 10 10 10
41231- 2 2 6 58 58 58 70 70 70 34 34 34
41232- 10 10 10 0 0 0 0 0 0 0 0 0
41233- 0 0 0 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 0 0 0
41239- 0 0 0 0 0 0 0 0 0 0 0 0
41240- 0 0 1 0 0 1 0 0 1 0 0 0
41241- 0 0 0 0 0 0 0 0 0 0 0 0
41242- 0 0 0 0 0 0 0 0 0 0 0 0
41243- 0 0 0 0 0 0 0 0 0 0 0 0
41244- 0 0 0 0 0 0 0 0 0 0 0 0
41245- 0 0 0 0 0 0 0 0 0 0 0 0
41246- 14 14 14 42 42 42 86 86 86 10 10 10
41247- 2 2 6 2 2 6 2 2 6 2 2 6
41248- 2 2 6 2 2 6 2 2 6 2 2 6
41249- 2 2 6 2 2 6 2 2 6 30 30 30
41250- 94 94 94 94 94 94 58 58 58 26 26 26
41251- 2 2 6 6 6 6 78 78 78 54 54 54
41252- 22 22 22 6 6 6 0 0 0 0 0 0
41253- 0 0 0 0 0 0 0 0 0 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 0 0 0
41259- 0 0 0 0 0 0 0 0 0 0 0 0
41260- 0 0 0 0 0 0 0 0 0 0 0 0
41261- 0 0 0 0 0 0 0 0 0 0 0 0
41262- 0 0 0 0 0 0 0 0 0 0 0 0
41263- 0 0 0 0 0 0 0 0 0 0 0 0
41264- 0 0 0 0 0 0 0 0 0 0 0 0
41265- 0 0 0 0 0 0 0 0 0 6 6 6
41266- 22 22 22 62 62 62 62 62 62 2 2 6
41267- 2 2 6 2 2 6 2 2 6 2 2 6
41268- 2 2 6 2 2 6 2 2 6 2 2 6
41269- 2 2 6 2 2 6 2 2 6 26 26 26
41270- 54 54 54 38 38 38 18 18 18 10 10 10
41271- 2 2 6 2 2 6 34 34 34 82 82 82
41272- 38 38 38 14 14 14 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 0 0 0
41279- 0 0 0 0 0 0 0 0 0 0 0 0
41280- 0 0 0 0 0 1 0 0 1 0 0 0
41281- 0 0 0 0 0 0 0 0 0 0 0 0
41282- 0 0 0 0 0 0 0 0 0 0 0 0
41283- 0 0 0 0 0 0 0 0 0 0 0 0
41284- 0 0 0 0 0 0 0 0 0 0 0 0
41285- 0 0 0 0 0 0 0 0 0 6 6 6
41286- 30 30 30 78 78 78 30 30 30 2 2 6
41287- 2 2 6 2 2 6 2 2 6 2 2 6
41288- 2 2 6 2 2 6 2 2 6 2 2 6
41289- 2 2 6 2 2 6 2 2 6 10 10 10
41290- 10 10 10 2 2 6 2 2 6 2 2 6
41291- 2 2 6 2 2 6 2 2 6 78 78 78
41292- 50 50 50 18 18 18 6 6 6 0 0 0
41293- 0 0 0 0 0 0 0 0 0 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 0 0 0
41299- 0 0 0 0 0 0 0 0 0 0 0 0
41300- 0 0 1 0 0 0 0 0 0 0 0 0
41301- 0 0 0 0 0 0 0 0 0 0 0 0
41302- 0 0 0 0 0 0 0 0 0 0 0 0
41303- 0 0 0 0 0 0 0 0 0 0 0 0
41304- 0 0 0 0 0 0 0 0 0 0 0 0
41305- 0 0 0 0 0 0 0 0 0 10 10 10
41306- 38 38 38 86 86 86 14 14 14 2 2 6
41307- 2 2 6 2 2 6 2 2 6 2 2 6
41308- 2 2 6 2 2 6 2 2 6 2 2 6
41309- 2 2 6 2 2 6 2 2 6 2 2 6
41310- 2 2 6 2 2 6 2 2 6 2 2 6
41311- 2 2 6 2 2 6 2 2 6 54 54 54
41312- 66 66 66 26 26 26 6 6 6 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 0 0 0
41319- 0 0 0 0 0 0 0 0 0 0 0 0
41320- 0 0 0 0 0 1 0 0 1 0 0 0
41321- 0 0 0 0 0 0 0 0 0 0 0 0
41322- 0 0 0 0 0 0 0 0 0 0 0 0
41323- 0 0 0 0 0 0 0 0 0 0 0 0
41324- 0 0 0 0 0 0 0 0 0 0 0 0
41325- 0 0 0 0 0 0 0 0 0 14 14 14
41326- 42 42 42 82 82 82 2 2 6 2 2 6
41327- 2 2 6 6 6 6 10 10 10 2 2 6
41328- 2 2 6 2 2 6 2 2 6 2 2 6
41329- 2 2 6 2 2 6 2 2 6 6 6 6
41330- 14 14 14 10 10 10 2 2 6 2 2 6
41331- 2 2 6 2 2 6 2 2 6 18 18 18
41332- 82 82 82 34 34 34 10 10 10 0 0 0
41333- 0 0 0 0 0 0 0 0 0 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 0 0 0
41339- 0 0 0 0 0 0 0 0 0 0 0 0
41340- 0 0 1 0 0 0 0 0 0 0 0 0
41341- 0 0 0 0 0 0 0 0 0 0 0 0
41342- 0 0 0 0 0 0 0 0 0 0 0 0
41343- 0 0 0 0 0 0 0 0 0 0 0 0
41344- 0 0 0 0 0 0 0 0 0 0 0 0
41345- 0 0 0 0 0 0 0 0 0 14 14 14
41346- 46 46 46 86 86 86 2 2 6 2 2 6
41347- 6 6 6 6 6 6 22 22 22 34 34 34
41348- 6 6 6 2 2 6 2 2 6 2 2 6
41349- 2 2 6 2 2 6 18 18 18 34 34 34
41350- 10 10 10 50 50 50 22 22 22 2 2 6
41351- 2 2 6 2 2 6 2 2 6 10 10 10
41352- 86 86 86 42 42 42 14 14 14 0 0 0
41353- 0 0 0 0 0 0 0 0 0 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 0 0 0
41359- 0 0 0 0 0 0 0 0 0 0 0 0
41360- 0 0 1 0 0 1 0 0 1 0 0 0
41361- 0 0 0 0 0 0 0 0 0 0 0 0
41362- 0 0 0 0 0 0 0 0 0 0 0 0
41363- 0 0 0 0 0 0 0 0 0 0 0 0
41364- 0 0 0 0 0 0 0 0 0 0 0 0
41365- 0 0 0 0 0 0 0 0 0 14 14 14
41366- 46 46 46 86 86 86 2 2 6 2 2 6
41367- 38 38 38 116 116 116 94 94 94 22 22 22
41368- 22 22 22 2 2 6 2 2 6 2 2 6
41369- 14 14 14 86 86 86 138 138 138 162 162 162
41370-154 154 154 38 38 38 26 26 26 6 6 6
41371- 2 2 6 2 2 6 2 2 6 2 2 6
41372- 86 86 86 46 46 46 14 14 14 0 0 0
41373- 0 0 0 0 0 0 0 0 0 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 0 0 0
41379- 0 0 0 0 0 0 0 0 0 0 0 0
41380- 0 0 0 0 0 0 0 0 0 0 0 0
41381- 0 0 0 0 0 0 0 0 0 0 0 0
41382- 0 0 0 0 0 0 0 0 0 0 0 0
41383- 0 0 0 0 0 0 0 0 0 0 0 0
41384- 0 0 0 0 0 0 0 0 0 0 0 0
41385- 0 0 0 0 0 0 0 0 0 14 14 14
41386- 46 46 46 86 86 86 2 2 6 14 14 14
41387-134 134 134 198 198 198 195 195 195 116 116 116
41388- 10 10 10 2 2 6 2 2 6 6 6 6
41389-101 98 89 187 187 187 210 210 210 218 218 218
41390-214 214 214 134 134 134 14 14 14 6 6 6
41391- 2 2 6 2 2 6 2 2 6 2 2 6
41392- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0
41399- 0 0 0 0 0 0 0 0 1 0 0 0
41400- 0 0 1 0 0 1 0 0 1 0 0 0
41401- 0 0 0 0 0 0 0 0 0 0 0 0
41402- 0 0 0 0 0 0 0 0 0 0 0 0
41403- 0 0 0 0 0 0 0 0 0 0 0 0
41404- 0 0 0 0 0 0 0 0 0 0 0 0
41405- 0 0 0 0 0 0 0 0 0 14 14 14
41406- 46 46 46 86 86 86 2 2 6 54 54 54
41407-218 218 218 195 195 195 226 226 226 246 246 246
41408- 58 58 58 2 2 6 2 2 6 30 30 30
41409-210 210 210 253 253 253 174 174 174 123 123 123
41410-221 221 221 234 234 234 74 74 74 2 2 6
41411- 2 2 6 2 2 6 2 2 6 2 2 6
41412- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
41419- 0 0 0 0 0 0 0 0 0 0 0 0
41420- 0 0 0 0 0 0 0 0 0 0 0 0
41421- 0 0 0 0 0 0 0 0 0 0 0 0
41422- 0 0 0 0 0 0 0 0 0 0 0 0
41423- 0 0 0 0 0 0 0 0 0 0 0 0
41424- 0 0 0 0 0 0 0 0 0 0 0 0
41425- 0 0 0 0 0 0 0 0 0 14 14 14
41426- 46 46 46 82 82 82 2 2 6 106 106 106
41427-170 170 170 26 26 26 86 86 86 226 226 226
41428-123 123 123 10 10 10 14 14 14 46 46 46
41429-231 231 231 190 190 190 6 6 6 70 70 70
41430- 90 90 90 238 238 238 158 158 158 2 2 6
41431- 2 2 6 2 2 6 2 2 6 2 2 6
41432- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0
41439- 0 0 0 0 0 0 0 0 1 0 0 0
41440- 0 0 1 0 0 1 0 0 1 0 0 0
41441- 0 0 0 0 0 0 0 0 0 0 0 0
41442- 0 0 0 0 0 0 0 0 0 0 0 0
41443- 0 0 0 0 0 0 0 0 0 0 0 0
41444- 0 0 0 0 0 0 0 0 0 0 0 0
41445- 0 0 0 0 0 0 0 0 0 14 14 14
41446- 42 42 42 86 86 86 6 6 6 116 116 116
41447-106 106 106 6 6 6 70 70 70 149 149 149
41448-128 128 128 18 18 18 38 38 38 54 54 54
41449-221 221 221 106 106 106 2 2 6 14 14 14
41450- 46 46 46 190 190 190 198 198 198 2 2 6
41451- 2 2 6 2 2 6 2 2 6 2 2 6
41452- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
41459- 0 0 0 0 0 0 0 0 1 0 0 0
41460- 0 0 1 0 0 0 0 0 1 0 0 0
41461- 0 0 0 0 0 0 0 0 0 0 0 0
41462- 0 0 0 0 0 0 0 0 0 0 0 0
41463- 0 0 0 0 0 0 0 0 0 0 0 0
41464- 0 0 0 0 0 0 0 0 0 0 0 0
41465- 0 0 0 0 0 0 0 0 0 14 14 14
41466- 42 42 42 94 94 94 14 14 14 101 101 101
41467-128 128 128 2 2 6 18 18 18 116 116 116
41468-118 98 46 121 92 8 121 92 8 98 78 10
41469-162 162 162 106 106 106 2 2 6 2 2 6
41470- 2 2 6 195 195 195 195 195 195 6 6 6
41471- 2 2 6 2 2 6 2 2 6 2 2 6
41472- 74 74 74 62 62 62 22 22 22 6 6 6
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 0 0 0
41479- 0 0 0 0 0 0 0 0 1 0 0 1
41480- 0 0 1 0 0 0 0 0 1 0 0 0
41481- 0 0 0 0 0 0 0 0 0 0 0 0
41482- 0 0 0 0 0 0 0 0 0 0 0 0
41483- 0 0 0 0 0 0 0 0 0 0 0 0
41484- 0 0 0 0 0 0 0 0 0 0 0 0
41485- 0 0 0 0 0 0 0 0 0 10 10 10
41486- 38 38 38 90 90 90 14 14 14 58 58 58
41487-210 210 210 26 26 26 54 38 6 154 114 10
41488-226 170 11 236 186 11 225 175 15 184 144 12
41489-215 174 15 175 146 61 37 26 9 2 2 6
41490- 70 70 70 246 246 246 138 138 138 2 2 6
41491- 2 2 6 2 2 6 2 2 6 2 2 6
41492- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
41499- 0 0 0 0 0 0 0 0 0 0 0 0
41500- 0 0 0 0 0 0 0 0 0 0 0 0
41501- 0 0 0 0 0 0 0 0 0 0 0 0
41502- 0 0 0 0 0 0 0 0 0 0 0 0
41503- 0 0 0 0 0 0 0 0 0 0 0 0
41504- 0 0 0 0 0 0 0 0 0 0 0 0
41505- 0 0 0 0 0 0 0 0 0 10 10 10
41506- 38 38 38 86 86 86 14 14 14 10 10 10
41507-195 195 195 188 164 115 192 133 9 225 175 15
41508-239 182 13 234 190 10 232 195 16 232 200 30
41509-245 207 45 241 208 19 232 195 16 184 144 12
41510-218 194 134 211 206 186 42 42 42 2 2 6
41511- 2 2 6 2 2 6 2 2 6 2 2 6
41512- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
41519- 0 0 0 0 0 0 0 0 0 0 0 0
41520- 0 0 0 0 0 0 0 0 0 0 0 0
41521- 0 0 0 0 0 0 0 0 0 0 0 0
41522- 0 0 0 0 0 0 0 0 0 0 0 0
41523- 0 0 0 0 0 0 0 0 0 0 0 0
41524- 0 0 0 0 0 0 0 0 0 0 0 0
41525- 0 0 0 0 0 0 0 0 0 10 10 10
41526- 34 34 34 86 86 86 14 14 14 2 2 6
41527-121 87 25 192 133 9 219 162 10 239 182 13
41528-236 186 11 232 195 16 241 208 19 244 214 54
41529-246 218 60 246 218 38 246 215 20 241 208 19
41530-241 208 19 226 184 13 121 87 25 2 2 6
41531- 2 2 6 2 2 6 2 2 6 2 2 6
41532- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0 0 0 0
41539- 0 0 0 0 0 0 0 0 0 0 0 0
41540- 0 0 0 0 0 0 0 0 0 0 0 0
41541- 0 0 0 0 0 0 0 0 0 0 0 0
41542- 0 0 0 0 0 0 0 0 0 0 0 0
41543- 0 0 0 0 0 0 0 0 0 0 0 0
41544- 0 0 0 0 0 0 0 0 0 0 0 0
41545- 0 0 0 0 0 0 0 0 0 10 10 10
41546- 34 34 34 82 82 82 30 30 30 61 42 6
41547-180 123 7 206 145 10 230 174 11 239 182 13
41548-234 190 10 238 202 15 241 208 19 246 218 74
41549-246 218 38 246 215 20 246 215 20 246 215 20
41550-226 184 13 215 174 15 184 144 12 6 6 6
41551- 2 2 6 2 2 6 2 2 6 2 2 6
41552- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0
41559- 0 0 0 0 0 0 0 0 0 0 0 0
41560- 0 0 0 0 0 0 0 0 0 0 0 0
41561- 0 0 0 0 0 0 0 0 0 0 0 0
41562- 0 0 0 0 0 0 0 0 0 0 0 0
41563- 0 0 0 0 0 0 0 0 0 0 0 0
41564- 0 0 0 0 0 0 0 0 0 0 0 0
41565- 0 0 0 0 0 0 0 0 0 10 10 10
41566- 30 30 30 78 78 78 50 50 50 104 69 6
41567-192 133 9 216 158 10 236 178 12 236 186 11
41568-232 195 16 241 208 19 244 214 54 245 215 43
41569-246 215 20 246 215 20 241 208 19 198 155 10
41570-200 144 11 216 158 10 156 118 10 2 2 6
41571- 2 2 6 2 2 6 2 2 6 2 2 6
41572- 6 6 6 90 90 90 54 54 54 18 18 18
41573- 6 6 6 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 0 0 0 0 0 0 0 0 0
41579- 0 0 0 0 0 0 0 0 0 0 0 0
41580- 0 0 0 0 0 0 0 0 0 0 0 0
41581- 0 0 0 0 0 0 0 0 0 0 0 0
41582- 0 0 0 0 0 0 0 0 0 0 0 0
41583- 0 0 0 0 0 0 0 0 0 0 0 0
41584- 0 0 0 0 0 0 0 0 0 0 0 0
41585- 0 0 0 0 0 0 0 0 0 10 10 10
41586- 30 30 30 78 78 78 46 46 46 22 22 22
41587-137 92 6 210 162 10 239 182 13 238 190 10
41588-238 202 15 241 208 19 246 215 20 246 215 20
41589-241 208 19 203 166 17 185 133 11 210 150 10
41590-216 158 10 210 150 10 102 78 10 2 2 6
41591- 6 6 6 54 54 54 14 14 14 2 2 6
41592- 2 2 6 62 62 62 74 74 74 30 30 30
41593- 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
41599- 0 0 0 0 0 0 0 0 0 0 0 0
41600- 0 0 0 0 0 0 0 0 0 0 0 0
41601- 0 0 0 0 0 0 0 0 0 0 0 0
41602- 0 0 0 0 0 0 0 0 0 0 0 0
41603- 0 0 0 0 0 0 0 0 0 0 0 0
41604- 0 0 0 0 0 0 0 0 0 0 0 0
41605- 0 0 0 0 0 0 0 0 0 10 10 10
41606- 34 34 34 78 78 78 50 50 50 6 6 6
41607- 94 70 30 139 102 15 190 146 13 226 184 13
41608-232 200 30 232 195 16 215 174 15 190 146 13
41609-168 122 10 192 133 9 210 150 10 213 154 11
41610-202 150 34 182 157 106 101 98 89 2 2 6
41611- 2 2 6 78 78 78 116 116 116 58 58 58
41612- 2 2 6 22 22 22 90 90 90 46 46 46
41613- 18 18 18 6 6 6 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 0 0 0
41618- 0 0 0 0 0 0 0 0 0 0 0 0
41619- 0 0 0 0 0 0 0 0 0 0 0 0
41620- 0 0 0 0 0 0 0 0 0 0 0 0
41621- 0 0 0 0 0 0 0 0 0 0 0 0
41622- 0 0 0 0 0 0 0 0 0 0 0 0
41623- 0 0 0 0 0 0 0 0 0 0 0 0
41624- 0 0 0 0 0 0 0 0 0 0 0 0
41625- 0 0 0 0 0 0 0 0 0 10 10 10
41626- 38 38 38 86 86 86 50 50 50 6 6 6
41627-128 128 128 174 154 114 156 107 11 168 122 10
41628-198 155 10 184 144 12 197 138 11 200 144 11
41629-206 145 10 206 145 10 197 138 11 188 164 115
41630-195 195 195 198 198 198 174 174 174 14 14 14
41631- 2 2 6 22 22 22 116 116 116 116 116 116
41632- 22 22 22 2 2 6 74 74 74 70 70 70
41633- 30 30 30 10 10 10 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 0 0 0
41638- 0 0 0 0 0 0 0 0 0 0 0 0
41639- 0 0 0 0 0 0 0 0 0 0 0 0
41640- 0 0 0 0 0 0 0 0 0 0 0 0
41641- 0 0 0 0 0 0 0 0 0 0 0 0
41642- 0 0 0 0 0 0 0 0 0 0 0 0
41643- 0 0 0 0 0 0 0 0 0 0 0 0
41644- 0 0 0 0 0 0 0 0 0 0 0 0
41645- 0 0 0 0 0 0 6 6 6 18 18 18
41646- 50 50 50 101 101 101 26 26 26 10 10 10
41647-138 138 138 190 190 190 174 154 114 156 107 11
41648-197 138 11 200 144 11 197 138 11 192 133 9
41649-180 123 7 190 142 34 190 178 144 187 187 187
41650-202 202 202 221 221 221 214 214 214 66 66 66
41651- 2 2 6 2 2 6 50 50 50 62 62 62
41652- 6 6 6 2 2 6 10 10 10 90 90 90
41653- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0
41658- 0 0 0 0 0 0 0 0 0 0 0 0
41659- 0 0 0 0 0 0 0 0 0 0 0 0
41660- 0 0 0 0 0 0 0 0 0 0 0 0
41661- 0 0 0 0 0 0 0 0 0 0 0 0
41662- 0 0 0 0 0 0 0 0 0 0 0 0
41663- 0 0 0 0 0 0 0 0 0 0 0 0
41664- 0 0 0 0 0 0 0 0 0 0 0 0
41665- 0 0 0 0 0 0 10 10 10 34 34 34
41666- 74 74 74 74 74 74 2 2 6 6 6 6
41667-144 144 144 198 198 198 190 190 190 178 166 146
41668-154 121 60 156 107 11 156 107 11 168 124 44
41669-174 154 114 187 187 187 190 190 190 210 210 210
41670-246 246 246 253 253 253 253 253 253 182 182 182
41671- 6 6 6 2 2 6 2 2 6 2 2 6
41672- 2 2 6 2 2 6 2 2 6 62 62 62
41673- 74 74 74 34 34 34 14 14 14 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 0 0 0 0 0 0 0 0 0
41678- 0 0 0 0 0 0 0 0 0 0 0 0
41679- 0 0 0 0 0 0 0 0 0 0 0 0
41680- 0 0 0 0 0 0 0 0 0 0 0 0
41681- 0 0 0 0 0 0 0 0 0 0 0 0
41682- 0 0 0 0 0 0 0 0 0 0 0 0
41683- 0 0 0 0 0 0 0 0 0 0 0 0
41684- 0 0 0 0 0 0 0 0 0 0 0 0
41685- 0 0 0 10 10 10 22 22 22 54 54 54
41686- 94 94 94 18 18 18 2 2 6 46 46 46
41687-234 234 234 221 221 221 190 190 190 190 190 190
41688-190 190 190 187 187 187 187 187 187 190 190 190
41689-190 190 190 195 195 195 214 214 214 242 242 242
41690-253 253 253 253 253 253 253 253 253 253 253 253
41691- 82 82 82 2 2 6 2 2 6 2 2 6
41692- 2 2 6 2 2 6 2 2 6 14 14 14
41693- 86 86 86 54 54 54 22 22 22 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
41698- 0 0 0 0 0 0 0 0 0 0 0 0
41699- 0 0 0 0 0 0 0 0 0 0 0 0
41700- 0 0 0 0 0 0 0 0 0 0 0 0
41701- 0 0 0 0 0 0 0 0 0 0 0 0
41702- 0 0 0 0 0 0 0 0 0 0 0 0
41703- 0 0 0 0 0 0 0 0 0 0 0 0
41704- 0 0 0 0 0 0 0 0 0 0 0 0
41705- 6 6 6 18 18 18 46 46 46 90 90 90
41706- 46 46 46 18 18 18 6 6 6 182 182 182
41707-253 253 253 246 246 246 206 206 206 190 190 190
41708-190 190 190 190 190 190 190 190 190 190 190 190
41709-206 206 206 231 231 231 250 250 250 253 253 253
41710-253 253 253 253 253 253 253 253 253 253 253 253
41711-202 202 202 14 14 14 2 2 6 2 2 6
41712- 2 2 6 2 2 6 2 2 6 2 2 6
41713- 42 42 42 86 86 86 42 42 42 18 18 18
41714- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
41718- 0 0 0 0 0 0 0 0 0 0 0 0
41719- 0 0 0 0 0 0 0 0 0 0 0 0
41720- 0 0 0 0 0 0 0 0 0 0 0 0
41721- 0 0 0 0 0 0 0 0 0 0 0 0
41722- 0 0 0 0 0 0 0 0 0 0 0 0
41723- 0 0 0 0 0 0 0 0 0 0 0 0
41724- 0 0 0 0 0 0 0 0 0 6 6 6
41725- 14 14 14 38 38 38 74 74 74 66 66 66
41726- 2 2 6 6 6 6 90 90 90 250 250 250
41727-253 253 253 253 253 253 238 238 238 198 198 198
41728-190 190 190 190 190 190 195 195 195 221 221 221
41729-246 246 246 253 253 253 253 253 253 253 253 253
41730-253 253 253 253 253 253 253 253 253 253 253 253
41731-253 253 253 82 82 82 2 2 6 2 2 6
41732- 2 2 6 2 2 6 2 2 6 2 2 6
41733- 2 2 6 78 78 78 70 70 70 34 34 34
41734- 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
41738- 0 0 0 0 0 0 0 0 0 0 0 0
41739- 0 0 0 0 0 0 0 0 0 0 0 0
41740- 0 0 0 0 0 0 0 0 0 0 0 0
41741- 0 0 0 0 0 0 0 0 0 0 0 0
41742- 0 0 0 0 0 0 0 0 0 0 0 0
41743- 0 0 0 0 0 0 0 0 0 0 0 0
41744- 0 0 0 0 0 0 0 0 0 14 14 14
41745- 34 34 34 66 66 66 78 78 78 6 6 6
41746- 2 2 6 18 18 18 218 218 218 253 253 253
41747-253 253 253 253 253 253 253 253 253 246 246 246
41748-226 226 226 231 231 231 246 246 246 253 253 253
41749-253 253 253 253 253 253 253 253 253 253 253 253
41750-253 253 253 253 253 253 253 253 253 253 253 253
41751-253 253 253 178 178 178 2 2 6 2 2 6
41752- 2 2 6 2 2 6 2 2 6 2 2 6
41753- 2 2 6 18 18 18 90 90 90 62 62 62
41754- 30 30 30 10 10 10 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 0 0 0
41757- 0 0 0 0 0 0 0 0 0 0 0 0
41758- 0 0 0 0 0 0 0 0 0 0 0 0
41759- 0 0 0 0 0 0 0 0 0 0 0 0
41760- 0 0 0 0 0 0 0 0 0 0 0 0
41761- 0 0 0 0 0 0 0 0 0 0 0 0
41762- 0 0 0 0 0 0 0 0 0 0 0 0
41763- 0 0 0 0 0 0 0 0 0 0 0 0
41764- 0 0 0 0 0 0 10 10 10 26 26 26
41765- 58 58 58 90 90 90 18 18 18 2 2 6
41766- 2 2 6 110 110 110 253 253 253 253 253 253
41767-253 253 253 253 253 253 253 253 253 253 253 253
41768-250 250 250 253 253 253 253 253 253 253 253 253
41769-253 253 253 253 253 253 253 253 253 253 253 253
41770-253 253 253 253 253 253 253 253 253 253 253 253
41771-253 253 253 231 231 231 18 18 18 2 2 6
41772- 2 2 6 2 2 6 2 2 6 2 2 6
41773- 2 2 6 2 2 6 18 18 18 94 94 94
41774- 54 54 54 26 26 26 10 10 10 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 0 0 0
41777- 0 0 0 0 0 0 0 0 0 0 0 0
41778- 0 0 0 0 0 0 0 0 0 0 0 0
41779- 0 0 0 0 0 0 0 0 0 0 0 0
41780- 0 0 0 0 0 0 0 0 0 0 0 0
41781- 0 0 0 0 0 0 0 0 0 0 0 0
41782- 0 0 0 0 0 0 0 0 0 0 0 0
41783- 0 0 0 0 0 0 0 0 0 0 0 0
41784- 0 0 0 6 6 6 22 22 22 50 50 50
41785- 90 90 90 26 26 26 2 2 6 2 2 6
41786- 14 14 14 195 195 195 250 250 250 253 253 253
41787-253 253 253 253 253 253 253 253 253 253 253 253
41788-253 253 253 253 253 253 253 253 253 253 253 253
41789-253 253 253 253 253 253 253 253 253 253 253 253
41790-253 253 253 253 253 253 253 253 253 253 253 253
41791-250 250 250 242 242 242 54 54 54 2 2 6
41792- 2 2 6 2 2 6 2 2 6 2 2 6
41793- 2 2 6 2 2 6 2 2 6 38 38 38
41794- 86 86 86 50 50 50 22 22 22 6 6 6
41795- 0 0 0 0 0 0 0 0 0 0 0 0
41796- 0 0 0 0 0 0 0 0 0 0 0 0
41797- 0 0 0 0 0 0 0 0 0 0 0 0
41798- 0 0 0 0 0 0 0 0 0 0 0 0
41799- 0 0 0 0 0 0 0 0 0 0 0 0
41800- 0 0 0 0 0 0 0 0 0 0 0 0
41801- 0 0 0 0 0 0 0 0 0 0 0 0
41802- 0 0 0 0 0 0 0 0 0 0 0 0
41803- 0 0 0 0 0 0 0 0 0 0 0 0
41804- 6 6 6 14 14 14 38 38 38 82 82 82
41805- 34 34 34 2 2 6 2 2 6 2 2 6
41806- 42 42 42 195 195 195 246 246 246 253 253 253
41807-253 253 253 253 253 253 253 253 253 250 250 250
41808-242 242 242 242 242 242 250 250 250 253 253 253
41809-253 253 253 253 253 253 253 253 253 253 253 253
41810-253 253 253 250 250 250 246 246 246 238 238 238
41811-226 226 226 231 231 231 101 101 101 6 6 6
41812- 2 2 6 2 2 6 2 2 6 2 2 6
41813- 2 2 6 2 2 6 2 2 6 2 2 6
41814- 38 38 38 82 82 82 42 42 42 14 14 14
41815- 6 6 6 0 0 0 0 0 0 0 0 0
41816- 0 0 0 0 0 0 0 0 0 0 0 0
41817- 0 0 0 0 0 0 0 0 0 0 0 0
41818- 0 0 0 0 0 0 0 0 0 0 0 0
41819- 0 0 0 0 0 0 0 0 0 0 0 0
41820- 0 0 0 0 0 0 0 0 0 0 0 0
41821- 0 0 0 0 0 0 0 0 0 0 0 0
41822- 0 0 0 0 0 0 0 0 0 0 0 0
41823- 0 0 0 0 0 0 0 0 0 0 0 0
41824- 10 10 10 26 26 26 62 62 62 66 66 66
41825- 2 2 6 2 2 6 2 2 6 6 6 6
41826- 70 70 70 170 170 170 206 206 206 234 234 234
41827-246 246 246 250 250 250 250 250 250 238 238 238
41828-226 226 226 231 231 231 238 238 238 250 250 250
41829-250 250 250 250 250 250 246 246 246 231 231 231
41830-214 214 214 206 206 206 202 202 202 202 202 202
41831-198 198 198 202 202 202 182 182 182 18 18 18
41832- 2 2 6 2 2 6 2 2 6 2 2 6
41833- 2 2 6 2 2 6 2 2 6 2 2 6
41834- 2 2 6 62 62 62 66 66 66 30 30 30
41835- 10 10 10 0 0 0 0 0 0 0 0 0
41836- 0 0 0 0 0 0 0 0 0 0 0 0
41837- 0 0 0 0 0 0 0 0 0 0 0 0
41838- 0 0 0 0 0 0 0 0 0 0 0 0
41839- 0 0 0 0 0 0 0 0 0 0 0 0
41840- 0 0 0 0 0 0 0 0 0 0 0 0
41841- 0 0 0 0 0 0 0 0 0 0 0 0
41842- 0 0 0 0 0 0 0 0 0 0 0 0
41843- 0 0 0 0 0 0 0 0 0 0 0 0
41844- 14 14 14 42 42 42 82 82 82 18 18 18
41845- 2 2 6 2 2 6 2 2 6 10 10 10
41846- 94 94 94 182 182 182 218 218 218 242 242 242
41847-250 250 250 253 253 253 253 253 253 250 250 250
41848-234 234 234 253 253 253 253 253 253 253 253 253
41849-253 253 253 253 253 253 253 253 253 246 246 246
41850-238 238 238 226 226 226 210 210 210 202 202 202
41851-195 195 195 195 195 195 210 210 210 158 158 158
41852- 6 6 6 14 14 14 50 50 50 14 14 14
41853- 2 2 6 2 2 6 2 2 6 2 2 6
41854- 2 2 6 6 6 6 86 86 86 46 46 46
41855- 18 18 18 6 6 6 0 0 0 0 0 0
41856- 0 0 0 0 0 0 0 0 0 0 0 0
41857- 0 0 0 0 0 0 0 0 0 0 0 0
41858- 0 0 0 0 0 0 0 0 0 0 0 0
41859- 0 0 0 0 0 0 0 0 0 0 0 0
41860- 0 0 0 0 0 0 0 0 0 0 0 0
41861- 0 0 0 0 0 0 0 0 0 0 0 0
41862- 0 0 0 0 0 0 0 0 0 0 0 0
41863- 0 0 0 0 0 0 0 0 0 6 6 6
41864- 22 22 22 54 54 54 70 70 70 2 2 6
41865- 2 2 6 10 10 10 2 2 6 22 22 22
41866-166 166 166 231 231 231 250 250 250 253 253 253
41867-253 253 253 253 253 253 253 253 253 250 250 250
41868-242 242 242 253 253 253 253 253 253 253 253 253
41869-253 253 253 253 253 253 253 253 253 253 253 253
41870-253 253 253 253 253 253 253 253 253 246 246 246
41871-231 231 231 206 206 206 198 198 198 226 226 226
41872- 94 94 94 2 2 6 6 6 6 38 38 38
41873- 30 30 30 2 2 6 2 2 6 2 2 6
41874- 2 2 6 2 2 6 62 62 62 66 66 66
41875- 26 26 26 10 10 10 0 0 0 0 0 0
41876- 0 0 0 0 0 0 0 0 0 0 0 0
41877- 0 0 0 0 0 0 0 0 0 0 0 0
41878- 0 0 0 0 0 0 0 0 0 0 0 0
41879- 0 0 0 0 0 0 0 0 0 0 0 0
41880- 0 0 0 0 0 0 0 0 0 0 0 0
41881- 0 0 0 0 0 0 0 0 0 0 0 0
41882- 0 0 0 0 0 0 0 0 0 0 0 0
41883- 0 0 0 0 0 0 0 0 0 10 10 10
41884- 30 30 30 74 74 74 50 50 50 2 2 6
41885- 26 26 26 26 26 26 2 2 6 106 106 106
41886-238 238 238 253 253 253 253 253 253 253 253 253
41887-253 253 253 253 253 253 253 253 253 253 253 253
41888-253 253 253 253 253 253 253 253 253 253 253 253
41889-253 253 253 253 253 253 253 253 253 253 253 253
41890-253 253 253 253 253 253 253 253 253 253 253 253
41891-253 253 253 246 246 246 218 218 218 202 202 202
41892-210 210 210 14 14 14 2 2 6 2 2 6
41893- 30 30 30 22 22 22 2 2 6 2 2 6
41894- 2 2 6 2 2 6 18 18 18 86 86 86
41895- 42 42 42 14 14 14 0 0 0 0 0 0
41896- 0 0 0 0 0 0 0 0 0 0 0 0
41897- 0 0 0 0 0 0 0 0 0 0 0 0
41898- 0 0 0 0 0 0 0 0 0 0 0 0
41899- 0 0 0 0 0 0 0 0 0 0 0 0
41900- 0 0 0 0 0 0 0 0 0 0 0 0
41901- 0 0 0 0 0 0 0 0 0 0 0 0
41902- 0 0 0 0 0 0 0 0 0 0 0 0
41903- 0 0 0 0 0 0 0 0 0 14 14 14
41904- 42 42 42 90 90 90 22 22 22 2 2 6
41905- 42 42 42 2 2 6 18 18 18 218 218 218
41906-253 253 253 253 253 253 253 253 253 253 253 253
41907-253 253 253 253 253 253 253 253 253 253 253 253
41908-253 253 253 253 253 253 253 253 253 253 253 253
41909-253 253 253 253 253 253 253 253 253 253 253 253
41910-253 253 253 253 253 253 253 253 253 253 253 253
41911-253 253 253 253 253 253 250 250 250 221 221 221
41912-218 218 218 101 101 101 2 2 6 14 14 14
41913- 18 18 18 38 38 38 10 10 10 2 2 6
41914- 2 2 6 2 2 6 2 2 6 78 78 78
41915- 58 58 58 22 22 22 6 6 6 0 0 0
41916- 0 0 0 0 0 0 0 0 0 0 0 0
41917- 0 0 0 0 0 0 0 0 0 0 0 0
41918- 0 0 0 0 0 0 0 0 0 0 0 0
41919- 0 0 0 0 0 0 0 0 0 0 0 0
41920- 0 0 0 0 0 0 0 0 0 0 0 0
41921- 0 0 0 0 0 0 0 0 0 0 0 0
41922- 0 0 0 0 0 0 0 0 0 0 0 0
41923- 0 0 0 0 0 0 6 6 6 18 18 18
41924- 54 54 54 82 82 82 2 2 6 26 26 26
41925- 22 22 22 2 2 6 123 123 123 253 253 253
41926-253 253 253 253 253 253 253 253 253 253 253 253
41927-253 253 253 253 253 253 253 253 253 253 253 253
41928-253 253 253 253 253 253 253 253 253 253 253 253
41929-253 253 253 253 253 253 253 253 253 253 253 253
41930-253 253 253 253 253 253 253 253 253 253 253 253
41931-253 253 253 253 253 253 253 253 253 250 250 250
41932-238 238 238 198 198 198 6 6 6 38 38 38
41933- 58 58 58 26 26 26 38 38 38 2 2 6
41934- 2 2 6 2 2 6 2 2 6 46 46 46
41935- 78 78 78 30 30 30 10 10 10 0 0 0
41936- 0 0 0 0 0 0 0 0 0 0 0 0
41937- 0 0 0 0 0 0 0 0 0 0 0 0
41938- 0 0 0 0 0 0 0 0 0 0 0 0
41939- 0 0 0 0 0 0 0 0 0 0 0 0
41940- 0 0 0 0 0 0 0 0 0 0 0 0
41941- 0 0 0 0 0 0 0 0 0 0 0 0
41942- 0 0 0 0 0 0 0 0 0 0 0 0
41943- 0 0 0 0 0 0 10 10 10 30 30 30
41944- 74 74 74 58 58 58 2 2 6 42 42 42
41945- 2 2 6 22 22 22 231 231 231 253 253 253
41946-253 253 253 253 253 253 253 253 253 253 253 253
41947-253 253 253 253 253 253 253 253 253 250 250 250
41948-253 253 253 253 253 253 253 253 253 253 253 253
41949-253 253 253 253 253 253 253 253 253 253 253 253
41950-253 253 253 253 253 253 253 253 253 253 253 253
41951-253 253 253 253 253 253 253 253 253 253 253 253
41952-253 253 253 246 246 246 46 46 46 38 38 38
41953- 42 42 42 14 14 14 38 38 38 14 14 14
41954- 2 2 6 2 2 6 2 2 6 6 6 6
41955- 86 86 86 46 46 46 14 14 14 0 0 0
41956- 0 0 0 0 0 0 0 0 0 0 0 0
41957- 0 0 0 0 0 0 0 0 0 0 0 0
41958- 0 0 0 0 0 0 0 0 0 0 0 0
41959- 0 0 0 0 0 0 0 0 0 0 0 0
41960- 0 0 0 0 0 0 0 0 0 0 0 0
41961- 0 0 0 0 0 0 0 0 0 0 0 0
41962- 0 0 0 0 0 0 0 0 0 0 0 0
41963- 0 0 0 6 6 6 14 14 14 42 42 42
41964- 90 90 90 18 18 18 18 18 18 26 26 26
41965- 2 2 6 116 116 116 253 253 253 253 253 253
41966-253 253 253 253 253 253 253 253 253 253 253 253
41967-253 253 253 253 253 253 250 250 250 238 238 238
41968-253 253 253 253 253 253 253 253 253 253 253 253
41969-253 253 253 253 253 253 253 253 253 253 253 253
41970-253 253 253 253 253 253 253 253 253 253 253 253
41971-253 253 253 253 253 253 253 253 253 253 253 253
41972-253 253 253 253 253 253 94 94 94 6 6 6
41973- 2 2 6 2 2 6 10 10 10 34 34 34
41974- 2 2 6 2 2 6 2 2 6 2 2 6
41975- 74 74 74 58 58 58 22 22 22 6 6 6
41976- 0 0 0 0 0 0 0 0 0 0 0 0
41977- 0 0 0 0 0 0 0 0 0 0 0 0
41978- 0 0 0 0 0 0 0 0 0 0 0 0
41979- 0 0 0 0 0 0 0 0 0 0 0 0
41980- 0 0 0 0 0 0 0 0 0 0 0 0
41981- 0 0 0 0 0 0 0 0 0 0 0 0
41982- 0 0 0 0 0 0 0 0 0 0 0 0
41983- 0 0 0 10 10 10 26 26 26 66 66 66
41984- 82 82 82 2 2 6 38 38 38 6 6 6
41985- 14 14 14 210 210 210 253 253 253 253 253 253
41986-253 253 253 253 253 253 253 253 253 253 253 253
41987-253 253 253 253 253 253 246 246 246 242 242 242
41988-253 253 253 253 253 253 253 253 253 253 253 253
41989-253 253 253 253 253 253 253 253 253 253 253 253
41990-253 253 253 253 253 253 253 253 253 253 253 253
41991-253 253 253 253 253 253 253 253 253 253 253 253
41992-253 253 253 253 253 253 144 144 144 2 2 6
41993- 2 2 6 2 2 6 2 2 6 46 46 46
41994- 2 2 6 2 2 6 2 2 6 2 2 6
41995- 42 42 42 74 74 74 30 30 30 10 10 10
41996- 0 0 0 0 0 0 0 0 0 0 0 0
41997- 0 0 0 0 0 0 0 0 0 0 0 0
41998- 0 0 0 0 0 0 0 0 0 0 0 0
41999- 0 0 0 0 0 0 0 0 0 0 0 0
42000- 0 0 0 0 0 0 0 0 0 0 0 0
42001- 0 0 0 0 0 0 0 0 0 0 0 0
42002- 0 0 0 0 0 0 0 0 0 0 0 0
42003- 6 6 6 14 14 14 42 42 42 90 90 90
42004- 26 26 26 6 6 6 42 42 42 2 2 6
42005- 74 74 74 250 250 250 253 253 253 253 253 253
42006-253 253 253 253 253 253 253 253 253 253 253 253
42007-253 253 253 253 253 253 242 242 242 242 242 242
42008-253 253 253 253 253 253 253 253 253 253 253 253
42009-253 253 253 253 253 253 253 253 253 253 253 253
42010-253 253 253 253 253 253 253 253 253 253 253 253
42011-253 253 253 253 253 253 253 253 253 253 253 253
42012-253 253 253 253 253 253 182 182 182 2 2 6
42013- 2 2 6 2 2 6 2 2 6 46 46 46
42014- 2 2 6 2 2 6 2 2 6 2 2 6
42015- 10 10 10 86 86 86 38 38 38 10 10 10
42016- 0 0 0 0 0 0 0 0 0 0 0 0
42017- 0 0 0 0 0 0 0 0 0 0 0 0
42018- 0 0 0 0 0 0 0 0 0 0 0 0
42019- 0 0 0 0 0 0 0 0 0 0 0 0
42020- 0 0 0 0 0 0 0 0 0 0 0 0
42021- 0 0 0 0 0 0 0 0 0 0 0 0
42022- 0 0 0 0 0 0 0 0 0 0 0 0
42023- 10 10 10 26 26 26 66 66 66 82 82 82
42024- 2 2 6 22 22 22 18 18 18 2 2 6
42025-149 149 149 253 253 253 253 253 253 253 253 253
42026-253 253 253 253 253 253 253 253 253 253 253 253
42027-253 253 253 253 253 253 234 234 234 242 242 242
42028-253 253 253 253 253 253 253 253 253 253 253 253
42029-253 253 253 253 253 253 253 253 253 253 253 253
42030-253 253 253 253 253 253 253 253 253 253 253 253
42031-253 253 253 253 253 253 253 253 253 253 253 253
42032-253 253 253 253 253 253 206 206 206 2 2 6
42033- 2 2 6 2 2 6 2 2 6 38 38 38
42034- 2 2 6 2 2 6 2 2 6 2 2 6
42035- 6 6 6 86 86 86 46 46 46 14 14 14
42036- 0 0 0 0 0 0 0 0 0 0 0 0
42037- 0 0 0 0 0 0 0 0 0 0 0 0
42038- 0 0 0 0 0 0 0 0 0 0 0 0
42039- 0 0 0 0 0 0 0 0 0 0 0 0
42040- 0 0 0 0 0 0 0 0 0 0 0 0
42041- 0 0 0 0 0 0 0 0 0 0 0 0
42042- 0 0 0 0 0 0 0 0 0 6 6 6
42043- 18 18 18 46 46 46 86 86 86 18 18 18
42044- 2 2 6 34 34 34 10 10 10 6 6 6
42045-210 210 210 253 253 253 253 253 253 253 253 253
42046-253 253 253 253 253 253 253 253 253 253 253 253
42047-253 253 253 253 253 253 234 234 234 242 242 242
42048-253 253 253 253 253 253 253 253 253 253 253 253
42049-253 253 253 253 253 253 253 253 253 253 253 253
42050-253 253 253 253 253 253 253 253 253 253 253 253
42051-253 253 253 253 253 253 253 253 253 253 253 253
42052-253 253 253 253 253 253 221 221 221 6 6 6
42053- 2 2 6 2 2 6 6 6 6 30 30 30
42054- 2 2 6 2 2 6 2 2 6 2 2 6
42055- 2 2 6 82 82 82 54 54 54 18 18 18
42056- 6 6 6 0 0 0 0 0 0 0 0 0
42057- 0 0 0 0 0 0 0 0 0 0 0 0
42058- 0 0 0 0 0 0 0 0 0 0 0 0
42059- 0 0 0 0 0 0 0 0 0 0 0 0
42060- 0 0 0 0 0 0 0 0 0 0 0 0
42061- 0 0 0 0 0 0 0 0 0 0 0 0
42062- 0 0 0 0 0 0 0 0 0 10 10 10
42063- 26 26 26 66 66 66 62 62 62 2 2 6
42064- 2 2 6 38 38 38 10 10 10 26 26 26
42065-238 238 238 253 253 253 253 253 253 253 253 253
42066-253 253 253 253 253 253 253 253 253 253 253 253
42067-253 253 253 253 253 253 231 231 231 238 238 238
42068-253 253 253 253 253 253 253 253 253 253 253 253
42069-253 253 253 253 253 253 253 253 253 253 253 253
42070-253 253 253 253 253 253 253 253 253 253 253 253
42071-253 253 253 253 253 253 253 253 253 253 253 253
42072-253 253 253 253 253 253 231 231 231 6 6 6
42073- 2 2 6 2 2 6 10 10 10 30 30 30
42074- 2 2 6 2 2 6 2 2 6 2 2 6
42075- 2 2 6 66 66 66 58 58 58 22 22 22
42076- 6 6 6 0 0 0 0 0 0 0 0 0
42077- 0 0 0 0 0 0 0 0 0 0 0 0
42078- 0 0 0 0 0 0 0 0 0 0 0 0
42079- 0 0 0 0 0 0 0 0 0 0 0 0
42080- 0 0 0 0 0 0 0 0 0 0 0 0
42081- 0 0 0 0 0 0 0 0 0 0 0 0
42082- 0 0 0 0 0 0 0 0 0 10 10 10
42083- 38 38 38 78 78 78 6 6 6 2 2 6
42084- 2 2 6 46 46 46 14 14 14 42 42 42
42085-246 246 246 253 253 253 253 253 253 253 253 253
42086-253 253 253 253 253 253 253 253 253 253 253 253
42087-253 253 253 253 253 253 231 231 231 242 242 242
42088-253 253 253 253 253 253 253 253 253 253 253 253
42089-253 253 253 253 253 253 253 253 253 253 253 253
42090-253 253 253 253 253 253 253 253 253 253 253 253
42091-253 253 253 253 253 253 253 253 253 253 253 253
42092-253 253 253 253 253 253 234 234 234 10 10 10
42093- 2 2 6 2 2 6 22 22 22 14 14 14
42094- 2 2 6 2 2 6 2 2 6 2 2 6
42095- 2 2 6 66 66 66 62 62 62 22 22 22
42096- 6 6 6 0 0 0 0 0 0 0 0 0
42097- 0 0 0 0 0 0 0 0 0 0 0 0
42098- 0 0 0 0 0 0 0 0 0 0 0 0
42099- 0 0 0 0 0 0 0 0 0 0 0 0
42100- 0 0 0 0 0 0 0 0 0 0 0 0
42101- 0 0 0 0 0 0 0 0 0 0 0 0
42102- 0 0 0 0 0 0 6 6 6 18 18 18
42103- 50 50 50 74 74 74 2 2 6 2 2 6
42104- 14 14 14 70 70 70 34 34 34 62 62 62
42105-250 250 250 253 253 253 253 253 253 253 253 253
42106-253 253 253 253 253 253 253 253 253 253 253 253
42107-253 253 253 253 253 253 231 231 231 246 246 246
42108-253 253 253 253 253 253 253 253 253 253 253 253
42109-253 253 253 253 253 253 253 253 253 253 253 253
42110-253 253 253 253 253 253 253 253 253 253 253 253
42111-253 253 253 253 253 253 253 253 253 253 253 253
42112-253 253 253 253 253 253 234 234 234 14 14 14
42113- 2 2 6 2 2 6 30 30 30 2 2 6
42114- 2 2 6 2 2 6 2 2 6 2 2 6
42115- 2 2 6 66 66 66 62 62 62 22 22 22
42116- 6 6 6 0 0 0 0 0 0 0 0 0
42117- 0 0 0 0 0 0 0 0 0 0 0 0
42118- 0 0 0 0 0 0 0 0 0 0 0 0
42119- 0 0 0 0 0 0 0 0 0 0 0 0
42120- 0 0 0 0 0 0 0 0 0 0 0 0
42121- 0 0 0 0 0 0 0 0 0 0 0 0
42122- 0 0 0 0 0 0 6 6 6 18 18 18
42123- 54 54 54 62 62 62 2 2 6 2 2 6
42124- 2 2 6 30 30 30 46 46 46 70 70 70
42125-250 250 250 253 253 253 253 253 253 253 253 253
42126-253 253 253 253 253 253 253 253 253 253 253 253
42127-253 253 253 253 253 253 231 231 231 246 246 246
42128-253 253 253 253 253 253 253 253 253 253 253 253
42129-253 253 253 253 253 253 253 253 253 253 253 253
42130-253 253 253 253 253 253 253 253 253 253 253 253
42131-253 253 253 253 253 253 253 253 253 253 253 253
42132-253 253 253 253 253 253 226 226 226 10 10 10
42133- 2 2 6 6 6 6 30 30 30 2 2 6
42134- 2 2 6 2 2 6 2 2 6 2 2 6
42135- 2 2 6 66 66 66 58 58 58 22 22 22
42136- 6 6 6 0 0 0 0 0 0 0 0 0
42137- 0 0 0 0 0 0 0 0 0 0 0 0
42138- 0 0 0 0 0 0 0 0 0 0 0 0
42139- 0 0 0 0 0 0 0 0 0 0 0 0
42140- 0 0 0 0 0 0 0 0 0 0 0 0
42141- 0 0 0 0 0 0 0 0 0 0 0 0
42142- 0 0 0 0 0 0 6 6 6 22 22 22
42143- 58 58 58 62 62 62 2 2 6 2 2 6
42144- 2 2 6 2 2 6 30 30 30 78 78 78
42145-250 250 250 253 253 253 253 253 253 253 253 253
42146-253 253 253 253 253 253 253 253 253 253 253 253
42147-253 253 253 253 253 253 231 231 231 246 246 246
42148-253 253 253 253 253 253 253 253 253 253 253 253
42149-253 253 253 253 253 253 253 253 253 253 253 253
42150-253 253 253 253 253 253 253 253 253 253 253 253
42151-253 253 253 253 253 253 253 253 253 253 253 253
42152-253 253 253 253 253 253 206 206 206 2 2 6
42153- 22 22 22 34 34 34 18 14 6 22 22 22
42154- 26 26 26 18 18 18 6 6 6 2 2 6
42155- 2 2 6 82 82 82 54 54 54 18 18 18
42156- 6 6 6 0 0 0 0 0 0 0 0 0
42157- 0 0 0 0 0 0 0 0 0 0 0 0
42158- 0 0 0 0 0 0 0 0 0 0 0 0
42159- 0 0 0 0 0 0 0 0 0 0 0 0
42160- 0 0 0 0 0 0 0 0 0 0 0 0
42161- 0 0 0 0 0 0 0 0 0 0 0 0
42162- 0 0 0 0 0 0 6 6 6 26 26 26
42163- 62 62 62 106 106 106 74 54 14 185 133 11
42164-210 162 10 121 92 8 6 6 6 62 62 62
42165-238 238 238 253 253 253 253 253 253 253 253 253
42166-253 253 253 253 253 253 253 253 253 253 253 253
42167-253 253 253 253 253 253 231 231 231 246 246 246
42168-253 253 253 253 253 253 253 253 253 253 253 253
42169-253 253 253 253 253 253 253 253 253 253 253 253
42170-253 253 253 253 253 253 253 253 253 253 253 253
42171-253 253 253 253 253 253 253 253 253 253 253 253
42172-253 253 253 253 253 253 158 158 158 18 18 18
42173- 14 14 14 2 2 6 2 2 6 2 2 6
42174- 6 6 6 18 18 18 66 66 66 38 38 38
42175- 6 6 6 94 94 94 50 50 50 18 18 18
42176- 6 6 6 0 0 0 0 0 0 0 0 0
42177- 0 0 0 0 0 0 0 0 0 0 0 0
42178- 0 0 0 0 0 0 0 0 0 0 0 0
42179- 0 0 0 0 0 0 0 0 0 0 0 0
42180- 0 0 0 0 0 0 0 0 0 0 0 0
42181- 0 0 0 0 0 0 0 0 0 6 6 6
42182- 10 10 10 10 10 10 18 18 18 38 38 38
42183- 78 78 78 142 134 106 216 158 10 242 186 14
42184-246 190 14 246 190 14 156 118 10 10 10 10
42185- 90 90 90 238 238 238 253 253 253 253 253 253
42186-253 253 253 253 253 253 253 253 253 253 253 253
42187-253 253 253 253 253 253 231 231 231 250 250 250
42188-253 253 253 253 253 253 253 253 253 253 253 253
42189-253 253 253 253 253 253 253 253 253 253 253 253
42190-253 253 253 253 253 253 253 253 253 253 253 253
42191-253 253 253 253 253 253 253 253 253 246 230 190
42192-238 204 91 238 204 91 181 142 44 37 26 9
42193- 2 2 6 2 2 6 2 2 6 2 2 6
42194- 2 2 6 2 2 6 38 38 38 46 46 46
42195- 26 26 26 106 106 106 54 54 54 18 18 18
42196- 6 6 6 0 0 0 0 0 0 0 0 0
42197- 0 0 0 0 0 0 0 0 0 0 0 0
42198- 0 0 0 0 0 0 0 0 0 0 0 0
42199- 0 0 0 0 0 0 0 0 0 0 0 0
42200- 0 0 0 0 0 0 0 0 0 0 0 0
42201- 0 0 0 6 6 6 14 14 14 22 22 22
42202- 30 30 30 38 38 38 50 50 50 70 70 70
42203-106 106 106 190 142 34 226 170 11 242 186 14
42204-246 190 14 246 190 14 246 190 14 154 114 10
42205- 6 6 6 74 74 74 226 226 226 253 253 253
42206-253 253 253 253 253 253 253 253 253 253 253 253
42207-253 253 253 253 253 253 231 231 231 250 250 250
42208-253 253 253 253 253 253 253 253 253 253 253 253
42209-253 253 253 253 253 253 253 253 253 253 253 253
42210-253 253 253 253 253 253 253 253 253 253 253 253
42211-253 253 253 253 253 253 253 253 253 228 184 62
42212-241 196 14 241 208 19 232 195 16 38 30 10
42213- 2 2 6 2 2 6 2 2 6 2 2 6
42214- 2 2 6 6 6 6 30 30 30 26 26 26
42215-203 166 17 154 142 90 66 66 66 26 26 26
42216- 6 6 6 0 0 0 0 0 0 0 0 0
42217- 0 0 0 0 0 0 0 0 0 0 0 0
42218- 0 0 0 0 0 0 0 0 0 0 0 0
42219- 0 0 0 0 0 0 0 0 0 0 0 0
42220- 0 0 0 0 0 0 0 0 0 0 0 0
42221- 6 6 6 18 18 18 38 38 38 58 58 58
42222- 78 78 78 86 86 86 101 101 101 123 123 123
42223-175 146 61 210 150 10 234 174 13 246 186 14
42224-246 190 14 246 190 14 246 190 14 238 190 10
42225-102 78 10 2 2 6 46 46 46 198 198 198
42226-253 253 253 253 253 253 253 253 253 253 253 253
42227-253 253 253 253 253 253 234 234 234 242 242 242
42228-253 253 253 253 253 253 253 253 253 253 253 253
42229-253 253 253 253 253 253 253 253 253 253 253 253
42230-253 253 253 253 253 253 253 253 253 253 253 253
42231-253 253 253 253 253 253 253 253 253 224 178 62
42232-242 186 14 241 196 14 210 166 10 22 18 6
42233- 2 2 6 2 2 6 2 2 6 2 2 6
42234- 2 2 6 2 2 6 6 6 6 121 92 8
42235-238 202 15 232 195 16 82 82 82 34 34 34
42236- 10 10 10 0 0 0 0 0 0 0 0 0
42237- 0 0 0 0 0 0 0 0 0 0 0 0
42238- 0 0 0 0 0 0 0 0 0 0 0 0
42239- 0 0 0 0 0 0 0 0 0 0 0 0
42240- 0 0 0 0 0 0 0 0 0 0 0 0
42241- 14 14 14 38 38 38 70 70 70 154 122 46
42242-190 142 34 200 144 11 197 138 11 197 138 11
42243-213 154 11 226 170 11 242 186 14 246 190 14
42244-246 190 14 246 190 14 246 190 14 246 190 14
42245-225 175 15 46 32 6 2 2 6 22 22 22
42246-158 158 158 250 250 250 253 253 253 253 253 253
42247-253 253 253 253 253 253 253 253 253 253 253 253
42248-253 253 253 253 253 253 253 253 253 253 253 253
42249-253 253 253 253 253 253 253 253 253 253 253 253
42250-253 253 253 253 253 253 253 253 253 253 253 253
42251-253 253 253 250 250 250 242 242 242 224 178 62
42252-239 182 13 236 186 11 213 154 11 46 32 6
42253- 2 2 6 2 2 6 2 2 6 2 2 6
42254- 2 2 6 2 2 6 61 42 6 225 175 15
42255-238 190 10 236 186 11 112 100 78 42 42 42
42256- 14 14 14 0 0 0 0 0 0 0 0 0
42257- 0 0 0 0 0 0 0 0 0 0 0 0
42258- 0 0 0 0 0 0 0 0 0 0 0 0
42259- 0 0 0 0 0 0 0 0 0 0 0 0
42260- 0 0 0 0 0 0 0 0 0 6 6 6
42261- 22 22 22 54 54 54 154 122 46 213 154 11
42262-226 170 11 230 174 11 226 170 11 226 170 11
42263-236 178 12 242 186 14 246 190 14 246 190 14
42264-246 190 14 246 190 14 246 190 14 246 190 14
42265-241 196 14 184 144 12 10 10 10 2 2 6
42266- 6 6 6 116 116 116 242 242 242 253 253 253
42267-253 253 253 253 253 253 253 253 253 253 253 253
42268-253 253 253 253 253 253 253 253 253 253 253 253
42269-253 253 253 253 253 253 253 253 253 253 253 253
42270-253 253 253 253 253 253 253 253 253 253 253 253
42271-253 253 253 231 231 231 198 198 198 214 170 54
42272-236 178 12 236 178 12 210 150 10 137 92 6
42273- 18 14 6 2 2 6 2 2 6 2 2 6
42274- 6 6 6 70 47 6 200 144 11 236 178 12
42275-239 182 13 239 182 13 124 112 88 58 58 58
42276- 22 22 22 6 6 6 0 0 0 0 0 0
42277- 0 0 0 0 0 0 0 0 0 0 0 0
42278- 0 0 0 0 0 0 0 0 0 0 0 0
42279- 0 0 0 0 0 0 0 0 0 0 0 0
42280- 0 0 0 0 0 0 0 0 0 10 10 10
42281- 30 30 30 70 70 70 180 133 36 226 170 11
42282-239 182 13 242 186 14 242 186 14 246 186 14
42283-246 190 14 246 190 14 246 190 14 246 190 14
42284-246 190 14 246 190 14 246 190 14 246 190 14
42285-246 190 14 232 195 16 98 70 6 2 2 6
42286- 2 2 6 2 2 6 66 66 66 221 221 221
42287-253 253 253 253 253 253 253 253 253 253 253 253
42288-253 253 253 253 253 253 253 253 253 253 253 253
42289-253 253 253 253 253 253 253 253 253 253 253 253
42290-253 253 253 253 253 253 253 253 253 253 253 253
42291-253 253 253 206 206 206 198 198 198 214 166 58
42292-230 174 11 230 174 11 216 158 10 192 133 9
42293-163 110 8 116 81 8 102 78 10 116 81 8
42294-167 114 7 197 138 11 226 170 11 239 182 13
42295-242 186 14 242 186 14 162 146 94 78 78 78
42296- 34 34 34 14 14 14 6 6 6 0 0 0
42297- 0 0 0 0 0 0 0 0 0 0 0 0
42298- 0 0 0 0 0 0 0 0 0 0 0 0
42299- 0 0 0 0 0 0 0 0 0 0 0 0
42300- 0 0 0 0 0 0 0 0 0 6 6 6
42301- 30 30 30 78 78 78 190 142 34 226 170 11
42302-239 182 13 246 190 14 246 190 14 246 190 14
42303-246 190 14 246 190 14 246 190 14 246 190 14
42304-246 190 14 246 190 14 246 190 14 246 190 14
42305-246 190 14 241 196 14 203 166 17 22 18 6
42306- 2 2 6 2 2 6 2 2 6 38 38 38
42307-218 218 218 253 253 253 253 253 253 253 253 253
42308-253 253 253 253 253 253 253 253 253 253 253 253
42309-253 253 253 253 253 253 253 253 253 253 253 253
42310-253 253 253 253 253 253 253 253 253 253 253 253
42311-250 250 250 206 206 206 198 198 198 202 162 69
42312-226 170 11 236 178 12 224 166 10 210 150 10
42313-200 144 11 197 138 11 192 133 9 197 138 11
42314-210 150 10 226 170 11 242 186 14 246 190 14
42315-246 190 14 246 186 14 225 175 15 124 112 88
42316- 62 62 62 30 30 30 14 14 14 6 6 6
42317- 0 0 0 0 0 0 0 0 0 0 0 0
42318- 0 0 0 0 0 0 0 0 0 0 0 0
42319- 0 0 0 0 0 0 0 0 0 0 0 0
42320- 0 0 0 0 0 0 0 0 0 10 10 10
42321- 30 30 30 78 78 78 174 135 50 224 166 10
42322-239 182 13 246 190 14 246 190 14 246 190 14
42323-246 190 14 246 190 14 246 190 14 246 190 14
42324-246 190 14 246 190 14 246 190 14 246 190 14
42325-246 190 14 246 190 14 241 196 14 139 102 15
42326- 2 2 6 2 2 6 2 2 6 2 2 6
42327- 78 78 78 250 250 250 253 253 253 253 253 253
42328-253 253 253 253 253 253 253 253 253 253 253 253
42329-253 253 253 253 253 253 253 253 253 253 253 253
42330-253 253 253 253 253 253 253 253 253 253 253 253
42331-250 250 250 214 214 214 198 198 198 190 150 46
42332-219 162 10 236 178 12 234 174 13 224 166 10
42333-216 158 10 213 154 11 213 154 11 216 158 10
42334-226 170 11 239 182 13 246 190 14 246 190 14
42335-246 190 14 246 190 14 242 186 14 206 162 42
42336-101 101 101 58 58 58 30 30 30 14 14 14
42337- 6 6 6 0 0 0 0 0 0 0 0 0
42338- 0 0 0 0 0 0 0 0 0 0 0 0
42339- 0 0 0 0 0 0 0 0 0 0 0 0
42340- 0 0 0 0 0 0 0 0 0 10 10 10
42341- 30 30 30 74 74 74 174 135 50 216 158 10
42342-236 178 12 246 190 14 246 190 14 246 190 14
42343-246 190 14 246 190 14 246 190 14 246 190 14
42344-246 190 14 246 190 14 246 190 14 246 190 14
42345-246 190 14 246 190 14 241 196 14 226 184 13
42346- 61 42 6 2 2 6 2 2 6 2 2 6
42347- 22 22 22 238 238 238 253 253 253 253 253 253
42348-253 253 253 253 253 253 253 253 253 253 253 253
42349-253 253 253 253 253 253 253 253 253 253 253 253
42350-253 253 253 253 253 253 253 253 253 253 253 253
42351-253 253 253 226 226 226 187 187 187 180 133 36
42352-216 158 10 236 178 12 239 182 13 236 178 12
42353-230 174 11 226 170 11 226 170 11 230 174 11
42354-236 178 12 242 186 14 246 190 14 246 190 14
42355-246 190 14 246 190 14 246 186 14 239 182 13
42356-206 162 42 106 106 106 66 66 66 34 34 34
42357- 14 14 14 6 6 6 0 0 0 0 0 0
42358- 0 0 0 0 0 0 0 0 0 0 0 0
42359- 0 0 0 0 0 0 0 0 0 0 0 0
42360- 0 0 0 0 0 0 0 0 0 6 6 6
42361- 26 26 26 70 70 70 163 133 67 213 154 11
42362-236 178 12 246 190 14 246 190 14 246 190 14
42363-246 190 14 246 190 14 246 190 14 246 190 14
42364-246 190 14 246 190 14 246 190 14 246 190 14
42365-246 190 14 246 190 14 246 190 14 241 196 14
42366-190 146 13 18 14 6 2 2 6 2 2 6
42367- 46 46 46 246 246 246 253 253 253 253 253 253
42368-253 253 253 253 253 253 253 253 253 253 253 253
42369-253 253 253 253 253 253 253 253 253 253 253 253
42370-253 253 253 253 253 253 253 253 253 253 253 253
42371-253 253 253 221 221 221 86 86 86 156 107 11
42372-216 158 10 236 178 12 242 186 14 246 186 14
42373-242 186 14 239 182 13 239 182 13 242 186 14
42374-242 186 14 246 186 14 246 190 14 246 190 14
42375-246 190 14 246 190 14 246 190 14 246 190 14
42376-242 186 14 225 175 15 142 122 72 66 66 66
42377- 30 30 30 10 10 10 0 0 0 0 0 0
42378- 0 0 0 0 0 0 0 0 0 0 0 0
42379- 0 0 0 0 0 0 0 0 0 0 0 0
42380- 0 0 0 0 0 0 0 0 0 6 6 6
42381- 26 26 26 70 70 70 163 133 67 210 150 10
42382-236 178 12 246 190 14 246 190 14 246 190 14
42383-246 190 14 246 190 14 246 190 14 246 190 14
42384-246 190 14 246 190 14 246 190 14 246 190 14
42385-246 190 14 246 190 14 246 190 14 246 190 14
42386-232 195 16 121 92 8 34 34 34 106 106 106
42387-221 221 221 253 253 253 253 253 253 253 253 253
42388-253 253 253 253 253 253 253 253 253 253 253 253
42389-253 253 253 253 253 253 253 253 253 253 253 253
42390-253 253 253 253 253 253 253 253 253 253 253 253
42391-242 242 242 82 82 82 18 14 6 163 110 8
42392-216 158 10 236 178 12 242 186 14 246 190 14
42393-246 190 14 246 190 14 246 190 14 246 190 14
42394-246 190 14 246 190 14 246 190 14 246 190 14
42395-246 190 14 246 190 14 246 190 14 246 190 14
42396-246 190 14 246 190 14 242 186 14 163 133 67
42397- 46 46 46 18 18 18 6 6 6 0 0 0
42398- 0 0 0 0 0 0 0 0 0 0 0 0
42399- 0 0 0 0 0 0 0 0 0 0 0 0
42400- 0 0 0 0 0 0 0 0 0 10 10 10
42401- 30 30 30 78 78 78 163 133 67 210 150 10
42402-236 178 12 246 186 14 246 190 14 246 190 14
42403-246 190 14 246 190 14 246 190 14 246 190 14
42404-246 190 14 246 190 14 246 190 14 246 190 14
42405-246 190 14 246 190 14 246 190 14 246 190 14
42406-241 196 14 215 174 15 190 178 144 253 253 253
42407-253 253 253 253 253 253 253 253 253 253 253 253
42408-253 253 253 253 253 253 253 253 253 253 253 253
42409-253 253 253 253 253 253 253 253 253 253 253 253
42410-253 253 253 253 253 253 253 253 253 218 218 218
42411- 58 58 58 2 2 6 22 18 6 167 114 7
42412-216 158 10 236 178 12 246 186 14 246 190 14
42413-246 190 14 246 190 14 246 190 14 246 190 14
42414-246 190 14 246 190 14 246 190 14 246 190 14
42415-246 190 14 246 190 14 246 190 14 246 190 14
42416-246 190 14 246 186 14 242 186 14 190 150 46
42417- 54 54 54 22 22 22 6 6 6 0 0 0
42418- 0 0 0 0 0 0 0 0 0 0 0 0
42419- 0 0 0 0 0 0 0 0 0 0 0 0
42420- 0 0 0 0 0 0 0 0 0 14 14 14
42421- 38 38 38 86 86 86 180 133 36 213 154 11
42422-236 178 12 246 186 14 246 190 14 246 190 14
42423-246 190 14 246 190 14 246 190 14 246 190 14
42424-246 190 14 246 190 14 246 190 14 246 190 14
42425-246 190 14 246 190 14 246 190 14 246 190 14
42426-246 190 14 232 195 16 190 146 13 214 214 214
42427-253 253 253 253 253 253 253 253 253 253 253 253
42428-253 253 253 253 253 253 253 253 253 253 253 253
42429-253 253 253 253 253 253 253 253 253 253 253 253
42430-253 253 253 250 250 250 170 170 170 26 26 26
42431- 2 2 6 2 2 6 37 26 9 163 110 8
42432-219 162 10 239 182 13 246 186 14 246 190 14
42433-246 190 14 246 190 14 246 190 14 246 190 14
42434-246 190 14 246 190 14 246 190 14 246 190 14
42435-246 190 14 246 190 14 246 190 14 246 190 14
42436-246 186 14 236 178 12 224 166 10 142 122 72
42437- 46 46 46 18 18 18 6 6 6 0 0 0
42438- 0 0 0 0 0 0 0 0 0 0 0 0
42439- 0 0 0 0 0 0 0 0 0 0 0 0
42440- 0 0 0 0 0 0 6 6 6 18 18 18
42441- 50 50 50 109 106 95 192 133 9 224 166 10
42442-242 186 14 246 190 14 246 190 14 246 190 14
42443-246 190 14 246 190 14 246 190 14 246 190 14
42444-246 190 14 246 190 14 246 190 14 246 190 14
42445-246 190 14 246 190 14 246 190 14 246 190 14
42446-242 186 14 226 184 13 210 162 10 142 110 46
42447-226 226 226 253 253 253 253 253 253 253 253 253
42448-253 253 253 253 253 253 253 253 253 253 253 253
42449-253 253 253 253 253 253 253 253 253 253 253 253
42450-198 198 198 66 66 66 2 2 6 2 2 6
42451- 2 2 6 2 2 6 50 34 6 156 107 11
42452-219 162 10 239 182 13 246 186 14 246 190 14
42453-246 190 14 246 190 14 246 190 14 246 190 14
42454-246 190 14 246 190 14 246 190 14 246 190 14
42455-246 190 14 246 190 14 246 190 14 242 186 14
42456-234 174 13 213 154 11 154 122 46 66 66 66
42457- 30 30 30 10 10 10 0 0 0 0 0 0
42458- 0 0 0 0 0 0 0 0 0 0 0 0
42459- 0 0 0 0 0 0 0 0 0 0 0 0
42460- 0 0 0 0 0 0 6 6 6 22 22 22
42461- 58 58 58 154 121 60 206 145 10 234 174 13
42462-242 186 14 246 186 14 246 190 14 246 190 14
42463-246 190 14 246 190 14 246 190 14 246 190 14
42464-246 190 14 246 190 14 246 190 14 246 190 14
42465-246 190 14 246 190 14 246 190 14 246 190 14
42466-246 186 14 236 178 12 210 162 10 163 110 8
42467- 61 42 6 138 138 138 218 218 218 250 250 250
42468-253 253 253 253 253 253 253 253 253 250 250 250
42469-242 242 242 210 210 210 144 144 144 66 66 66
42470- 6 6 6 2 2 6 2 2 6 2 2 6
42471- 2 2 6 2 2 6 61 42 6 163 110 8
42472-216 158 10 236 178 12 246 190 14 246 190 14
42473-246 190 14 246 190 14 246 190 14 246 190 14
42474-246 190 14 246 190 14 246 190 14 246 190 14
42475-246 190 14 239 182 13 230 174 11 216 158 10
42476-190 142 34 124 112 88 70 70 70 38 38 38
42477- 18 18 18 6 6 6 0 0 0 0 0 0
42478- 0 0 0 0 0 0 0 0 0 0 0 0
42479- 0 0 0 0 0 0 0 0 0 0 0 0
42480- 0 0 0 0 0 0 6 6 6 22 22 22
42481- 62 62 62 168 124 44 206 145 10 224 166 10
42482-236 178 12 239 182 13 242 186 14 242 186 14
42483-246 186 14 246 190 14 246 190 14 246 190 14
42484-246 190 14 246 190 14 246 190 14 246 190 14
42485-246 190 14 246 190 14 246 190 14 246 190 14
42486-246 190 14 236 178 12 216 158 10 175 118 6
42487- 80 54 7 2 2 6 6 6 6 30 30 30
42488- 54 54 54 62 62 62 50 50 50 38 38 38
42489- 14 14 14 2 2 6 2 2 6 2 2 6
42490- 2 2 6 2 2 6 2 2 6 2 2 6
42491- 2 2 6 6 6 6 80 54 7 167 114 7
42492-213 154 11 236 178 12 246 190 14 246 190 14
42493-246 190 14 246 190 14 246 190 14 246 190 14
42494-246 190 14 242 186 14 239 182 13 239 182 13
42495-230 174 11 210 150 10 174 135 50 124 112 88
42496- 82 82 82 54 54 54 34 34 34 18 18 18
42497- 6 6 6 0 0 0 0 0 0 0 0 0
42498- 0 0 0 0 0 0 0 0 0 0 0 0
42499- 0 0 0 0 0 0 0 0 0 0 0 0
42500- 0 0 0 0 0 0 6 6 6 18 18 18
42501- 50 50 50 158 118 36 192 133 9 200 144 11
42502-216 158 10 219 162 10 224 166 10 226 170 11
42503-230 174 11 236 178 12 239 182 13 239 182 13
42504-242 186 14 246 186 14 246 190 14 246 190 14
42505-246 190 14 246 190 14 246 190 14 246 190 14
42506-246 186 14 230 174 11 210 150 10 163 110 8
42507-104 69 6 10 10 10 2 2 6 2 2 6
42508- 2 2 6 2 2 6 2 2 6 2 2 6
42509- 2 2 6 2 2 6 2 2 6 2 2 6
42510- 2 2 6 2 2 6 2 2 6 2 2 6
42511- 2 2 6 6 6 6 91 60 6 167 114 7
42512-206 145 10 230 174 11 242 186 14 246 190 14
42513-246 190 14 246 190 14 246 186 14 242 186 14
42514-239 182 13 230 174 11 224 166 10 213 154 11
42515-180 133 36 124 112 88 86 86 86 58 58 58
42516- 38 38 38 22 22 22 10 10 10 6 6 6
42517- 0 0 0 0 0 0 0 0 0 0 0 0
42518- 0 0 0 0 0 0 0 0 0 0 0 0
42519- 0 0 0 0 0 0 0 0 0 0 0 0
42520- 0 0 0 0 0 0 0 0 0 14 14 14
42521- 34 34 34 70 70 70 138 110 50 158 118 36
42522-167 114 7 180 123 7 192 133 9 197 138 11
42523-200 144 11 206 145 10 213 154 11 219 162 10
42524-224 166 10 230 174 11 239 182 13 242 186 14
42525-246 186 14 246 186 14 246 186 14 246 186 14
42526-239 182 13 216 158 10 185 133 11 152 99 6
42527-104 69 6 18 14 6 2 2 6 2 2 6
42528- 2 2 6 2 2 6 2 2 6 2 2 6
42529- 2 2 6 2 2 6 2 2 6 2 2 6
42530- 2 2 6 2 2 6 2 2 6 2 2 6
42531- 2 2 6 6 6 6 80 54 7 152 99 6
42532-192 133 9 219 162 10 236 178 12 239 182 13
42533-246 186 14 242 186 14 239 182 13 236 178 12
42534-224 166 10 206 145 10 192 133 9 154 121 60
42535- 94 94 94 62 62 62 42 42 42 22 22 22
42536- 14 14 14 6 6 6 0 0 0 0 0 0
42537- 0 0 0 0 0 0 0 0 0 0 0 0
42538- 0 0 0 0 0 0 0 0 0 0 0 0
42539- 0 0 0 0 0 0 0 0 0 0 0 0
42540- 0 0 0 0 0 0 0 0 0 6 6 6
42541- 18 18 18 34 34 34 58 58 58 78 78 78
42542-101 98 89 124 112 88 142 110 46 156 107 11
42543-163 110 8 167 114 7 175 118 6 180 123 7
42544-185 133 11 197 138 11 210 150 10 219 162 10
42545-226 170 11 236 178 12 236 178 12 234 174 13
42546-219 162 10 197 138 11 163 110 8 130 83 6
42547- 91 60 6 10 10 10 2 2 6 2 2 6
42548- 18 18 18 38 38 38 38 38 38 38 38 38
42549- 38 38 38 38 38 38 38 38 38 38 38 38
42550- 38 38 38 38 38 38 26 26 26 2 2 6
42551- 2 2 6 6 6 6 70 47 6 137 92 6
42552-175 118 6 200 144 11 219 162 10 230 174 11
42553-234 174 13 230 174 11 219 162 10 210 150 10
42554-192 133 9 163 110 8 124 112 88 82 82 82
42555- 50 50 50 30 30 30 14 14 14 6 6 6
42556- 0 0 0 0 0 0 0 0 0 0 0 0
42557- 0 0 0 0 0 0 0 0 0 0 0 0
42558- 0 0 0 0 0 0 0 0 0 0 0 0
42559- 0 0 0 0 0 0 0 0 0 0 0 0
42560- 0 0 0 0 0 0 0 0 0 0 0 0
42561- 6 6 6 14 14 14 22 22 22 34 34 34
42562- 42 42 42 58 58 58 74 74 74 86 86 86
42563-101 98 89 122 102 70 130 98 46 121 87 25
42564-137 92 6 152 99 6 163 110 8 180 123 7
42565-185 133 11 197 138 11 206 145 10 200 144 11
42566-180 123 7 156 107 11 130 83 6 104 69 6
42567- 50 34 6 54 54 54 110 110 110 101 98 89
42568- 86 86 86 82 82 82 78 78 78 78 78 78
42569- 78 78 78 78 78 78 78 78 78 78 78 78
42570- 78 78 78 82 82 82 86 86 86 94 94 94
42571-106 106 106 101 101 101 86 66 34 124 80 6
42572-156 107 11 180 123 7 192 133 9 200 144 11
42573-206 145 10 200 144 11 192 133 9 175 118 6
42574-139 102 15 109 106 95 70 70 70 42 42 42
42575- 22 22 22 10 10 10 0 0 0 0 0 0
42576- 0 0 0 0 0 0 0 0 0 0 0 0
42577- 0 0 0 0 0 0 0 0 0 0 0 0
42578- 0 0 0 0 0 0 0 0 0 0 0 0
42579- 0 0 0 0 0 0 0 0 0 0 0 0
42580- 0 0 0 0 0 0 0 0 0 0 0 0
42581- 0 0 0 0 0 0 6 6 6 10 10 10
42582- 14 14 14 22 22 22 30 30 30 38 38 38
42583- 50 50 50 62 62 62 74 74 74 90 90 90
42584-101 98 89 112 100 78 121 87 25 124 80 6
42585-137 92 6 152 99 6 152 99 6 152 99 6
42586-138 86 6 124 80 6 98 70 6 86 66 30
42587-101 98 89 82 82 82 58 58 58 46 46 46
42588- 38 38 38 34 34 34 34 34 34 34 34 34
42589- 34 34 34 34 34 34 34 34 34 34 34 34
42590- 34 34 34 34 34 34 38 38 38 42 42 42
42591- 54 54 54 82 82 82 94 86 76 91 60 6
42592-134 86 6 156 107 11 167 114 7 175 118 6
42593-175 118 6 167 114 7 152 99 6 121 87 25
42594-101 98 89 62 62 62 34 34 34 18 18 18
42595- 6 6 6 0 0 0 0 0 0 0 0 0
42596- 0 0 0 0 0 0 0 0 0 0 0 0
42597- 0 0 0 0 0 0 0 0 0 0 0 0
42598- 0 0 0 0 0 0 0 0 0 0 0 0
42599- 0 0 0 0 0 0 0 0 0 0 0 0
42600- 0 0 0 0 0 0 0 0 0 0 0 0
42601- 0 0 0 0 0 0 0 0 0 0 0 0
42602- 0 0 0 6 6 6 6 6 6 10 10 10
42603- 18 18 18 22 22 22 30 30 30 42 42 42
42604- 50 50 50 66 66 66 86 86 86 101 98 89
42605-106 86 58 98 70 6 104 69 6 104 69 6
42606-104 69 6 91 60 6 82 62 34 90 90 90
42607- 62 62 62 38 38 38 22 22 22 14 14 14
42608- 10 10 10 10 10 10 10 10 10 10 10 10
42609- 10 10 10 10 10 10 6 6 6 10 10 10
42610- 10 10 10 10 10 10 10 10 10 14 14 14
42611- 22 22 22 42 42 42 70 70 70 89 81 66
42612- 80 54 7 104 69 6 124 80 6 137 92 6
42613-134 86 6 116 81 8 100 82 52 86 86 86
42614- 58 58 58 30 30 30 14 14 14 6 6 6
42615- 0 0 0 0 0 0 0 0 0 0 0 0
42616- 0 0 0 0 0 0 0 0 0 0 0 0
42617- 0 0 0 0 0 0 0 0 0 0 0 0
42618- 0 0 0 0 0 0 0 0 0 0 0 0
42619- 0 0 0 0 0 0 0 0 0 0 0 0
42620- 0 0 0 0 0 0 0 0 0 0 0 0
42621- 0 0 0 0 0 0 0 0 0 0 0 0
42622- 0 0 0 0 0 0 0 0 0 0 0 0
42623- 0 0 0 6 6 6 10 10 10 14 14 14
42624- 18 18 18 26 26 26 38 38 38 54 54 54
42625- 70 70 70 86 86 86 94 86 76 89 81 66
42626- 89 81 66 86 86 86 74 74 74 50 50 50
42627- 30 30 30 14 14 14 6 6 6 0 0 0
42628- 0 0 0 0 0 0 0 0 0 0 0 0
42629- 0 0 0 0 0 0 0 0 0 0 0 0
42630- 0 0 0 0 0 0 0 0 0 0 0 0
42631- 6 6 6 18 18 18 34 34 34 58 58 58
42632- 82 82 82 89 81 66 89 81 66 89 81 66
42633- 94 86 66 94 86 76 74 74 74 50 50 50
42634- 26 26 26 14 14 14 6 6 6 0 0 0
42635- 0 0 0 0 0 0 0 0 0 0 0 0
42636- 0 0 0 0 0 0 0 0 0 0 0 0
42637- 0 0 0 0 0 0 0 0 0 0 0 0
42638- 0 0 0 0 0 0 0 0 0 0 0 0
42639- 0 0 0 0 0 0 0 0 0 0 0 0
42640- 0 0 0 0 0 0 0 0 0 0 0 0
42641- 0 0 0 0 0 0 0 0 0 0 0 0
42642- 0 0 0 0 0 0 0 0 0 0 0 0
42643- 0 0 0 0 0 0 0 0 0 0 0 0
42644- 6 6 6 6 6 6 14 14 14 18 18 18
42645- 30 30 30 38 38 38 46 46 46 54 54 54
42646- 50 50 50 42 42 42 30 30 30 18 18 18
42647- 10 10 10 0 0 0 0 0 0 0 0 0
42648- 0 0 0 0 0 0 0 0 0 0 0 0
42649- 0 0 0 0 0 0 0 0 0 0 0 0
42650- 0 0 0 0 0 0 0 0 0 0 0 0
42651- 0 0 0 6 6 6 14 14 14 26 26 26
42652- 38 38 38 50 50 50 58 58 58 58 58 58
42653- 54 54 54 42 42 42 30 30 30 18 18 18
42654- 10 10 10 0 0 0 0 0 0 0 0 0
42655- 0 0 0 0 0 0 0 0 0 0 0 0
42656- 0 0 0 0 0 0 0 0 0 0 0 0
42657- 0 0 0 0 0 0 0 0 0 0 0 0
42658- 0 0 0 0 0 0 0 0 0 0 0 0
42659- 0 0 0 0 0 0 0 0 0 0 0 0
42660- 0 0 0 0 0 0 0 0 0 0 0 0
42661- 0 0 0 0 0 0 0 0 0 0 0 0
42662- 0 0 0 0 0 0 0 0 0 0 0 0
42663- 0 0 0 0 0 0 0 0 0 0 0 0
42664- 0 0 0 0 0 0 0 0 0 6 6 6
42665- 6 6 6 10 10 10 14 14 14 18 18 18
42666- 18 18 18 14 14 14 10 10 10 6 6 6
42667- 0 0 0 0 0 0 0 0 0 0 0 0
42668- 0 0 0 0 0 0 0 0 0 0 0 0
42669- 0 0 0 0 0 0 0 0 0 0 0 0
42670- 0 0 0 0 0 0 0 0 0 0 0 0
42671- 0 0 0 0 0 0 0 0 0 6 6 6
42672- 14 14 14 18 18 18 22 22 22 22 22 22
42673- 18 18 18 14 14 14 10 10 10 6 6 6
42674- 0 0 0 0 0 0 0 0 0 0 0 0
42675- 0 0 0 0 0 0 0 0 0 0 0 0
42676- 0 0 0 0 0 0 0 0 0 0 0 0
42677- 0 0 0 0 0 0 0 0 0 0 0 0
42678- 0 0 0 0 0 0 0 0 0 0 0 0
42679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42683+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42690+4 4 4 4 4 4 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
42693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42697+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
42702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
42707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42711+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42720+4 4 4 4 4 4
42721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42725+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
42729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42734+4 4 4 4 4 4
42735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42739+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
42743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42748+4 4 4 4 4 4
42749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42753+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
42757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42762+4 4 4 4 4 4
42763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42767+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
42768+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42772+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
42773+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42774+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
42775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42776+4 4 4 4 4 4
42777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42781+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
42782+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
42783+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42786+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
42787+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
42788+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
42789+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42790+4 4 4 4 4 4
42791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42795+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
42796+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
42797+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42800+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
42801+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
42802+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
42803+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
42804+4 4 4 4 4 4
42805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42808+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
42809+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
42810+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
42811+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
42812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42813+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42814+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
42815+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
42816+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
42817+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
42818+4 4 4 4 4 4
42819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42822+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
42823+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
42824+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
42825+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
42826+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42827+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
42828+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
42829+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
42830+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
42831+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
42832+4 4 4 4 4 4
42833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42836+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
42837+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
42838+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
42839+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
42840+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42841+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
42842+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
42843+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
42844+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
42845+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
42846+4 4 4 4 4 4
42847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42849+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
42850+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
42851+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
42852+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
42853+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
42854+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
42855+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
42856+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
42857+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
42858+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
42859+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
42860+4 4 4 4 4 4
42861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42863+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
42864+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
42865+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
42866+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
42867+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
42868+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
42869+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
42870+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
42871+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
42872+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
42873+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
42874+4 4 4 4 4 4
42875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42877+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
42878+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
42879+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
42880+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
42881+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
42882+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
42883+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
42884+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
42885+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
42886+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
42887+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
42888+4 4 4 4 4 4
42889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42891+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
42892+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
42893+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
42894+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
42895+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
42896+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
42897+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
42898+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
42899+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
42900+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
42901+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
42902+4 4 4 4 4 4
42903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42904+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
42905+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
42906+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
42907+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
42908+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
42909+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
42910+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
42911+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
42912+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
42913+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
42914+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
42915+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
42916+4 4 4 4 4 4
42917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42918+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
42919+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
42920+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
42921+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42922+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
42923+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
42924+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
42925+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
42926+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
42927+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
42928+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
42929+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
42930+0 0 0 4 4 4
42931+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
42932+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
42933+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
42934+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
42935+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
42936+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
42937+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
42938+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
42939+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
42940+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
42941+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
42942+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
42943+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
42944+2 0 0 0 0 0
42945+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
42946+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
42947+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
42948+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
42949+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
42950+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
42951+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
42952+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
42953+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
42954+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
42955+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
42956+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
42957+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
42958+37 38 37 0 0 0
42959+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
42960+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
42961+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
42962+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
42963+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
42964+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
42965+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
42966+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
42967+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
42968+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
42969+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
42970+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
42971+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
42972+85 115 134 4 0 0
42973+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
42974+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
42975+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
42976+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
42977+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
42978+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
42979+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
42980+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
42981+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
42982+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
42983+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
42984+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
42985+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
42986+60 73 81 4 0 0
42987+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
42988+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
42989+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
42990+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
42991+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
42992+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
42993+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
42994+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
42995+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
42996+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
42997+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
42998+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
42999+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
43000+16 19 21 4 0 0
43001+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
43002+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
43003+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
43004+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
43005+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
43006+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
43007+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
43008+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
43009+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
43010+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
43011+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
43012+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
43013+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
43014+4 0 0 4 3 3
43015+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
43016+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
43017+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
43018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
43019+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
43020+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
43021+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
43022+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
43023+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
43024+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
43025+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
43026+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
43027+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
43028+3 2 2 4 4 4
43029+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
43030+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
43031+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
43032+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
43033+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
43034+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
43035+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
43036+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
43037+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
43038+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
43039+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
43040+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
43041+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
43042+4 4 4 4 4 4
43043+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
43044+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
43045+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
43046+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
43047+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
43048+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
43049+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
43050+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
43051+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
43052+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
43053+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
43054+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
43055+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
43056+4 4 4 4 4 4
43057+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
43058+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
43059+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
43060+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
43061+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
43062+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43063+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
43064+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
43065+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
43066+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
43067+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
43068+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
43069+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
43070+5 5 5 5 5 5
43071+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
43072+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
43073+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
43074+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
43075+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
43076+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43077+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
43078+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
43079+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
43080+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
43081+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
43082+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
43083+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
43084+5 5 5 4 4 4
43085+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
43086+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
43087+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
43088+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
43089+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43090+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
43091+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
43092+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
43093+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
43094+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
43095+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
43096+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43098+4 4 4 4 4 4
43099+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
43100+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
43101+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
43102+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
43103+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
43104+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43105+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43106+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
43107+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
43108+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
43109+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
43110+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
43111+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43112+4 4 4 4 4 4
43113+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
43114+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
43115+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
43116+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
43117+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43118+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
43119+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
43120+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
43121+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
43122+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
43123+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
43124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43125+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43126+4 4 4 4 4 4
43127+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
43128+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
43129+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
43130+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
43131+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43132+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43133+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
43134+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
43135+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
43136+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
43137+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
43138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43139+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43140+4 4 4 4 4 4
43141+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
43142+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
43143+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
43144+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
43145+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43146+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
43147+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
43148+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
43149+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
43150+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
43151+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43153+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43154+4 4 4 4 4 4
43155+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
43156+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
43157+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
43158+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
43159+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
43160+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
43161+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
43162+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
43163+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
43164+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
43165+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
43166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43167+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43168+4 4 4 4 4 4
43169+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
43170+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
43171+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
43172+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
43173+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
43174+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
43175+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
43176+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
43177+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
43178+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
43179+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
43180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43181+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43182+4 4 4 4 4 4
43183+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
43184+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
43185+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
43186+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43187+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
43188+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
43189+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
43190+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
43191+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
43192+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
43193+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43195+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43196+4 4 4 4 4 4
43197+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
43198+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
43199+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
43200+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43201+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43202+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
43203+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
43204+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
43205+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
43206+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
43207+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43209+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43210+4 4 4 4 4 4
43211+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
43212+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
43213+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43214+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
43215+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43216+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
43217+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
43218+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
43219+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
43220+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
43221+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43223+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43224+4 4 4 4 4 4
43225+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
43226+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
43227+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43228+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
43229+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43230+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
43231+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
43232+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
43233+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43234+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43235+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43238+4 4 4 4 4 4
43239+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43240+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
43241+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
43242+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
43243+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
43244+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
43245+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
43246+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
43247+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43248+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43249+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43251+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43252+4 4 4 4 4 4
43253+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
43254+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
43255+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
43256+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
43257+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43258+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
43259+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
43260+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
43261+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43262+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43263+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43265+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43266+4 4 4 4 4 4
43267+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
43268+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
43269+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43270+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
43271+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
43272+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
43273+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
43274+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
43275+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43276+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43277+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43279+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43280+4 4 4 4 4 4
43281+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
43282+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
43283+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43284+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
43285+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
43286+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
43287+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
43288+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
43289+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
43290+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43291+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43294+4 4 4 4 4 4
43295+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43296+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
43297+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
43298+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
43299+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
43300+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
43301+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
43302+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
43303+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43304+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43305+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43308+4 4 4 4 4 4
43309+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
43310+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
43311+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43312+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
43313+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
43314+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
43315+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
43316+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
43317+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
43318+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43319+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43322+4 4 4 4 4 4
43323+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
43324+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
43325+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
43326+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
43327+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
43328+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
43329+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
43330+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
43331+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43332+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43333+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43336+4 4 4 4 4 4
43337+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43338+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
43339+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
43340+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
43341+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
43342+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
43343+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
43344+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
43345+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43346+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43347+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43350+4 4 4 4 4 4
43351+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43352+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
43353+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
43354+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
43355+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
43356+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
43357+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43358+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
43359+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
43360+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43361+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43364+4 4 4 4 4 4
43365+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43366+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
43367+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
43368+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43369+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
43370+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
43371+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
43372+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
43373+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
43374+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43375+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43378+4 4 4 4 4 4
43379+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
43380+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
43381+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
43382+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
43383+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
43384+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
43385+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
43386+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
43387+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
43388+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43389+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43391+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43392+4 4 4 4 4 4
43393+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43394+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
43395+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
43396+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
43397+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
43398+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
43399+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
43400+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
43401+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
43402+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43403+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43405+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43406+4 4 4 4 4 4
43407+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
43408+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
43409+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
43410+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
43411+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
43412+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
43413+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
43414+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
43415+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
43416+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43417+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43419+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43420+4 4 4 4 4 4
43421+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
43422+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
43423+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
43424+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
43425+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
43426+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
43427+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
43428+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
43429+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
43430+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
43431+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43433+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43434+4 4 4 4 4 4
43435+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
43436+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
43437+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
43438+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
43439+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
43440+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
43441+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
43442+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
43443+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
43444+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
43445+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43447+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43448+4 4 4 4 4 4
43449+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
43450+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43451+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
43452+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
43453+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
43454+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
43455+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
43456+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
43457+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
43458+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
43459+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43461+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43462+4 4 4 4 4 4
43463+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
43464+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
43465+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
43466+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
43467+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
43468+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
43469+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43470+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
43471+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
43472+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
43473+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43475+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43476+4 4 4 4 4 4
43477+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
43478+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
43479+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
43480+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
43481+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
43482+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
43483+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
43484+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
43485+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
43486+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
43487+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43489+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43490+4 4 4 4 4 4
43491+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
43492+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
43493+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43494+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
43495+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
43496+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
43497+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
43498+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
43499+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
43500+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
43501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43503+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43504+4 4 4 4 4 4
43505+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43506+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
43507+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
43508+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
43509+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
43510+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
43511+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
43512+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
43513+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
43514+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43517+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43518+4 4 4 4 4 4
43519+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
43520+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
43521+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
43522+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
43523+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
43524+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
43525+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
43526+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
43527+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
43528+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
43529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43531+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43532+4 4 4 4 4 4
43533+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
43534+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
43535+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
43536+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
43537+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
43538+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
43539+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
43540+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
43541+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
43542+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
43543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43545+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43546+4 4 4 4 4 4
43547+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
43548+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43549+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
43550+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
43551+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
43552+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
43553+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
43554+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
43555+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
43556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43559+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43560+4 4 4 4 4 4
43561+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
43562+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
43563+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
43564+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
43565+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
43566+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
43567+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
43568+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
43569+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
43570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
43575+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43576+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
43577+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
43578+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
43579+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
43580+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
43581+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
43582+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
43583+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
43589+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
43590+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
43591+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43592+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
43593+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
43594+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
43595+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
43596+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
43597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
43603+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43604+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
43605+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
43606+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
43607+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
43608+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
43609+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
43610+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
43611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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
43617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43618+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
43619+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43620+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
43621+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
43622+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
43623+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
43624+4 0 0 4 3 3 6 6 6 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 4 4 4
43626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43628+4 4 4 4 4 4 4 4 4 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
43631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43632+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
43633+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
43634+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
43635+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
43636+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
43637+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
43638+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43642+4 4 4 4 4 4 4 4 4 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
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 5 5 5 5 5 5 5 5 5
43647+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
43648+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43649+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
43650+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
43651+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
43652+5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43656+4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43662+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
43663+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
43664+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
43665+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
43666+4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4
43669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 5 5 5
43676+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43677+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
43678+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
43679+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4
43683+4 4 4 4 4 4 4 4 4 4 4 4 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
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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
43691+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
43692+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
43693+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
43694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43700+4 4 4 4 4 4
43701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43704+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
43705+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
43706+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
43707+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
43708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43714+4 4 4 4 4 4
43715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43718+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
43719+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
43720+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
43721+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
43722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43728+4 4 4 4 4 4
43729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
43733+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
43734+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
43735+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
43736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43742+4 4 4 4 4 4
43743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43747+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
43748+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
43749+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
43750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43756+4 4 4 4 4 4
43757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43761+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
43762+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
43763+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43770+4 4 4 4 4 4
43771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43775+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
43776+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
43777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43784+4 4 4 4 4 4
43785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43789+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
43790+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
43791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
43798+4 4 4 4 4 4
43799diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
43800index 86d449e..af6a7f7 100644
43801--- a/drivers/video/udlfb.c
43802+++ b/drivers/video/udlfb.c
43803@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
43804 dlfb_urb_completion(urb);
43805
43806 error:
43807- atomic_add(bytes_sent, &dev->bytes_sent);
43808- atomic_add(bytes_identical, &dev->bytes_identical);
43809- atomic_add(width*height*2, &dev->bytes_rendered);
43810+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43811+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43812+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
43813 end_cycles = get_cycles();
43814- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43815+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43816 >> 10)), /* Kcycles */
43817 &dev->cpu_kcycles_used);
43818
43819@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
43820 dlfb_urb_completion(urb);
43821
43822 error:
43823- atomic_add(bytes_sent, &dev->bytes_sent);
43824- atomic_add(bytes_identical, &dev->bytes_identical);
43825- atomic_add(bytes_rendered, &dev->bytes_rendered);
43826+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
43827+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
43828+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
43829 end_cycles = get_cycles();
43830- atomic_add(((unsigned int) ((end_cycles - start_cycles)
43831+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
43832 >> 10)), /* Kcycles */
43833 &dev->cpu_kcycles_used);
43834 }
43835@@ -1372,7 +1372,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
43836 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43837 struct dlfb_data *dev = fb_info->par;
43838 return snprintf(buf, PAGE_SIZE, "%u\n",
43839- atomic_read(&dev->bytes_rendered));
43840+ atomic_read_unchecked(&dev->bytes_rendered));
43841 }
43842
43843 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43844@@ -1380,7 +1380,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
43845 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43846 struct dlfb_data *dev = fb_info->par;
43847 return snprintf(buf, PAGE_SIZE, "%u\n",
43848- atomic_read(&dev->bytes_identical));
43849+ atomic_read_unchecked(&dev->bytes_identical));
43850 }
43851
43852 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43853@@ -1388,7 +1388,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
43854 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43855 struct dlfb_data *dev = fb_info->par;
43856 return snprintf(buf, PAGE_SIZE, "%u\n",
43857- atomic_read(&dev->bytes_sent));
43858+ atomic_read_unchecked(&dev->bytes_sent));
43859 }
43860
43861 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43862@@ -1396,7 +1396,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
43863 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43864 struct dlfb_data *dev = fb_info->par;
43865 return snprintf(buf, PAGE_SIZE, "%u\n",
43866- atomic_read(&dev->cpu_kcycles_used));
43867+ atomic_read_unchecked(&dev->cpu_kcycles_used));
43868 }
43869
43870 static ssize_t edid_show(
43871@@ -1456,10 +1456,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
43872 struct fb_info *fb_info = dev_get_drvdata(fbdev);
43873 struct dlfb_data *dev = fb_info->par;
43874
43875- atomic_set(&dev->bytes_rendered, 0);
43876- atomic_set(&dev->bytes_identical, 0);
43877- atomic_set(&dev->bytes_sent, 0);
43878- atomic_set(&dev->cpu_kcycles_used, 0);
43879+ atomic_set_unchecked(&dev->bytes_rendered, 0);
43880+ atomic_set_unchecked(&dev->bytes_identical, 0);
43881+ atomic_set_unchecked(&dev->bytes_sent, 0);
43882+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
43883
43884 return count;
43885 }
43886diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
43887index 2f8f82d..191de37 100644
43888--- a/drivers/video/uvesafb.c
43889+++ b/drivers/video/uvesafb.c
43890@@ -19,6 +19,7 @@
43891 #include <linux/io.h>
43892 #include <linux/mutex.h>
43893 #include <linux/slab.h>
43894+#include <linux/moduleloader.h>
43895 #include <video/edid.h>
43896 #include <video/uvesafb.h>
43897 #ifdef CONFIG_X86
43898@@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
43899 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
43900 par->pmi_setpal = par->ypan = 0;
43901 } else {
43902+
43903+#ifdef CONFIG_PAX_KERNEXEC
43904+#ifdef CONFIG_MODULES
43905+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
43906+#endif
43907+ if (!par->pmi_code) {
43908+ par->pmi_setpal = par->ypan = 0;
43909+ return 0;
43910+ }
43911+#endif
43912+
43913 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
43914 + task->t.regs.edi);
43915+
43916+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43917+ pax_open_kernel();
43918+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
43919+ pax_close_kernel();
43920+
43921+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
43922+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
43923+#else
43924 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
43925 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
43926+#endif
43927+
43928 printk(KERN_INFO "uvesafb: protected mode interface info at "
43929 "%04x:%04x\n",
43930 (u16)task->t.regs.es, (u16)task->t.regs.edi);
43931@@ -818,13 +841,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
43932 par->ypan = ypan;
43933
43934 if (par->pmi_setpal || par->ypan) {
43935+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
43936 if (__supported_pte_mask & _PAGE_NX) {
43937 par->pmi_setpal = par->ypan = 0;
43938 printk(KERN_WARNING "uvesafb: NX protection is actively."
43939 "We have better not to use the PMI.\n");
43940- } else {
43941+ } else
43942+#endif
43943 uvesafb_vbe_getpmi(task, par);
43944- }
43945 }
43946 #else
43947 /* The protected mode interface is not available on non-x86. */
43948@@ -1838,6 +1862,11 @@ out:
43949 if (par->vbe_modes)
43950 kfree(par->vbe_modes);
43951
43952+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43953+ if (par->pmi_code)
43954+ module_free_exec(NULL, par->pmi_code);
43955+#endif
43956+
43957 framebuffer_release(info);
43958 return err;
43959 }
43960@@ -1864,6 +1893,12 @@ static int uvesafb_remove(struct platform_device *dev)
43961 kfree(par->vbe_state_orig);
43962 if (par->vbe_state_saved)
43963 kfree(par->vbe_state_saved);
43964+
43965+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
43966+ if (par->pmi_code)
43967+ module_free_exec(NULL, par->pmi_code);
43968+#endif
43969+
43970 }
43971
43972 framebuffer_release(info);
43973diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
43974index 501b340..86bd4cf 100644
43975--- a/drivers/video/vesafb.c
43976+++ b/drivers/video/vesafb.c
43977@@ -9,6 +9,7 @@
43978 */
43979
43980 #include <linux/module.h>
43981+#include <linux/moduleloader.h>
43982 #include <linux/kernel.h>
43983 #include <linux/errno.h>
43984 #include <linux/string.h>
43985@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
43986 static int vram_total __initdata; /* Set total amount of memory */
43987 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
43988 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
43989-static void (*pmi_start)(void) __read_mostly;
43990-static void (*pmi_pal) (void) __read_mostly;
43991+static void (*pmi_start)(void) __read_only;
43992+static void (*pmi_pal) (void) __read_only;
43993 static int depth __read_mostly;
43994 static int vga_compat __read_mostly;
43995 /* --------------------------------------------------------------------- */
43996@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
43997 unsigned int size_vmode;
43998 unsigned int size_remap;
43999 unsigned int size_total;
44000+ void *pmi_code = NULL;
44001
44002 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
44003 return -ENODEV;
44004@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
44005 size_remap = size_total;
44006 vesafb_fix.smem_len = size_remap;
44007
44008-#ifndef __i386__
44009- screen_info.vesapm_seg = 0;
44010-#endif
44011-
44012 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
44013 printk(KERN_WARNING
44014 "vesafb: cannot reserve video memory at 0x%lx\n",
44015@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
44016 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
44017 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
44018
44019+#ifdef __i386__
44020+
44021+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44022+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
44023+ if (!pmi_code)
44024+#elif !defined(CONFIG_PAX_KERNEXEC)
44025+ if (0)
44026+#endif
44027+
44028+#endif
44029+ screen_info.vesapm_seg = 0;
44030+
44031 if (screen_info.vesapm_seg) {
44032- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
44033- screen_info.vesapm_seg,screen_info.vesapm_off);
44034+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
44035+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
44036 }
44037
44038 if (screen_info.vesapm_seg < 0xc000)
44039@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
44040
44041 if (ypan || pmi_setpal) {
44042 unsigned short *pmi_base;
44043+
44044 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
44045- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
44046- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
44047+
44048+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44049+ pax_open_kernel();
44050+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
44051+#else
44052+ pmi_code = pmi_base;
44053+#endif
44054+
44055+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
44056+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
44057+
44058+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44059+ pmi_start = ktva_ktla(pmi_start);
44060+ pmi_pal = ktva_ktla(pmi_pal);
44061+ pax_close_kernel();
44062+#endif
44063+
44064 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
44065 if (pmi_base[3]) {
44066 printk(KERN_INFO "vesafb: pmi: ports = ");
44067@@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
44068 info->node, info->fix.id);
44069 return 0;
44070 err:
44071+
44072+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
44073+ module_free_exec(NULL, pmi_code);
44074+#endif
44075+
44076 if (info->screen_base)
44077 iounmap(info->screen_base);
44078 framebuffer_release(info);
44079diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
44080index 88714ae..16c2e11 100644
44081--- a/drivers/video/via/via_clock.h
44082+++ b/drivers/video/via/via_clock.h
44083@@ -56,7 +56,7 @@ struct via_clock {
44084
44085 void (*set_engine_pll_state)(u8 state);
44086 void (*set_engine_pll)(struct via_pll_config config);
44087-};
44088+} __no_const;
44089
44090
44091 static inline u32 get_pll_internal_frequency(u32 ref_freq,
44092diff --git a/drivers/virtio/virtio_mmio.c b/drivers/virtio/virtio_mmio.c
44093index 6b1b7e1..b2fa4d5 100644
44094--- a/drivers/virtio/virtio_mmio.c
44095+++ b/drivers/virtio/virtio_mmio.c
44096@@ -530,7 +530,7 @@ static int vm_cmdline_set(const char *device,
44097
44098 resources[0].end = memparse(device, &str) - 1;
44099
44100- processed = sscanf(str, "@%lli:%u%n:%d%n",
44101+ processed = sscanf(str, "@%lli:%llu%n:%d%n",
44102 &base, &resources[1].start, &consumed,
44103 &vm_cmdline_id, &consumed);
44104
44105diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
44106index fef20db..d28b1ab 100644
44107--- a/drivers/xen/xenfs/xenstored.c
44108+++ b/drivers/xen/xenfs/xenstored.c
44109@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
44110 static int xsd_kva_open(struct inode *inode, struct file *file)
44111 {
44112 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
44113+#ifdef CONFIG_GRKERNSEC_HIDESYM
44114+ NULL);
44115+#else
44116 xen_store_interface);
44117+#endif
44118+
44119 if (!file->private_data)
44120 return -ENOMEM;
44121 return 0;
44122diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
44123index 890bed5..17ae73e 100644
44124--- a/fs/9p/vfs_inode.c
44125+++ b/fs/9p/vfs_inode.c
44126@@ -1329,7 +1329,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
44127 void
44128 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44129 {
44130- char *s = nd_get_link(nd);
44131+ const char *s = nd_get_link(nd);
44132
44133 p9_debug(P9_DEBUG_VFS, " %s %s\n",
44134 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
44135diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
44136index 0efd152..b5802ad 100644
44137--- a/fs/Kconfig.binfmt
44138+++ b/fs/Kconfig.binfmt
44139@@ -89,7 +89,7 @@ config HAVE_AOUT
44140
44141 config BINFMT_AOUT
44142 tristate "Kernel support for a.out and ECOFF binaries"
44143- depends on HAVE_AOUT
44144+ depends on HAVE_AOUT && BROKEN
44145 ---help---
44146 A.out (Assembler.OUTput) is a set of formats for libraries and
44147 executables used in the earliest versions of UNIX. Linux used
44148diff --git a/fs/aio.c b/fs/aio.c
44149index 71f613c..9d01f1f 100644
44150--- a/fs/aio.c
44151+++ b/fs/aio.c
44152@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
44153 size += sizeof(struct io_event) * nr_events;
44154 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
44155
44156- if (nr_pages < 0)
44157+ if (nr_pages <= 0)
44158 return -EINVAL;
44159
44160 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
44161@@ -1373,18 +1373,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
44162 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44163 {
44164 ssize_t ret;
44165+ struct iovec iovstack;
44166
44167 #ifdef CONFIG_COMPAT
44168 if (compat)
44169 ret = compat_rw_copy_check_uvector(type,
44170 (struct compat_iovec __user *)kiocb->ki_buf,
44171- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44172+ kiocb->ki_nbytes, 1, &iovstack,
44173 &kiocb->ki_iovec);
44174 else
44175 #endif
44176 ret = rw_copy_check_uvector(type,
44177 (struct iovec __user *)kiocb->ki_buf,
44178- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
44179+ kiocb->ki_nbytes, 1, &iovstack,
44180 &kiocb->ki_iovec);
44181 if (ret < 0)
44182 goto out;
44183@@ -1393,6 +1394,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
44184 if (ret < 0)
44185 goto out;
44186
44187+ if (kiocb->ki_iovec == &iovstack) {
44188+ kiocb->ki_inline_vec = iovstack;
44189+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
44190+ }
44191 kiocb->ki_nr_segs = kiocb->ki_nbytes;
44192 kiocb->ki_cur_seg = 0;
44193 /* ki_nbytes/left now reflect bytes instead of segs */
44194diff --git a/fs/attr.c b/fs/attr.c
44195index cce7df5..eaa2731 100644
44196--- a/fs/attr.c
44197+++ b/fs/attr.c
44198@@ -100,6 +100,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
44199 unsigned long limit;
44200
44201 limit = rlimit(RLIMIT_FSIZE);
44202+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
44203 if (limit != RLIM_INFINITY && offset > limit)
44204 goto out_sig;
44205 if (offset > inode->i_sb->s_maxbytes)
44206diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
44207index dce436e..55e670d 100644
44208--- a/fs/autofs4/waitq.c
44209+++ b/fs/autofs4/waitq.c
44210@@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
44211 {
44212 unsigned long sigpipe, flags;
44213 mm_segment_t fs;
44214- const char *data = (const char *)addr;
44215+ const char __user *data = (const char __force_user *)addr;
44216 ssize_t wr = 0;
44217
44218 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
44219@@ -347,6 +347,10 @@ static int validate_request(struct autofs_wait_queue **wait,
44220 return 1;
44221 }
44222
44223+#ifdef CONFIG_GRKERNSEC_HIDESYM
44224+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
44225+#endif
44226+
44227 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44228 enum autofs_notify notify)
44229 {
44230@@ -380,7 +384,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
44231
44232 /* If this is a direct mount request create a dummy name */
44233 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
44234+#ifdef CONFIG_GRKERNSEC_HIDESYM
44235+ /* this name does get written to userland via autofs4_write() */
44236+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
44237+#else
44238 qstr.len = sprintf(name, "%p", dentry);
44239+#endif
44240 else {
44241 qstr.len = autofs4_getpath(sbi, dentry, &name);
44242 if (!qstr.len) {
44243diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
44244index 2b3bda8..6a2d4be 100644
44245--- a/fs/befs/linuxvfs.c
44246+++ b/fs/befs/linuxvfs.c
44247@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
44248 {
44249 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
44250 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
44251- char *link = nd_get_link(nd);
44252+ const char *link = nd_get_link(nd);
44253 if (!IS_ERR(link))
44254 kfree(link);
44255 }
44256diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
44257index 0e7a6f8..332b1ca 100644
44258--- a/fs/binfmt_aout.c
44259+++ b/fs/binfmt_aout.c
44260@@ -16,6 +16,7 @@
44261 #include <linux/string.h>
44262 #include <linux/fs.h>
44263 #include <linux/file.h>
44264+#include <linux/security.h>
44265 #include <linux/stat.h>
44266 #include <linux/fcntl.h>
44267 #include <linux/ptrace.h>
44268@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
44269 #endif
44270 # define START_STACK(u) ((void __user *)u.start_stack)
44271
44272+ memset(&dump, 0, sizeof(dump));
44273+
44274 fs = get_fs();
44275 set_fs(KERNEL_DS);
44276 has_dumped = 1;
44277@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
44278
44279 /* If the size of the dump file exceeds the rlimit, then see what would happen
44280 if we wrote the stack, but not the data area. */
44281+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
44282 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
44283 dump.u_dsize = 0;
44284
44285 /* Make sure we have enough room to write the stack and data areas. */
44286+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
44287 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
44288 dump.u_ssize = 0;
44289
44290@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44291 rlim = rlimit(RLIMIT_DATA);
44292 if (rlim >= RLIM_INFINITY)
44293 rlim = ~0;
44294+
44295+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
44296 if (ex.a_data + ex.a_bss > rlim)
44297 return -ENOMEM;
44298
44299@@ -267,6 +274,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44300
44301 install_exec_creds(bprm);
44302
44303+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44304+ current->mm->pax_flags = 0UL;
44305+#endif
44306+
44307+#ifdef CONFIG_PAX_PAGEEXEC
44308+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
44309+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
44310+
44311+#ifdef CONFIG_PAX_EMUTRAMP
44312+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
44313+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
44314+#endif
44315+
44316+#ifdef CONFIG_PAX_MPROTECT
44317+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
44318+ current->mm->pax_flags |= MF_PAX_MPROTECT;
44319+#endif
44320+
44321+ }
44322+#endif
44323+
44324 if (N_MAGIC(ex) == OMAGIC) {
44325 unsigned long text_addr, map_size;
44326 loff_t pos;
44327@@ -332,7 +360,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
44328 }
44329
44330 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
44331- PROT_READ | PROT_WRITE | PROT_EXEC,
44332+ PROT_READ | PROT_WRITE,
44333 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
44334 fd_offset + ex.a_text);
44335 if (error != N_DATADDR(ex)) {
44336diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
44337index fbd9f60..0b845dd 100644
44338--- a/fs/binfmt_elf.c
44339+++ b/fs/binfmt_elf.c
44340@@ -33,6 +33,7 @@
44341 #include <linux/elf.h>
44342 #include <linux/utsname.h>
44343 #include <linux/coredump.h>
44344+#include <linux/xattr.h>
44345 #include <asm/uaccess.h>
44346 #include <asm/param.h>
44347 #include <asm/page.h>
44348@@ -59,6 +60,10 @@ static int elf_core_dump(struct coredump_params *cprm);
44349 #define elf_core_dump NULL
44350 #endif
44351
44352+#ifdef CONFIG_PAX_MPROTECT
44353+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
44354+#endif
44355+
44356 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
44357 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
44358 #else
44359@@ -78,6 +83,11 @@ static struct linux_binfmt elf_format = {
44360 .load_binary = load_elf_binary,
44361 .load_shlib = load_elf_library,
44362 .core_dump = elf_core_dump,
44363+
44364+#ifdef CONFIG_PAX_MPROTECT
44365+ .handle_mprotect= elf_handle_mprotect,
44366+#endif
44367+
44368 .min_coredump = ELF_EXEC_PAGESIZE,
44369 };
44370
44371@@ -85,6 +95,8 @@ static struct linux_binfmt elf_format = {
44372
44373 static int set_brk(unsigned long start, unsigned long end)
44374 {
44375+ unsigned long e = end;
44376+
44377 start = ELF_PAGEALIGN(start);
44378 end = ELF_PAGEALIGN(end);
44379 if (end > start) {
44380@@ -93,7 +105,7 @@ static int set_brk(unsigned long start, unsigned long end)
44381 if (BAD_ADDR(addr))
44382 return addr;
44383 }
44384- current->mm->start_brk = current->mm->brk = end;
44385+ current->mm->start_brk = current->mm->brk = e;
44386 return 0;
44387 }
44388
44389@@ -154,12 +166,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44390 elf_addr_t __user *u_rand_bytes;
44391 const char *k_platform = ELF_PLATFORM;
44392 const char *k_base_platform = ELF_BASE_PLATFORM;
44393- unsigned char k_rand_bytes[16];
44394+ u32 k_rand_bytes[4];
44395 int items;
44396 elf_addr_t *elf_info;
44397 int ei_index = 0;
44398 const struct cred *cred = current_cred();
44399 struct vm_area_struct *vma;
44400+ unsigned long saved_auxv[AT_VECTOR_SIZE];
44401
44402 /*
44403 * In some cases (e.g. Hyper-Threading), we want to avoid L1
44404@@ -201,8 +214,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44405 * Generate 16 random bytes for userspace PRNG seeding.
44406 */
44407 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
44408- u_rand_bytes = (elf_addr_t __user *)
44409- STACK_ALLOC(p, sizeof(k_rand_bytes));
44410+ srandom32(k_rand_bytes[0] ^ random32());
44411+ srandom32(k_rand_bytes[1] ^ random32());
44412+ srandom32(k_rand_bytes[2] ^ random32());
44413+ srandom32(k_rand_bytes[3] ^ random32());
44414+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
44415+ u_rand_bytes = (elf_addr_t __user *) p;
44416 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
44417 return -EFAULT;
44418
44419@@ -314,9 +331,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
44420 return -EFAULT;
44421 current->mm->env_end = p;
44422
44423+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
44424+
44425 /* Put the elf_info on the stack in the right place. */
44426 sp = (elf_addr_t __user *)envp + 1;
44427- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
44428+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
44429 return -EFAULT;
44430 return 0;
44431 }
44432@@ -380,15 +399,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
44433 an ELF header */
44434
44435 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44436- struct file *interpreter, unsigned long *interp_map_addr,
44437- unsigned long no_base)
44438+ struct file *interpreter, unsigned long no_base)
44439 {
44440 struct elf_phdr *elf_phdata;
44441 struct elf_phdr *eppnt;
44442- unsigned long load_addr = 0;
44443+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
44444 int load_addr_set = 0;
44445 unsigned long last_bss = 0, elf_bss = 0;
44446- unsigned long error = ~0UL;
44447+ unsigned long error = -EINVAL;
44448 unsigned long total_size;
44449 int retval, i, size;
44450
44451@@ -434,6 +452,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44452 goto out_close;
44453 }
44454
44455+#ifdef CONFIG_PAX_SEGMEXEC
44456+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
44457+ pax_task_size = SEGMEXEC_TASK_SIZE;
44458+#endif
44459+
44460 eppnt = elf_phdata;
44461 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
44462 if (eppnt->p_type == PT_LOAD) {
44463@@ -457,8 +480,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44464 map_addr = elf_map(interpreter, load_addr + vaddr,
44465 eppnt, elf_prot, elf_type, total_size);
44466 total_size = 0;
44467- if (!*interp_map_addr)
44468- *interp_map_addr = map_addr;
44469 error = map_addr;
44470 if (BAD_ADDR(map_addr))
44471 goto out_close;
44472@@ -477,8 +498,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
44473 k = load_addr + eppnt->p_vaddr;
44474 if (BAD_ADDR(k) ||
44475 eppnt->p_filesz > eppnt->p_memsz ||
44476- eppnt->p_memsz > TASK_SIZE ||
44477- TASK_SIZE - eppnt->p_memsz < k) {
44478+ eppnt->p_memsz > pax_task_size ||
44479+ pax_task_size - eppnt->p_memsz < k) {
44480 error = -ENOMEM;
44481 goto out_close;
44482 }
44483@@ -530,6 +551,315 @@ out:
44484 return error;
44485 }
44486
44487+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44488+#ifdef CONFIG_PAX_SOFTMODE
44489+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
44490+{
44491+ unsigned long pax_flags = 0UL;
44492+
44493+#ifdef CONFIG_PAX_PAGEEXEC
44494+ if (elf_phdata->p_flags & PF_PAGEEXEC)
44495+ pax_flags |= MF_PAX_PAGEEXEC;
44496+#endif
44497+
44498+#ifdef CONFIG_PAX_SEGMEXEC
44499+ if (elf_phdata->p_flags & PF_SEGMEXEC)
44500+ pax_flags |= MF_PAX_SEGMEXEC;
44501+#endif
44502+
44503+#ifdef CONFIG_PAX_EMUTRAMP
44504+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
44505+ pax_flags |= MF_PAX_EMUTRAMP;
44506+#endif
44507+
44508+#ifdef CONFIG_PAX_MPROTECT
44509+ if (elf_phdata->p_flags & PF_MPROTECT)
44510+ pax_flags |= MF_PAX_MPROTECT;
44511+#endif
44512+
44513+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44514+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
44515+ pax_flags |= MF_PAX_RANDMMAP;
44516+#endif
44517+
44518+ return pax_flags;
44519+}
44520+#endif
44521+
44522+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
44523+{
44524+ unsigned long pax_flags = 0UL;
44525+
44526+#ifdef CONFIG_PAX_PAGEEXEC
44527+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
44528+ pax_flags |= MF_PAX_PAGEEXEC;
44529+#endif
44530+
44531+#ifdef CONFIG_PAX_SEGMEXEC
44532+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
44533+ pax_flags |= MF_PAX_SEGMEXEC;
44534+#endif
44535+
44536+#ifdef CONFIG_PAX_EMUTRAMP
44537+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
44538+ pax_flags |= MF_PAX_EMUTRAMP;
44539+#endif
44540+
44541+#ifdef CONFIG_PAX_MPROTECT
44542+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
44543+ pax_flags |= MF_PAX_MPROTECT;
44544+#endif
44545+
44546+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44547+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
44548+ pax_flags |= MF_PAX_RANDMMAP;
44549+#endif
44550+
44551+ return pax_flags;
44552+}
44553+#endif
44554+
44555+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44556+#ifdef CONFIG_PAX_SOFTMODE
44557+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
44558+{
44559+ unsigned long pax_flags = 0UL;
44560+
44561+#ifdef CONFIG_PAX_PAGEEXEC
44562+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
44563+ pax_flags |= MF_PAX_PAGEEXEC;
44564+#endif
44565+
44566+#ifdef CONFIG_PAX_SEGMEXEC
44567+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
44568+ pax_flags |= MF_PAX_SEGMEXEC;
44569+#endif
44570+
44571+#ifdef CONFIG_PAX_EMUTRAMP
44572+ if (pax_flags_softmode & MF_PAX_EMUTRAMP)
44573+ pax_flags |= MF_PAX_EMUTRAMP;
44574+#endif
44575+
44576+#ifdef CONFIG_PAX_MPROTECT
44577+ if (pax_flags_softmode & MF_PAX_MPROTECT)
44578+ pax_flags |= MF_PAX_MPROTECT;
44579+#endif
44580+
44581+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44582+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
44583+ pax_flags |= MF_PAX_RANDMMAP;
44584+#endif
44585+
44586+ return pax_flags;
44587+}
44588+#endif
44589+
44590+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
44591+{
44592+ unsigned long pax_flags = 0UL;
44593+
44594+#ifdef CONFIG_PAX_PAGEEXEC
44595+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
44596+ pax_flags |= MF_PAX_PAGEEXEC;
44597+#endif
44598+
44599+#ifdef CONFIG_PAX_SEGMEXEC
44600+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
44601+ pax_flags |= MF_PAX_SEGMEXEC;
44602+#endif
44603+
44604+#ifdef CONFIG_PAX_EMUTRAMP
44605+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
44606+ pax_flags |= MF_PAX_EMUTRAMP;
44607+#endif
44608+
44609+#ifdef CONFIG_PAX_MPROTECT
44610+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
44611+ pax_flags |= MF_PAX_MPROTECT;
44612+#endif
44613+
44614+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
44615+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
44616+ pax_flags |= MF_PAX_RANDMMAP;
44617+#endif
44618+
44619+ return pax_flags;
44620+}
44621+#endif
44622+
44623+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44624+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
44625+{
44626+ unsigned long pax_flags = 0UL;
44627+
44628+#ifdef CONFIG_PAX_EI_PAX
44629+
44630+#ifdef CONFIG_PAX_PAGEEXEC
44631+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
44632+ pax_flags |= MF_PAX_PAGEEXEC;
44633+#endif
44634+
44635+#ifdef CONFIG_PAX_SEGMEXEC
44636+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
44637+ pax_flags |= MF_PAX_SEGMEXEC;
44638+#endif
44639+
44640+#ifdef CONFIG_PAX_EMUTRAMP
44641+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
44642+ pax_flags |= MF_PAX_EMUTRAMP;
44643+#endif
44644+
44645+#ifdef CONFIG_PAX_MPROTECT
44646+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
44647+ pax_flags |= MF_PAX_MPROTECT;
44648+#endif
44649+
44650+#ifdef CONFIG_PAX_ASLR
44651+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
44652+ pax_flags |= MF_PAX_RANDMMAP;
44653+#endif
44654+
44655+#else
44656+
44657+#ifdef CONFIG_PAX_PAGEEXEC
44658+ pax_flags |= MF_PAX_PAGEEXEC;
44659+#endif
44660+
44661+#ifdef CONFIG_PAX_SEGMEXEC
44662+ pax_flags |= MF_PAX_SEGMEXEC;
44663+#endif
44664+
44665+#ifdef CONFIG_PAX_MPROTECT
44666+ pax_flags |= MF_PAX_MPROTECT;
44667+#endif
44668+
44669+#ifdef CONFIG_PAX_RANDMMAP
44670+ if (randomize_va_space)
44671+ pax_flags |= MF_PAX_RANDMMAP;
44672+#endif
44673+
44674+#endif
44675+
44676+ return pax_flags;
44677+}
44678+
44679+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
44680+{
44681+
44682+#ifdef CONFIG_PAX_PT_PAX_FLAGS
44683+ unsigned long i;
44684+
44685+ for (i = 0UL; i < elf_ex->e_phnum; i++)
44686+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
44687+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
44688+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
44689+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
44690+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
44691+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
44692+ return ~0UL;
44693+
44694+#ifdef CONFIG_PAX_SOFTMODE
44695+ if (pax_softmode)
44696+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
44697+ else
44698+#endif
44699+
44700+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
44701+ break;
44702+ }
44703+#endif
44704+
44705+ return ~0UL;
44706+}
44707+
44708+static unsigned long pax_parse_xattr_pax(struct file * const file)
44709+{
44710+
44711+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
44712+ ssize_t xattr_size, i;
44713+ unsigned char xattr_value[5];
44714+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
44715+
44716+ xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
44717+ if (xattr_size <= 0 || xattr_size > 5)
44718+ return ~0UL;
44719+
44720+ for (i = 0; i < xattr_size; i++)
44721+ switch (xattr_value[i]) {
44722+ default:
44723+ return ~0UL;
44724+
44725+#define parse_flag(option1, option2, flag) \
44726+ case option1: \
44727+ if (pax_flags_hardmode & MF_PAX_##flag) \
44728+ return ~0UL; \
44729+ pax_flags_hardmode |= MF_PAX_##flag; \
44730+ break; \
44731+ case option2: \
44732+ if (pax_flags_softmode & MF_PAX_##flag) \
44733+ return ~0UL; \
44734+ pax_flags_softmode |= MF_PAX_##flag; \
44735+ break;
44736+
44737+ parse_flag('p', 'P', PAGEEXEC);
44738+ parse_flag('e', 'E', EMUTRAMP);
44739+ parse_flag('m', 'M', MPROTECT);
44740+ parse_flag('r', 'R', RANDMMAP);
44741+ parse_flag('s', 'S', SEGMEXEC);
44742+
44743+#undef parse_flag
44744+ }
44745+
44746+ if (pax_flags_hardmode & pax_flags_softmode)
44747+ return ~0UL;
44748+
44749+#ifdef CONFIG_PAX_SOFTMODE
44750+ if (pax_softmode)
44751+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
44752+ else
44753+#endif
44754+
44755+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
44756+#else
44757+ return ~0UL;
44758+#endif
44759+
44760+}
44761+
44762+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
44763+{
44764+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
44765+
44766+ pax_flags = pax_parse_ei_pax(elf_ex);
44767+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
44768+ xattr_pax_flags = pax_parse_xattr_pax(file);
44769+
44770+ if (pt_pax_flags == ~0UL)
44771+ pt_pax_flags = xattr_pax_flags;
44772+ else if (xattr_pax_flags == ~0UL)
44773+ xattr_pax_flags = pt_pax_flags;
44774+ if (pt_pax_flags != xattr_pax_flags)
44775+ return -EINVAL;
44776+ if (pt_pax_flags != ~0UL)
44777+ pax_flags = pt_pax_flags;
44778+
44779+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
44780+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44781+ if ((__supported_pte_mask & _PAGE_NX))
44782+ pax_flags &= ~MF_PAX_SEGMEXEC;
44783+ else
44784+ pax_flags &= ~MF_PAX_PAGEEXEC;
44785+ }
44786+#endif
44787+
44788+ if (0 > pax_check_flags(&pax_flags))
44789+ return -EINVAL;
44790+
44791+ current->mm->pax_flags = pax_flags;
44792+ return 0;
44793+}
44794+#endif
44795+
44796 /*
44797 * These are the functions used to load ELF style executables and shared
44798 * libraries. There is no binary dependent code anywhere else.
44799@@ -546,6 +876,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
44800 {
44801 unsigned int random_variable = 0;
44802
44803+#ifdef CONFIG_PAX_RANDUSTACK
44804+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
44805+ return stack_top - current->mm->delta_stack;
44806+#endif
44807+
44808 if ((current->flags & PF_RANDOMIZE) &&
44809 !(current->personality & ADDR_NO_RANDOMIZE)) {
44810 random_variable = get_random_int() & STACK_RND_MASK;
44811@@ -564,7 +899,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44812 unsigned long load_addr = 0, load_bias = 0;
44813 int load_addr_set = 0;
44814 char * elf_interpreter = NULL;
44815- unsigned long error;
44816+ unsigned long error = 0;
44817 struct elf_phdr *elf_ppnt, *elf_phdata;
44818 unsigned long elf_bss, elf_brk;
44819 int retval, i;
44820@@ -574,11 +909,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44821 unsigned long start_code, end_code, start_data, end_data;
44822 unsigned long reloc_func_desc __maybe_unused = 0;
44823 int executable_stack = EXSTACK_DEFAULT;
44824- unsigned long def_flags = 0;
44825 struct {
44826 struct elfhdr elf_ex;
44827 struct elfhdr interp_elf_ex;
44828 } *loc;
44829+ unsigned long pax_task_size = TASK_SIZE;
44830
44831 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
44832 if (!loc) {
44833@@ -714,11 +1049,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44834 goto out_free_dentry;
44835
44836 /* OK, This is the point of no return */
44837- current->mm->def_flags = def_flags;
44838+
44839+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44840+ current->mm->pax_flags = 0UL;
44841+#endif
44842+
44843+#ifdef CONFIG_PAX_DLRESOLVE
44844+ current->mm->call_dl_resolve = 0UL;
44845+#endif
44846+
44847+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
44848+ current->mm->call_syscall = 0UL;
44849+#endif
44850+
44851+#ifdef CONFIG_PAX_ASLR
44852+ current->mm->delta_mmap = 0UL;
44853+ current->mm->delta_stack = 0UL;
44854+#endif
44855+
44856+ current->mm->def_flags = 0;
44857+
44858+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
44859+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
44860+ send_sig(SIGKILL, current, 0);
44861+ goto out_free_dentry;
44862+ }
44863+#endif
44864+
44865+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44866+ pax_set_initial_flags(bprm);
44867+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
44868+ if (pax_set_initial_flags_func)
44869+ (pax_set_initial_flags_func)(bprm);
44870+#endif
44871+
44872+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
44873+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
44874+ current->mm->context.user_cs_limit = PAGE_SIZE;
44875+ current->mm->def_flags |= VM_PAGEEXEC;
44876+ }
44877+#endif
44878+
44879+#ifdef CONFIG_PAX_SEGMEXEC
44880+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
44881+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
44882+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
44883+ pax_task_size = SEGMEXEC_TASK_SIZE;
44884+ current->mm->def_flags |= VM_NOHUGEPAGE;
44885+ }
44886+#endif
44887+
44888+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
44889+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44890+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
44891+ put_cpu();
44892+ }
44893+#endif
44894
44895 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
44896 may depend on the personality. */
44897 SET_PERSONALITY(loc->elf_ex);
44898+
44899+#ifdef CONFIG_PAX_ASLR
44900+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44901+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
44902+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
44903+ }
44904+#endif
44905+
44906+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
44907+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
44908+ executable_stack = EXSTACK_DISABLE_X;
44909+ current->personality &= ~READ_IMPLIES_EXEC;
44910+ } else
44911+#endif
44912+
44913 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
44914 current->personality |= READ_IMPLIES_EXEC;
44915
44916@@ -809,6 +1214,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44917 #else
44918 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
44919 #endif
44920+
44921+#ifdef CONFIG_PAX_RANDMMAP
44922+ /* PaX: randomize base address at the default exe base if requested */
44923+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
44924+#ifdef CONFIG_SPARC64
44925+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
44926+#else
44927+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
44928+#endif
44929+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
44930+ elf_flags |= MAP_FIXED;
44931+ }
44932+#endif
44933+
44934 }
44935
44936 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
44937@@ -841,9 +1260,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44938 * allowed task size. Note that p_filesz must always be
44939 * <= p_memsz so it is only necessary to check p_memsz.
44940 */
44941- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44942- elf_ppnt->p_memsz > TASK_SIZE ||
44943- TASK_SIZE - elf_ppnt->p_memsz < k) {
44944+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
44945+ elf_ppnt->p_memsz > pax_task_size ||
44946+ pax_task_size - elf_ppnt->p_memsz < k) {
44947 /* set_brk can never work. Avoid overflows. */
44948 send_sig(SIGKILL, current, 0);
44949 retval = -EINVAL;
44950@@ -882,17 +1301,44 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
44951 goto out_free_dentry;
44952 }
44953 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
44954- send_sig(SIGSEGV, current, 0);
44955- retval = -EFAULT; /* Nobody gets to see this, but.. */
44956- goto out_free_dentry;
44957+ /*
44958+ * This bss-zeroing can fail if the ELF
44959+ * file specifies odd protections. So
44960+ * we don't check the return value
44961+ */
44962 }
44963
44964+#ifdef CONFIG_PAX_RANDMMAP
44965+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
44966+ unsigned long start, size;
44967+
44968+ start = ELF_PAGEALIGN(elf_brk);
44969+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
44970+ down_read(&current->mm->mmap_sem);
44971+ retval = -ENOMEM;
44972+ if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
44973+ unsigned long prot = PROT_NONE;
44974+
44975+ up_read(&current->mm->mmap_sem);
44976+ current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
44977+// if (current->personality & ADDR_NO_RANDOMIZE)
44978+// prot = PROT_READ;
44979+ start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
44980+ retval = IS_ERR_VALUE(start) ? start : 0;
44981+ } else
44982+ up_read(&current->mm->mmap_sem);
44983+ if (retval == 0)
44984+ retval = set_brk(start + size, start + size + PAGE_SIZE);
44985+ if (retval < 0) {
44986+ send_sig(SIGKILL, current, 0);
44987+ goto out_free_dentry;
44988+ }
44989+ }
44990+#endif
44991+
44992 if (elf_interpreter) {
44993- unsigned long interp_map_addr = 0;
44994-
44995 elf_entry = load_elf_interp(&loc->interp_elf_ex,
44996 interpreter,
44997- &interp_map_addr,
44998 load_bias);
44999 if (!IS_ERR((void *)elf_entry)) {
45000 /*
45001@@ -1114,7 +1560,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
45002 * Decide what to dump of a segment, part, all or none.
45003 */
45004 static unsigned long vma_dump_size(struct vm_area_struct *vma,
45005- unsigned long mm_flags)
45006+ unsigned long mm_flags, long signr)
45007 {
45008 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
45009
45010@@ -1151,7 +1597,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
45011 if (vma->vm_file == NULL)
45012 return 0;
45013
45014- if (FILTER(MAPPED_PRIVATE))
45015+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
45016 goto whole;
45017
45018 /*
45019@@ -1373,9 +1819,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
45020 {
45021 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
45022 int i = 0;
45023- do
45024+ do {
45025 i += 2;
45026- while (auxv[i - 2] != AT_NULL);
45027+ } while (auxv[i - 2] != AT_NULL);
45028 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
45029 }
45030
45031@@ -2003,14 +2449,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
45032 }
45033
45034 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
45035- unsigned long mm_flags)
45036+ struct coredump_params *cprm)
45037 {
45038 struct vm_area_struct *vma;
45039 size_t size = 0;
45040
45041 for (vma = first_vma(current, gate_vma); vma != NULL;
45042 vma = next_vma(vma, gate_vma))
45043- size += vma_dump_size(vma, mm_flags);
45044+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45045 return size;
45046 }
45047
45048@@ -2104,7 +2550,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45049
45050 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
45051
45052- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
45053+ offset += elf_core_vma_data_size(gate_vma, cprm);
45054 offset += elf_core_extra_data_size();
45055 e_shoff = offset;
45056
45057@@ -2118,10 +2564,12 @@ static int elf_core_dump(struct coredump_params *cprm)
45058 offset = dataoff;
45059
45060 size += sizeof(*elf);
45061+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45062 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
45063 goto end_coredump;
45064
45065 size += sizeof(*phdr4note);
45066+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45067 if (size > cprm->limit
45068 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
45069 goto end_coredump;
45070@@ -2135,7 +2583,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45071 phdr.p_offset = offset;
45072 phdr.p_vaddr = vma->vm_start;
45073 phdr.p_paddr = 0;
45074- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
45075+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45076 phdr.p_memsz = vma->vm_end - vma->vm_start;
45077 offset += phdr.p_filesz;
45078 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
45079@@ -2146,6 +2594,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45080 phdr.p_align = ELF_EXEC_PAGESIZE;
45081
45082 size += sizeof(phdr);
45083+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45084 if (size > cprm->limit
45085 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
45086 goto end_coredump;
45087@@ -2170,7 +2619,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45088 unsigned long addr;
45089 unsigned long end;
45090
45091- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
45092+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
45093
45094 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
45095 struct page *page;
45096@@ -2179,6 +2628,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45097 page = get_dump_page(addr);
45098 if (page) {
45099 void *kaddr = kmap(page);
45100+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
45101 stop = ((size += PAGE_SIZE) > cprm->limit) ||
45102 !dump_write(cprm->file, kaddr,
45103 PAGE_SIZE);
45104@@ -2196,6 +2646,7 @@ static int elf_core_dump(struct coredump_params *cprm)
45105
45106 if (e_phnum == PN_XNUM) {
45107 size += sizeof(*shdr4extnum);
45108+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
45109 if (size > cprm->limit
45110 || !dump_write(cprm->file, shdr4extnum,
45111 sizeof(*shdr4extnum)))
45112@@ -2216,6 +2667,97 @@ out:
45113
45114 #endif /* CONFIG_ELF_CORE */
45115
45116+#ifdef CONFIG_PAX_MPROTECT
45117+/* PaX: non-PIC ELF libraries need relocations on their executable segments
45118+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
45119+ * we'll remove VM_MAYWRITE for good on RELRO segments.
45120+ *
45121+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
45122+ * basis because we want to allow the common case and not the special ones.
45123+ */
45124+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
45125+{
45126+ struct elfhdr elf_h;
45127+ struct elf_phdr elf_p;
45128+ unsigned long i;
45129+ unsigned long oldflags;
45130+ bool is_textrel_rw, is_textrel_rx, is_relro;
45131+
45132+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
45133+ return;
45134+
45135+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
45136+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
45137+
45138+#ifdef CONFIG_PAX_ELFRELOCS
45139+ /* possible TEXTREL */
45140+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
45141+ 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);
45142+#else
45143+ is_textrel_rw = false;
45144+ is_textrel_rx = false;
45145+#endif
45146+
45147+ /* possible RELRO */
45148+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
45149+
45150+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
45151+ return;
45152+
45153+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
45154+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
45155+
45156+#ifdef CONFIG_PAX_ETEXECRELOCS
45157+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45158+#else
45159+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
45160+#endif
45161+
45162+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
45163+ !elf_check_arch(&elf_h) ||
45164+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
45165+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
45166+ return;
45167+
45168+ for (i = 0UL; i < elf_h.e_phnum; i++) {
45169+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
45170+ return;
45171+ switch (elf_p.p_type) {
45172+ case PT_DYNAMIC:
45173+ if (!is_textrel_rw && !is_textrel_rx)
45174+ continue;
45175+ i = 0UL;
45176+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
45177+ elf_dyn dyn;
45178+
45179+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
45180+ return;
45181+ if (dyn.d_tag == DT_NULL)
45182+ return;
45183+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
45184+ gr_log_textrel(vma);
45185+ if (is_textrel_rw)
45186+ vma->vm_flags |= VM_MAYWRITE;
45187+ else
45188+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
45189+ vma->vm_flags &= ~VM_MAYWRITE;
45190+ return;
45191+ }
45192+ i++;
45193+ }
45194+ return;
45195+
45196+ case PT_GNU_RELRO:
45197+ if (!is_relro)
45198+ continue;
45199+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
45200+ vma->vm_flags &= ~VM_MAYWRITE;
45201+ return;
45202+ }
45203+ }
45204+}
45205+#endif
45206+
45207 static int __init init_elf_binfmt(void)
45208 {
45209 register_binfmt(&elf_format);
45210diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
45211index e280352..7b2f231 100644
45212--- a/fs/binfmt_flat.c
45213+++ b/fs/binfmt_flat.c
45214@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
45215 realdatastart = (unsigned long) -ENOMEM;
45216 printk("Unable to allocate RAM for process data, errno %d\n",
45217 (int)-realdatastart);
45218+ down_write(&current->mm->mmap_sem);
45219 vm_munmap(textpos, text_len);
45220+ up_write(&current->mm->mmap_sem);
45221 ret = realdatastart;
45222 goto err;
45223 }
45224@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45225 }
45226 if (IS_ERR_VALUE(result)) {
45227 printk("Unable to read data+bss, errno %d\n", (int)-result);
45228+ down_write(&current->mm->mmap_sem);
45229 vm_munmap(textpos, text_len);
45230 vm_munmap(realdatastart, len);
45231+ up_write(&current->mm->mmap_sem);
45232 ret = result;
45233 goto err;
45234 }
45235@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
45236 }
45237 if (IS_ERR_VALUE(result)) {
45238 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
45239+ down_write(&current->mm->mmap_sem);
45240 vm_munmap(textpos, text_len + data_len + extra +
45241 MAX_SHARED_LIBS * sizeof(unsigned long));
45242+ up_write(&current->mm->mmap_sem);
45243 ret = result;
45244 goto err;
45245 }
45246diff --git a/fs/bio.c b/fs/bio.c
45247index b96fc6c..431d628 100644
45248--- a/fs/bio.c
45249+++ b/fs/bio.c
45250@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
45251 /*
45252 * Overflow, abort
45253 */
45254- if (end < start)
45255+ if (end < start || end - start > INT_MAX - nr_pages)
45256 return ERR_PTR(-EINVAL);
45257
45258 nr_pages += end - start;
45259@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
45260 /*
45261 * Overflow, abort
45262 */
45263- if (end < start)
45264+ if (end < start || end - start > INT_MAX - nr_pages)
45265 return ERR_PTR(-EINVAL);
45266
45267 nr_pages += end - start;
45268@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
45269 const int read = bio_data_dir(bio) == READ;
45270 struct bio_map_data *bmd = bio->bi_private;
45271 int i;
45272- char *p = bmd->sgvecs[0].iov_base;
45273+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
45274
45275 __bio_for_each_segment(bvec, bio, i, 0) {
45276 char *addr = page_address(bvec->bv_page);
45277diff --git a/fs/block_dev.c b/fs/block_dev.c
45278index ab3a456..7da538b 100644
45279--- a/fs/block_dev.c
45280+++ b/fs/block_dev.c
45281@@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
45282 else if (bdev->bd_contains == bdev)
45283 return true; /* is a whole device which isn't held */
45284
45285- else if (whole->bd_holder == bd_may_claim)
45286+ else if (whole->bd_holder == (void *)bd_may_claim)
45287 return true; /* is a partition of a device that is being partitioned */
45288 else if (whole->bd_holder != NULL)
45289 return false; /* is a partition of a held device */
45290diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
45291index cdfb4c4..da736d4 100644
45292--- a/fs/btrfs/ctree.c
45293+++ b/fs/btrfs/ctree.c
45294@@ -1035,9 +1035,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
45295 free_extent_buffer(buf);
45296 add_root_to_dirty_list(root);
45297 } else {
45298- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
45299- parent_start = parent->start;
45300- else
45301+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
45302+ if (parent)
45303+ parent_start = parent->start;
45304+ else
45305+ parent_start = 0;
45306+ } else
45307 parent_start = 0;
45308
45309 WARN_ON(trans->transid != btrfs_header_generation(parent));
45310diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
45311index 95542a1..95a8727 100644
45312--- a/fs/btrfs/inode.c
45313+++ b/fs/btrfs/inode.c
45314@@ -7243,7 +7243,7 @@ fail:
45315 return -ENOMEM;
45316 }
45317
45318-static int btrfs_getattr(struct vfsmount *mnt,
45319+int btrfs_getattr(struct vfsmount *mnt,
45320 struct dentry *dentry, struct kstat *stat)
45321 {
45322 struct inode *inode = dentry->d_inode;
45323@@ -7257,6 +7257,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
45324 return 0;
45325 }
45326
45327+EXPORT_SYMBOL(btrfs_getattr);
45328+
45329+dev_t get_btrfs_dev_from_inode(struct inode *inode)
45330+{
45331+ return BTRFS_I(inode)->root->anon_dev;
45332+}
45333+EXPORT_SYMBOL(get_btrfs_dev_from_inode);
45334+
45335 /*
45336 * If a file is moved, it will inherit the cow and compression flags of the new
45337 * directory.
45338diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
45339index 8fcf9a5..a200000 100644
45340--- a/fs/btrfs/ioctl.c
45341+++ b/fs/btrfs/ioctl.c
45342@@ -2965,9 +2965,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45343 for (i = 0; i < num_types; i++) {
45344 struct btrfs_space_info *tmp;
45345
45346+ /* Don't copy in more than we allocated */
45347 if (!slot_count)
45348 break;
45349
45350+ slot_count--;
45351+
45352 info = NULL;
45353 rcu_read_lock();
45354 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
45355@@ -2989,10 +2992,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
45356 memcpy(dest, &space, sizeof(space));
45357 dest++;
45358 space_args.total_spaces++;
45359- slot_count--;
45360 }
45361- if (!slot_count)
45362- break;
45363 }
45364 up_read(&info->groups_sem);
45365 }
45366diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
45367index 776f0aa..3aad281 100644
45368--- a/fs/btrfs/relocation.c
45369+++ b/fs/btrfs/relocation.c
45370@@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
45371 }
45372 spin_unlock(&rc->reloc_root_tree.lock);
45373
45374- BUG_ON((struct btrfs_root *)node->data != root);
45375+ BUG_ON(!node || (struct btrfs_root *)node->data != root);
45376
45377 if (!del) {
45378 spin_lock(&rc->reloc_root_tree.lock);
45379diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
45380index 622f469..e8d2d55 100644
45381--- a/fs/cachefiles/bind.c
45382+++ b/fs/cachefiles/bind.c
45383@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
45384 args);
45385
45386 /* start by checking things over */
45387- ASSERT(cache->fstop_percent >= 0 &&
45388- cache->fstop_percent < cache->fcull_percent &&
45389+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
45390 cache->fcull_percent < cache->frun_percent &&
45391 cache->frun_percent < 100);
45392
45393- ASSERT(cache->bstop_percent >= 0 &&
45394- cache->bstop_percent < cache->bcull_percent &&
45395+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
45396 cache->bcull_percent < cache->brun_percent &&
45397 cache->brun_percent < 100);
45398
45399diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
45400index 0a1467b..6a53245 100644
45401--- a/fs/cachefiles/daemon.c
45402+++ b/fs/cachefiles/daemon.c
45403@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
45404 if (n > buflen)
45405 return -EMSGSIZE;
45406
45407- if (copy_to_user(_buffer, buffer, n) != 0)
45408+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
45409 return -EFAULT;
45410
45411 return n;
45412@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
45413 if (test_bit(CACHEFILES_DEAD, &cache->flags))
45414 return -EIO;
45415
45416- if (datalen < 0 || datalen > PAGE_SIZE - 1)
45417+ if (datalen > PAGE_SIZE - 1)
45418 return -EOPNOTSUPP;
45419
45420 /* drag the command string into the kernel so we can parse it */
45421@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
45422 if (args[0] != '%' || args[1] != '\0')
45423 return -EINVAL;
45424
45425- if (fstop < 0 || fstop >= cache->fcull_percent)
45426+ if (fstop >= cache->fcull_percent)
45427 return cachefiles_daemon_range_error(cache, args);
45428
45429 cache->fstop_percent = fstop;
45430@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
45431 if (args[0] != '%' || args[1] != '\0')
45432 return -EINVAL;
45433
45434- if (bstop < 0 || bstop >= cache->bcull_percent)
45435+ if (bstop >= cache->bcull_percent)
45436 return cachefiles_daemon_range_error(cache, args);
45437
45438 cache->bstop_percent = bstop;
45439diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
45440index bd6bc1b..b627b53 100644
45441--- a/fs/cachefiles/internal.h
45442+++ b/fs/cachefiles/internal.h
45443@@ -57,7 +57,7 @@ struct cachefiles_cache {
45444 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
45445 struct rb_root active_nodes; /* active nodes (can't be culled) */
45446 rwlock_t active_lock; /* lock for active_nodes */
45447- atomic_t gravecounter; /* graveyard uniquifier */
45448+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
45449 unsigned frun_percent; /* when to stop culling (% files) */
45450 unsigned fcull_percent; /* when to start culling (% files) */
45451 unsigned fstop_percent; /* when to stop allocating (% files) */
45452@@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
45453 * proc.c
45454 */
45455 #ifdef CONFIG_CACHEFILES_HISTOGRAM
45456-extern atomic_t cachefiles_lookup_histogram[HZ];
45457-extern atomic_t cachefiles_mkdir_histogram[HZ];
45458-extern atomic_t cachefiles_create_histogram[HZ];
45459+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45460+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45461+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
45462
45463 extern int __init cachefiles_proc_init(void);
45464 extern void cachefiles_proc_cleanup(void);
45465 static inline
45466-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
45467+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
45468 {
45469 unsigned long jif = jiffies - start_jif;
45470 if (jif >= HZ)
45471 jif = HZ - 1;
45472- atomic_inc(&histogram[jif]);
45473+ atomic_inc_unchecked(&histogram[jif]);
45474 }
45475
45476 #else
45477diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
45478index b0b5f7c..039bb26 100644
45479--- a/fs/cachefiles/namei.c
45480+++ b/fs/cachefiles/namei.c
45481@@ -318,7 +318,7 @@ try_again:
45482 /* first step is to make up a grave dentry in the graveyard */
45483 sprintf(nbuffer, "%08x%08x",
45484 (uint32_t) get_seconds(),
45485- (uint32_t) atomic_inc_return(&cache->gravecounter));
45486+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
45487
45488 /* do the multiway lock magic */
45489 trap = lock_rename(cache->graveyard, dir);
45490diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
45491index eccd339..4c1d995 100644
45492--- a/fs/cachefiles/proc.c
45493+++ b/fs/cachefiles/proc.c
45494@@ -14,9 +14,9 @@
45495 #include <linux/seq_file.h>
45496 #include "internal.h"
45497
45498-atomic_t cachefiles_lookup_histogram[HZ];
45499-atomic_t cachefiles_mkdir_histogram[HZ];
45500-atomic_t cachefiles_create_histogram[HZ];
45501+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
45502+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
45503+atomic_unchecked_t cachefiles_create_histogram[HZ];
45504
45505 /*
45506 * display the latency histogram
45507@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
45508 return 0;
45509 default:
45510 index = (unsigned long) v - 3;
45511- x = atomic_read(&cachefiles_lookup_histogram[index]);
45512- y = atomic_read(&cachefiles_mkdir_histogram[index]);
45513- z = atomic_read(&cachefiles_create_histogram[index]);
45514+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
45515+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
45516+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
45517 if (x == 0 && y == 0 && z == 0)
45518 return 0;
45519
45520diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
45521index c994691..2a1537f 100644
45522--- a/fs/cachefiles/rdwr.c
45523+++ b/fs/cachefiles/rdwr.c
45524@@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
45525 old_fs = get_fs();
45526 set_fs(KERNEL_DS);
45527 ret = file->f_op->write(
45528- file, (const void __user *) data, len, &pos);
45529+ file, (const void __force_user *) data, len, &pos);
45530 set_fs(old_fs);
45531 kunmap(page);
45532 if (ret != len)
45533diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
45534index e5b7731..b9c59fb 100644
45535--- a/fs/ceph/dir.c
45536+++ b/fs/ceph/dir.c
45537@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
45538 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
45539 struct ceph_mds_client *mdsc = fsc->mdsc;
45540 unsigned frag = fpos_frag(filp->f_pos);
45541- int off = fpos_off(filp->f_pos);
45542+ unsigned int off = fpos_off(filp->f_pos);
45543 int err;
45544 u32 ftype;
45545 struct ceph_mds_reply_info_parsed *rinfo;
45546diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
45547index d9ea6ed..1e6c8ac 100644
45548--- a/fs/cifs/cifs_debug.c
45549+++ b/fs/cifs/cifs_debug.c
45550@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45551
45552 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
45553 #ifdef CONFIG_CIFS_STATS2
45554- atomic_set(&totBufAllocCount, 0);
45555- atomic_set(&totSmBufAllocCount, 0);
45556+ atomic_set_unchecked(&totBufAllocCount, 0);
45557+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45558 #endif /* CONFIG_CIFS_STATS2 */
45559 spin_lock(&cifs_tcp_ses_lock);
45560 list_for_each(tmp1, &cifs_tcp_ses_list) {
45561@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
45562 tcon = list_entry(tmp3,
45563 struct cifs_tcon,
45564 tcon_list);
45565- atomic_set(&tcon->num_smbs_sent, 0);
45566+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
45567 if (server->ops->clear_stats)
45568 server->ops->clear_stats(tcon);
45569 }
45570@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45571 smBufAllocCount.counter, cifs_min_small);
45572 #ifdef CONFIG_CIFS_STATS2
45573 seq_printf(m, "Total Large %d Small %d Allocations\n",
45574- atomic_read(&totBufAllocCount),
45575- atomic_read(&totSmBufAllocCount));
45576+ atomic_read_unchecked(&totBufAllocCount),
45577+ atomic_read_unchecked(&totSmBufAllocCount));
45578 #endif /* CONFIG_CIFS_STATS2 */
45579
45580 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
45581@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
45582 if (tcon->need_reconnect)
45583 seq_puts(m, "\tDISCONNECTED ");
45584 seq_printf(m, "\nSMBs: %d",
45585- atomic_read(&tcon->num_smbs_sent));
45586+ atomic_read_unchecked(&tcon->num_smbs_sent));
45587 if (server->ops->print_stats)
45588 server->ops->print_stats(m, tcon);
45589 }
45590diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
45591index e7931cc..76a1ab9 100644
45592--- a/fs/cifs/cifsfs.c
45593+++ b/fs/cifs/cifsfs.c
45594@@ -999,7 +999,7 @@ cifs_init_request_bufs(void)
45595 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
45596 cifs_req_cachep = kmem_cache_create("cifs_request",
45597 CIFSMaxBufSize + max_hdr_size, 0,
45598- SLAB_HWCACHE_ALIGN, NULL);
45599+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
45600 if (cifs_req_cachep == NULL)
45601 return -ENOMEM;
45602
45603@@ -1026,7 +1026,7 @@ cifs_init_request_bufs(void)
45604 efficient to alloc 1 per page off the slab compared to 17K (5page)
45605 alloc of large cifs buffers even when page debugging is on */
45606 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
45607- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
45608+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
45609 NULL);
45610 if (cifs_sm_req_cachep == NULL) {
45611 mempool_destroy(cifs_req_poolp);
45612@@ -1111,8 +1111,8 @@ init_cifs(void)
45613 atomic_set(&bufAllocCount, 0);
45614 atomic_set(&smBufAllocCount, 0);
45615 #ifdef CONFIG_CIFS_STATS2
45616- atomic_set(&totBufAllocCount, 0);
45617- atomic_set(&totSmBufAllocCount, 0);
45618+ atomic_set_unchecked(&totBufAllocCount, 0);
45619+ atomic_set_unchecked(&totSmBufAllocCount, 0);
45620 #endif /* CONFIG_CIFS_STATS2 */
45621
45622 atomic_set(&midCount, 0);
45623diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
45624index f5af252..489b5f2 100644
45625--- a/fs/cifs/cifsglob.h
45626+++ b/fs/cifs/cifsglob.h
45627@@ -751,35 +751,35 @@ struct cifs_tcon {
45628 __u16 Flags; /* optional support bits */
45629 enum statusEnum tidStatus;
45630 #ifdef CONFIG_CIFS_STATS
45631- atomic_t num_smbs_sent;
45632+ atomic_unchecked_t num_smbs_sent;
45633 union {
45634 struct {
45635- atomic_t num_writes;
45636- atomic_t num_reads;
45637- atomic_t num_flushes;
45638- atomic_t num_oplock_brks;
45639- atomic_t num_opens;
45640- atomic_t num_closes;
45641- atomic_t num_deletes;
45642- atomic_t num_mkdirs;
45643- atomic_t num_posixopens;
45644- atomic_t num_posixmkdirs;
45645- atomic_t num_rmdirs;
45646- atomic_t num_renames;
45647- atomic_t num_t2renames;
45648- atomic_t num_ffirst;
45649- atomic_t num_fnext;
45650- atomic_t num_fclose;
45651- atomic_t num_hardlinks;
45652- atomic_t num_symlinks;
45653- atomic_t num_locks;
45654- atomic_t num_acl_get;
45655- atomic_t num_acl_set;
45656+ atomic_unchecked_t num_writes;
45657+ atomic_unchecked_t num_reads;
45658+ atomic_unchecked_t num_flushes;
45659+ atomic_unchecked_t num_oplock_brks;
45660+ atomic_unchecked_t num_opens;
45661+ atomic_unchecked_t num_closes;
45662+ atomic_unchecked_t num_deletes;
45663+ atomic_unchecked_t num_mkdirs;
45664+ atomic_unchecked_t num_posixopens;
45665+ atomic_unchecked_t num_posixmkdirs;
45666+ atomic_unchecked_t num_rmdirs;
45667+ atomic_unchecked_t num_renames;
45668+ atomic_unchecked_t num_t2renames;
45669+ atomic_unchecked_t num_ffirst;
45670+ atomic_unchecked_t num_fnext;
45671+ atomic_unchecked_t num_fclose;
45672+ atomic_unchecked_t num_hardlinks;
45673+ atomic_unchecked_t num_symlinks;
45674+ atomic_unchecked_t num_locks;
45675+ atomic_unchecked_t num_acl_get;
45676+ atomic_unchecked_t num_acl_set;
45677 } cifs_stats;
45678 #ifdef CONFIG_CIFS_SMB2
45679 struct {
45680- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45681- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45682+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
45683+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
45684 } smb2_stats;
45685 #endif /* CONFIG_CIFS_SMB2 */
45686 } stats;
45687@@ -1094,7 +1094,7 @@ build_path_to_root(struct smb_vol *vol, struct cifs_sb_info *cifs_sb,
45688 }
45689
45690 #ifdef CONFIG_CIFS_STATS
45691-#define cifs_stats_inc atomic_inc
45692+#define cifs_stats_inc atomic_inc_unchecked
45693
45694 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
45695 unsigned int bytes)
45696@@ -1459,8 +1459,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
45697 /* Various Debug counters */
45698 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
45699 #ifdef CONFIG_CIFS_STATS2
45700-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
45701-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
45702+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
45703+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
45704 #endif
45705 GLOBAL_EXTERN atomic_t smBufAllocCount;
45706 GLOBAL_EXTERN atomic_t midCount;
45707diff --git a/fs/cifs/link.c b/fs/cifs/link.c
45708index 51dc2fb..1e12a33 100644
45709--- a/fs/cifs/link.c
45710+++ b/fs/cifs/link.c
45711@@ -616,7 +616,7 @@ symlink_exit:
45712
45713 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
45714 {
45715- char *p = nd_get_link(nd);
45716+ const char *p = nd_get_link(nd);
45717 if (!IS_ERR(p))
45718 kfree(p);
45719 }
45720diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
45721index 3a00c0d..42d901c 100644
45722--- a/fs/cifs/misc.c
45723+++ b/fs/cifs/misc.c
45724@@ -169,7 +169,7 @@ cifs_buf_get(void)
45725 memset(ret_buf, 0, buf_size + 3);
45726 atomic_inc(&bufAllocCount);
45727 #ifdef CONFIG_CIFS_STATS2
45728- atomic_inc(&totBufAllocCount);
45729+ atomic_inc_unchecked(&totBufAllocCount);
45730 #endif /* CONFIG_CIFS_STATS2 */
45731 }
45732
45733@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
45734 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
45735 atomic_inc(&smBufAllocCount);
45736 #ifdef CONFIG_CIFS_STATS2
45737- atomic_inc(&totSmBufAllocCount);
45738+ atomic_inc_unchecked(&totSmBufAllocCount);
45739 #endif /* CONFIG_CIFS_STATS2 */
45740
45741 }
45742diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
45743index 591bf19..690d600 100644
45744--- a/fs/cifs/smb1ops.c
45745+++ b/fs/cifs/smb1ops.c
45746@@ -617,27 +617,27 @@ static void
45747 cifs_clear_stats(struct cifs_tcon *tcon)
45748 {
45749 #ifdef CONFIG_CIFS_STATS
45750- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
45751- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
45752- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
45753- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45754- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
45755- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
45756- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45757- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
45758- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
45759- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
45760- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
45761- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
45762- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
45763- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
45764- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
45765- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
45766- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
45767- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
45768- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
45769- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
45770- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
45771+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
45772+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
45773+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
45774+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
45775+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
45776+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
45777+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
45778+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
45779+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
45780+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
45781+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
45782+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
45783+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
45784+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
45785+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
45786+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
45787+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
45788+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
45789+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
45790+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
45791+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
45792 #endif
45793 }
45794
45795@@ -646,36 +646,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45796 {
45797 #ifdef CONFIG_CIFS_STATS
45798 seq_printf(m, " Oplocks breaks: %d",
45799- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
45800+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
45801 seq_printf(m, "\nReads: %d Bytes: %llu",
45802- atomic_read(&tcon->stats.cifs_stats.num_reads),
45803+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
45804 (long long)(tcon->bytes_read));
45805 seq_printf(m, "\nWrites: %d Bytes: %llu",
45806- atomic_read(&tcon->stats.cifs_stats.num_writes),
45807+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
45808 (long long)(tcon->bytes_written));
45809 seq_printf(m, "\nFlushes: %d",
45810- atomic_read(&tcon->stats.cifs_stats.num_flushes));
45811+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
45812 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
45813- atomic_read(&tcon->stats.cifs_stats.num_locks),
45814- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
45815- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
45816+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
45817+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
45818+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
45819 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
45820- atomic_read(&tcon->stats.cifs_stats.num_opens),
45821- atomic_read(&tcon->stats.cifs_stats.num_closes),
45822- atomic_read(&tcon->stats.cifs_stats.num_deletes));
45823+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
45824+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
45825+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
45826 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
45827- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
45828- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
45829+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
45830+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
45831 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
45832- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
45833- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
45834+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
45835+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
45836 seq_printf(m, "\nRenames: %d T2 Renames %d",
45837- atomic_read(&tcon->stats.cifs_stats.num_renames),
45838- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
45839+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
45840+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
45841 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
45842- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
45843- atomic_read(&tcon->stats.cifs_stats.num_fnext),
45844- atomic_read(&tcon->stats.cifs_stats.num_fclose));
45845+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
45846+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
45847+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
45848 #endif
45849 }
45850
45851diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
45852index 4d9dbe0..0af4601 100644
45853--- a/fs/cifs/smb2ops.c
45854+++ b/fs/cifs/smb2ops.c
45855@@ -291,8 +291,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
45856 #ifdef CONFIG_CIFS_STATS
45857 int i;
45858 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
45859- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45860- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45861+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
45862+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
45863 }
45864 #endif
45865 }
45866@@ -301,66 +301,66 @@ static void
45867 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
45868 {
45869 #ifdef CONFIG_CIFS_STATS
45870- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45871- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45872+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
45873+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
45874 seq_printf(m, "\nNegotiates: %d sent %d failed",
45875- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
45876- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
45877+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
45878+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
45879 seq_printf(m, "\nSessionSetups: %d sent %d failed",
45880- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
45881- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
45882+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
45883+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
45884 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
45885 seq_printf(m, "\nLogoffs: %d sent %d failed",
45886- atomic_read(&sent[SMB2_LOGOFF_HE]),
45887- atomic_read(&failed[SMB2_LOGOFF_HE]));
45888+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
45889+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
45890 seq_printf(m, "\nTreeConnects: %d sent %d failed",
45891- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
45892- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
45893+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
45894+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
45895 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
45896- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
45897- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
45898+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
45899+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
45900 seq_printf(m, "\nCreates: %d sent %d failed",
45901- atomic_read(&sent[SMB2_CREATE_HE]),
45902- atomic_read(&failed[SMB2_CREATE_HE]));
45903+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
45904+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
45905 seq_printf(m, "\nCloses: %d sent %d failed",
45906- atomic_read(&sent[SMB2_CLOSE_HE]),
45907- atomic_read(&failed[SMB2_CLOSE_HE]));
45908+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
45909+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
45910 seq_printf(m, "\nFlushes: %d sent %d failed",
45911- atomic_read(&sent[SMB2_FLUSH_HE]),
45912- atomic_read(&failed[SMB2_FLUSH_HE]));
45913+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
45914+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
45915 seq_printf(m, "\nReads: %d sent %d failed",
45916- atomic_read(&sent[SMB2_READ_HE]),
45917- atomic_read(&failed[SMB2_READ_HE]));
45918+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
45919+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
45920 seq_printf(m, "\nWrites: %d sent %d failed",
45921- atomic_read(&sent[SMB2_WRITE_HE]),
45922- atomic_read(&failed[SMB2_WRITE_HE]));
45923+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
45924+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
45925 seq_printf(m, "\nLocks: %d sent %d failed",
45926- atomic_read(&sent[SMB2_LOCK_HE]),
45927- atomic_read(&failed[SMB2_LOCK_HE]));
45928+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
45929+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
45930 seq_printf(m, "\nIOCTLs: %d sent %d failed",
45931- atomic_read(&sent[SMB2_IOCTL_HE]),
45932- atomic_read(&failed[SMB2_IOCTL_HE]));
45933+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
45934+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
45935 seq_printf(m, "\nCancels: %d sent %d failed",
45936- atomic_read(&sent[SMB2_CANCEL_HE]),
45937- atomic_read(&failed[SMB2_CANCEL_HE]));
45938+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
45939+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
45940 seq_printf(m, "\nEchos: %d sent %d failed",
45941- atomic_read(&sent[SMB2_ECHO_HE]),
45942- atomic_read(&failed[SMB2_ECHO_HE]));
45943+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
45944+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
45945 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
45946- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
45947- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
45948+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
45949+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
45950 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
45951- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
45952- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
45953+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
45954+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
45955 seq_printf(m, "\nQueryInfos: %d sent %d failed",
45956- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
45957- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
45958+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
45959+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
45960 seq_printf(m, "\nSetInfos: %d sent %d failed",
45961- atomic_read(&sent[SMB2_SET_INFO_HE]),
45962- atomic_read(&failed[SMB2_SET_INFO_HE]));
45963+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
45964+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
45965 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
45966- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
45967- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
45968+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
45969+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
45970 #endif
45971 }
45972
45973diff --git a/fs/coda/cache.c b/fs/coda/cache.c
45974index 958ae0e..505c9d0 100644
45975--- a/fs/coda/cache.c
45976+++ b/fs/coda/cache.c
45977@@ -24,7 +24,7 @@
45978 #include "coda_linux.h"
45979 #include "coda_cache.h"
45980
45981-static atomic_t permission_epoch = ATOMIC_INIT(0);
45982+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
45983
45984 /* replace or extend an acl cache hit */
45985 void coda_cache_enter(struct inode *inode, int mask)
45986@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
45987 struct coda_inode_info *cii = ITOC(inode);
45988
45989 spin_lock(&cii->c_lock);
45990- cii->c_cached_epoch = atomic_read(&permission_epoch);
45991+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
45992 if (cii->c_uid != current_fsuid()) {
45993 cii->c_uid = current_fsuid();
45994 cii->c_cached_perm = mask;
45995@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
45996 {
45997 struct coda_inode_info *cii = ITOC(inode);
45998 spin_lock(&cii->c_lock);
45999- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
46000+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
46001 spin_unlock(&cii->c_lock);
46002 }
46003
46004 /* remove all acl caches */
46005 void coda_cache_clear_all(struct super_block *sb)
46006 {
46007- atomic_inc(&permission_epoch);
46008+ atomic_inc_unchecked(&permission_epoch);
46009 }
46010
46011
46012@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
46013 spin_lock(&cii->c_lock);
46014 hit = (mask & cii->c_cached_perm) == mask &&
46015 cii->c_uid == current_fsuid() &&
46016- cii->c_cached_epoch == atomic_read(&permission_epoch);
46017+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
46018 spin_unlock(&cii->c_lock);
46019
46020 return hit;
46021diff --git a/fs/compat.c b/fs/compat.c
46022index 015e1e1..5ce8e54 100644
46023--- a/fs/compat.c
46024+++ b/fs/compat.c
46025@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
46026
46027 set_fs(KERNEL_DS);
46028 /* The __user pointer cast is valid because of the set_fs() */
46029- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
46030+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
46031 set_fs(oldfs);
46032 /* truncating is ok because it's a user address */
46033 if (!ret)
46034@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
46035 goto out;
46036
46037 ret = -EINVAL;
46038- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
46039+ if (nr_segs > UIO_MAXIOV)
46040 goto out;
46041 if (nr_segs > fast_segs) {
46042 ret = -ENOMEM;
46043@@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
46044
46045 struct compat_readdir_callback {
46046 struct compat_old_linux_dirent __user *dirent;
46047+ struct file * file;
46048 int result;
46049 };
46050
46051@@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
46052 buf->result = -EOVERFLOW;
46053 return -EOVERFLOW;
46054 }
46055+
46056+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46057+ return 0;
46058+
46059 buf->result++;
46060 dirent = buf->dirent;
46061 if (!access_ok(VERIFY_WRITE, dirent,
46062@@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
46063
46064 buf.result = 0;
46065 buf.dirent = dirent;
46066+ buf.file = f.file;
46067
46068 error = vfs_readdir(f.file, compat_fillonedir, &buf);
46069 if (buf.result)
46070@@ -897,6 +903,7 @@ struct compat_linux_dirent {
46071 struct compat_getdents_callback {
46072 struct compat_linux_dirent __user *current_dir;
46073 struct compat_linux_dirent __user *previous;
46074+ struct file * file;
46075 int count;
46076 int error;
46077 };
46078@@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
46079 buf->error = -EOVERFLOW;
46080 return -EOVERFLOW;
46081 }
46082+
46083+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46084+ return 0;
46085+
46086 dirent = buf->previous;
46087 if (dirent) {
46088 if (__put_user(offset, &dirent->d_off))
46089@@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46090 buf.previous = NULL;
46091 buf.count = count;
46092 buf.error = 0;
46093+ buf.file = f.file;
46094
46095 error = vfs_readdir(f.file, compat_filldir, &buf);
46096 if (error >= 0)
46097@@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
46098 struct compat_getdents_callback64 {
46099 struct linux_dirent64 __user *current_dir;
46100 struct linux_dirent64 __user *previous;
46101+ struct file * file;
46102 int count;
46103 int error;
46104 };
46105@@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
46106 buf->error = -EINVAL; /* only used if we fail.. */
46107 if (reclen > buf->count)
46108 return -EINVAL;
46109+
46110+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
46111+ return 0;
46112+
46113 dirent = buf->previous;
46114
46115 if (dirent) {
46116@@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
46117 buf.previous = NULL;
46118 buf.count = count;
46119 buf.error = 0;
46120+ buf.file = f.file;
46121
46122 error = vfs_readdir(f.file, compat_filldir64, &buf);
46123 if (error >= 0)
46124 error = buf.error;
46125 lastdirent = buf.previous;
46126 if (lastdirent) {
46127- typeof(lastdirent->d_off) d_off = f.file->f_pos;
46128+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
46129 if (__put_user_unaligned(d_off, &lastdirent->d_off))
46130 error = -EFAULT;
46131 else
46132diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
46133index a81147e..20bf2b5 100644
46134--- a/fs/compat_binfmt_elf.c
46135+++ b/fs/compat_binfmt_elf.c
46136@@ -30,11 +30,13 @@
46137 #undef elf_phdr
46138 #undef elf_shdr
46139 #undef elf_note
46140+#undef elf_dyn
46141 #undef elf_addr_t
46142 #define elfhdr elf32_hdr
46143 #define elf_phdr elf32_phdr
46144 #define elf_shdr elf32_shdr
46145 #define elf_note elf32_note
46146+#define elf_dyn Elf32_Dyn
46147 #define elf_addr_t Elf32_Addr
46148
46149 /*
46150diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
46151index 4c6285f..b7a2411 100644
46152--- a/fs/compat_ioctl.c
46153+++ b/fs/compat_ioctl.c
46154@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
46155 return -EFAULT;
46156 if (__get_user(udata, &ss32->iomem_base))
46157 return -EFAULT;
46158- ss.iomem_base = compat_ptr(udata);
46159+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
46160 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
46161 __get_user(ss.port_high, &ss32->port_high))
46162 return -EFAULT;
46163@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
46164 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
46165 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
46166 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
46167- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46168+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
46169 return -EFAULT;
46170
46171 return ioctl_preallocate(file, p);
46172@@ -1617,8 +1617,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
46173 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
46174 {
46175 unsigned int a, b;
46176- a = *(unsigned int *)p;
46177- b = *(unsigned int *)q;
46178+ a = *(const unsigned int *)p;
46179+ b = *(const unsigned int *)q;
46180 if (a > b)
46181 return 1;
46182 if (a < b)
46183diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
46184index 7414ae2..d98ad6d 100644
46185--- a/fs/configfs/dir.c
46186+++ b/fs/configfs/dir.c
46187@@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46188 }
46189 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
46190 struct configfs_dirent *next;
46191- const char * name;
46192+ const unsigned char * name;
46193+ char d_name[sizeof(next->s_dentry->d_iname)];
46194 int len;
46195 struct inode *inode = NULL;
46196
46197@@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
46198 continue;
46199
46200 name = configfs_get_name(next);
46201- len = strlen(name);
46202+ if (next->s_dentry && name == next->s_dentry->d_iname) {
46203+ len = next->s_dentry->d_name.len;
46204+ memcpy(d_name, name, len);
46205+ name = d_name;
46206+ } else
46207+ len = strlen(name);
46208
46209 /*
46210 * We'll have a dentry and an inode for
46211diff --git a/fs/coredump.c b/fs/coredump.c
46212index ce47379..68c8e43 100644
46213--- a/fs/coredump.c
46214+++ b/fs/coredump.c
46215@@ -52,7 +52,7 @@ struct core_name {
46216 char *corename;
46217 int used, size;
46218 };
46219-static atomic_t call_count = ATOMIC_INIT(1);
46220+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
46221
46222 /* The maximal length of core_pattern is also specified in sysctl.c */
46223
46224@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
46225 {
46226 char *old_corename = cn->corename;
46227
46228- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
46229+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
46230 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
46231
46232 if (!cn->corename) {
46233@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
46234 int pid_in_pattern = 0;
46235 int err = 0;
46236
46237- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
46238+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
46239 cn->corename = kmalloc(cn->size, GFP_KERNEL);
46240 cn->used = 0;
46241
46242@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
46243 pipe = file->f_path.dentry->d_inode->i_pipe;
46244
46245 pipe_lock(pipe);
46246- pipe->readers++;
46247- pipe->writers--;
46248+ atomic_inc(&pipe->readers);
46249+ atomic_dec(&pipe->writers);
46250
46251- while ((pipe->readers > 1) && (!signal_pending(current))) {
46252+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
46253 wake_up_interruptible_sync(&pipe->wait);
46254 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
46255 pipe_wait(pipe);
46256 }
46257
46258- pipe->readers--;
46259- pipe->writers++;
46260+ atomic_dec(&pipe->readers);
46261+ atomic_inc(&pipe->writers);
46262 pipe_unlock(pipe);
46263
46264 }
46265@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46266 int ispipe;
46267 struct files_struct *displaced;
46268 bool need_nonrelative = false;
46269- static atomic_t core_dump_count = ATOMIC_INIT(0);
46270+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
46271+ long signr = siginfo->si_signo;
46272 struct coredump_params cprm = {
46273 .siginfo = siginfo,
46274 .regs = regs,
46275@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46276 .mm_flags = mm->flags,
46277 };
46278
46279- audit_core_dumps(siginfo->si_signo);
46280+ audit_core_dumps(signr);
46281+
46282+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
46283+ gr_handle_brute_attach(cprm.mm_flags);
46284
46285 binfmt = mm->binfmt;
46286 if (!binfmt || !binfmt->core_dump)
46287@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46288 need_nonrelative = true;
46289 }
46290
46291- retval = coredump_wait(siginfo->si_signo, &core_state);
46292+ retval = coredump_wait(signr, &core_state);
46293 if (retval < 0)
46294 goto fail_creds;
46295
46296@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46297 }
46298 cprm.limit = RLIM_INFINITY;
46299
46300- dump_count = atomic_inc_return(&core_dump_count);
46301+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
46302 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
46303 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
46304 task_tgid_vnr(current), current->comm);
46305@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo, struct pt_regs *regs)
46306 } else {
46307 struct inode *inode;
46308
46309+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
46310+
46311 if (cprm.limit < binfmt->min_coredump)
46312 goto fail_unlock;
46313
46314@@ -640,7 +646,7 @@ close_fail:
46315 filp_close(cprm.file, NULL);
46316 fail_dropcount:
46317 if (ispipe)
46318- atomic_dec(&core_dump_count);
46319+ atomic_dec_unchecked(&core_dump_count);
46320 fail_unlock:
46321 kfree(cn.corename);
46322 fail_corename:
46323@@ -659,7 +665,7 @@ fail:
46324 */
46325 int dump_write(struct file *file, const void *addr, int nr)
46326 {
46327- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
46328+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
46329 }
46330 EXPORT_SYMBOL(dump_write);
46331
46332diff --git a/fs/dcache.c b/fs/dcache.c
46333index 0d0adb6..f4646e9 100644
46334--- a/fs/dcache.c
46335+++ b/fs/dcache.c
46336@@ -3164,7 +3164,7 @@ void __init vfs_caches_init(unsigned long mempages)
46337 mempages -= reserve;
46338
46339 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
46340- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
46341+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
46342
46343 dcache_init();
46344 inode_init();
46345diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
46346index b607d92..41fda09 100644
46347--- a/fs/debugfs/inode.c
46348+++ b/fs/debugfs/inode.c
46349@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
46350 */
46351 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
46352 {
46353+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
46354+ return __create_file(name, S_IFDIR | S_IRWXU,
46355+#else
46356 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
46357+#endif
46358 parent, NULL, NULL);
46359 }
46360 EXPORT_SYMBOL_GPL(debugfs_create_dir);
46361diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
46362index cc7709e..7e7211f 100644
46363--- a/fs/ecryptfs/inode.c
46364+++ b/fs/ecryptfs/inode.c
46365@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
46366 old_fs = get_fs();
46367 set_fs(get_ds());
46368 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
46369- (char __user *)lower_buf,
46370+ (char __force_user *)lower_buf,
46371 PATH_MAX);
46372 set_fs(old_fs);
46373 if (rc < 0)
46374@@ -706,7 +706,7 @@ out:
46375 static void
46376 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
46377 {
46378- char *buf = nd_get_link(nd);
46379+ const char *buf = nd_get_link(nd);
46380 if (!IS_ERR(buf)) {
46381 /* Free the char* */
46382 kfree(buf);
46383diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
46384index 412e6ed..4292d22 100644
46385--- a/fs/ecryptfs/miscdev.c
46386+++ b/fs/ecryptfs/miscdev.c
46387@@ -315,7 +315,7 @@ check_list:
46388 goto out_unlock_msg_ctx;
46389 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
46390 if (msg_ctx->msg) {
46391- if (copy_to_user(&buf[i], packet_length, packet_length_size))
46392+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
46393 goto out_unlock_msg_ctx;
46394 i += packet_length_size;
46395 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
46396diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
46397index b2a34a1..162fa69 100644
46398--- a/fs/ecryptfs/read_write.c
46399+++ b/fs/ecryptfs/read_write.c
46400@@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
46401 return -EIO;
46402 fs_save = get_fs();
46403 set_fs(get_ds());
46404- rc = vfs_write(lower_file, data, size, &offset);
46405+ rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
46406 set_fs(fs_save);
46407 mark_inode_dirty_sync(ecryptfs_inode);
46408 return rc;
46409@@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
46410 return -EIO;
46411 fs_save = get_fs();
46412 set_fs(get_ds());
46413- rc = vfs_read(lower_file, data, size, &offset);
46414+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
46415 set_fs(fs_save);
46416 return rc;
46417 }
46418diff --git a/fs/exec.c b/fs/exec.c
46419index c6e6de4..fb98879 100644
46420--- a/fs/exec.c
46421+++ b/fs/exec.c
46422@@ -55,6 +55,17 @@
46423 #include <linux/pipe_fs_i.h>
46424 #include <linux/oom.h>
46425 #include <linux/compat.h>
46426+#include <linux/random.h>
46427+#include <linux/seq_file.h>
46428+#include <linux/coredump.h>
46429+#include <linux/mman.h>
46430+
46431+#ifdef CONFIG_PAX_REFCOUNT
46432+#include <linux/kallsyms.h>
46433+#include <linux/kdebug.h>
46434+#endif
46435+
46436+#include <trace/events/fs.h>
46437
46438 #include <asm/uaccess.h>
46439 #include <asm/mmu_context.h>
46440@@ -66,6 +77,18 @@
46441
46442 #include <trace/events/sched.h>
46443
46444+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
46445+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
46446+{
46447+ 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");
46448+}
46449+#endif
46450+
46451+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
46452+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
46453+EXPORT_SYMBOL(pax_set_initial_flags_func);
46454+#endif
46455+
46456 int suid_dumpable = 0;
46457
46458 static LIST_HEAD(formats);
46459@@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46460 int write)
46461 {
46462 struct page *page;
46463- int ret;
46464
46465-#ifdef CONFIG_STACK_GROWSUP
46466- if (write) {
46467- ret = expand_downwards(bprm->vma, pos);
46468- if (ret < 0)
46469- return NULL;
46470- }
46471-#endif
46472- ret = get_user_pages(current, bprm->mm, pos,
46473- 1, write, 1, &page, NULL);
46474- if (ret <= 0)
46475+ if (0 > expand_downwards(bprm->vma, pos))
46476+ return NULL;
46477+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
46478 return NULL;
46479
46480 if (write) {
46481@@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
46482 if (size <= ARG_MAX)
46483 return page;
46484
46485+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46486+ // only allow 512KB for argv+env on suid/sgid binaries
46487+ // to prevent easy ASLR exhaustion
46488+ if (((bprm->cred->euid != current_euid()) ||
46489+ (bprm->cred->egid != current_egid())) &&
46490+ (size > (512 * 1024))) {
46491+ put_page(page);
46492+ return NULL;
46493+ }
46494+#endif
46495+
46496 /*
46497 * Limit to 1/4-th the stack size for the argv+env strings.
46498 * This ensures that:
46499@@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46500 vma->vm_end = STACK_TOP_MAX;
46501 vma->vm_start = vma->vm_end - PAGE_SIZE;
46502 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
46503+
46504+#ifdef CONFIG_PAX_SEGMEXEC
46505+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
46506+#endif
46507+
46508 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
46509 INIT_LIST_HEAD(&vma->anon_vma_chain);
46510
46511@@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
46512 mm->stack_vm = mm->total_vm = 1;
46513 up_write(&mm->mmap_sem);
46514 bprm->p = vma->vm_end - sizeof(void *);
46515+
46516+#ifdef CONFIG_PAX_RANDUSTACK
46517+ if (randomize_va_space)
46518+ bprm->p ^= random32() & ~PAGE_MASK;
46519+#endif
46520+
46521 return 0;
46522 err:
46523 up_write(&mm->mmap_sem);
46524@@ -384,19 +421,7 @@ err:
46525 return err;
46526 }
46527
46528-struct user_arg_ptr {
46529-#ifdef CONFIG_COMPAT
46530- bool is_compat;
46531-#endif
46532- union {
46533- const char __user *const __user *native;
46534-#ifdef CONFIG_COMPAT
46535- const compat_uptr_t __user *compat;
46536-#endif
46537- } ptr;
46538-};
46539-
46540-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46541+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46542 {
46543 const char __user *native;
46544
46545@@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
46546 compat_uptr_t compat;
46547
46548 if (get_user(compat, argv.ptr.compat + nr))
46549- return ERR_PTR(-EFAULT);
46550+ return (const char __force_user *)ERR_PTR(-EFAULT);
46551
46552 return compat_ptr(compat);
46553 }
46554 #endif
46555
46556 if (get_user(native, argv.ptr.native + nr))
46557- return ERR_PTR(-EFAULT);
46558+ return (const char __force_user *)ERR_PTR(-EFAULT);
46559
46560 return native;
46561 }
46562@@ -431,11 +456,12 @@ static int count(struct user_arg_ptr argv, int max)
46563 if (!p)
46564 break;
46565
46566- if (IS_ERR(p))
46567+ if (IS_ERR((const char __force_kernel *)p))
46568 return -EFAULT;
46569
46570- if (i++ >= max)
46571+ if (i >= max)
46572 return -E2BIG;
46573+ ++i;
46574
46575 if (fatal_signal_pending(current))
46576 return -ERESTARTNOHAND;
46577@@ -465,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
46578
46579 ret = -EFAULT;
46580 str = get_user_arg_ptr(argv, argc);
46581- if (IS_ERR(str))
46582+ if (IS_ERR((const char __force_kernel *)str))
46583 goto out;
46584
46585 len = strnlen_user(str, MAX_ARG_STRLEN);
46586@@ -547,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
46587 int r;
46588 mm_segment_t oldfs = get_fs();
46589 struct user_arg_ptr argv = {
46590- .ptr.native = (const char __user *const __user *)__argv,
46591+ .ptr.native = (const char __force_user *const __force_user *)__argv,
46592 };
46593
46594 set_fs(KERNEL_DS);
46595@@ -582,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46596 unsigned long new_end = old_end - shift;
46597 struct mmu_gather tlb;
46598
46599- BUG_ON(new_start > new_end);
46600+ if (new_start >= new_end || new_start < mmap_min_addr)
46601+ return -ENOMEM;
46602
46603 /*
46604 * ensure there are no vmas between where we want to go
46605@@ -591,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
46606 if (vma != find_vma(mm, new_start))
46607 return -EFAULT;
46608
46609+#ifdef CONFIG_PAX_SEGMEXEC
46610+ BUG_ON(pax_find_mirror_vma(vma));
46611+#endif
46612+
46613 /*
46614 * cover the whole range: [new_start, old_end)
46615 */
46616@@ -671,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46617 stack_top = arch_align_stack(stack_top);
46618 stack_top = PAGE_ALIGN(stack_top);
46619
46620- if (unlikely(stack_top < mmap_min_addr) ||
46621- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
46622- return -ENOMEM;
46623-
46624 stack_shift = vma->vm_end - stack_top;
46625
46626 bprm->p -= stack_shift;
46627@@ -686,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
46628 bprm->exec -= stack_shift;
46629
46630 down_write(&mm->mmap_sem);
46631+
46632+ /* Move stack pages down in memory. */
46633+ if (stack_shift) {
46634+ ret = shift_arg_pages(vma, stack_shift);
46635+ if (ret)
46636+ goto out_unlock;
46637+ }
46638+
46639 vm_flags = VM_STACK_FLAGS;
46640
46641+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46642+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
46643+ vm_flags &= ~VM_EXEC;
46644+
46645+#ifdef CONFIG_PAX_MPROTECT
46646+ if (mm->pax_flags & MF_PAX_MPROTECT)
46647+ vm_flags &= ~VM_MAYEXEC;
46648+#endif
46649+
46650+ }
46651+#endif
46652+
46653 /*
46654 * Adjust stack execute permissions; explicitly enable for
46655 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
46656@@ -706,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
46657 goto out_unlock;
46658 BUG_ON(prev != vma);
46659
46660- /* Move stack pages down in memory. */
46661- if (stack_shift) {
46662- ret = shift_arg_pages(vma, stack_shift);
46663- if (ret)
46664- goto out_unlock;
46665- }
46666-
46667 /* mprotect_fixup is overkill to remove the temporary stack flags */
46668 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
46669
46670@@ -736,6 +776,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
46671 #endif
46672 current->mm->start_stack = bprm->p;
46673 ret = expand_stack(vma, stack_base);
46674+
46675+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
46676+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
46677+ unsigned long size, flags, vm_flags;
46678+
46679+ size = STACK_TOP - vma->vm_end;
46680+ flags = MAP_FIXED | MAP_PRIVATE;
46681+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
46682+
46683+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
46684+
46685+#ifdef CONFIG_X86
46686+ if (!ret) {
46687+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
46688+ ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
46689+ }
46690+#endif
46691+
46692+ }
46693+#endif
46694+
46695 if (ret)
46696 ret = -EFAULT;
46697
46698@@ -771,6 +832,8 @@ struct file *open_exec(const char *name)
46699
46700 fsnotify_open(file);
46701
46702+ trace_open_exec(name);
46703+
46704 err = deny_write_access(file);
46705 if (err)
46706 goto exit;
46707@@ -794,7 +857,7 @@ int kernel_read(struct file *file, loff_t offset,
46708 old_fs = get_fs();
46709 set_fs(get_ds());
46710 /* The cast to a user pointer is valid due to the set_fs() */
46711- result = vfs_read(file, (void __user *)addr, count, &pos);
46712+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
46713 set_fs(old_fs);
46714 return result;
46715 }
46716@@ -1246,7 +1309,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
46717 }
46718 rcu_read_unlock();
46719
46720- if (p->fs->users > n_fs) {
46721+ if (atomic_read(&p->fs->users) > n_fs) {
46722 bprm->unsafe |= LSM_UNSAFE_SHARE;
46723 } else {
46724 res = -EAGAIN;
46725@@ -1449,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
46726
46727 EXPORT_SYMBOL(search_binary_handler);
46728
46729+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46730+static DEFINE_PER_CPU(u64, exec_counter);
46731+static int __init init_exec_counters(void)
46732+{
46733+ unsigned int cpu;
46734+
46735+ for_each_possible_cpu(cpu) {
46736+ per_cpu(exec_counter, cpu) = (u64)cpu;
46737+ }
46738+
46739+ return 0;
46740+}
46741+early_initcall(init_exec_counters);
46742+static inline void increment_exec_counter(void)
46743+{
46744+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
46745+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
46746+}
46747+#else
46748+static inline void increment_exec_counter(void) {}
46749+#endif
46750+
46751 /*
46752 * sys_execve() executes a new program.
46753 */
46754@@ -1457,6 +1542,11 @@ static int do_execve_common(const char *filename,
46755 struct user_arg_ptr envp,
46756 struct pt_regs *regs)
46757 {
46758+#ifdef CONFIG_GRKERNSEC
46759+ struct file *old_exec_file;
46760+ struct acl_subject_label *old_acl;
46761+ struct rlimit old_rlim[RLIM_NLIMITS];
46762+#endif
46763 struct linux_binprm *bprm;
46764 struct file *file;
46765 struct files_struct *displaced;
46766@@ -1464,6 +1554,8 @@ static int do_execve_common(const char *filename,
46767 int retval;
46768 const struct cred *cred = current_cred();
46769
46770+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
46771+
46772 /*
46773 * We move the actual failure in case of RLIMIT_NPROC excess from
46774 * set*uid() to execve() because too many poorly written programs
46775@@ -1504,12 +1596,27 @@ static int do_execve_common(const char *filename,
46776 if (IS_ERR(file))
46777 goto out_unmark;
46778
46779+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
46780+ retval = -EPERM;
46781+ goto out_file;
46782+ }
46783+
46784 sched_exec();
46785
46786 bprm->file = file;
46787 bprm->filename = filename;
46788 bprm->interp = filename;
46789
46790+ if (gr_process_user_ban()) {
46791+ retval = -EPERM;
46792+ goto out_file;
46793+ }
46794+
46795+ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
46796+ retval = -EACCES;
46797+ goto out_file;
46798+ }
46799+
46800 retval = bprm_mm_init(bprm);
46801 if (retval)
46802 goto out_file;
46803@@ -1526,24 +1633,65 @@ static int do_execve_common(const char *filename,
46804 if (retval < 0)
46805 goto out;
46806
46807+#ifdef CONFIG_GRKERNSEC
46808+ old_acl = current->acl;
46809+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
46810+ old_exec_file = current->exec_file;
46811+ get_file(file);
46812+ current->exec_file = file;
46813+#endif
46814+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
46815+ /* limit suid stack to 8MB
46816+ we saved the old limits above and will restore them if this exec fails
46817+ */
46818+ if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
46819+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
46820+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
46821+#endif
46822+
46823+ if (!gr_tpe_allow(file)) {
46824+ retval = -EACCES;
46825+ goto out_fail;
46826+ }
46827+
46828+ if (gr_check_crash_exec(file)) {
46829+ retval = -EACCES;
46830+ goto out_fail;
46831+ }
46832+
46833+ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
46834+ bprm->unsafe);
46835+ if (retval < 0)
46836+ goto out_fail;
46837+
46838 retval = copy_strings_kernel(1, &bprm->filename, bprm);
46839 if (retval < 0)
46840- goto out;
46841+ goto out_fail;
46842
46843 bprm->exec = bprm->p;
46844 retval = copy_strings(bprm->envc, envp, bprm);
46845 if (retval < 0)
46846- goto out;
46847+ goto out_fail;
46848
46849 retval = copy_strings(bprm->argc, argv, bprm);
46850 if (retval < 0)
46851- goto out;
46852+ goto out_fail;
46853+
46854+ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
46855+
46856+ gr_handle_exec_args(bprm, argv);
46857
46858 retval = search_binary_handler(bprm,regs);
46859 if (retval < 0)
46860- goto out;
46861+ goto out_fail;
46862+#ifdef CONFIG_GRKERNSEC
46863+ if (old_exec_file)
46864+ fput(old_exec_file);
46865+#endif
46866
46867 /* execve succeeded */
46868+
46869+ increment_exec_counter();
46870 current->fs->in_exec = 0;
46871 current->in_execve = 0;
46872 acct_update_integrals(current);
46873@@ -1552,6 +1700,14 @@ static int do_execve_common(const char *filename,
46874 put_files_struct(displaced);
46875 return retval;
46876
46877+out_fail:
46878+#ifdef CONFIG_GRKERNSEC
46879+ current->acl = old_acl;
46880+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
46881+ fput(current->exec_file);
46882+ current->exec_file = old_exec_file;
46883+#endif
46884+
46885 out:
46886 if (bprm->mm) {
46887 acct_arg_size(bprm, 0);
46888@@ -1727,3 +1883,253 @@ int kernel_execve(const char *filename,
46889 ret_from_kernel_execve(p);
46890 }
46891 #endif
46892+
46893+int pax_check_flags(unsigned long *flags)
46894+{
46895+ int retval = 0;
46896+
46897+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
46898+ if (*flags & MF_PAX_SEGMEXEC)
46899+ {
46900+ *flags &= ~MF_PAX_SEGMEXEC;
46901+ retval = -EINVAL;
46902+ }
46903+#endif
46904+
46905+ if ((*flags & MF_PAX_PAGEEXEC)
46906+
46907+#ifdef CONFIG_PAX_PAGEEXEC
46908+ && (*flags & MF_PAX_SEGMEXEC)
46909+#endif
46910+
46911+ )
46912+ {
46913+ *flags &= ~MF_PAX_PAGEEXEC;
46914+ retval = -EINVAL;
46915+ }
46916+
46917+ if ((*flags & MF_PAX_MPROTECT)
46918+
46919+#ifdef CONFIG_PAX_MPROTECT
46920+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46921+#endif
46922+
46923+ )
46924+ {
46925+ *flags &= ~MF_PAX_MPROTECT;
46926+ retval = -EINVAL;
46927+ }
46928+
46929+ if ((*flags & MF_PAX_EMUTRAMP)
46930+
46931+#ifdef CONFIG_PAX_EMUTRAMP
46932+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
46933+#endif
46934+
46935+ )
46936+ {
46937+ *flags &= ~MF_PAX_EMUTRAMP;
46938+ retval = -EINVAL;
46939+ }
46940+
46941+ return retval;
46942+}
46943+
46944+EXPORT_SYMBOL(pax_check_flags);
46945+
46946+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
46947+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
46948+{
46949+ struct task_struct *tsk = current;
46950+ struct mm_struct *mm = current->mm;
46951+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
46952+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
46953+ char *path_exec = NULL;
46954+ char *path_fault = NULL;
46955+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
46956+ siginfo_t info = { };
46957+
46958+ if (buffer_exec && buffer_fault) {
46959+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
46960+
46961+ down_read(&mm->mmap_sem);
46962+ vma = mm->mmap;
46963+ while (vma && (!vma_exec || !vma_fault)) {
46964+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
46965+ vma_exec = vma;
46966+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
46967+ vma_fault = vma;
46968+ vma = vma->vm_next;
46969+ }
46970+ if (vma_exec) {
46971+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
46972+ if (IS_ERR(path_exec))
46973+ path_exec = "<path too long>";
46974+ else {
46975+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
46976+ if (path_exec) {
46977+ *path_exec = 0;
46978+ path_exec = buffer_exec;
46979+ } else
46980+ path_exec = "<path too long>";
46981+ }
46982+ }
46983+ if (vma_fault) {
46984+ start = vma_fault->vm_start;
46985+ end = vma_fault->vm_end;
46986+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
46987+ if (vma_fault->vm_file) {
46988+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
46989+ if (IS_ERR(path_fault))
46990+ path_fault = "<path too long>";
46991+ else {
46992+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
46993+ if (path_fault) {
46994+ *path_fault = 0;
46995+ path_fault = buffer_fault;
46996+ } else
46997+ path_fault = "<path too long>";
46998+ }
46999+ } else
47000+ path_fault = "<anonymous mapping>";
47001+ }
47002+ up_read(&mm->mmap_sem);
47003+ }
47004+ if (tsk->signal->curr_ip)
47005+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
47006+ else
47007+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
47008+ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
47009+ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
47010+ task_uid(tsk), task_euid(tsk), pc, sp);
47011+ free_page((unsigned long)buffer_exec);
47012+ free_page((unsigned long)buffer_fault);
47013+ pax_report_insns(regs, pc, sp);
47014+ info.si_signo = SIGKILL;
47015+ info.si_errno = 0;
47016+ info.si_code = SI_KERNEL;
47017+ info.si_pid = 0;
47018+ info.si_uid = 0;
47019+ do_coredump(&info, regs);
47020+}
47021+#endif
47022+
47023+#ifdef CONFIG_PAX_REFCOUNT
47024+void pax_report_refcount_overflow(struct pt_regs *regs)
47025+{
47026+ if (current->signal->curr_ip)
47027+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47028+ &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
47029+ else
47030+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
47031+ current->comm, task_pid_nr(current), current_uid(), current_euid());
47032+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
47033+ show_regs(regs);
47034+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
47035+}
47036+#endif
47037+
47038+#ifdef CONFIG_PAX_USERCOPY
47039+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
47040+static noinline int check_stack_object(const void *obj, unsigned long len)
47041+{
47042+ const void * const stack = task_stack_page(current);
47043+ const void * const stackend = stack + THREAD_SIZE;
47044+
47045+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47046+ const void *frame = NULL;
47047+ const void *oldframe;
47048+#endif
47049+
47050+ if (obj + len < obj)
47051+ return -1;
47052+
47053+ if (obj + len <= stack || stackend <= obj)
47054+ return 0;
47055+
47056+ if (obj < stack || stackend < obj + len)
47057+ return -1;
47058+
47059+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
47060+ oldframe = __builtin_frame_address(1);
47061+ if (oldframe)
47062+ frame = __builtin_frame_address(2);
47063+ /*
47064+ low ----------------------------------------------> high
47065+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
47066+ ^----------------^
47067+ allow copies only within here
47068+ */
47069+ while (stack <= frame && frame < stackend) {
47070+ /* if obj + len extends past the last frame, this
47071+ check won't pass and the next frame will be 0,
47072+ causing us to bail out and correctly report
47073+ the copy as invalid
47074+ */
47075+ if (obj + len <= frame)
47076+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
47077+ oldframe = frame;
47078+ frame = *(const void * const *)frame;
47079+ }
47080+ return -1;
47081+#else
47082+ return 1;
47083+#endif
47084+}
47085+
47086+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
47087+{
47088+ if (current->signal->curr_ip)
47089+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47090+ &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47091+ else
47092+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
47093+ to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
47094+ dump_stack();
47095+ gr_handle_kernel_exploit();
47096+ do_group_exit(SIGKILL);
47097+}
47098+#endif
47099+
47100+void check_object_size(const void *ptr, unsigned long n, bool to)
47101+{
47102+
47103+#ifdef CONFIG_PAX_USERCOPY
47104+ const char *type;
47105+
47106+ if (!n)
47107+ return;
47108+
47109+ type = check_heap_object(ptr, n);
47110+ if (!type) {
47111+ if (check_stack_object(ptr, n) != -1)
47112+ return;
47113+ type = "<process stack>";
47114+ }
47115+
47116+ pax_report_usercopy(ptr, n, to, type);
47117+#endif
47118+
47119+}
47120+EXPORT_SYMBOL(check_object_size);
47121+
47122+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
47123+void pax_track_stack(void)
47124+{
47125+ unsigned long sp = (unsigned long)&sp;
47126+ if (sp < current_thread_info()->lowest_stack &&
47127+ sp > (unsigned long)task_stack_page(current))
47128+ current_thread_info()->lowest_stack = sp;
47129+}
47130+EXPORT_SYMBOL(pax_track_stack);
47131+#endif
47132+
47133+#ifdef CONFIG_PAX_SIZE_OVERFLOW
47134+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
47135+{
47136+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
47137+ dump_stack();
47138+ do_group_exit(SIGKILL);
47139+}
47140+EXPORT_SYMBOL(report_size_overflow);
47141+#endif
47142diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
47143index 2616d0e..2ffdec9 100644
47144--- a/fs/ext2/balloc.c
47145+++ b/fs/ext2/balloc.c
47146@@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
47147
47148 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47149 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47150- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47151+ if (free_blocks < root_blocks + 1 &&
47152 !uid_eq(sbi->s_resuid, current_fsuid()) &&
47153 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47154- !in_group_p (sbi->s_resgid))) {
47155+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47156 return 0;
47157 }
47158 return 1;
47159diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
47160index 22548f5..41521d8 100644
47161--- a/fs/ext3/balloc.c
47162+++ b/fs/ext3/balloc.c
47163@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
47164
47165 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
47166 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
47167- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
47168+ if (free_blocks < root_blocks + 1 &&
47169 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
47170 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
47171- !in_group_p (sbi->s_resgid))) {
47172+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
47173 return 0;
47174 }
47175 return 1;
47176diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
47177index cf18217..8f6b9c3 100644
47178--- a/fs/ext4/balloc.c
47179+++ b/fs/ext4/balloc.c
47180@@ -498,8 +498,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
47181 /* Hm, nope. Are (enough) root reserved clusters available? */
47182 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
47183 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
47184- capable(CAP_SYS_RESOURCE) ||
47185- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
47186+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
47187+ capable_nolog(CAP_SYS_RESOURCE)) {
47188
47189 if (free_clusters >= (nclusters + dirty_clusters))
47190 return 1;
47191diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
47192index 3c20de1..6ff2460 100644
47193--- a/fs/ext4/ext4.h
47194+++ b/fs/ext4/ext4.h
47195@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
47196 unsigned long s_mb_last_start;
47197
47198 /* stats for buddy allocator */
47199- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
47200- atomic_t s_bal_success; /* we found long enough chunks */
47201- atomic_t s_bal_allocated; /* in blocks */
47202- atomic_t s_bal_ex_scanned; /* total extents scanned */
47203- atomic_t s_bal_goals; /* goal hits */
47204- atomic_t s_bal_breaks; /* too long searches */
47205- atomic_t s_bal_2orders; /* 2^order hits */
47206+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
47207+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
47208+ atomic_unchecked_t s_bal_allocated; /* in blocks */
47209+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
47210+ atomic_unchecked_t s_bal_goals; /* goal hits */
47211+ atomic_unchecked_t s_bal_breaks; /* too long searches */
47212+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
47213 spinlock_t s_bal_lock;
47214 unsigned long s_mb_buddies_generated;
47215 unsigned long long s_mb_generation_time;
47216- atomic_t s_mb_lost_chunks;
47217- atomic_t s_mb_preallocated;
47218- atomic_t s_mb_discarded;
47219+ atomic_unchecked_t s_mb_lost_chunks;
47220+ atomic_unchecked_t s_mb_preallocated;
47221+ atomic_unchecked_t s_mb_discarded;
47222 atomic_t s_lock_busy;
47223
47224 /* locality groups */
47225diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
47226index 526e553..3f2de85 100644
47227--- a/fs/ext4/mballoc.c
47228+++ b/fs/ext4/mballoc.c
47229@@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
47230 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
47231
47232 if (EXT4_SB(sb)->s_mb_stats)
47233- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
47234+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
47235
47236 break;
47237 }
47238@@ -2044,7 +2044,7 @@ repeat:
47239 ac->ac_status = AC_STATUS_CONTINUE;
47240 ac->ac_flags |= EXT4_MB_HINT_FIRST;
47241 cr = 3;
47242- atomic_inc(&sbi->s_mb_lost_chunks);
47243+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
47244 goto repeat;
47245 }
47246 }
47247@@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
47248 if (sbi->s_mb_stats) {
47249 ext4_msg(sb, KERN_INFO,
47250 "mballoc: %u blocks %u reqs (%u success)",
47251- atomic_read(&sbi->s_bal_allocated),
47252- atomic_read(&sbi->s_bal_reqs),
47253- atomic_read(&sbi->s_bal_success));
47254+ atomic_read_unchecked(&sbi->s_bal_allocated),
47255+ atomic_read_unchecked(&sbi->s_bal_reqs),
47256+ atomic_read_unchecked(&sbi->s_bal_success));
47257 ext4_msg(sb, KERN_INFO,
47258 "mballoc: %u extents scanned, %u goal hits, "
47259 "%u 2^N hits, %u breaks, %u lost",
47260- atomic_read(&sbi->s_bal_ex_scanned),
47261- atomic_read(&sbi->s_bal_goals),
47262- atomic_read(&sbi->s_bal_2orders),
47263- atomic_read(&sbi->s_bal_breaks),
47264- atomic_read(&sbi->s_mb_lost_chunks));
47265+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
47266+ atomic_read_unchecked(&sbi->s_bal_goals),
47267+ atomic_read_unchecked(&sbi->s_bal_2orders),
47268+ atomic_read_unchecked(&sbi->s_bal_breaks),
47269+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
47270 ext4_msg(sb, KERN_INFO,
47271 "mballoc: %lu generated and it took %Lu",
47272 sbi->s_mb_buddies_generated,
47273 sbi->s_mb_generation_time);
47274 ext4_msg(sb, KERN_INFO,
47275 "mballoc: %u preallocated, %u discarded",
47276- atomic_read(&sbi->s_mb_preallocated),
47277- atomic_read(&sbi->s_mb_discarded));
47278+ atomic_read_unchecked(&sbi->s_mb_preallocated),
47279+ atomic_read_unchecked(&sbi->s_mb_discarded));
47280 }
47281
47282 free_percpu(sbi->s_locality_groups);
47283@@ -3052,16 +3052,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
47284 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
47285
47286 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
47287- atomic_inc(&sbi->s_bal_reqs);
47288- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47289+ atomic_inc_unchecked(&sbi->s_bal_reqs);
47290+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
47291 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
47292- atomic_inc(&sbi->s_bal_success);
47293- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
47294+ atomic_inc_unchecked(&sbi->s_bal_success);
47295+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
47296 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
47297 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
47298- atomic_inc(&sbi->s_bal_goals);
47299+ atomic_inc_unchecked(&sbi->s_bal_goals);
47300 if (ac->ac_found > sbi->s_mb_max_to_scan)
47301- atomic_inc(&sbi->s_bal_breaks);
47302+ atomic_inc_unchecked(&sbi->s_bal_breaks);
47303 }
47304
47305 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
47306@@ -3461,7 +3461,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
47307 trace_ext4_mb_new_inode_pa(ac, pa);
47308
47309 ext4_mb_use_inode_pa(ac, pa);
47310- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
47311+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
47312
47313 ei = EXT4_I(ac->ac_inode);
47314 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47315@@ -3521,7 +3521,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
47316 trace_ext4_mb_new_group_pa(ac, pa);
47317
47318 ext4_mb_use_group_pa(ac, pa);
47319- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47320+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
47321
47322 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
47323 lg = ac->ac_lg;
47324@@ -3610,7 +3610,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
47325 * from the bitmap and continue.
47326 */
47327 }
47328- atomic_add(free, &sbi->s_mb_discarded);
47329+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
47330
47331 return err;
47332 }
47333@@ -3628,7 +3628,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
47334 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
47335 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
47336 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
47337- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47338+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
47339 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
47340
47341 return 0;
47342diff --git a/fs/ext4/super.c b/fs/ext4/super.c
47343index d59b351..775f8c8 100644
47344--- a/fs/ext4/super.c
47345+++ b/fs/ext4/super.c
47346@@ -3212,7 +3212,6 @@ int ext4_calculate_overhead(struct super_block *sb)
47347 ext4_fsblk_t overhead = 0;
47348 char *buf = (char *) get_zeroed_page(GFP_KERNEL);
47349
47350- memset(buf, 0, PAGE_SIZE);
47351 if (!buf)
47352 return -ENOMEM;
47353
47354diff --git a/fs/fcntl.c b/fs/fcntl.c
47355index 71a600a..20d87b1 100644
47356--- a/fs/fcntl.c
47357+++ b/fs/fcntl.c
47358@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
47359 if (err)
47360 return err;
47361
47362+ if (gr_handle_chroot_fowner(pid, type))
47363+ return -ENOENT;
47364+ if (gr_check_protected_task_fowner(pid, type))
47365+ return -EACCES;
47366+
47367 f_modown(filp, pid, type, force);
47368 return 0;
47369 }
47370diff --git a/fs/fhandle.c b/fs/fhandle.c
47371index f775bfd..629bd4c 100644
47372--- a/fs/fhandle.c
47373+++ b/fs/fhandle.c
47374@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
47375 } else
47376 retval = 0;
47377 /* copy the mount id */
47378- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
47379- sizeof(*mnt_id)) ||
47380+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
47381 copy_to_user(ufh, handle,
47382 sizeof(struct file_handle) + handle_bytes))
47383 retval = -EFAULT;
47384diff --git a/fs/fifo.c b/fs/fifo.c
47385index cf6f434..3d7942c 100644
47386--- a/fs/fifo.c
47387+++ b/fs/fifo.c
47388@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
47389 */
47390 filp->f_op = &read_pipefifo_fops;
47391 pipe->r_counter++;
47392- if (pipe->readers++ == 0)
47393+ if (atomic_inc_return(&pipe->readers) == 1)
47394 wake_up_partner(inode);
47395
47396- if (!pipe->writers) {
47397+ if (!atomic_read(&pipe->writers)) {
47398 if ((filp->f_flags & O_NONBLOCK)) {
47399 /* suppress POLLHUP until we have
47400 * seen a writer */
47401@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
47402 * errno=ENXIO when there is no process reading the FIFO.
47403 */
47404 ret = -ENXIO;
47405- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
47406+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
47407 goto err;
47408
47409 filp->f_op = &write_pipefifo_fops;
47410 pipe->w_counter++;
47411- if (!pipe->writers++)
47412+ if (atomic_inc_return(&pipe->writers) == 1)
47413 wake_up_partner(inode);
47414
47415- if (!pipe->readers) {
47416+ if (!atomic_read(&pipe->readers)) {
47417 if (wait_for_partner(inode, &pipe->r_counter))
47418 goto err_wr;
47419 }
47420@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
47421 */
47422 filp->f_op = &rdwr_pipefifo_fops;
47423
47424- pipe->readers++;
47425- pipe->writers++;
47426+ atomic_inc(&pipe->readers);
47427+ atomic_inc(&pipe->writers);
47428 pipe->r_counter++;
47429 pipe->w_counter++;
47430- if (pipe->readers == 1 || pipe->writers == 1)
47431+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
47432 wake_up_partner(inode);
47433 break;
47434
47435@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
47436 return 0;
47437
47438 err_rd:
47439- if (!--pipe->readers)
47440+ if (atomic_dec_and_test(&pipe->readers))
47441 wake_up_interruptible(&pipe->wait);
47442 ret = -ERESTARTSYS;
47443 goto err;
47444
47445 err_wr:
47446- if (!--pipe->writers)
47447+ if (atomic_dec_and_test(&pipe->writers))
47448 wake_up_interruptible(&pipe->wait);
47449 ret = -ERESTARTSYS;
47450 goto err;
47451
47452 err:
47453- if (!pipe->readers && !pipe->writers)
47454+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
47455 free_pipe_info(inode);
47456
47457 err_nocleanup:
47458diff --git a/fs/file.c b/fs/file.c
47459index eff2316..8c8930c 100644
47460--- a/fs/file.c
47461+++ b/fs/file.c
47462@@ -16,6 +16,7 @@
47463 #include <linux/slab.h>
47464 #include <linux/vmalloc.h>
47465 #include <linux/file.h>
47466+#include <linux/security.h>
47467 #include <linux/fdtable.h>
47468 #include <linux/bitops.h>
47469 #include <linux/interrupt.h>
47470@@ -898,6 +899,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
47471 if (!file)
47472 return __close_fd(files, fd);
47473
47474+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
47475 if (fd >= rlimit(RLIMIT_NOFILE))
47476 return -EBADF;
47477
47478@@ -924,6 +926,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
47479 if (unlikely(oldfd == newfd))
47480 return -EINVAL;
47481
47482+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
47483 if (newfd >= rlimit(RLIMIT_NOFILE))
47484 return -EBADF;
47485
47486@@ -979,6 +982,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
47487 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
47488 {
47489 int err;
47490+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
47491 if (from >= rlimit(RLIMIT_NOFILE))
47492 return -EINVAL;
47493 err = alloc_fd(from, flags);
47494diff --git a/fs/filesystems.c b/fs/filesystems.c
47495index da165f6..3671bdb 100644
47496--- a/fs/filesystems.c
47497+++ b/fs/filesystems.c
47498@@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
47499 int len = dot ? dot - name : strlen(name);
47500
47501 fs = __get_fs_type(name, len);
47502+
47503+#ifdef CONFIG_GRKERNSEC_MODHARDEN
47504+ if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
47505+#else
47506 if (!fs && (request_module("%.*s", len, name) == 0))
47507+#endif
47508 fs = __get_fs_type(name, len);
47509
47510 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
47511diff --git a/fs/fs_struct.c b/fs/fs_struct.c
47512index 5df4775..9d9336f 100644
47513--- a/fs/fs_struct.c
47514+++ b/fs/fs_struct.c
47515@@ -4,6 +4,7 @@
47516 #include <linux/path.h>
47517 #include <linux/slab.h>
47518 #include <linux/fs_struct.h>
47519+#include <linux/grsecurity.h>
47520 #include "internal.h"
47521
47522 /*
47523@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
47524 write_seqcount_begin(&fs->seq);
47525 old_root = fs->root;
47526 fs->root = *path;
47527+ gr_set_chroot_entries(current, path);
47528 write_seqcount_end(&fs->seq);
47529 spin_unlock(&fs->lock);
47530 if (old_root.dentry)
47531@@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
47532 return 1;
47533 }
47534
47535+static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
47536+{
47537+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
47538+ return 0;
47539+ *p = *new;
47540+
47541+ /* This function is only called from pivot_root(). Leave our
47542+ gr_chroot_dentry and is_chrooted flags as-is, so that a
47543+ pivoted root isn't treated as a chroot
47544+ */
47545+ //gr_set_chroot_entries(task, new);
47546+
47547+ return 1;
47548+}
47549+
47550 void chroot_fs_refs(struct path *old_root, struct path *new_root)
47551 {
47552 struct task_struct *g, *p;
47553@@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
47554 int hits = 0;
47555 spin_lock(&fs->lock);
47556 write_seqcount_begin(&fs->seq);
47557- hits += replace_path(&fs->root, old_root, new_root);
47558+ hits += replace_root_path(p, &fs->root, old_root, new_root);
47559 hits += replace_path(&fs->pwd, old_root, new_root);
47560 write_seqcount_end(&fs->seq);
47561 while (hits--) {
47562@@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
47563 task_lock(tsk);
47564 spin_lock(&fs->lock);
47565 tsk->fs = NULL;
47566- kill = !--fs->users;
47567+ gr_clear_chroot_entries(tsk);
47568+ kill = !atomic_dec_return(&fs->users);
47569 spin_unlock(&fs->lock);
47570 task_unlock(tsk);
47571 if (kill)
47572@@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47573 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
47574 /* We don't need to lock fs - think why ;-) */
47575 if (fs) {
47576- fs->users = 1;
47577+ atomic_set(&fs->users, 1);
47578 fs->in_exec = 0;
47579 spin_lock_init(&fs->lock);
47580 seqcount_init(&fs->seq);
47581@@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
47582 spin_lock(&old->lock);
47583 fs->root = old->root;
47584 path_get(&fs->root);
47585+ /* instead of calling gr_set_chroot_entries here,
47586+ we call it from every caller of this function
47587+ */
47588 fs->pwd = old->pwd;
47589 path_get(&fs->pwd);
47590 spin_unlock(&old->lock);
47591@@ -139,8 +160,9 @@ int unshare_fs_struct(void)
47592
47593 task_lock(current);
47594 spin_lock(&fs->lock);
47595- kill = !--fs->users;
47596+ kill = !atomic_dec_return(&fs->users);
47597 current->fs = new_fs;
47598+ gr_set_chroot_entries(current, &new_fs->root);
47599 spin_unlock(&fs->lock);
47600 task_unlock(current);
47601
47602@@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
47603
47604 int current_umask(void)
47605 {
47606- return current->fs->umask;
47607+ return current->fs->umask | gr_acl_umask();
47608 }
47609 EXPORT_SYMBOL(current_umask);
47610
47611 /* to be mentioned only in INIT_TASK */
47612 struct fs_struct init_fs = {
47613- .users = 1,
47614+ .users = ATOMIC_INIT(1),
47615 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
47616 .seq = SEQCNT_ZERO,
47617 .umask = 0022,
47618@@ -175,12 +197,13 @@ void daemonize_fs_struct(void)
47619 task_lock(current);
47620
47621 spin_lock(&init_fs.lock);
47622- init_fs.users++;
47623+ atomic_inc(&init_fs.users);
47624 spin_unlock(&init_fs.lock);
47625
47626 spin_lock(&fs->lock);
47627 current->fs = &init_fs;
47628- kill = !--fs->users;
47629+ gr_set_chroot_entries(current, &current->fs->root);
47630+ kill = !atomic_dec_return(&fs->users);
47631 spin_unlock(&fs->lock);
47632
47633 task_unlock(current);
47634diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
47635index 9905350..02eaec4 100644
47636--- a/fs/fscache/cookie.c
47637+++ b/fs/fscache/cookie.c
47638@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
47639 parent ? (char *) parent->def->name : "<no-parent>",
47640 def->name, netfs_data);
47641
47642- fscache_stat(&fscache_n_acquires);
47643+ fscache_stat_unchecked(&fscache_n_acquires);
47644
47645 /* if there's no parent cookie, then we don't create one here either */
47646 if (!parent) {
47647- fscache_stat(&fscache_n_acquires_null);
47648+ fscache_stat_unchecked(&fscache_n_acquires_null);
47649 _leave(" [no parent]");
47650 return NULL;
47651 }
47652@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
47653 /* allocate and initialise a cookie */
47654 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
47655 if (!cookie) {
47656- fscache_stat(&fscache_n_acquires_oom);
47657+ fscache_stat_unchecked(&fscache_n_acquires_oom);
47658 _leave(" [ENOMEM]");
47659 return NULL;
47660 }
47661@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47662
47663 switch (cookie->def->type) {
47664 case FSCACHE_COOKIE_TYPE_INDEX:
47665- fscache_stat(&fscache_n_cookie_index);
47666+ fscache_stat_unchecked(&fscache_n_cookie_index);
47667 break;
47668 case FSCACHE_COOKIE_TYPE_DATAFILE:
47669- fscache_stat(&fscache_n_cookie_data);
47670+ fscache_stat_unchecked(&fscache_n_cookie_data);
47671 break;
47672 default:
47673- fscache_stat(&fscache_n_cookie_special);
47674+ fscache_stat_unchecked(&fscache_n_cookie_special);
47675 break;
47676 }
47677
47678@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
47679 if (fscache_acquire_non_index_cookie(cookie) < 0) {
47680 atomic_dec(&parent->n_children);
47681 __fscache_cookie_put(cookie);
47682- fscache_stat(&fscache_n_acquires_nobufs);
47683+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
47684 _leave(" = NULL");
47685 return NULL;
47686 }
47687 }
47688
47689- fscache_stat(&fscache_n_acquires_ok);
47690+ fscache_stat_unchecked(&fscache_n_acquires_ok);
47691 _leave(" = %p", cookie);
47692 return cookie;
47693 }
47694@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
47695 cache = fscache_select_cache_for_object(cookie->parent);
47696 if (!cache) {
47697 up_read(&fscache_addremove_sem);
47698- fscache_stat(&fscache_n_acquires_no_cache);
47699+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
47700 _leave(" = -ENOMEDIUM [no cache]");
47701 return -ENOMEDIUM;
47702 }
47703@@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
47704 object = cache->ops->alloc_object(cache, cookie);
47705 fscache_stat_d(&fscache_n_cop_alloc_object);
47706 if (IS_ERR(object)) {
47707- fscache_stat(&fscache_n_object_no_alloc);
47708+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
47709 ret = PTR_ERR(object);
47710 goto error;
47711 }
47712
47713- fscache_stat(&fscache_n_object_alloc);
47714+ fscache_stat_unchecked(&fscache_n_object_alloc);
47715
47716 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
47717
47718@@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
47719 struct fscache_object *object;
47720 struct hlist_node *_p;
47721
47722- fscache_stat(&fscache_n_updates);
47723+ fscache_stat_unchecked(&fscache_n_updates);
47724
47725 if (!cookie) {
47726- fscache_stat(&fscache_n_updates_null);
47727+ fscache_stat_unchecked(&fscache_n_updates_null);
47728 _leave(" [no cookie]");
47729 return;
47730 }
47731@@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47732 struct fscache_object *object;
47733 unsigned long event;
47734
47735- fscache_stat(&fscache_n_relinquishes);
47736+ fscache_stat_unchecked(&fscache_n_relinquishes);
47737 if (retire)
47738- fscache_stat(&fscache_n_relinquishes_retire);
47739+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
47740
47741 if (!cookie) {
47742- fscache_stat(&fscache_n_relinquishes_null);
47743+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
47744 _leave(" [no cookie]");
47745 return;
47746 }
47747@@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
47748
47749 /* wait for the cookie to finish being instantiated (or to fail) */
47750 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
47751- fscache_stat(&fscache_n_relinquishes_waitcrt);
47752+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
47753 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
47754 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
47755 }
47756diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
47757index f6aad48..88dcf26 100644
47758--- a/fs/fscache/internal.h
47759+++ b/fs/fscache/internal.h
47760@@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
47761 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
47762 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
47763
47764-extern atomic_t fscache_n_op_pend;
47765-extern atomic_t fscache_n_op_run;
47766-extern atomic_t fscache_n_op_enqueue;
47767-extern atomic_t fscache_n_op_deferred_release;
47768-extern atomic_t fscache_n_op_release;
47769-extern atomic_t fscache_n_op_gc;
47770-extern atomic_t fscache_n_op_cancelled;
47771-extern atomic_t fscache_n_op_rejected;
47772+extern atomic_unchecked_t fscache_n_op_pend;
47773+extern atomic_unchecked_t fscache_n_op_run;
47774+extern atomic_unchecked_t fscache_n_op_enqueue;
47775+extern atomic_unchecked_t fscache_n_op_deferred_release;
47776+extern atomic_unchecked_t fscache_n_op_release;
47777+extern atomic_unchecked_t fscache_n_op_gc;
47778+extern atomic_unchecked_t fscache_n_op_cancelled;
47779+extern atomic_unchecked_t fscache_n_op_rejected;
47780
47781-extern atomic_t fscache_n_attr_changed;
47782-extern atomic_t fscache_n_attr_changed_ok;
47783-extern atomic_t fscache_n_attr_changed_nobufs;
47784-extern atomic_t fscache_n_attr_changed_nomem;
47785-extern atomic_t fscache_n_attr_changed_calls;
47786+extern atomic_unchecked_t fscache_n_attr_changed;
47787+extern atomic_unchecked_t fscache_n_attr_changed_ok;
47788+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
47789+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
47790+extern atomic_unchecked_t fscache_n_attr_changed_calls;
47791
47792-extern atomic_t fscache_n_allocs;
47793-extern atomic_t fscache_n_allocs_ok;
47794-extern atomic_t fscache_n_allocs_wait;
47795-extern atomic_t fscache_n_allocs_nobufs;
47796-extern atomic_t fscache_n_allocs_intr;
47797-extern atomic_t fscache_n_allocs_object_dead;
47798-extern atomic_t fscache_n_alloc_ops;
47799-extern atomic_t fscache_n_alloc_op_waits;
47800+extern atomic_unchecked_t fscache_n_allocs;
47801+extern atomic_unchecked_t fscache_n_allocs_ok;
47802+extern atomic_unchecked_t fscache_n_allocs_wait;
47803+extern atomic_unchecked_t fscache_n_allocs_nobufs;
47804+extern atomic_unchecked_t fscache_n_allocs_intr;
47805+extern atomic_unchecked_t fscache_n_allocs_object_dead;
47806+extern atomic_unchecked_t fscache_n_alloc_ops;
47807+extern atomic_unchecked_t fscache_n_alloc_op_waits;
47808
47809-extern atomic_t fscache_n_retrievals;
47810-extern atomic_t fscache_n_retrievals_ok;
47811-extern atomic_t fscache_n_retrievals_wait;
47812-extern atomic_t fscache_n_retrievals_nodata;
47813-extern atomic_t fscache_n_retrievals_nobufs;
47814-extern atomic_t fscache_n_retrievals_intr;
47815-extern atomic_t fscache_n_retrievals_nomem;
47816-extern atomic_t fscache_n_retrievals_object_dead;
47817-extern atomic_t fscache_n_retrieval_ops;
47818-extern atomic_t fscache_n_retrieval_op_waits;
47819+extern atomic_unchecked_t fscache_n_retrievals;
47820+extern atomic_unchecked_t fscache_n_retrievals_ok;
47821+extern atomic_unchecked_t fscache_n_retrievals_wait;
47822+extern atomic_unchecked_t fscache_n_retrievals_nodata;
47823+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
47824+extern atomic_unchecked_t fscache_n_retrievals_intr;
47825+extern atomic_unchecked_t fscache_n_retrievals_nomem;
47826+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
47827+extern atomic_unchecked_t fscache_n_retrieval_ops;
47828+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
47829
47830-extern atomic_t fscache_n_stores;
47831-extern atomic_t fscache_n_stores_ok;
47832-extern atomic_t fscache_n_stores_again;
47833-extern atomic_t fscache_n_stores_nobufs;
47834-extern atomic_t fscache_n_stores_oom;
47835-extern atomic_t fscache_n_store_ops;
47836-extern atomic_t fscache_n_store_calls;
47837-extern atomic_t fscache_n_store_pages;
47838-extern atomic_t fscache_n_store_radix_deletes;
47839-extern atomic_t fscache_n_store_pages_over_limit;
47840+extern atomic_unchecked_t fscache_n_stores;
47841+extern atomic_unchecked_t fscache_n_stores_ok;
47842+extern atomic_unchecked_t fscache_n_stores_again;
47843+extern atomic_unchecked_t fscache_n_stores_nobufs;
47844+extern atomic_unchecked_t fscache_n_stores_oom;
47845+extern atomic_unchecked_t fscache_n_store_ops;
47846+extern atomic_unchecked_t fscache_n_store_calls;
47847+extern atomic_unchecked_t fscache_n_store_pages;
47848+extern atomic_unchecked_t fscache_n_store_radix_deletes;
47849+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
47850
47851-extern atomic_t fscache_n_store_vmscan_not_storing;
47852-extern atomic_t fscache_n_store_vmscan_gone;
47853-extern atomic_t fscache_n_store_vmscan_busy;
47854-extern atomic_t fscache_n_store_vmscan_cancelled;
47855+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47856+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
47857+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
47858+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47859
47860-extern atomic_t fscache_n_marks;
47861-extern atomic_t fscache_n_uncaches;
47862+extern atomic_unchecked_t fscache_n_marks;
47863+extern atomic_unchecked_t fscache_n_uncaches;
47864
47865-extern atomic_t fscache_n_acquires;
47866-extern atomic_t fscache_n_acquires_null;
47867-extern atomic_t fscache_n_acquires_no_cache;
47868-extern atomic_t fscache_n_acquires_ok;
47869-extern atomic_t fscache_n_acquires_nobufs;
47870-extern atomic_t fscache_n_acquires_oom;
47871+extern atomic_unchecked_t fscache_n_acquires;
47872+extern atomic_unchecked_t fscache_n_acquires_null;
47873+extern atomic_unchecked_t fscache_n_acquires_no_cache;
47874+extern atomic_unchecked_t fscache_n_acquires_ok;
47875+extern atomic_unchecked_t fscache_n_acquires_nobufs;
47876+extern atomic_unchecked_t fscache_n_acquires_oom;
47877
47878-extern atomic_t fscache_n_updates;
47879-extern atomic_t fscache_n_updates_null;
47880-extern atomic_t fscache_n_updates_run;
47881+extern atomic_unchecked_t fscache_n_updates;
47882+extern atomic_unchecked_t fscache_n_updates_null;
47883+extern atomic_unchecked_t fscache_n_updates_run;
47884
47885-extern atomic_t fscache_n_relinquishes;
47886-extern atomic_t fscache_n_relinquishes_null;
47887-extern atomic_t fscache_n_relinquishes_waitcrt;
47888-extern atomic_t fscache_n_relinquishes_retire;
47889+extern atomic_unchecked_t fscache_n_relinquishes;
47890+extern atomic_unchecked_t fscache_n_relinquishes_null;
47891+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47892+extern atomic_unchecked_t fscache_n_relinquishes_retire;
47893
47894-extern atomic_t fscache_n_cookie_index;
47895-extern atomic_t fscache_n_cookie_data;
47896-extern atomic_t fscache_n_cookie_special;
47897+extern atomic_unchecked_t fscache_n_cookie_index;
47898+extern atomic_unchecked_t fscache_n_cookie_data;
47899+extern atomic_unchecked_t fscache_n_cookie_special;
47900
47901-extern atomic_t fscache_n_object_alloc;
47902-extern atomic_t fscache_n_object_no_alloc;
47903-extern atomic_t fscache_n_object_lookups;
47904-extern atomic_t fscache_n_object_lookups_negative;
47905-extern atomic_t fscache_n_object_lookups_positive;
47906-extern atomic_t fscache_n_object_lookups_timed_out;
47907-extern atomic_t fscache_n_object_created;
47908-extern atomic_t fscache_n_object_avail;
47909-extern atomic_t fscache_n_object_dead;
47910+extern atomic_unchecked_t fscache_n_object_alloc;
47911+extern atomic_unchecked_t fscache_n_object_no_alloc;
47912+extern atomic_unchecked_t fscache_n_object_lookups;
47913+extern atomic_unchecked_t fscache_n_object_lookups_negative;
47914+extern atomic_unchecked_t fscache_n_object_lookups_positive;
47915+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
47916+extern atomic_unchecked_t fscache_n_object_created;
47917+extern atomic_unchecked_t fscache_n_object_avail;
47918+extern atomic_unchecked_t fscache_n_object_dead;
47919
47920-extern atomic_t fscache_n_checkaux_none;
47921-extern atomic_t fscache_n_checkaux_okay;
47922-extern atomic_t fscache_n_checkaux_update;
47923-extern atomic_t fscache_n_checkaux_obsolete;
47924+extern atomic_unchecked_t fscache_n_checkaux_none;
47925+extern atomic_unchecked_t fscache_n_checkaux_okay;
47926+extern atomic_unchecked_t fscache_n_checkaux_update;
47927+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
47928
47929 extern atomic_t fscache_n_cop_alloc_object;
47930 extern atomic_t fscache_n_cop_lookup_object;
47931@@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
47932 atomic_inc(stat);
47933 }
47934
47935+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
47936+{
47937+ atomic_inc_unchecked(stat);
47938+}
47939+
47940 static inline void fscache_stat_d(atomic_t *stat)
47941 {
47942 atomic_dec(stat);
47943@@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
47944
47945 #define __fscache_stat(stat) (NULL)
47946 #define fscache_stat(stat) do {} while (0)
47947+#define fscache_stat_unchecked(stat) do {} while (0)
47948 #define fscache_stat_d(stat) do {} while (0)
47949 #endif
47950
47951diff --git a/fs/fscache/object.c b/fs/fscache/object.c
47952index b6b897c..0ffff9c 100644
47953--- a/fs/fscache/object.c
47954+++ b/fs/fscache/object.c
47955@@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47956 /* update the object metadata on disk */
47957 case FSCACHE_OBJECT_UPDATING:
47958 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
47959- fscache_stat(&fscache_n_updates_run);
47960+ fscache_stat_unchecked(&fscache_n_updates_run);
47961 fscache_stat(&fscache_n_cop_update_object);
47962 object->cache->ops->update_object(object);
47963 fscache_stat_d(&fscache_n_cop_update_object);
47964@@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47965 spin_lock(&object->lock);
47966 object->state = FSCACHE_OBJECT_DEAD;
47967 spin_unlock(&object->lock);
47968- fscache_stat(&fscache_n_object_dead);
47969+ fscache_stat_unchecked(&fscache_n_object_dead);
47970 goto terminal_transit;
47971
47972 /* handle the parent cache of this object being withdrawn from
47973@@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
47974 spin_lock(&object->lock);
47975 object->state = FSCACHE_OBJECT_DEAD;
47976 spin_unlock(&object->lock);
47977- fscache_stat(&fscache_n_object_dead);
47978+ fscache_stat_unchecked(&fscache_n_object_dead);
47979 goto terminal_transit;
47980
47981 /* complain about the object being woken up once it is
47982@@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47983 parent->cookie->def->name, cookie->def->name,
47984 object->cache->tag->name);
47985
47986- fscache_stat(&fscache_n_object_lookups);
47987+ fscache_stat_unchecked(&fscache_n_object_lookups);
47988 fscache_stat(&fscache_n_cop_lookup_object);
47989 ret = object->cache->ops->lookup_object(object);
47990 fscache_stat_d(&fscache_n_cop_lookup_object);
47991@@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
47992 if (ret == -ETIMEDOUT) {
47993 /* probably stuck behind another object, so move this one to
47994 * the back of the queue */
47995- fscache_stat(&fscache_n_object_lookups_timed_out);
47996+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
47997 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
47998 }
47999
48000@@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
48001
48002 spin_lock(&object->lock);
48003 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48004- fscache_stat(&fscache_n_object_lookups_negative);
48005+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
48006
48007 /* transit here to allow write requests to begin stacking up
48008 * and read requests to begin returning ENODATA */
48009@@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
48010 * result, in which case there may be data available */
48011 spin_lock(&object->lock);
48012 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
48013- fscache_stat(&fscache_n_object_lookups_positive);
48014+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
48015
48016 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
48017
48018@@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
48019 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
48020 } else {
48021 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
48022- fscache_stat(&fscache_n_object_created);
48023+ fscache_stat_unchecked(&fscache_n_object_created);
48024
48025 object->state = FSCACHE_OBJECT_AVAILABLE;
48026 spin_unlock(&object->lock);
48027@@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
48028 fscache_enqueue_dependents(object);
48029
48030 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
48031- fscache_stat(&fscache_n_object_avail);
48032+ fscache_stat_unchecked(&fscache_n_object_avail);
48033
48034 _leave("");
48035 }
48036@@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48037 enum fscache_checkaux result;
48038
48039 if (!object->cookie->def->check_aux) {
48040- fscache_stat(&fscache_n_checkaux_none);
48041+ fscache_stat_unchecked(&fscache_n_checkaux_none);
48042 return FSCACHE_CHECKAUX_OKAY;
48043 }
48044
48045@@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
48046 switch (result) {
48047 /* entry okay as is */
48048 case FSCACHE_CHECKAUX_OKAY:
48049- fscache_stat(&fscache_n_checkaux_okay);
48050+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
48051 break;
48052
48053 /* entry requires update */
48054 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
48055- fscache_stat(&fscache_n_checkaux_update);
48056+ fscache_stat_unchecked(&fscache_n_checkaux_update);
48057 break;
48058
48059 /* entry requires deletion */
48060 case FSCACHE_CHECKAUX_OBSOLETE:
48061- fscache_stat(&fscache_n_checkaux_obsolete);
48062+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
48063 break;
48064
48065 default:
48066diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
48067index 30afdfa..2256596 100644
48068--- a/fs/fscache/operation.c
48069+++ b/fs/fscache/operation.c
48070@@ -17,7 +17,7 @@
48071 #include <linux/slab.h>
48072 #include "internal.h"
48073
48074-atomic_t fscache_op_debug_id;
48075+atomic_unchecked_t fscache_op_debug_id;
48076 EXPORT_SYMBOL(fscache_op_debug_id);
48077
48078 /**
48079@@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
48080 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
48081 ASSERTCMP(atomic_read(&op->usage), >, 0);
48082
48083- fscache_stat(&fscache_n_op_enqueue);
48084+ fscache_stat_unchecked(&fscache_n_op_enqueue);
48085 switch (op->flags & FSCACHE_OP_TYPE) {
48086 case FSCACHE_OP_ASYNC:
48087 _debug("queue async");
48088@@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
48089 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
48090 if (op->processor)
48091 fscache_enqueue_operation(op);
48092- fscache_stat(&fscache_n_op_run);
48093+ fscache_stat_unchecked(&fscache_n_op_run);
48094 }
48095
48096 /*
48097@@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48098 if (object->n_ops > 1) {
48099 atomic_inc(&op->usage);
48100 list_add_tail(&op->pend_link, &object->pending_ops);
48101- fscache_stat(&fscache_n_op_pend);
48102+ fscache_stat_unchecked(&fscache_n_op_pend);
48103 } else if (!list_empty(&object->pending_ops)) {
48104 atomic_inc(&op->usage);
48105 list_add_tail(&op->pend_link, &object->pending_ops);
48106- fscache_stat(&fscache_n_op_pend);
48107+ fscache_stat_unchecked(&fscache_n_op_pend);
48108 fscache_start_operations(object);
48109 } else {
48110 ASSERTCMP(object->n_in_progress, ==, 0);
48111@@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
48112 object->n_exclusive++; /* reads and writes must wait */
48113 atomic_inc(&op->usage);
48114 list_add_tail(&op->pend_link, &object->pending_ops);
48115- fscache_stat(&fscache_n_op_pend);
48116+ fscache_stat_unchecked(&fscache_n_op_pend);
48117 ret = 0;
48118 } else {
48119 /* not allowed to submit ops in any other state */
48120@@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
48121 if (object->n_exclusive > 0) {
48122 atomic_inc(&op->usage);
48123 list_add_tail(&op->pend_link, &object->pending_ops);
48124- fscache_stat(&fscache_n_op_pend);
48125+ fscache_stat_unchecked(&fscache_n_op_pend);
48126 } else if (!list_empty(&object->pending_ops)) {
48127 atomic_inc(&op->usage);
48128 list_add_tail(&op->pend_link, &object->pending_ops);
48129- fscache_stat(&fscache_n_op_pend);
48130+ fscache_stat_unchecked(&fscache_n_op_pend);
48131 fscache_start_operations(object);
48132 } else {
48133 ASSERTCMP(object->n_exclusive, ==, 0);
48134@@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
48135 object->n_ops++;
48136 atomic_inc(&op->usage);
48137 list_add_tail(&op->pend_link, &object->pending_ops);
48138- fscache_stat(&fscache_n_op_pend);
48139+ fscache_stat_unchecked(&fscache_n_op_pend);
48140 ret = 0;
48141 } else if (object->state == FSCACHE_OBJECT_DYING ||
48142 object->state == FSCACHE_OBJECT_LC_DYING ||
48143 object->state == FSCACHE_OBJECT_WITHDRAWING) {
48144- fscache_stat(&fscache_n_op_rejected);
48145+ fscache_stat_unchecked(&fscache_n_op_rejected);
48146 ret = -ENOBUFS;
48147 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
48148 fscache_report_unexpected_submission(object, op, ostate);
48149@@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
48150
48151 ret = -EBUSY;
48152 if (!list_empty(&op->pend_link)) {
48153- fscache_stat(&fscache_n_op_cancelled);
48154+ fscache_stat_unchecked(&fscache_n_op_cancelled);
48155 list_del_init(&op->pend_link);
48156 object->n_ops--;
48157 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
48158@@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
48159 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
48160 BUG();
48161
48162- fscache_stat(&fscache_n_op_release);
48163+ fscache_stat_unchecked(&fscache_n_op_release);
48164
48165 if (op->release) {
48166 op->release(op);
48167@@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
48168 * lock, and defer it otherwise */
48169 if (!spin_trylock(&object->lock)) {
48170 _debug("defer put");
48171- fscache_stat(&fscache_n_op_deferred_release);
48172+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
48173
48174 cache = object->cache;
48175 spin_lock(&cache->op_gc_list_lock);
48176@@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
48177
48178 _debug("GC DEFERRED REL OBJ%x OP%x",
48179 object->debug_id, op->debug_id);
48180- fscache_stat(&fscache_n_op_gc);
48181+ fscache_stat_unchecked(&fscache_n_op_gc);
48182
48183 ASSERTCMP(atomic_read(&op->usage), ==, 0);
48184
48185diff --git a/fs/fscache/page.c b/fs/fscache/page.c
48186index 3f7a59b..cf196cc 100644
48187--- a/fs/fscache/page.c
48188+++ b/fs/fscache/page.c
48189@@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48190 val = radix_tree_lookup(&cookie->stores, page->index);
48191 if (!val) {
48192 rcu_read_unlock();
48193- fscache_stat(&fscache_n_store_vmscan_not_storing);
48194+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
48195 __fscache_uncache_page(cookie, page);
48196 return true;
48197 }
48198@@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
48199 spin_unlock(&cookie->stores_lock);
48200
48201 if (xpage) {
48202- fscache_stat(&fscache_n_store_vmscan_cancelled);
48203- fscache_stat(&fscache_n_store_radix_deletes);
48204+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
48205+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48206 ASSERTCMP(xpage, ==, page);
48207 } else {
48208- fscache_stat(&fscache_n_store_vmscan_gone);
48209+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
48210 }
48211
48212 wake_up_bit(&cookie->flags, 0);
48213@@ -107,7 +107,7 @@ page_busy:
48214 /* we might want to wait here, but that could deadlock the allocator as
48215 * the work threads writing to the cache may all end up sleeping
48216 * on memory allocation */
48217- fscache_stat(&fscache_n_store_vmscan_busy);
48218+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
48219 return false;
48220 }
48221 EXPORT_SYMBOL(__fscache_maybe_release_page);
48222@@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
48223 FSCACHE_COOKIE_STORING_TAG);
48224 if (!radix_tree_tag_get(&cookie->stores, page->index,
48225 FSCACHE_COOKIE_PENDING_TAG)) {
48226- fscache_stat(&fscache_n_store_radix_deletes);
48227+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
48228 xpage = radix_tree_delete(&cookie->stores, page->index);
48229 }
48230 spin_unlock(&cookie->stores_lock);
48231@@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
48232
48233 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
48234
48235- fscache_stat(&fscache_n_attr_changed_calls);
48236+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
48237
48238 if (fscache_object_is_active(object)) {
48239 fscache_stat(&fscache_n_cop_attr_changed);
48240@@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48241
48242 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48243
48244- fscache_stat(&fscache_n_attr_changed);
48245+ fscache_stat_unchecked(&fscache_n_attr_changed);
48246
48247 op = kzalloc(sizeof(*op), GFP_KERNEL);
48248 if (!op) {
48249- fscache_stat(&fscache_n_attr_changed_nomem);
48250+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
48251 _leave(" = -ENOMEM");
48252 return -ENOMEM;
48253 }
48254@@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48255 if (fscache_submit_exclusive_op(object, op) < 0)
48256 goto nobufs;
48257 spin_unlock(&cookie->lock);
48258- fscache_stat(&fscache_n_attr_changed_ok);
48259+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
48260 fscache_put_operation(op);
48261 _leave(" = 0");
48262 return 0;
48263@@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
48264 nobufs:
48265 spin_unlock(&cookie->lock);
48266 kfree(op);
48267- fscache_stat(&fscache_n_attr_changed_nobufs);
48268+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
48269 _leave(" = %d", -ENOBUFS);
48270 return -ENOBUFS;
48271 }
48272@@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
48273 /* allocate a retrieval operation and attempt to submit it */
48274 op = kzalloc(sizeof(*op), GFP_NOIO);
48275 if (!op) {
48276- fscache_stat(&fscache_n_retrievals_nomem);
48277+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48278 return NULL;
48279 }
48280
48281@@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48282 return 0;
48283 }
48284
48285- fscache_stat(&fscache_n_retrievals_wait);
48286+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
48287
48288 jif = jiffies;
48289 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
48290 fscache_wait_bit_interruptible,
48291 TASK_INTERRUPTIBLE) != 0) {
48292- fscache_stat(&fscache_n_retrievals_intr);
48293+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48294 _leave(" = -ERESTARTSYS");
48295 return -ERESTARTSYS;
48296 }
48297@@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
48298 */
48299 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48300 struct fscache_retrieval *op,
48301- atomic_t *stat_op_waits,
48302- atomic_t *stat_object_dead)
48303+ atomic_unchecked_t *stat_op_waits,
48304+ atomic_unchecked_t *stat_object_dead)
48305 {
48306 int ret;
48307
48308@@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48309 goto check_if_dead;
48310
48311 _debug(">>> WT");
48312- fscache_stat(stat_op_waits);
48313+ fscache_stat_unchecked(stat_op_waits);
48314 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
48315 fscache_wait_bit_interruptible,
48316 TASK_INTERRUPTIBLE) < 0) {
48317@@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
48318
48319 check_if_dead:
48320 if (unlikely(fscache_object_is_dead(object))) {
48321- fscache_stat(stat_object_dead);
48322+ fscache_stat_unchecked(stat_object_dead);
48323 return -ENOBUFS;
48324 }
48325 return 0;
48326@@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48327
48328 _enter("%p,%p,,,", cookie, page);
48329
48330- fscache_stat(&fscache_n_retrievals);
48331+ fscache_stat_unchecked(&fscache_n_retrievals);
48332
48333 if (hlist_empty(&cookie->backing_objects))
48334 goto nobufs;
48335@@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48336 goto nobufs_unlock;
48337 spin_unlock(&cookie->lock);
48338
48339- fscache_stat(&fscache_n_retrieval_ops);
48340+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48341
48342 /* pin the netfs read context in case we need to do the actual netfs
48343 * read because we've encountered a cache read failure */
48344@@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
48345
48346 error:
48347 if (ret == -ENOMEM)
48348- fscache_stat(&fscache_n_retrievals_nomem);
48349+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48350 else if (ret == -ERESTARTSYS)
48351- fscache_stat(&fscache_n_retrievals_intr);
48352+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48353 else if (ret == -ENODATA)
48354- fscache_stat(&fscache_n_retrievals_nodata);
48355+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48356 else if (ret < 0)
48357- fscache_stat(&fscache_n_retrievals_nobufs);
48358+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48359 else
48360- fscache_stat(&fscache_n_retrievals_ok);
48361+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48362
48363 fscache_put_retrieval(op);
48364 _leave(" = %d", ret);
48365@@ -429,7 +429,7 @@ nobufs_unlock:
48366 spin_unlock(&cookie->lock);
48367 kfree(op);
48368 nobufs:
48369- fscache_stat(&fscache_n_retrievals_nobufs);
48370+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48371 _leave(" = -ENOBUFS");
48372 return -ENOBUFS;
48373 }
48374@@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48375
48376 _enter("%p,,%d,,,", cookie, *nr_pages);
48377
48378- fscache_stat(&fscache_n_retrievals);
48379+ fscache_stat_unchecked(&fscache_n_retrievals);
48380
48381 if (hlist_empty(&cookie->backing_objects))
48382 goto nobufs;
48383@@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48384 goto nobufs_unlock;
48385 spin_unlock(&cookie->lock);
48386
48387- fscache_stat(&fscache_n_retrieval_ops);
48388+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
48389
48390 /* pin the netfs read context in case we need to do the actual netfs
48391 * read because we've encountered a cache read failure */
48392@@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
48393
48394 error:
48395 if (ret == -ENOMEM)
48396- fscache_stat(&fscache_n_retrievals_nomem);
48397+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
48398 else if (ret == -ERESTARTSYS)
48399- fscache_stat(&fscache_n_retrievals_intr);
48400+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
48401 else if (ret == -ENODATA)
48402- fscache_stat(&fscache_n_retrievals_nodata);
48403+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
48404 else if (ret < 0)
48405- fscache_stat(&fscache_n_retrievals_nobufs);
48406+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48407 else
48408- fscache_stat(&fscache_n_retrievals_ok);
48409+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
48410
48411 fscache_put_retrieval(op);
48412 _leave(" = %d", ret);
48413@@ -545,7 +545,7 @@ nobufs_unlock:
48414 spin_unlock(&cookie->lock);
48415 kfree(op);
48416 nobufs:
48417- fscache_stat(&fscache_n_retrievals_nobufs);
48418+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
48419 _leave(" = -ENOBUFS");
48420 return -ENOBUFS;
48421 }
48422@@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48423
48424 _enter("%p,%p,,,", cookie, page);
48425
48426- fscache_stat(&fscache_n_allocs);
48427+ fscache_stat_unchecked(&fscache_n_allocs);
48428
48429 if (hlist_empty(&cookie->backing_objects))
48430 goto nobufs;
48431@@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48432 goto nobufs_unlock;
48433 spin_unlock(&cookie->lock);
48434
48435- fscache_stat(&fscache_n_alloc_ops);
48436+ fscache_stat_unchecked(&fscache_n_alloc_ops);
48437
48438 ret = fscache_wait_for_retrieval_activation(
48439 object, op,
48440@@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
48441
48442 error:
48443 if (ret == -ERESTARTSYS)
48444- fscache_stat(&fscache_n_allocs_intr);
48445+ fscache_stat_unchecked(&fscache_n_allocs_intr);
48446 else if (ret < 0)
48447- fscache_stat(&fscache_n_allocs_nobufs);
48448+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48449 else
48450- fscache_stat(&fscache_n_allocs_ok);
48451+ fscache_stat_unchecked(&fscache_n_allocs_ok);
48452
48453 fscache_put_retrieval(op);
48454 _leave(" = %d", ret);
48455@@ -625,7 +625,7 @@ nobufs_unlock:
48456 spin_unlock(&cookie->lock);
48457 kfree(op);
48458 nobufs:
48459- fscache_stat(&fscache_n_allocs_nobufs);
48460+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
48461 _leave(" = -ENOBUFS");
48462 return -ENOBUFS;
48463 }
48464@@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48465
48466 spin_lock(&cookie->stores_lock);
48467
48468- fscache_stat(&fscache_n_store_calls);
48469+ fscache_stat_unchecked(&fscache_n_store_calls);
48470
48471 /* find a page to store */
48472 page = NULL;
48473@@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48474 page = results[0];
48475 _debug("gang %d [%lx]", n, page->index);
48476 if (page->index > op->store_limit) {
48477- fscache_stat(&fscache_n_store_pages_over_limit);
48478+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
48479 goto superseded;
48480 }
48481
48482@@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
48483 spin_unlock(&cookie->stores_lock);
48484 spin_unlock(&object->lock);
48485
48486- fscache_stat(&fscache_n_store_pages);
48487+ fscache_stat_unchecked(&fscache_n_store_pages);
48488 fscache_stat(&fscache_n_cop_write_page);
48489 ret = object->cache->ops->write_page(op, page);
48490 fscache_stat_d(&fscache_n_cop_write_page);
48491@@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48492 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48493 ASSERT(PageFsCache(page));
48494
48495- fscache_stat(&fscache_n_stores);
48496+ fscache_stat_unchecked(&fscache_n_stores);
48497
48498 op = kzalloc(sizeof(*op), GFP_NOIO);
48499 if (!op)
48500@@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48501 spin_unlock(&cookie->stores_lock);
48502 spin_unlock(&object->lock);
48503
48504- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
48505+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
48506 op->store_limit = object->store_limit;
48507
48508 if (fscache_submit_op(object, &op->op) < 0)
48509@@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48510
48511 spin_unlock(&cookie->lock);
48512 radix_tree_preload_end();
48513- fscache_stat(&fscache_n_store_ops);
48514- fscache_stat(&fscache_n_stores_ok);
48515+ fscache_stat_unchecked(&fscache_n_store_ops);
48516+ fscache_stat_unchecked(&fscache_n_stores_ok);
48517
48518 /* the work queue now carries its own ref on the object */
48519 fscache_put_operation(&op->op);
48520@@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
48521 return 0;
48522
48523 already_queued:
48524- fscache_stat(&fscache_n_stores_again);
48525+ fscache_stat_unchecked(&fscache_n_stores_again);
48526 already_pending:
48527 spin_unlock(&cookie->stores_lock);
48528 spin_unlock(&object->lock);
48529 spin_unlock(&cookie->lock);
48530 radix_tree_preload_end();
48531 kfree(op);
48532- fscache_stat(&fscache_n_stores_ok);
48533+ fscache_stat_unchecked(&fscache_n_stores_ok);
48534 _leave(" = 0");
48535 return 0;
48536
48537@@ -851,14 +851,14 @@ nobufs:
48538 spin_unlock(&cookie->lock);
48539 radix_tree_preload_end();
48540 kfree(op);
48541- fscache_stat(&fscache_n_stores_nobufs);
48542+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
48543 _leave(" = -ENOBUFS");
48544 return -ENOBUFS;
48545
48546 nomem_free:
48547 kfree(op);
48548 nomem:
48549- fscache_stat(&fscache_n_stores_oom);
48550+ fscache_stat_unchecked(&fscache_n_stores_oom);
48551 _leave(" = -ENOMEM");
48552 return -ENOMEM;
48553 }
48554@@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
48555 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
48556 ASSERTCMP(page, !=, NULL);
48557
48558- fscache_stat(&fscache_n_uncaches);
48559+ fscache_stat_unchecked(&fscache_n_uncaches);
48560
48561 /* cache withdrawal may beat us to it */
48562 if (!PageFsCache(page))
48563@@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
48564 unsigned long loop;
48565
48566 #ifdef CONFIG_FSCACHE_STATS
48567- atomic_add(pagevec->nr, &fscache_n_marks);
48568+ atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
48569 #endif
48570
48571 for (loop = 0; loop < pagevec->nr; loop++) {
48572diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
48573index 4765190..2a067f2 100644
48574--- a/fs/fscache/stats.c
48575+++ b/fs/fscache/stats.c
48576@@ -18,95 +18,95 @@
48577 /*
48578 * operation counters
48579 */
48580-atomic_t fscache_n_op_pend;
48581-atomic_t fscache_n_op_run;
48582-atomic_t fscache_n_op_enqueue;
48583-atomic_t fscache_n_op_requeue;
48584-atomic_t fscache_n_op_deferred_release;
48585-atomic_t fscache_n_op_release;
48586-atomic_t fscache_n_op_gc;
48587-atomic_t fscache_n_op_cancelled;
48588-atomic_t fscache_n_op_rejected;
48589+atomic_unchecked_t fscache_n_op_pend;
48590+atomic_unchecked_t fscache_n_op_run;
48591+atomic_unchecked_t fscache_n_op_enqueue;
48592+atomic_unchecked_t fscache_n_op_requeue;
48593+atomic_unchecked_t fscache_n_op_deferred_release;
48594+atomic_unchecked_t fscache_n_op_release;
48595+atomic_unchecked_t fscache_n_op_gc;
48596+atomic_unchecked_t fscache_n_op_cancelled;
48597+atomic_unchecked_t fscache_n_op_rejected;
48598
48599-atomic_t fscache_n_attr_changed;
48600-atomic_t fscache_n_attr_changed_ok;
48601-atomic_t fscache_n_attr_changed_nobufs;
48602-atomic_t fscache_n_attr_changed_nomem;
48603-atomic_t fscache_n_attr_changed_calls;
48604+atomic_unchecked_t fscache_n_attr_changed;
48605+atomic_unchecked_t fscache_n_attr_changed_ok;
48606+atomic_unchecked_t fscache_n_attr_changed_nobufs;
48607+atomic_unchecked_t fscache_n_attr_changed_nomem;
48608+atomic_unchecked_t fscache_n_attr_changed_calls;
48609
48610-atomic_t fscache_n_allocs;
48611-atomic_t fscache_n_allocs_ok;
48612-atomic_t fscache_n_allocs_wait;
48613-atomic_t fscache_n_allocs_nobufs;
48614-atomic_t fscache_n_allocs_intr;
48615-atomic_t fscache_n_allocs_object_dead;
48616-atomic_t fscache_n_alloc_ops;
48617-atomic_t fscache_n_alloc_op_waits;
48618+atomic_unchecked_t fscache_n_allocs;
48619+atomic_unchecked_t fscache_n_allocs_ok;
48620+atomic_unchecked_t fscache_n_allocs_wait;
48621+atomic_unchecked_t fscache_n_allocs_nobufs;
48622+atomic_unchecked_t fscache_n_allocs_intr;
48623+atomic_unchecked_t fscache_n_allocs_object_dead;
48624+atomic_unchecked_t fscache_n_alloc_ops;
48625+atomic_unchecked_t fscache_n_alloc_op_waits;
48626
48627-atomic_t fscache_n_retrievals;
48628-atomic_t fscache_n_retrievals_ok;
48629-atomic_t fscache_n_retrievals_wait;
48630-atomic_t fscache_n_retrievals_nodata;
48631-atomic_t fscache_n_retrievals_nobufs;
48632-atomic_t fscache_n_retrievals_intr;
48633-atomic_t fscache_n_retrievals_nomem;
48634-atomic_t fscache_n_retrievals_object_dead;
48635-atomic_t fscache_n_retrieval_ops;
48636-atomic_t fscache_n_retrieval_op_waits;
48637+atomic_unchecked_t fscache_n_retrievals;
48638+atomic_unchecked_t fscache_n_retrievals_ok;
48639+atomic_unchecked_t fscache_n_retrievals_wait;
48640+atomic_unchecked_t fscache_n_retrievals_nodata;
48641+atomic_unchecked_t fscache_n_retrievals_nobufs;
48642+atomic_unchecked_t fscache_n_retrievals_intr;
48643+atomic_unchecked_t fscache_n_retrievals_nomem;
48644+atomic_unchecked_t fscache_n_retrievals_object_dead;
48645+atomic_unchecked_t fscache_n_retrieval_ops;
48646+atomic_unchecked_t fscache_n_retrieval_op_waits;
48647
48648-atomic_t fscache_n_stores;
48649-atomic_t fscache_n_stores_ok;
48650-atomic_t fscache_n_stores_again;
48651-atomic_t fscache_n_stores_nobufs;
48652-atomic_t fscache_n_stores_oom;
48653-atomic_t fscache_n_store_ops;
48654-atomic_t fscache_n_store_calls;
48655-atomic_t fscache_n_store_pages;
48656-atomic_t fscache_n_store_radix_deletes;
48657-atomic_t fscache_n_store_pages_over_limit;
48658+atomic_unchecked_t fscache_n_stores;
48659+atomic_unchecked_t fscache_n_stores_ok;
48660+atomic_unchecked_t fscache_n_stores_again;
48661+atomic_unchecked_t fscache_n_stores_nobufs;
48662+atomic_unchecked_t fscache_n_stores_oom;
48663+atomic_unchecked_t fscache_n_store_ops;
48664+atomic_unchecked_t fscache_n_store_calls;
48665+atomic_unchecked_t fscache_n_store_pages;
48666+atomic_unchecked_t fscache_n_store_radix_deletes;
48667+atomic_unchecked_t fscache_n_store_pages_over_limit;
48668
48669-atomic_t fscache_n_store_vmscan_not_storing;
48670-atomic_t fscache_n_store_vmscan_gone;
48671-atomic_t fscache_n_store_vmscan_busy;
48672-atomic_t fscache_n_store_vmscan_cancelled;
48673+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
48674+atomic_unchecked_t fscache_n_store_vmscan_gone;
48675+atomic_unchecked_t fscache_n_store_vmscan_busy;
48676+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
48677
48678-atomic_t fscache_n_marks;
48679-atomic_t fscache_n_uncaches;
48680+atomic_unchecked_t fscache_n_marks;
48681+atomic_unchecked_t fscache_n_uncaches;
48682
48683-atomic_t fscache_n_acquires;
48684-atomic_t fscache_n_acquires_null;
48685-atomic_t fscache_n_acquires_no_cache;
48686-atomic_t fscache_n_acquires_ok;
48687-atomic_t fscache_n_acquires_nobufs;
48688-atomic_t fscache_n_acquires_oom;
48689+atomic_unchecked_t fscache_n_acquires;
48690+atomic_unchecked_t fscache_n_acquires_null;
48691+atomic_unchecked_t fscache_n_acquires_no_cache;
48692+atomic_unchecked_t fscache_n_acquires_ok;
48693+atomic_unchecked_t fscache_n_acquires_nobufs;
48694+atomic_unchecked_t fscache_n_acquires_oom;
48695
48696-atomic_t fscache_n_updates;
48697-atomic_t fscache_n_updates_null;
48698-atomic_t fscache_n_updates_run;
48699+atomic_unchecked_t fscache_n_updates;
48700+atomic_unchecked_t fscache_n_updates_null;
48701+atomic_unchecked_t fscache_n_updates_run;
48702
48703-atomic_t fscache_n_relinquishes;
48704-atomic_t fscache_n_relinquishes_null;
48705-atomic_t fscache_n_relinquishes_waitcrt;
48706-atomic_t fscache_n_relinquishes_retire;
48707+atomic_unchecked_t fscache_n_relinquishes;
48708+atomic_unchecked_t fscache_n_relinquishes_null;
48709+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
48710+atomic_unchecked_t fscache_n_relinquishes_retire;
48711
48712-atomic_t fscache_n_cookie_index;
48713-atomic_t fscache_n_cookie_data;
48714-atomic_t fscache_n_cookie_special;
48715+atomic_unchecked_t fscache_n_cookie_index;
48716+atomic_unchecked_t fscache_n_cookie_data;
48717+atomic_unchecked_t fscache_n_cookie_special;
48718
48719-atomic_t fscache_n_object_alloc;
48720-atomic_t fscache_n_object_no_alloc;
48721-atomic_t fscache_n_object_lookups;
48722-atomic_t fscache_n_object_lookups_negative;
48723-atomic_t fscache_n_object_lookups_positive;
48724-atomic_t fscache_n_object_lookups_timed_out;
48725-atomic_t fscache_n_object_created;
48726-atomic_t fscache_n_object_avail;
48727-atomic_t fscache_n_object_dead;
48728+atomic_unchecked_t fscache_n_object_alloc;
48729+atomic_unchecked_t fscache_n_object_no_alloc;
48730+atomic_unchecked_t fscache_n_object_lookups;
48731+atomic_unchecked_t fscache_n_object_lookups_negative;
48732+atomic_unchecked_t fscache_n_object_lookups_positive;
48733+atomic_unchecked_t fscache_n_object_lookups_timed_out;
48734+atomic_unchecked_t fscache_n_object_created;
48735+atomic_unchecked_t fscache_n_object_avail;
48736+atomic_unchecked_t fscache_n_object_dead;
48737
48738-atomic_t fscache_n_checkaux_none;
48739-atomic_t fscache_n_checkaux_okay;
48740-atomic_t fscache_n_checkaux_update;
48741-atomic_t fscache_n_checkaux_obsolete;
48742+atomic_unchecked_t fscache_n_checkaux_none;
48743+atomic_unchecked_t fscache_n_checkaux_okay;
48744+atomic_unchecked_t fscache_n_checkaux_update;
48745+atomic_unchecked_t fscache_n_checkaux_obsolete;
48746
48747 atomic_t fscache_n_cop_alloc_object;
48748 atomic_t fscache_n_cop_lookup_object;
48749@@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
48750 seq_puts(m, "FS-Cache statistics\n");
48751
48752 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
48753- atomic_read(&fscache_n_cookie_index),
48754- atomic_read(&fscache_n_cookie_data),
48755- atomic_read(&fscache_n_cookie_special));
48756+ atomic_read_unchecked(&fscache_n_cookie_index),
48757+ atomic_read_unchecked(&fscache_n_cookie_data),
48758+ atomic_read_unchecked(&fscache_n_cookie_special));
48759
48760 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
48761- atomic_read(&fscache_n_object_alloc),
48762- atomic_read(&fscache_n_object_no_alloc),
48763- atomic_read(&fscache_n_object_avail),
48764- atomic_read(&fscache_n_object_dead));
48765+ atomic_read_unchecked(&fscache_n_object_alloc),
48766+ atomic_read_unchecked(&fscache_n_object_no_alloc),
48767+ atomic_read_unchecked(&fscache_n_object_avail),
48768+ atomic_read_unchecked(&fscache_n_object_dead));
48769 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
48770- atomic_read(&fscache_n_checkaux_none),
48771- atomic_read(&fscache_n_checkaux_okay),
48772- atomic_read(&fscache_n_checkaux_update),
48773- atomic_read(&fscache_n_checkaux_obsolete));
48774+ atomic_read_unchecked(&fscache_n_checkaux_none),
48775+ atomic_read_unchecked(&fscache_n_checkaux_okay),
48776+ atomic_read_unchecked(&fscache_n_checkaux_update),
48777+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
48778
48779 seq_printf(m, "Pages : mrk=%u unc=%u\n",
48780- atomic_read(&fscache_n_marks),
48781- atomic_read(&fscache_n_uncaches));
48782+ atomic_read_unchecked(&fscache_n_marks),
48783+ atomic_read_unchecked(&fscache_n_uncaches));
48784
48785 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
48786 " oom=%u\n",
48787- atomic_read(&fscache_n_acquires),
48788- atomic_read(&fscache_n_acquires_null),
48789- atomic_read(&fscache_n_acquires_no_cache),
48790- atomic_read(&fscache_n_acquires_ok),
48791- atomic_read(&fscache_n_acquires_nobufs),
48792- atomic_read(&fscache_n_acquires_oom));
48793+ atomic_read_unchecked(&fscache_n_acquires),
48794+ atomic_read_unchecked(&fscache_n_acquires_null),
48795+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
48796+ atomic_read_unchecked(&fscache_n_acquires_ok),
48797+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
48798+ atomic_read_unchecked(&fscache_n_acquires_oom));
48799
48800 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
48801- atomic_read(&fscache_n_object_lookups),
48802- atomic_read(&fscache_n_object_lookups_negative),
48803- atomic_read(&fscache_n_object_lookups_positive),
48804- atomic_read(&fscache_n_object_created),
48805- atomic_read(&fscache_n_object_lookups_timed_out));
48806+ atomic_read_unchecked(&fscache_n_object_lookups),
48807+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
48808+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
48809+ atomic_read_unchecked(&fscache_n_object_created),
48810+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
48811
48812 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
48813- atomic_read(&fscache_n_updates),
48814- atomic_read(&fscache_n_updates_null),
48815- atomic_read(&fscache_n_updates_run));
48816+ atomic_read_unchecked(&fscache_n_updates),
48817+ atomic_read_unchecked(&fscache_n_updates_null),
48818+ atomic_read_unchecked(&fscache_n_updates_run));
48819
48820 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
48821- atomic_read(&fscache_n_relinquishes),
48822- atomic_read(&fscache_n_relinquishes_null),
48823- atomic_read(&fscache_n_relinquishes_waitcrt),
48824- atomic_read(&fscache_n_relinquishes_retire));
48825+ atomic_read_unchecked(&fscache_n_relinquishes),
48826+ atomic_read_unchecked(&fscache_n_relinquishes_null),
48827+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
48828+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
48829
48830 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
48831- atomic_read(&fscache_n_attr_changed),
48832- atomic_read(&fscache_n_attr_changed_ok),
48833- atomic_read(&fscache_n_attr_changed_nobufs),
48834- atomic_read(&fscache_n_attr_changed_nomem),
48835- atomic_read(&fscache_n_attr_changed_calls));
48836+ atomic_read_unchecked(&fscache_n_attr_changed),
48837+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
48838+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
48839+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
48840+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
48841
48842 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
48843- atomic_read(&fscache_n_allocs),
48844- atomic_read(&fscache_n_allocs_ok),
48845- atomic_read(&fscache_n_allocs_wait),
48846- atomic_read(&fscache_n_allocs_nobufs),
48847- atomic_read(&fscache_n_allocs_intr));
48848+ atomic_read_unchecked(&fscache_n_allocs),
48849+ atomic_read_unchecked(&fscache_n_allocs_ok),
48850+ atomic_read_unchecked(&fscache_n_allocs_wait),
48851+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
48852+ atomic_read_unchecked(&fscache_n_allocs_intr));
48853 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
48854- atomic_read(&fscache_n_alloc_ops),
48855- atomic_read(&fscache_n_alloc_op_waits),
48856- atomic_read(&fscache_n_allocs_object_dead));
48857+ atomic_read_unchecked(&fscache_n_alloc_ops),
48858+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
48859+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
48860
48861 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
48862 " int=%u oom=%u\n",
48863- atomic_read(&fscache_n_retrievals),
48864- atomic_read(&fscache_n_retrievals_ok),
48865- atomic_read(&fscache_n_retrievals_wait),
48866- atomic_read(&fscache_n_retrievals_nodata),
48867- atomic_read(&fscache_n_retrievals_nobufs),
48868- atomic_read(&fscache_n_retrievals_intr),
48869- atomic_read(&fscache_n_retrievals_nomem));
48870+ atomic_read_unchecked(&fscache_n_retrievals),
48871+ atomic_read_unchecked(&fscache_n_retrievals_ok),
48872+ atomic_read_unchecked(&fscache_n_retrievals_wait),
48873+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
48874+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
48875+ atomic_read_unchecked(&fscache_n_retrievals_intr),
48876+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
48877 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
48878- atomic_read(&fscache_n_retrieval_ops),
48879- atomic_read(&fscache_n_retrieval_op_waits),
48880- atomic_read(&fscache_n_retrievals_object_dead));
48881+ atomic_read_unchecked(&fscache_n_retrieval_ops),
48882+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
48883+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
48884
48885 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
48886- atomic_read(&fscache_n_stores),
48887- atomic_read(&fscache_n_stores_ok),
48888- atomic_read(&fscache_n_stores_again),
48889- atomic_read(&fscache_n_stores_nobufs),
48890- atomic_read(&fscache_n_stores_oom));
48891+ atomic_read_unchecked(&fscache_n_stores),
48892+ atomic_read_unchecked(&fscache_n_stores_ok),
48893+ atomic_read_unchecked(&fscache_n_stores_again),
48894+ atomic_read_unchecked(&fscache_n_stores_nobufs),
48895+ atomic_read_unchecked(&fscache_n_stores_oom));
48896 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
48897- atomic_read(&fscache_n_store_ops),
48898- atomic_read(&fscache_n_store_calls),
48899- atomic_read(&fscache_n_store_pages),
48900- atomic_read(&fscache_n_store_radix_deletes),
48901- atomic_read(&fscache_n_store_pages_over_limit));
48902+ atomic_read_unchecked(&fscache_n_store_ops),
48903+ atomic_read_unchecked(&fscache_n_store_calls),
48904+ atomic_read_unchecked(&fscache_n_store_pages),
48905+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
48906+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
48907
48908 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
48909- atomic_read(&fscache_n_store_vmscan_not_storing),
48910- atomic_read(&fscache_n_store_vmscan_gone),
48911- atomic_read(&fscache_n_store_vmscan_busy),
48912- atomic_read(&fscache_n_store_vmscan_cancelled));
48913+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
48914+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
48915+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
48916+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
48917
48918 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
48919- atomic_read(&fscache_n_op_pend),
48920- atomic_read(&fscache_n_op_run),
48921- atomic_read(&fscache_n_op_enqueue),
48922- atomic_read(&fscache_n_op_cancelled),
48923- atomic_read(&fscache_n_op_rejected));
48924+ atomic_read_unchecked(&fscache_n_op_pend),
48925+ atomic_read_unchecked(&fscache_n_op_run),
48926+ atomic_read_unchecked(&fscache_n_op_enqueue),
48927+ atomic_read_unchecked(&fscache_n_op_cancelled),
48928+ atomic_read_unchecked(&fscache_n_op_rejected));
48929 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
48930- atomic_read(&fscache_n_op_deferred_release),
48931- atomic_read(&fscache_n_op_release),
48932- atomic_read(&fscache_n_op_gc));
48933+ atomic_read_unchecked(&fscache_n_op_deferred_release),
48934+ atomic_read_unchecked(&fscache_n_op_release),
48935+ atomic_read_unchecked(&fscache_n_op_gc));
48936
48937 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
48938 atomic_read(&fscache_n_cop_alloc_object),
48939diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
48940index ee8d550..7189d8c 100644
48941--- a/fs/fuse/cuse.c
48942+++ b/fs/fuse/cuse.c
48943@@ -585,10 +585,12 @@ static int __init cuse_init(void)
48944 INIT_LIST_HEAD(&cuse_conntbl[i]);
48945
48946 /* inherit and extend fuse_dev_operations */
48947- cuse_channel_fops = fuse_dev_operations;
48948- cuse_channel_fops.owner = THIS_MODULE;
48949- cuse_channel_fops.open = cuse_channel_open;
48950- cuse_channel_fops.release = cuse_channel_release;
48951+ pax_open_kernel();
48952+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
48953+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
48954+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
48955+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
48956+ pax_close_kernel();
48957
48958 cuse_class = class_create(THIS_MODULE, "cuse");
48959 if (IS_ERR(cuse_class))
48960diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
48961index 8c23fa7..0e3aac7 100644
48962--- a/fs/fuse/dev.c
48963+++ b/fs/fuse/dev.c
48964@@ -1241,7 +1241,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
48965 ret = 0;
48966 pipe_lock(pipe);
48967
48968- if (!pipe->readers) {
48969+ if (!atomic_read(&pipe->readers)) {
48970 send_sig(SIGPIPE, current, 0);
48971 if (!ret)
48972 ret = -EPIPE;
48973diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
48974index 324bc08..4fdd56e 100644
48975--- a/fs/fuse/dir.c
48976+++ b/fs/fuse/dir.c
48977@@ -1226,7 +1226,7 @@ static char *read_link(struct dentry *dentry)
48978 return link;
48979 }
48980
48981-static void free_link(char *link)
48982+static void free_link(const char *link)
48983 {
48984 if (!IS_ERR(link))
48985 free_page((unsigned long) link);
48986diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
48987index 381893c..3793318 100644
48988--- a/fs/gfs2/inode.c
48989+++ b/fs/gfs2/inode.c
48990@@ -1490,7 +1490,7 @@ out:
48991
48992 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48993 {
48994- char *s = nd_get_link(nd);
48995+ const char *s = nd_get_link(nd);
48996 if (!IS_ERR(s))
48997 kfree(s);
48998 }
48999diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
49000index c5bc355..5a513bb 100644
49001--- a/fs/hugetlbfs/inode.c
49002+++ b/fs/hugetlbfs/inode.c
49003@@ -923,7 +923,7 @@ static struct file_system_type hugetlbfs_fs_type = {
49004 .kill_sb = kill_litter_super,
49005 };
49006
49007-static struct vfsmount *hugetlbfs_vfsmount;
49008+struct vfsmount *hugetlbfs_vfsmount;
49009
49010 static int can_do_hugetlb_shm(void)
49011 {
49012diff --git a/fs/inode.c b/fs/inode.c
49013index 64999f1..8fad608 100644
49014--- a/fs/inode.c
49015+++ b/fs/inode.c
49016@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
49017
49018 #ifdef CONFIG_SMP
49019 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
49020- static atomic_t shared_last_ino;
49021- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
49022+ static atomic_unchecked_t shared_last_ino;
49023+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
49024
49025 res = next - LAST_INO_BATCH;
49026 }
49027diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
49028index 4a6cf28..d3a29d3 100644
49029--- a/fs/jffs2/erase.c
49030+++ b/fs/jffs2/erase.c
49031@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
49032 struct jffs2_unknown_node marker = {
49033 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
49034 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49035- .totlen = cpu_to_je32(c->cleanmarker_size)
49036+ .totlen = cpu_to_je32(c->cleanmarker_size),
49037+ .hdr_crc = cpu_to_je32(0)
49038 };
49039
49040 jffs2_prealloc_raw_node_refs(c, jeb, 1);
49041diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
49042index a6597d6..41b30ec 100644
49043--- a/fs/jffs2/wbuf.c
49044+++ b/fs/jffs2/wbuf.c
49045@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
49046 {
49047 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
49048 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
49049- .totlen = constant_cpu_to_je32(8)
49050+ .totlen = constant_cpu_to_je32(8),
49051+ .hdr_crc = constant_cpu_to_je32(0)
49052 };
49053
49054 /*
49055diff --git a/fs/jfs/super.c b/fs/jfs/super.c
49056index 1a543be..d803c40 100644
49057--- a/fs/jfs/super.c
49058+++ b/fs/jfs/super.c
49059@@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
49060
49061 jfs_inode_cachep =
49062 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
49063- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
49064+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
49065 init_once);
49066 if (jfs_inode_cachep == NULL)
49067 return -ENOMEM;
49068diff --git a/fs/libfs.c b/fs/libfs.c
49069index 7cc37ca..b3e3eec 100644
49070--- a/fs/libfs.c
49071+++ b/fs/libfs.c
49072@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49073
49074 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
49075 struct dentry *next;
49076+ char d_name[sizeof(next->d_iname)];
49077+ const unsigned char *name;
49078+
49079 next = list_entry(p, struct dentry, d_u.d_child);
49080 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
49081 if (!simple_positive(next)) {
49082@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
49083
49084 spin_unlock(&next->d_lock);
49085 spin_unlock(&dentry->d_lock);
49086- if (filldir(dirent, next->d_name.name,
49087+ name = next->d_name.name;
49088+ if (name == next->d_iname) {
49089+ memcpy(d_name, name, next->d_name.len);
49090+ name = d_name;
49091+ }
49092+ if (filldir(dirent, name,
49093 next->d_name.len, filp->f_pos,
49094 next->d_inode->i_ino,
49095 dt_type(next->d_inode)) < 0)
49096diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
49097index 05d2912..760abfa 100644
49098--- a/fs/lockd/clntproc.c
49099+++ b/fs/lockd/clntproc.c
49100@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
49101 /*
49102 * Cookie counter for NLM requests
49103 */
49104-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
49105+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
49106
49107 void nlmclnt_next_cookie(struct nlm_cookie *c)
49108 {
49109- u32 cookie = atomic_inc_return(&nlm_cookie);
49110+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
49111
49112 memcpy(c->data, &cookie, 4);
49113 c->len=4;
49114diff --git a/fs/locks.c b/fs/locks.c
49115index a94e331..060bce3 100644
49116--- a/fs/locks.c
49117+++ b/fs/locks.c
49118@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
49119 return;
49120
49121 if (filp->f_op && filp->f_op->flock) {
49122- struct file_lock fl = {
49123+ struct file_lock flock = {
49124 .fl_pid = current->tgid,
49125 .fl_file = filp,
49126 .fl_flags = FL_FLOCK,
49127 .fl_type = F_UNLCK,
49128 .fl_end = OFFSET_MAX,
49129 };
49130- filp->f_op->flock(filp, F_SETLKW, &fl);
49131- if (fl.fl_ops && fl.fl_ops->fl_release_private)
49132- fl.fl_ops->fl_release_private(&fl);
49133+ filp->f_op->flock(filp, F_SETLKW, &flock);
49134+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
49135+ flock.fl_ops->fl_release_private(&flock);
49136 }
49137
49138 lock_flocks();
49139diff --git a/fs/namei.c b/fs/namei.c
49140index 5f4cdf3..959a013 100644
49141--- a/fs/namei.c
49142+++ b/fs/namei.c
49143@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
49144 if (ret != -EACCES)
49145 return ret;
49146
49147+#ifdef CONFIG_GRKERNSEC
49148+ /* we'll block if we have to log due to a denied capability use */
49149+ if (mask & MAY_NOT_BLOCK)
49150+ return -ECHILD;
49151+#endif
49152+
49153 if (S_ISDIR(inode->i_mode)) {
49154 /* DACs are overridable for directories */
49155- if (inode_capable(inode, CAP_DAC_OVERRIDE))
49156- return 0;
49157 if (!(mask & MAY_WRITE))
49158- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49159+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49160+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49161 return 0;
49162+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
49163+ return 0;
49164 return -EACCES;
49165 }
49166 /*
49167+ * Searching includes executable on directories, else just read.
49168+ */
49169+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49170+ if (mask == MAY_READ)
49171+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
49172+ inode_capable(inode, CAP_DAC_READ_SEARCH))
49173+ return 0;
49174+
49175+ /*
49176 * Read/write DACs are always overridable.
49177 * Executable DACs are overridable when there is
49178 * at least one exec bit set.
49179@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
49180 if (inode_capable(inode, CAP_DAC_OVERRIDE))
49181 return 0;
49182
49183- /*
49184- * Searching includes executable on directories, else just read.
49185- */
49186- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
49187- if (mask == MAY_READ)
49188- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
49189- return 0;
49190-
49191 return -EACCES;
49192 }
49193
49194@@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49195 {
49196 struct dentry *dentry = link->dentry;
49197 int error;
49198- char *s;
49199+ const char *s;
49200
49201 BUG_ON(nd->flags & LOOKUP_RCU);
49202
49203@@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
49204 if (error)
49205 goto out_put_nd_path;
49206
49207+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
49208+ dentry->d_inode, dentry, nd->path.mnt)) {
49209+ error = -EACCES;
49210+ goto out_put_nd_path;
49211+ }
49212+
49213 nd->last_type = LAST_BIND;
49214 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
49215 error = PTR_ERR(*p);
49216@@ -1605,6 +1619,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
49217 break;
49218 res = walk_component(nd, path, &nd->last,
49219 nd->last_type, LOOKUP_FOLLOW);
49220+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
49221+ res = -EACCES;
49222 put_link(nd, &link, cookie);
49223 } while (res > 0);
49224
49225@@ -1703,7 +1719,7 @@ EXPORT_SYMBOL(full_name_hash);
49226 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
49227 {
49228 unsigned long a, b, adata, bdata, mask, hash, len;
49229- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49230+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
49231
49232 hash = a = 0;
49233 len = -sizeof(unsigned long);
49234@@ -1993,6 +2009,8 @@ static int path_lookupat(int dfd, const char *name,
49235 if (err)
49236 break;
49237 err = lookup_last(nd, &path);
49238+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
49239+ err = -EACCES;
49240 put_link(nd, &link, cookie);
49241 }
49242 }
49243@@ -2000,6 +2018,21 @@ static int path_lookupat(int dfd, const char *name,
49244 if (!err)
49245 err = complete_walk(nd);
49246
49247+ if (!(nd->flags & LOOKUP_PARENT)) {
49248+#ifdef CONFIG_GRKERNSEC
49249+ if (flags & LOOKUP_RCU) {
49250+ if (!err)
49251+ path_put(&nd->path);
49252+ err = -ECHILD;
49253+ } else
49254+#endif
49255+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49256+ if (!err)
49257+ path_put(&nd->path);
49258+ err = -ENOENT;
49259+ }
49260+ }
49261+
49262 if (!err && nd->flags & LOOKUP_DIRECTORY) {
49263 if (!nd->inode->i_op->lookup) {
49264 path_put(&nd->path);
49265@@ -2027,8 +2060,17 @@ static int filename_lookup(int dfd, struct filename *name,
49266 retval = path_lookupat(dfd, name->name,
49267 flags | LOOKUP_REVAL, nd);
49268
49269- if (likely(!retval))
49270+ if (likely(!retval)) {
49271+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
49272+#ifdef CONFIG_GRKERNSEC
49273+ if (flags & LOOKUP_RCU)
49274+ return -ECHILD;
49275+#endif
49276+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
49277+ return -ENOENT;
49278+ }
49279 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
49280+ }
49281 return retval;
49282 }
49283
49284@@ -2402,6 +2444,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
49285 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
49286 return -EPERM;
49287
49288+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
49289+ return -EPERM;
49290+ if (gr_handle_rawio(inode))
49291+ return -EPERM;
49292+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
49293+ return -EACCES;
49294+
49295 return 0;
49296 }
49297
49298@@ -2623,7 +2672,7 @@ looked_up:
49299 * cleared otherwise prior to returning.
49300 */
49301 static int lookup_open(struct nameidata *nd, struct path *path,
49302- struct file *file,
49303+ struct path *link, struct file *file,
49304 const struct open_flags *op,
49305 bool got_write, int *opened)
49306 {
49307@@ -2658,6 +2707,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49308 /* Negative dentry, just create the file */
49309 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
49310 umode_t mode = op->mode;
49311+
49312+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
49313+ error = -EACCES;
49314+ goto out_dput;
49315+ }
49316+
49317+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
49318+ error = -EACCES;
49319+ goto out_dput;
49320+ }
49321+
49322 if (!IS_POSIXACL(dir->d_inode))
49323 mode &= ~current_umask();
49324 /*
49325@@ -2679,6 +2739,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
49326 nd->flags & LOOKUP_EXCL);
49327 if (error)
49328 goto out_dput;
49329+ else
49330+ gr_handle_create(dentry, nd->path.mnt);
49331 }
49332 out_no_open:
49333 path->dentry = dentry;
49334@@ -2693,7 +2755,7 @@ out_dput:
49335 /*
49336 * Handle the last step of open()
49337 */
49338-static int do_last(struct nameidata *nd, struct path *path,
49339+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
49340 struct file *file, const struct open_flags *op,
49341 int *opened, struct filename *name)
49342 {
49343@@ -2722,16 +2784,44 @@ static int do_last(struct nameidata *nd, struct path *path,
49344 error = complete_walk(nd);
49345 if (error)
49346 return error;
49347+#ifdef CONFIG_GRKERNSEC
49348+ if (nd->flags & LOOKUP_RCU) {
49349+ error = -ECHILD;
49350+ goto out;
49351+ }
49352+#endif
49353+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49354+ error = -ENOENT;
49355+ goto out;
49356+ }
49357 audit_inode(name, nd->path.dentry, 0);
49358 if (open_flag & O_CREAT) {
49359 error = -EISDIR;
49360 goto out;
49361 }
49362+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49363+ error = -EACCES;
49364+ goto out;
49365+ }
49366 goto finish_open;
49367 case LAST_BIND:
49368 error = complete_walk(nd);
49369 if (error)
49370 return error;
49371+#ifdef CONFIG_GRKERNSEC
49372+ if (nd->flags & LOOKUP_RCU) {
49373+ error = -ECHILD;
49374+ goto out;
49375+ }
49376+#endif
49377+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
49378+ error = -ENOENT;
49379+ goto out;
49380+ }
49381+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49382+ error = -EACCES;
49383+ goto out;
49384+ }
49385 audit_inode(name, dir, 0);
49386 goto finish_open;
49387 }
49388@@ -2780,7 +2870,7 @@ retry_lookup:
49389 */
49390 }
49391 mutex_lock(&dir->d_inode->i_mutex);
49392- error = lookup_open(nd, path, file, op, got_write, opened);
49393+ error = lookup_open(nd, path, link, file, op, got_write, opened);
49394 mutex_unlock(&dir->d_inode->i_mutex);
49395
49396 if (error <= 0) {
49397@@ -2804,11 +2894,28 @@ retry_lookup:
49398 goto finish_open_created;
49399 }
49400
49401+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
49402+ error = -ENOENT;
49403+ goto exit_dput;
49404+ }
49405+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
49406+ error = -EACCES;
49407+ goto exit_dput;
49408+ }
49409+
49410 /*
49411 * create/update audit record if it already exists.
49412 */
49413- if (path->dentry->d_inode)
49414+ if (path->dentry->d_inode) {
49415+ /* only check if O_CREAT is specified, all other checks need to go
49416+ into may_open */
49417+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
49418+ error = -EACCES;
49419+ goto exit_dput;
49420+ }
49421+
49422 audit_inode(name, path->dentry, 0);
49423+ }
49424
49425 /*
49426 * If atomic_open() acquired write access it is dropped now due to
49427@@ -2849,6 +2956,11 @@ finish_lookup:
49428 }
49429 }
49430 BUG_ON(inode != path->dentry->d_inode);
49431+ /* if we're resolving a symlink to another symlink */
49432+ if (link && gr_handle_symlink_owner(link, inode)) {
49433+ error = -EACCES;
49434+ goto out;
49435+ }
49436 return 1;
49437 }
49438
49439@@ -2858,7 +2970,6 @@ finish_lookup:
49440 save_parent.dentry = nd->path.dentry;
49441 save_parent.mnt = mntget(path->mnt);
49442 nd->path.dentry = path->dentry;
49443-
49444 }
49445 nd->inode = inode;
49446 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
49447@@ -2867,6 +2978,22 @@ finish_lookup:
49448 path_put(&save_parent);
49449 return error;
49450 }
49451+
49452+#ifdef CONFIG_GRKERNSEC
49453+ if (nd->flags & LOOKUP_RCU) {
49454+ error = -ECHILD;
49455+ goto out;
49456+ }
49457+#endif
49458+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
49459+ error = -ENOENT;
49460+ goto out;
49461+ }
49462+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
49463+ error = -EACCES;
49464+ goto out;
49465+ }
49466+
49467 error = -EISDIR;
49468 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
49469 goto out;
49470@@ -2965,7 +3092,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49471 if (unlikely(error))
49472 goto out;
49473
49474- error = do_last(nd, &path, file, op, &opened, pathname);
49475+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
49476 while (unlikely(error > 0)) { /* trailing symlink */
49477 struct path link = path;
49478 void *cookie;
49479@@ -2983,7 +3110,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
49480 error = follow_link(&link, nd, &cookie);
49481 if (unlikely(error))
49482 break;
49483- error = do_last(nd, &path, file, op, &opened, pathname);
49484+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
49485 put_link(nd, &link, cookie);
49486 }
49487 out:
49488@@ -3073,8 +3200,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
49489 goto unlock;
49490
49491 error = -EEXIST;
49492- if (dentry->d_inode)
49493+ if (dentry->d_inode) {
49494+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
49495+ error = -ENOENT;
49496+ }
49497 goto fail;
49498+ }
49499 /*
49500 * Special case - lookup gave negative, but... we had foo/bar/
49501 * From the vfs_mknod() POV we just have a negative dentry -
49502@@ -3125,6 +3256,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
49503 }
49504 EXPORT_SYMBOL(user_path_create);
49505
49506+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, int is_dir)
49507+{
49508+ struct filename *tmp = getname(pathname);
49509+ struct dentry *res;
49510+ if (IS_ERR(tmp))
49511+ return ERR_CAST(tmp);
49512+ res = kern_path_create(dfd, tmp->name, path, is_dir);
49513+ if (IS_ERR(res))
49514+ putname(tmp);
49515+ else
49516+ *to = tmp;
49517+ return res;
49518+}
49519+
49520 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
49521 {
49522 int error = may_create(dir, dentry);
49523@@ -3186,6 +3331,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49524
49525 if (!IS_POSIXACL(path.dentry->d_inode))
49526 mode &= ~current_umask();
49527+
49528+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
49529+ error = -EPERM;
49530+ goto out;
49531+ }
49532+
49533+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
49534+ error = -EACCES;
49535+ goto out;
49536+ }
49537+
49538 error = security_path_mknod(&path, dentry, mode, dev);
49539 if (error)
49540 goto out;
49541@@ -3202,6 +3358,8 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
49542 break;
49543 }
49544 out:
49545+ if (!error)
49546+ gr_handle_create(dentry, path.mnt);
49547 done_path_create(&path, dentry);
49548 return error;
49549 }
49550@@ -3248,9 +3406,18 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
49551
49552 if (!IS_POSIXACL(path.dentry->d_inode))
49553 mode &= ~current_umask();
49554+
49555+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
49556+ error = -EACCES;
49557+ goto out;
49558+ }
49559+
49560 error = security_path_mkdir(&path, dentry, mode);
49561 if (!error)
49562 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
49563+ if (!error)
49564+ gr_handle_create(dentry, path.mnt);
49565+out:
49566 done_path_create(&path, dentry);
49567 return error;
49568 }
49569@@ -3327,6 +3494,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
49570 struct filename *name;
49571 struct dentry *dentry;
49572 struct nameidata nd;
49573+ ino_t saved_ino = 0;
49574+ dev_t saved_dev = 0;
49575
49576 name = user_path_parent(dfd, pathname, &nd);
49577 if (IS_ERR(name))
49578@@ -3358,10 +3527,21 @@ static long do_rmdir(int dfd, const char __user *pathname)
49579 error = -ENOENT;
49580 goto exit3;
49581 }
49582+
49583+ saved_ino = dentry->d_inode->i_ino;
49584+ saved_dev = gr_get_dev_from_dentry(dentry);
49585+
49586+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
49587+ error = -EACCES;
49588+ goto exit3;
49589+ }
49590+
49591 error = security_path_rmdir(&nd.path, dentry);
49592 if (error)
49593 goto exit3;
49594 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
49595+ if (!error && (saved_dev || saved_ino))
49596+ gr_handle_delete(saved_ino, saved_dev);
49597 exit3:
49598 dput(dentry);
49599 exit2:
49600@@ -3423,6 +3603,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49601 struct dentry *dentry;
49602 struct nameidata nd;
49603 struct inode *inode = NULL;
49604+ ino_t saved_ino = 0;
49605+ dev_t saved_dev = 0;
49606
49607 name = user_path_parent(dfd, pathname, &nd);
49608 if (IS_ERR(name))
49609@@ -3448,10 +3630,22 @@ static long do_unlinkat(int dfd, const char __user *pathname)
49610 if (!inode)
49611 goto slashes;
49612 ihold(inode);
49613+
49614+ if (inode->i_nlink <= 1) {
49615+ saved_ino = inode->i_ino;
49616+ saved_dev = gr_get_dev_from_dentry(dentry);
49617+ }
49618+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
49619+ error = -EACCES;
49620+ goto exit2;
49621+ }
49622+
49623 error = security_path_unlink(&nd.path, dentry);
49624 if (error)
49625 goto exit2;
49626 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
49627+ if (!error && (saved_ino || saved_dev))
49628+ gr_handle_delete(saved_ino, saved_dev);
49629 exit2:
49630 dput(dentry);
49631 }
49632@@ -3523,9 +3717,17 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
49633 if (IS_ERR(dentry))
49634 goto out_putname;
49635
49636+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
49637+ error = -EACCES;
49638+ goto out;
49639+ }
49640+
49641 error = security_path_symlink(&path, dentry, from->name);
49642 if (!error)
49643 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
49644+ if (!error)
49645+ gr_handle_create(dentry, path.mnt);
49646+out:
49647 done_path_create(&path, dentry);
49648 out_putname:
49649 putname(from);
49650@@ -3595,6 +3797,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49651 {
49652 struct dentry *new_dentry;
49653 struct path old_path, new_path;
49654+ struct filename *to = NULL;
49655 int how = 0;
49656 int error;
49657
49658@@ -3618,7 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49659 if (error)
49660 return error;
49661
49662- new_dentry = user_path_create(newdfd, newname, &new_path, 0);
49663+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
49664 error = PTR_ERR(new_dentry);
49665 if (IS_ERR(new_dentry))
49666 goto out;
49667@@ -3629,11 +3832,28 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
49668 error = may_linkat(&old_path);
49669 if (unlikely(error))
49670 goto out_dput;
49671+
49672+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
49673+ old_path.dentry->d_inode,
49674+ old_path.dentry->d_inode->i_mode, to)) {
49675+ error = -EACCES;
49676+ goto out_dput;
49677+ }
49678+
49679+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
49680+ old_path.dentry, old_path.mnt, to)) {
49681+ error = -EACCES;
49682+ goto out_dput;
49683+ }
49684+
49685 error = security_path_link(old_path.dentry, &new_path, new_dentry);
49686 if (error)
49687 goto out_dput;
49688 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
49689+ if (!error)
49690+ gr_handle_create(new_dentry, new_path.mnt);
49691 out_dput:
49692+ putname(to);
49693 done_path_create(&new_path, new_dentry);
49694 out:
49695 path_put(&old_path);
49696@@ -3873,12 +4093,21 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
49697 if (new_dentry == trap)
49698 goto exit5;
49699
49700+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
49701+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
49702+ to);
49703+ if (error)
49704+ goto exit5;
49705+
49706 error = security_path_rename(&oldnd.path, old_dentry,
49707 &newnd.path, new_dentry);
49708 if (error)
49709 goto exit5;
49710 error = vfs_rename(old_dir->d_inode, old_dentry,
49711 new_dir->d_inode, new_dentry);
49712+ if (!error)
49713+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
49714+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
49715 exit5:
49716 dput(new_dentry);
49717 exit4:
49718@@ -3903,6 +4132,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
49719
49720 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
49721 {
49722+ char tmpbuf[64];
49723+ const char *newlink;
49724 int len;
49725
49726 len = PTR_ERR(link);
49727@@ -3912,7 +4143,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
49728 len = strlen(link);
49729 if (len > (unsigned) buflen)
49730 len = buflen;
49731- if (copy_to_user(buffer, link, len))
49732+
49733+ if (len < sizeof(tmpbuf)) {
49734+ memcpy(tmpbuf, link, len);
49735+ newlink = tmpbuf;
49736+ } else
49737+ newlink = link;
49738+
49739+ if (copy_to_user(buffer, newlink, len))
49740 len = -EFAULT;
49741 out:
49742 return len;
49743diff --git a/fs/namespace.c b/fs/namespace.c
49744index 2496062..e26f6d6 100644
49745--- a/fs/namespace.c
49746+++ b/fs/namespace.c
49747@@ -1212,6 +1212,9 @@ static int do_umount(struct mount *mnt, int flags)
49748 if (!(sb->s_flags & MS_RDONLY))
49749 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
49750 up_write(&sb->s_umount);
49751+
49752+ gr_log_remount(mnt->mnt_devname, retval);
49753+
49754 return retval;
49755 }
49756
49757@@ -1231,6 +1234,9 @@ static int do_umount(struct mount *mnt, int flags)
49758 br_write_unlock(&vfsmount_lock);
49759 up_write(&namespace_sem);
49760 release_mounts(&umount_list);
49761+
49762+ gr_log_unmount(mnt->mnt_devname, retval);
49763+
49764 return retval;
49765 }
49766
49767@@ -2244,6 +2250,16 @@ long do_mount(const char *dev_name, const char *dir_name,
49768 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
49769 MS_STRICTATIME);
49770
49771+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
49772+ retval = -EPERM;
49773+ goto dput_out;
49774+ }
49775+
49776+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
49777+ retval = -EPERM;
49778+ goto dput_out;
49779+ }
49780+
49781 if (flags & MS_REMOUNT)
49782 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
49783 data_page);
49784@@ -2258,6 +2274,9 @@ long do_mount(const char *dev_name, const char *dir_name,
49785 dev_name, data_page);
49786 dput_out:
49787 path_put(&path);
49788+
49789+ gr_log_mount(dev_name, dir_name, retval);
49790+
49791 return retval;
49792 }
49793
49794@@ -2516,6 +2535,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
49795 if (error)
49796 goto out2;
49797
49798+ if (gr_handle_chroot_pivot()) {
49799+ error = -EPERM;
49800+ goto out2;
49801+ }
49802+
49803 get_fs_root(current->fs, &root);
49804 error = lock_mount(&old);
49805 if (error)
49806diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
49807index 6fa01ae..2790820 100644
49808--- a/fs/nfs/inode.c
49809+++ b/fs/nfs/inode.c
49810@@ -1029,16 +1029,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
49811 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
49812 }
49813
49814-static atomic_long_t nfs_attr_generation_counter;
49815+static atomic_long_unchecked_t nfs_attr_generation_counter;
49816
49817 static unsigned long nfs_read_attr_generation_counter(void)
49818 {
49819- return atomic_long_read(&nfs_attr_generation_counter);
49820+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
49821 }
49822
49823 unsigned long nfs_inc_attr_generation_counter(void)
49824 {
49825- return atomic_long_inc_return(&nfs_attr_generation_counter);
49826+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
49827 }
49828
49829 void nfs_fattr_init(struct nfs_fattr *fattr)
49830diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
49831index f59169e..fd7d359 100644
49832--- a/fs/nfsd/vfs.c
49833+++ b/fs/nfsd/vfs.c
49834@@ -941,7 +941,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49835 } else {
49836 oldfs = get_fs();
49837 set_fs(KERNEL_DS);
49838- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
49839+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
49840 set_fs(oldfs);
49841 }
49842
49843@@ -1045,7 +1045,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
49844
49845 /* Write the data. */
49846 oldfs = get_fs(); set_fs(KERNEL_DS);
49847- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
49848+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
49849 set_fs(oldfs);
49850 if (host_err < 0)
49851 goto out_nfserr;
49852@@ -1587,7 +1587,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
49853 */
49854
49855 oldfs = get_fs(); set_fs(KERNEL_DS);
49856- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
49857+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
49858 set_fs(oldfs);
49859
49860 if (host_err < 0)
49861diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
49862index 6fcaeb8..9d16d04 100644
49863--- a/fs/notify/fanotify/fanotify_user.c
49864+++ b/fs/notify/fanotify/fanotify_user.c
49865@@ -250,8 +250,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
49866
49867 fd = fanotify_event_metadata.fd;
49868 ret = -EFAULT;
49869- if (copy_to_user(buf, &fanotify_event_metadata,
49870- fanotify_event_metadata.event_len))
49871+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
49872+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
49873 goto out_close_fd;
49874
49875 ret = prepare_for_access_response(group, event, fd);
49876diff --git a/fs/notify/notification.c b/fs/notify/notification.c
49877index c887b13..0fdf472 100644
49878--- a/fs/notify/notification.c
49879+++ b/fs/notify/notification.c
49880@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
49881 * get set to 0 so it will never get 'freed'
49882 */
49883 static struct fsnotify_event *q_overflow_event;
49884-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49885+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49886
49887 /**
49888 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
49889@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
49890 */
49891 u32 fsnotify_get_cookie(void)
49892 {
49893- return atomic_inc_return(&fsnotify_sync_cookie);
49894+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
49895 }
49896 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
49897
49898diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
49899index 99e3610..02c1068 100644
49900--- a/fs/ntfs/dir.c
49901+++ b/fs/ntfs/dir.c
49902@@ -1329,7 +1329,7 @@ find_next_index_buffer:
49903 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
49904 ~(s64)(ndir->itype.index.block_size - 1)));
49905 /* Bounds checks. */
49906- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49907+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
49908 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
49909 "inode 0x%lx or driver bug.", vdir->i_ino);
49910 goto err_out;
49911diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
49912index 1ecf464..e1ff8bf 100644
49913--- a/fs/ntfs/file.c
49914+++ b/fs/ntfs/file.c
49915@@ -2232,6 +2232,6 @@ const struct inode_operations ntfs_file_inode_ops = {
49916 #endif /* NTFS_RW */
49917 };
49918
49919-const struct file_operations ntfs_empty_file_ops = {};
49920+const struct file_operations ntfs_empty_file_ops __read_only;
49921
49922-const struct inode_operations ntfs_empty_inode_ops = {};
49923+const struct inode_operations ntfs_empty_inode_ops __read_only;
49924diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
49925index a9f78c7..ed8a381 100644
49926--- a/fs/ocfs2/localalloc.c
49927+++ b/fs/ocfs2/localalloc.c
49928@@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
49929 goto bail;
49930 }
49931
49932- atomic_inc(&osb->alloc_stats.moves);
49933+ atomic_inc_unchecked(&osb->alloc_stats.moves);
49934
49935 bail:
49936 if (handle)
49937diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
49938index d355e6e..578d905 100644
49939--- a/fs/ocfs2/ocfs2.h
49940+++ b/fs/ocfs2/ocfs2.h
49941@@ -235,11 +235,11 @@ enum ocfs2_vol_state
49942
49943 struct ocfs2_alloc_stats
49944 {
49945- atomic_t moves;
49946- atomic_t local_data;
49947- atomic_t bitmap_data;
49948- atomic_t bg_allocs;
49949- atomic_t bg_extends;
49950+ atomic_unchecked_t moves;
49951+ atomic_unchecked_t local_data;
49952+ atomic_unchecked_t bitmap_data;
49953+ atomic_unchecked_t bg_allocs;
49954+ atomic_unchecked_t bg_extends;
49955 };
49956
49957 enum ocfs2_local_alloc_state
49958diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
49959index f169da4..9112253 100644
49960--- a/fs/ocfs2/suballoc.c
49961+++ b/fs/ocfs2/suballoc.c
49962@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
49963 mlog_errno(status);
49964 goto bail;
49965 }
49966- atomic_inc(&osb->alloc_stats.bg_extends);
49967+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
49968
49969 /* You should never ask for this much metadata */
49970 BUG_ON(bits_wanted >
49971@@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
49972 mlog_errno(status);
49973 goto bail;
49974 }
49975- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49976+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49977
49978 *suballoc_loc = res.sr_bg_blkno;
49979 *suballoc_bit_start = res.sr_bit_offset;
49980@@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
49981 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
49982 res->sr_bits);
49983
49984- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49985+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49986
49987 BUG_ON(res->sr_bits != 1);
49988
49989@@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
49990 mlog_errno(status);
49991 goto bail;
49992 }
49993- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49994+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
49995
49996 BUG_ON(res.sr_bits != 1);
49997
49998@@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
49999 cluster_start,
50000 num_clusters);
50001 if (!status)
50002- atomic_inc(&osb->alloc_stats.local_data);
50003+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
50004 } else {
50005 if (min_clusters > (osb->bitmap_cpg - 1)) {
50006 /* The only paths asking for contiguousness
50007@@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
50008 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
50009 res.sr_bg_blkno,
50010 res.sr_bit_offset);
50011- atomic_inc(&osb->alloc_stats.bitmap_data);
50012+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
50013 *num_clusters = res.sr_bits;
50014 }
50015 }
50016diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
50017index 0e91ec2..f4b3fc6 100644
50018--- a/fs/ocfs2/super.c
50019+++ b/fs/ocfs2/super.c
50020@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
50021 "%10s => GlobalAllocs: %d LocalAllocs: %d "
50022 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
50023 "Stats",
50024- atomic_read(&osb->alloc_stats.bitmap_data),
50025- atomic_read(&osb->alloc_stats.local_data),
50026- atomic_read(&osb->alloc_stats.bg_allocs),
50027- atomic_read(&osb->alloc_stats.moves),
50028- atomic_read(&osb->alloc_stats.bg_extends));
50029+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
50030+ atomic_read_unchecked(&osb->alloc_stats.local_data),
50031+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
50032+ atomic_read_unchecked(&osb->alloc_stats.moves),
50033+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
50034
50035 out += snprintf(buf + out, len - out,
50036 "%10s => State: %u Descriptor: %llu Size: %u bits "
50037@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
50038 spin_lock_init(&osb->osb_xattr_lock);
50039 ocfs2_init_steal_slots(osb);
50040
50041- atomic_set(&osb->alloc_stats.moves, 0);
50042- atomic_set(&osb->alloc_stats.local_data, 0);
50043- atomic_set(&osb->alloc_stats.bitmap_data, 0);
50044- atomic_set(&osb->alloc_stats.bg_allocs, 0);
50045- atomic_set(&osb->alloc_stats.bg_extends, 0);
50046+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
50047+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
50048+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
50049+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
50050+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
50051
50052 /* Copy the blockcheck stats from the superblock probe */
50053 osb->osb_ecc_stats = *stats;
50054diff --git a/fs/open.c b/fs/open.c
50055index 59071f5..c6229a0 100644
50056--- a/fs/open.c
50057+++ b/fs/open.c
50058@@ -31,6 +31,8 @@
50059 #include <linux/ima.h>
50060 #include <linux/dnotify.h>
50061
50062+#define CREATE_TRACE_POINTS
50063+#include <trace/events/fs.h>
50064 #include "internal.h"
50065
50066 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
50067@@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
50068 error = locks_verify_truncate(inode, NULL, length);
50069 if (!error)
50070 error = security_path_truncate(&path);
50071+
50072+ if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
50073+ error = -EACCES;
50074+
50075 if (!error)
50076 error = do_truncate(path.dentry, length, 0, NULL);
50077
50078@@ -362,6 +368,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
50079 if (__mnt_is_readonly(path.mnt))
50080 res = -EROFS;
50081
50082+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
50083+ res = -EACCES;
50084+
50085 out_path_release:
50086 path_put(&path);
50087 out:
50088@@ -388,6 +397,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
50089 if (error)
50090 goto dput_and_out;
50091
50092+ gr_log_chdir(path.dentry, path.mnt);
50093+
50094 set_fs_pwd(current->fs, &path);
50095
50096 dput_and_out:
50097@@ -413,6 +424,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
50098 goto out_putf;
50099
50100 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
50101+
50102+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
50103+ error = -EPERM;
50104+
50105+ if (!error)
50106+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
50107+
50108 if (!error)
50109 set_fs_pwd(current->fs, &f.file->f_path);
50110 out_putf:
50111@@ -441,7 +459,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
50112 if (error)
50113 goto dput_and_out;
50114
50115+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
50116+ goto dput_and_out;
50117+
50118 set_fs_root(current->fs, &path);
50119+
50120+ gr_handle_chroot_chdir(&path);
50121+
50122 error = 0;
50123 dput_and_out:
50124 path_put(&path);
50125@@ -459,6 +483,16 @@ static int chmod_common(struct path *path, umode_t mode)
50126 if (error)
50127 return error;
50128 mutex_lock(&inode->i_mutex);
50129+
50130+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
50131+ error = -EACCES;
50132+ goto out_unlock;
50133+ }
50134+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
50135+ error = -EACCES;
50136+ goto out_unlock;
50137+ }
50138+
50139 error = security_path_chmod(path, mode);
50140 if (error)
50141 goto out_unlock;
50142@@ -514,6 +548,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
50143 uid = make_kuid(current_user_ns(), user);
50144 gid = make_kgid(current_user_ns(), group);
50145
50146+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
50147+ return -EACCES;
50148+
50149 newattrs.ia_valid = ATTR_CTIME;
50150 if (user != (uid_t) -1) {
50151 if (!uid_valid(uid))
50152@@ -925,6 +962,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
50153 } else {
50154 fsnotify_open(f);
50155 fd_install(fd, f);
50156+ trace_do_sys_open(tmp->name, flags, mode);
50157 }
50158 }
50159 putname(tmp);
50160diff --git a/fs/pipe.c b/fs/pipe.c
50161index bd3479d..fb92c4d 100644
50162--- a/fs/pipe.c
50163+++ b/fs/pipe.c
50164@@ -438,9 +438,9 @@ redo:
50165 }
50166 if (bufs) /* More to do? */
50167 continue;
50168- if (!pipe->writers)
50169+ if (!atomic_read(&pipe->writers))
50170 break;
50171- if (!pipe->waiting_writers) {
50172+ if (!atomic_read(&pipe->waiting_writers)) {
50173 /* syscall merging: Usually we must not sleep
50174 * if O_NONBLOCK is set, or if we got some data.
50175 * But if a writer sleeps in kernel space, then
50176@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
50177 mutex_lock(&inode->i_mutex);
50178 pipe = inode->i_pipe;
50179
50180- if (!pipe->readers) {
50181+ if (!atomic_read(&pipe->readers)) {
50182 send_sig(SIGPIPE, current, 0);
50183 ret = -EPIPE;
50184 goto out;
50185@@ -553,7 +553,7 @@ redo1:
50186 for (;;) {
50187 int bufs;
50188
50189- if (!pipe->readers) {
50190+ if (!atomic_read(&pipe->readers)) {
50191 send_sig(SIGPIPE, current, 0);
50192 if (!ret)
50193 ret = -EPIPE;
50194@@ -644,9 +644,9 @@ redo2:
50195 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50196 do_wakeup = 0;
50197 }
50198- pipe->waiting_writers++;
50199+ atomic_inc(&pipe->waiting_writers);
50200 pipe_wait(pipe);
50201- pipe->waiting_writers--;
50202+ atomic_dec(&pipe->waiting_writers);
50203 }
50204 out:
50205 mutex_unlock(&inode->i_mutex);
50206@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50207 mask = 0;
50208 if (filp->f_mode & FMODE_READ) {
50209 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
50210- if (!pipe->writers && filp->f_version != pipe->w_counter)
50211+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
50212 mask |= POLLHUP;
50213 }
50214
50215@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
50216 * Most Unices do not set POLLERR for FIFOs but on Linux they
50217 * behave exactly like pipes for poll().
50218 */
50219- if (!pipe->readers)
50220+ if (!atomic_read(&pipe->readers))
50221 mask |= POLLERR;
50222 }
50223
50224@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
50225
50226 mutex_lock(&inode->i_mutex);
50227 pipe = inode->i_pipe;
50228- pipe->readers -= decr;
50229- pipe->writers -= decw;
50230+ atomic_sub(decr, &pipe->readers);
50231+ atomic_sub(decw, &pipe->writers);
50232
50233- if (!pipe->readers && !pipe->writers) {
50234+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
50235 free_pipe_info(inode);
50236 } else {
50237 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
50238@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
50239
50240 if (inode->i_pipe) {
50241 ret = 0;
50242- inode->i_pipe->readers++;
50243+ atomic_inc(&inode->i_pipe->readers);
50244 }
50245
50246 mutex_unlock(&inode->i_mutex);
50247@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
50248
50249 if (inode->i_pipe) {
50250 ret = 0;
50251- inode->i_pipe->writers++;
50252+ atomic_inc(&inode->i_pipe->writers);
50253 }
50254
50255 mutex_unlock(&inode->i_mutex);
50256@@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
50257 if (inode->i_pipe) {
50258 ret = 0;
50259 if (filp->f_mode & FMODE_READ)
50260- inode->i_pipe->readers++;
50261+ atomic_inc(&inode->i_pipe->readers);
50262 if (filp->f_mode & FMODE_WRITE)
50263- inode->i_pipe->writers++;
50264+ atomic_inc(&inode->i_pipe->writers);
50265 }
50266
50267 mutex_unlock(&inode->i_mutex);
50268@@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
50269 inode->i_pipe = NULL;
50270 }
50271
50272-static struct vfsmount *pipe_mnt __read_mostly;
50273+struct vfsmount *pipe_mnt __read_mostly;
50274
50275 /*
50276 * pipefs_dname() is called from d_path().
50277@@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
50278 goto fail_iput;
50279 inode->i_pipe = pipe;
50280
50281- pipe->readers = pipe->writers = 1;
50282+ atomic_set(&pipe->readers, 1);
50283+ atomic_set(&pipe->writers, 1);
50284 inode->i_fop = &rdwr_pipefifo_fops;
50285
50286 /*
50287diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
50288index 15af622..0e9f4467 100644
50289--- a/fs/proc/Kconfig
50290+++ b/fs/proc/Kconfig
50291@@ -30,12 +30,12 @@ config PROC_FS
50292
50293 config PROC_KCORE
50294 bool "/proc/kcore support" if !ARM
50295- depends on PROC_FS && MMU
50296+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
50297
50298 config PROC_VMCORE
50299 bool "/proc/vmcore support"
50300- depends on PROC_FS && CRASH_DUMP
50301- default y
50302+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
50303+ default n
50304 help
50305 Exports the dump image of crashed kernel in ELF format.
50306
50307@@ -59,8 +59,8 @@ config PROC_SYSCTL
50308 limited in memory.
50309
50310 config PROC_PAGE_MONITOR
50311- default y
50312- depends on PROC_FS && MMU
50313+ default n
50314+ depends on PROC_FS && MMU && !GRKERNSEC
50315 bool "Enable /proc page monitoring" if EXPERT
50316 help
50317 Various /proc files exist to monitor process memory utilization:
50318diff --git a/fs/proc/array.c b/fs/proc/array.c
50319index bd31e02..15cae71 100644
50320--- a/fs/proc/array.c
50321+++ b/fs/proc/array.c
50322@@ -60,6 +60,7 @@
50323 #include <linux/tty.h>
50324 #include <linux/string.h>
50325 #include <linux/mman.h>
50326+#include <linux/grsecurity.h>
50327 #include <linux/proc_fs.h>
50328 #include <linux/ioport.h>
50329 #include <linux/uaccess.h>
50330@@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
50331 seq_putc(m, '\n');
50332 }
50333
50334+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50335+static inline void task_pax(struct seq_file *m, struct task_struct *p)
50336+{
50337+ if (p->mm)
50338+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
50339+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
50340+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
50341+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
50342+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
50343+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
50344+ else
50345+ seq_printf(m, "PaX:\t-----\n");
50346+}
50347+#endif
50348+
50349 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50350 struct pid *pid, struct task_struct *task)
50351 {
50352@@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
50353 task_cpus_allowed(m, task);
50354 cpuset_task_status_allowed(m, task);
50355 task_context_switch_counts(m, task);
50356+
50357+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
50358+ task_pax(m, task);
50359+#endif
50360+
50361+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
50362+ task_grsec_rbac(m, task);
50363+#endif
50364+
50365 return 0;
50366 }
50367
50368+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50369+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50370+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50371+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50372+#endif
50373+
50374 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50375 struct pid *pid, struct task_struct *task, int whole)
50376 {
50377@@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50378 char tcomm[sizeof(task->comm)];
50379 unsigned long flags;
50380
50381+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50382+ if (current->exec_id != m->exec_id) {
50383+ gr_log_badprocpid("stat");
50384+ return 0;
50385+ }
50386+#endif
50387+
50388 state = *get_task_state(task);
50389 vsize = eip = esp = 0;
50390 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50391@@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50392 gtime = task->gtime;
50393 }
50394
50395+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50396+ if (PAX_RAND_FLAGS(mm)) {
50397+ eip = 0;
50398+ esp = 0;
50399+ wchan = 0;
50400+ }
50401+#endif
50402+#ifdef CONFIG_GRKERNSEC_HIDESYM
50403+ wchan = 0;
50404+ eip =0;
50405+ esp =0;
50406+#endif
50407+
50408 /* scale priority and nice values from timeslices to -20..20 */
50409 /* to make it look like a "normal" Unix priority/nice value */
50410 priority = task_prio(task);
50411@@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50412 seq_put_decimal_ull(m, ' ', vsize);
50413 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
50414 seq_put_decimal_ull(m, ' ', rsslim);
50415+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50416+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
50417+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
50418+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
50419+#else
50420 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
50421 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
50422 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
50423+#endif
50424 seq_put_decimal_ull(m, ' ', esp);
50425 seq_put_decimal_ull(m, ' ', eip);
50426 /* The signal information here is obsolete.
50427@@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
50428 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
50429 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
50430
50431- if (mm && permitted) {
50432+ if (mm && permitted
50433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50434+ && !PAX_RAND_FLAGS(mm)
50435+#endif
50436+ ) {
50437 seq_put_decimal_ull(m, ' ', mm->start_data);
50438 seq_put_decimal_ull(m, ' ', mm->end_data);
50439 seq_put_decimal_ull(m, ' ', mm->start_brk);
50440@@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50441 struct pid *pid, struct task_struct *task)
50442 {
50443 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
50444- struct mm_struct *mm = get_task_mm(task);
50445+ struct mm_struct *mm;
50446
50447+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50448+ if (current->exec_id != m->exec_id) {
50449+ gr_log_badprocpid("statm");
50450+ return 0;
50451+ }
50452+#endif
50453+ mm = get_task_mm(task);
50454 if (mm) {
50455 size = task_statm(mm, &shared, &text, &data, &resident);
50456 mmput(mm);
50457@@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
50458 return 0;
50459 }
50460
50461+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50462+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
50463+{
50464+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
50465+}
50466+#endif
50467+
50468 #ifdef CONFIG_CHECKPOINT_RESTORE
50469 static struct pid *
50470 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
50471diff --git a/fs/proc/base.c b/fs/proc/base.c
50472index 9e28356..c485b3c 100644
50473--- a/fs/proc/base.c
50474+++ b/fs/proc/base.c
50475@@ -111,6 +111,14 @@ struct pid_entry {
50476 union proc_op op;
50477 };
50478
50479+struct getdents_callback {
50480+ struct linux_dirent __user * current_dir;
50481+ struct linux_dirent __user * previous;
50482+ struct file * file;
50483+ int count;
50484+ int error;
50485+};
50486+
50487 #define NOD(NAME, MODE, IOP, FOP, OP) { \
50488 .name = (NAME), \
50489 .len = sizeof(NAME) - 1, \
50490@@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
50491 if (!mm->arg_end)
50492 goto out_mm; /* Shh! No looking before we're done */
50493
50494+ if (gr_acl_handle_procpidmem(task))
50495+ goto out_mm;
50496+
50497 len = mm->arg_end - mm->arg_start;
50498
50499 if (len > PAGE_SIZE)
50500@@ -235,12 +246,28 @@ out:
50501 return res;
50502 }
50503
50504+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50505+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
50506+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
50507+ _mm->pax_flags & MF_PAX_SEGMEXEC))
50508+#endif
50509+
50510 static int proc_pid_auxv(struct task_struct *task, char *buffer)
50511 {
50512 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
50513 int res = PTR_ERR(mm);
50514 if (mm && !IS_ERR(mm)) {
50515 unsigned int nwords = 0;
50516+
50517+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50518+ /* allow if we're currently ptracing this task */
50519+ if (PAX_RAND_FLAGS(mm) &&
50520+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
50521+ mmput(mm);
50522+ return 0;
50523+ }
50524+#endif
50525+
50526 do {
50527 nwords += 2;
50528 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
50529@@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
50530 }
50531
50532
50533-#ifdef CONFIG_KALLSYMS
50534+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50535 /*
50536 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
50537 * Returns the resolved symbol. If that fails, simply return the address.
50538@@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
50539 mutex_unlock(&task->signal->cred_guard_mutex);
50540 }
50541
50542-#ifdef CONFIG_STACKTRACE
50543+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50544
50545 #define MAX_STACK_TRACE_DEPTH 64
50546
50547@@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
50548 return count;
50549 }
50550
50551-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50552+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50553 static int proc_pid_syscall(struct task_struct *task, char *buffer)
50554 {
50555 long nr;
50556@@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
50557 /************************************************************************/
50558
50559 /* permission checks */
50560-static int proc_fd_access_allowed(struct inode *inode)
50561+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
50562 {
50563 struct task_struct *task;
50564 int allowed = 0;
50565@@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
50566 */
50567 task = get_proc_task(inode);
50568 if (task) {
50569- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50570+ if (log)
50571+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
50572+ else
50573+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
50574 put_task_struct(task);
50575 }
50576 return allowed;
50577@@ -562,10 +592,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
50578 struct task_struct *task,
50579 int hide_pid_min)
50580 {
50581+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50582+ return false;
50583+
50584+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50585+ rcu_read_lock();
50586+ {
50587+ const struct cred *tmpcred = current_cred();
50588+ const struct cred *cred = __task_cred(task);
50589+
50590+ if (!tmpcred->uid || (tmpcred->uid == cred->uid)
50591+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50592+ || in_group_p(grsec_proc_gid)
50593+#endif
50594+ ) {
50595+ rcu_read_unlock();
50596+ return true;
50597+ }
50598+ }
50599+ rcu_read_unlock();
50600+
50601+ if (!pid->hide_pid)
50602+ return false;
50603+#endif
50604+
50605 if (pid->hide_pid < hide_pid_min)
50606 return true;
50607 if (in_group_p(pid->pid_gid))
50608 return true;
50609+
50610 return ptrace_may_access(task, PTRACE_MODE_READ);
50611 }
50612
50613@@ -583,7 +638,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
50614 put_task_struct(task);
50615
50616 if (!has_perms) {
50617+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50618+ {
50619+#else
50620 if (pid->hide_pid == 2) {
50621+#endif
50622 /*
50623 * Let's make getdents(), stat(), and open()
50624 * consistent with each other. If a process
50625@@ -681,6 +740,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50626 if (!task)
50627 return -ESRCH;
50628
50629+ if (gr_acl_handle_procpidmem(task)) {
50630+ put_task_struct(task);
50631+ return -EPERM;
50632+ }
50633+
50634 mm = mm_access(task, mode);
50635 put_task_struct(task);
50636
50637@@ -696,6 +760,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
50638
50639 file->private_data = mm;
50640
50641+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50642+ file->f_version = current->exec_id;
50643+#endif
50644+
50645 return 0;
50646 }
50647
50648@@ -717,6 +785,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
50649 ssize_t copied;
50650 char *page;
50651
50652+#ifdef CONFIG_GRKERNSEC
50653+ if (write)
50654+ return -EPERM;
50655+#endif
50656+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50657+ if (file->f_version != current->exec_id) {
50658+ gr_log_badprocpid("mem");
50659+ return 0;
50660+ }
50661+#endif
50662+
50663 if (!mm)
50664 return 0;
50665
50666@@ -821,6 +900,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
50667 if (!mm)
50668 return 0;
50669
50670+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50671+ if (file->f_version != current->exec_id) {
50672+ gr_log_badprocpid("environ");
50673+ return 0;
50674+ }
50675+#endif
50676+
50677 page = (char *)__get_free_page(GFP_TEMPORARY);
50678 if (!page)
50679 return -ENOMEM;
50680@@ -1436,7 +1522,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
50681 int error = -EACCES;
50682
50683 /* Are we allowed to snoop on the tasks file descriptors? */
50684- if (!proc_fd_access_allowed(inode))
50685+ if (!proc_fd_access_allowed(inode, 0))
50686 goto out;
50687
50688 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50689@@ -1480,8 +1566,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
50690 struct path path;
50691
50692 /* Are we allowed to snoop on the tasks file descriptors? */
50693- if (!proc_fd_access_allowed(inode))
50694- goto out;
50695+ /* logging this is needed for learning on chromium to work properly,
50696+ but we don't want to flood the logs from 'ps' which does a readlink
50697+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
50698+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
50699+ */
50700+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
50701+ if (!proc_fd_access_allowed(inode,0))
50702+ goto out;
50703+ } else {
50704+ if (!proc_fd_access_allowed(inode,1))
50705+ goto out;
50706+ }
50707
50708 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
50709 if (error)
50710@@ -1531,7 +1627,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
50711 rcu_read_lock();
50712 cred = __task_cred(task);
50713 inode->i_uid = cred->euid;
50714+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50715+ inode->i_gid = grsec_proc_gid;
50716+#else
50717 inode->i_gid = cred->egid;
50718+#endif
50719 rcu_read_unlock();
50720 }
50721 security_task_to_inode(task, inode);
50722@@ -1567,10 +1667,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
50723 return -ENOENT;
50724 }
50725 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50726+#ifdef CONFIG_GRKERNSEC_PROC_USER
50727+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50728+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50729+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50730+#endif
50731 task_dumpable(task)) {
50732 cred = __task_cred(task);
50733 stat->uid = cred->euid;
50734+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50735+ stat->gid = grsec_proc_gid;
50736+#else
50737 stat->gid = cred->egid;
50738+#endif
50739 }
50740 }
50741 rcu_read_unlock();
50742@@ -1608,11 +1717,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
50743
50744 if (task) {
50745 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
50746+#ifdef CONFIG_GRKERNSEC_PROC_USER
50747+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
50748+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50749+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
50750+#endif
50751 task_dumpable(task)) {
50752 rcu_read_lock();
50753 cred = __task_cred(task);
50754 inode->i_uid = cred->euid;
50755+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50756+ inode->i_gid = grsec_proc_gid;
50757+#else
50758 inode->i_gid = cred->egid;
50759+#endif
50760 rcu_read_unlock();
50761 } else {
50762 inode->i_uid = GLOBAL_ROOT_UID;
50763@@ -2065,6 +2183,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
50764 if (!task)
50765 goto out_no_task;
50766
50767+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50768+ goto out;
50769+
50770 /*
50771 * Yes, it does not scale. And it should not. Don't add
50772 * new entries into /proc/<tgid>/ without very good reasons.
50773@@ -2109,6 +2230,9 @@ static int proc_pident_readdir(struct file *filp,
50774 if (!task)
50775 goto out_no_task;
50776
50777+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50778+ goto out;
50779+
50780 ret = 0;
50781 i = filp->f_pos;
50782 switch (i) {
50783@@ -2380,7 +2504,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
50784 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
50785 void *cookie)
50786 {
50787- char *s = nd_get_link(nd);
50788+ const char *s = nd_get_link(nd);
50789 if (!IS_ERR(s))
50790 kfree(s);
50791 }
50792@@ -2662,7 +2786,7 @@ static const struct pid_entry tgid_base_stuff[] = {
50793 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
50794 #endif
50795 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50796-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50797+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50798 INF("syscall", S_IRUGO, proc_pid_syscall),
50799 #endif
50800 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50801@@ -2687,10 +2811,10 @@ static const struct pid_entry tgid_base_stuff[] = {
50802 #ifdef CONFIG_SECURITY
50803 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50804 #endif
50805-#ifdef CONFIG_KALLSYMS
50806+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50807 INF("wchan", S_IRUGO, proc_pid_wchan),
50808 #endif
50809-#ifdef CONFIG_STACKTRACE
50810+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50811 ONE("stack", S_IRUGO, proc_pid_stack),
50812 #endif
50813 #ifdef CONFIG_SCHEDSTATS
50814@@ -2724,6 +2848,9 @@ static const struct pid_entry tgid_base_stuff[] = {
50815 #ifdef CONFIG_HARDWALL
50816 INF("hardwall", S_IRUGO, proc_pid_hardwall),
50817 #endif
50818+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
50819+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
50820+#endif
50821 #ifdef CONFIG_USER_NS
50822 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
50823 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
50824@@ -2856,7 +2983,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
50825 if (!inode)
50826 goto out;
50827
50828+#ifdef CONFIG_GRKERNSEC_PROC_USER
50829+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
50830+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50831+ inode->i_gid = grsec_proc_gid;
50832+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
50833+#else
50834 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
50835+#endif
50836 inode->i_op = &proc_tgid_base_inode_operations;
50837 inode->i_fop = &proc_tgid_base_operations;
50838 inode->i_flags|=S_IMMUTABLE;
50839@@ -2898,7 +3032,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
50840 if (!task)
50841 goto out;
50842
50843+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
50844+ goto out_put_task;
50845+
50846 result = proc_pid_instantiate(dir, dentry, task, NULL);
50847+out_put_task:
50848 put_task_struct(task);
50849 out:
50850 return result;
50851@@ -2961,6 +3099,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
50852 static int fake_filldir(void *buf, const char *name, int namelen,
50853 loff_t offset, u64 ino, unsigned d_type)
50854 {
50855+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
50856+ __buf->error = -EINVAL;
50857 return 0;
50858 }
50859
50860@@ -3027,7 +3167,7 @@ static const struct pid_entry tid_base_stuff[] = {
50861 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
50862 #endif
50863 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
50864-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
50865+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50866 INF("syscall", S_IRUGO, proc_pid_syscall),
50867 #endif
50868 INF("cmdline", S_IRUGO, proc_pid_cmdline),
50869@@ -3054,10 +3194,10 @@ static const struct pid_entry tid_base_stuff[] = {
50870 #ifdef CONFIG_SECURITY
50871 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
50872 #endif
50873-#ifdef CONFIG_KALLSYMS
50874+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50875 INF("wchan", S_IRUGO, proc_pid_wchan),
50876 #endif
50877-#ifdef CONFIG_STACKTRACE
50878+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
50879 ONE("stack", S_IRUGO, proc_pid_stack),
50880 #endif
50881 #ifdef CONFIG_SCHEDSTATS
50882diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
50883index 82676e3..5f8518a 100644
50884--- a/fs/proc/cmdline.c
50885+++ b/fs/proc/cmdline.c
50886@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
50887
50888 static int __init proc_cmdline_init(void)
50889 {
50890+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50891+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
50892+#else
50893 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
50894+#endif
50895 return 0;
50896 }
50897 module_init(proc_cmdline_init);
50898diff --git a/fs/proc/devices.c b/fs/proc/devices.c
50899index b143471..bb105e5 100644
50900--- a/fs/proc/devices.c
50901+++ b/fs/proc/devices.c
50902@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
50903
50904 static int __init proc_devices_init(void)
50905 {
50906+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50907+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
50908+#else
50909 proc_create("devices", 0, NULL, &proc_devinfo_operations);
50910+#endif
50911 return 0;
50912 }
50913 module_init(proc_devices_init);
50914diff --git a/fs/proc/fd.c b/fs/proc/fd.c
50915index f28a875..c467953 100644
50916--- a/fs/proc/fd.c
50917+++ b/fs/proc/fd.c
50918@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
50919 if (!task)
50920 return -ENOENT;
50921
50922- files = get_files_struct(task);
50923+ if (!gr_acl_handle_procpidmem(task))
50924+ files = get_files_struct(task);
50925 put_task_struct(task);
50926
50927 if (files) {
50928@@ -300,11 +301,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
50929 */
50930 int proc_fd_permission(struct inode *inode, int mask)
50931 {
50932+ struct task_struct *task;
50933 int rv = generic_permission(inode, mask);
50934- if (rv == 0)
50935- return 0;
50936+
50937 if (task_pid(current) == proc_pid(inode))
50938 rv = 0;
50939+
50940+ task = get_proc_task(inode);
50941+ if (task == NULL)
50942+ return rv;
50943+
50944+ if (gr_acl_handle_procpidmem(task))
50945+ rv = -EACCES;
50946+
50947+ put_task_struct(task);
50948+
50949 return rv;
50950 }
50951
50952diff --git a/fs/proc/inode.c b/fs/proc/inode.c
50953index 3b22bbd..895b58c 100644
50954--- a/fs/proc/inode.c
50955+++ b/fs/proc/inode.c
50956@@ -21,11 +21,17 @@
50957 #include <linux/seq_file.h>
50958 #include <linux/slab.h>
50959 #include <linux/mount.h>
50960+#include <linux/grsecurity.h>
50961
50962 #include <asm/uaccess.h>
50963
50964 #include "internal.h"
50965
50966+#ifdef CONFIG_PROC_SYSCTL
50967+extern const struct inode_operations proc_sys_inode_operations;
50968+extern const struct inode_operations proc_sys_dir_operations;
50969+#endif
50970+
50971 static void proc_evict_inode(struct inode *inode)
50972 {
50973 struct proc_dir_entry *de;
50974@@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
50975 ns_ops = PROC_I(inode)->ns_ops;
50976 if (ns_ops && ns_ops->put)
50977 ns_ops->put(PROC_I(inode)->ns);
50978+
50979+#ifdef CONFIG_PROC_SYSCTL
50980+ if (inode->i_op == &proc_sys_inode_operations ||
50981+ inode->i_op == &proc_sys_dir_operations)
50982+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
50983+#endif
50984+
50985 }
50986
50987 static struct kmem_cache * proc_inode_cachep;
50988@@ -455,7 +468,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
50989 if (de->mode) {
50990 inode->i_mode = de->mode;
50991 inode->i_uid = de->uid;
50992+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
50993+ inode->i_gid = grsec_proc_gid;
50994+#else
50995 inode->i_gid = de->gid;
50996+#endif
50997 }
50998 if (de->size)
50999 inode->i_size = de->size;
51000diff --git a/fs/proc/internal.h b/fs/proc/internal.h
51001index 43973b0..a20e704 100644
51002--- a/fs/proc/internal.h
51003+++ b/fs/proc/internal.h
51004@@ -54,6 +54,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
51005 struct pid *pid, struct task_struct *task);
51006 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
51007 struct pid *pid, struct task_struct *task);
51008+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
51009+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
51010+#endif
51011 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
51012
51013 extern const struct file_operations proc_tid_children_operations;
51014diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
51015index 86c67ee..cdca321 100644
51016--- a/fs/proc/kcore.c
51017+++ b/fs/proc/kcore.c
51018@@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51019 * the addresses in the elf_phdr on our list.
51020 */
51021 start = kc_offset_to_vaddr(*fpos - elf_buflen);
51022- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
51023+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
51024+ if (tsz > buflen)
51025 tsz = buflen;
51026-
51027+
51028 while (buflen) {
51029 struct kcore_list *m;
51030
51031@@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51032 kfree(elf_buf);
51033 } else {
51034 if (kern_addr_valid(start)) {
51035- unsigned long n;
51036+ char *elf_buf;
51037+ mm_segment_t oldfs;
51038
51039- n = copy_to_user(buffer, (char *)start, tsz);
51040- /*
51041- * We cannot distinguish between fault on source
51042- * and fault on destination. When this happens
51043- * we clear too and hope it will trigger the
51044- * EFAULT again.
51045- */
51046- if (n) {
51047- if (clear_user(buffer + tsz - n,
51048- n))
51049+ elf_buf = kmalloc(tsz, GFP_KERNEL);
51050+ if (!elf_buf)
51051+ return -ENOMEM;
51052+ oldfs = get_fs();
51053+ set_fs(KERNEL_DS);
51054+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
51055+ set_fs(oldfs);
51056+ if (copy_to_user(buffer, elf_buf, tsz)) {
51057+ kfree(elf_buf);
51058 return -EFAULT;
51059+ }
51060 }
51061+ set_fs(oldfs);
51062+ kfree(elf_buf);
51063 } else {
51064 if (clear_user(buffer, tsz))
51065 return -EFAULT;
51066@@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
51067
51068 static int open_kcore(struct inode *inode, struct file *filp)
51069 {
51070+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
51071+ return -EPERM;
51072+#endif
51073 if (!capable(CAP_SYS_RAWIO))
51074 return -EPERM;
51075 if (kcore_need_update)
51076diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
51077index 80e4645..53e5fcf 100644
51078--- a/fs/proc/meminfo.c
51079+++ b/fs/proc/meminfo.c
51080@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
51081 vmi.used >> 10,
51082 vmi.largest_chunk >> 10
51083 #ifdef CONFIG_MEMORY_FAILURE
51084- ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
51085+ ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
51086 #endif
51087 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
51088 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
51089diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
51090index b1822dd..df622cb 100644
51091--- a/fs/proc/nommu.c
51092+++ b/fs/proc/nommu.c
51093@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
51094 if (len < 1)
51095 len = 1;
51096 seq_printf(m, "%*c", len, ' ');
51097- seq_path(m, &file->f_path, "");
51098+ seq_path(m, &file->f_path, "\n\\");
51099 }
51100
51101 seq_putc(m, '\n');
51102diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
51103index fe72cd0..cb9b67d 100644
51104--- a/fs/proc/proc_net.c
51105+++ b/fs/proc/proc_net.c
51106@@ -23,6 +23,7 @@
51107 #include <linux/nsproxy.h>
51108 #include <net/net_namespace.h>
51109 #include <linux/seq_file.h>
51110+#include <linux/grsecurity.h>
51111
51112 #include "internal.h"
51113
51114@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
51115 struct task_struct *task;
51116 struct nsproxy *ns;
51117 struct net *net = NULL;
51118+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51119+ const struct cred *cred = current_cred();
51120+#endif
51121+
51122+#ifdef CONFIG_GRKERNSEC_PROC_USER
51123+ if (cred->fsuid)
51124+ return net;
51125+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51126+ if (cred->fsuid && !in_group_p(grsec_proc_gid))
51127+ return net;
51128+#endif
51129
51130 rcu_read_lock();
51131 task = pid_task(proc_pid(dir), PIDTYPE_PID);
51132diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
51133index a781bdf..6665284 100644
51134--- a/fs/proc/proc_sysctl.c
51135+++ b/fs/proc/proc_sysctl.c
51136@@ -12,11 +12,15 @@
51137 #include <linux/module.h>
51138 #include "internal.h"
51139
51140+extern int gr_handle_chroot_sysctl(const int op);
51141+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
51142+ const int op);
51143+
51144 static const struct dentry_operations proc_sys_dentry_operations;
51145 static const struct file_operations proc_sys_file_operations;
51146-static const struct inode_operations proc_sys_inode_operations;
51147+const struct inode_operations proc_sys_inode_operations;
51148 static const struct file_operations proc_sys_dir_file_operations;
51149-static const struct inode_operations proc_sys_dir_operations;
51150+const struct inode_operations proc_sys_dir_operations;
51151
51152 void proc_sys_poll_notify(struct ctl_table_poll *poll)
51153 {
51154@@ -465,6 +469,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
51155
51156 err = NULL;
51157 d_set_d_op(dentry, &proc_sys_dentry_operations);
51158+
51159+ gr_handle_proc_create(dentry, inode);
51160+
51161 d_add(dentry, inode);
51162
51163 out:
51164@@ -480,18 +487,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51165 struct inode *inode = filp->f_path.dentry->d_inode;
51166 struct ctl_table_header *head = grab_header(inode);
51167 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
51168+ int op = write ? MAY_WRITE : MAY_READ;
51169 ssize_t error;
51170 size_t res;
51171
51172 if (IS_ERR(head))
51173 return PTR_ERR(head);
51174
51175+
51176 /*
51177 * At this point we know that the sysctl was not unregistered
51178 * and won't be until we finish.
51179 */
51180 error = -EPERM;
51181- if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
51182+ if (sysctl_perm(head->root, table, op))
51183 goto out;
51184
51185 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
51186@@ -499,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
51187 if (!table->proc_handler)
51188 goto out;
51189
51190+#ifdef CONFIG_GRKERNSEC
51191+ error = -EPERM;
51192+ if (gr_handle_chroot_sysctl(op))
51193+ goto out;
51194+ dget(filp->f_path.dentry);
51195+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
51196+ dput(filp->f_path.dentry);
51197+ goto out;
51198+ }
51199+ dput(filp->f_path.dentry);
51200+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
51201+ goto out;
51202+ if (write && !capable(CAP_SYS_ADMIN))
51203+ goto out;
51204+#endif
51205+
51206 /* careful: calling conventions are nasty here */
51207 res = count;
51208 error = table->proc_handler(table, write, buf, &res, ppos);
51209@@ -596,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
51210 return -ENOMEM;
51211 } else {
51212 d_set_d_op(child, &proc_sys_dentry_operations);
51213+
51214+ gr_handle_proc_create(child, inode);
51215+
51216 d_add(child, inode);
51217 }
51218 } else {
51219@@ -639,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
51220 if ((*pos)++ < file->f_pos)
51221 return 0;
51222
51223+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
51224+ return 0;
51225+
51226 if (unlikely(S_ISLNK(table->mode)))
51227 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
51228 else
51229@@ -756,6 +787,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
51230 if (IS_ERR(head))
51231 return PTR_ERR(head);
51232
51233+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
51234+ return -ENOENT;
51235+
51236 generic_fillattr(inode, stat);
51237 if (table)
51238 stat->mode = (stat->mode & S_IFMT) | table->mode;
51239@@ -778,13 +812,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
51240 .llseek = generic_file_llseek,
51241 };
51242
51243-static const struct inode_operations proc_sys_inode_operations = {
51244+const struct inode_operations proc_sys_inode_operations = {
51245 .permission = proc_sys_permission,
51246 .setattr = proc_sys_setattr,
51247 .getattr = proc_sys_getattr,
51248 };
51249
51250-static const struct inode_operations proc_sys_dir_operations = {
51251+const struct inode_operations proc_sys_dir_operations = {
51252 .lookup = proc_sys_lookup,
51253 .permission = proc_sys_permission,
51254 .setattr = proc_sys_setattr,
51255diff --git a/fs/proc/root.c b/fs/proc/root.c
51256index 9889a92..2613b48 100644
51257--- a/fs/proc/root.c
51258+++ b/fs/proc/root.c
51259@@ -187,7 +187,15 @@ void __init proc_root_init(void)
51260 #ifdef CONFIG_PROC_DEVICETREE
51261 proc_device_tree_init();
51262 #endif
51263+#ifdef CONFIG_GRKERNSEC_PROC_ADD
51264+#ifdef CONFIG_GRKERNSEC_PROC_USER
51265+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
51266+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
51267+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
51268+#endif
51269+#else
51270 proc_mkdir("bus", NULL);
51271+#endif
51272 proc_sys_init();
51273 }
51274
51275diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
51276index 90c63f9..e662cfc 100644
51277--- a/fs/proc/task_mmu.c
51278+++ b/fs/proc/task_mmu.c
51279@@ -11,12 +11,19 @@
51280 #include <linux/rmap.h>
51281 #include <linux/swap.h>
51282 #include <linux/swapops.h>
51283+#include <linux/grsecurity.h>
51284
51285 #include <asm/elf.h>
51286 #include <asm/uaccess.h>
51287 #include <asm/tlbflush.h>
51288 #include "internal.h"
51289
51290+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51291+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
51292+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
51293+ _mm->pax_flags & MF_PAX_SEGMEXEC))
51294+#endif
51295+
51296 void task_mem(struct seq_file *m, struct mm_struct *mm)
51297 {
51298 unsigned long data, text, lib, swap;
51299@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51300 "VmExe:\t%8lu kB\n"
51301 "VmLib:\t%8lu kB\n"
51302 "VmPTE:\t%8lu kB\n"
51303- "VmSwap:\t%8lu kB\n",
51304- hiwater_vm << (PAGE_SHIFT-10),
51305+ "VmSwap:\t%8lu kB\n"
51306+
51307+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51308+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
51309+#endif
51310+
51311+ ,hiwater_vm << (PAGE_SHIFT-10),
51312 total_vm << (PAGE_SHIFT-10),
51313 mm->locked_vm << (PAGE_SHIFT-10),
51314 mm->pinned_vm << (PAGE_SHIFT-10),
51315@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51316 data << (PAGE_SHIFT-10),
51317 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
51318 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
51319- swap << (PAGE_SHIFT-10));
51320+ swap << (PAGE_SHIFT-10)
51321+
51322+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
51323+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51324+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
51325+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
51326+#else
51327+ , mm->context.user_cs_base
51328+ , mm->context.user_cs_limit
51329+#endif
51330+#endif
51331+
51332+ );
51333 }
51334
51335 unsigned long task_vsize(struct mm_struct *mm)
51336@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51337 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
51338 }
51339
51340- /* We don't show the stack guard page in /proc/maps */
51341+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51342+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
51343+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
51344+#else
51345 start = vma->vm_start;
51346- if (stack_guard_page_start(vma, start))
51347- start += PAGE_SIZE;
51348 end = vma->vm_end;
51349- if (stack_guard_page_end(vma, end))
51350- end -= PAGE_SIZE;
51351+#endif
51352
51353 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
51354 start,
51355@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51356 flags & VM_WRITE ? 'w' : '-',
51357 flags & VM_EXEC ? 'x' : '-',
51358 flags & VM_MAYSHARE ? 's' : 'p',
51359+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51360+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
51361+#else
51362 pgoff,
51363+#endif
51364 MAJOR(dev), MINOR(dev), ino, &len);
51365
51366 /*
51367@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51368 */
51369 if (file) {
51370 pad_len_spaces(m, len);
51371- seq_path(m, &file->f_path, "\n");
51372+ seq_path(m, &file->f_path, "\n\\");
51373 goto done;
51374 }
51375
51376@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
51377 * Thread stack in /proc/PID/task/TID/maps or
51378 * the main process stack.
51379 */
51380- if (!is_pid || (vma->vm_start <= mm->start_stack &&
51381- vma->vm_end >= mm->start_stack)) {
51382+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
51383+ (vma->vm_start <= mm->start_stack &&
51384+ vma->vm_end >= mm->start_stack)) {
51385 name = "[stack]";
51386 } else {
51387 /* Thread stack in /proc/PID/maps */
51388@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
51389 struct proc_maps_private *priv = m->private;
51390 struct task_struct *task = priv->task;
51391
51392+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51393+ if (current->exec_id != m->exec_id) {
51394+ gr_log_badprocpid("maps");
51395+ return 0;
51396+ }
51397+#endif
51398+
51399 show_map_vma(m, vma, is_pid);
51400
51401 if (m->count < m->size) /* vma is copied successfully */
51402@@ -538,12 +574,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51403 .private = &mss,
51404 };
51405
51406+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51407+ if (current->exec_id != m->exec_id) {
51408+ gr_log_badprocpid("smaps");
51409+ return 0;
51410+ }
51411+#endif
51412 memset(&mss, 0, sizeof mss);
51413- mss.vma = vma;
51414- /* mmap_sem is held in m_start */
51415- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51416- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51417-
51418+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51419+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
51420+#endif
51421+ mss.vma = vma;
51422+ /* mmap_sem is held in m_start */
51423+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
51424+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
51425+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51426+ }
51427+#endif
51428 show_map_vma(m, vma, is_pid);
51429
51430 seq_printf(m,
51431@@ -561,7 +608,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
51432 "KernelPageSize: %8lu kB\n"
51433 "MMUPageSize: %8lu kB\n"
51434 "Locked: %8lu kB\n",
51435+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51436+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
51437+#else
51438 (vma->vm_end - vma->vm_start) >> 10,
51439+#endif
51440 mss.resident >> 10,
51441 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
51442 mss.shared_clean >> 10,
51443@@ -1211,6 +1262,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51444 int n;
51445 char buffer[50];
51446
51447+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51448+ if (current->exec_id != m->exec_id) {
51449+ gr_log_badprocpid("numa_maps");
51450+ return 0;
51451+ }
51452+#endif
51453+
51454 if (!mm)
51455 return 0;
51456
51457@@ -1228,11 +1286,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
51458 mpol_to_str(buffer, sizeof(buffer), pol, 0);
51459 mpol_cond_put(pol);
51460
51461+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51462+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
51463+#else
51464 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
51465+#endif
51466
51467 if (file) {
51468 seq_printf(m, " file=");
51469- seq_path(m, &file->f_path, "\n\t= ");
51470+ seq_path(m, &file->f_path, "\n\t\\= ");
51471 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
51472 seq_printf(m, " heap");
51473 } else {
51474diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
51475index 1ccfa53..0848f95 100644
51476--- a/fs/proc/task_nommu.c
51477+++ b/fs/proc/task_nommu.c
51478@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
51479 else
51480 bytes += kobjsize(mm);
51481
51482- if (current->fs && current->fs->users > 1)
51483+ if (current->fs && atomic_read(&current->fs->users) > 1)
51484 sbytes += kobjsize(current->fs);
51485 else
51486 bytes += kobjsize(current->fs);
51487@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
51488
51489 if (file) {
51490 pad_len_spaces(m, len);
51491- seq_path(m, &file->f_path, "");
51492+ seq_path(m, &file->f_path, "\n\\");
51493 } else if (mm) {
51494 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
51495
51496diff --git a/fs/pstore/ftrace.c b/fs/pstore/ftrace.c
51497index 2d57e1a..43b1280 100644
51498--- a/fs/pstore/ftrace.c
51499+++ b/fs/pstore/ftrace.c
51500@@ -28,7 +28,9 @@
51501 #include "internal.h"
51502
51503 static void notrace pstore_ftrace_call(unsigned long ip,
51504- unsigned long parent_ip)
51505+ unsigned long parent_ip,
51506+ struct ftrace_ops *op,
51507+ struct pt_regs *regs)
51508 {
51509 unsigned long flags;
51510 struct pstore_ftrace_record rec = {};
51511diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
51512index 16e8abb..2dcf914 100644
51513--- a/fs/quota/netlink.c
51514+++ b/fs/quota/netlink.c
51515@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
51516 void quota_send_warning(struct kqid qid, dev_t dev,
51517 const char warntype)
51518 {
51519- static atomic_t seq;
51520+ static atomic_unchecked_t seq;
51521 struct sk_buff *skb;
51522 void *msg_head;
51523 int ret;
51524@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
51525 "VFS: Not enough memory to send quota warning.\n");
51526 return;
51527 }
51528- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
51529+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
51530 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
51531 if (!msg_head) {
51532 printk(KERN_ERR
51533diff --git a/fs/read_write.c b/fs/read_write.c
51534index d065348..8e2b43d 100644
51535--- a/fs/read_write.c
51536+++ b/fs/read_write.c
51537@@ -935,6 +935,8 @@ ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, size_t count,
51538 if (retval > 0) {
51539 add_rchar(current, retval);
51540 add_wchar(current, retval);
51541+ fsnotify_access(in.file);
51542+ fsnotify_modify(out.file);
51543 }
51544
51545 inc_syscr(current);
51546diff --git a/fs/readdir.c b/fs/readdir.c
51547index 5e69ef5..e5d9099 100644
51548--- a/fs/readdir.c
51549+++ b/fs/readdir.c
51550@@ -17,6 +17,7 @@
51551 #include <linux/security.h>
51552 #include <linux/syscalls.h>
51553 #include <linux/unistd.h>
51554+#include <linux/namei.h>
51555
51556 #include <asm/uaccess.h>
51557
51558@@ -67,6 +68,7 @@ struct old_linux_dirent {
51559
51560 struct readdir_callback {
51561 struct old_linux_dirent __user * dirent;
51562+ struct file * file;
51563 int result;
51564 };
51565
51566@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
51567 buf->result = -EOVERFLOW;
51568 return -EOVERFLOW;
51569 }
51570+
51571+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51572+ return 0;
51573+
51574 buf->result++;
51575 dirent = buf->dirent;
51576 if (!access_ok(VERIFY_WRITE, dirent,
51577@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
51578
51579 buf.result = 0;
51580 buf.dirent = dirent;
51581+ buf.file = f.file;
51582
51583 error = vfs_readdir(f.file, fillonedir, &buf);
51584 if (buf.result)
51585@@ -139,6 +146,7 @@ struct linux_dirent {
51586 struct getdents_callback {
51587 struct linux_dirent __user * current_dir;
51588 struct linux_dirent __user * previous;
51589+ struct file * file;
51590 int count;
51591 int error;
51592 };
51593@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
51594 buf->error = -EOVERFLOW;
51595 return -EOVERFLOW;
51596 }
51597+
51598+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51599+ return 0;
51600+
51601 dirent = buf->previous;
51602 if (dirent) {
51603 if (__put_user(offset, &dirent->d_off))
51604@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51605 buf.previous = NULL;
51606 buf.count = count;
51607 buf.error = 0;
51608+ buf.file = f.file;
51609
51610 error = vfs_readdir(f.file, filldir, &buf);
51611 if (error >= 0)
51612@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
51613 struct getdents_callback64 {
51614 struct linux_dirent64 __user * current_dir;
51615 struct linux_dirent64 __user * previous;
51616+ struct file *file;
51617 int count;
51618 int error;
51619 };
51620@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
51621 buf->error = -EINVAL; /* only used if we fail.. */
51622 if (reclen > buf->count)
51623 return -EINVAL;
51624+
51625+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
51626+ return 0;
51627+
51628 dirent = buf->previous;
51629 if (dirent) {
51630 if (__put_user(offset, &dirent->d_off))
51631@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51632
51633 buf.current_dir = dirent;
51634 buf.previous = NULL;
51635+ buf.file = f.file;
51636 buf.count = count;
51637 buf.error = 0;
51638
51639@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
51640 error = buf.error;
51641 lastdirent = buf.previous;
51642 if (lastdirent) {
51643- typeof(lastdirent->d_off) d_off = f.file->f_pos;
51644+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
51645 if (__put_user(d_off, &lastdirent->d_off))
51646 error = -EFAULT;
51647 else
51648diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
51649index 2b7882b..1c5ef48 100644
51650--- a/fs/reiserfs/do_balan.c
51651+++ b/fs/reiserfs/do_balan.c
51652@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
51653 return;
51654 }
51655
51656- atomic_inc(&(fs_generation(tb->tb_sb)));
51657+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
51658 do_balance_starts(tb);
51659
51660 /* balance leaf returns 0 except if combining L R and S into
51661diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
51662index e60e870..f40ac16 100644
51663--- a/fs/reiserfs/procfs.c
51664+++ b/fs/reiserfs/procfs.c
51665@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
51666 "SMALL_TAILS " : "NO_TAILS ",
51667 replay_only(sb) ? "REPLAY_ONLY " : "",
51668 convert_reiserfs(sb) ? "CONV " : "",
51669- atomic_read(&r->s_generation_counter),
51670+ atomic_read_unchecked(&r->s_generation_counter),
51671 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
51672 SF(s_do_balance), SF(s_unneeded_left_neighbor),
51673 SF(s_good_search_by_key_reada), SF(s_bmaps),
51674diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
51675index 33215f5..c5d427a 100644
51676--- a/fs/reiserfs/reiserfs.h
51677+++ b/fs/reiserfs/reiserfs.h
51678@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
51679 /* Comment? -Hans */
51680 wait_queue_head_t s_wait;
51681 /* To be obsoleted soon by per buffer seals.. -Hans */
51682- atomic_t s_generation_counter; // increased by one every time the
51683+ atomic_unchecked_t s_generation_counter; // increased by one every time the
51684 // tree gets re-balanced
51685 unsigned long s_properties; /* File system properties. Currently holds
51686 on-disk FS format */
51687@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
51688 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
51689
51690 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
51691-#define get_generation(s) atomic_read (&fs_generation(s))
51692+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
51693 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
51694 #define __fs_changed(gen,s) (gen != get_generation (s))
51695 #define fs_changed(gen,s) \
51696diff --git a/fs/select.c b/fs/select.c
51697index 2ef72d9..f213b17 100644
51698--- a/fs/select.c
51699+++ b/fs/select.c
51700@@ -20,6 +20,7 @@
51701 #include <linux/export.h>
51702 #include <linux/slab.h>
51703 #include <linux/poll.h>
51704+#include <linux/security.h>
51705 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
51706 #include <linux/file.h>
51707 #include <linux/fdtable.h>
51708@@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
51709 struct poll_list *walk = head;
51710 unsigned long todo = nfds;
51711
51712+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
51713 if (nfds > rlimit(RLIMIT_NOFILE))
51714 return -EINVAL;
51715
51716diff --git a/fs/seq_file.c b/fs/seq_file.c
51717index 99dffab..e4fcb71 100644
51718--- a/fs/seq_file.c
51719+++ b/fs/seq_file.c
51720@@ -10,6 +10,7 @@
51721 #include <linux/seq_file.h>
51722 #include <linux/slab.h>
51723 #include <linux/cred.h>
51724+#include <linux/sched.h>
51725
51726 #include <asm/uaccess.h>
51727 #include <asm/page.h>
51728@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
51729 #ifdef CONFIG_USER_NS
51730 p->user_ns = file->f_cred->user_ns;
51731 #endif
51732+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
51733+ p->exec_id = current->exec_id;
51734+#endif
51735
51736 /*
51737 * Wrappers around seq_open(e.g. swaps_open) need to be
51738@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51739 return 0;
51740 }
51741 if (!m->buf) {
51742- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51743+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51744 if (!m->buf)
51745 return -ENOMEM;
51746 }
51747@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
51748 Eoverflow:
51749 m->op->stop(m, p);
51750 kfree(m->buf);
51751- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51752+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51753 return !m->buf ? -ENOMEM : -EAGAIN;
51754 }
51755
51756@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51757
51758 /* grab buffer if we didn't have one */
51759 if (!m->buf) {
51760- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
51761+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
51762 if (!m->buf)
51763 goto Enomem;
51764 }
51765@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
51766 goto Fill;
51767 m->op->stop(m, p);
51768 kfree(m->buf);
51769- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
51770+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
51771 if (!m->buf)
51772 goto Enomem;
51773 m->count = 0;
51774@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
51775 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
51776 void *data)
51777 {
51778- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
51779+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
51780 int res = -ENOMEM;
51781
51782 if (op) {
51783diff --git a/fs/splice.c b/fs/splice.c
51784index 48c7bd1..d0740e4 100644
51785--- a/fs/splice.c
51786+++ b/fs/splice.c
51787@@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51788 pipe_lock(pipe);
51789
51790 for (;;) {
51791- if (!pipe->readers) {
51792+ if (!atomic_read(&pipe->readers)) {
51793 send_sig(SIGPIPE, current, 0);
51794 if (!ret)
51795 ret = -EPIPE;
51796@@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
51797 do_wakeup = 0;
51798 }
51799
51800- pipe->waiting_writers++;
51801+ atomic_inc(&pipe->waiting_writers);
51802 pipe_wait(pipe);
51803- pipe->waiting_writers--;
51804+ atomic_dec(&pipe->waiting_writers);
51805 }
51806
51807 pipe_unlock(pipe);
51808@@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
51809 old_fs = get_fs();
51810 set_fs(get_ds());
51811 /* The cast to a user pointer is valid due to the set_fs() */
51812- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
51813+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
51814 set_fs(old_fs);
51815
51816 return res;
51817@@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
51818 old_fs = get_fs();
51819 set_fs(get_ds());
51820 /* The cast to a user pointer is valid due to the set_fs() */
51821- res = vfs_write(file, (const char __user *)buf, count, &pos);
51822+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
51823 set_fs(old_fs);
51824
51825 return res;
51826@@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
51827 goto err;
51828
51829 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
51830- vec[i].iov_base = (void __user *) page_address(page);
51831+ vec[i].iov_base = (void __force_user *) page_address(page);
51832 vec[i].iov_len = this_len;
51833 spd.pages[i] = page;
51834 spd.nr_pages++;
51835@@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
51836 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
51837 {
51838 while (!pipe->nrbufs) {
51839- if (!pipe->writers)
51840+ if (!atomic_read(&pipe->writers))
51841 return 0;
51842
51843- if (!pipe->waiting_writers && sd->num_spliced)
51844+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
51845 return 0;
51846
51847 if (sd->flags & SPLICE_F_NONBLOCK)
51848@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
51849 * out of the pipe right after the splice_to_pipe(). So set
51850 * PIPE_READERS appropriately.
51851 */
51852- pipe->readers = 1;
51853+ atomic_set(&pipe->readers, 1);
51854
51855 current->splice_pipe = pipe;
51856 }
51857@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51858 ret = -ERESTARTSYS;
51859 break;
51860 }
51861- if (!pipe->writers)
51862+ if (!atomic_read(&pipe->writers))
51863 break;
51864- if (!pipe->waiting_writers) {
51865+ if (!atomic_read(&pipe->waiting_writers)) {
51866 if (flags & SPLICE_F_NONBLOCK) {
51867 ret = -EAGAIN;
51868 break;
51869@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51870 pipe_lock(pipe);
51871
51872 while (pipe->nrbufs >= pipe->buffers) {
51873- if (!pipe->readers) {
51874+ if (!atomic_read(&pipe->readers)) {
51875 send_sig(SIGPIPE, current, 0);
51876 ret = -EPIPE;
51877 break;
51878@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
51879 ret = -ERESTARTSYS;
51880 break;
51881 }
51882- pipe->waiting_writers++;
51883+ atomic_inc(&pipe->waiting_writers);
51884 pipe_wait(pipe);
51885- pipe->waiting_writers--;
51886+ atomic_dec(&pipe->waiting_writers);
51887 }
51888
51889 pipe_unlock(pipe);
51890@@ -1826,14 +1826,14 @@ retry:
51891 pipe_double_lock(ipipe, opipe);
51892
51893 do {
51894- if (!opipe->readers) {
51895+ if (!atomic_read(&opipe->readers)) {
51896 send_sig(SIGPIPE, current, 0);
51897 if (!ret)
51898 ret = -EPIPE;
51899 break;
51900 }
51901
51902- if (!ipipe->nrbufs && !ipipe->writers)
51903+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
51904 break;
51905
51906 /*
51907@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51908 pipe_double_lock(ipipe, opipe);
51909
51910 do {
51911- if (!opipe->readers) {
51912+ if (!atomic_read(&opipe->readers)) {
51913 send_sig(SIGPIPE, current, 0);
51914 if (!ret)
51915 ret = -EPIPE;
51916@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
51917 * return EAGAIN if we have the potential of some data in the
51918 * future, otherwise just return 0
51919 */
51920- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
51921+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
51922 ret = -EAGAIN;
51923
51924 pipe_unlock(ipipe);
51925diff --git a/fs/stat.c b/fs/stat.c
51926index eae4946..6198f55 100644
51927--- a/fs/stat.c
51928+++ b/fs/stat.c
51929@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
51930 stat->gid = inode->i_gid;
51931 stat->rdev = inode->i_rdev;
51932 stat->size = i_size_read(inode);
51933- stat->atime = inode->i_atime;
51934- stat->mtime = inode->i_mtime;
51935+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51936+ stat->atime = inode->i_ctime;
51937+ stat->mtime = inode->i_ctime;
51938+ } else {
51939+ stat->atime = inode->i_atime;
51940+ stat->mtime = inode->i_mtime;
51941+ }
51942 stat->ctime = inode->i_ctime;
51943 stat->blksize = (1 << inode->i_blkbits);
51944 stat->blocks = inode->i_blocks;
51945@@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
51946 if (retval)
51947 return retval;
51948
51949- if (inode->i_op->getattr)
51950- return inode->i_op->getattr(mnt, dentry, stat);
51951+ if (inode->i_op->getattr) {
51952+ retval = inode->i_op->getattr(mnt, dentry, stat);
51953+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
51954+ stat->atime = stat->ctime;
51955+ stat->mtime = stat->ctime;
51956+ }
51957+ return retval;
51958+ }
51959
51960 generic_fillattr(inode, stat);
51961 return 0;
51962diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
51963index 2fbdff6..5530a61 100644
51964--- a/fs/sysfs/dir.c
51965+++ b/fs/sysfs/dir.c
51966@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
51967 struct sysfs_dirent *sd;
51968 int rc;
51969
51970+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
51971+ const char *parent_name = parent_sd->s_name;
51972+
51973+ mode = S_IFDIR | S_IRWXU;
51974+
51975+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
51976+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
51977+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
51978+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
51979+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
51980+#endif
51981+
51982 /* allocate */
51983 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
51984 if (!sd)
51985diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
51986index 00012e3..8392349 100644
51987--- a/fs/sysfs/file.c
51988+++ b/fs/sysfs/file.c
51989@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
51990
51991 struct sysfs_open_dirent {
51992 atomic_t refcnt;
51993- atomic_t event;
51994+ atomic_unchecked_t event;
51995 wait_queue_head_t poll;
51996 struct list_head buffers; /* goes through sysfs_buffer.list */
51997 };
51998@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
51999 if (!sysfs_get_active(attr_sd))
52000 return -ENODEV;
52001
52002- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
52003+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
52004 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
52005
52006 sysfs_put_active(attr_sd);
52007@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
52008 return -ENOMEM;
52009
52010 atomic_set(&new_od->refcnt, 0);
52011- atomic_set(&new_od->event, 1);
52012+ atomic_set_unchecked(&new_od->event, 1);
52013 init_waitqueue_head(&new_od->poll);
52014 INIT_LIST_HEAD(&new_od->buffers);
52015 goto retry;
52016@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
52017
52018 sysfs_put_active(attr_sd);
52019
52020- if (buffer->event != atomic_read(&od->event))
52021+ if (buffer->event != atomic_read_unchecked(&od->event))
52022 goto trigger;
52023
52024 return DEFAULT_POLLMASK;
52025@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
52026
52027 od = sd->s_attr.open;
52028 if (od) {
52029- atomic_inc(&od->event);
52030+ atomic_inc_unchecked(&od->event);
52031 wake_up_interruptible(&od->poll);
52032 }
52033
52034diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
52035index 3c9eb56..9dea5be 100644
52036--- a/fs/sysfs/symlink.c
52037+++ b/fs/sysfs/symlink.c
52038@@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52039
52040 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
52041 {
52042- char *page = nd_get_link(nd);
52043+ const char *page = nd_get_link(nd);
52044 if (!IS_ERR(page))
52045 free_page((unsigned long)page);
52046 }
52047diff --git a/fs/udf/misc.c b/fs/udf/misc.c
52048index c175b4d..8f36a16 100644
52049--- a/fs/udf/misc.c
52050+++ b/fs/udf/misc.c
52051@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
52052
52053 u8 udf_tag_checksum(const struct tag *t)
52054 {
52055- u8 *data = (u8 *)t;
52056+ const u8 *data = (const u8 *)t;
52057 u8 checksum = 0;
52058 int i;
52059 for (i = 0; i < sizeof(struct tag); ++i)
52060diff --git a/fs/utimes.c b/fs/utimes.c
52061index bb0696a..552054b 100644
52062--- a/fs/utimes.c
52063+++ b/fs/utimes.c
52064@@ -1,6 +1,7 @@
52065 #include <linux/compiler.h>
52066 #include <linux/file.h>
52067 #include <linux/fs.h>
52068+#include <linux/security.h>
52069 #include <linux/linkage.h>
52070 #include <linux/mount.h>
52071 #include <linux/namei.h>
52072@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
52073 goto mnt_drop_write_and_out;
52074 }
52075 }
52076+
52077+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
52078+ error = -EACCES;
52079+ goto mnt_drop_write_and_out;
52080+ }
52081+
52082 mutex_lock(&inode->i_mutex);
52083 error = notify_change(path->dentry, &newattrs);
52084 mutex_unlock(&inode->i_mutex);
52085diff --git a/fs/xattr.c b/fs/xattr.c
52086index e21c119..21dfc7c 100644
52087--- a/fs/xattr.c
52088+++ b/fs/xattr.c
52089@@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
52090 * Extended attribute SET operations
52091 */
52092 static long
52093-setxattr(struct dentry *d, const char __user *name, const void __user *value,
52094+setxattr(struct path *path, const char __user *name, const void __user *value,
52095 size_t size, int flags)
52096 {
52097 int error;
52098@@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
52099 posix_acl_fix_xattr_from_user(kvalue, size);
52100 }
52101
52102- error = vfs_setxattr(d, kname, kvalue, size, flags);
52103+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
52104+ error = -EACCES;
52105+ goto out;
52106+ }
52107+
52108+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
52109 out:
52110 if (vvalue)
52111 vfree(vvalue);
52112@@ -376,7 +381,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
52113 return error;
52114 error = mnt_want_write(path.mnt);
52115 if (!error) {
52116- error = setxattr(path.dentry, name, value, size, flags);
52117+ error = setxattr(&path, name, value, size, flags);
52118 mnt_drop_write(path.mnt);
52119 }
52120 path_put(&path);
52121@@ -395,7 +400,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
52122 return error;
52123 error = mnt_want_write(path.mnt);
52124 if (!error) {
52125- error = setxattr(path.dentry, name, value, size, flags);
52126+ error = setxattr(&path, name, value, size, flags);
52127 mnt_drop_write(path.mnt);
52128 }
52129 path_put(&path);
52130@@ -406,16 +411,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
52131 const void __user *,value, size_t, size, int, flags)
52132 {
52133 struct fd f = fdget(fd);
52134- struct dentry *dentry;
52135 int error = -EBADF;
52136
52137 if (!f.file)
52138 return error;
52139- dentry = f.file->f_path.dentry;
52140- audit_inode(NULL, dentry, 0);
52141+ audit_inode(NULL, f.file->f_path.dentry, 0);
52142 error = mnt_want_write_file(f.file);
52143 if (!error) {
52144- error = setxattr(dentry, name, value, size, flags);
52145+ error = setxattr(&f.file->f_path, name, value, size, flags);
52146 mnt_drop_write_file(f.file);
52147 }
52148 fdput(f);
52149diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
52150index 9fbea87..6b19972 100644
52151--- a/fs/xattr_acl.c
52152+++ b/fs/xattr_acl.c
52153@@ -76,8 +76,8 @@ struct posix_acl *
52154 posix_acl_from_xattr(struct user_namespace *user_ns,
52155 const void *value, size_t size)
52156 {
52157- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
52158- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
52159+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
52160+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
52161 int count;
52162 struct posix_acl *acl;
52163 struct posix_acl_entry *acl_e;
52164diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
52165index 83d0cf3..2ef526b 100644
52166--- a/fs/xfs/xfs_bmap.c
52167+++ b/fs/xfs/xfs_bmap.c
52168@@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
52169 int nmap,
52170 int ret_nmap);
52171 #else
52172-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
52173+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
52174 #endif /* DEBUG */
52175
52176 STATIC int
52177diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
52178index 1b9fc3e..e1bdde0 100644
52179--- a/fs/xfs/xfs_dir2_sf.c
52180+++ b/fs/xfs/xfs_dir2_sf.c
52181@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
52182 }
52183
52184 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
52185- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52186+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
52187+ char name[sfep->namelen];
52188+ memcpy(name, sfep->name, sfep->namelen);
52189+ if (filldir(dirent, name, sfep->namelen,
52190+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
52191+ *offset = off & 0x7fffffff;
52192+ return 0;
52193+ }
52194+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
52195 off & 0x7fffffff, ino, DT_UNKNOWN)) {
52196 *offset = off & 0x7fffffff;
52197 return 0;
52198diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
52199index c1df3c6..f987db6 100644
52200--- a/fs/xfs/xfs_ioctl.c
52201+++ b/fs/xfs/xfs_ioctl.c
52202@@ -126,7 +126,7 @@ xfs_find_handle(
52203 }
52204
52205 error = -EFAULT;
52206- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
52207+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
52208 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
52209 goto out_put;
52210
52211diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
52212index 4e00cf0..3374374 100644
52213--- a/fs/xfs/xfs_iops.c
52214+++ b/fs/xfs/xfs_iops.c
52215@@ -394,7 +394,7 @@ xfs_vn_put_link(
52216 struct nameidata *nd,
52217 void *p)
52218 {
52219- char *s = nd_get_link(nd);
52220+ const char *s = nd_get_link(nd);
52221
52222 if (!IS_ERR(s))
52223 kfree(s);
52224diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
52225new file mode 100644
52226index 0000000..5ce8347
52227--- /dev/null
52228+++ b/grsecurity/Kconfig
52229@@ -0,0 +1,1015 @@
52230+#
52231+# grecurity configuration
52232+#
52233+menu "Memory Protections"
52234+depends on GRKERNSEC
52235+
52236+config GRKERNSEC_KMEM
52237+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
52238+ default y if GRKERNSEC_CONFIG_AUTO
52239+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
52240+ help
52241+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
52242+ be written to or read from to modify or leak the contents of the running
52243+ kernel. /dev/port will also not be allowed to be opened. If you have module
52244+ support disabled, enabling this will close up four ways that are
52245+ currently used to insert malicious code into the running kernel.
52246+ Even with all these features enabled, we still highly recommend that
52247+ you use the RBAC system, as it is still possible for an attacker to
52248+ modify the running kernel through privileged I/O granted by ioperm/iopl.
52249+ If you are not using XFree86, you may be able to stop this additional
52250+ case by enabling the 'Disable privileged I/O' option. Though nothing
52251+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
52252+ but only to video memory, which is the only writing we allow in this
52253+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
52254+ not be allowed to mprotect it with PROT_WRITE later.
52255+ It is highly recommended that you say Y here if you meet all the
52256+ conditions above.
52257+
52258+config GRKERNSEC_VM86
52259+ bool "Restrict VM86 mode"
52260+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52261+ depends on X86_32
52262+
52263+ help
52264+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
52265+ make use of a special execution mode on 32bit x86 processors called
52266+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
52267+ video cards and will still work with this option enabled. The purpose
52268+ of the option is to prevent exploitation of emulation errors in
52269+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
52270+ Nearly all users should be able to enable this option.
52271+
52272+config GRKERNSEC_IO
52273+ bool "Disable privileged I/O"
52274+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52275+ depends on X86
52276+ select RTC_CLASS
52277+ select RTC_INTF_DEV
52278+ select RTC_DRV_CMOS
52279+
52280+ help
52281+ If you say Y here, all ioperm and iopl calls will return an error.
52282+ Ioperm and iopl can be used to modify the running kernel.
52283+ Unfortunately, some programs need this access to operate properly,
52284+ the most notable of which are XFree86 and hwclock. hwclock can be
52285+ remedied by having RTC support in the kernel, so real-time
52286+ clock support is enabled if this option is enabled, to ensure
52287+ that hwclock operates correctly. XFree86 still will not
52288+ operate correctly with this option enabled, so DO NOT CHOOSE Y
52289+ IF YOU USE XFree86. If you use XFree86 and you still want to
52290+ protect your kernel against modification, use the RBAC system.
52291+
52292+config GRKERNSEC_JIT_HARDEN
52293+ bool "Harden BPF JIT against spray attacks"
52294+ default y if GRKERNSEC_CONFIG_AUTO
52295+ depends on BPF_JIT
52296+ help
52297+ If you say Y here, the native code generated by the kernel's Berkeley
52298+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
52299+ attacks that attempt to fit attacker-beneficial instructions in
52300+ 32bit immediate fields of JIT-generated native instructions. The
52301+ attacker will generally aim to cause an unintended instruction sequence
52302+ of JIT-generated native code to execute by jumping into the middle of
52303+ a generated instruction. This feature effectively randomizes the 32bit
52304+ immediate constants present in the generated code to thwart such attacks.
52305+
52306+ If you're using KERNEXEC, it's recommended that you enable this option
52307+ to supplement the hardening of the kernel.
52308+
52309+config GRKERNSEC_RAND_THREADSTACK
52310+ bool "Insert random gaps between thread stacks"
52311+ default y if GRKERNSEC_CONFIG_AUTO
52312+ depends on PAX_RANDMMAP && !PPC
52313+ help
52314+ If you say Y here, a random-sized gap will be enforced between allocated
52315+ thread stacks. Glibc's NPTL and other threading libraries that
52316+ pass MAP_STACK to the kernel for thread stack allocation are supported.
52317+ The implementation currently provides 8 bits of entropy for the gap.
52318+
52319+ Many distributions do not compile threaded remote services with the
52320+ -fstack-check argument to GCC, causing the variable-sized stack-based
52321+ allocator, alloca(), to not probe the stack on allocation. This
52322+ permits an unbounded alloca() to skip over any guard page and potentially
52323+ modify another thread's stack reliably. An enforced random gap
52324+ reduces the reliability of such an attack and increases the chance
52325+ that such a read/write to another thread's stack instead lands in
52326+ an unmapped area, causing a crash and triggering grsecurity's
52327+ anti-bruteforcing logic.
52328+
52329+config GRKERNSEC_PROC_MEMMAP
52330+ bool "Harden ASLR against information leaks and entropy reduction"
52331+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
52332+ depends on PAX_NOEXEC || PAX_ASLR
52333+ help
52334+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
52335+ give no information about the addresses of its mappings if
52336+ PaX features that rely on random addresses are enabled on the task.
52337+ In addition to sanitizing this information and disabling other
52338+ dangerous sources of information, this option causes reads of sensitive
52339+ /proc/<pid> entries where the file descriptor was opened in a different
52340+ task than the one performing the read. Such attempts are logged.
52341+ This option also limits argv/env strings for suid/sgid binaries
52342+ to 512KB to prevent a complete exhaustion of the stack entropy provided
52343+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
52344+ binaries to prevent alternative mmap layouts from being abused.
52345+
52346+ If you use PaX it is essential that you say Y here as it closes up
52347+ several holes that make full ASLR useless locally.
52348+
52349+config GRKERNSEC_BRUTE
52350+ bool "Deter exploit bruteforcing"
52351+ default y if GRKERNSEC_CONFIG_AUTO
52352+ help
52353+ If you say Y here, attempts to bruteforce exploits against forking
52354+ daemons such as apache or sshd, as well as against suid/sgid binaries
52355+ will be deterred. When a child of a forking daemon is killed by PaX
52356+ or crashes due to an illegal instruction or other suspicious signal,
52357+ the parent process will be delayed 30 seconds upon every subsequent
52358+ fork until the administrator is able to assess the situation and
52359+ restart the daemon.
52360+ In the suid/sgid case, the attempt is logged, the user has all their
52361+ processes terminated, and they are prevented from executing any further
52362+ processes for 15 minutes.
52363+ It is recommended that you also enable signal logging in the auditing
52364+ section so that logs are generated when a process triggers a suspicious
52365+ signal.
52366+ If the sysctl option is enabled, a sysctl option with name
52367+ "deter_bruteforce" is created.
52368+
52369+
52370+config GRKERNSEC_MODHARDEN
52371+ bool "Harden module auto-loading"
52372+ default y if GRKERNSEC_CONFIG_AUTO
52373+ depends on MODULES
52374+ help
52375+ If you say Y here, module auto-loading in response to use of some
52376+ feature implemented by an unloaded module will be restricted to
52377+ root users. Enabling this option helps defend against attacks
52378+ by unprivileged users who abuse the auto-loading behavior to
52379+ cause a vulnerable module to load that is then exploited.
52380+
52381+ If this option prevents a legitimate use of auto-loading for a
52382+ non-root user, the administrator can execute modprobe manually
52383+ with the exact name of the module mentioned in the alert log.
52384+ Alternatively, the administrator can add the module to the list
52385+ of modules loaded at boot by modifying init scripts.
52386+
52387+ Modification of init scripts will most likely be needed on
52388+ Ubuntu servers with encrypted home directory support enabled,
52389+ as the first non-root user logging in will cause the ecb(aes),
52390+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
52391+
52392+config GRKERNSEC_HIDESYM
52393+ bool "Hide kernel symbols"
52394+ default y if GRKERNSEC_CONFIG_AUTO
52395+ select PAX_USERCOPY_SLABS
52396+ help
52397+ If you say Y here, getting information on loaded modules, and
52398+ displaying all kernel symbols through a syscall will be restricted
52399+ to users with CAP_SYS_MODULE. For software compatibility reasons,
52400+ /proc/kallsyms will be restricted to the root user. The RBAC
52401+ system can hide that entry even from root.
52402+
52403+ This option also prevents leaking of kernel addresses through
52404+ several /proc entries.
52405+
52406+ Note that this option is only effective provided the following
52407+ conditions are met:
52408+ 1) The kernel using grsecurity is not precompiled by some distribution
52409+ 2) You have also enabled GRKERNSEC_DMESG
52410+ 3) You are using the RBAC system and hiding other files such as your
52411+ kernel image and System.map. Alternatively, enabling this option
52412+ causes the permissions on /boot, /lib/modules, and the kernel
52413+ source directory to change at compile time to prevent
52414+ reading by non-root users.
52415+ If the above conditions are met, this option will aid in providing a
52416+ useful protection against local kernel exploitation of overflows
52417+ and arbitrary read/write vulnerabilities.
52418+
52419+config GRKERNSEC_KERN_LOCKOUT
52420+ bool "Active kernel exploit response"
52421+ default y if GRKERNSEC_CONFIG_AUTO
52422+ depends on X86 || ARM || PPC || SPARC
52423+ help
52424+ If you say Y here, when a PaX alert is triggered due to suspicious
52425+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
52426+ or an OOPS occurs due to bad memory accesses, instead of just
52427+ terminating the offending process (and potentially allowing
52428+ a subsequent exploit from the same user), we will take one of two
52429+ actions:
52430+ If the user was root, we will panic the system
52431+ If the user was non-root, we will log the attempt, terminate
52432+ all processes owned by the user, then prevent them from creating
52433+ any new processes until the system is restarted
52434+ This deters repeated kernel exploitation/bruteforcing attempts
52435+ and is useful for later forensics.
52436+
52437+endmenu
52438+menu "Role Based Access Control Options"
52439+depends on GRKERNSEC
52440+
52441+config GRKERNSEC_RBAC_DEBUG
52442+ bool
52443+
52444+config GRKERNSEC_NO_RBAC
52445+ bool "Disable RBAC system"
52446+ help
52447+ If you say Y here, the /dev/grsec device will be removed from the kernel,
52448+ preventing the RBAC system from being enabled. You should only say Y
52449+ here if you have no intention of using the RBAC system, so as to prevent
52450+ an attacker with root access from misusing the RBAC system to hide files
52451+ and processes when loadable module support and /dev/[k]mem have been
52452+ locked down.
52453+
52454+config GRKERNSEC_ACL_HIDEKERN
52455+ bool "Hide kernel processes"
52456+ help
52457+ If you say Y here, all kernel threads will be hidden to all
52458+ processes but those whose subject has the "view hidden processes"
52459+ flag.
52460+
52461+config GRKERNSEC_ACL_MAXTRIES
52462+ int "Maximum tries before password lockout"
52463+ default 3
52464+ help
52465+ This option enforces the maximum number of times a user can attempt
52466+ to authorize themselves with the grsecurity RBAC system before being
52467+ denied the ability to attempt authorization again for a specified time.
52468+ The lower the number, the harder it will be to brute-force a password.
52469+
52470+config GRKERNSEC_ACL_TIMEOUT
52471+ int "Time to wait after max password tries, in seconds"
52472+ default 30
52473+ help
52474+ This option specifies the time the user must wait after attempting to
52475+ authorize to the RBAC system with the maximum number of invalid
52476+ passwords. The higher the number, the harder it will be to brute-force
52477+ a password.
52478+
52479+endmenu
52480+menu "Filesystem Protections"
52481+depends on GRKERNSEC
52482+
52483+config GRKERNSEC_PROC
52484+ bool "Proc restrictions"
52485+ default y if GRKERNSEC_CONFIG_AUTO
52486+ help
52487+ If you say Y here, the permissions of the /proc filesystem
52488+ will be altered to enhance system security and privacy. You MUST
52489+ choose either a user only restriction or a user and group restriction.
52490+ Depending upon the option you choose, you can either restrict users to
52491+ see only the processes they themselves run, or choose a group that can
52492+ view all processes and files normally restricted to root if you choose
52493+ the "restrict to user only" option. NOTE: If you're running identd or
52494+ ntpd as a non-root user, you will have to run it as the group you
52495+ specify here.
52496+
52497+config GRKERNSEC_PROC_USER
52498+ bool "Restrict /proc to user only"
52499+ depends on GRKERNSEC_PROC
52500+ help
52501+ If you say Y here, non-root users will only be able to view their own
52502+ processes, and restricts them from viewing network-related information,
52503+ and viewing kernel symbol and module information.
52504+
52505+config GRKERNSEC_PROC_USERGROUP
52506+ bool "Allow special group"
52507+ default y if GRKERNSEC_CONFIG_AUTO
52508+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
52509+ help
52510+ If you say Y here, you will be able to select a group that will be
52511+ able to view all processes and network-related information. If you've
52512+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
52513+ remain hidden. This option is useful if you want to run identd as
52514+ a non-root user. The group you select may also be chosen at boot time
52515+ via "grsec_proc_gid=" on the kernel commandline.
52516+
52517+config GRKERNSEC_PROC_GID
52518+ int "GID for special group"
52519+ depends on GRKERNSEC_PROC_USERGROUP
52520+ default 1001
52521+
52522+config GRKERNSEC_PROC_ADD
52523+ bool "Additional restrictions"
52524+ default y if GRKERNSEC_CONFIG_AUTO
52525+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
52526+ help
52527+ If you say Y here, additional restrictions will be placed on
52528+ /proc that keep normal users from viewing device information and
52529+ slabinfo information that could be useful for exploits.
52530+
52531+config GRKERNSEC_LINK
52532+ bool "Linking restrictions"
52533+ default y if GRKERNSEC_CONFIG_AUTO
52534+ help
52535+ If you say Y here, /tmp race exploits will be prevented, since users
52536+ will no longer be able to follow symlinks owned by other users in
52537+ world-writable +t directories (e.g. /tmp), unless the owner of the
52538+ symlink is the owner of the directory. users will also not be
52539+ able to hardlink to files they do not own. If the sysctl option is
52540+ enabled, a sysctl option with name "linking_restrictions" is created.
52541+
52542+config GRKERNSEC_SYMLINKOWN
52543+ bool "Kernel-enforced SymlinksIfOwnerMatch"
52544+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52545+ help
52546+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
52547+ that prevents it from being used as a security feature. As Apache
52548+ verifies the symlink by performing a stat() against the target of
52549+ the symlink before it is followed, an attacker can setup a symlink
52550+ to point to a same-owned file, then replace the symlink with one
52551+ that targets another user's file just after Apache "validates" the
52552+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
52553+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
52554+ will be in place for the group you specify. If the sysctl option
52555+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
52556+ created.
52557+
52558+config GRKERNSEC_SYMLINKOWN_GID
52559+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
52560+ depends on GRKERNSEC_SYMLINKOWN
52561+ default 1006
52562+ help
52563+ Setting this GID determines what group kernel-enforced
52564+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
52565+ is enabled, a sysctl option with name "symlinkown_gid" is created.
52566+
52567+config GRKERNSEC_FIFO
52568+ bool "FIFO restrictions"
52569+ default y if GRKERNSEC_CONFIG_AUTO
52570+ help
52571+ If you say Y here, users will not be able to write to FIFOs they don't
52572+ own in world-writable +t directories (e.g. /tmp), unless the owner of
52573+ the FIFO is the same owner of the directory it's held in. If the sysctl
52574+ option is enabled, a sysctl option with name "fifo_restrictions" is
52575+ created.
52576+
52577+config GRKERNSEC_SYSFS_RESTRICT
52578+ bool "Sysfs/debugfs restriction"
52579+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
52580+ depends on SYSFS
52581+ help
52582+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
52583+ any filesystem normally mounted under it (e.g. debugfs) will be
52584+ mostly accessible only by root. These filesystems generally provide access
52585+ to hardware and debug information that isn't appropriate for unprivileged
52586+ users of the system. Sysfs and debugfs have also become a large source
52587+ of new vulnerabilities, ranging from infoleaks to local compromise.
52588+ There has been very little oversight with an eye toward security involved
52589+ in adding new exporters of information to these filesystems, so their
52590+ use is discouraged.
52591+ For reasons of compatibility, a few directories have been whitelisted
52592+ for access by non-root users:
52593+ /sys/fs/selinux
52594+ /sys/fs/fuse
52595+ /sys/devices/system/cpu
52596+
52597+config GRKERNSEC_ROFS
52598+ bool "Runtime read-only mount protection"
52599+ help
52600+ If you say Y here, a sysctl option with name "romount_protect" will
52601+ be created. By setting this option to 1 at runtime, filesystems
52602+ will be protected in the following ways:
52603+ * No new writable mounts will be allowed
52604+ * Existing read-only mounts won't be able to be remounted read/write
52605+ * Write operations will be denied on all block devices
52606+ This option acts independently of grsec_lock: once it is set to 1,
52607+ it cannot be turned off. Therefore, please be mindful of the resulting
52608+ behavior if this option is enabled in an init script on a read-only
52609+ filesystem. This feature is mainly intended for secure embedded systems.
52610+
52611+config GRKERNSEC_DEVICE_SIDECHANNEL
52612+ bool "Eliminate stat/notify-based device sidechannels"
52613+ default y if GRKERNSEC_CONFIG_AUTO
52614+ help
52615+ If you say Y here, timing analyses on block or character
52616+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
52617+ will be thwarted for unprivileged users. If a process without
52618+ CAP_MKNOD stats such a device, the last access and last modify times
52619+ will match the device's create time. No access or modify events
52620+ will be triggered through inotify/dnotify/fanotify for such devices.
52621+ This feature will prevent attacks that may at a minimum
52622+ allow an attacker to determine the administrator's password length.
52623+
52624+config GRKERNSEC_CHROOT
52625+ bool "Chroot jail restrictions"
52626+ default y if GRKERNSEC_CONFIG_AUTO
52627+ help
52628+ If you say Y here, you will be able to choose several options that will
52629+ make breaking out of a chrooted jail much more difficult. If you
52630+ encounter no software incompatibilities with the following options, it
52631+ is recommended that you enable each one.
52632+
52633+config GRKERNSEC_CHROOT_MOUNT
52634+ bool "Deny mounts"
52635+ default y if GRKERNSEC_CONFIG_AUTO
52636+ depends on GRKERNSEC_CHROOT
52637+ help
52638+ If you say Y here, processes inside a chroot will not be able to
52639+ mount or remount filesystems. If the sysctl option is enabled, a
52640+ sysctl option with name "chroot_deny_mount" is created.
52641+
52642+config GRKERNSEC_CHROOT_DOUBLE
52643+ bool "Deny double-chroots"
52644+ default y if GRKERNSEC_CONFIG_AUTO
52645+ depends on GRKERNSEC_CHROOT
52646+ help
52647+ If you say Y here, processes inside a chroot will not be able to chroot
52648+ again outside the chroot. This is a widely used method of breaking
52649+ out of a chroot jail and should not be allowed. If the sysctl
52650+ option is enabled, a sysctl option with name
52651+ "chroot_deny_chroot" is created.
52652+
52653+config GRKERNSEC_CHROOT_PIVOT
52654+ bool "Deny pivot_root in chroot"
52655+ default y if GRKERNSEC_CONFIG_AUTO
52656+ depends on GRKERNSEC_CHROOT
52657+ help
52658+ If you say Y here, processes inside a chroot will not be able to use
52659+ a function called pivot_root() that was introduced in Linux 2.3.41. It
52660+ works similar to chroot in that it changes the root filesystem. This
52661+ function could be misused in a chrooted process to attempt to break out
52662+ of the chroot, and therefore should not be allowed. If the sysctl
52663+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
52664+ created.
52665+
52666+config GRKERNSEC_CHROOT_CHDIR
52667+ bool "Enforce chdir(\"/\") on all chroots"
52668+ default y if GRKERNSEC_CONFIG_AUTO
52669+ depends on GRKERNSEC_CHROOT
52670+ help
52671+ If you say Y here, the current working directory of all newly-chrooted
52672+ applications will be set to the the root directory of the chroot.
52673+ The man page on chroot(2) states:
52674+ Note that this call does not change the current working
52675+ directory, so that `.' can be outside the tree rooted at
52676+ `/'. In particular, the super-user can escape from a
52677+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
52678+
52679+ It is recommended that you say Y here, since it's not known to break
52680+ any software. If the sysctl option is enabled, a sysctl option with
52681+ name "chroot_enforce_chdir" is created.
52682+
52683+config GRKERNSEC_CHROOT_CHMOD
52684+ bool "Deny (f)chmod +s"
52685+ default y if GRKERNSEC_CONFIG_AUTO
52686+ depends on GRKERNSEC_CHROOT
52687+ help
52688+ If you say Y here, processes inside a chroot will not be able to chmod
52689+ or fchmod files to make them have suid or sgid bits. This protects
52690+ against another published method of breaking a chroot. If the sysctl
52691+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
52692+ created.
52693+
52694+config GRKERNSEC_CHROOT_FCHDIR
52695+ bool "Deny fchdir out of chroot"
52696+ default y if GRKERNSEC_CONFIG_AUTO
52697+ depends on GRKERNSEC_CHROOT
52698+ help
52699+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
52700+ to a file descriptor of the chrooting process that points to a directory
52701+ outside the filesystem will be stopped. If the sysctl option
52702+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
52703+
52704+config GRKERNSEC_CHROOT_MKNOD
52705+ bool "Deny mknod"
52706+ default y if GRKERNSEC_CONFIG_AUTO
52707+ depends on GRKERNSEC_CHROOT
52708+ help
52709+ If you say Y here, processes inside a chroot will not be allowed to
52710+ mknod. The problem with using mknod inside a chroot is that it
52711+ would allow an attacker to create a device entry that is the same
52712+ as one on the physical root of your system, which could range from
52713+ anything from the console device to a device for your harddrive (which
52714+ they could then use to wipe the drive or steal data). It is recommended
52715+ that you say Y here, unless you run into software incompatibilities.
52716+ If the sysctl option is enabled, a sysctl option with name
52717+ "chroot_deny_mknod" is created.
52718+
52719+config GRKERNSEC_CHROOT_SHMAT
52720+ bool "Deny shmat() out of chroot"
52721+ default y if GRKERNSEC_CONFIG_AUTO
52722+ depends on GRKERNSEC_CHROOT
52723+ help
52724+ If you say Y here, processes inside a chroot will not be able to attach
52725+ to shared memory segments that were created outside of the chroot jail.
52726+ It is recommended that you say Y here. If the sysctl option is enabled,
52727+ a sysctl option with name "chroot_deny_shmat" is created.
52728+
52729+config GRKERNSEC_CHROOT_UNIX
52730+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
52731+ default y if GRKERNSEC_CONFIG_AUTO
52732+ depends on GRKERNSEC_CHROOT
52733+ help
52734+ If you say Y here, processes inside a chroot will not be able to
52735+ connect to abstract (meaning not belonging to a filesystem) Unix
52736+ domain sockets that were bound outside of a chroot. It is recommended
52737+ that you say Y here. If the sysctl option is enabled, a sysctl option
52738+ with name "chroot_deny_unix" is created.
52739+
52740+config GRKERNSEC_CHROOT_FINDTASK
52741+ bool "Protect outside processes"
52742+ default y if GRKERNSEC_CONFIG_AUTO
52743+ depends on GRKERNSEC_CHROOT
52744+ help
52745+ If you say Y here, processes inside a chroot will not be able to
52746+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
52747+ getsid, or view any process outside of the chroot. If the sysctl
52748+ option is enabled, a sysctl option with name "chroot_findtask" is
52749+ created.
52750+
52751+config GRKERNSEC_CHROOT_NICE
52752+ bool "Restrict priority changes"
52753+ default y if GRKERNSEC_CONFIG_AUTO
52754+ depends on GRKERNSEC_CHROOT
52755+ help
52756+ If you say Y here, processes inside a chroot will not be able to raise
52757+ the priority of processes in the chroot, or alter the priority of
52758+ processes outside the chroot. This provides more security than simply
52759+ removing CAP_SYS_NICE from the process' capability set. If the
52760+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
52761+ is created.
52762+
52763+config GRKERNSEC_CHROOT_SYSCTL
52764+ bool "Deny sysctl writes"
52765+ default y if GRKERNSEC_CONFIG_AUTO
52766+ depends on GRKERNSEC_CHROOT
52767+ help
52768+ If you say Y here, an attacker in a chroot will not be able to
52769+ write to sysctl entries, either by sysctl(2) or through a /proc
52770+ interface. It is strongly recommended that you say Y here. If the
52771+ sysctl option is enabled, a sysctl option with name
52772+ "chroot_deny_sysctl" is created.
52773+
52774+config GRKERNSEC_CHROOT_CAPS
52775+ bool "Capability restrictions"
52776+ default y if GRKERNSEC_CONFIG_AUTO
52777+ depends on GRKERNSEC_CHROOT
52778+ help
52779+ If you say Y here, the capabilities on all processes within a
52780+ chroot jail will be lowered to stop module insertion, raw i/o,
52781+ system and net admin tasks, rebooting the system, modifying immutable
52782+ files, modifying IPC owned by another, and changing the system time.
52783+ This is left an option because it can break some apps. Disable this
52784+ if your chrooted apps are having problems performing those kinds of
52785+ tasks. If the sysctl option is enabled, a sysctl option with
52786+ name "chroot_caps" is created.
52787+
52788+endmenu
52789+menu "Kernel Auditing"
52790+depends on GRKERNSEC
52791+
52792+config GRKERNSEC_AUDIT_GROUP
52793+ bool "Single group for auditing"
52794+ help
52795+ If you say Y here, the exec, chdir, and (un)mount logging features
52796+ will only operate on a group you specify. This option is recommended
52797+ if you only want to watch certain users instead of having a large
52798+ amount of logs from the entire system. If the sysctl option is enabled,
52799+ a sysctl option with name "audit_group" is created.
52800+
52801+config GRKERNSEC_AUDIT_GID
52802+ int "GID for auditing"
52803+ depends on GRKERNSEC_AUDIT_GROUP
52804+ default 1007
52805+
52806+config GRKERNSEC_EXECLOG
52807+ bool "Exec logging"
52808+ help
52809+ If you say Y here, all execve() calls will be logged (since the
52810+ other exec*() calls are frontends to execve(), all execution
52811+ will be logged). Useful for shell-servers that like to keep track
52812+ of their users. If the sysctl option is enabled, a sysctl option with
52813+ name "exec_logging" is created.
52814+ WARNING: This option when enabled will produce a LOT of logs, especially
52815+ on an active system.
52816+
52817+config GRKERNSEC_RESLOG
52818+ bool "Resource logging"
52819+ default y if GRKERNSEC_CONFIG_AUTO
52820+ help
52821+ If you say Y here, all attempts to overstep resource limits will
52822+ be logged with the resource name, the requested size, and the current
52823+ limit. It is highly recommended that you say Y here. If the sysctl
52824+ option is enabled, a sysctl option with name "resource_logging" is
52825+ created. If the RBAC system is enabled, the sysctl value is ignored.
52826+
52827+config GRKERNSEC_CHROOT_EXECLOG
52828+ bool "Log execs within chroot"
52829+ help
52830+ If you say Y here, all executions inside a chroot jail will be logged
52831+ to syslog. This can cause a large amount of logs if certain
52832+ applications (eg. djb's daemontools) are installed on the system, and
52833+ is therefore left as an option. If the sysctl option is enabled, a
52834+ sysctl option with name "chroot_execlog" is created.
52835+
52836+config GRKERNSEC_AUDIT_PTRACE
52837+ bool "Ptrace logging"
52838+ help
52839+ If you say Y here, all attempts to attach to a process via ptrace
52840+ will be logged. If the sysctl option is enabled, a sysctl option
52841+ with name "audit_ptrace" is created.
52842+
52843+config GRKERNSEC_AUDIT_CHDIR
52844+ bool "Chdir logging"
52845+ help
52846+ If you say Y here, all chdir() calls will be logged. If the sysctl
52847+ option is enabled, a sysctl option with name "audit_chdir" is created.
52848+
52849+config GRKERNSEC_AUDIT_MOUNT
52850+ bool "(Un)Mount logging"
52851+ help
52852+ If you say Y here, all mounts and unmounts will be logged. If the
52853+ sysctl option is enabled, a sysctl option with name "audit_mount" is
52854+ created.
52855+
52856+config GRKERNSEC_SIGNAL
52857+ bool "Signal logging"
52858+ default y if GRKERNSEC_CONFIG_AUTO
52859+ help
52860+ If you say Y here, certain important signals will be logged, such as
52861+ SIGSEGV, which will as a result inform you of when a error in a program
52862+ occurred, which in some cases could mean a possible exploit attempt.
52863+ If the sysctl option is enabled, a sysctl option with name
52864+ "signal_logging" is created.
52865+
52866+config GRKERNSEC_FORKFAIL
52867+ bool "Fork failure logging"
52868+ help
52869+ If you say Y here, all failed fork() attempts will be logged.
52870+ This could suggest a fork bomb, or someone attempting to overstep
52871+ their process limit. If the sysctl option is enabled, a sysctl option
52872+ with name "forkfail_logging" is created.
52873+
52874+config GRKERNSEC_TIME
52875+ bool "Time change logging"
52876+ default y if GRKERNSEC_CONFIG_AUTO
52877+ help
52878+ If you say Y here, any changes of the system clock will be logged.
52879+ If the sysctl option is enabled, a sysctl option with name
52880+ "timechange_logging" is created.
52881+
52882+config GRKERNSEC_PROC_IPADDR
52883+ bool "/proc/<pid>/ipaddr support"
52884+ default y if GRKERNSEC_CONFIG_AUTO
52885+ help
52886+ If you say Y here, a new entry will be added to each /proc/<pid>
52887+ directory that contains the IP address of the person using the task.
52888+ The IP is carried across local TCP and AF_UNIX stream sockets.
52889+ This information can be useful for IDS/IPSes to perform remote response
52890+ to a local attack. The entry is readable by only the owner of the
52891+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
52892+ the RBAC system), and thus does not create privacy concerns.
52893+
52894+config GRKERNSEC_RWXMAP_LOG
52895+ bool 'Denied RWX mmap/mprotect logging'
52896+ default y if GRKERNSEC_CONFIG_AUTO
52897+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
52898+ help
52899+ If you say Y here, calls to mmap() and mprotect() with explicit
52900+ usage of PROT_WRITE and PROT_EXEC together will be logged when
52901+ denied by the PAX_MPROTECT feature. If the sysctl option is
52902+ enabled, a sysctl option with name "rwxmap_logging" is created.
52903+
52904+config GRKERNSEC_AUDIT_TEXTREL
52905+ bool 'ELF text relocations logging (READ HELP)'
52906+ depends on PAX_MPROTECT
52907+ help
52908+ If you say Y here, text relocations will be logged with the filename
52909+ of the offending library or binary. The purpose of the feature is
52910+ to help Linux distribution developers get rid of libraries and
52911+ binaries that need text relocations which hinder the future progress
52912+ of PaX. Only Linux distribution developers should say Y here, and
52913+ never on a production machine, as this option creates an information
52914+ leak that could aid an attacker in defeating the randomization of
52915+ a single memory region. If the sysctl option is enabled, a sysctl
52916+ option with name "audit_textrel" is created.
52917+
52918+endmenu
52919+
52920+menu "Executable Protections"
52921+depends on GRKERNSEC
52922+
52923+config GRKERNSEC_DMESG
52924+ bool "Dmesg(8) restriction"
52925+ default y if GRKERNSEC_CONFIG_AUTO
52926+ help
52927+ If you say Y here, non-root users will not be able to use dmesg(8)
52928+ to view the contents of the kernel's circular log buffer.
52929+ The kernel's log buffer often contains kernel addresses and other
52930+ identifying information useful to an attacker in fingerprinting a
52931+ system for a targeted exploit.
52932+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
52933+ created.
52934+
52935+config GRKERNSEC_HARDEN_PTRACE
52936+ bool "Deter ptrace-based process snooping"
52937+ default y if GRKERNSEC_CONFIG_AUTO
52938+ help
52939+ If you say Y here, TTY sniffers and other malicious monitoring
52940+ programs implemented through ptrace will be defeated. If you
52941+ have been using the RBAC system, this option has already been
52942+ enabled for several years for all users, with the ability to make
52943+ fine-grained exceptions.
52944+
52945+ This option only affects the ability of non-root users to ptrace
52946+ processes that are not a descendent of the ptracing process.
52947+ This means that strace ./binary and gdb ./binary will still work,
52948+ but attaching to arbitrary processes will not. If the sysctl
52949+ option is enabled, a sysctl option with name "harden_ptrace" is
52950+ created.
52951+
52952+config GRKERNSEC_PTRACE_READEXEC
52953+ bool "Require read access to ptrace sensitive binaries"
52954+ default y if GRKERNSEC_CONFIG_AUTO
52955+ help
52956+ If you say Y here, unprivileged users will not be able to ptrace unreadable
52957+ binaries. This option is useful in environments that
52958+ remove the read bits (e.g. file mode 4711) from suid binaries to
52959+ prevent infoleaking of their contents. This option adds
52960+ consistency to the use of that file mode, as the binary could normally
52961+ be read out when run without privileges while ptracing.
52962+
52963+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
52964+ is created.
52965+
52966+config GRKERNSEC_SETXID
52967+ bool "Enforce consistent multithreaded privileges"
52968+ default y if GRKERNSEC_CONFIG_AUTO
52969+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
52970+ help
52971+ If you say Y here, a change from a root uid to a non-root uid
52972+ in a multithreaded application will cause the resulting uids,
52973+ gids, supplementary groups, and capabilities in that thread
52974+ to be propagated to the other threads of the process. In most
52975+ cases this is unnecessary, as glibc will emulate this behavior
52976+ on behalf of the application. Other libcs do not act in the
52977+ same way, allowing the other threads of the process to continue
52978+ running with root privileges. If the sysctl option is enabled,
52979+ a sysctl option with name "consistent_setxid" is created.
52980+
52981+config GRKERNSEC_TPE
52982+ bool "Trusted Path Execution (TPE)"
52983+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
52984+ help
52985+ If you say Y here, you will be able to choose a gid to add to the
52986+ supplementary groups of users you want to mark as "untrusted."
52987+ These users will not be able to execute any files that are not in
52988+ root-owned directories writable only by root. If the sysctl option
52989+ is enabled, a sysctl option with name "tpe" is created.
52990+
52991+config GRKERNSEC_TPE_ALL
52992+ bool "Partially restrict all non-root users"
52993+ depends on GRKERNSEC_TPE
52994+ help
52995+ If you say Y here, all non-root users will be covered under
52996+ a weaker TPE restriction. This is separate from, and in addition to,
52997+ the main TPE options that you have selected elsewhere. Thus, if a
52998+ "trusted" GID is chosen, this restriction applies to even that GID.
52999+ Under this restriction, all non-root users will only be allowed to
53000+ execute files in directories they own that are not group or
53001+ world-writable, or in directories owned by root and writable only by
53002+ root. If the sysctl option is enabled, a sysctl option with name
53003+ "tpe_restrict_all" is created.
53004+
53005+config GRKERNSEC_TPE_INVERT
53006+ bool "Invert GID option"
53007+ depends on GRKERNSEC_TPE
53008+ help
53009+ If you say Y here, the group you specify in the TPE configuration will
53010+ decide what group TPE restrictions will be *disabled* for. This
53011+ option is useful if you want TPE restrictions to be applied to most
53012+ users on the system. If the sysctl option is enabled, a sysctl option
53013+ with name "tpe_invert" is created. Unlike other sysctl options, this
53014+ entry will default to on for backward-compatibility.
53015+
53016+config GRKERNSEC_TPE_GID
53017+ int
53018+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
53019+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
53020+
53021+config GRKERNSEC_TPE_UNTRUSTED_GID
53022+ int "GID for TPE-untrusted users"
53023+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
53024+ default 1005
53025+ help
53026+ Setting this GID determines what group TPE restrictions will be
53027+ *enabled* for. If the sysctl option is enabled, a sysctl option
53028+ with name "tpe_gid" is created.
53029+
53030+config GRKERNSEC_TPE_TRUSTED_GID
53031+ int "GID for TPE-trusted users"
53032+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
53033+ default 1005
53034+ help
53035+ Setting this GID determines what group TPE restrictions will be
53036+ *disabled* for. If the sysctl option is enabled, a sysctl option
53037+ with name "tpe_gid" is created.
53038+
53039+endmenu
53040+menu "Network Protections"
53041+depends on GRKERNSEC
53042+
53043+config GRKERNSEC_RANDNET
53044+ bool "Larger entropy pools"
53045+ default y if GRKERNSEC_CONFIG_AUTO
53046+ help
53047+ If you say Y here, the entropy pools used for many features of Linux
53048+ and grsecurity will be doubled in size. Since several grsecurity
53049+ features use additional randomness, it is recommended that you say Y
53050+ here. Saying Y here has a similar effect as modifying
53051+ /proc/sys/kernel/random/poolsize.
53052+
53053+config GRKERNSEC_BLACKHOLE
53054+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
53055+ default y if GRKERNSEC_CONFIG_AUTO
53056+ depends on NET
53057+ help
53058+ If you say Y here, neither TCP resets nor ICMP
53059+ destination-unreachable packets will be sent in response to packets
53060+ sent to ports for which no associated listening process exists.
53061+ This feature supports both IPV4 and IPV6 and exempts the
53062+ loopback interface from blackholing. Enabling this feature
53063+ makes a host more resilient to DoS attacks and reduces network
53064+ visibility against scanners.
53065+
53066+ The blackhole feature as-implemented is equivalent to the FreeBSD
53067+ blackhole feature, as it prevents RST responses to all packets, not
53068+ just SYNs. Under most application behavior this causes no
53069+ problems, but applications (like haproxy) may not close certain
53070+ connections in a way that cleanly terminates them on the remote
53071+ end, leaving the remote host in LAST_ACK state. Because of this
53072+ side-effect and to prevent intentional LAST_ACK DoSes, this
53073+ feature also adds automatic mitigation against such attacks.
53074+ The mitigation drastically reduces the amount of time a socket
53075+ can spend in LAST_ACK state. If you're using haproxy and not
53076+ all servers it connects to have this option enabled, consider
53077+ disabling this feature on the haproxy host.
53078+
53079+ If the sysctl option is enabled, two sysctl options with names
53080+ "ip_blackhole" and "lastack_retries" will be created.
53081+ While "ip_blackhole" takes the standard zero/non-zero on/off
53082+ toggle, "lastack_retries" uses the same kinds of values as
53083+ "tcp_retries1" and "tcp_retries2". The default value of 4
53084+ prevents a socket from lasting more than 45 seconds in LAST_ACK
53085+ state.
53086+
53087+config GRKERNSEC_NO_SIMULT_CONNECT
53088+ bool "Disable TCP Simultaneous Connect"
53089+ default y if GRKERNSEC_CONFIG_AUTO
53090+ depends on NET
53091+ help
53092+ If you say Y here, a feature by Willy Tarreau will be enabled that
53093+ removes a weakness in Linux's strict implementation of TCP that
53094+ allows two clients to connect to each other without either entering
53095+ a listening state. The weakness allows an attacker to easily prevent
53096+ a client from connecting to a known server provided the source port
53097+ for the connection is guessed correctly.
53098+
53099+ As the weakness could be used to prevent an antivirus or IPS from
53100+ fetching updates, or prevent an SSL gateway from fetching a CRL,
53101+ it should be eliminated by enabling this option. Though Linux is
53102+ one of few operating systems supporting simultaneous connect, it
53103+ has no legitimate use in practice and is rarely supported by firewalls.
53104+
53105+config GRKERNSEC_SOCKET
53106+ bool "Socket restrictions"
53107+ depends on NET
53108+ help
53109+ If you say Y here, you will be able to choose from several options.
53110+ If you assign a GID on your system and add it to the supplementary
53111+ groups of users you want to restrict socket access to, this patch
53112+ will perform up to three things, based on the option(s) you choose.
53113+
53114+config GRKERNSEC_SOCKET_ALL
53115+ bool "Deny any sockets to group"
53116+ depends on GRKERNSEC_SOCKET
53117+ help
53118+ If you say Y here, you will be able to choose a GID of whose users will
53119+ be unable to connect to other hosts from your machine or run server
53120+ applications from your machine. If the sysctl option is enabled, a
53121+ sysctl option with name "socket_all" is created.
53122+
53123+config GRKERNSEC_SOCKET_ALL_GID
53124+ int "GID to deny all sockets for"
53125+ depends on GRKERNSEC_SOCKET_ALL
53126+ default 1004
53127+ help
53128+ Here you can choose the GID to disable socket access for. Remember to
53129+ add the users you want socket access disabled for to the GID
53130+ specified here. If the sysctl option is enabled, a sysctl option
53131+ with name "socket_all_gid" is created.
53132+
53133+config GRKERNSEC_SOCKET_CLIENT
53134+ bool "Deny client sockets to group"
53135+ depends on GRKERNSEC_SOCKET
53136+ help
53137+ If you say Y here, you will be able to choose a GID of whose users will
53138+ be unable to connect to other hosts from your machine, but will be
53139+ able to run servers. If this option is enabled, all users in the group
53140+ you specify will have to use passive mode when initiating ftp transfers
53141+ from the shell on your machine. If the sysctl option is enabled, a
53142+ sysctl option with name "socket_client" is created.
53143+
53144+config GRKERNSEC_SOCKET_CLIENT_GID
53145+ int "GID to deny client sockets for"
53146+ depends on GRKERNSEC_SOCKET_CLIENT
53147+ default 1003
53148+ help
53149+ Here you can choose the GID to disable client socket access for.
53150+ Remember to add the users you want client socket access disabled for to
53151+ the GID specified here. If the sysctl option is enabled, a sysctl
53152+ option with name "socket_client_gid" is created.
53153+
53154+config GRKERNSEC_SOCKET_SERVER
53155+ bool "Deny server sockets to group"
53156+ depends on GRKERNSEC_SOCKET
53157+ help
53158+ If you say Y here, you will be able to choose a GID of whose users will
53159+ be unable to run server applications from your machine. If the sysctl
53160+ option is enabled, a sysctl option with name "socket_server" is created.
53161+
53162+config GRKERNSEC_SOCKET_SERVER_GID
53163+ int "GID to deny server sockets for"
53164+ depends on GRKERNSEC_SOCKET_SERVER
53165+ default 1002
53166+ help
53167+ Here you can choose the GID to disable server socket access for.
53168+ Remember to add the users you want server socket access disabled for to
53169+ the GID specified here. If the sysctl option is enabled, a sysctl
53170+ option with name "socket_server_gid" is created.
53171+
53172+endmenu
53173+menu "Sysctl Support"
53174+depends on GRKERNSEC && SYSCTL
53175+
53176+config GRKERNSEC_SYSCTL
53177+ bool "Sysctl support"
53178+ default y if GRKERNSEC_CONFIG_AUTO
53179+ help
53180+ If you say Y here, you will be able to change the options that
53181+ grsecurity runs with at bootup, without having to recompile your
53182+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
53183+ to enable (1) or disable (0) various features. All the sysctl entries
53184+ are mutable until the "grsec_lock" entry is set to a non-zero value.
53185+ All features enabled in the kernel configuration are disabled at boot
53186+ if you do not say Y to the "Turn on features by default" option.
53187+ All options should be set at startup, and the grsec_lock entry should
53188+ be set to a non-zero value after all the options are set.
53189+ *THIS IS EXTREMELY IMPORTANT*
53190+
53191+config GRKERNSEC_SYSCTL_DISTRO
53192+ bool "Extra sysctl support for distro makers (READ HELP)"
53193+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
53194+ help
53195+ If you say Y here, additional sysctl options will be created
53196+ for features that affect processes running as root. Therefore,
53197+ it is critical when using this option that the grsec_lock entry be
53198+ enabled after boot. Only distros with prebuilt kernel packages
53199+ with this option enabled that can ensure grsec_lock is enabled
53200+ after boot should use this option.
53201+ *Failure to set grsec_lock after boot makes all grsec features
53202+ this option covers useless*
53203+
53204+ Currently this option creates the following sysctl entries:
53205+ "Disable Privileged I/O": "disable_priv_io"
53206+
53207+config GRKERNSEC_SYSCTL_ON
53208+ bool "Turn on features by default"
53209+ default y if GRKERNSEC_CONFIG_AUTO
53210+ depends on GRKERNSEC_SYSCTL
53211+ help
53212+ If you say Y here, instead of having all features enabled in the
53213+ kernel configuration disabled at boot time, the features will be
53214+ enabled at boot time. It is recommended you say Y here unless
53215+ there is some reason you would want all sysctl-tunable features to
53216+ be disabled by default. As mentioned elsewhere, it is important
53217+ to enable the grsec_lock entry once you have finished modifying
53218+ the sysctl entries.
53219+
53220+endmenu
53221+menu "Logging Options"
53222+depends on GRKERNSEC
53223+
53224+config GRKERNSEC_FLOODTIME
53225+ int "Seconds in between log messages (minimum)"
53226+ default 10
53227+ help
53228+ This option allows you to enforce the number of seconds between
53229+ grsecurity log messages. The default should be suitable for most
53230+ people, however, if you choose to change it, choose a value small enough
53231+ to allow informative logs to be produced, but large enough to
53232+ prevent flooding.
53233+
53234+config GRKERNSEC_FLOODBURST
53235+ int "Number of messages in a burst (maximum)"
53236+ default 6
53237+ help
53238+ This option allows you to choose the maximum number of messages allowed
53239+ within the flood time interval you chose in a separate option. The
53240+ default should be suitable for most people, however if you find that
53241+ many of your logs are being interpreted as flooding, you may want to
53242+ raise this value.
53243+
53244+endmenu
53245diff --git a/grsecurity/Makefile b/grsecurity/Makefile
53246new file mode 100644
53247index 0000000..1b9afa9
53248--- /dev/null
53249+++ b/grsecurity/Makefile
53250@@ -0,0 +1,38 @@
53251+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
53252+# during 2001-2009 it has been completely redesigned by Brad Spengler
53253+# into an RBAC system
53254+#
53255+# All code in this directory and various hooks inserted throughout the kernel
53256+# are copyright Brad Spengler - Open Source Security, Inc., and released
53257+# under the GPL v2 or higher
53258+
53259+KBUILD_CFLAGS += -Werror
53260+
53261+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
53262+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
53263+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
53264+
53265+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
53266+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
53267+ gracl_learn.o grsec_log.o
53268+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
53269+
53270+ifdef CONFIG_NET
53271+obj-y += grsec_sock.o
53272+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
53273+endif
53274+
53275+ifndef CONFIG_GRKERNSEC
53276+obj-y += grsec_disabled.o
53277+endif
53278+
53279+ifdef CONFIG_GRKERNSEC_HIDESYM
53280+extra-y := grsec_hidesym.o
53281+$(obj)/grsec_hidesym.o:
53282+ @-chmod -f 500 /boot
53283+ @-chmod -f 500 /lib/modules
53284+ @-chmod -f 500 /lib64/modules
53285+ @-chmod -f 500 /lib32/modules
53286+ @-chmod -f 700 .
53287+ @echo ' grsec: protected kernel image paths'
53288+endif
53289diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
53290new file mode 100644
53291index 0000000..78353bd
53292--- /dev/null
53293+++ b/grsecurity/gracl.c
53294@@ -0,0 +1,4039 @@
53295+#include <linux/kernel.h>
53296+#include <linux/module.h>
53297+#include <linux/sched.h>
53298+#include <linux/mm.h>
53299+#include <linux/file.h>
53300+#include <linux/fs.h>
53301+#include <linux/namei.h>
53302+#include <linux/mount.h>
53303+#include <linux/tty.h>
53304+#include <linux/proc_fs.h>
53305+#include <linux/lglock.h>
53306+#include <linux/slab.h>
53307+#include <linux/vmalloc.h>
53308+#include <linux/types.h>
53309+#include <linux/sysctl.h>
53310+#include <linux/netdevice.h>
53311+#include <linux/ptrace.h>
53312+#include <linux/gracl.h>
53313+#include <linux/gralloc.h>
53314+#include <linux/security.h>
53315+#include <linux/grinternal.h>
53316+#include <linux/pid_namespace.h>
53317+#include <linux/stop_machine.h>
53318+#include <linux/fdtable.h>
53319+#include <linux/percpu.h>
53320+#include <linux/lglock.h>
53321+#include "../fs/mount.h"
53322+
53323+#include <asm/uaccess.h>
53324+#include <asm/errno.h>
53325+#include <asm/mman.h>
53326+
53327+extern struct lglock vfsmount_lock;
53328+
53329+static struct acl_role_db acl_role_set;
53330+static struct name_db name_set;
53331+static struct inodev_db inodev_set;
53332+
53333+/* for keeping track of userspace pointers used for subjects, so we
53334+ can share references in the kernel as well
53335+*/
53336+
53337+static struct path real_root;
53338+
53339+static struct acl_subj_map_db subj_map_set;
53340+
53341+static struct acl_role_label *default_role;
53342+
53343+static struct acl_role_label *role_list;
53344+
53345+static u16 acl_sp_role_value;
53346+
53347+extern char *gr_shared_page[4];
53348+static DEFINE_MUTEX(gr_dev_mutex);
53349+DEFINE_RWLOCK(gr_inode_lock);
53350+
53351+struct gr_arg *gr_usermode;
53352+
53353+static unsigned int gr_status __read_only = GR_STATUS_INIT;
53354+
53355+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
53356+extern void gr_clear_learn_entries(void);
53357+
53358+#ifdef CONFIG_GRKERNSEC_RESLOG
53359+extern void gr_log_resource(const struct task_struct *task,
53360+ const int res, const unsigned long wanted, const int gt);
53361+#endif
53362+
53363+unsigned char *gr_system_salt;
53364+unsigned char *gr_system_sum;
53365+
53366+static struct sprole_pw **acl_special_roles = NULL;
53367+static __u16 num_sprole_pws = 0;
53368+
53369+static struct acl_role_label *kernel_role = NULL;
53370+
53371+static unsigned int gr_auth_attempts = 0;
53372+static unsigned long gr_auth_expires = 0UL;
53373+
53374+#ifdef CONFIG_NET
53375+extern struct vfsmount *sock_mnt;
53376+#endif
53377+
53378+extern struct vfsmount *pipe_mnt;
53379+extern struct vfsmount *shm_mnt;
53380+#ifdef CONFIG_HUGETLBFS
53381+extern struct vfsmount *hugetlbfs_vfsmount;
53382+#endif
53383+
53384+static struct acl_object_label *fakefs_obj_rw;
53385+static struct acl_object_label *fakefs_obj_rwx;
53386+
53387+extern int gr_init_uidset(void);
53388+extern void gr_free_uidset(void);
53389+extern void gr_remove_uid(uid_t uid);
53390+extern int gr_find_uid(uid_t uid);
53391+
53392+__inline__ int
53393+gr_acl_is_enabled(void)
53394+{
53395+ return (gr_status & GR_READY);
53396+}
53397+
53398+#ifdef CONFIG_BTRFS_FS
53399+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
53400+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
53401+#endif
53402+
53403+static inline dev_t __get_dev(const struct dentry *dentry)
53404+{
53405+#ifdef CONFIG_BTRFS_FS
53406+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
53407+ return get_btrfs_dev_from_inode(dentry->d_inode);
53408+ else
53409+#endif
53410+ return dentry->d_inode->i_sb->s_dev;
53411+}
53412+
53413+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
53414+{
53415+ return __get_dev(dentry);
53416+}
53417+
53418+static char gr_task_roletype_to_char(struct task_struct *task)
53419+{
53420+ switch (task->role->roletype &
53421+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
53422+ GR_ROLE_SPECIAL)) {
53423+ case GR_ROLE_DEFAULT:
53424+ return 'D';
53425+ case GR_ROLE_USER:
53426+ return 'U';
53427+ case GR_ROLE_GROUP:
53428+ return 'G';
53429+ case GR_ROLE_SPECIAL:
53430+ return 'S';
53431+ }
53432+
53433+ return 'X';
53434+}
53435+
53436+char gr_roletype_to_char(void)
53437+{
53438+ return gr_task_roletype_to_char(current);
53439+}
53440+
53441+__inline__ int
53442+gr_acl_tpe_check(void)
53443+{
53444+ if (unlikely(!(gr_status & GR_READY)))
53445+ return 0;
53446+ if (current->role->roletype & GR_ROLE_TPE)
53447+ return 1;
53448+ else
53449+ return 0;
53450+}
53451+
53452+int
53453+gr_handle_rawio(const struct inode *inode)
53454+{
53455+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
53456+ if (inode && S_ISBLK(inode->i_mode) &&
53457+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
53458+ !capable(CAP_SYS_RAWIO))
53459+ return 1;
53460+#endif
53461+ return 0;
53462+}
53463+
53464+static int
53465+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
53466+{
53467+ if (likely(lena != lenb))
53468+ return 0;
53469+
53470+ return !memcmp(a, b, lena);
53471+}
53472+
53473+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
53474+{
53475+ *buflen -= namelen;
53476+ if (*buflen < 0)
53477+ return -ENAMETOOLONG;
53478+ *buffer -= namelen;
53479+ memcpy(*buffer, str, namelen);
53480+ return 0;
53481+}
53482+
53483+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
53484+{
53485+ return prepend(buffer, buflen, name->name, name->len);
53486+}
53487+
53488+static int prepend_path(const struct path *path, struct path *root,
53489+ char **buffer, int *buflen)
53490+{
53491+ struct dentry *dentry = path->dentry;
53492+ struct vfsmount *vfsmnt = path->mnt;
53493+ struct mount *mnt = real_mount(vfsmnt);
53494+ bool slash = false;
53495+ int error = 0;
53496+
53497+ while (dentry != root->dentry || vfsmnt != root->mnt) {
53498+ struct dentry * parent;
53499+
53500+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
53501+ /* Global root? */
53502+ if (!mnt_has_parent(mnt)) {
53503+ goto out;
53504+ }
53505+ dentry = mnt->mnt_mountpoint;
53506+ mnt = mnt->mnt_parent;
53507+ vfsmnt = &mnt->mnt;
53508+ continue;
53509+ }
53510+ parent = dentry->d_parent;
53511+ prefetch(parent);
53512+ spin_lock(&dentry->d_lock);
53513+ error = prepend_name(buffer, buflen, &dentry->d_name);
53514+ spin_unlock(&dentry->d_lock);
53515+ if (!error)
53516+ error = prepend(buffer, buflen, "/", 1);
53517+ if (error)
53518+ break;
53519+
53520+ slash = true;
53521+ dentry = parent;
53522+ }
53523+
53524+out:
53525+ if (!error && !slash)
53526+ error = prepend(buffer, buflen, "/", 1);
53527+
53528+ return error;
53529+}
53530+
53531+/* this must be called with vfsmount_lock and rename_lock held */
53532+
53533+static char *__our_d_path(const struct path *path, struct path *root,
53534+ char *buf, int buflen)
53535+{
53536+ char *res = buf + buflen;
53537+ int error;
53538+
53539+ prepend(&res, &buflen, "\0", 1);
53540+ error = prepend_path(path, root, &res, &buflen);
53541+ if (error)
53542+ return ERR_PTR(error);
53543+
53544+ return res;
53545+}
53546+
53547+static char *
53548+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
53549+{
53550+ char *retval;
53551+
53552+ retval = __our_d_path(path, root, buf, buflen);
53553+ if (unlikely(IS_ERR(retval)))
53554+ retval = strcpy(buf, "<path too long>");
53555+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
53556+ retval[1] = '\0';
53557+
53558+ return retval;
53559+}
53560+
53561+static char *
53562+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53563+ char *buf, int buflen)
53564+{
53565+ struct path path;
53566+ char *res;
53567+
53568+ path.dentry = (struct dentry *)dentry;
53569+ path.mnt = (struct vfsmount *)vfsmnt;
53570+
53571+ /* we can use real_root.dentry, real_root.mnt, because this is only called
53572+ by the RBAC system */
53573+ res = gen_full_path(&path, &real_root, buf, buflen);
53574+
53575+ return res;
53576+}
53577+
53578+static char *
53579+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
53580+ char *buf, int buflen)
53581+{
53582+ char *res;
53583+ struct path path;
53584+ struct path root;
53585+ struct task_struct *reaper = init_pid_ns.child_reaper;
53586+
53587+ path.dentry = (struct dentry *)dentry;
53588+ path.mnt = (struct vfsmount *)vfsmnt;
53589+
53590+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
53591+ get_fs_root(reaper->fs, &root);
53592+
53593+ write_seqlock(&rename_lock);
53594+ br_read_lock(&vfsmount_lock);
53595+ res = gen_full_path(&path, &root, buf, buflen);
53596+ br_read_unlock(&vfsmount_lock);
53597+ write_sequnlock(&rename_lock);
53598+
53599+ path_put(&root);
53600+ return res;
53601+}
53602+
53603+static char *
53604+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53605+{
53606+ char *ret;
53607+ write_seqlock(&rename_lock);
53608+ br_read_lock(&vfsmount_lock);
53609+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53610+ PAGE_SIZE);
53611+ br_read_unlock(&vfsmount_lock);
53612+ write_sequnlock(&rename_lock);
53613+ return ret;
53614+}
53615+
53616+static char *
53617+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
53618+{
53619+ char *ret;
53620+ char *buf;
53621+ int buflen;
53622+
53623+ write_seqlock(&rename_lock);
53624+ br_read_lock(&vfsmount_lock);
53625+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
53626+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
53627+ buflen = (int)(ret - buf);
53628+ if (buflen >= 5)
53629+ prepend(&ret, &buflen, "/proc", 5);
53630+ else
53631+ ret = strcpy(buf, "<path too long>");
53632+ br_read_unlock(&vfsmount_lock);
53633+ write_sequnlock(&rename_lock);
53634+ return ret;
53635+}
53636+
53637+char *
53638+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
53639+{
53640+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
53641+ PAGE_SIZE);
53642+}
53643+
53644+char *
53645+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
53646+{
53647+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
53648+ PAGE_SIZE);
53649+}
53650+
53651+char *
53652+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
53653+{
53654+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
53655+ PAGE_SIZE);
53656+}
53657+
53658+char *
53659+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
53660+{
53661+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
53662+ PAGE_SIZE);
53663+}
53664+
53665+char *
53666+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
53667+{
53668+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
53669+ PAGE_SIZE);
53670+}
53671+
53672+__inline__ __u32
53673+to_gr_audit(const __u32 reqmode)
53674+{
53675+ /* masks off auditable permission flags, then shifts them to create
53676+ auditing flags, and adds the special case of append auditing if
53677+ we're requesting write */
53678+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
53679+}
53680+
53681+struct acl_subject_label *
53682+lookup_subject_map(const struct acl_subject_label *userp)
53683+{
53684+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
53685+ struct subject_map *match;
53686+
53687+ match = subj_map_set.s_hash[index];
53688+
53689+ while (match && match->user != userp)
53690+ match = match->next;
53691+
53692+ if (match != NULL)
53693+ return match->kernel;
53694+ else
53695+ return NULL;
53696+}
53697+
53698+static void
53699+insert_subj_map_entry(struct subject_map *subjmap)
53700+{
53701+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
53702+ struct subject_map **curr;
53703+
53704+ subjmap->prev = NULL;
53705+
53706+ curr = &subj_map_set.s_hash[index];
53707+ if (*curr != NULL)
53708+ (*curr)->prev = subjmap;
53709+
53710+ subjmap->next = *curr;
53711+ *curr = subjmap;
53712+
53713+ return;
53714+}
53715+
53716+static struct acl_role_label *
53717+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
53718+ const gid_t gid)
53719+{
53720+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
53721+ struct acl_role_label *match;
53722+ struct role_allowed_ip *ipp;
53723+ unsigned int x;
53724+ u32 curr_ip = task->signal->curr_ip;
53725+
53726+ task->signal->saved_ip = curr_ip;
53727+
53728+ match = acl_role_set.r_hash[index];
53729+
53730+ while (match) {
53731+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
53732+ for (x = 0; x < match->domain_child_num; x++) {
53733+ if (match->domain_children[x] == uid)
53734+ goto found;
53735+ }
53736+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
53737+ break;
53738+ match = match->next;
53739+ }
53740+found:
53741+ if (match == NULL) {
53742+ try_group:
53743+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
53744+ match = acl_role_set.r_hash[index];
53745+
53746+ while (match) {
53747+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
53748+ for (x = 0; x < match->domain_child_num; x++) {
53749+ if (match->domain_children[x] == gid)
53750+ goto found2;
53751+ }
53752+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
53753+ break;
53754+ match = match->next;
53755+ }
53756+found2:
53757+ if (match == NULL)
53758+ match = default_role;
53759+ if (match->allowed_ips == NULL)
53760+ return match;
53761+ else {
53762+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53763+ if (likely
53764+ ((ntohl(curr_ip) & ipp->netmask) ==
53765+ (ntohl(ipp->addr) & ipp->netmask)))
53766+ return match;
53767+ }
53768+ match = default_role;
53769+ }
53770+ } else if (match->allowed_ips == NULL) {
53771+ return match;
53772+ } else {
53773+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
53774+ if (likely
53775+ ((ntohl(curr_ip) & ipp->netmask) ==
53776+ (ntohl(ipp->addr) & ipp->netmask)))
53777+ return match;
53778+ }
53779+ goto try_group;
53780+ }
53781+
53782+ return match;
53783+}
53784+
53785+struct acl_subject_label *
53786+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
53787+ const struct acl_role_label *role)
53788+{
53789+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53790+ struct acl_subject_label *match;
53791+
53792+ match = role->subj_hash[index];
53793+
53794+ while (match && (match->inode != ino || match->device != dev ||
53795+ (match->mode & GR_DELETED))) {
53796+ match = match->next;
53797+ }
53798+
53799+ if (match && !(match->mode & GR_DELETED))
53800+ return match;
53801+ else
53802+ return NULL;
53803+}
53804+
53805+struct acl_subject_label *
53806+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
53807+ const struct acl_role_label *role)
53808+{
53809+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
53810+ struct acl_subject_label *match;
53811+
53812+ match = role->subj_hash[index];
53813+
53814+ while (match && (match->inode != ino || match->device != dev ||
53815+ !(match->mode & GR_DELETED))) {
53816+ match = match->next;
53817+ }
53818+
53819+ if (match && (match->mode & GR_DELETED))
53820+ return match;
53821+ else
53822+ return NULL;
53823+}
53824+
53825+static struct acl_object_label *
53826+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
53827+ const struct acl_subject_label *subj)
53828+{
53829+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53830+ struct acl_object_label *match;
53831+
53832+ match = subj->obj_hash[index];
53833+
53834+ while (match && (match->inode != ino || match->device != dev ||
53835+ (match->mode & GR_DELETED))) {
53836+ match = match->next;
53837+ }
53838+
53839+ if (match && !(match->mode & GR_DELETED))
53840+ return match;
53841+ else
53842+ return NULL;
53843+}
53844+
53845+static struct acl_object_label *
53846+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
53847+ const struct acl_subject_label *subj)
53848+{
53849+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
53850+ struct acl_object_label *match;
53851+
53852+ match = subj->obj_hash[index];
53853+
53854+ while (match && (match->inode != ino || match->device != dev ||
53855+ !(match->mode & GR_DELETED))) {
53856+ match = match->next;
53857+ }
53858+
53859+ if (match && (match->mode & GR_DELETED))
53860+ return match;
53861+
53862+ match = subj->obj_hash[index];
53863+
53864+ while (match && (match->inode != ino || match->device != dev ||
53865+ (match->mode & GR_DELETED))) {
53866+ match = match->next;
53867+ }
53868+
53869+ if (match && !(match->mode & GR_DELETED))
53870+ return match;
53871+ else
53872+ return NULL;
53873+}
53874+
53875+static struct name_entry *
53876+lookup_name_entry(const char *name)
53877+{
53878+ unsigned int len = strlen(name);
53879+ unsigned int key = full_name_hash(name, len);
53880+ unsigned int index = key % name_set.n_size;
53881+ struct name_entry *match;
53882+
53883+ match = name_set.n_hash[index];
53884+
53885+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
53886+ match = match->next;
53887+
53888+ return match;
53889+}
53890+
53891+static struct name_entry *
53892+lookup_name_entry_create(const char *name)
53893+{
53894+ unsigned int len = strlen(name);
53895+ unsigned int key = full_name_hash(name, len);
53896+ unsigned int index = key % name_set.n_size;
53897+ struct name_entry *match;
53898+
53899+ match = name_set.n_hash[index];
53900+
53901+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53902+ !match->deleted))
53903+ match = match->next;
53904+
53905+ if (match && match->deleted)
53906+ return match;
53907+
53908+ match = name_set.n_hash[index];
53909+
53910+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
53911+ match->deleted))
53912+ match = match->next;
53913+
53914+ if (match && !match->deleted)
53915+ return match;
53916+ else
53917+ return NULL;
53918+}
53919+
53920+static struct inodev_entry *
53921+lookup_inodev_entry(const ino_t ino, const dev_t dev)
53922+{
53923+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
53924+ struct inodev_entry *match;
53925+
53926+ match = inodev_set.i_hash[index];
53927+
53928+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
53929+ match = match->next;
53930+
53931+ return match;
53932+}
53933+
53934+static void
53935+insert_inodev_entry(struct inodev_entry *entry)
53936+{
53937+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
53938+ inodev_set.i_size);
53939+ struct inodev_entry **curr;
53940+
53941+ entry->prev = NULL;
53942+
53943+ curr = &inodev_set.i_hash[index];
53944+ if (*curr != NULL)
53945+ (*curr)->prev = entry;
53946+
53947+ entry->next = *curr;
53948+ *curr = entry;
53949+
53950+ return;
53951+}
53952+
53953+static void
53954+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
53955+{
53956+ unsigned int index =
53957+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
53958+ struct acl_role_label **curr;
53959+ struct acl_role_label *tmp, *tmp2;
53960+
53961+ curr = &acl_role_set.r_hash[index];
53962+
53963+ /* simple case, slot is empty, just set it to our role */
53964+ if (*curr == NULL) {
53965+ *curr = role;
53966+ } else {
53967+ /* example:
53968+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
53969+ 2 -> 3
53970+ */
53971+ /* first check to see if we can already be reached via this slot */
53972+ tmp = *curr;
53973+ while (tmp && tmp != role)
53974+ tmp = tmp->next;
53975+ if (tmp == role) {
53976+ /* we don't need to add ourselves to this slot's chain */
53977+ return;
53978+ }
53979+ /* we need to add ourselves to this chain, two cases */
53980+ if (role->next == NULL) {
53981+ /* simple case, append the current chain to our role */
53982+ role->next = *curr;
53983+ *curr = role;
53984+ } else {
53985+ /* 1 -> 2 -> 3 -> 4
53986+ 2 -> 3 -> 4
53987+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
53988+ */
53989+ /* trickier case: walk our role's chain until we find
53990+ the role for the start of the current slot's chain */
53991+ tmp = role;
53992+ tmp2 = *curr;
53993+ while (tmp->next && tmp->next != tmp2)
53994+ tmp = tmp->next;
53995+ if (tmp->next == tmp2) {
53996+ /* from example above, we found 3, so just
53997+ replace this slot's chain with ours */
53998+ *curr = role;
53999+ } else {
54000+ /* we didn't find a subset of our role's chain
54001+ in the current slot's chain, so append their
54002+ chain to ours, and set us as the first role in
54003+ the slot's chain
54004+
54005+ we could fold this case with the case above,
54006+ but making it explicit for clarity
54007+ */
54008+ tmp->next = tmp2;
54009+ *curr = role;
54010+ }
54011+ }
54012+ }
54013+
54014+ return;
54015+}
54016+
54017+static void
54018+insert_acl_role_label(struct acl_role_label *role)
54019+{
54020+ int i;
54021+
54022+ if (role_list == NULL) {
54023+ role_list = role;
54024+ role->prev = NULL;
54025+ } else {
54026+ role->prev = role_list;
54027+ role_list = role;
54028+ }
54029+
54030+ /* used for hash chains */
54031+ role->next = NULL;
54032+
54033+ if (role->roletype & GR_ROLE_DOMAIN) {
54034+ for (i = 0; i < role->domain_child_num; i++)
54035+ __insert_acl_role_label(role, role->domain_children[i]);
54036+ } else
54037+ __insert_acl_role_label(role, role->uidgid);
54038+}
54039+
54040+static int
54041+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
54042+{
54043+ struct name_entry **curr, *nentry;
54044+ struct inodev_entry *ientry;
54045+ unsigned int len = strlen(name);
54046+ unsigned int key = full_name_hash(name, len);
54047+ unsigned int index = key % name_set.n_size;
54048+
54049+ curr = &name_set.n_hash[index];
54050+
54051+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
54052+ curr = &((*curr)->next);
54053+
54054+ if (*curr != NULL)
54055+ return 1;
54056+
54057+ nentry = acl_alloc(sizeof (struct name_entry));
54058+ if (nentry == NULL)
54059+ return 0;
54060+ ientry = acl_alloc(sizeof (struct inodev_entry));
54061+ if (ientry == NULL)
54062+ return 0;
54063+ ientry->nentry = nentry;
54064+
54065+ nentry->key = key;
54066+ nentry->name = name;
54067+ nentry->inode = inode;
54068+ nentry->device = device;
54069+ nentry->len = len;
54070+ nentry->deleted = deleted;
54071+
54072+ nentry->prev = NULL;
54073+ curr = &name_set.n_hash[index];
54074+ if (*curr != NULL)
54075+ (*curr)->prev = nentry;
54076+ nentry->next = *curr;
54077+ *curr = nentry;
54078+
54079+ /* insert us into the table searchable by inode/dev */
54080+ insert_inodev_entry(ientry);
54081+
54082+ return 1;
54083+}
54084+
54085+static void
54086+insert_acl_obj_label(struct acl_object_label *obj,
54087+ struct acl_subject_label *subj)
54088+{
54089+ unsigned int index =
54090+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
54091+ struct acl_object_label **curr;
54092+
54093+
54094+ obj->prev = NULL;
54095+
54096+ curr = &subj->obj_hash[index];
54097+ if (*curr != NULL)
54098+ (*curr)->prev = obj;
54099+
54100+ obj->next = *curr;
54101+ *curr = obj;
54102+
54103+ return;
54104+}
54105+
54106+static void
54107+insert_acl_subj_label(struct acl_subject_label *obj,
54108+ struct acl_role_label *role)
54109+{
54110+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
54111+ struct acl_subject_label **curr;
54112+
54113+ obj->prev = NULL;
54114+
54115+ curr = &role->subj_hash[index];
54116+ if (*curr != NULL)
54117+ (*curr)->prev = obj;
54118+
54119+ obj->next = *curr;
54120+ *curr = obj;
54121+
54122+ return;
54123+}
54124+
54125+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
54126+
54127+static void *
54128+create_table(__u32 * len, int elementsize)
54129+{
54130+ unsigned int table_sizes[] = {
54131+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
54132+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
54133+ 4194301, 8388593, 16777213, 33554393, 67108859
54134+ };
54135+ void *newtable = NULL;
54136+ unsigned int pwr = 0;
54137+
54138+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
54139+ table_sizes[pwr] <= *len)
54140+ pwr++;
54141+
54142+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
54143+ return newtable;
54144+
54145+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
54146+ newtable =
54147+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
54148+ else
54149+ newtable = vmalloc(table_sizes[pwr] * elementsize);
54150+
54151+ *len = table_sizes[pwr];
54152+
54153+ return newtable;
54154+}
54155+
54156+static int
54157+init_variables(const struct gr_arg *arg)
54158+{
54159+ struct task_struct *reaper = init_pid_ns.child_reaper;
54160+ unsigned int stacksize;
54161+
54162+ subj_map_set.s_size = arg->role_db.num_subjects;
54163+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
54164+ name_set.n_size = arg->role_db.num_objects;
54165+ inodev_set.i_size = arg->role_db.num_objects;
54166+
54167+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
54168+ !name_set.n_size || !inodev_set.i_size)
54169+ return 1;
54170+
54171+ if (!gr_init_uidset())
54172+ return 1;
54173+
54174+ /* set up the stack that holds allocation info */
54175+
54176+ stacksize = arg->role_db.num_pointers + 5;
54177+
54178+ if (!acl_alloc_stack_init(stacksize))
54179+ return 1;
54180+
54181+ /* grab reference for the real root dentry and vfsmount */
54182+ get_fs_root(reaper->fs, &real_root);
54183+
54184+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54185+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
54186+#endif
54187+
54188+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
54189+ if (fakefs_obj_rw == NULL)
54190+ return 1;
54191+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
54192+
54193+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
54194+ if (fakefs_obj_rwx == NULL)
54195+ return 1;
54196+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
54197+
54198+ subj_map_set.s_hash =
54199+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
54200+ acl_role_set.r_hash =
54201+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
54202+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
54203+ inodev_set.i_hash =
54204+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
54205+
54206+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
54207+ !name_set.n_hash || !inodev_set.i_hash)
54208+ return 1;
54209+
54210+ memset(subj_map_set.s_hash, 0,
54211+ sizeof(struct subject_map *) * subj_map_set.s_size);
54212+ memset(acl_role_set.r_hash, 0,
54213+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
54214+ memset(name_set.n_hash, 0,
54215+ sizeof (struct name_entry *) * name_set.n_size);
54216+ memset(inodev_set.i_hash, 0,
54217+ sizeof (struct inodev_entry *) * inodev_set.i_size);
54218+
54219+ return 0;
54220+}
54221+
54222+/* free information not needed after startup
54223+ currently contains user->kernel pointer mappings for subjects
54224+*/
54225+
54226+static void
54227+free_init_variables(void)
54228+{
54229+ __u32 i;
54230+
54231+ if (subj_map_set.s_hash) {
54232+ for (i = 0; i < subj_map_set.s_size; i++) {
54233+ if (subj_map_set.s_hash[i]) {
54234+ kfree(subj_map_set.s_hash[i]);
54235+ subj_map_set.s_hash[i] = NULL;
54236+ }
54237+ }
54238+
54239+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
54240+ PAGE_SIZE)
54241+ kfree(subj_map_set.s_hash);
54242+ else
54243+ vfree(subj_map_set.s_hash);
54244+ }
54245+
54246+ return;
54247+}
54248+
54249+static void
54250+free_variables(void)
54251+{
54252+ struct acl_subject_label *s;
54253+ struct acl_role_label *r;
54254+ struct task_struct *task, *task2;
54255+ unsigned int x;
54256+
54257+ gr_clear_learn_entries();
54258+
54259+ read_lock(&tasklist_lock);
54260+ do_each_thread(task2, task) {
54261+ task->acl_sp_role = 0;
54262+ task->acl_role_id = 0;
54263+ task->acl = NULL;
54264+ task->role = NULL;
54265+ } while_each_thread(task2, task);
54266+ read_unlock(&tasklist_lock);
54267+
54268+ /* release the reference to the real root dentry and vfsmount */
54269+ path_put(&real_root);
54270+ memset(&real_root, 0, sizeof(real_root));
54271+
54272+ /* free all object hash tables */
54273+
54274+ FOR_EACH_ROLE_START(r)
54275+ if (r->subj_hash == NULL)
54276+ goto next_role;
54277+ FOR_EACH_SUBJECT_START(r, s, x)
54278+ if (s->obj_hash == NULL)
54279+ break;
54280+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54281+ kfree(s->obj_hash);
54282+ else
54283+ vfree(s->obj_hash);
54284+ FOR_EACH_SUBJECT_END(s, x)
54285+ FOR_EACH_NESTED_SUBJECT_START(r, s)
54286+ if (s->obj_hash == NULL)
54287+ break;
54288+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
54289+ kfree(s->obj_hash);
54290+ else
54291+ vfree(s->obj_hash);
54292+ FOR_EACH_NESTED_SUBJECT_END(s)
54293+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
54294+ kfree(r->subj_hash);
54295+ else
54296+ vfree(r->subj_hash);
54297+ r->subj_hash = NULL;
54298+next_role:
54299+ FOR_EACH_ROLE_END(r)
54300+
54301+ acl_free_all();
54302+
54303+ if (acl_role_set.r_hash) {
54304+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
54305+ PAGE_SIZE)
54306+ kfree(acl_role_set.r_hash);
54307+ else
54308+ vfree(acl_role_set.r_hash);
54309+ }
54310+ if (name_set.n_hash) {
54311+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
54312+ PAGE_SIZE)
54313+ kfree(name_set.n_hash);
54314+ else
54315+ vfree(name_set.n_hash);
54316+ }
54317+
54318+ if (inodev_set.i_hash) {
54319+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
54320+ PAGE_SIZE)
54321+ kfree(inodev_set.i_hash);
54322+ else
54323+ vfree(inodev_set.i_hash);
54324+ }
54325+
54326+ gr_free_uidset();
54327+
54328+ memset(&name_set, 0, sizeof (struct name_db));
54329+ memset(&inodev_set, 0, sizeof (struct inodev_db));
54330+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
54331+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
54332+
54333+ default_role = NULL;
54334+ kernel_role = NULL;
54335+ role_list = NULL;
54336+
54337+ return;
54338+}
54339+
54340+static __u32
54341+count_user_objs(struct acl_object_label *userp)
54342+{
54343+ struct acl_object_label o_tmp;
54344+ __u32 num = 0;
54345+
54346+ while (userp) {
54347+ if (copy_from_user(&o_tmp, userp,
54348+ sizeof (struct acl_object_label)))
54349+ break;
54350+
54351+ userp = o_tmp.prev;
54352+ num++;
54353+ }
54354+
54355+ return num;
54356+}
54357+
54358+static struct acl_subject_label *
54359+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
54360+
54361+static int
54362+copy_user_glob(struct acl_object_label *obj)
54363+{
54364+ struct acl_object_label *g_tmp, **guser;
54365+ unsigned int len;
54366+ char *tmp;
54367+
54368+ if (obj->globbed == NULL)
54369+ return 0;
54370+
54371+ guser = &obj->globbed;
54372+ while (*guser) {
54373+ g_tmp = (struct acl_object_label *)
54374+ acl_alloc(sizeof (struct acl_object_label));
54375+ if (g_tmp == NULL)
54376+ return -ENOMEM;
54377+
54378+ if (copy_from_user(g_tmp, *guser,
54379+ sizeof (struct acl_object_label)))
54380+ return -EFAULT;
54381+
54382+ len = strnlen_user(g_tmp->filename, PATH_MAX);
54383+
54384+ if (!len || len >= PATH_MAX)
54385+ return -EINVAL;
54386+
54387+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54388+ return -ENOMEM;
54389+
54390+ if (copy_from_user(tmp, g_tmp->filename, len))
54391+ return -EFAULT;
54392+ tmp[len-1] = '\0';
54393+ g_tmp->filename = tmp;
54394+
54395+ *guser = g_tmp;
54396+ guser = &(g_tmp->next);
54397+ }
54398+
54399+ return 0;
54400+}
54401+
54402+static int
54403+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
54404+ struct acl_role_label *role)
54405+{
54406+ struct acl_object_label *o_tmp;
54407+ unsigned int len;
54408+ int ret;
54409+ char *tmp;
54410+
54411+ while (userp) {
54412+ if ((o_tmp = (struct acl_object_label *)
54413+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
54414+ return -ENOMEM;
54415+
54416+ if (copy_from_user(o_tmp, userp,
54417+ sizeof (struct acl_object_label)))
54418+ return -EFAULT;
54419+
54420+ userp = o_tmp->prev;
54421+
54422+ len = strnlen_user(o_tmp->filename, PATH_MAX);
54423+
54424+ if (!len || len >= PATH_MAX)
54425+ return -EINVAL;
54426+
54427+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54428+ return -ENOMEM;
54429+
54430+ if (copy_from_user(tmp, o_tmp->filename, len))
54431+ return -EFAULT;
54432+ tmp[len-1] = '\0';
54433+ o_tmp->filename = tmp;
54434+
54435+ insert_acl_obj_label(o_tmp, subj);
54436+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
54437+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
54438+ return -ENOMEM;
54439+
54440+ ret = copy_user_glob(o_tmp);
54441+ if (ret)
54442+ return ret;
54443+
54444+ if (o_tmp->nested) {
54445+ int already_copied;
54446+
54447+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
54448+ if (IS_ERR(o_tmp->nested))
54449+ return PTR_ERR(o_tmp->nested);
54450+
54451+ /* insert into nested subject list if we haven't copied this one yet
54452+ to prevent duplicate entries */
54453+ if (!already_copied) {
54454+ o_tmp->nested->next = role->hash->first;
54455+ role->hash->first = o_tmp->nested;
54456+ }
54457+ }
54458+ }
54459+
54460+ return 0;
54461+}
54462+
54463+static __u32
54464+count_user_subjs(struct acl_subject_label *userp)
54465+{
54466+ struct acl_subject_label s_tmp;
54467+ __u32 num = 0;
54468+
54469+ while (userp) {
54470+ if (copy_from_user(&s_tmp, userp,
54471+ sizeof (struct acl_subject_label)))
54472+ break;
54473+
54474+ userp = s_tmp.prev;
54475+ }
54476+
54477+ return num;
54478+}
54479+
54480+static int
54481+copy_user_allowedips(struct acl_role_label *rolep)
54482+{
54483+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
54484+
54485+ ruserip = rolep->allowed_ips;
54486+
54487+ while (ruserip) {
54488+ rlast = rtmp;
54489+
54490+ if ((rtmp = (struct role_allowed_ip *)
54491+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
54492+ return -ENOMEM;
54493+
54494+ if (copy_from_user(rtmp, ruserip,
54495+ sizeof (struct role_allowed_ip)))
54496+ return -EFAULT;
54497+
54498+ ruserip = rtmp->prev;
54499+
54500+ if (!rlast) {
54501+ rtmp->prev = NULL;
54502+ rolep->allowed_ips = rtmp;
54503+ } else {
54504+ rlast->next = rtmp;
54505+ rtmp->prev = rlast;
54506+ }
54507+
54508+ if (!ruserip)
54509+ rtmp->next = NULL;
54510+ }
54511+
54512+ return 0;
54513+}
54514+
54515+static int
54516+copy_user_transitions(struct acl_role_label *rolep)
54517+{
54518+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
54519+
54520+ unsigned int len;
54521+ char *tmp;
54522+
54523+ rusertp = rolep->transitions;
54524+
54525+ while (rusertp) {
54526+ rlast = rtmp;
54527+
54528+ if ((rtmp = (struct role_transition *)
54529+ acl_alloc(sizeof (struct role_transition))) == NULL)
54530+ return -ENOMEM;
54531+
54532+ if (copy_from_user(rtmp, rusertp,
54533+ sizeof (struct role_transition)))
54534+ return -EFAULT;
54535+
54536+ rusertp = rtmp->prev;
54537+
54538+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
54539+
54540+ if (!len || len >= GR_SPROLE_LEN)
54541+ return -EINVAL;
54542+
54543+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54544+ return -ENOMEM;
54545+
54546+ if (copy_from_user(tmp, rtmp->rolename, len))
54547+ return -EFAULT;
54548+ tmp[len-1] = '\0';
54549+ rtmp->rolename = tmp;
54550+
54551+ if (!rlast) {
54552+ rtmp->prev = NULL;
54553+ rolep->transitions = rtmp;
54554+ } else {
54555+ rlast->next = rtmp;
54556+ rtmp->prev = rlast;
54557+ }
54558+
54559+ if (!rusertp)
54560+ rtmp->next = NULL;
54561+ }
54562+
54563+ return 0;
54564+}
54565+
54566+static struct acl_subject_label *
54567+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
54568+{
54569+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
54570+ unsigned int len;
54571+ char *tmp;
54572+ __u32 num_objs;
54573+ struct acl_ip_label **i_tmp, *i_utmp2;
54574+ struct gr_hash_struct ghash;
54575+ struct subject_map *subjmap;
54576+ unsigned int i_num;
54577+ int err;
54578+
54579+ if (already_copied != NULL)
54580+ *already_copied = 0;
54581+
54582+ s_tmp = lookup_subject_map(userp);
54583+
54584+ /* we've already copied this subject into the kernel, just return
54585+ the reference to it, and don't copy it over again
54586+ */
54587+ if (s_tmp) {
54588+ if (already_copied != NULL)
54589+ *already_copied = 1;
54590+ return(s_tmp);
54591+ }
54592+
54593+ if ((s_tmp = (struct acl_subject_label *)
54594+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
54595+ return ERR_PTR(-ENOMEM);
54596+
54597+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
54598+ if (subjmap == NULL)
54599+ return ERR_PTR(-ENOMEM);
54600+
54601+ subjmap->user = userp;
54602+ subjmap->kernel = s_tmp;
54603+ insert_subj_map_entry(subjmap);
54604+
54605+ if (copy_from_user(s_tmp, userp,
54606+ sizeof (struct acl_subject_label)))
54607+ return ERR_PTR(-EFAULT);
54608+
54609+ len = strnlen_user(s_tmp->filename, PATH_MAX);
54610+
54611+ if (!len || len >= PATH_MAX)
54612+ return ERR_PTR(-EINVAL);
54613+
54614+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54615+ return ERR_PTR(-ENOMEM);
54616+
54617+ if (copy_from_user(tmp, s_tmp->filename, len))
54618+ return ERR_PTR(-EFAULT);
54619+ tmp[len-1] = '\0';
54620+ s_tmp->filename = tmp;
54621+
54622+ if (!strcmp(s_tmp->filename, "/"))
54623+ role->root_label = s_tmp;
54624+
54625+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
54626+ return ERR_PTR(-EFAULT);
54627+
54628+ /* copy user and group transition tables */
54629+
54630+ if (s_tmp->user_trans_num) {
54631+ uid_t *uidlist;
54632+
54633+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
54634+ if (uidlist == NULL)
54635+ return ERR_PTR(-ENOMEM);
54636+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
54637+ return ERR_PTR(-EFAULT);
54638+
54639+ s_tmp->user_transitions = uidlist;
54640+ }
54641+
54642+ if (s_tmp->group_trans_num) {
54643+ gid_t *gidlist;
54644+
54645+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
54646+ if (gidlist == NULL)
54647+ return ERR_PTR(-ENOMEM);
54648+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
54649+ return ERR_PTR(-EFAULT);
54650+
54651+ s_tmp->group_transitions = gidlist;
54652+ }
54653+
54654+ /* set up object hash table */
54655+ num_objs = count_user_objs(ghash.first);
54656+
54657+ s_tmp->obj_hash_size = num_objs;
54658+ s_tmp->obj_hash =
54659+ (struct acl_object_label **)
54660+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
54661+
54662+ if (!s_tmp->obj_hash)
54663+ return ERR_PTR(-ENOMEM);
54664+
54665+ memset(s_tmp->obj_hash, 0,
54666+ s_tmp->obj_hash_size *
54667+ sizeof (struct acl_object_label *));
54668+
54669+ /* add in objects */
54670+ err = copy_user_objs(ghash.first, s_tmp, role);
54671+
54672+ if (err)
54673+ return ERR_PTR(err);
54674+
54675+ /* set pointer for parent subject */
54676+ if (s_tmp->parent_subject) {
54677+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
54678+
54679+ if (IS_ERR(s_tmp2))
54680+ return s_tmp2;
54681+
54682+ s_tmp->parent_subject = s_tmp2;
54683+ }
54684+
54685+ /* add in ip acls */
54686+
54687+ if (!s_tmp->ip_num) {
54688+ s_tmp->ips = NULL;
54689+ goto insert;
54690+ }
54691+
54692+ i_tmp =
54693+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
54694+ sizeof (struct acl_ip_label *));
54695+
54696+ if (!i_tmp)
54697+ return ERR_PTR(-ENOMEM);
54698+
54699+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
54700+ *(i_tmp + i_num) =
54701+ (struct acl_ip_label *)
54702+ acl_alloc(sizeof (struct acl_ip_label));
54703+ if (!*(i_tmp + i_num))
54704+ return ERR_PTR(-ENOMEM);
54705+
54706+ if (copy_from_user
54707+ (&i_utmp2, s_tmp->ips + i_num,
54708+ sizeof (struct acl_ip_label *)))
54709+ return ERR_PTR(-EFAULT);
54710+
54711+ if (copy_from_user
54712+ (*(i_tmp + i_num), i_utmp2,
54713+ sizeof (struct acl_ip_label)))
54714+ return ERR_PTR(-EFAULT);
54715+
54716+ if ((*(i_tmp + i_num))->iface == NULL)
54717+ continue;
54718+
54719+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
54720+ if (!len || len >= IFNAMSIZ)
54721+ return ERR_PTR(-EINVAL);
54722+ tmp = acl_alloc(len);
54723+ if (tmp == NULL)
54724+ return ERR_PTR(-ENOMEM);
54725+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
54726+ return ERR_PTR(-EFAULT);
54727+ (*(i_tmp + i_num))->iface = tmp;
54728+ }
54729+
54730+ s_tmp->ips = i_tmp;
54731+
54732+insert:
54733+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
54734+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
54735+ return ERR_PTR(-ENOMEM);
54736+
54737+ return s_tmp;
54738+}
54739+
54740+static int
54741+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
54742+{
54743+ struct acl_subject_label s_pre;
54744+ struct acl_subject_label * ret;
54745+ int err;
54746+
54747+ while (userp) {
54748+ if (copy_from_user(&s_pre, userp,
54749+ sizeof (struct acl_subject_label)))
54750+ return -EFAULT;
54751+
54752+ ret = do_copy_user_subj(userp, role, NULL);
54753+
54754+ err = PTR_ERR(ret);
54755+ if (IS_ERR(ret))
54756+ return err;
54757+
54758+ insert_acl_subj_label(ret, role);
54759+
54760+ userp = s_pre.prev;
54761+ }
54762+
54763+ return 0;
54764+}
54765+
54766+static int
54767+copy_user_acl(struct gr_arg *arg)
54768+{
54769+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
54770+ struct acl_subject_label *subj_list;
54771+ struct sprole_pw *sptmp;
54772+ struct gr_hash_struct *ghash;
54773+ uid_t *domainlist;
54774+ unsigned int r_num;
54775+ unsigned int len;
54776+ char *tmp;
54777+ int err = 0;
54778+ __u16 i;
54779+ __u32 num_subjs;
54780+
54781+ /* we need a default and kernel role */
54782+ if (arg->role_db.num_roles < 2)
54783+ return -EINVAL;
54784+
54785+ /* copy special role authentication info from userspace */
54786+
54787+ num_sprole_pws = arg->num_sprole_pws;
54788+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
54789+
54790+ if (!acl_special_roles && num_sprole_pws)
54791+ return -ENOMEM;
54792+
54793+ for (i = 0; i < num_sprole_pws; i++) {
54794+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
54795+ if (!sptmp)
54796+ return -ENOMEM;
54797+ if (copy_from_user(sptmp, arg->sprole_pws + i,
54798+ sizeof (struct sprole_pw)))
54799+ return -EFAULT;
54800+
54801+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
54802+
54803+ if (!len || len >= GR_SPROLE_LEN)
54804+ return -EINVAL;
54805+
54806+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54807+ return -ENOMEM;
54808+
54809+ if (copy_from_user(tmp, sptmp->rolename, len))
54810+ return -EFAULT;
54811+
54812+ tmp[len-1] = '\0';
54813+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54814+ printk(KERN_ALERT "Copying special role %s\n", tmp);
54815+#endif
54816+ sptmp->rolename = tmp;
54817+ acl_special_roles[i] = sptmp;
54818+ }
54819+
54820+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
54821+
54822+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
54823+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
54824+
54825+ if (!r_tmp)
54826+ return -ENOMEM;
54827+
54828+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
54829+ sizeof (struct acl_role_label *)))
54830+ return -EFAULT;
54831+
54832+ if (copy_from_user(r_tmp, r_utmp2,
54833+ sizeof (struct acl_role_label)))
54834+ return -EFAULT;
54835+
54836+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
54837+
54838+ if (!len || len >= PATH_MAX)
54839+ return -EINVAL;
54840+
54841+ if ((tmp = (char *) acl_alloc(len)) == NULL)
54842+ return -ENOMEM;
54843+
54844+ if (copy_from_user(tmp, r_tmp->rolename, len))
54845+ return -EFAULT;
54846+
54847+ tmp[len-1] = '\0';
54848+ r_tmp->rolename = tmp;
54849+
54850+ if (!strcmp(r_tmp->rolename, "default")
54851+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
54852+ default_role = r_tmp;
54853+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
54854+ kernel_role = r_tmp;
54855+ }
54856+
54857+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
54858+ return -ENOMEM;
54859+
54860+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
54861+ return -EFAULT;
54862+
54863+ r_tmp->hash = ghash;
54864+
54865+ num_subjs = count_user_subjs(r_tmp->hash->first);
54866+
54867+ r_tmp->subj_hash_size = num_subjs;
54868+ r_tmp->subj_hash =
54869+ (struct acl_subject_label **)
54870+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
54871+
54872+ if (!r_tmp->subj_hash)
54873+ return -ENOMEM;
54874+
54875+ err = copy_user_allowedips(r_tmp);
54876+ if (err)
54877+ return err;
54878+
54879+ /* copy domain info */
54880+ if (r_tmp->domain_children != NULL) {
54881+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
54882+ if (domainlist == NULL)
54883+ return -ENOMEM;
54884+
54885+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
54886+ return -EFAULT;
54887+
54888+ r_tmp->domain_children = domainlist;
54889+ }
54890+
54891+ err = copy_user_transitions(r_tmp);
54892+ if (err)
54893+ return err;
54894+
54895+ memset(r_tmp->subj_hash, 0,
54896+ r_tmp->subj_hash_size *
54897+ sizeof (struct acl_subject_label *));
54898+
54899+ /* acquire the list of subjects, then NULL out
54900+ the list prior to parsing the subjects for this role,
54901+ as during this parsing the list is replaced with a list
54902+ of *nested* subjects for the role
54903+ */
54904+ subj_list = r_tmp->hash->first;
54905+
54906+ /* set nested subject list to null */
54907+ r_tmp->hash->first = NULL;
54908+
54909+ err = copy_user_subjs(subj_list, r_tmp);
54910+
54911+ if (err)
54912+ return err;
54913+
54914+ insert_acl_role_label(r_tmp);
54915+ }
54916+
54917+ if (default_role == NULL || kernel_role == NULL)
54918+ return -EINVAL;
54919+
54920+ return err;
54921+}
54922+
54923+static int
54924+gracl_init(struct gr_arg *args)
54925+{
54926+ int error = 0;
54927+
54928+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
54929+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
54930+
54931+ if (init_variables(args)) {
54932+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
54933+ error = -ENOMEM;
54934+ free_variables();
54935+ goto out;
54936+ }
54937+
54938+ error = copy_user_acl(args);
54939+ free_init_variables();
54940+ if (error) {
54941+ free_variables();
54942+ goto out;
54943+ }
54944+
54945+ if ((error = gr_set_acls(0))) {
54946+ free_variables();
54947+ goto out;
54948+ }
54949+
54950+ pax_open_kernel();
54951+ gr_status |= GR_READY;
54952+ pax_close_kernel();
54953+
54954+ out:
54955+ return error;
54956+}
54957+
54958+/* derived from glibc fnmatch() 0: match, 1: no match*/
54959+
54960+static int
54961+glob_match(const char *p, const char *n)
54962+{
54963+ char c;
54964+
54965+ while ((c = *p++) != '\0') {
54966+ switch (c) {
54967+ case '?':
54968+ if (*n == '\0')
54969+ return 1;
54970+ else if (*n == '/')
54971+ return 1;
54972+ break;
54973+ case '\\':
54974+ if (*n != c)
54975+ return 1;
54976+ break;
54977+ case '*':
54978+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
54979+ if (*n == '/')
54980+ return 1;
54981+ else if (c == '?') {
54982+ if (*n == '\0')
54983+ return 1;
54984+ else
54985+ ++n;
54986+ }
54987+ }
54988+ if (c == '\0') {
54989+ return 0;
54990+ } else {
54991+ const char *endp;
54992+
54993+ if ((endp = strchr(n, '/')) == NULL)
54994+ endp = n + strlen(n);
54995+
54996+ if (c == '[') {
54997+ for (--p; n < endp; ++n)
54998+ if (!glob_match(p, n))
54999+ return 0;
55000+ } else if (c == '/') {
55001+ while (*n != '\0' && *n != '/')
55002+ ++n;
55003+ if (*n == '/' && !glob_match(p, n + 1))
55004+ return 0;
55005+ } else {
55006+ for (--p; n < endp; ++n)
55007+ if (*n == c && !glob_match(p, n))
55008+ return 0;
55009+ }
55010+
55011+ return 1;
55012+ }
55013+ case '[':
55014+ {
55015+ int not;
55016+ char cold;
55017+
55018+ if (*n == '\0' || *n == '/')
55019+ return 1;
55020+
55021+ not = (*p == '!' || *p == '^');
55022+ if (not)
55023+ ++p;
55024+
55025+ c = *p++;
55026+ for (;;) {
55027+ unsigned char fn = (unsigned char)*n;
55028+
55029+ if (c == '\0')
55030+ return 1;
55031+ else {
55032+ if (c == fn)
55033+ goto matched;
55034+ cold = c;
55035+ c = *p++;
55036+
55037+ if (c == '-' && *p != ']') {
55038+ unsigned char cend = *p++;
55039+
55040+ if (cend == '\0')
55041+ return 1;
55042+
55043+ if (cold <= fn && fn <= cend)
55044+ goto matched;
55045+
55046+ c = *p++;
55047+ }
55048+ }
55049+
55050+ if (c == ']')
55051+ break;
55052+ }
55053+ if (!not)
55054+ return 1;
55055+ break;
55056+ matched:
55057+ while (c != ']') {
55058+ if (c == '\0')
55059+ return 1;
55060+
55061+ c = *p++;
55062+ }
55063+ if (not)
55064+ return 1;
55065+ }
55066+ break;
55067+ default:
55068+ if (c != *n)
55069+ return 1;
55070+ }
55071+
55072+ ++n;
55073+ }
55074+
55075+ if (*n == '\0')
55076+ return 0;
55077+
55078+ if (*n == '/')
55079+ return 0;
55080+
55081+ return 1;
55082+}
55083+
55084+static struct acl_object_label *
55085+chk_glob_label(struct acl_object_label *globbed,
55086+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
55087+{
55088+ struct acl_object_label *tmp;
55089+
55090+ if (*path == NULL)
55091+ *path = gr_to_filename_nolock(dentry, mnt);
55092+
55093+ tmp = globbed;
55094+
55095+ while (tmp) {
55096+ if (!glob_match(tmp->filename, *path))
55097+ return tmp;
55098+ tmp = tmp->next;
55099+ }
55100+
55101+ return NULL;
55102+}
55103+
55104+static struct acl_object_label *
55105+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55106+ const ino_t curr_ino, const dev_t curr_dev,
55107+ const struct acl_subject_label *subj, char **path, const int checkglob)
55108+{
55109+ struct acl_subject_label *tmpsubj;
55110+ struct acl_object_label *retval;
55111+ struct acl_object_label *retval2;
55112+
55113+ tmpsubj = (struct acl_subject_label *) subj;
55114+ read_lock(&gr_inode_lock);
55115+ do {
55116+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
55117+ if (retval) {
55118+ if (checkglob && retval->globbed) {
55119+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
55120+ if (retval2)
55121+ retval = retval2;
55122+ }
55123+ break;
55124+ }
55125+ } while ((tmpsubj = tmpsubj->parent_subject));
55126+ read_unlock(&gr_inode_lock);
55127+
55128+ return retval;
55129+}
55130+
55131+static __inline__ struct acl_object_label *
55132+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
55133+ struct dentry *curr_dentry,
55134+ const struct acl_subject_label *subj, char **path, const int checkglob)
55135+{
55136+ int newglob = checkglob;
55137+ ino_t inode;
55138+ dev_t device;
55139+
55140+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
55141+ as we don't want a / * rule to match instead of the / object
55142+ don't do this for create lookups that call this function though, since they're looking up
55143+ on the parent and thus need globbing checks on all paths
55144+ */
55145+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
55146+ newglob = GR_NO_GLOB;
55147+
55148+ spin_lock(&curr_dentry->d_lock);
55149+ inode = curr_dentry->d_inode->i_ino;
55150+ device = __get_dev(curr_dentry);
55151+ spin_unlock(&curr_dentry->d_lock);
55152+
55153+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
55154+}
55155+
55156+static struct acl_object_label *
55157+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55158+ const struct acl_subject_label *subj, char *path, const int checkglob)
55159+{
55160+ struct dentry *dentry = (struct dentry *) l_dentry;
55161+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55162+ struct mount *real_mnt = real_mount(mnt);
55163+ struct acl_object_label *retval;
55164+ struct dentry *parent;
55165+
55166+ write_seqlock(&rename_lock);
55167+ br_read_lock(&vfsmount_lock);
55168+
55169+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
55170+#ifdef CONFIG_NET
55171+ mnt == sock_mnt ||
55172+#endif
55173+#ifdef CONFIG_HUGETLBFS
55174+ (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
55175+#endif
55176+ /* ignore Eric Biederman */
55177+ IS_PRIVATE(l_dentry->d_inode))) {
55178+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
55179+ goto out;
55180+ }
55181+
55182+ for (;;) {
55183+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55184+ break;
55185+
55186+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55187+ if (!mnt_has_parent(real_mnt))
55188+ break;
55189+
55190+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55191+ if (retval != NULL)
55192+ goto out;
55193+
55194+ dentry = real_mnt->mnt_mountpoint;
55195+ real_mnt = real_mnt->mnt_parent;
55196+ mnt = &real_mnt->mnt;
55197+ continue;
55198+ }
55199+
55200+ parent = dentry->d_parent;
55201+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55202+ if (retval != NULL)
55203+ goto out;
55204+
55205+ dentry = parent;
55206+ }
55207+
55208+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
55209+
55210+ /* real_root is pinned so we don't have to hold a reference */
55211+ if (retval == NULL)
55212+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
55213+out:
55214+ br_read_unlock(&vfsmount_lock);
55215+ write_sequnlock(&rename_lock);
55216+
55217+ BUG_ON(retval == NULL);
55218+
55219+ return retval;
55220+}
55221+
55222+static __inline__ struct acl_object_label *
55223+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55224+ const struct acl_subject_label *subj)
55225+{
55226+ char *path = NULL;
55227+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
55228+}
55229+
55230+static __inline__ struct acl_object_label *
55231+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55232+ const struct acl_subject_label *subj)
55233+{
55234+ char *path = NULL;
55235+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
55236+}
55237+
55238+static __inline__ struct acl_object_label *
55239+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55240+ const struct acl_subject_label *subj, char *path)
55241+{
55242+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
55243+}
55244+
55245+static struct acl_subject_label *
55246+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
55247+ const struct acl_role_label *role)
55248+{
55249+ struct dentry *dentry = (struct dentry *) l_dentry;
55250+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
55251+ struct mount *real_mnt = real_mount(mnt);
55252+ struct acl_subject_label *retval;
55253+ struct dentry *parent;
55254+
55255+ write_seqlock(&rename_lock);
55256+ br_read_lock(&vfsmount_lock);
55257+
55258+ for (;;) {
55259+ if (dentry == real_root.dentry && mnt == real_root.mnt)
55260+ break;
55261+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
55262+ if (!mnt_has_parent(real_mnt))
55263+ break;
55264+
55265+ spin_lock(&dentry->d_lock);
55266+ read_lock(&gr_inode_lock);
55267+ retval =
55268+ lookup_acl_subj_label(dentry->d_inode->i_ino,
55269+ __get_dev(dentry), role);
55270+ read_unlock(&gr_inode_lock);
55271+ spin_unlock(&dentry->d_lock);
55272+ if (retval != NULL)
55273+ goto out;
55274+
55275+ dentry = real_mnt->mnt_mountpoint;
55276+ real_mnt = real_mnt->mnt_parent;
55277+ mnt = &real_mnt->mnt;
55278+ continue;
55279+ }
55280+
55281+ spin_lock(&dentry->d_lock);
55282+ read_lock(&gr_inode_lock);
55283+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55284+ __get_dev(dentry), role);
55285+ read_unlock(&gr_inode_lock);
55286+ parent = dentry->d_parent;
55287+ spin_unlock(&dentry->d_lock);
55288+
55289+ if (retval != NULL)
55290+ goto out;
55291+
55292+ dentry = parent;
55293+ }
55294+
55295+ spin_lock(&dentry->d_lock);
55296+ read_lock(&gr_inode_lock);
55297+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
55298+ __get_dev(dentry), role);
55299+ read_unlock(&gr_inode_lock);
55300+ spin_unlock(&dentry->d_lock);
55301+
55302+ if (unlikely(retval == NULL)) {
55303+ /* real_root is pinned, we don't need to hold a reference */
55304+ read_lock(&gr_inode_lock);
55305+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
55306+ __get_dev(real_root.dentry), role);
55307+ read_unlock(&gr_inode_lock);
55308+ }
55309+out:
55310+ br_read_unlock(&vfsmount_lock);
55311+ write_sequnlock(&rename_lock);
55312+
55313+ BUG_ON(retval == NULL);
55314+
55315+ return retval;
55316+}
55317+
55318+static void
55319+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
55320+{
55321+ struct task_struct *task = current;
55322+ const struct cred *cred = current_cred();
55323+
55324+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
55325+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55326+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55327+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
55328+
55329+ return;
55330+}
55331+
55332+static void
55333+gr_log_learn_id_change(const char type, const unsigned int real,
55334+ const unsigned int effective, const unsigned int fs)
55335+{
55336+ struct task_struct *task = current;
55337+ const struct cred *cred = current_cred();
55338+
55339+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
55340+ cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
55341+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
55342+ type, real, effective, fs, &task->signal->saved_ip);
55343+
55344+ return;
55345+}
55346+
55347+__u32
55348+gr_search_file(const struct dentry * dentry, const __u32 mode,
55349+ const struct vfsmount * mnt)
55350+{
55351+ __u32 retval = mode;
55352+ struct acl_subject_label *curracl;
55353+ struct acl_object_label *currobj;
55354+
55355+ if (unlikely(!(gr_status & GR_READY)))
55356+ return (mode & ~GR_AUDITS);
55357+
55358+ curracl = current->acl;
55359+
55360+ currobj = chk_obj_label(dentry, mnt, curracl);
55361+ retval = currobj->mode & mode;
55362+
55363+ /* if we're opening a specified transfer file for writing
55364+ (e.g. /dev/initctl), then transfer our role to init
55365+ */
55366+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
55367+ current->role->roletype & GR_ROLE_PERSIST)) {
55368+ struct task_struct *task = init_pid_ns.child_reaper;
55369+
55370+ if (task->role != current->role) {
55371+ task->acl_sp_role = 0;
55372+ task->acl_role_id = current->acl_role_id;
55373+ task->role = current->role;
55374+ rcu_read_lock();
55375+ read_lock(&grsec_exec_file_lock);
55376+ gr_apply_subject_to_task(task);
55377+ read_unlock(&grsec_exec_file_lock);
55378+ rcu_read_unlock();
55379+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
55380+ }
55381+ }
55382+
55383+ if (unlikely
55384+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
55385+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
55386+ __u32 new_mode = mode;
55387+
55388+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55389+
55390+ retval = new_mode;
55391+
55392+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
55393+ new_mode |= GR_INHERIT;
55394+
55395+ if (!(mode & GR_NOLEARN))
55396+ gr_log_learn(dentry, mnt, new_mode);
55397+ }
55398+
55399+ return retval;
55400+}
55401+
55402+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
55403+ const struct dentry *parent,
55404+ const struct vfsmount *mnt)
55405+{
55406+ struct name_entry *match;
55407+ struct acl_object_label *matchpo;
55408+ struct acl_subject_label *curracl;
55409+ char *path;
55410+
55411+ if (unlikely(!(gr_status & GR_READY)))
55412+ return NULL;
55413+
55414+ preempt_disable();
55415+ path = gr_to_filename_rbac(new_dentry, mnt);
55416+ match = lookup_name_entry_create(path);
55417+
55418+ curracl = current->acl;
55419+
55420+ if (match) {
55421+ read_lock(&gr_inode_lock);
55422+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
55423+ read_unlock(&gr_inode_lock);
55424+
55425+ if (matchpo) {
55426+ preempt_enable();
55427+ return matchpo;
55428+ }
55429+ }
55430+
55431+ // lookup parent
55432+
55433+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
55434+
55435+ preempt_enable();
55436+ return matchpo;
55437+}
55438+
55439+__u32
55440+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
55441+ const struct vfsmount * mnt, const __u32 mode)
55442+{
55443+ struct acl_object_label *matchpo;
55444+ __u32 retval;
55445+
55446+ if (unlikely(!(gr_status & GR_READY)))
55447+ return (mode & ~GR_AUDITS);
55448+
55449+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
55450+
55451+ retval = matchpo->mode & mode;
55452+
55453+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
55454+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55455+ __u32 new_mode = mode;
55456+
55457+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
55458+
55459+ gr_log_learn(new_dentry, mnt, new_mode);
55460+ return new_mode;
55461+ }
55462+
55463+ return retval;
55464+}
55465+
55466+__u32
55467+gr_check_link(const struct dentry * new_dentry,
55468+ const struct dentry * parent_dentry,
55469+ const struct vfsmount * parent_mnt,
55470+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
55471+{
55472+ struct acl_object_label *obj;
55473+ __u32 oldmode, newmode;
55474+ __u32 needmode;
55475+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
55476+ GR_DELETE | GR_INHERIT;
55477+
55478+ if (unlikely(!(gr_status & GR_READY)))
55479+ return (GR_CREATE | GR_LINK);
55480+
55481+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
55482+ oldmode = obj->mode;
55483+
55484+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
55485+ newmode = obj->mode;
55486+
55487+ needmode = newmode & checkmodes;
55488+
55489+ // old name for hardlink must have at least the permissions of the new name
55490+ if ((oldmode & needmode) != needmode)
55491+ goto bad;
55492+
55493+ // if old name had restrictions/auditing, make sure the new name does as well
55494+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
55495+
55496+ // don't allow hardlinking of suid/sgid/fcapped files without permission
55497+ if (is_privileged_binary(old_dentry))
55498+ needmode |= GR_SETID;
55499+
55500+ if ((newmode & needmode) != needmode)
55501+ goto bad;
55502+
55503+ // enforce minimum permissions
55504+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
55505+ return newmode;
55506+bad:
55507+ needmode = oldmode;
55508+ if (is_privileged_binary(old_dentry))
55509+ needmode |= GR_SETID;
55510+
55511+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
55512+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
55513+ return (GR_CREATE | GR_LINK);
55514+ } else if (newmode & GR_SUPPRESS)
55515+ return GR_SUPPRESS;
55516+ else
55517+ return 0;
55518+}
55519+
55520+int
55521+gr_check_hidden_task(const struct task_struct *task)
55522+{
55523+ if (unlikely(!(gr_status & GR_READY)))
55524+ return 0;
55525+
55526+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
55527+ return 1;
55528+
55529+ return 0;
55530+}
55531+
55532+int
55533+gr_check_protected_task(const struct task_struct *task)
55534+{
55535+ if (unlikely(!(gr_status & GR_READY) || !task))
55536+ return 0;
55537+
55538+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55539+ task->acl != current->acl)
55540+ return 1;
55541+
55542+ return 0;
55543+}
55544+
55545+int
55546+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
55547+{
55548+ struct task_struct *p;
55549+ int ret = 0;
55550+
55551+ if (unlikely(!(gr_status & GR_READY) || !pid))
55552+ return ret;
55553+
55554+ read_lock(&tasklist_lock);
55555+ do_each_pid_task(pid, type, p) {
55556+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
55557+ p->acl != current->acl) {
55558+ ret = 1;
55559+ goto out;
55560+ }
55561+ } while_each_pid_task(pid, type, p);
55562+out:
55563+ read_unlock(&tasklist_lock);
55564+
55565+ return ret;
55566+}
55567+
55568+void
55569+gr_copy_label(struct task_struct *tsk)
55570+{
55571+ tsk->signal->used_accept = 0;
55572+ tsk->acl_sp_role = 0;
55573+ tsk->acl_role_id = current->acl_role_id;
55574+ tsk->acl = current->acl;
55575+ tsk->role = current->role;
55576+ tsk->signal->curr_ip = current->signal->curr_ip;
55577+ tsk->signal->saved_ip = current->signal->saved_ip;
55578+ if (current->exec_file)
55579+ get_file(current->exec_file);
55580+ tsk->exec_file = current->exec_file;
55581+ tsk->is_writable = current->is_writable;
55582+ if (unlikely(current->signal->used_accept)) {
55583+ current->signal->curr_ip = 0;
55584+ current->signal->saved_ip = 0;
55585+ }
55586+
55587+ return;
55588+}
55589+
55590+static void
55591+gr_set_proc_res(struct task_struct *task)
55592+{
55593+ struct acl_subject_label *proc;
55594+ unsigned short i;
55595+
55596+ proc = task->acl;
55597+
55598+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
55599+ return;
55600+
55601+ for (i = 0; i < RLIM_NLIMITS; i++) {
55602+ if (!(proc->resmask & (1 << i)))
55603+ continue;
55604+
55605+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
55606+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
55607+ }
55608+
55609+ return;
55610+}
55611+
55612+extern int __gr_process_user_ban(struct user_struct *user);
55613+
55614+int
55615+gr_check_user_change(int real, int effective, int fs)
55616+{
55617+ unsigned int i;
55618+ __u16 num;
55619+ uid_t *uidlist;
55620+ int curuid;
55621+ int realok = 0;
55622+ int effectiveok = 0;
55623+ int fsok = 0;
55624+
55625+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
55626+ struct user_struct *user;
55627+
55628+ if (real == -1)
55629+ goto skipit;
55630+
55631+ user = find_user(real);
55632+ if (user == NULL)
55633+ goto skipit;
55634+
55635+ if (__gr_process_user_ban(user)) {
55636+ /* for find_user */
55637+ free_uid(user);
55638+ return 1;
55639+ }
55640+
55641+ /* for find_user */
55642+ free_uid(user);
55643+
55644+skipit:
55645+#endif
55646+
55647+ if (unlikely(!(gr_status & GR_READY)))
55648+ return 0;
55649+
55650+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55651+ gr_log_learn_id_change('u', real, effective, fs);
55652+
55653+ num = current->acl->user_trans_num;
55654+ uidlist = current->acl->user_transitions;
55655+
55656+ if (uidlist == NULL)
55657+ return 0;
55658+
55659+ if (real == -1)
55660+ realok = 1;
55661+ if (effective == -1)
55662+ effectiveok = 1;
55663+ if (fs == -1)
55664+ fsok = 1;
55665+
55666+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
55667+ for (i = 0; i < num; i++) {
55668+ curuid = (int)uidlist[i];
55669+ if (real == curuid)
55670+ realok = 1;
55671+ if (effective == curuid)
55672+ effectiveok = 1;
55673+ if (fs == curuid)
55674+ fsok = 1;
55675+ }
55676+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
55677+ for (i = 0; i < num; i++) {
55678+ curuid = (int)uidlist[i];
55679+ if (real == curuid)
55680+ break;
55681+ if (effective == curuid)
55682+ break;
55683+ if (fs == curuid)
55684+ break;
55685+ }
55686+ /* not in deny list */
55687+ if (i == num) {
55688+ realok = 1;
55689+ effectiveok = 1;
55690+ fsok = 1;
55691+ }
55692+ }
55693+
55694+ if (realok && effectiveok && fsok)
55695+ return 0;
55696+ else {
55697+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55698+ return 1;
55699+ }
55700+}
55701+
55702+int
55703+gr_check_group_change(int real, int effective, int fs)
55704+{
55705+ unsigned int i;
55706+ __u16 num;
55707+ gid_t *gidlist;
55708+ int curgid;
55709+ int realok = 0;
55710+ int effectiveok = 0;
55711+ int fsok = 0;
55712+
55713+ if (unlikely(!(gr_status & GR_READY)))
55714+ return 0;
55715+
55716+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55717+ gr_log_learn_id_change('g', real, effective, fs);
55718+
55719+ num = current->acl->group_trans_num;
55720+ gidlist = current->acl->group_transitions;
55721+
55722+ if (gidlist == NULL)
55723+ return 0;
55724+
55725+ if (real == -1)
55726+ realok = 1;
55727+ if (effective == -1)
55728+ effectiveok = 1;
55729+ if (fs == -1)
55730+ fsok = 1;
55731+
55732+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
55733+ for (i = 0; i < num; i++) {
55734+ curgid = (int)gidlist[i];
55735+ if (real == curgid)
55736+ realok = 1;
55737+ if (effective == curgid)
55738+ effectiveok = 1;
55739+ if (fs == curgid)
55740+ fsok = 1;
55741+ }
55742+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
55743+ for (i = 0; i < num; i++) {
55744+ curgid = (int)gidlist[i];
55745+ if (real == curgid)
55746+ break;
55747+ if (effective == curgid)
55748+ break;
55749+ if (fs == curgid)
55750+ break;
55751+ }
55752+ /* not in deny list */
55753+ if (i == num) {
55754+ realok = 1;
55755+ effectiveok = 1;
55756+ fsok = 1;
55757+ }
55758+ }
55759+
55760+ if (realok && effectiveok && fsok)
55761+ return 0;
55762+ else {
55763+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
55764+ return 1;
55765+ }
55766+}
55767+
55768+extern int gr_acl_is_capable(const int cap);
55769+
55770+void
55771+gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
55772+{
55773+ struct acl_role_label *role = task->role;
55774+ struct acl_subject_label *subj = NULL;
55775+ struct acl_object_label *obj;
55776+ struct file *filp;
55777+
55778+ if (unlikely(!(gr_status & GR_READY)))
55779+ return;
55780+
55781+ filp = task->exec_file;
55782+
55783+ /* kernel process, we'll give them the kernel role */
55784+ if (unlikely(!filp)) {
55785+ task->role = kernel_role;
55786+ task->acl = kernel_role->root_label;
55787+ return;
55788+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
55789+ role = lookup_acl_role_label(task, uid, gid);
55790+
55791+ /* don't change the role if we're not a privileged process */
55792+ if (role && task->role != role &&
55793+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
55794+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
55795+ return;
55796+
55797+ /* perform subject lookup in possibly new role
55798+ we can use this result below in the case where role == task->role
55799+ */
55800+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
55801+
55802+ /* if we changed uid/gid, but result in the same role
55803+ and are using inheritance, don't lose the inherited subject
55804+ if current subject is other than what normal lookup
55805+ would result in, we arrived via inheritance, don't
55806+ lose subject
55807+ */
55808+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
55809+ (subj == task->acl)))
55810+ task->acl = subj;
55811+
55812+ task->role = role;
55813+
55814+ task->is_writable = 0;
55815+
55816+ /* ignore additional mmap checks for processes that are writable
55817+ by the default ACL */
55818+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55819+ if (unlikely(obj->mode & GR_WRITE))
55820+ task->is_writable = 1;
55821+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55822+ if (unlikely(obj->mode & GR_WRITE))
55823+ task->is_writable = 1;
55824+
55825+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55826+ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55827+#endif
55828+
55829+ gr_set_proc_res(task);
55830+
55831+ return;
55832+}
55833+
55834+int
55835+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
55836+ const int unsafe_flags)
55837+{
55838+ struct task_struct *task = current;
55839+ struct acl_subject_label *newacl;
55840+ struct acl_object_label *obj;
55841+ __u32 retmode;
55842+
55843+ if (unlikely(!(gr_status & GR_READY)))
55844+ return 0;
55845+
55846+ newacl = chk_subj_label(dentry, mnt, task->role);
55847+
55848+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
55849+ did an exec
55850+ */
55851+ rcu_read_lock();
55852+ read_lock(&tasklist_lock);
55853+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
55854+ (task->parent->acl->mode & GR_POVERRIDE))) {
55855+ read_unlock(&tasklist_lock);
55856+ rcu_read_unlock();
55857+ goto skip_check;
55858+ }
55859+ read_unlock(&tasklist_lock);
55860+ rcu_read_unlock();
55861+
55862+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
55863+ !(task->role->roletype & GR_ROLE_GOD) &&
55864+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
55865+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
55866+ if (unsafe_flags & LSM_UNSAFE_SHARE)
55867+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
55868+ else
55869+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
55870+ return -EACCES;
55871+ }
55872+
55873+skip_check:
55874+
55875+ obj = chk_obj_label(dentry, mnt, task->acl);
55876+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
55877+
55878+ if (!(task->acl->mode & GR_INHERITLEARN) &&
55879+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
55880+ if (obj->nested)
55881+ task->acl = obj->nested;
55882+ else
55883+ task->acl = newacl;
55884+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
55885+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
55886+
55887+ task->is_writable = 0;
55888+
55889+ /* ignore additional mmap checks for processes that are writable
55890+ by the default ACL */
55891+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
55892+ if (unlikely(obj->mode & GR_WRITE))
55893+ task->is_writable = 1;
55894+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
55895+ if (unlikely(obj->mode & GR_WRITE))
55896+ task->is_writable = 1;
55897+
55898+ gr_set_proc_res(task);
55899+
55900+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55901+ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55902+#endif
55903+ return 0;
55904+}
55905+
55906+/* always called with valid inodev ptr */
55907+static void
55908+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
55909+{
55910+ struct acl_object_label *matchpo;
55911+ struct acl_subject_label *matchps;
55912+ struct acl_subject_label *subj;
55913+ struct acl_role_label *role;
55914+ unsigned int x;
55915+
55916+ FOR_EACH_ROLE_START(role)
55917+ FOR_EACH_SUBJECT_START(role, subj, x)
55918+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55919+ matchpo->mode |= GR_DELETED;
55920+ FOR_EACH_SUBJECT_END(subj,x)
55921+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
55922+ /* nested subjects aren't in the role's subj_hash table */
55923+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
55924+ matchpo->mode |= GR_DELETED;
55925+ FOR_EACH_NESTED_SUBJECT_END(subj)
55926+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
55927+ matchps->mode |= GR_DELETED;
55928+ FOR_EACH_ROLE_END(role)
55929+
55930+ inodev->nentry->deleted = 1;
55931+
55932+ return;
55933+}
55934+
55935+void
55936+gr_handle_delete(const ino_t ino, const dev_t dev)
55937+{
55938+ struct inodev_entry *inodev;
55939+
55940+ if (unlikely(!(gr_status & GR_READY)))
55941+ return;
55942+
55943+ write_lock(&gr_inode_lock);
55944+ inodev = lookup_inodev_entry(ino, dev);
55945+ if (inodev != NULL)
55946+ do_handle_delete(inodev, ino, dev);
55947+ write_unlock(&gr_inode_lock);
55948+
55949+ return;
55950+}
55951+
55952+static void
55953+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
55954+ const ino_t newinode, const dev_t newdevice,
55955+ struct acl_subject_label *subj)
55956+{
55957+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
55958+ struct acl_object_label *match;
55959+
55960+ match = subj->obj_hash[index];
55961+
55962+ while (match && (match->inode != oldinode ||
55963+ match->device != olddevice ||
55964+ !(match->mode & GR_DELETED)))
55965+ match = match->next;
55966+
55967+ if (match && (match->inode == oldinode)
55968+ && (match->device == olddevice)
55969+ && (match->mode & GR_DELETED)) {
55970+ if (match->prev == NULL) {
55971+ subj->obj_hash[index] = match->next;
55972+ if (match->next != NULL)
55973+ match->next->prev = NULL;
55974+ } else {
55975+ match->prev->next = match->next;
55976+ if (match->next != NULL)
55977+ match->next->prev = match->prev;
55978+ }
55979+ match->prev = NULL;
55980+ match->next = NULL;
55981+ match->inode = newinode;
55982+ match->device = newdevice;
55983+ match->mode &= ~GR_DELETED;
55984+
55985+ insert_acl_obj_label(match, subj);
55986+ }
55987+
55988+ return;
55989+}
55990+
55991+static void
55992+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
55993+ const ino_t newinode, const dev_t newdevice,
55994+ struct acl_role_label *role)
55995+{
55996+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
55997+ struct acl_subject_label *match;
55998+
55999+ match = role->subj_hash[index];
56000+
56001+ while (match && (match->inode != oldinode ||
56002+ match->device != olddevice ||
56003+ !(match->mode & GR_DELETED)))
56004+ match = match->next;
56005+
56006+ if (match && (match->inode == oldinode)
56007+ && (match->device == olddevice)
56008+ && (match->mode & GR_DELETED)) {
56009+ if (match->prev == NULL) {
56010+ role->subj_hash[index] = match->next;
56011+ if (match->next != NULL)
56012+ match->next->prev = NULL;
56013+ } else {
56014+ match->prev->next = match->next;
56015+ if (match->next != NULL)
56016+ match->next->prev = match->prev;
56017+ }
56018+ match->prev = NULL;
56019+ match->next = NULL;
56020+ match->inode = newinode;
56021+ match->device = newdevice;
56022+ match->mode &= ~GR_DELETED;
56023+
56024+ insert_acl_subj_label(match, role);
56025+ }
56026+
56027+ return;
56028+}
56029+
56030+static void
56031+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
56032+ const ino_t newinode, const dev_t newdevice)
56033+{
56034+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
56035+ struct inodev_entry *match;
56036+
56037+ match = inodev_set.i_hash[index];
56038+
56039+ while (match && (match->nentry->inode != oldinode ||
56040+ match->nentry->device != olddevice || !match->nentry->deleted))
56041+ match = match->next;
56042+
56043+ if (match && (match->nentry->inode == oldinode)
56044+ && (match->nentry->device == olddevice) &&
56045+ match->nentry->deleted) {
56046+ if (match->prev == NULL) {
56047+ inodev_set.i_hash[index] = match->next;
56048+ if (match->next != NULL)
56049+ match->next->prev = NULL;
56050+ } else {
56051+ match->prev->next = match->next;
56052+ if (match->next != NULL)
56053+ match->next->prev = match->prev;
56054+ }
56055+ match->prev = NULL;
56056+ match->next = NULL;
56057+ match->nentry->inode = newinode;
56058+ match->nentry->device = newdevice;
56059+ match->nentry->deleted = 0;
56060+
56061+ insert_inodev_entry(match);
56062+ }
56063+
56064+ return;
56065+}
56066+
56067+static void
56068+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
56069+{
56070+ struct acl_subject_label *subj;
56071+ struct acl_role_label *role;
56072+ unsigned int x;
56073+
56074+ FOR_EACH_ROLE_START(role)
56075+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
56076+
56077+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
56078+ if ((subj->inode == ino) && (subj->device == dev)) {
56079+ subj->inode = ino;
56080+ subj->device = dev;
56081+ }
56082+ /* nested subjects aren't in the role's subj_hash table */
56083+ update_acl_obj_label(matchn->inode, matchn->device,
56084+ ino, dev, subj);
56085+ FOR_EACH_NESTED_SUBJECT_END(subj)
56086+ FOR_EACH_SUBJECT_START(role, subj, x)
56087+ update_acl_obj_label(matchn->inode, matchn->device,
56088+ ino, dev, subj);
56089+ FOR_EACH_SUBJECT_END(subj,x)
56090+ FOR_EACH_ROLE_END(role)
56091+
56092+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
56093+
56094+ return;
56095+}
56096+
56097+static void
56098+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
56099+ const struct vfsmount *mnt)
56100+{
56101+ ino_t ino = dentry->d_inode->i_ino;
56102+ dev_t dev = __get_dev(dentry);
56103+
56104+ __do_handle_create(matchn, ino, dev);
56105+
56106+ return;
56107+}
56108+
56109+void
56110+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
56111+{
56112+ struct name_entry *matchn;
56113+
56114+ if (unlikely(!(gr_status & GR_READY)))
56115+ return;
56116+
56117+ preempt_disable();
56118+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
56119+
56120+ if (unlikely((unsigned long)matchn)) {
56121+ write_lock(&gr_inode_lock);
56122+ do_handle_create(matchn, dentry, mnt);
56123+ write_unlock(&gr_inode_lock);
56124+ }
56125+ preempt_enable();
56126+
56127+ return;
56128+}
56129+
56130+void
56131+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
56132+{
56133+ struct name_entry *matchn;
56134+
56135+ if (unlikely(!(gr_status & GR_READY)))
56136+ return;
56137+
56138+ preempt_disable();
56139+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
56140+
56141+ if (unlikely((unsigned long)matchn)) {
56142+ write_lock(&gr_inode_lock);
56143+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
56144+ write_unlock(&gr_inode_lock);
56145+ }
56146+ preempt_enable();
56147+
56148+ return;
56149+}
56150+
56151+void
56152+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
56153+ struct dentry *old_dentry,
56154+ struct dentry *new_dentry,
56155+ struct vfsmount *mnt, const __u8 replace)
56156+{
56157+ struct name_entry *matchn;
56158+ struct inodev_entry *inodev;
56159+ struct inode *inode = new_dentry->d_inode;
56160+ ino_t old_ino = old_dentry->d_inode->i_ino;
56161+ dev_t old_dev = __get_dev(old_dentry);
56162+
56163+ /* vfs_rename swaps the name and parent link for old_dentry and
56164+ new_dentry
56165+ at this point, old_dentry has the new name, parent link, and inode
56166+ for the renamed file
56167+ if a file is being replaced by a rename, new_dentry has the inode
56168+ and name for the replaced file
56169+ */
56170+
56171+ if (unlikely(!(gr_status & GR_READY)))
56172+ return;
56173+
56174+ preempt_disable();
56175+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
56176+
56177+ /* we wouldn't have to check d_inode if it weren't for
56178+ NFS silly-renaming
56179+ */
56180+
56181+ write_lock(&gr_inode_lock);
56182+ if (unlikely(replace && inode)) {
56183+ ino_t new_ino = inode->i_ino;
56184+ dev_t new_dev = __get_dev(new_dentry);
56185+
56186+ inodev = lookup_inodev_entry(new_ino, new_dev);
56187+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
56188+ do_handle_delete(inodev, new_ino, new_dev);
56189+ }
56190+
56191+ inodev = lookup_inodev_entry(old_ino, old_dev);
56192+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
56193+ do_handle_delete(inodev, old_ino, old_dev);
56194+
56195+ if (unlikely((unsigned long)matchn))
56196+ do_handle_create(matchn, old_dentry, mnt);
56197+
56198+ write_unlock(&gr_inode_lock);
56199+ preempt_enable();
56200+
56201+ return;
56202+}
56203+
56204+static int
56205+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
56206+ unsigned char **sum)
56207+{
56208+ struct acl_role_label *r;
56209+ struct role_allowed_ip *ipp;
56210+ struct role_transition *trans;
56211+ unsigned int i;
56212+ int found = 0;
56213+ u32 curr_ip = current->signal->curr_ip;
56214+
56215+ current->signal->saved_ip = curr_ip;
56216+
56217+ /* check transition table */
56218+
56219+ for (trans = current->role->transitions; trans; trans = trans->next) {
56220+ if (!strcmp(rolename, trans->rolename)) {
56221+ found = 1;
56222+ break;
56223+ }
56224+ }
56225+
56226+ if (!found)
56227+ return 0;
56228+
56229+ /* handle special roles that do not require authentication
56230+ and check ip */
56231+
56232+ FOR_EACH_ROLE_START(r)
56233+ if (!strcmp(rolename, r->rolename) &&
56234+ (r->roletype & GR_ROLE_SPECIAL)) {
56235+ found = 0;
56236+ if (r->allowed_ips != NULL) {
56237+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
56238+ if ((ntohl(curr_ip) & ipp->netmask) ==
56239+ (ntohl(ipp->addr) & ipp->netmask))
56240+ found = 1;
56241+ }
56242+ } else
56243+ found = 2;
56244+ if (!found)
56245+ return 0;
56246+
56247+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
56248+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
56249+ *salt = NULL;
56250+ *sum = NULL;
56251+ return 1;
56252+ }
56253+ }
56254+ FOR_EACH_ROLE_END(r)
56255+
56256+ for (i = 0; i < num_sprole_pws; i++) {
56257+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
56258+ *salt = acl_special_roles[i]->salt;
56259+ *sum = acl_special_roles[i]->sum;
56260+ return 1;
56261+ }
56262+ }
56263+
56264+ return 0;
56265+}
56266+
56267+static void
56268+assign_special_role(char *rolename)
56269+{
56270+ struct acl_object_label *obj;
56271+ struct acl_role_label *r;
56272+ struct acl_role_label *assigned = NULL;
56273+ struct task_struct *tsk;
56274+ struct file *filp;
56275+
56276+ FOR_EACH_ROLE_START(r)
56277+ if (!strcmp(rolename, r->rolename) &&
56278+ (r->roletype & GR_ROLE_SPECIAL)) {
56279+ assigned = r;
56280+ break;
56281+ }
56282+ FOR_EACH_ROLE_END(r)
56283+
56284+ if (!assigned)
56285+ return;
56286+
56287+ read_lock(&tasklist_lock);
56288+ read_lock(&grsec_exec_file_lock);
56289+
56290+ tsk = current->real_parent;
56291+ if (tsk == NULL)
56292+ goto out_unlock;
56293+
56294+ filp = tsk->exec_file;
56295+ if (filp == NULL)
56296+ goto out_unlock;
56297+
56298+ tsk->is_writable = 0;
56299+
56300+ tsk->acl_sp_role = 1;
56301+ tsk->acl_role_id = ++acl_sp_role_value;
56302+ tsk->role = assigned;
56303+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
56304+
56305+ /* ignore additional mmap checks for processes that are writable
56306+ by the default ACL */
56307+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56308+ if (unlikely(obj->mode & GR_WRITE))
56309+ tsk->is_writable = 1;
56310+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
56311+ if (unlikely(obj->mode & GR_WRITE))
56312+ tsk->is_writable = 1;
56313+
56314+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56315+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
56316+#endif
56317+
56318+out_unlock:
56319+ read_unlock(&grsec_exec_file_lock);
56320+ read_unlock(&tasklist_lock);
56321+ return;
56322+}
56323+
56324+int gr_check_secure_terminal(struct task_struct *task)
56325+{
56326+ struct task_struct *p, *p2, *p3;
56327+ struct files_struct *files;
56328+ struct fdtable *fdt;
56329+ struct file *our_file = NULL, *file;
56330+ int i;
56331+
56332+ if (task->signal->tty == NULL)
56333+ return 1;
56334+
56335+ files = get_files_struct(task);
56336+ if (files != NULL) {
56337+ rcu_read_lock();
56338+ fdt = files_fdtable(files);
56339+ for (i=0; i < fdt->max_fds; i++) {
56340+ file = fcheck_files(files, i);
56341+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
56342+ get_file(file);
56343+ our_file = file;
56344+ }
56345+ }
56346+ rcu_read_unlock();
56347+ put_files_struct(files);
56348+ }
56349+
56350+ if (our_file == NULL)
56351+ return 1;
56352+
56353+ read_lock(&tasklist_lock);
56354+ do_each_thread(p2, p) {
56355+ files = get_files_struct(p);
56356+ if (files == NULL ||
56357+ (p->signal && p->signal->tty == task->signal->tty)) {
56358+ if (files != NULL)
56359+ put_files_struct(files);
56360+ continue;
56361+ }
56362+ rcu_read_lock();
56363+ fdt = files_fdtable(files);
56364+ for (i=0; i < fdt->max_fds; i++) {
56365+ file = fcheck_files(files, i);
56366+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
56367+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
56368+ p3 = task;
56369+ while (p3->pid > 0) {
56370+ if (p3 == p)
56371+ break;
56372+ p3 = p3->real_parent;
56373+ }
56374+ if (p3 == p)
56375+ break;
56376+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
56377+ gr_handle_alertkill(p);
56378+ rcu_read_unlock();
56379+ put_files_struct(files);
56380+ read_unlock(&tasklist_lock);
56381+ fput(our_file);
56382+ return 0;
56383+ }
56384+ }
56385+ rcu_read_unlock();
56386+ put_files_struct(files);
56387+ } while_each_thread(p2, p);
56388+ read_unlock(&tasklist_lock);
56389+
56390+ fput(our_file);
56391+ return 1;
56392+}
56393+
56394+static int gr_rbac_disable(void *unused)
56395+{
56396+ pax_open_kernel();
56397+ gr_status &= ~GR_READY;
56398+ pax_close_kernel();
56399+
56400+ return 0;
56401+}
56402+
56403+ssize_t
56404+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
56405+{
56406+ struct gr_arg_wrapper uwrap;
56407+ unsigned char *sprole_salt = NULL;
56408+ unsigned char *sprole_sum = NULL;
56409+ int error = sizeof (struct gr_arg_wrapper);
56410+ int error2 = 0;
56411+
56412+ mutex_lock(&gr_dev_mutex);
56413+
56414+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
56415+ error = -EPERM;
56416+ goto out;
56417+ }
56418+
56419+ if (count != sizeof (struct gr_arg_wrapper)) {
56420+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
56421+ error = -EINVAL;
56422+ goto out;
56423+ }
56424+
56425+
56426+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
56427+ gr_auth_expires = 0;
56428+ gr_auth_attempts = 0;
56429+ }
56430+
56431+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
56432+ error = -EFAULT;
56433+ goto out;
56434+ }
56435+
56436+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
56437+ error = -EINVAL;
56438+ goto out;
56439+ }
56440+
56441+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
56442+ error = -EFAULT;
56443+ goto out;
56444+ }
56445+
56446+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56447+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56448+ time_after(gr_auth_expires, get_seconds())) {
56449+ error = -EBUSY;
56450+ goto out;
56451+ }
56452+
56453+ /* if non-root trying to do anything other than use a special role,
56454+ do not attempt authentication, do not count towards authentication
56455+ locking
56456+ */
56457+
56458+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
56459+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
56460+ !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
56461+ error = -EPERM;
56462+ goto out;
56463+ }
56464+
56465+ /* ensure pw and special role name are null terminated */
56466+
56467+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
56468+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
56469+
56470+ /* Okay.
56471+ * We have our enough of the argument structure..(we have yet
56472+ * to copy_from_user the tables themselves) . Copy the tables
56473+ * only if we need them, i.e. for loading operations. */
56474+
56475+ switch (gr_usermode->mode) {
56476+ case GR_STATUS:
56477+ if (gr_status & GR_READY) {
56478+ error = 1;
56479+ if (!gr_check_secure_terminal(current))
56480+ error = 3;
56481+ } else
56482+ error = 2;
56483+ goto out;
56484+ case GR_SHUTDOWN:
56485+ if ((gr_status & GR_READY)
56486+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56487+ stop_machine(gr_rbac_disable, NULL, NULL);
56488+ free_variables();
56489+ memset(gr_usermode, 0, sizeof (struct gr_arg));
56490+ memset(gr_system_salt, 0, GR_SALT_LEN);
56491+ memset(gr_system_sum, 0, GR_SHA_LEN);
56492+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
56493+ } else if (gr_status & GR_READY) {
56494+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
56495+ error = -EPERM;
56496+ } else {
56497+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
56498+ error = -EAGAIN;
56499+ }
56500+ break;
56501+ case GR_ENABLE:
56502+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
56503+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
56504+ else {
56505+ if (gr_status & GR_READY)
56506+ error = -EAGAIN;
56507+ else
56508+ error = error2;
56509+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
56510+ }
56511+ break;
56512+ case GR_RELOAD:
56513+ if (!(gr_status & GR_READY)) {
56514+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
56515+ error = -EAGAIN;
56516+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56517+ stop_machine(gr_rbac_disable, NULL, NULL);
56518+ free_variables();
56519+ error2 = gracl_init(gr_usermode);
56520+ if (!error2)
56521+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
56522+ else {
56523+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56524+ error = error2;
56525+ }
56526+ } else {
56527+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
56528+ error = -EPERM;
56529+ }
56530+ break;
56531+ case GR_SEGVMOD:
56532+ if (unlikely(!(gr_status & GR_READY))) {
56533+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
56534+ error = -EAGAIN;
56535+ break;
56536+ }
56537+
56538+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
56539+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
56540+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
56541+ struct acl_subject_label *segvacl;
56542+ segvacl =
56543+ lookup_acl_subj_label(gr_usermode->segv_inode,
56544+ gr_usermode->segv_device,
56545+ current->role);
56546+ if (segvacl) {
56547+ segvacl->crashes = 0;
56548+ segvacl->expires = 0;
56549+ }
56550+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
56551+ gr_remove_uid(gr_usermode->segv_uid);
56552+ }
56553+ } else {
56554+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
56555+ error = -EPERM;
56556+ }
56557+ break;
56558+ case GR_SPROLE:
56559+ case GR_SPROLEPAM:
56560+ if (unlikely(!(gr_status & GR_READY))) {
56561+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
56562+ error = -EAGAIN;
56563+ break;
56564+ }
56565+
56566+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
56567+ current->role->expires = 0;
56568+ current->role->auth_attempts = 0;
56569+ }
56570+
56571+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
56572+ time_after(current->role->expires, get_seconds())) {
56573+ error = -EBUSY;
56574+ goto out;
56575+ }
56576+
56577+ if (lookup_special_role_auth
56578+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
56579+ && ((!sprole_salt && !sprole_sum)
56580+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
56581+ char *p = "";
56582+ assign_special_role(gr_usermode->sp_role);
56583+ read_lock(&tasklist_lock);
56584+ if (current->real_parent)
56585+ p = current->real_parent->role->rolename;
56586+ read_unlock(&tasklist_lock);
56587+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
56588+ p, acl_sp_role_value);
56589+ } else {
56590+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
56591+ error = -EPERM;
56592+ if(!(current->role->auth_attempts++))
56593+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56594+
56595+ goto out;
56596+ }
56597+ break;
56598+ case GR_UNSPROLE:
56599+ if (unlikely(!(gr_status & GR_READY))) {
56600+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
56601+ error = -EAGAIN;
56602+ break;
56603+ }
56604+
56605+ if (current->role->roletype & GR_ROLE_SPECIAL) {
56606+ char *p = "";
56607+ int i = 0;
56608+
56609+ read_lock(&tasklist_lock);
56610+ if (current->real_parent) {
56611+ p = current->real_parent->role->rolename;
56612+ i = current->real_parent->acl_role_id;
56613+ }
56614+ read_unlock(&tasklist_lock);
56615+
56616+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
56617+ gr_set_acls(1);
56618+ } else {
56619+ error = -EPERM;
56620+ goto out;
56621+ }
56622+ break;
56623+ default:
56624+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
56625+ error = -EINVAL;
56626+ break;
56627+ }
56628+
56629+ if (error != -EPERM)
56630+ goto out;
56631+
56632+ if(!(gr_auth_attempts++))
56633+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
56634+
56635+ out:
56636+ mutex_unlock(&gr_dev_mutex);
56637+ return error;
56638+}
56639+
56640+/* must be called with
56641+ rcu_read_lock();
56642+ read_lock(&tasklist_lock);
56643+ read_lock(&grsec_exec_file_lock);
56644+*/
56645+int gr_apply_subject_to_task(struct task_struct *task)
56646+{
56647+ struct acl_object_label *obj;
56648+ char *tmpname;
56649+ struct acl_subject_label *tmpsubj;
56650+ struct file *filp;
56651+ struct name_entry *nmatch;
56652+
56653+ filp = task->exec_file;
56654+ if (filp == NULL)
56655+ return 0;
56656+
56657+ /* the following is to apply the correct subject
56658+ on binaries running when the RBAC system
56659+ is enabled, when the binaries have been
56660+ replaced or deleted since their execution
56661+ -----
56662+ when the RBAC system starts, the inode/dev
56663+ from exec_file will be one the RBAC system
56664+ is unaware of. It only knows the inode/dev
56665+ of the present file on disk, or the absence
56666+ of it.
56667+ */
56668+ preempt_disable();
56669+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
56670+
56671+ nmatch = lookup_name_entry(tmpname);
56672+ preempt_enable();
56673+ tmpsubj = NULL;
56674+ if (nmatch) {
56675+ if (nmatch->deleted)
56676+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
56677+ else
56678+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
56679+ if (tmpsubj != NULL)
56680+ task->acl = tmpsubj;
56681+ }
56682+ if (tmpsubj == NULL)
56683+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
56684+ task->role);
56685+ if (task->acl) {
56686+ task->is_writable = 0;
56687+ /* ignore additional mmap checks for processes that are writable
56688+ by the default ACL */
56689+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
56690+ if (unlikely(obj->mode & GR_WRITE))
56691+ task->is_writable = 1;
56692+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
56693+ if (unlikely(obj->mode & GR_WRITE))
56694+ task->is_writable = 1;
56695+
56696+ gr_set_proc_res(task);
56697+
56698+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
56699+ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
56700+#endif
56701+ } else {
56702+ return 1;
56703+ }
56704+
56705+ return 0;
56706+}
56707+
56708+int
56709+gr_set_acls(const int type)
56710+{
56711+ struct task_struct *task, *task2;
56712+ struct acl_role_label *role = current->role;
56713+ __u16 acl_role_id = current->acl_role_id;
56714+ const struct cred *cred;
56715+ int ret;
56716+
56717+ rcu_read_lock();
56718+ read_lock(&tasklist_lock);
56719+ read_lock(&grsec_exec_file_lock);
56720+ do_each_thread(task2, task) {
56721+ /* check to see if we're called from the exit handler,
56722+ if so, only replace ACLs that have inherited the admin
56723+ ACL */
56724+
56725+ if (type && (task->role != role ||
56726+ task->acl_role_id != acl_role_id))
56727+ continue;
56728+
56729+ task->acl_role_id = 0;
56730+ task->acl_sp_role = 0;
56731+
56732+ if (task->exec_file) {
56733+ cred = __task_cred(task);
56734+ task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
56735+ ret = gr_apply_subject_to_task(task);
56736+ if (ret) {
56737+ read_unlock(&grsec_exec_file_lock);
56738+ read_unlock(&tasklist_lock);
56739+ rcu_read_unlock();
56740+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
56741+ return ret;
56742+ }
56743+ } else {
56744+ // it's a kernel process
56745+ task->role = kernel_role;
56746+ task->acl = kernel_role->root_label;
56747+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
56748+ task->acl->mode &= ~GR_PROCFIND;
56749+#endif
56750+ }
56751+ } while_each_thread(task2, task);
56752+ read_unlock(&grsec_exec_file_lock);
56753+ read_unlock(&tasklist_lock);
56754+ rcu_read_unlock();
56755+
56756+ return 0;
56757+}
56758+
56759+void
56760+gr_learn_resource(const struct task_struct *task,
56761+ const int res, const unsigned long wanted, const int gt)
56762+{
56763+ struct acl_subject_label *acl;
56764+ const struct cred *cred;
56765+
56766+ if (unlikely((gr_status & GR_READY) &&
56767+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
56768+ goto skip_reslog;
56769+
56770+#ifdef CONFIG_GRKERNSEC_RESLOG
56771+ gr_log_resource(task, res, wanted, gt);
56772+#endif
56773+ skip_reslog:
56774+
56775+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
56776+ return;
56777+
56778+ acl = task->acl;
56779+
56780+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
56781+ !(acl->resmask & (1 << (unsigned short) res))))
56782+ return;
56783+
56784+ if (wanted >= acl->res[res].rlim_cur) {
56785+ unsigned long res_add;
56786+
56787+ res_add = wanted;
56788+ switch (res) {
56789+ case RLIMIT_CPU:
56790+ res_add += GR_RLIM_CPU_BUMP;
56791+ break;
56792+ case RLIMIT_FSIZE:
56793+ res_add += GR_RLIM_FSIZE_BUMP;
56794+ break;
56795+ case RLIMIT_DATA:
56796+ res_add += GR_RLIM_DATA_BUMP;
56797+ break;
56798+ case RLIMIT_STACK:
56799+ res_add += GR_RLIM_STACK_BUMP;
56800+ break;
56801+ case RLIMIT_CORE:
56802+ res_add += GR_RLIM_CORE_BUMP;
56803+ break;
56804+ case RLIMIT_RSS:
56805+ res_add += GR_RLIM_RSS_BUMP;
56806+ break;
56807+ case RLIMIT_NPROC:
56808+ res_add += GR_RLIM_NPROC_BUMP;
56809+ break;
56810+ case RLIMIT_NOFILE:
56811+ res_add += GR_RLIM_NOFILE_BUMP;
56812+ break;
56813+ case RLIMIT_MEMLOCK:
56814+ res_add += GR_RLIM_MEMLOCK_BUMP;
56815+ break;
56816+ case RLIMIT_AS:
56817+ res_add += GR_RLIM_AS_BUMP;
56818+ break;
56819+ case RLIMIT_LOCKS:
56820+ res_add += GR_RLIM_LOCKS_BUMP;
56821+ break;
56822+ case RLIMIT_SIGPENDING:
56823+ res_add += GR_RLIM_SIGPENDING_BUMP;
56824+ break;
56825+ case RLIMIT_MSGQUEUE:
56826+ res_add += GR_RLIM_MSGQUEUE_BUMP;
56827+ break;
56828+ case RLIMIT_NICE:
56829+ res_add += GR_RLIM_NICE_BUMP;
56830+ break;
56831+ case RLIMIT_RTPRIO:
56832+ res_add += GR_RLIM_RTPRIO_BUMP;
56833+ break;
56834+ case RLIMIT_RTTIME:
56835+ res_add += GR_RLIM_RTTIME_BUMP;
56836+ break;
56837+ }
56838+
56839+ acl->res[res].rlim_cur = res_add;
56840+
56841+ if (wanted > acl->res[res].rlim_max)
56842+ acl->res[res].rlim_max = res_add;
56843+
56844+ /* only log the subject filename, since resource logging is supported for
56845+ single-subject learning only */
56846+ rcu_read_lock();
56847+ cred = __task_cred(task);
56848+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
56849+ task->role->roletype, cred->uid, cred->gid, acl->filename,
56850+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
56851+ "", (unsigned long) res, &task->signal->saved_ip);
56852+ rcu_read_unlock();
56853+ }
56854+
56855+ return;
56856+}
56857+
56858+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
56859+void
56860+pax_set_initial_flags(struct linux_binprm *bprm)
56861+{
56862+ struct task_struct *task = current;
56863+ struct acl_subject_label *proc;
56864+ unsigned long flags;
56865+
56866+ if (unlikely(!(gr_status & GR_READY)))
56867+ return;
56868+
56869+ flags = pax_get_flags(task);
56870+
56871+ proc = task->acl;
56872+
56873+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
56874+ flags &= ~MF_PAX_PAGEEXEC;
56875+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
56876+ flags &= ~MF_PAX_SEGMEXEC;
56877+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
56878+ flags &= ~MF_PAX_RANDMMAP;
56879+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
56880+ flags &= ~MF_PAX_EMUTRAMP;
56881+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
56882+ flags &= ~MF_PAX_MPROTECT;
56883+
56884+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
56885+ flags |= MF_PAX_PAGEEXEC;
56886+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
56887+ flags |= MF_PAX_SEGMEXEC;
56888+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
56889+ flags |= MF_PAX_RANDMMAP;
56890+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
56891+ flags |= MF_PAX_EMUTRAMP;
56892+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
56893+ flags |= MF_PAX_MPROTECT;
56894+
56895+ pax_set_flags(task, flags);
56896+
56897+ return;
56898+}
56899+#endif
56900+
56901+int
56902+gr_handle_proc_ptrace(struct task_struct *task)
56903+{
56904+ struct file *filp;
56905+ struct task_struct *tmp = task;
56906+ struct task_struct *curtemp = current;
56907+ __u32 retmode;
56908+
56909+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56910+ if (unlikely(!(gr_status & GR_READY)))
56911+ return 0;
56912+#endif
56913+
56914+ read_lock(&tasklist_lock);
56915+ read_lock(&grsec_exec_file_lock);
56916+ filp = task->exec_file;
56917+
56918+ while (tmp->pid > 0) {
56919+ if (tmp == curtemp)
56920+ break;
56921+ tmp = tmp->real_parent;
56922+ }
56923+
56924+ if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56925+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
56926+ read_unlock(&grsec_exec_file_lock);
56927+ read_unlock(&tasklist_lock);
56928+ return 1;
56929+ }
56930+
56931+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56932+ if (!(gr_status & GR_READY)) {
56933+ read_unlock(&grsec_exec_file_lock);
56934+ read_unlock(&tasklist_lock);
56935+ return 0;
56936+ }
56937+#endif
56938+
56939+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
56940+ read_unlock(&grsec_exec_file_lock);
56941+ read_unlock(&tasklist_lock);
56942+
56943+ if (retmode & GR_NOPTRACE)
56944+ return 1;
56945+
56946+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
56947+ && (current->acl != task->acl || (current->acl != current->role->root_label
56948+ && current->pid != task->pid)))
56949+ return 1;
56950+
56951+ return 0;
56952+}
56953+
56954+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
56955+{
56956+ if (unlikely(!(gr_status & GR_READY)))
56957+ return;
56958+
56959+ if (!(current->role->roletype & GR_ROLE_GOD))
56960+ return;
56961+
56962+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
56963+ p->role->rolename, gr_task_roletype_to_char(p),
56964+ p->acl->filename);
56965+}
56966+
56967+int
56968+gr_handle_ptrace(struct task_struct *task, const long request)
56969+{
56970+ struct task_struct *tmp = task;
56971+ struct task_struct *curtemp = current;
56972+ __u32 retmode;
56973+
56974+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
56975+ if (unlikely(!(gr_status & GR_READY)))
56976+ return 0;
56977+#endif
56978+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
56979+ read_lock(&tasklist_lock);
56980+ while (tmp->pid > 0) {
56981+ if (tmp == curtemp)
56982+ break;
56983+ tmp = tmp->real_parent;
56984+ }
56985+
56986+ if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
56987+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
56988+ read_unlock(&tasklist_lock);
56989+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
56990+ return 1;
56991+ }
56992+ read_unlock(&tasklist_lock);
56993+ }
56994+
56995+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
56996+ if (!(gr_status & GR_READY))
56997+ return 0;
56998+#endif
56999+
57000+ read_lock(&grsec_exec_file_lock);
57001+ if (unlikely(!task->exec_file)) {
57002+ read_unlock(&grsec_exec_file_lock);
57003+ return 0;
57004+ }
57005+
57006+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
57007+ read_unlock(&grsec_exec_file_lock);
57008+
57009+ if (retmode & GR_NOPTRACE) {
57010+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57011+ return 1;
57012+ }
57013+
57014+ if (retmode & GR_PTRACERD) {
57015+ switch (request) {
57016+ case PTRACE_SEIZE:
57017+ case PTRACE_POKETEXT:
57018+ case PTRACE_POKEDATA:
57019+ case PTRACE_POKEUSR:
57020+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
57021+ case PTRACE_SETREGS:
57022+ case PTRACE_SETFPREGS:
57023+#endif
57024+#ifdef CONFIG_X86
57025+ case PTRACE_SETFPXREGS:
57026+#endif
57027+#ifdef CONFIG_ALTIVEC
57028+ case PTRACE_SETVRREGS:
57029+#endif
57030+ return 1;
57031+ default:
57032+ return 0;
57033+ }
57034+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
57035+ !(current->role->roletype & GR_ROLE_GOD) &&
57036+ (current->acl != task->acl)) {
57037+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
57038+ return 1;
57039+ }
57040+
57041+ return 0;
57042+}
57043+
57044+static int is_writable_mmap(const struct file *filp)
57045+{
57046+ struct task_struct *task = current;
57047+ struct acl_object_label *obj, *obj2;
57048+
57049+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
57050+ !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))) {
57051+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
57052+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
57053+ task->role->root_label);
57054+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
57055+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
57056+ return 1;
57057+ }
57058+ }
57059+ return 0;
57060+}
57061+
57062+int
57063+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
57064+{
57065+ __u32 mode;
57066+
57067+ if (unlikely(!file || !(prot & PROT_EXEC)))
57068+ return 1;
57069+
57070+ if (is_writable_mmap(file))
57071+ return 0;
57072+
57073+ mode =
57074+ gr_search_file(file->f_path.dentry,
57075+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57076+ file->f_path.mnt);
57077+
57078+ if (!gr_tpe_allow(file))
57079+ return 0;
57080+
57081+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57082+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57083+ return 0;
57084+ } else if (unlikely(!(mode & GR_EXEC))) {
57085+ return 0;
57086+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57087+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57088+ return 1;
57089+ }
57090+
57091+ return 1;
57092+}
57093+
57094+int
57095+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
57096+{
57097+ __u32 mode;
57098+
57099+ if (unlikely(!file || !(prot & PROT_EXEC)))
57100+ return 1;
57101+
57102+ if (is_writable_mmap(file))
57103+ return 0;
57104+
57105+ mode =
57106+ gr_search_file(file->f_path.dentry,
57107+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
57108+ file->f_path.mnt);
57109+
57110+ if (!gr_tpe_allow(file))
57111+ return 0;
57112+
57113+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
57114+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57115+ return 0;
57116+ } else if (unlikely(!(mode & GR_EXEC))) {
57117+ return 0;
57118+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
57119+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
57120+ return 1;
57121+ }
57122+
57123+ return 1;
57124+}
57125+
57126+void
57127+gr_acl_handle_psacct(struct task_struct *task, const long code)
57128+{
57129+ unsigned long runtime;
57130+ unsigned long cputime;
57131+ unsigned int wday, cday;
57132+ __u8 whr, chr;
57133+ __u8 wmin, cmin;
57134+ __u8 wsec, csec;
57135+ struct timespec timeval;
57136+
57137+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
57138+ !(task->acl->mode & GR_PROCACCT)))
57139+ return;
57140+
57141+ do_posix_clock_monotonic_gettime(&timeval);
57142+ runtime = timeval.tv_sec - task->start_time.tv_sec;
57143+ wday = runtime / (3600 * 24);
57144+ runtime -= wday * (3600 * 24);
57145+ whr = runtime / 3600;
57146+ runtime -= whr * 3600;
57147+ wmin = runtime / 60;
57148+ runtime -= wmin * 60;
57149+ wsec = runtime;
57150+
57151+ cputime = (task->utime + task->stime) / HZ;
57152+ cday = cputime / (3600 * 24);
57153+ cputime -= cday * (3600 * 24);
57154+ chr = cputime / 3600;
57155+ cputime -= chr * 3600;
57156+ cmin = cputime / 60;
57157+ cputime -= cmin * 60;
57158+ csec = cputime;
57159+
57160+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
57161+
57162+ return;
57163+}
57164+
57165+void gr_set_kernel_label(struct task_struct *task)
57166+{
57167+ if (gr_status & GR_READY) {
57168+ task->role = kernel_role;
57169+ task->acl = kernel_role->root_label;
57170+ }
57171+ return;
57172+}
57173+
57174+#ifdef CONFIG_TASKSTATS
57175+int gr_is_taskstats_denied(int pid)
57176+{
57177+ struct task_struct *task;
57178+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57179+ const struct cred *cred;
57180+#endif
57181+ int ret = 0;
57182+
57183+ /* restrict taskstats viewing to un-chrooted root users
57184+ who have the 'view' subject flag if the RBAC system is enabled
57185+ */
57186+
57187+ rcu_read_lock();
57188+ read_lock(&tasklist_lock);
57189+ task = find_task_by_vpid(pid);
57190+ if (task) {
57191+#ifdef CONFIG_GRKERNSEC_CHROOT
57192+ if (proc_is_chrooted(task))
57193+ ret = -EACCES;
57194+#endif
57195+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57196+ cred = __task_cred(task);
57197+#ifdef CONFIG_GRKERNSEC_PROC_USER
57198+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
57199+ ret = -EACCES;
57200+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
57201+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
57202+ ret = -EACCES;
57203+#endif
57204+#endif
57205+ if (gr_status & GR_READY) {
57206+ if (!(task->acl->mode & GR_VIEW))
57207+ ret = -EACCES;
57208+ }
57209+ } else
57210+ ret = -ENOENT;
57211+
57212+ read_unlock(&tasklist_lock);
57213+ rcu_read_unlock();
57214+
57215+ return ret;
57216+}
57217+#endif
57218+
57219+/* AUXV entries are filled via a descendant of search_binary_handler
57220+ after we've already applied the subject for the target
57221+*/
57222+int gr_acl_enable_at_secure(void)
57223+{
57224+ if (unlikely(!(gr_status & GR_READY)))
57225+ return 0;
57226+
57227+ if (current->acl->mode & GR_ATSECURE)
57228+ return 1;
57229+
57230+ return 0;
57231+}
57232+
57233+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
57234+{
57235+ struct task_struct *task = current;
57236+ struct dentry *dentry = file->f_path.dentry;
57237+ struct vfsmount *mnt = file->f_path.mnt;
57238+ struct acl_object_label *obj, *tmp;
57239+ struct acl_subject_label *subj;
57240+ unsigned int bufsize;
57241+ int is_not_root;
57242+ char *path;
57243+ dev_t dev = __get_dev(dentry);
57244+
57245+ if (unlikely(!(gr_status & GR_READY)))
57246+ return 1;
57247+
57248+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
57249+ return 1;
57250+
57251+ /* ignore Eric Biederman */
57252+ if (IS_PRIVATE(dentry->d_inode))
57253+ return 1;
57254+
57255+ subj = task->acl;
57256+ read_lock(&gr_inode_lock);
57257+ do {
57258+ obj = lookup_acl_obj_label(ino, dev, subj);
57259+ if (obj != NULL) {
57260+ read_unlock(&gr_inode_lock);
57261+ return (obj->mode & GR_FIND) ? 1 : 0;
57262+ }
57263+ } while ((subj = subj->parent_subject));
57264+ read_unlock(&gr_inode_lock);
57265+
57266+ /* this is purely an optimization since we're looking for an object
57267+ for the directory we're doing a readdir on
57268+ if it's possible for any globbed object to match the entry we're
57269+ filling into the directory, then the object we find here will be
57270+ an anchor point with attached globbed objects
57271+ */
57272+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
57273+ if (obj->globbed == NULL)
57274+ return (obj->mode & GR_FIND) ? 1 : 0;
57275+
57276+ is_not_root = ((obj->filename[0] == '/') &&
57277+ (obj->filename[1] == '\0')) ? 0 : 1;
57278+ bufsize = PAGE_SIZE - namelen - is_not_root;
57279+
57280+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
57281+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
57282+ return 1;
57283+
57284+ preempt_disable();
57285+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57286+ bufsize);
57287+
57288+ bufsize = strlen(path);
57289+
57290+ /* if base is "/", don't append an additional slash */
57291+ if (is_not_root)
57292+ *(path + bufsize) = '/';
57293+ memcpy(path + bufsize + is_not_root, name, namelen);
57294+ *(path + bufsize + namelen + is_not_root) = '\0';
57295+
57296+ tmp = obj->globbed;
57297+ while (tmp) {
57298+ if (!glob_match(tmp->filename, path)) {
57299+ preempt_enable();
57300+ return (tmp->mode & GR_FIND) ? 1 : 0;
57301+ }
57302+ tmp = tmp->next;
57303+ }
57304+ preempt_enable();
57305+ return (obj->mode & GR_FIND) ? 1 : 0;
57306+}
57307+
57308+void gr_put_exec_file(struct task_struct *task)
57309+{
57310+ struct file *filp;
57311+
57312+ write_lock(&grsec_exec_file_lock);
57313+ filp = task->exec_file;
57314+ task->exec_file = NULL;
57315+ write_unlock(&grsec_exec_file_lock);
57316+
57317+ if (filp)
57318+ fput(filp);
57319+
57320+ return;
57321+}
57322+
57323+
57324+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
57325+EXPORT_SYMBOL(gr_acl_is_enabled);
57326+#endif
57327+EXPORT_SYMBOL(gr_learn_resource);
57328+EXPORT_SYMBOL(gr_set_kernel_label);
57329+#ifdef CONFIG_SECURITY
57330+EXPORT_SYMBOL(gr_check_user_change);
57331+EXPORT_SYMBOL(gr_check_group_change);
57332+#endif
57333+
57334diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
57335new file mode 100644
57336index 0000000..34fefda
57337--- /dev/null
57338+++ b/grsecurity/gracl_alloc.c
57339@@ -0,0 +1,105 @@
57340+#include <linux/kernel.h>
57341+#include <linux/mm.h>
57342+#include <linux/slab.h>
57343+#include <linux/vmalloc.h>
57344+#include <linux/gracl.h>
57345+#include <linux/grsecurity.h>
57346+
57347+static unsigned long alloc_stack_next = 1;
57348+static unsigned long alloc_stack_size = 1;
57349+static void **alloc_stack;
57350+
57351+static __inline__ int
57352+alloc_pop(void)
57353+{
57354+ if (alloc_stack_next == 1)
57355+ return 0;
57356+
57357+ kfree(alloc_stack[alloc_stack_next - 2]);
57358+
57359+ alloc_stack_next--;
57360+
57361+ return 1;
57362+}
57363+
57364+static __inline__ int
57365+alloc_push(void *buf)
57366+{
57367+ if (alloc_stack_next >= alloc_stack_size)
57368+ return 1;
57369+
57370+ alloc_stack[alloc_stack_next - 1] = buf;
57371+
57372+ alloc_stack_next++;
57373+
57374+ return 0;
57375+}
57376+
57377+void *
57378+acl_alloc(unsigned long len)
57379+{
57380+ void *ret = NULL;
57381+
57382+ if (!len || len > PAGE_SIZE)
57383+ goto out;
57384+
57385+ ret = kmalloc(len, GFP_KERNEL);
57386+
57387+ if (ret) {
57388+ if (alloc_push(ret)) {
57389+ kfree(ret);
57390+ ret = NULL;
57391+ }
57392+ }
57393+
57394+out:
57395+ return ret;
57396+}
57397+
57398+void *
57399+acl_alloc_num(unsigned long num, unsigned long len)
57400+{
57401+ if (!len || (num > (PAGE_SIZE / len)))
57402+ return NULL;
57403+
57404+ return acl_alloc(num * len);
57405+}
57406+
57407+void
57408+acl_free_all(void)
57409+{
57410+ if (gr_acl_is_enabled() || !alloc_stack)
57411+ return;
57412+
57413+ while (alloc_pop()) ;
57414+
57415+ if (alloc_stack) {
57416+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
57417+ kfree(alloc_stack);
57418+ else
57419+ vfree(alloc_stack);
57420+ }
57421+
57422+ alloc_stack = NULL;
57423+ alloc_stack_size = 1;
57424+ alloc_stack_next = 1;
57425+
57426+ return;
57427+}
57428+
57429+int
57430+acl_alloc_stack_init(unsigned long size)
57431+{
57432+ if ((size * sizeof (void *)) <= PAGE_SIZE)
57433+ alloc_stack =
57434+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
57435+ else
57436+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
57437+
57438+ alloc_stack_size = size;
57439+
57440+ if (!alloc_stack)
57441+ return 0;
57442+ else
57443+ return 1;
57444+}
57445diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
57446new file mode 100644
57447index 0000000..6d21049
57448--- /dev/null
57449+++ b/grsecurity/gracl_cap.c
57450@@ -0,0 +1,110 @@
57451+#include <linux/kernel.h>
57452+#include <linux/module.h>
57453+#include <linux/sched.h>
57454+#include <linux/gracl.h>
57455+#include <linux/grsecurity.h>
57456+#include <linux/grinternal.h>
57457+
57458+extern const char *captab_log[];
57459+extern int captab_log_entries;
57460+
57461+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57462+{
57463+ struct acl_subject_label *curracl;
57464+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57465+ kernel_cap_t cap_audit = __cap_empty_set;
57466+
57467+ if (!gr_acl_is_enabled())
57468+ return 1;
57469+
57470+ curracl = task->acl;
57471+
57472+ cap_drop = curracl->cap_lower;
57473+ cap_mask = curracl->cap_mask;
57474+ cap_audit = curracl->cap_invert_audit;
57475+
57476+ while ((curracl = curracl->parent_subject)) {
57477+ /* if the cap isn't specified in the current computed mask but is specified in the
57478+ current level subject, and is lowered in the current level subject, then add
57479+ it to the set of dropped capabilities
57480+ otherwise, add the current level subject's mask to the current computed mask
57481+ */
57482+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57483+ cap_raise(cap_mask, cap);
57484+ if (cap_raised(curracl->cap_lower, cap))
57485+ cap_raise(cap_drop, cap);
57486+ if (cap_raised(curracl->cap_invert_audit, cap))
57487+ cap_raise(cap_audit, cap);
57488+ }
57489+ }
57490+
57491+ if (!cap_raised(cap_drop, cap)) {
57492+ if (cap_raised(cap_audit, cap))
57493+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
57494+ return 1;
57495+ }
57496+
57497+ curracl = task->acl;
57498+
57499+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
57500+ && cap_raised(cred->cap_effective, cap)) {
57501+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
57502+ task->role->roletype, cred->uid,
57503+ cred->gid, task->exec_file ?
57504+ gr_to_filename(task->exec_file->f_path.dentry,
57505+ task->exec_file->f_path.mnt) : curracl->filename,
57506+ curracl->filename, 0UL,
57507+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
57508+ return 1;
57509+ }
57510+
57511+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
57512+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
57513+
57514+ return 0;
57515+}
57516+
57517+int
57518+gr_acl_is_capable(const int cap)
57519+{
57520+ return gr_task_acl_is_capable(current, current_cred(), cap);
57521+}
57522+
57523+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
57524+{
57525+ struct acl_subject_label *curracl;
57526+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
57527+
57528+ if (!gr_acl_is_enabled())
57529+ return 1;
57530+
57531+ curracl = task->acl;
57532+
57533+ cap_drop = curracl->cap_lower;
57534+ cap_mask = curracl->cap_mask;
57535+
57536+ while ((curracl = curracl->parent_subject)) {
57537+ /* if the cap isn't specified in the current computed mask but is specified in the
57538+ current level subject, and is lowered in the current level subject, then add
57539+ it to the set of dropped capabilities
57540+ otherwise, add the current level subject's mask to the current computed mask
57541+ */
57542+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
57543+ cap_raise(cap_mask, cap);
57544+ if (cap_raised(curracl->cap_lower, cap))
57545+ cap_raise(cap_drop, cap);
57546+ }
57547+ }
57548+
57549+ if (!cap_raised(cap_drop, cap))
57550+ return 1;
57551+
57552+ return 0;
57553+}
57554+
57555+int
57556+gr_acl_is_capable_nolog(const int cap)
57557+{
57558+ return gr_task_acl_is_capable_nolog(current, cap);
57559+}
57560+
57561diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
57562new file mode 100644
57563index 0000000..a340c17
57564--- /dev/null
57565+++ b/grsecurity/gracl_fs.c
57566@@ -0,0 +1,431 @@
57567+#include <linux/kernel.h>
57568+#include <linux/sched.h>
57569+#include <linux/types.h>
57570+#include <linux/fs.h>
57571+#include <linux/file.h>
57572+#include <linux/stat.h>
57573+#include <linux/grsecurity.h>
57574+#include <linux/grinternal.h>
57575+#include <linux/gracl.h>
57576+
57577+umode_t
57578+gr_acl_umask(void)
57579+{
57580+ if (unlikely(!gr_acl_is_enabled()))
57581+ return 0;
57582+
57583+ return current->role->umask;
57584+}
57585+
57586+__u32
57587+gr_acl_handle_hidden_file(const struct dentry * dentry,
57588+ const struct vfsmount * mnt)
57589+{
57590+ __u32 mode;
57591+
57592+ if (unlikely(!dentry->d_inode))
57593+ return GR_FIND;
57594+
57595+ mode =
57596+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
57597+
57598+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
57599+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57600+ return mode;
57601+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
57602+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
57603+ return 0;
57604+ } else if (unlikely(!(mode & GR_FIND)))
57605+ return 0;
57606+
57607+ return GR_FIND;
57608+}
57609+
57610+__u32
57611+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
57612+ int acc_mode)
57613+{
57614+ __u32 reqmode = GR_FIND;
57615+ __u32 mode;
57616+
57617+ if (unlikely(!dentry->d_inode))
57618+ return reqmode;
57619+
57620+ if (acc_mode & MAY_APPEND)
57621+ reqmode |= GR_APPEND;
57622+ else if (acc_mode & MAY_WRITE)
57623+ reqmode |= GR_WRITE;
57624+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
57625+ reqmode |= GR_READ;
57626+
57627+ mode =
57628+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57629+ mnt);
57630+
57631+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57632+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57633+ reqmode & GR_READ ? " reading" : "",
57634+ reqmode & GR_WRITE ? " writing" : reqmode &
57635+ GR_APPEND ? " appending" : "");
57636+ return reqmode;
57637+ } else
57638+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57639+ {
57640+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
57641+ reqmode & GR_READ ? " reading" : "",
57642+ reqmode & GR_WRITE ? " writing" : reqmode &
57643+ GR_APPEND ? " appending" : "");
57644+ return 0;
57645+ } else if (unlikely((mode & reqmode) != reqmode))
57646+ return 0;
57647+
57648+ return reqmode;
57649+}
57650+
57651+__u32
57652+gr_acl_handle_creat(const struct dentry * dentry,
57653+ const struct dentry * p_dentry,
57654+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
57655+ const int imode)
57656+{
57657+ __u32 reqmode = GR_WRITE | GR_CREATE;
57658+ __u32 mode;
57659+
57660+ if (acc_mode & MAY_APPEND)
57661+ reqmode |= GR_APPEND;
57662+ // if a directory was required or the directory already exists, then
57663+ // don't count this open as a read
57664+ if ((acc_mode & MAY_READ) &&
57665+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
57666+ reqmode |= GR_READ;
57667+ if ((open_flags & O_CREAT) &&
57668+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57669+ reqmode |= GR_SETID;
57670+
57671+ mode =
57672+ gr_check_create(dentry, p_dentry, p_mnt,
57673+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57674+
57675+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57676+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57677+ reqmode & GR_READ ? " reading" : "",
57678+ reqmode & GR_WRITE ? " writing" : reqmode &
57679+ GR_APPEND ? " appending" : "");
57680+ return reqmode;
57681+ } else
57682+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57683+ {
57684+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
57685+ reqmode & GR_READ ? " reading" : "",
57686+ reqmode & GR_WRITE ? " writing" : reqmode &
57687+ GR_APPEND ? " appending" : "");
57688+ return 0;
57689+ } else if (unlikely((mode & reqmode) != reqmode))
57690+ return 0;
57691+
57692+ return reqmode;
57693+}
57694+
57695+__u32
57696+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
57697+ const int fmode)
57698+{
57699+ __u32 mode, reqmode = GR_FIND;
57700+
57701+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
57702+ reqmode |= GR_EXEC;
57703+ if (fmode & S_IWOTH)
57704+ reqmode |= GR_WRITE;
57705+ if (fmode & S_IROTH)
57706+ reqmode |= GR_READ;
57707+
57708+ mode =
57709+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
57710+ mnt);
57711+
57712+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
57713+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57714+ reqmode & GR_READ ? " reading" : "",
57715+ reqmode & GR_WRITE ? " writing" : "",
57716+ reqmode & GR_EXEC ? " executing" : "");
57717+ return reqmode;
57718+ } else
57719+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
57720+ {
57721+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
57722+ reqmode & GR_READ ? " reading" : "",
57723+ reqmode & GR_WRITE ? " writing" : "",
57724+ reqmode & GR_EXEC ? " executing" : "");
57725+ return 0;
57726+ } else if (unlikely((mode & reqmode) != reqmode))
57727+ return 0;
57728+
57729+ return reqmode;
57730+}
57731+
57732+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
57733+{
57734+ __u32 mode;
57735+
57736+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
57737+
57738+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57739+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
57740+ return mode;
57741+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57742+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
57743+ return 0;
57744+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57745+ return 0;
57746+
57747+ return (reqmode);
57748+}
57749+
57750+__u32
57751+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
57752+{
57753+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
57754+}
57755+
57756+__u32
57757+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
57758+{
57759+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
57760+}
57761+
57762+__u32
57763+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
57764+{
57765+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
57766+}
57767+
57768+__u32
57769+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
57770+{
57771+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
57772+}
57773+
57774+__u32
57775+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
57776+ umode_t *modeptr)
57777+{
57778+ umode_t mode;
57779+
57780+ *modeptr &= ~gr_acl_umask();
57781+ mode = *modeptr;
57782+
57783+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
57784+ return 1;
57785+
57786+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
57787+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
57788+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
57789+ GR_CHMOD_ACL_MSG);
57790+ } else {
57791+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
57792+ }
57793+}
57794+
57795+__u32
57796+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
57797+{
57798+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
57799+}
57800+
57801+__u32
57802+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
57803+{
57804+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
57805+}
57806+
57807+__u32
57808+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
57809+{
57810+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
57811+}
57812+
57813+__u32
57814+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
57815+{
57816+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
57817+ GR_UNIXCONNECT_ACL_MSG);
57818+}
57819+
57820+/* hardlinks require at minimum create and link permission,
57821+ any additional privilege required is based on the
57822+ privilege of the file being linked to
57823+*/
57824+__u32
57825+gr_acl_handle_link(const struct dentry * new_dentry,
57826+ const struct dentry * parent_dentry,
57827+ const struct vfsmount * parent_mnt,
57828+ const struct dentry * old_dentry,
57829+ const struct vfsmount * old_mnt, const struct filename *to)
57830+{
57831+ __u32 mode;
57832+ __u32 needmode = GR_CREATE | GR_LINK;
57833+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
57834+
57835+ mode =
57836+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
57837+ old_mnt);
57838+
57839+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
57840+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57841+ return mode;
57842+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57843+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
57844+ return 0;
57845+ } else if (unlikely((mode & needmode) != needmode))
57846+ return 0;
57847+
57848+ return 1;
57849+}
57850+
57851+__u32
57852+gr_acl_handle_symlink(const struct dentry * new_dentry,
57853+ const struct dentry * parent_dentry,
57854+ const struct vfsmount * parent_mnt, const struct filename *from)
57855+{
57856+ __u32 needmode = GR_WRITE | GR_CREATE;
57857+ __u32 mode;
57858+
57859+ mode =
57860+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
57861+ GR_CREATE | GR_AUDIT_CREATE |
57862+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
57863+
57864+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
57865+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57866+ return mode;
57867+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
57868+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
57869+ return 0;
57870+ } else if (unlikely((mode & needmode) != needmode))
57871+ return 0;
57872+
57873+ return (GR_WRITE | GR_CREATE);
57874+}
57875+
57876+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)
57877+{
57878+ __u32 mode;
57879+
57880+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
57881+
57882+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
57883+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
57884+ return mode;
57885+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
57886+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
57887+ return 0;
57888+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
57889+ return 0;
57890+
57891+ return (reqmode);
57892+}
57893+
57894+__u32
57895+gr_acl_handle_mknod(const struct dentry * new_dentry,
57896+ const struct dentry * parent_dentry,
57897+ const struct vfsmount * parent_mnt,
57898+ const int mode)
57899+{
57900+ __u32 reqmode = GR_WRITE | GR_CREATE;
57901+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
57902+ reqmode |= GR_SETID;
57903+
57904+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57905+ reqmode, GR_MKNOD_ACL_MSG);
57906+}
57907+
57908+__u32
57909+gr_acl_handle_mkdir(const struct dentry *new_dentry,
57910+ const struct dentry *parent_dentry,
57911+ const struct vfsmount *parent_mnt)
57912+{
57913+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
57914+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
57915+}
57916+
57917+#define RENAME_CHECK_SUCCESS(old, new) \
57918+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
57919+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
57920+
57921+int
57922+gr_acl_handle_rename(struct dentry *new_dentry,
57923+ struct dentry *parent_dentry,
57924+ const struct vfsmount *parent_mnt,
57925+ struct dentry *old_dentry,
57926+ struct inode *old_parent_inode,
57927+ struct vfsmount *old_mnt, const struct filename *newname)
57928+{
57929+ __u32 comp1, comp2;
57930+ int error = 0;
57931+
57932+ if (unlikely(!gr_acl_is_enabled()))
57933+ return 0;
57934+
57935+ if (!new_dentry->d_inode) {
57936+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
57937+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
57938+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
57939+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
57940+ GR_DELETE | GR_AUDIT_DELETE |
57941+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57942+ GR_SUPPRESS, old_mnt);
57943+ } else {
57944+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
57945+ GR_CREATE | GR_DELETE |
57946+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
57947+ GR_AUDIT_READ | GR_AUDIT_WRITE |
57948+ GR_SUPPRESS, parent_mnt);
57949+ comp2 =
57950+ gr_search_file(old_dentry,
57951+ GR_READ | GR_WRITE | GR_AUDIT_READ |
57952+ GR_DELETE | GR_AUDIT_DELETE |
57953+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
57954+ }
57955+
57956+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
57957+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
57958+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57959+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
57960+ && !(comp2 & GR_SUPPRESS)) {
57961+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
57962+ error = -EACCES;
57963+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
57964+ error = -EACCES;
57965+
57966+ return error;
57967+}
57968+
57969+void
57970+gr_acl_handle_exit(void)
57971+{
57972+ u16 id;
57973+ char *rolename;
57974+
57975+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
57976+ !(current->role->roletype & GR_ROLE_PERSIST))) {
57977+ id = current->acl_role_id;
57978+ rolename = current->role->rolename;
57979+ gr_set_acls(1);
57980+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
57981+ }
57982+
57983+ gr_put_exec_file(current);
57984+ return;
57985+}
57986+
57987+int
57988+gr_acl_handle_procpidmem(const struct task_struct *task)
57989+{
57990+ if (unlikely(!gr_acl_is_enabled()))
57991+ return 0;
57992+
57993+ if (task != current && task->acl->mode & GR_PROTPROCFD)
57994+ return -EACCES;
57995+
57996+ return 0;
57997+}
57998diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
57999new file mode 100644
58000index 0000000..58800a7
58001--- /dev/null
58002+++ b/grsecurity/gracl_ip.c
58003@@ -0,0 +1,384 @@
58004+#include <linux/kernel.h>
58005+#include <asm/uaccess.h>
58006+#include <asm/errno.h>
58007+#include <net/sock.h>
58008+#include <linux/file.h>
58009+#include <linux/fs.h>
58010+#include <linux/net.h>
58011+#include <linux/in.h>
58012+#include <linux/skbuff.h>
58013+#include <linux/ip.h>
58014+#include <linux/udp.h>
58015+#include <linux/types.h>
58016+#include <linux/sched.h>
58017+#include <linux/netdevice.h>
58018+#include <linux/inetdevice.h>
58019+#include <linux/gracl.h>
58020+#include <linux/grsecurity.h>
58021+#include <linux/grinternal.h>
58022+
58023+#define GR_BIND 0x01
58024+#define GR_CONNECT 0x02
58025+#define GR_INVERT 0x04
58026+#define GR_BINDOVERRIDE 0x08
58027+#define GR_CONNECTOVERRIDE 0x10
58028+#define GR_SOCK_FAMILY 0x20
58029+
58030+static const char * gr_protocols[IPPROTO_MAX] = {
58031+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
58032+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
58033+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
58034+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
58035+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
58036+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
58037+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
58038+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
58039+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
58040+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
58041+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
58042+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
58043+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
58044+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
58045+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
58046+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
58047+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
58048+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
58049+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
58050+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
58051+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
58052+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
58053+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
58054+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
58055+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
58056+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
58057+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
58058+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
58059+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
58060+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
58061+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
58062+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
58063+ };
58064+
58065+static const char * gr_socktypes[SOCK_MAX] = {
58066+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
58067+ "unknown:7", "unknown:8", "unknown:9", "packet"
58068+ };
58069+
58070+static const char * gr_sockfamilies[AF_MAX+1] = {
58071+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
58072+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
58073+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
58074+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
58075+ };
58076+
58077+const char *
58078+gr_proto_to_name(unsigned char proto)
58079+{
58080+ return gr_protocols[proto];
58081+}
58082+
58083+const char *
58084+gr_socktype_to_name(unsigned char type)
58085+{
58086+ return gr_socktypes[type];
58087+}
58088+
58089+const char *
58090+gr_sockfamily_to_name(unsigned char family)
58091+{
58092+ return gr_sockfamilies[family];
58093+}
58094+
58095+int
58096+gr_search_socket(const int domain, const int type, const int protocol)
58097+{
58098+ struct acl_subject_label *curr;
58099+ const struct cred *cred = current_cred();
58100+
58101+ if (unlikely(!gr_acl_is_enabled()))
58102+ goto exit;
58103+
58104+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
58105+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
58106+ goto exit; // let the kernel handle it
58107+
58108+ curr = current->acl;
58109+
58110+ if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
58111+ /* the family is allowed, if this is PF_INET allow it only if
58112+ the extra sock type/protocol checks pass */
58113+ if (domain == PF_INET)
58114+ goto inet_check;
58115+ goto exit;
58116+ } else {
58117+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58118+ __u32 fakeip = 0;
58119+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58120+ current->role->roletype, cred->uid,
58121+ cred->gid, current->exec_file ?
58122+ gr_to_filename(current->exec_file->f_path.dentry,
58123+ current->exec_file->f_path.mnt) :
58124+ curr->filename, curr->filename,
58125+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
58126+ &current->signal->saved_ip);
58127+ goto exit;
58128+ }
58129+ goto exit_fail;
58130+ }
58131+
58132+inet_check:
58133+ /* the rest of this checking is for IPv4 only */
58134+ if (!curr->ips)
58135+ goto exit;
58136+
58137+ if ((curr->ip_type & (1 << type)) &&
58138+ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
58139+ goto exit;
58140+
58141+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58142+ /* we don't place acls on raw sockets , and sometimes
58143+ dgram/ip sockets are opened for ioctl and not
58144+ bind/connect, so we'll fake a bind learn log */
58145+ if (type == SOCK_RAW || type == SOCK_PACKET) {
58146+ __u32 fakeip = 0;
58147+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58148+ current->role->roletype, cred->uid,
58149+ cred->gid, current->exec_file ?
58150+ gr_to_filename(current->exec_file->f_path.dentry,
58151+ current->exec_file->f_path.mnt) :
58152+ curr->filename, curr->filename,
58153+ &fakeip, 0, type,
58154+ protocol, GR_CONNECT, &current->signal->saved_ip);
58155+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
58156+ __u32 fakeip = 0;
58157+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58158+ current->role->roletype, cred->uid,
58159+ cred->gid, current->exec_file ?
58160+ gr_to_filename(current->exec_file->f_path.dentry,
58161+ current->exec_file->f_path.mnt) :
58162+ curr->filename, curr->filename,
58163+ &fakeip, 0, type,
58164+ protocol, GR_BIND, &current->signal->saved_ip);
58165+ }
58166+ /* we'll log when they use connect or bind */
58167+ goto exit;
58168+ }
58169+
58170+exit_fail:
58171+ if (domain == PF_INET)
58172+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
58173+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
58174+ else
58175+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
58176+ gr_socktype_to_name(type), protocol);
58177+
58178+ return 0;
58179+exit:
58180+ return 1;
58181+}
58182+
58183+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)
58184+{
58185+ if ((ip->mode & mode) &&
58186+ (ip_port >= ip->low) &&
58187+ (ip_port <= ip->high) &&
58188+ ((ntohl(ip_addr) & our_netmask) ==
58189+ (ntohl(our_addr) & our_netmask))
58190+ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
58191+ && (ip->type & (1 << type))) {
58192+ if (ip->mode & GR_INVERT)
58193+ return 2; // specifically denied
58194+ else
58195+ return 1; // allowed
58196+ }
58197+
58198+ return 0; // not specifically allowed, may continue parsing
58199+}
58200+
58201+static int
58202+gr_search_connectbind(const int full_mode, struct sock *sk,
58203+ struct sockaddr_in *addr, const int type)
58204+{
58205+ char iface[IFNAMSIZ] = {0};
58206+ struct acl_subject_label *curr;
58207+ struct acl_ip_label *ip;
58208+ struct inet_sock *isk;
58209+ struct net_device *dev;
58210+ struct in_device *idev;
58211+ unsigned long i;
58212+ int ret;
58213+ int mode = full_mode & (GR_BIND | GR_CONNECT);
58214+ __u32 ip_addr = 0;
58215+ __u32 our_addr;
58216+ __u32 our_netmask;
58217+ char *p;
58218+ __u16 ip_port = 0;
58219+ const struct cred *cred = current_cred();
58220+
58221+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
58222+ return 0;
58223+
58224+ curr = current->acl;
58225+ isk = inet_sk(sk);
58226+
58227+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
58228+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
58229+ addr->sin_addr.s_addr = curr->inaddr_any_override;
58230+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
58231+ struct sockaddr_in saddr;
58232+ int err;
58233+
58234+ saddr.sin_family = AF_INET;
58235+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
58236+ saddr.sin_port = isk->inet_sport;
58237+
58238+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58239+ if (err)
58240+ return err;
58241+
58242+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
58243+ if (err)
58244+ return err;
58245+ }
58246+
58247+ if (!curr->ips)
58248+ return 0;
58249+
58250+ ip_addr = addr->sin_addr.s_addr;
58251+ ip_port = ntohs(addr->sin_port);
58252+
58253+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
58254+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
58255+ current->role->roletype, cred->uid,
58256+ cred->gid, current->exec_file ?
58257+ gr_to_filename(current->exec_file->f_path.dentry,
58258+ current->exec_file->f_path.mnt) :
58259+ curr->filename, curr->filename,
58260+ &ip_addr, ip_port, type,
58261+ sk->sk_protocol, mode, &current->signal->saved_ip);
58262+ return 0;
58263+ }
58264+
58265+ for (i = 0; i < curr->ip_num; i++) {
58266+ ip = *(curr->ips + i);
58267+ if (ip->iface != NULL) {
58268+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
58269+ p = strchr(iface, ':');
58270+ if (p != NULL)
58271+ *p = '\0';
58272+ dev = dev_get_by_name(sock_net(sk), iface);
58273+ if (dev == NULL)
58274+ continue;
58275+ idev = in_dev_get(dev);
58276+ if (idev == NULL) {
58277+ dev_put(dev);
58278+ continue;
58279+ }
58280+ rcu_read_lock();
58281+ for_ifa(idev) {
58282+ if (!strcmp(ip->iface, ifa->ifa_label)) {
58283+ our_addr = ifa->ifa_address;
58284+ our_netmask = 0xffffffff;
58285+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58286+ if (ret == 1) {
58287+ rcu_read_unlock();
58288+ in_dev_put(idev);
58289+ dev_put(dev);
58290+ return 0;
58291+ } else if (ret == 2) {
58292+ rcu_read_unlock();
58293+ in_dev_put(idev);
58294+ dev_put(dev);
58295+ goto denied;
58296+ }
58297+ }
58298+ } endfor_ifa(idev);
58299+ rcu_read_unlock();
58300+ in_dev_put(idev);
58301+ dev_put(dev);
58302+ } else {
58303+ our_addr = ip->addr;
58304+ our_netmask = ip->netmask;
58305+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
58306+ if (ret == 1)
58307+ return 0;
58308+ else if (ret == 2)
58309+ goto denied;
58310+ }
58311+ }
58312+
58313+denied:
58314+ if (mode == GR_BIND)
58315+ 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));
58316+ else if (mode == GR_CONNECT)
58317+ 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));
58318+
58319+ return -EACCES;
58320+}
58321+
58322+int
58323+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
58324+{
58325+ /* always allow disconnection of dgram sockets with connect */
58326+ if (addr->sin_family == AF_UNSPEC)
58327+ return 0;
58328+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
58329+}
58330+
58331+int
58332+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
58333+{
58334+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
58335+}
58336+
58337+int gr_search_listen(struct socket *sock)
58338+{
58339+ struct sock *sk = sock->sk;
58340+ struct sockaddr_in addr;
58341+
58342+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58343+ addr.sin_port = inet_sk(sk)->inet_sport;
58344+
58345+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58346+}
58347+
58348+int gr_search_accept(struct socket *sock)
58349+{
58350+ struct sock *sk = sock->sk;
58351+ struct sockaddr_in addr;
58352+
58353+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
58354+ addr.sin_port = inet_sk(sk)->inet_sport;
58355+
58356+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
58357+}
58358+
58359+int
58360+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
58361+{
58362+ if (addr)
58363+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
58364+ else {
58365+ struct sockaddr_in sin;
58366+ const struct inet_sock *inet = inet_sk(sk);
58367+
58368+ sin.sin_addr.s_addr = inet->inet_daddr;
58369+ sin.sin_port = inet->inet_dport;
58370+
58371+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58372+ }
58373+}
58374+
58375+int
58376+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
58377+{
58378+ struct sockaddr_in sin;
58379+
58380+ if (unlikely(skb->len < sizeof (struct udphdr)))
58381+ return 0; // skip this packet
58382+
58383+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
58384+ sin.sin_port = udp_hdr(skb)->source;
58385+
58386+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
58387+}
58388diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
58389new file mode 100644
58390index 0000000..25f54ef
58391--- /dev/null
58392+++ b/grsecurity/gracl_learn.c
58393@@ -0,0 +1,207 @@
58394+#include <linux/kernel.h>
58395+#include <linux/mm.h>
58396+#include <linux/sched.h>
58397+#include <linux/poll.h>
58398+#include <linux/string.h>
58399+#include <linux/file.h>
58400+#include <linux/types.h>
58401+#include <linux/vmalloc.h>
58402+#include <linux/grinternal.h>
58403+
58404+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
58405+ size_t count, loff_t *ppos);
58406+extern int gr_acl_is_enabled(void);
58407+
58408+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
58409+static int gr_learn_attached;
58410+
58411+/* use a 512k buffer */
58412+#define LEARN_BUFFER_SIZE (512 * 1024)
58413+
58414+static DEFINE_SPINLOCK(gr_learn_lock);
58415+static DEFINE_MUTEX(gr_learn_user_mutex);
58416+
58417+/* we need to maintain two buffers, so that the kernel context of grlearn
58418+ uses a semaphore around the userspace copying, and the other kernel contexts
58419+ use a spinlock when copying into the buffer, since they cannot sleep
58420+*/
58421+static char *learn_buffer;
58422+static char *learn_buffer_user;
58423+static int learn_buffer_len;
58424+static int learn_buffer_user_len;
58425+
58426+static ssize_t
58427+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
58428+{
58429+ DECLARE_WAITQUEUE(wait, current);
58430+ ssize_t retval = 0;
58431+
58432+ add_wait_queue(&learn_wait, &wait);
58433+ set_current_state(TASK_INTERRUPTIBLE);
58434+ do {
58435+ mutex_lock(&gr_learn_user_mutex);
58436+ spin_lock(&gr_learn_lock);
58437+ if (learn_buffer_len)
58438+ break;
58439+ spin_unlock(&gr_learn_lock);
58440+ mutex_unlock(&gr_learn_user_mutex);
58441+ if (file->f_flags & O_NONBLOCK) {
58442+ retval = -EAGAIN;
58443+ goto out;
58444+ }
58445+ if (signal_pending(current)) {
58446+ retval = -ERESTARTSYS;
58447+ goto out;
58448+ }
58449+
58450+ schedule();
58451+ } while (1);
58452+
58453+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
58454+ learn_buffer_user_len = learn_buffer_len;
58455+ retval = learn_buffer_len;
58456+ learn_buffer_len = 0;
58457+
58458+ spin_unlock(&gr_learn_lock);
58459+
58460+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
58461+ retval = -EFAULT;
58462+
58463+ mutex_unlock(&gr_learn_user_mutex);
58464+out:
58465+ set_current_state(TASK_RUNNING);
58466+ remove_wait_queue(&learn_wait, &wait);
58467+ return retval;
58468+}
58469+
58470+static unsigned int
58471+poll_learn(struct file * file, poll_table * wait)
58472+{
58473+ poll_wait(file, &learn_wait, wait);
58474+
58475+ if (learn_buffer_len)
58476+ return (POLLIN | POLLRDNORM);
58477+
58478+ return 0;
58479+}
58480+
58481+void
58482+gr_clear_learn_entries(void)
58483+{
58484+ char *tmp;
58485+
58486+ mutex_lock(&gr_learn_user_mutex);
58487+ spin_lock(&gr_learn_lock);
58488+ tmp = learn_buffer;
58489+ learn_buffer = NULL;
58490+ spin_unlock(&gr_learn_lock);
58491+ if (tmp)
58492+ vfree(tmp);
58493+ if (learn_buffer_user != NULL) {
58494+ vfree(learn_buffer_user);
58495+ learn_buffer_user = NULL;
58496+ }
58497+ learn_buffer_len = 0;
58498+ mutex_unlock(&gr_learn_user_mutex);
58499+
58500+ return;
58501+}
58502+
58503+void
58504+gr_add_learn_entry(const char *fmt, ...)
58505+{
58506+ va_list args;
58507+ unsigned int len;
58508+
58509+ if (!gr_learn_attached)
58510+ return;
58511+
58512+ spin_lock(&gr_learn_lock);
58513+
58514+ /* leave a gap at the end so we know when it's "full" but don't have to
58515+ compute the exact length of the string we're trying to append
58516+ */
58517+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
58518+ spin_unlock(&gr_learn_lock);
58519+ wake_up_interruptible(&learn_wait);
58520+ return;
58521+ }
58522+ if (learn_buffer == NULL) {
58523+ spin_unlock(&gr_learn_lock);
58524+ return;
58525+ }
58526+
58527+ va_start(args, fmt);
58528+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
58529+ va_end(args);
58530+
58531+ learn_buffer_len += len + 1;
58532+
58533+ spin_unlock(&gr_learn_lock);
58534+ wake_up_interruptible(&learn_wait);
58535+
58536+ return;
58537+}
58538+
58539+static int
58540+open_learn(struct inode *inode, struct file *file)
58541+{
58542+ if (file->f_mode & FMODE_READ && gr_learn_attached)
58543+ return -EBUSY;
58544+ if (file->f_mode & FMODE_READ) {
58545+ int retval = 0;
58546+ mutex_lock(&gr_learn_user_mutex);
58547+ if (learn_buffer == NULL)
58548+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
58549+ if (learn_buffer_user == NULL)
58550+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
58551+ if (learn_buffer == NULL) {
58552+ retval = -ENOMEM;
58553+ goto out_error;
58554+ }
58555+ if (learn_buffer_user == NULL) {
58556+ retval = -ENOMEM;
58557+ goto out_error;
58558+ }
58559+ learn_buffer_len = 0;
58560+ learn_buffer_user_len = 0;
58561+ gr_learn_attached = 1;
58562+out_error:
58563+ mutex_unlock(&gr_learn_user_mutex);
58564+ return retval;
58565+ }
58566+ return 0;
58567+}
58568+
58569+static int
58570+close_learn(struct inode *inode, struct file *file)
58571+{
58572+ if (file->f_mode & FMODE_READ) {
58573+ char *tmp = NULL;
58574+ mutex_lock(&gr_learn_user_mutex);
58575+ spin_lock(&gr_learn_lock);
58576+ tmp = learn_buffer;
58577+ learn_buffer = NULL;
58578+ spin_unlock(&gr_learn_lock);
58579+ if (tmp)
58580+ vfree(tmp);
58581+ if (learn_buffer_user != NULL) {
58582+ vfree(learn_buffer_user);
58583+ learn_buffer_user = NULL;
58584+ }
58585+ learn_buffer_len = 0;
58586+ learn_buffer_user_len = 0;
58587+ gr_learn_attached = 0;
58588+ mutex_unlock(&gr_learn_user_mutex);
58589+ }
58590+
58591+ return 0;
58592+}
58593+
58594+const struct file_operations grsec_fops = {
58595+ .read = read_learn,
58596+ .write = write_grsec_handler,
58597+ .open = open_learn,
58598+ .release = close_learn,
58599+ .poll = poll_learn,
58600+};
58601diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
58602new file mode 100644
58603index 0000000..39645c9
58604--- /dev/null
58605+++ b/grsecurity/gracl_res.c
58606@@ -0,0 +1,68 @@
58607+#include <linux/kernel.h>
58608+#include <linux/sched.h>
58609+#include <linux/gracl.h>
58610+#include <linux/grinternal.h>
58611+
58612+static const char *restab_log[] = {
58613+ [RLIMIT_CPU] = "RLIMIT_CPU",
58614+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
58615+ [RLIMIT_DATA] = "RLIMIT_DATA",
58616+ [RLIMIT_STACK] = "RLIMIT_STACK",
58617+ [RLIMIT_CORE] = "RLIMIT_CORE",
58618+ [RLIMIT_RSS] = "RLIMIT_RSS",
58619+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
58620+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
58621+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
58622+ [RLIMIT_AS] = "RLIMIT_AS",
58623+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
58624+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
58625+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
58626+ [RLIMIT_NICE] = "RLIMIT_NICE",
58627+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
58628+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
58629+ [GR_CRASH_RES] = "RLIMIT_CRASH"
58630+};
58631+
58632+void
58633+gr_log_resource(const struct task_struct *task,
58634+ const int res, const unsigned long wanted, const int gt)
58635+{
58636+ const struct cred *cred;
58637+ unsigned long rlim;
58638+
58639+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
58640+ return;
58641+
58642+ // not yet supported resource
58643+ if (unlikely(!restab_log[res]))
58644+ return;
58645+
58646+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
58647+ rlim = task_rlimit_max(task, res);
58648+ else
58649+ rlim = task_rlimit(task, res);
58650+
58651+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
58652+ return;
58653+
58654+ rcu_read_lock();
58655+ cred = __task_cred(task);
58656+
58657+ if (res == RLIMIT_NPROC &&
58658+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
58659+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
58660+ goto out_rcu_unlock;
58661+ else if (res == RLIMIT_MEMLOCK &&
58662+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
58663+ goto out_rcu_unlock;
58664+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
58665+ goto out_rcu_unlock;
58666+ rcu_read_unlock();
58667+
58668+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
58669+
58670+ return;
58671+out_rcu_unlock:
58672+ rcu_read_unlock();
58673+ return;
58674+}
58675diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
58676new file mode 100644
58677index 0000000..25197e9
58678--- /dev/null
58679+++ b/grsecurity/gracl_segv.c
58680@@ -0,0 +1,299 @@
58681+#include <linux/kernel.h>
58682+#include <linux/mm.h>
58683+#include <asm/uaccess.h>
58684+#include <asm/errno.h>
58685+#include <asm/mman.h>
58686+#include <net/sock.h>
58687+#include <linux/file.h>
58688+#include <linux/fs.h>
58689+#include <linux/net.h>
58690+#include <linux/in.h>
58691+#include <linux/slab.h>
58692+#include <linux/types.h>
58693+#include <linux/sched.h>
58694+#include <linux/timer.h>
58695+#include <linux/gracl.h>
58696+#include <linux/grsecurity.h>
58697+#include <linux/grinternal.h>
58698+
58699+static struct crash_uid *uid_set;
58700+static unsigned short uid_used;
58701+static DEFINE_SPINLOCK(gr_uid_lock);
58702+extern rwlock_t gr_inode_lock;
58703+extern struct acl_subject_label *
58704+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
58705+ struct acl_role_label *role);
58706+
58707+#ifdef CONFIG_BTRFS_FS
58708+extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
58709+extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
58710+#endif
58711+
58712+static inline dev_t __get_dev(const struct dentry *dentry)
58713+{
58714+#ifdef CONFIG_BTRFS_FS
58715+ if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
58716+ return get_btrfs_dev_from_inode(dentry->d_inode);
58717+ else
58718+#endif
58719+ return dentry->d_inode->i_sb->s_dev;
58720+}
58721+
58722+int
58723+gr_init_uidset(void)
58724+{
58725+ uid_set =
58726+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
58727+ uid_used = 0;
58728+
58729+ return uid_set ? 1 : 0;
58730+}
58731+
58732+void
58733+gr_free_uidset(void)
58734+{
58735+ if (uid_set)
58736+ kfree(uid_set);
58737+
58738+ return;
58739+}
58740+
58741+int
58742+gr_find_uid(const uid_t uid)
58743+{
58744+ struct crash_uid *tmp = uid_set;
58745+ uid_t buid;
58746+ int low = 0, high = uid_used - 1, mid;
58747+
58748+ while (high >= low) {
58749+ mid = (low + high) >> 1;
58750+ buid = tmp[mid].uid;
58751+ if (buid == uid)
58752+ return mid;
58753+ if (buid > uid)
58754+ high = mid - 1;
58755+ if (buid < uid)
58756+ low = mid + 1;
58757+ }
58758+
58759+ return -1;
58760+}
58761+
58762+static __inline__ void
58763+gr_insertsort(void)
58764+{
58765+ unsigned short i, j;
58766+ struct crash_uid index;
58767+
58768+ for (i = 1; i < uid_used; i++) {
58769+ index = uid_set[i];
58770+ j = i;
58771+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
58772+ uid_set[j] = uid_set[j - 1];
58773+ j--;
58774+ }
58775+ uid_set[j] = index;
58776+ }
58777+
58778+ return;
58779+}
58780+
58781+static __inline__ void
58782+gr_insert_uid(const uid_t uid, const unsigned long expires)
58783+{
58784+ int loc;
58785+
58786+ if (uid_used == GR_UIDTABLE_MAX)
58787+ return;
58788+
58789+ loc = gr_find_uid(uid);
58790+
58791+ if (loc >= 0) {
58792+ uid_set[loc].expires = expires;
58793+ return;
58794+ }
58795+
58796+ uid_set[uid_used].uid = uid;
58797+ uid_set[uid_used].expires = expires;
58798+ uid_used++;
58799+
58800+ gr_insertsort();
58801+
58802+ return;
58803+}
58804+
58805+void
58806+gr_remove_uid(const unsigned short loc)
58807+{
58808+ unsigned short i;
58809+
58810+ for (i = loc + 1; i < uid_used; i++)
58811+ uid_set[i - 1] = uid_set[i];
58812+
58813+ uid_used--;
58814+
58815+ return;
58816+}
58817+
58818+int
58819+gr_check_crash_uid(const uid_t uid)
58820+{
58821+ int loc;
58822+ int ret = 0;
58823+
58824+ if (unlikely(!gr_acl_is_enabled()))
58825+ return 0;
58826+
58827+ spin_lock(&gr_uid_lock);
58828+ loc = gr_find_uid(uid);
58829+
58830+ if (loc < 0)
58831+ goto out_unlock;
58832+
58833+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
58834+ gr_remove_uid(loc);
58835+ else
58836+ ret = 1;
58837+
58838+out_unlock:
58839+ spin_unlock(&gr_uid_lock);
58840+ return ret;
58841+}
58842+
58843+static __inline__ int
58844+proc_is_setxid(const struct cred *cred)
58845+{
58846+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
58847+ !uid_eq(cred->uid, cred->fsuid))
58848+ return 1;
58849+ if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
58850+ !uid_eq(cred->gid, cred->fsgid))
58851+ return 1;
58852+
58853+ return 0;
58854+}
58855+
58856+extern int gr_fake_force_sig(int sig, struct task_struct *t);
58857+
58858+void
58859+gr_handle_crash(struct task_struct *task, const int sig)
58860+{
58861+ struct acl_subject_label *curr;
58862+ struct task_struct *tsk, *tsk2;
58863+ const struct cred *cred;
58864+ const struct cred *cred2;
58865+
58866+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
58867+ return;
58868+
58869+ if (unlikely(!gr_acl_is_enabled()))
58870+ return;
58871+
58872+ curr = task->acl;
58873+
58874+ if (!(curr->resmask & (1 << GR_CRASH_RES)))
58875+ return;
58876+
58877+ if (time_before_eq(curr->expires, get_seconds())) {
58878+ curr->expires = 0;
58879+ curr->crashes = 0;
58880+ }
58881+
58882+ curr->crashes++;
58883+
58884+ if (!curr->expires)
58885+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
58886+
58887+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58888+ time_after(curr->expires, get_seconds())) {
58889+ rcu_read_lock();
58890+ cred = __task_cred(task);
58891+ if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
58892+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58893+ spin_lock(&gr_uid_lock);
58894+ gr_insert_uid(cred->uid, curr->expires);
58895+ spin_unlock(&gr_uid_lock);
58896+ curr->expires = 0;
58897+ curr->crashes = 0;
58898+ read_lock(&tasklist_lock);
58899+ do_each_thread(tsk2, tsk) {
58900+ cred2 = __task_cred(tsk);
58901+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
58902+ gr_fake_force_sig(SIGKILL, tsk);
58903+ } while_each_thread(tsk2, tsk);
58904+ read_unlock(&tasklist_lock);
58905+ } else {
58906+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
58907+ read_lock(&tasklist_lock);
58908+ read_lock(&grsec_exec_file_lock);
58909+ do_each_thread(tsk2, tsk) {
58910+ if (likely(tsk != task)) {
58911+ // if this thread has the same subject as the one that triggered
58912+ // RES_CRASH and it's the same binary, kill it
58913+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
58914+ gr_fake_force_sig(SIGKILL, tsk);
58915+ }
58916+ } while_each_thread(tsk2, tsk);
58917+ read_unlock(&grsec_exec_file_lock);
58918+ read_unlock(&tasklist_lock);
58919+ }
58920+ rcu_read_unlock();
58921+ }
58922+
58923+ return;
58924+}
58925+
58926+int
58927+gr_check_crash_exec(const struct file *filp)
58928+{
58929+ struct acl_subject_label *curr;
58930+
58931+ if (unlikely(!gr_acl_is_enabled()))
58932+ return 0;
58933+
58934+ read_lock(&gr_inode_lock);
58935+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
58936+ __get_dev(filp->f_path.dentry),
58937+ current->role);
58938+ read_unlock(&gr_inode_lock);
58939+
58940+ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
58941+ (!curr->crashes && !curr->expires))
58942+ return 0;
58943+
58944+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
58945+ time_after(curr->expires, get_seconds()))
58946+ return 1;
58947+ else if (time_before_eq(curr->expires, get_seconds())) {
58948+ curr->crashes = 0;
58949+ curr->expires = 0;
58950+ }
58951+
58952+ return 0;
58953+}
58954+
58955+void
58956+gr_handle_alertkill(struct task_struct *task)
58957+{
58958+ struct acl_subject_label *curracl;
58959+ __u32 curr_ip;
58960+ struct task_struct *p, *p2;
58961+
58962+ if (unlikely(!gr_acl_is_enabled()))
58963+ return;
58964+
58965+ curracl = task->acl;
58966+ curr_ip = task->signal->curr_ip;
58967+
58968+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
58969+ read_lock(&tasklist_lock);
58970+ do_each_thread(p2, p) {
58971+ if (p->signal->curr_ip == curr_ip)
58972+ gr_fake_force_sig(SIGKILL, p);
58973+ } while_each_thread(p2, p);
58974+ read_unlock(&tasklist_lock);
58975+ } else if (curracl->mode & GR_KILLPROC)
58976+ gr_fake_force_sig(SIGKILL, task);
58977+
58978+ return;
58979+}
58980diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
58981new file mode 100644
58982index 0000000..9d83a69
58983--- /dev/null
58984+++ b/grsecurity/gracl_shm.c
58985@@ -0,0 +1,40 @@
58986+#include <linux/kernel.h>
58987+#include <linux/mm.h>
58988+#include <linux/sched.h>
58989+#include <linux/file.h>
58990+#include <linux/ipc.h>
58991+#include <linux/gracl.h>
58992+#include <linux/grsecurity.h>
58993+#include <linux/grinternal.h>
58994+
58995+int
58996+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58997+ const time_t shm_createtime, const uid_t cuid, const int shmid)
58998+{
58999+ struct task_struct *task;
59000+
59001+ if (!gr_acl_is_enabled())
59002+ return 1;
59003+
59004+ rcu_read_lock();
59005+ read_lock(&tasklist_lock);
59006+
59007+ task = find_task_by_vpid(shm_cprid);
59008+
59009+ if (unlikely(!task))
59010+ task = find_task_by_vpid(shm_lapid);
59011+
59012+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
59013+ (task->pid == shm_lapid)) &&
59014+ (task->acl->mode & GR_PROTSHM) &&
59015+ (task->acl != current->acl))) {
59016+ read_unlock(&tasklist_lock);
59017+ rcu_read_unlock();
59018+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
59019+ return 0;
59020+ }
59021+ read_unlock(&tasklist_lock);
59022+ rcu_read_unlock();
59023+
59024+ return 1;
59025+}
59026diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
59027new file mode 100644
59028index 0000000..bc0be01
59029--- /dev/null
59030+++ b/grsecurity/grsec_chdir.c
59031@@ -0,0 +1,19 @@
59032+#include <linux/kernel.h>
59033+#include <linux/sched.h>
59034+#include <linux/fs.h>
59035+#include <linux/file.h>
59036+#include <linux/grsecurity.h>
59037+#include <linux/grinternal.h>
59038+
59039+void
59040+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
59041+{
59042+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
59043+ if ((grsec_enable_chdir && grsec_enable_group &&
59044+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
59045+ !grsec_enable_group)) {
59046+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
59047+ }
59048+#endif
59049+ return;
59050+}
59051diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
59052new file mode 100644
59053index 0000000..9807ee2
59054--- /dev/null
59055+++ b/grsecurity/grsec_chroot.c
59056@@ -0,0 +1,368 @@
59057+#include <linux/kernel.h>
59058+#include <linux/module.h>
59059+#include <linux/sched.h>
59060+#include <linux/file.h>
59061+#include <linux/fs.h>
59062+#include <linux/mount.h>
59063+#include <linux/types.h>
59064+#include "../fs/mount.h"
59065+#include <linux/grsecurity.h>
59066+#include <linux/grinternal.h>
59067+
59068+void gr_set_chroot_entries(struct task_struct *task, struct path *path)
59069+{
59070+#ifdef CONFIG_GRKERNSEC
59071+ if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
59072+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
59073+ task->gr_is_chrooted = 1;
59074+ else
59075+ task->gr_is_chrooted = 0;
59076+
59077+ task->gr_chroot_dentry = path->dentry;
59078+#endif
59079+ return;
59080+}
59081+
59082+void gr_clear_chroot_entries(struct task_struct *task)
59083+{
59084+#ifdef CONFIG_GRKERNSEC
59085+ task->gr_is_chrooted = 0;
59086+ task->gr_chroot_dentry = NULL;
59087+#endif
59088+ return;
59089+}
59090+
59091+int
59092+gr_handle_chroot_unix(const pid_t pid)
59093+{
59094+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
59095+ struct task_struct *p;
59096+
59097+ if (unlikely(!grsec_enable_chroot_unix))
59098+ return 1;
59099+
59100+ if (likely(!proc_is_chrooted(current)))
59101+ return 1;
59102+
59103+ rcu_read_lock();
59104+ read_lock(&tasklist_lock);
59105+ p = find_task_by_vpid_unrestricted(pid);
59106+ if (unlikely(p && !have_same_root(current, p))) {
59107+ read_unlock(&tasklist_lock);
59108+ rcu_read_unlock();
59109+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
59110+ return 0;
59111+ }
59112+ read_unlock(&tasklist_lock);
59113+ rcu_read_unlock();
59114+#endif
59115+ return 1;
59116+}
59117+
59118+int
59119+gr_handle_chroot_nice(void)
59120+{
59121+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59122+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
59123+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
59124+ return -EPERM;
59125+ }
59126+#endif
59127+ return 0;
59128+}
59129+
59130+int
59131+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
59132+{
59133+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
59134+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
59135+ && proc_is_chrooted(current)) {
59136+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
59137+ return -EACCES;
59138+ }
59139+#endif
59140+ return 0;
59141+}
59142+
59143+int
59144+gr_handle_chroot_rawio(const struct inode *inode)
59145+{
59146+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59147+ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
59148+ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
59149+ return 1;
59150+#endif
59151+ return 0;
59152+}
59153+
59154+int
59155+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
59156+{
59157+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59158+ struct task_struct *p;
59159+ int ret = 0;
59160+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
59161+ return ret;
59162+
59163+ read_lock(&tasklist_lock);
59164+ do_each_pid_task(pid, type, p) {
59165+ if (!have_same_root(current, p)) {
59166+ ret = 1;
59167+ goto out;
59168+ }
59169+ } while_each_pid_task(pid, type, p);
59170+out:
59171+ read_unlock(&tasklist_lock);
59172+ return ret;
59173+#endif
59174+ return 0;
59175+}
59176+
59177+int
59178+gr_pid_is_chrooted(struct task_struct *p)
59179+{
59180+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
59181+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
59182+ return 0;
59183+
59184+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
59185+ !have_same_root(current, p)) {
59186+ return 1;
59187+ }
59188+#endif
59189+ return 0;
59190+}
59191+
59192+EXPORT_SYMBOL(gr_pid_is_chrooted);
59193+
59194+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
59195+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
59196+{
59197+ struct path path, currentroot;
59198+ int ret = 0;
59199+
59200+ path.dentry = (struct dentry *)u_dentry;
59201+ path.mnt = (struct vfsmount *)u_mnt;
59202+ get_fs_root(current->fs, &currentroot);
59203+ if (path_is_under(&path, &currentroot))
59204+ ret = 1;
59205+ path_put(&currentroot);
59206+
59207+ return ret;
59208+}
59209+#endif
59210+
59211+int
59212+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
59213+{
59214+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
59215+ if (!grsec_enable_chroot_fchdir)
59216+ return 1;
59217+
59218+ if (!proc_is_chrooted(current))
59219+ return 1;
59220+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
59221+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
59222+ return 0;
59223+ }
59224+#endif
59225+ return 1;
59226+}
59227+
59228+int
59229+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59230+ const time_t shm_createtime)
59231+{
59232+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
59233+ struct task_struct *p;
59234+ time_t starttime;
59235+
59236+ if (unlikely(!grsec_enable_chroot_shmat))
59237+ return 1;
59238+
59239+ if (likely(!proc_is_chrooted(current)))
59240+ return 1;
59241+
59242+ rcu_read_lock();
59243+ read_lock(&tasklist_lock);
59244+
59245+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
59246+ starttime = p->start_time.tv_sec;
59247+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
59248+ if (have_same_root(current, p)) {
59249+ goto allow;
59250+ } else {
59251+ read_unlock(&tasklist_lock);
59252+ rcu_read_unlock();
59253+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59254+ return 0;
59255+ }
59256+ }
59257+ /* creator exited, pid reuse, fall through to next check */
59258+ }
59259+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
59260+ if (unlikely(!have_same_root(current, p))) {
59261+ read_unlock(&tasklist_lock);
59262+ rcu_read_unlock();
59263+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
59264+ return 0;
59265+ }
59266+ }
59267+
59268+allow:
59269+ read_unlock(&tasklist_lock);
59270+ rcu_read_unlock();
59271+#endif
59272+ return 1;
59273+}
59274+
59275+void
59276+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
59277+{
59278+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
59279+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
59280+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
59281+#endif
59282+ return;
59283+}
59284+
59285+int
59286+gr_handle_chroot_mknod(const struct dentry *dentry,
59287+ const struct vfsmount *mnt, const int mode)
59288+{
59289+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
59290+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
59291+ proc_is_chrooted(current)) {
59292+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
59293+ return -EPERM;
59294+ }
59295+#endif
59296+ return 0;
59297+}
59298+
59299+int
59300+gr_handle_chroot_mount(const struct dentry *dentry,
59301+ const struct vfsmount *mnt, const char *dev_name)
59302+{
59303+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
59304+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
59305+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
59306+ return -EPERM;
59307+ }
59308+#endif
59309+ return 0;
59310+}
59311+
59312+int
59313+gr_handle_chroot_pivot(void)
59314+{
59315+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
59316+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
59317+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
59318+ return -EPERM;
59319+ }
59320+#endif
59321+ return 0;
59322+}
59323+
59324+int
59325+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
59326+{
59327+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
59328+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
59329+ !gr_is_outside_chroot(dentry, mnt)) {
59330+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
59331+ return -EPERM;
59332+ }
59333+#endif
59334+ return 0;
59335+}
59336+
59337+extern const char *captab_log[];
59338+extern int captab_log_entries;
59339+
59340+int
59341+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
59342+{
59343+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59344+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59345+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59346+ if (cap_raised(chroot_caps, cap)) {
59347+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
59348+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
59349+ }
59350+ return 0;
59351+ }
59352+ }
59353+#endif
59354+ return 1;
59355+}
59356+
59357+int
59358+gr_chroot_is_capable(const int cap)
59359+{
59360+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59361+ return gr_task_chroot_is_capable(current, current_cred(), cap);
59362+#endif
59363+ return 1;
59364+}
59365+
59366+int
59367+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
59368+{
59369+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59370+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
59371+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
59372+ if (cap_raised(chroot_caps, cap)) {
59373+ return 0;
59374+ }
59375+ }
59376+#endif
59377+ return 1;
59378+}
59379+
59380+int
59381+gr_chroot_is_capable_nolog(const int cap)
59382+{
59383+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
59384+ return gr_task_chroot_is_capable_nolog(current, cap);
59385+#endif
59386+ return 1;
59387+}
59388+
59389+int
59390+gr_handle_chroot_sysctl(const int op)
59391+{
59392+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
59393+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
59394+ proc_is_chrooted(current))
59395+ return -EACCES;
59396+#endif
59397+ return 0;
59398+}
59399+
59400+void
59401+gr_handle_chroot_chdir(struct path *path)
59402+{
59403+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
59404+ if (grsec_enable_chroot_chdir)
59405+ set_fs_pwd(current->fs, path);
59406+#endif
59407+ return;
59408+}
59409+
59410+int
59411+gr_handle_chroot_chmod(const struct dentry *dentry,
59412+ const struct vfsmount *mnt, const int mode)
59413+{
59414+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
59415+ /* allow chmod +s on directories, but not files */
59416+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
59417+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
59418+ proc_is_chrooted(current)) {
59419+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
59420+ return -EPERM;
59421+ }
59422+#endif
59423+ return 0;
59424+}
59425diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
59426new file mode 100644
59427index 0000000..7de2055
59428--- /dev/null
59429+++ b/grsecurity/grsec_disabled.c
59430@@ -0,0 +1,442 @@
59431+#include <linux/kernel.h>
59432+#include <linux/module.h>
59433+#include <linux/sched.h>
59434+#include <linux/file.h>
59435+#include <linux/fs.h>
59436+#include <linux/kdev_t.h>
59437+#include <linux/net.h>
59438+#include <linux/in.h>
59439+#include <linux/ip.h>
59440+#include <linux/skbuff.h>
59441+#include <linux/sysctl.h>
59442+
59443+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59444+void
59445+pax_set_initial_flags(struct linux_binprm *bprm)
59446+{
59447+ return;
59448+}
59449+#endif
59450+
59451+#ifdef CONFIG_SYSCTL
59452+__u32
59453+gr_handle_sysctl(const struct ctl_table * table, const int op)
59454+{
59455+ return 0;
59456+}
59457+#endif
59458+
59459+#ifdef CONFIG_TASKSTATS
59460+int gr_is_taskstats_denied(int pid)
59461+{
59462+ return 0;
59463+}
59464+#endif
59465+
59466+int
59467+gr_acl_is_enabled(void)
59468+{
59469+ return 0;
59470+}
59471+
59472+void
59473+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59474+{
59475+ return;
59476+}
59477+
59478+int
59479+gr_handle_rawio(const struct inode *inode)
59480+{
59481+ return 0;
59482+}
59483+
59484+void
59485+gr_acl_handle_psacct(struct task_struct *task, const long code)
59486+{
59487+ return;
59488+}
59489+
59490+int
59491+gr_handle_ptrace(struct task_struct *task, const long request)
59492+{
59493+ return 0;
59494+}
59495+
59496+int
59497+gr_handle_proc_ptrace(struct task_struct *task)
59498+{
59499+ return 0;
59500+}
59501+
59502+void
59503+gr_learn_resource(const struct task_struct *task,
59504+ const int res, const unsigned long wanted, const int gt)
59505+{
59506+ return;
59507+}
59508+
59509+int
59510+gr_set_acls(const int type)
59511+{
59512+ return 0;
59513+}
59514+
59515+int
59516+gr_check_hidden_task(const struct task_struct *tsk)
59517+{
59518+ return 0;
59519+}
59520+
59521+int
59522+gr_check_protected_task(const struct task_struct *task)
59523+{
59524+ return 0;
59525+}
59526+
59527+int
59528+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59529+{
59530+ return 0;
59531+}
59532+
59533+void
59534+gr_copy_label(struct task_struct *tsk)
59535+{
59536+ return;
59537+}
59538+
59539+void
59540+gr_set_pax_flags(struct task_struct *task)
59541+{
59542+ return;
59543+}
59544+
59545+int
59546+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59547+ const int unsafe_share)
59548+{
59549+ return 0;
59550+}
59551+
59552+void
59553+gr_handle_delete(const ino_t ino, const dev_t dev)
59554+{
59555+ return;
59556+}
59557+
59558+void
59559+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59560+{
59561+ return;
59562+}
59563+
59564+void
59565+gr_handle_crash(struct task_struct *task, const int sig)
59566+{
59567+ return;
59568+}
59569+
59570+int
59571+gr_check_crash_exec(const struct file *filp)
59572+{
59573+ return 0;
59574+}
59575+
59576+int
59577+gr_check_crash_uid(const uid_t uid)
59578+{
59579+ return 0;
59580+}
59581+
59582+void
59583+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59584+ struct dentry *old_dentry,
59585+ struct dentry *new_dentry,
59586+ struct vfsmount *mnt, const __u8 replace)
59587+{
59588+ return;
59589+}
59590+
59591+int
59592+gr_search_socket(const int family, const int type, const int protocol)
59593+{
59594+ return 1;
59595+}
59596+
59597+int
59598+gr_search_connectbind(const int mode, const struct socket *sock,
59599+ const struct sockaddr_in *addr)
59600+{
59601+ return 0;
59602+}
59603+
59604+void
59605+gr_handle_alertkill(struct task_struct *task)
59606+{
59607+ return;
59608+}
59609+
59610+__u32
59611+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
59612+{
59613+ return 1;
59614+}
59615+
59616+__u32
59617+gr_acl_handle_hidden_file(const struct dentry * dentry,
59618+ const struct vfsmount * mnt)
59619+{
59620+ return 1;
59621+}
59622+
59623+__u32
59624+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
59625+ int acc_mode)
59626+{
59627+ return 1;
59628+}
59629+
59630+__u32
59631+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
59632+{
59633+ return 1;
59634+}
59635+
59636+__u32
59637+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
59638+{
59639+ return 1;
59640+}
59641+
59642+int
59643+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
59644+ unsigned int *vm_flags)
59645+{
59646+ return 1;
59647+}
59648+
59649+__u32
59650+gr_acl_handle_truncate(const struct dentry * dentry,
59651+ const struct vfsmount * mnt)
59652+{
59653+ return 1;
59654+}
59655+
59656+__u32
59657+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
59658+{
59659+ return 1;
59660+}
59661+
59662+__u32
59663+gr_acl_handle_access(const struct dentry * dentry,
59664+ const struct vfsmount * mnt, const int fmode)
59665+{
59666+ return 1;
59667+}
59668+
59669+__u32
59670+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
59671+ umode_t *mode)
59672+{
59673+ return 1;
59674+}
59675+
59676+__u32
59677+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
59678+{
59679+ return 1;
59680+}
59681+
59682+__u32
59683+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
59684+{
59685+ return 1;
59686+}
59687+
59688+void
59689+grsecurity_init(void)
59690+{
59691+ return;
59692+}
59693+
59694+umode_t gr_acl_umask(void)
59695+{
59696+ return 0;
59697+}
59698+
59699+__u32
59700+gr_acl_handle_mknod(const struct dentry * new_dentry,
59701+ const struct dentry * parent_dentry,
59702+ const struct vfsmount * parent_mnt,
59703+ const int mode)
59704+{
59705+ return 1;
59706+}
59707+
59708+__u32
59709+gr_acl_handle_mkdir(const struct dentry * new_dentry,
59710+ const struct dentry * parent_dentry,
59711+ const struct vfsmount * parent_mnt)
59712+{
59713+ return 1;
59714+}
59715+
59716+__u32
59717+gr_acl_handle_symlink(const struct dentry * new_dentry,
59718+ const struct dentry * parent_dentry,
59719+ const struct vfsmount * parent_mnt, const struct filename *from)
59720+{
59721+ return 1;
59722+}
59723+
59724+__u32
59725+gr_acl_handle_link(const struct dentry * new_dentry,
59726+ const struct dentry * parent_dentry,
59727+ const struct vfsmount * parent_mnt,
59728+ const struct dentry * old_dentry,
59729+ const struct vfsmount * old_mnt, const struct filename *to)
59730+{
59731+ return 1;
59732+}
59733+
59734+int
59735+gr_acl_handle_rename(const struct dentry *new_dentry,
59736+ const struct dentry *parent_dentry,
59737+ const struct vfsmount *parent_mnt,
59738+ const struct dentry *old_dentry,
59739+ const struct inode *old_parent_inode,
59740+ const struct vfsmount *old_mnt, const struct filename *newname)
59741+{
59742+ return 0;
59743+}
59744+
59745+int
59746+gr_acl_handle_filldir(const struct file *file, const char *name,
59747+ const int namelen, const ino_t ino)
59748+{
59749+ return 1;
59750+}
59751+
59752+int
59753+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
59754+ const time_t shm_createtime, const uid_t cuid, const int shmid)
59755+{
59756+ return 1;
59757+}
59758+
59759+int
59760+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
59761+{
59762+ return 0;
59763+}
59764+
59765+int
59766+gr_search_accept(const struct socket *sock)
59767+{
59768+ return 0;
59769+}
59770+
59771+int
59772+gr_search_listen(const struct socket *sock)
59773+{
59774+ return 0;
59775+}
59776+
59777+int
59778+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
59779+{
59780+ return 0;
59781+}
59782+
59783+__u32
59784+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
59785+{
59786+ return 1;
59787+}
59788+
59789+__u32
59790+gr_acl_handle_creat(const struct dentry * dentry,
59791+ const struct dentry * p_dentry,
59792+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
59793+ const int imode)
59794+{
59795+ return 1;
59796+}
59797+
59798+void
59799+gr_acl_handle_exit(void)
59800+{
59801+ return;
59802+}
59803+
59804+int
59805+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
59806+{
59807+ return 1;
59808+}
59809+
59810+void
59811+gr_set_role_label(const uid_t uid, const gid_t gid)
59812+{
59813+ return;
59814+}
59815+
59816+int
59817+gr_acl_handle_procpidmem(const struct task_struct *task)
59818+{
59819+ return 0;
59820+}
59821+
59822+int
59823+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
59824+{
59825+ return 0;
59826+}
59827+
59828+int
59829+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
59830+{
59831+ return 0;
59832+}
59833+
59834+void
59835+gr_set_kernel_label(struct task_struct *task)
59836+{
59837+ return;
59838+}
59839+
59840+int
59841+gr_check_user_change(int real, int effective, int fs)
59842+{
59843+ return 0;
59844+}
59845+
59846+int
59847+gr_check_group_change(int real, int effective, int fs)
59848+{
59849+ return 0;
59850+}
59851+
59852+int gr_acl_enable_at_secure(void)
59853+{
59854+ return 0;
59855+}
59856+
59857+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
59858+{
59859+ return dentry->d_inode->i_sb->s_dev;
59860+}
59861+
59862+void gr_put_exec_file(struct task_struct *task)
59863+{
59864+ return;
59865+}
59866+
59867+EXPORT_SYMBOL(gr_learn_resource);
59868+EXPORT_SYMBOL(gr_set_kernel_label);
59869+#ifdef CONFIG_SECURITY
59870+EXPORT_SYMBOL(gr_check_user_change);
59871+EXPORT_SYMBOL(gr_check_group_change);
59872+#endif
59873diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
59874new file mode 100644
59875index 0000000..abfa971
59876--- /dev/null
59877+++ b/grsecurity/grsec_exec.c
59878@@ -0,0 +1,174 @@
59879+#include <linux/kernel.h>
59880+#include <linux/sched.h>
59881+#include <linux/file.h>
59882+#include <linux/binfmts.h>
59883+#include <linux/fs.h>
59884+#include <linux/types.h>
59885+#include <linux/grdefs.h>
59886+#include <linux/grsecurity.h>
59887+#include <linux/grinternal.h>
59888+#include <linux/capability.h>
59889+#include <linux/module.h>
59890+
59891+#include <asm/uaccess.h>
59892+
59893+#ifdef CONFIG_GRKERNSEC_EXECLOG
59894+static char gr_exec_arg_buf[132];
59895+static DEFINE_MUTEX(gr_exec_arg_mutex);
59896+#endif
59897+
59898+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
59899+
59900+void
59901+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
59902+{
59903+#ifdef CONFIG_GRKERNSEC_EXECLOG
59904+ char *grarg = gr_exec_arg_buf;
59905+ unsigned int i, x, execlen = 0;
59906+ char c;
59907+
59908+ if (!((grsec_enable_execlog && grsec_enable_group &&
59909+ in_group_p(grsec_audit_gid))
59910+ || (grsec_enable_execlog && !grsec_enable_group)))
59911+ return;
59912+
59913+ mutex_lock(&gr_exec_arg_mutex);
59914+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
59915+
59916+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
59917+ const char __user *p;
59918+ unsigned int len;
59919+
59920+ p = get_user_arg_ptr(argv, i);
59921+ if (IS_ERR(p))
59922+ goto log;
59923+
59924+ len = strnlen_user(p, 128 - execlen);
59925+ if (len > 128 - execlen)
59926+ len = 128 - execlen;
59927+ else if (len > 0)
59928+ len--;
59929+ if (copy_from_user(grarg + execlen, p, len))
59930+ goto log;
59931+
59932+ /* rewrite unprintable characters */
59933+ for (x = 0; x < len; x++) {
59934+ c = *(grarg + execlen + x);
59935+ if (c < 32 || c > 126)
59936+ *(grarg + execlen + x) = ' ';
59937+ }
59938+
59939+ execlen += len;
59940+ *(grarg + execlen) = ' ';
59941+ *(grarg + execlen + 1) = '\0';
59942+ execlen++;
59943+ }
59944+
59945+ log:
59946+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
59947+ bprm->file->f_path.mnt, grarg);
59948+ mutex_unlock(&gr_exec_arg_mutex);
59949+#endif
59950+ return;
59951+}
59952+
59953+#ifdef CONFIG_GRKERNSEC
59954+extern int gr_acl_is_capable(const int cap);
59955+extern int gr_acl_is_capable_nolog(const int cap);
59956+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59957+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
59958+extern int gr_chroot_is_capable(const int cap);
59959+extern int gr_chroot_is_capable_nolog(const int cap);
59960+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
59961+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
59962+#endif
59963+
59964+const char *captab_log[] = {
59965+ "CAP_CHOWN",
59966+ "CAP_DAC_OVERRIDE",
59967+ "CAP_DAC_READ_SEARCH",
59968+ "CAP_FOWNER",
59969+ "CAP_FSETID",
59970+ "CAP_KILL",
59971+ "CAP_SETGID",
59972+ "CAP_SETUID",
59973+ "CAP_SETPCAP",
59974+ "CAP_LINUX_IMMUTABLE",
59975+ "CAP_NET_BIND_SERVICE",
59976+ "CAP_NET_BROADCAST",
59977+ "CAP_NET_ADMIN",
59978+ "CAP_NET_RAW",
59979+ "CAP_IPC_LOCK",
59980+ "CAP_IPC_OWNER",
59981+ "CAP_SYS_MODULE",
59982+ "CAP_SYS_RAWIO",
59983+ "CAP_SYS_CHROOT",
59984+ "CAP_SYS_PTRACE",
59985+ "CAP_SYS_PACCT",
59986+ "CAP_SYS_ADMIN",
59987+ "CAP_SYS_BOOT",
59988+ "CAP_SYS_NICE",
59989+ "CAP_SYS_RESOURCE",
59990+ "CAP_SYS_TIME",
59991+ "CAP_SYS_TTY_CONFIG",
59992+ "CAP_MKNOD",
59993+ "CAP_LEASE",
59994+ "CAP_AUDIT_WRITE",
59995+ "CAP_AUDIT_CONTROL",
59996+ "CAP_SETFCAP",
59997+ "CAP_MAC_OVERRIDE",
59998+ "CAP_MAC_ADMIN",
59999+ "CAP_SYSLOG",
60000+ "CAP_WAKE_ALARM"
60001+};
60002+
60003+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
60004+
60005+int gr_is_capable(const int cap)
60006+{
60007+#ifdef CONFIG_GRKERNSEC
60008+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
60009+ return 1;
60010+ return 0;
60011+#else
60012+ return 1;
60013+#endif
60014+}
60015+
60016+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60017+{
60018+#ifdef CONFIG_GRKERNSEC
60019+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
60020+ return 1;
60021+ return 0;
60022+#else
60023+ return 1;
60024+#endif
60025+}
60026+
60027+int gr_is_capable_nolog(const int cap)
60028+{
60029+#ifdef CONFIG_GRKERNSEC
60030+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
60031+ return 1;
60032+ return 0;
60033+#else
60034+ return 1;
60035+#endif
60036+}
60037+
60038+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
60039+{
60040+#ifdef CONFIG_GRKERNSEC
60041+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
60042+ return 1;
60043+ return 0;
60044+#else
60045+ return 1;
60046+#endif
60047+}
60048+
60049+EXPORT_SYMBOL(gr_is_capable);
60050+EXPORT_SYMBOL(gr_is_capable_nolog);
60051+EXPORT_SYMBOL(gr_task_is_capable);
60052+EXPORT_SYMBOL(gr_task_is_capable_nolog);
60053diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
60054new file mode 100644
60055index 0000000..d3ee748
60056--- /dev/null
60057+++ b/grsecurity/grsec_fifo.c
60058@@ -0,0 +1,24 @@
60059+#include <linux/kernel.h>
60060+#include <linux/sched.h>
60061+#include <linux/fs.h>
60062+#include <linux/file.h>
60063+#include <linux/grinternal.h>
60064+
60065+int
60066+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
60067+ const struct dentry *dir, const int flag, const int acc_mode)
60068+{
60069+#ifdef CONFIG_GRKERNSEC_FIFO
60070+ const struct cred *cred = current_cred();
60071+
60072+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
60073+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
60074+ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
60075+ (cred->fsuid != dentry->d_inode->i_uid)) {
60076+ if (!inode_permission(dentry->d_inode, acc_mode))
60077+ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
60078+ return -EACCES;
60079+ }
60080+#endif
60081+ return 0;
60082+}
60083diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
60084new file mode 100644
60085index 0000000..8ca18bf
60086--- /dev/null
60087+++ b/grsecurity/grsec_fork.c
60088@@ -0,0 +1,23 @@
60089+#include <linux/kernel.h>
60090+#include <linux/sched.h>
60091+#include <linux/grsecurity.h>
60092+#include <linux/grinternal.h>
60093+#include <linux/errno.h>
60094+
60095+void
60096+gr_log_forkfail(const int retval)
60097+{
60098+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60099+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
60100+ switch (retval) {
60101+ case -EAGAIN:
60102+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
60103+ break;
60104+ case -ENOMEM:
60105+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
60106+ break;
60107+ }
60108+ }
60109+#endif
60110+ return;
60111+}
60112diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
60113new file mode 100644
60114index 0000000..05a6015
60115--- /dev/null
60116+++ b/grsecurity/grsec_init.c
60117@@ -0,0 +1,283 @@
60118+#include <linux/kernel.h>
60119+#include <linux/sched.h>
60120+#include <linux/mm.h>
60121+#include <linux/gracl.h>
60122+#include <linux/slab.h>
60123+#include <linux/vmalloc.h>
60124+#include <linux/percpu.h>
60125+#include <linux/module.h>
60126+
60127+int grsec_enable_ptrace_readexec;
60128+int grsec_enable_setxid;
60129+int grsec_enable_symlinkown;
60130+int grsec_symlinkown_gid;
60131+int grsec_enable_brute;
60132+int grsec_enable_link;
60133+int grsec_enable_dmesg;
60134+int grsec_enable_harden_ptrace;
60135+int grsec_enable_fifo;
60136+int grsec_enable_execlog;
60137+int grsec_enable_signal;
60138+int grsec_enable_forkfail;
60139+int grsec_enable_audit_ptrace;
60140+int grsec_enable_time;
60141+int grsec_enable_audit_textrel;
60142+int grsec_enable_group;
60143+int grsec_audit_gid;
60144+int grsec_enable_chdir;
60145+int grsec_enable_mount;
60146+int grsec_enable_rofs;
60147+int grsec_enable_chroot_findtask;
60148+int grsec_enable_chroot_mount;
60149+int grsec_enable_chroot_shmat;
60150+int grsec_enable_chroot_fchdir;
60151+int grsec_enable_chroot_double;
60152+int grsec_enable_chroot_pivot;
60153+int grsec_enable_chroot_chdir;
60154+int grsec_enable_chroot_chmod;
60155+int grsec_enable_chroot_mknod;
60156+int grsec_enable_chroot_nice;
60157+int grsec_enable_chroot_execlog;
60158+int grsec_enable_chroot_caps;
60159+int grsec_enable_chroot_sysctl;
60160+int grsec_enable_chroot_unix;
60161+int grsec_enable_tpe;
60162+int grsec_tpe_gid;
60163+int grsec_enable_blackhole;
60164+#ifdef CONFIG_IPV6_MODULE
60165+EXPORT_SYMBOL(grsec_enable_blackhole);
60166+#endif
60167+int grsec_lastack_retries;
60168+int grsec_enable_tpe_all;
60169+int grsec_enable_tpe_invert;
60170+int grsec_enable_socket_all;
60171+int grsec_socket_all_gid;
60172+int grsec_enable_socket_client;
60173+int grsec_socket_client_gid;
60174+int grsec_enable_socket_server;
60175+int grsec_socket_server_gid;
60176+int grsec_resource_logging;
60177+int grsec_disable_privio;
60178+int grsec_enable_log_rwxmaps;
60179+int grsec_lock;
60180+
60181+DEFINE_SPINLOCK(grsec_alert_lock);
60182+unsigned long grsec_alert_wtime = 0;
60183+unsigned long grsec_alert_fyet = 0;
60184+
60185+DEFINE_SPINLOCK(grsec_audit_lock);
60186+
60187+DEFINE_RWLOCK(grsec_exec_file_lock);
60188+
60189+char *gr_shared_page[4];
60190+
60191+char *gr_alert_log_fmt;
60192+char *gr_audit_log_fmt;
60193+char *gr_alert_log_buf;
60194+char *gr_audit_log_buf;
60195+
60196+extern struct gr_arg *gr_usermode;
60197+extern unsigned char *gr_system_salt;
60198+extern unsigned char *gr_system_sum;
60199+
60200+void __init
60201+grsecurity_init(void)
60202+{
60203+ int j;
60204+ /* create the per-cpu shared pages */
60205+
60206+#ifdef CONFIG_X86
60207+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
60208+#endif
60209+
60210+ for (j = 0; j < 4; j++) {
60211+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
60212+ if (gr_shared_page[j] == NULL) {
60213+ panic("Unable to allocate grsecurity shared page");
60214+ return;
60215+ }
60216+ }
60217+
60218+ /* allocate log buffers */
60219+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
60220+ if (!gr_alert_log_fmt) {
60221+ panic("Unable to allocate grsecurity alert log format buffer");
60222+ return;
60223+ }
60224+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
60225+ if (!gr_audit_log_fmt) {
60226+ panic("Unable to allocate grsecurity audit log format buffer");
60227+ return;
60228+ }
60229+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60230+ if (!gr_alert_log_buf) {
60231+ panic("Unable to allocate grsecurity alert log buffer");
60232+ return;
60233+ }
60234+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
60235+ if (!gr_audit_log_buf) {
60236+ panic("Unable to allocate grsecurity audit log buffer");
60237+ return;
60238+ }
60239+
60240+ /* allocate memory for authentication structure */
60241+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
60242+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
60243+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
60244+
60245+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
60246+ panic("Unable to allocate grsecurity authentication structure");
60247+ return;
60248+ }
60249+
60250+
60251+#ifdef CONFIG_GRKERNSEC_IO
60252+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
60253+ grsec_disable_privio = 1;
60254+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60255+ grsec_disable_privio = 1;
60256+#else
60257+ grsec_disable_privio = 0;
60258+#endif
60259+#endif
60260+
60261+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60262+ /* for backward compatibility, tpe_invert always defaults to on if
60263+ enabled in the kernel
60264+ */
60265+ grsec_enable_tpe_invert = 1;
60266+#endif
60267+
60268+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
60269+#ifndef CONFIG_GRKERNSEC_SYSCTL
60270+ grsec_lock = 1;
60271+#endif
60272+
60273+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60274+ grsec_enable_audit_textrel = 1;
60275+#endif
60276+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60277+ grsec_enable_log_rwxmaps = 1;
60278+#endif
60279+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60280+ grsec_enable_group = 1;
60281+ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
60282+#endif
60283+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60284+ grsec_enable_ptrace_readexec = 1;
60285+#endif
60286+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60287+ grsec_enable_chdir = 1;
60288+#endif
60289+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60290+ grsec_enable_harden_ptrace = 1;
60291+#endif
60292+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60293+ grsec_enable_mount = 1;
60294+#endif
60295+#ifdef CONFIG_GRKERNSEC_LINK
60296+ grsec_enable_link = 1;
60297+#endif
60298+#ifdef CONFIG_GRKERNSEC_BRUTE
60299+ grsec_enable_brute = 1;
60300+#endif
60301+#ifdef CONFIG_GRKERNSEC_DMESG
60302+ grsec_enable_dmesg = 1;
60303+#endif
60304+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
60305+ grsec_enable_blackhole = 1;
60306+ grsec_lastack_retries = 4;
60307+#endif
60308+#ifdef CONFIG_GRKERNSEC_FIFO
60309+ grsec_enable_fifo = 1;
60310+#endif
60311+#ifdef CONFIG_GRKERNSEC_EXECLOG
60312+ grsec_enable_execlog = 1;
60313+#endif
60314+#ifdef CONFIG_GRKERNSEC_SETXID
60315+ grsec_enable_setxid = 1;
60316+#endif
60317+#ifdef CONFIG_GRKERNSEC_SIGNAL
60318+ grsec_enable_signal = 1;
60319+#endif
60320+#ifdef CONFIG_GRKERNSEC_FORKFAIL
60321+ grsec_enable_forkfail = 1;
60322+#endif
60323+#ifdef CONFIG_GRKERNSEC_TIME
60324+ grsec_enable_time = 1;
60325+#endif
60326+#ifdef CONFIG_GRKERNSEC_RESLOG
60327+ grsec_resource_logging = 1;
60328+#endif
60329+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60330+ grsec_enable_chroot_findtask = 1;
60331+#endif
60332+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60333+ grsec_enable_chroot_unix = 1;
60334+#endif
60335+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60336+ grsec_enable_chroot_mount = 1;
60337+#endif
60338+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60339+ grsec_enable_chroot_fchdir = 1;
60340+#endif
60341+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60342+ grsec_enable_chroot_shmat = 1;
60343+#endif
60344+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60345+ grsec_enable_audit_ptrace = 1;
60346+#endif
60347+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60348+ grsec_enable_chroot_double = 1;
60349+#endif
60350+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60351+ grsec_enable_chroot_pivot = 1;
60352+#endif
60353+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60354+ grsec_enable_chroot_chdir = 1;
60355+#endif
60356+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60357+ grsec_enable_chroot_chmod = 1;
60358+#endif
60359+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60360+ grsec_enable_chroot_mknod = 1;
60361+#endif
60362+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60363+ grsec_enable_chroot_nice = 1;
60364+#endif
60365+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60366+ grsec_enable_chroot_execlog = 1;
60367+#endif
60368+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60369+ grsec_enable_chroot_caps = 1;
60370+#endif
60371+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60372+ grsec_enable_chroot_sysctl = 1;
60373+#endif
60374+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60375+ grsec_enable_symlinkown = 1;
60376+ grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
60377+#endif
60378+#ifdef CONFIG_GRKERNSEC_TPE
60379+ grsec_enable_tpe = 1;
60380+ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
60381+#ifdef CONFIG_GRKERNSEC_TPE_ALL
60382+ grsec_enable_tpe_all = 1;
60383+#endif
60384+#endif
60385+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60386+ grsec_enable_socket_all = 1;
60387+ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
60388+#endif
60389+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60390+ grsec_enable_socket_client = 1;
60391+ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
60392+#endif
60393+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60394+ grsec_enable_socket_server = 1;
60395+ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
60396+#endif
60397+#endif
60398+
60399+ return;
60400+}
60401diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
60402new file mode 100644
60403index 0000000..6095407
60404--- /dev/null
60405+++ b/grsecurity/grsec_link.c
60406@@ -0,0 +1,58 @@
60407+#include <linux/kernel.h>
60408+#include <linux/sched.h>
60409+#include <linux/fs.h>
60410+#include <linux/file.h>
60411+#include <linux/grinternal.h>
60412+
60413+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
60414+{
60415+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
60416+ const struct inode *link_inode = link->dentry->d_inode;
60417+
60418+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
60419+ /* ignore root-owned links, e.g. /proc/self */
60420+ !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
60421+ !uid_eq(link_inode->i_uid, target->i_uid)) {
60422+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
60423+ return 1;
60424+ }
60425+#endif
60426+ return 0;
60427+}
60428+
60429+int
60430+gr_handle_follow_link(const struct inode *parent,
60431+ const struct inode *inode,
60432+ const struct dentry *dentry, const struct vfsmount *mnt)
60433+{
60434+#ifdef CONFIG_GRKERNSEC_LINK
60435+ const struct cred *cred = current_cred();
60436+
60437+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
60438+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
60439+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
60440+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
60441+ return -EACCES;
60442+ }
60443+#endif
60444+ return 0;
60445+}
60446+
60447+int
60448+gr_handle_hardlink(const struct dentry *dentry,
60449+ const struct vfsmount *mnt,
60450+ struct inode *inode, const int mode, const struct filename *to)
60451+{
60452+#ifdef CONFIG_GRKERNSEC_LINK
60453+ const struct cred *cred = current_cred();
60454+
60455+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
60456+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
60457+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
60458+ !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
60459+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
60460+ return -EPERM;
60461+ }
60462+#endif
60463+ return 0;
60464+}
60465diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
60466new file mode 100644
60467index 0000000..a45d2e9
60468--- /dev/null
60469+++ b/grsecurity/grsec_log.c
60470@@ -0,0 +1,322 @@
60471+#include <linux/kernel.h>
60472+#include <linux/sched.h>
60473+#include <linux/file.h>
60474+#include <linux/tty.h>
60475+#include <linux/fs.h>
60476+#include <linux/grinternal.h>
60477+
60478+#ifdef CONFIG_TREE_PREEMPT_RCU
60479+#define DISABLE_PREEMPT() preempt_disable()
60480+#define ENABLE_PREEMPT() preempt_enable()
60481+#else
60482+#define DISABLE_PREEMPT()
60483+#define ENABLE_PREEMPT()
60484+#endif
60485+
60486+#define BEGIN_LOCKS(x) \
60487+ DISABLE_PREEMPT(); \
60488+ rcu_read_lock(); \
60489+ read_lock(&tasklist_lock); \
60490+ read_lock(&grsec_exec_file_lock); \
60491+ if (x != GR_DO_AUDIT) \
60492+ spin_lock(&grsec_alert_lock); \
60493+ else \
60494+ spin_lock(&grsec_audit_lock)
60495+
60496+#define END_LOCKS(x) \
60497+ if (x != GR_DO_AUDIT) \
60498+ spin_unlock(&grsec_alert_lock); \
60499+ else \
60500+ spin_unlock(&grsec_audit_lock); \
60501+ read_unlock(&grsec_exec_file_lock); \
60502+ read_unlock(&tasklist_lock); \
60503+ rcu_read_unlock(); \
60504+ ENABLE_PREEMPT(); \
60505+ if (x == GR_DONT_AUDIT) \
60506+ gr_handle_alertkill(current)
60507+
60508+enum {
60509+ FLOODING,
60510+ NO_FLOODING
60511+};
60512+
60513+extern char *gr_alert_log_fmt;
60514+extern char *gr_audit_log_fmt;
60515+extern char *gr_alert_log_buf;
60516+extern char *gr_audit_log_buf;
60517+
60518+static int gr_log_start(int audit)
60519+{
60520+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
60521+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
60522+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60523+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
60524+ unsigned long curr_secs = get_seconds();
60525+
60526+ if (audit == GR_DO_AUDIT)
60527+ goto set_fmt;
60528+
60529+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
60530+ grsec_alert_wtime = curr_secs;
60531+ grsec_alert_fyet = 0;
60532+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
60533+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
60534+ grsec_alert_fyet++;
60535+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
60536+ grsec_alert_wtime = curr_secs;
60537+ grsec_alert_fyet++;
60538+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
60539+ return FLOODING;
60540+ }
60541+ else return FLOODING;
60542+
60543+set_fmt:
60544+#endif
60545+ memset(buf, 0, PAGE_SIZE);
60546+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
60547+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
60548+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60549+ } else if (current->signal->curr_ip) {
60550+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
60551+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
60552+ } else if (gr_acl_is_enabled()) {
60553+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
60554+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
60555+ } else {
60556+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
60557+ strcpy(buf, fmt);
60558+ }
60559+
60560+ return NO_FLOODING;
60561+}
60562+
60563+static void gr_log_middle(int audit, const char *msg, va_list ap)
60564+ __attribute__ ((format (printf, 2, 0)));
60565+
60566+static void gr_log_middle(int audit, const char *msg, va_list ap)
60567+{
60568+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60569+ unsigned int len = strlen(buf);
60570+
60571+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60572+
60573+ return;
60574+}
60575+
60576+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60577+ __attribute__ ((format (printf, 2, 3)));
60578+
60579+static void gr_log_middle_varargs(int audit, const char *msg, ...)
60580+{
60581+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60582+ unsigned int len = strlen(buf);
60583+ va_list ap;
60584+
60585+ va_start(ap, msg);
60586+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
60587+ va_end(ap);
60588+
60589+ return;
60590+}
60591+
60592+static void gr_log_end(int audit, int append_default)
60593+{
60594+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
60595+
60596+ if (append_default) {
60597+ unsigned int len = strlen(buf);
60598+ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
60599+ }
60600+
60601+ printk("%s\n", buf);
60602+
60603+ return;
60604+}
60605+
60606+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
60607+{
60608+ int logtype;
60609+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
60610+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
60611+ void *voidptr = NULL;
60612+ int num1 = 0, num2 = 0;
60613+ unsigned long ulong1 = 0, ulong2 = 0;
60614+ struct dentry *dentry = NULL;
60615+ struct vfsmount *mnt = NULL;
60616+ struct file *file = NULL;
60617+ struct task_struct *task = NULL;
60618+ const struct cred *cred, *pcred;
60619+ va_list ap;
60620+
60621+ BEGIN_LOCKS(audit);
60622+ logtype = gr_log_start(audit);
60623+ if (logtype == FLOODING) {
60624+ END_LOCKS(audit);
60625+ return;
60626+ }
60627+ va_start(ap, argtypes);
60628+ switch (argtypes) {
60629+ case GR_TTYSNIFF:
60630+ task = va_arg(ap, struct task_struct *);
60631+ gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
60632+ break;
60633+ case GR_SYSCTL_HIDDEN:
60634+ str1 = va_arg(ap, char *);
60635+ gr_log_middle_varargs(audit, msg, result, str1);
60636+ break;
60637+ case GR_RBAC:
60638+ dentry = va_arg(ap, struct dentry *);
60639+ mnt = va_arg(ap, struct vfsmount *);
60640+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
60641+ break;
60642+ case GR_RBAC_STR:
60643+ dentry = va_arg(ap, struct dentry *);
60644+ mnt = va_arg(ap, struct vfsmount *);
60645+ str1 = va_arg(ap, char *);
60646+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
60647+ break;
60648+ case GR_STR_RBAC:
60649+ str1 = va_arg(ap, char *);
60650+ dentry = va_arg(ap, struct dentry *);
60651+ mnt = va_arg(ap, struct vfsmount *);
60652+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
60653+ break;
60654+ case GR_RBAC_MODE2:
60655+ dentry = va_arg(ap, struct dentry *);
60656+ mnt = va_arg(ap, struct vfsmount *);
60657+ str1 = va_arg(ap, char *);
60658+ str2 = va_arg(ap, char *);
60659+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
60660+ break;
60661+ case GR_RBAC_MODE3:
60662+ dentry = va_arg(ap, struct dentry *);
60663+ mnt = va_arg(ap, struct vfsmount *);
60664+ str1 = va_arg(ap, char *);
60665+ str2 = va_arg(ap, char *);
60666+ str3 = va_arg(ap, char *);
60667+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
60668+ break;
60669+ case GR_FILENAME:
60670+ dentry = va_arg(ap, struct dentry *);
60671+ mnt = va_arg(ap, struct vfsmount *);
60672+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
60673+ break;
60674+ case GR_STR_FILENAME:
60675+ str1 = va_arg(ap, char *);
60676+ dentry = va_arg(ap, struct dentry *);
60677+ mnt = va_arg(ap, struct vfsmount *);
60678+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
60679+ break;
60680+ case GR_FILENAME_STR:
60681+ dentry = va_arg(ap, struct dentry *);
60682+ mnt = va_arg(ap, struct vfsmount *);
60683+ str1 = va_arg(ap, char *);
60684+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
60685+ break;
60686+ case GR_FILENAME_TWO_INT:
60687+ dentry = va_arg(ap, struct dentry *);
60688+ mnt = va_arg(ap, struct vfsmount *);
60689+ num1 = va_arg(ap, int);
60690+ num2 = va_arg(ap, int);
60691+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
60692+ break;
60693+ case GR_FILENAME_TWO_INT_STR:
60694+ dentry = va_arg(ap, struct dentry *);
60695+ mnt = va_arg(ap, struct vfsmount *);
60696+ num1 = va_arg(ap, int);
60697+ num2 = va_arg(ap, int);
60698+ str1 = va_arg(ap, char *);
60699+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
60700+ break;
60701+ case GR_TEXTREL:
60702+ file = va_arg(ap, struct file *);
60703+ ulong1 = va_arg(ap, unsigned long);
60704+ ulong2 = va_arg(ap, unsigned long);
60705+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
60706+ break;
60707+ case GR_PTRACE:
60708+ task = va_arg(ap, struct task_struct *);
60709+ 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);
60710+ break;
60711+ case GR_RESOURCE:
60712+ task = va_arg(ap, struct task_struct *);
60713+ cred = __task_cred(task);
60714+ pcred = __task_cred(task->real_parent);
60715+ ulong1 = va_arg(ap, unsigned long);
60716+ str1 = va_arg(ap, char *);
60717+ ulong2 = va_arg(ap, unsigned long);
60718+ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60719+ break;
60720+ case GR_CAP:
60721+ task = va_arg(ap, struct task_struct *);
60722+ cred = __task_cred(task);
60723+ pcred = __task_cred(task->real_parent);
60724+ str1 = va_arg(ap, char *);
60725+ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60726+ break;
60727+ case GR_SIG:
60728+ str1 = va_arg(ap, char *);
60729+ voidptr = va_arg(ap, void *);
60730+ gr_log_middle_varargs(audit, msg, str1, voidptr);
60731+ break;
60732+ case GR_SIG2:
60733+ task = va_arg(ap, struct task_struct *);
60734+ cred = __task_cred(task);
60735+ pcred = __task_cred(task->real_parent);
60736+ num1 = va_arg(ap, int);
60737+ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60738+ break;
60739+ case GR_CRASH1:
60740+ task = va_arg(ap, struct task_struct *);
60741+ cred = __task_cred(task);
60742+ pcred = __task_cred(task->real_parent);
60743+ ulong1 = va_arg(ap, unsigned long);
60744+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
60745+ break;
60746+ case GR_CRASH2:
60747+ task = va_arg(ap, struct task_struct *);
60748+ cred = __task_cred(task);
60749+ pcred = __task_cred(task->real_parent);
60750+ ulong1 = va_arg(ap, unsigned long);
60751+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
60752+ break;
60753+ case GR_RWXMAP:
60754+ file = va_arg(ap, struct file *);
60755+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
60756+ break;
60757+ case GR_PSACCT:
60758+ {
60759+ unsigned int wday, cday;
60760+ __u8 whr, chr;
60761+ __u8 wmin, cmin;
60762+ __u8 wsec, csec;
60763+ char cur_tty[64] = { 0 };
60764+ char parent_tty[64] = { 0 };
60765+
60766+ task = va_arg(ap, struct task_struct *);
60767+ wday = va_arg(ap, unsigned int);
60768+ cday = va_arg(ap, unsigned int);
60769+ whr = va_arg(ap, int);
60770+ chr = va_arg(ap, int);
60771+ wmin = va_arg(ap, int);
60772+ cmin = va_arg(ap, int);
60773+ wsec = va_arg(ap, int);
60774+ csec = va_arg(ap, int);
60775+ ulong1 = va_arg(ap, unsigned long);
60776+ cred = __task_cred(task);
60777+ pcred = __task_cred(task->real_parent);
60778+
60779+ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->gid, cred->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
60780+ }
60781+ break;
60782+ default:
60783+ gr_log_middle(audit, msg, ap);
60784+ }
60785+ va_end(ap);
60786+ // these don't need DEFAULTSECARGS printed on the end
60787+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
60788+ gr_log_end(audit, 0);
60789+ else
60790+ gr_log_end(audit, 1);
60791+ END_LOCKS(audit);
60792+}
60793diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
60794new file mode 100644
60795index 0000000..f536303
60796--- /dev/null
60797+++ b/grsecurity/grsec_mem.c
60798@@ -0,0 +1,40 @@
60799+#include <linux/kernel.h>
60800+#include <linux/sched.h>
60801+#include <linux/mm.h>
60802+#include <linux/mman.h>
60803+#include <linux/grinternal.h>
60804+
60805+void
60806+gr_handle_ioperm(void)
60807+{
60808+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
60809+ return;
60810+}
60811+
60812+void
60813+gr_handle_iopl(void)
60814+{
60815+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
60816+ return;
60817+}
60818+
60819+void
60820+gr_handle_mem_readwrite(u64 from, u64 to)
60821+{
60822+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
60823+ return;
60824+}
60825+
60826+void
60827+gr_handle_vm86(void)
60828+{
60829+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
60830+ return;
60831+}
60832+
60833+void
60834+gr_log_badprocpid(const char *entry)
60835+{
60836+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
60837+ return;
60838+}
60839diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
60840new file mode 100644
60841index 0000000..2131422
60842--- /dev/null
60843+++ b/grsecurity/grsec_mount.c
60844@@ -0,0 +1,62 @@
60845+#include <linux/kernel.h>
60846+#include <linux/sched.h>
60847+#include <linux/mount.h>
60848+#include <linux/grsecurity.h>
60849+#include <linux/grinternal.h>
60850+
60851+void
60852+gr_log_remount(const char *devname, const int retval)
60853+{
60854+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60855+ if (grsec_enable_mount && (retval >= 0))
60856+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
60857+#endif
60858+ return;
60859+}
60860+
60861+void
60862+gr_log_unmount(const char *devname, const int retval)
60863+{
60864+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60865+ if (grsec_enable_mount && (retval >= 0))
60866+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
60867+#endif
60868+ return;
60869+}
60870+
60871+void
60872+gr_log_mount(const char *from, const char *to, const int retval)
60873+{
60874+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60875+ if (grsec_enable_mount && (retval >= 0))
60876+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
60877+#endif
60878+ return;
60879+}
60880+
60881+int
60882+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
60883+{
60884+#ifdef CONFIG_GRKERNSEC_ROFS
60885+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
60886+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
60887+ return -EPERM;
60888+ } else
60889+ return 0;
60890+#endif
60891+ return 0;
60892+}
60893+
60894+int
60895+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
60896+{
60897+#ifdef CONFIG_GRKERNSEC_ROFS
60898+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
60899+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
60900+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
60901+ return -EPERM;
60902+ } else
60903+ return 0;
60904+#endif
60905+ return 0;
60906+}
60907diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
60908new file mode 100644
60909index 0000000..a3b12a0
60910--- /dev/null
60911+++ b/grsecurity/grsec_pax.c
60912@@ -0,0 +1,36 @@
60913+#include <linux/kernel.h>
60914+#include <linux/sched.h>
60915+#include <linux/mm.h>
60916+#include <linux/file.h>
60917+#include <linux/grinternal.h>
60918+#include <linux/grsecurity.h>
60919+
60920+void
60921+gr_log_textrel(struct vm_area_struct * vma)
60922+{
60923+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60924+ if (grsec_enable_audit_textrel)
60925+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
60926+#endif
60927+ return;
60928+}
60929+
60930+void
60931+gr_log_rwxmmap(struct file *file)
60932+{
60933+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60934+ if (grsec_enable_log_rwxmaps)
60935+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
60936+#endif
60937+ return;
60938+}
60939+
60940+void
60941+gr_log_rwxmprotect(struct file *file)
60942+{
60943+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
60944+ if (grsec_enable_log_rwxmaps)
60945+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
60946+#endif
60947+ return;
60948+}
60949diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
60950new file mode 100644
60951index 0000000..f7f29aa
60952--- /dev/null
60953+++ b/grsecurity/grsec_ptrace.c
60954@@ -0,0 +1,30 @@
60955+#include <linux/kernel.h>
60956+#include <linux/sched.h>
60957+#include <linux/grinternal.h>
60958+#include <linux/security.h>
60959+
60960+void
60961+gr_audit_ptrace(struct task_struct *task)
60962+{
60963+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60964+ if (grsec_enable_audit_ptrace)
60965+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
60966+#endif
60967+ return;
60968+}
60969+
60970+int
60971+gr_ptrace_readexec(struct file *file, int unsafe_flags)
60972+{
60973+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
60974+ const struct dentry *dentry = file->f_path.dentry;
60975+ const struct vfsmount *mnt = file->f_path.mnt;
60976+
60977+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
60978+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
60979+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
60980+ return -EACCES;
60981+ }
60982+#endif
60983+ return 0;
60984+}
60985diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
60986new file mode 100644
60987index 0000000..5c00416
60988--- /dev/null
60989+++ b/grsecurity/grsec_sig.c
60990@@ -0,0 +1,222 @@
60991+#include <linux/kernel.h>
60992+#include <linux/sched.h>
60993+#include <linux/delay.h>
60994+#include <linux/grsecurity.h>
60995+#include <linux/grinternal.h>
60996+#include <linux/hardirq.h>
60997+
60998+char *signames[] = {
60999+ [SIGSEGV] = "Segmentation fault",
61000+ [SIGILL] = "Illegal instruction",
61001+ [SIGABRT] = "Abort",
61002+ [SIGBUS] = "Invalid alignment/Bus error"
61003+};
61004+
61005+void
61006+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
61007+{
61008+#ifdef CONFIG_GRKERNSEC_SIGNAL
61009+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
61010+ (sig == SIGABRT) || (sig == SIGBUS))) {
61011+ if (t->pid == current->pid) {
61012+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
61013+ } else {
61014+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
61015+ }
61016+ }
61017+#endif
61018+ return;
61019+}
61020+
61021+int
61022+gr_handle_signal(const struct task_struct *p, const int sig)
61023+{
61024+#ifdef CONFIG_GRKERNSEC
61025+ /* ignore the 0 signal for protected task checks */
61026+ if (current->pid > 1 && sig && gr_check_protected_task(p)) {
61027+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
61028+ return -EPERM;
61029+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
61030+ return -EPERM;
61031+ }
61032+#endif
61033+ return 0;
61034+}
61035+
61036+#ifdef CONFIG_GRKERNSEC
61037+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
61038+
61039+int gr_fake_force_sig(int sig, struct task_struct *t)
61040+{
61041+ unsigned long int flags;
61042+ int ret, blocked, ignored;
61043+ struct k_sigaction *action;
61044+
61045+ spin_lock_irqsave(&t->sighand->siglock, flags);
61046+ action = &t->sighand->action[sig-1];
61047+ ignored = action->sa.sa_handler == SIG_IGN;
61048+ blocked = sigismember(&t->blocked, sig);
61049+ if (blocked || ignored) {
61050+ action->sa.sa_handler = SIG_DFL;
61051+ if (blocked) {
61052+ sigdelset(&t->blocked, sig);
61053+ recalc_sigpending_and_wake(t);
61054+ }
61055+ }
61056+ if (action->sa.sa_handler == SIG_DFL)
61057+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
61058+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
61059+
61060+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
61061+
61062+ return ret;
61063+}
61064+#endif
61065+
61066+#ifdef CONFIG_GRKERNSEC_BRUTE
61067+#define GR_USER_BAN_TIME (15 * 60)
61068+#define GR_DAEMON_BRUTE_TIME (30 * 60)
61069+
61070+static int __get_dumpable(unsigned long mm_flags)
61071+{
61072+ int ret;
61073+
61074+ ret = mm_flags & MMF_DUMPABLE_MASK;
61075+ return (ret >= 2) ? 2 : ret;
61076+}
61077+#endif
61078+
61079+void gr_handle_brute_attach(unsigned long mm_flags)
61080+{
61081+#ifdef CONFIG_GRKERNSEC_BRUTE
61082+ struct task_struct *p = current;
61083+ kuid_t uid = GLOBAL_ROOT_UID;
61084+ int daemon = 0;
61085+
61086+ if (!grsec_enable_brute)
61087+ return;
61088+
61089+ rcu_read_lock();
61090+ read_lock(&tasklist_lock);
61091+ read_lock(&grsec_exec_file_lock);
61092+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
61093+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
61094+ p->real_parent->brute = 1;
61095+ daemon = 1;
61096+ } else {
61097+ const struct cred *cred = __task_cred(p), *cred2;
61098+ struct task_struct *tsk, *tsk2;
61099+
61100+ if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
61101+ struct user_struct *user;
61102+
61103+ uid = cred->uid;
61104+
61105+ /* this is put upon execution past expiration */
61106+ user = find_user(uid);
61107+ if (user == NULL)
61108+ goto unlock;
61109+ user->banned = 1;
61110+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
61111+ if (user->ban_expires == ~0UL)
61112+ user->ban_expires--;
61113+
61114+ do_each_thread(tsk2, tsk) {
61115+ cred2 = __task_cred(tsk);
61116+ if (tsk != p && uid_eq(cred2->uid, uid))
61117+ gr_fake_force_sig(SIGKILL, tsk);
61118+ } while_each_thread(tsk2, tsk);
61119+ }
61120+ }
61121+unlock:
61122+ read_unlock(&grsec_exec_file_lock);
61123+ read_unlock(&tasklist_lock);
61124+ rcu_read_unlock();
61125+
61126+ if (!uid_eq(uid, GLOBAL_ROOT_UID))
61127+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
61128+ from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
61129+ else if (daemon)
61130+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
61131+
61132+#endif
61133+ return;
61134+}
61135+
61136+void gr_handle_brute_check(void)
61137+{
61138+#ifdef CONFIG_GRKERNSEC_BRUTE
61139+ struct task_struct *p = current;
61140+
61141+ if (unlikely(p->brute)) {
61142+ if (!grsec_enable_brute)
61143+ p->brute = 0;
61144+ else if (time_before(get_seconds(), p->brute_expires))
61145+ msleep(30 * 1000);
61146+ }
61147+#endif
61148+ return;
61149+}
61150+
61151+void gr_handle_kernel_exploit(void)
61152+{
61153+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
61154+ const struct cred *cred;
61155+ struct task_struct *tsk, *tsk2;
61156+ struct user_struct *user;
61157+ kuid_t uid;
61158+
61159+ if (in_irq() || in_serving_softirq() || in_nmi())
61160+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
61161+
61162+ uid = current_uid();
61163+
61164+ if (uid_eq(uid, GLOBAL_ROOT_UID))
61165+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
61166+ else {
61167+ /* kill all the processes of this user, hold a reference
61168+ to their creds struct, and prevent them from creating
61169+ another process until system reset
61170+ */
61171+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
61172+ from_kuid_munged(&init_user_ns, uid));
61173+ /* we intentionally leak this ref */
61174+ user = get_uid(current->cred->user);
61175+ if (user) {
61176+ user->banned = 1;
61177+ user->ban_expires = ~0UL;
61178+ }
61179+
61180+ read_lock(&tasklist_lock);
61181+ do_each_thread(tsk2, tsk) {
61182+ cred = __task_cred(tsk);
61183+ if (uid_eq(cred->uid, uid))
61184+ gr_fake_force_sig(SIGKILL, tsk);
61185+ } while_each_thread(tsk2, tsk);
61186+ read_unlock(&tasklist_lock);
61187+ }
61188+#endif
61189+}
61190+
61191+int __gr_process_user_ban(struct user_struct *user)
61192+{
61193+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61194+ if (unlikely(user->banned)) {
61195+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
61196+ user->banned = 0;
61197+ user->ban_expires = 0;
61198+ free_uid(user);
61199+ } else
61200+ return -EPERM;
61201+ }
61202+#endif
61203+ return 0;
61204+}
61205+
61206+int gr_process_user_ban(void)
61207+{
61208+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
61209+ return __gr_process_user_ban(current->cred->user);
61210+#endif
61211+ return 0;
61212+}
61213diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
61214new file mode 100644
61215index 0000000..4030d57
61216--- /dev/null
61217+++ b/grsecurity/grsec_sock.c
61218@@ -0,0 +1,244 @@
61219+#include <linux/kernel.h>
61220+#include <linux/module.h>
61221+#include <linux/sched.h>
61222+#include <linux/file.h>
61223+#include <linux/net.h>
61224+#include <linux/in.h>
61225+#include <linux/ip.h>
61226+#include <net/sock.h>
61227+#include <net/inet_sock.h>
61228+#include <linux/grsecurity.h>
61229+#include <linux/grinternal.h>
61230+#include <linux/gracl.h>
61231+
61232+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
61233+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
61234+
61235+EXPORT_SYMBOL(gr_search_udp_recvmsg);
61236+EXPORT_SYMBOL(gr_search_udp_sendmsg);
61237+
61238+#ifdef CONFIG_UNIX_MODULE
61239+EXPORT_SYMBOL(gr_acl_handle_unix);
61240+EXPORT_SYMBOL(gr_acl_handle_mknod);
61241+EXPORT_SYMBOL(gr_handle_chroot_unix);
61242+EXPORT_SYMBOL(gr_handle_create);
61243+#endif
61244+
61245+#ifdef CONFIG_GRKERNSEC
61246+#define gr_conn_table_size 32749
61247+struct conn_table_entry {
61248+ struct conn_table_entry *next;
61249+ struct signal_struct *sig;
61250+};
61251+
61252+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
61253+DEFINE_SPINLOCK(gr_conn_table_lock);
61254+
61255+extern const char * gr_socktype_to_name(unsigned char type);
61256+extern const char * gr_proto_to_name(unsigned char proto);
61257+extern const char * gr_sockfamily_to_name(unsigned char family);
61258+
61259+static __inline__ int
61260+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
61261+{
61262+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
61263+}
61264+
61265+static __inline__ int
61266+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
61267+ __u16 sport, __u16 dport)
61268+{
61269+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
61270+ sig->gr_sport == sport && sig->gr_dport == dport))
61271+ return 1;
61272+ else
61273+ return 0;
61274+}
61275+
61276+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
61277+{
61278+ struct conn_table_entry **match;
61279+ unsigned int index;
61280+
61281+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61282+ sig->gr_sport, sig->gr_dport,
61283+ gr_conn_table_size);
61284+
61285+ newent->sig = sig;
61286+
61287+ match = &gr_conn_table[index];
61288+ newent->next = *match;
61289+ *match = newent;
61290+
61291+ return;
61292+}
61293+
61294+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
61295+{
61296+ struct conn_table_entry *match, *last = NULL;
61297+ unsigned int index;
61298+
61299+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
61300+ sig->gr_sport, sig->gr_dport,
61301+ gr_conn_table_size);
61302+
61303+ match = gr_conn_table[index];
61304+ while (match && !conn_match(match->sig,
61305+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
61306+ sig->gr_dport)) {
61307+ last = match;
61308+ match = match->next;
61309+ }
61310+
61311+ if (match) {
61312+ if (last)
61313+ last->next = match->next;
61314+ else
61315+ gr_conn_table[index] = NULL;
61316+ kfree(match);
61317+ }
61318+
61319+ return;
61320+}
61321+
61322+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
61323+ __u16 sport, __u16 dport)
61324+{
61325+ struct conn_table_entry *match;
61326+ unsigned int index;
61327+
61328+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
61329+
61330+ match = gr_conn_table[index];
61331+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
61332+ match = match->next;
61333+
61334+ if (match)
61335+ return match->sig;
61336+ else
61337+ return NULL;
61338+}
61339+
61340+#endif
61341+
61342+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
61343+{
61344+#ifdef CONFIG_GRKERNSEC
61345+ struct signal_struct *sig = task->signal;
61346+ struct conn_table_entry *newent;
61347+
61348+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
61349+ if (newent == NULL)
61350+ return;
61351+ /* no bh lock needed since we are called with bh disabled */
61352+ spin_lock(&gr_conn_table_lock);
61353+ gr_del_task_from_ip_table_nolock(sig);
61354+ sig->gr_saddr = inet->inet_rcv_saddr;
61355+ sig->gr_daddr = inet->inet_daddr;
61356+ sig->gr_sport = inet->inet_sport;
61357+ sig->gr_dport = inet->inet_dport;
61358+ gr_add_to_task_ip_table_nolock(sig, newent);
61359+ spin_unlock(&gr_conn_table_lock);
61360+#endif
61361+ return;
61362+}
61363+
61364+void gr_del_task_from_ip_table(struct task_struct *task)
61365+{
61366+#ifdef CONFIG_GRKERNSEC
61367+ spin_lock_bh(&gr_conn_table_lock);
61368+ gr_del_task_from_ip_table_nolock(task->signal);
61369+ spin_unlock_bh(&gr_conn_table_lock);
61370+#endif
61371+ return;
61372+}
61373+
61374+void
61375+gr_attach_curr_ip(const struct sock *sk)
61376+{
61377+#ifdef CONFIG_GRKERNSEC
61378+ struct signal_struct *p, *set;
61379+ const struct inet_sock *inet = inet_sk(sk);
61380+
61381+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
61382+ return;
61383+
61384+ set = current->signal;
61385+
61386+ spin_lock_bh(&gr_conn_table_lock);
61387+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
61388+ inet->inet_dport, inet->inet_sport);
61389+ if (unlikely(p != NULL)) {
61390+ set->curr_ip = p->curr_ip;
61391+ set->used_accept = 1;
61392+ gr_del_task_from_ip_table_nolock(p);
61393+ spin_unlock_bh(&gr_conn_table_lock);
61394+ return;
61395+ }
61396+ spin_unlock_bh(&gr_conn_table_lock);
61397+
61398+ set->curr_ip = inet->inet_daddr;
61399+ set->used_accept = 1;
61400+#endif
61401+ return;
61402+}
61403+
61404+int
61405+gr_handle_sock_all(const int family, const int type, const int protocol)
61406+{
61407+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61408+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
61409+ (family != AF_UNIX)) {
61410+ if (family == AF_INET)
61411+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
61412+ else
61413+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
61414+ return -EACCES;
61415+ }
61416+#endif
61417+ return 0;
61418+}
61419+
61420+int
61421+gr_handle_sock_server(const struct sockaddr *sck)
61422+{
61423+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61424+ if (grsec_enable_socket_server &&
61425+ in_group_p(grsec_socket_server_gid) &&
61426+ sck && (sck->sa_family != AF_UNIX) &&
61427+ (sck->sa_family != AF_LOCAL)) {
61428+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61429+ return -EACCES;
61430+ }
61431+#endif
61432+ return 0;
61433+}
61434+
61435+int
61436+gr_handle_sock_server_other(const struct sock *sck)
61437+{
61438+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61439+ if (grsec_enable_socket_server &&
61440+ in_group_p(grsec_socket_server_gid) &&
61441+ sck && (sck->sk_family != AF_UNIX) &&
61442+ (sck->sk_family != AF_LOCAL)) {
61443+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
61444+ return -EACCES;
61445+ }
61446+#endif
61447+ return 0;
61448+}
61449+
61450+int
61451+gr_handle_sock_client(const struct sockaddr *sck)
61452+{
61453+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61454+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
61455+ sck && (sck->sa_family != AF_UNIX) &&
61456+ (sck->sa_family != AF_LOCAL)) {
61457+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
61458+ return -EACCES;
61459+ }
61460+#endif
61461+ return 0;
61462+}
61463diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
61464new file mode 100644
61465index 0000000..f55ef0f
61466--- /dev/null
61467+++ b/grsecurity/grsec_sysctl.c
61468@@ -0,0 +1,469 @@
61469+#include <linux/kernel.h>
61470+#include <linux/sched.h>
61471+#include <linux/sysctl.h>
61472+#include <linux/grsecurity.h>
61473+#include <linux/grinternal.h>
61474+
61475+int
61476+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
61477+{
61478+#ifdef CONFIG_GRKERNSEC_SYSCTL
61479+ if (dirname == NULL || name == NULL)
61480+ return 0;
61481+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
61482+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
61483+ return -EACCES;
61484+ }
61485+#endif
61486+ return 0;
61487+}
61488+
61489+#ifdef CONFIG_GRKERNSEC_ROFS
61490+static int __maybe_unused one = 1;
61491+#endif
61492+
61493+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
61494+struct ctl_table grsecurity_table[] = {
61495+#ifdef CONFIG_GRKERNSEC_SYSCTL
61496+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
61497+#ifdef CONFIG_GRKERNSEC_IO
61498+ {
61499+ .procname = "disable_priv_io",
61500+ .data = &grsec_disable_privio,
61501+ .maxlen = sizeof(int),
61502+ .mode = 0600,
61503+ .proc_handler = &proc_dointvec,
61504+ },
61505+#endif
61506+#endif
61507+#ifdef CONFIG_GRKERNSEC_LINK
61508+ {
61509+ .procname = "linking_restrictions",
61510+ .data = &grsec_enable_link,
61511+ .maxlen = sizeof(int),
61512+ .mode = 0600,
61513+ .proc_handler = &proc_dointvec,
61514+ },
61515+#endif
61516+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
61517+ {
61518+ .procname = "enforce_symlinksifowner",
61519+ .data = &grsec_enable_symlinkown,
61520+ .maxlen = sizeof(int),
61521+ .mode = 0600,
61522+ .proc_handler = &proc_dointvec,
61523+ },
61524+ {
61525+ .procname = "symlinkown_gid",
61526+ .data = &grsec_symlinkown_gid,
61527+ .maxlen = sizeof(int),
61528+ .mode = 0600,
61529+ .proc_handler = &proc_dointvec,
61530+ },
61531+#endif
61532+#ifdef CONFIG_GRKERNSEC_BRUTE
61533+ {
61534+ .procname = "deter_bruteforce",
61535+ .data = &grsec_enable_brute,
61536+ .maxlen = sizeof(int),
61537+ .mode = 0600,
61538+ .proc_handler = &proc_dointvec,
61539+ },
61540+#endif
61541+#ifdef CONFIG_GRKERNSEC_FIFO
61542+ {
61543+ .procname = "fifo_restrictions",
61544+ .data = &grsec_enable_fifo,
61545+ .maxlen = sizeof(int),
61546+ .mode = 0600,
61547+ .proc_handler = &proc_dointvec,
61548+ },
61549+#endif
61550+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
61551+ {
61552+ .procname = "ptrace_readexec",
61553+ .data = &grsec_enable_ptrace_readexec,
61554+ .maxlen = sizeof(int),
61555+ .mode = 0600,
61556+ .proc_handler = &proc_dointvec,
61557+ },
61558+#endif
61559+#ifdef CONFIG_GRKERNSEC_SETXID
61560+ {
61561+ .procname = "consistent_setxid",
61562+ .data = &grsec_enable_setxid,
61563+ .maxlen = sizeof(int),
61564+ .mode = 0600,
61565+ .proc_handler = &proc_dointvec,
61566+ },
61567+#endif
61568+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
61569+ {
61570+ .procname = "ip_blackhole",
61571+ .data = &grsec_enable_blackhole,
61572+ .maxlen = sizeof(int),
61573+ .mode = 0600,
61574+ .proc_handler = &proc_dointvec,
61575+ },
61576+ {
61577+ .procname = "lastack_retries",
61578+ .data = &grsec_lastack_retries,
61579+ .maxlen = sizeof(int),
61580+ .mode = 0600,
61581+ .proc_handler = &proc_dointvec,
61582+ },
61583+#endif
61584+#ifdef CONFIG_GRKERNSEC_EXECLOG
61585+ {
61586+ .procname = "exec_logging",
61587+ .data = &grsec_enable_execlog,
61588+ .maxlen = sizeof(int),
61589+ .mode = 0600,
61590+ .proc_handler = &proc_dointvec,
61591+ },
61592+#endif
61593+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
61594+ {
61595+ .procname = "rwxmap_logging",
61596+ .data = &grsec_enable_log_rwxmaps,
61597+ .maxlen = sizeof(int),
61598+ .mode = 0600,
61599+ .proc_handler = &proc_dointvec,
61600+ },
61601+#endif
61602+#ifdef CONFIG_GRKERNSEC_SIGNAL
61603+ {
61604+ .procname = "signal_logging",
61605+ .data = &grsec_enable_signal,
61606+ .maxlen = sizeof(int),
61607+ .mode = 0600,
61608+ .proc_handler = &proc_dointvec,
61609+ },
61610+#endif
61611+#ifdef CONFIG_GRKERNSEC_FORKFAIL
61612+ {
61613+ .procname = "forkfail_logging",
61614+ .data = &grsec_enable_forkfail,
61615+ .maxlen = sizeof(int),
61616+ .mode = 0600,
61617+ .proc_handler = &proc_dointvec,
61618+ },
61619+#endif
61620+#ifdef CONFIG_GRKERNSEC_TIME
61621+ {
61622+ .procname = "timechange_logging",
61623+ .data = &grsec_enable_time,
61624+ .maxlen = sizeof(int),
61625+ .mode = 0600,
61626+ .proc_handler = &proc_dointvec,
61627+ },
61628+#endif
61629+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
61630+ {
61631+ .procname = "chroot_deny_shmat",
61632+ .data = &grsec_enable_chroot_shmat,
61633+ .maxlen = sizeof(int),
61634+ .mode = 0600,
61635+ .proc_handler = &proc_dointvec,
61636+ },
61637+#endif
61638+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
61639+ {
61640+ .procname = "chroot_deny_unix",
61641+ .data = &grsec_enable_chroot_unix,
61642+ .maxlen = sizeof(int),
61643+ .mode = 0600,
61644+ .proc_handler = &proc_dointvec,
61645+ },
61646+#endif
61647+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
61648+ {
61649+ .procname = "chroot_deny_mount",
61650+ .data = &grsec_enable_chroot_mount,
61651+ .maxlen = sizeof(int),
61652+ .mode = 0600,
61653+ .proc_handler = &proc_dointvec,
61654+ },
61655+#endif
61656+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
61657+ {
61658+ .procname = "chroot_deny_fchdir",
61659+ .data = &grsec_enable_chroot_fchdir,
61660+ .maxlen = sizeof(int),
61661+ .mode = 0600,
61662+ .proc_handler = &proc_dointvec,
61663+ },
61664+#endif
61665+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
61666+ {
61667+ .procname = "chroot_deny_chroot",
61668+ .data = &grsec_enable_chroot_double,
61669+ .maxlen = sizeof(int),
61670+ .mode = 0600,
61671+ .proc_handler = &proc_dointvec,
61672+ },
61673+#endif
61674+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
61675+ {
61676+ .procname = "chroot_deny_pivot",
61677+ .data = &grsec_enable_chroot_pivot,
61678+ .maxlen = sizeof(int),
61679+ .mode = 0600,
61680+ .proc_handler = &proc_dointvec,
61681+ },
61682+#endif
61683+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
61684+ {
61685+ .procname = "chroot_enforce_chdir",
61686+ .data = &grsec_enable_chroot_chdir,
61687+ .maxlen = sizeof(int),
61688+ .mode = 0600,
61689+ .proc_handler = &proc_dointvec,
61690+ },
61691+#endif
61692+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
61693+ {
61694+ .procname = "chroot_deny_chmod",
61695+ .data = &grsec_enable_chroot_chmod,
61696+ .maxlen = sizeof(int),
61697+ .mode = 0600,
61698+ .proc_handler = &proc_dointvec,
61699+ },
61700+#endif
61701+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
61702+ {
61703+ .procname = "chroot_deny_mknod",
61704+ .data = &grsec_enable_chroot_mknod,
61705+ .maxlen = sizeof(int),
61706+ .mode = 0600,
61707+ .proc_handler = &proc_dointvec,
61708+ },
61709+#endif
61710+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
61711+ {
61712+ .procname = "chroot_restrict_nice",
61713+ .data = &grsec_enable_chroot_nice,
61714+ .maxlen = sizeof(int),
61715+ .mode = 0600,
61716+ .proc_handler = &proc_dointvec,
61717+ },
61718+#endif
61719+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
61720+ {
61721+ .procname = "chroot_execlog",
61722+ .data = &grsec_enable_chroot_execlog,
61723+ .maxlen = sizeof(int),
61724+ .mode = 0600,
61725+ .proc_handler = &proc_dointvec,
61726+ },
61727+#endif
61728+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
61729+ {
61730+ .procname = "chroot_caps",
61731+ .data = &grsec_enable_chroot_caps,
61732+ .maxlen = sizeof(int),
61733+ .mode = 0600,
61734+ .proc_handler = &proc_dointvec,
61735+ },
61736+#endif
61737+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
61738+ {
61739+ .procname = "chroot_deny_sysctl",
61740+ .data = &grsec_enable_chroot_sysctl,
61741+ .maxlen = sizeof(int),
61742+ .mode = 0600,
61743+ .proc_handler = &proc_dointvec,
61744+ },
61745+#endif
61746+#ifdef CONFIG_GRKERNSEC_TPE
61747+ {
61748+ .procname = "tpe",
61749+ .data = &grsec_enable_tpe,
61750+ .maxlen = sizeof(int),
61751+ .mode = 0600,
61752+ .proc_handler = &proc_dointvec,
61753+ },
61754+ {
61755+ .procname = "tpe_gid",
61756+ .data = &grsec_tpe_gid,
61757+ .maxlen = sizeof(int),
61758+ .mode = 0600,
61759+ .proc_handler = &proc_dointvec,
61760+ },
61761+#endif
61762+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61763+ {
61764+ .procname = "tpe_invert",
61765+ .data = &grsec_enable_tpe_invert,
61766+ .maxlen = sizeof(int),
61767+ .mode = 0600,
61768+ .proc_handler = &proc_dointvec,
61769+ },
61770+#endif
61771+#ifdef CONFIG_GRKERNSEC_TPE_ALL
61772+ {
61773+ .procname = "tpe_restrict_all",
61774+ .data = &grsec_enable_tpe_all,
61775+ .maxlen = sizeof(int),
61776+ .mode = 0600,
61777+ .proc_handler = &proc_dointvec,
61778+ },
61779+#endif
61780+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
61781+ {
61782+ .procname = "socket_all",
61783+ .data = &grsec_enable_socket_all,
61784+ .maxlen = sizeof(int),
61785+ .mode = 0600,
61786+ .proc_handler = &proc_dointvec,
61787+ },
61788+ {
61789+ .procname = "socket_all_gid",
61790+ .data = &grsec_socket_all_gid,
61791+ .maxlen = sizeof(int),
61792+ .mode = 0600,
61793+ .proc_handler = &proc_dointvec,
61794+ },
61795+#endif
61796+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
61797+ {
61798+ .procname = "socket_client",
61799+ .data = &grsec_enable_socket_client,
61800+ .maxlen = sizeof(int),
61801+ .mode = 0600,
61802+ .proc_handler = &proc_dointvec,
61803+ },
61804+ {
61805+ .procname = "socket_client_gid",
61806+ .data = &grsec_socket_client_gid,
61807+ .maxlen = sizeof(int),
61808+ .mode = 0600,
61809+ .proc_handler = &proc_dointvec,
61810+ },
61811+#endif
61812+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
61813+ {
61814+ .procname = "socket_server",
61815+ .data = &grsec_enable_socket_server,
61816+ .maxlen = sizeof(int),
61817+ .mode = 0600,
61818+ .proc_handler = &proc_dointvec,
61819+ },
61820+ {
61821+ .procname = "socket_server_gid",
61822+ .data = &grsec_socket_server_gid,
61823+ .maxlen = sizeof(int),
61824+ .mode = 0600,
61825+ .proc_handler = &proc_dointvec,
61826+ },
61827+#endif
61828+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
61829+ {
61830+ .procname = "audit_group",
61831+ .data = &grsec_enable_group,
61832+ .maxlen = sizeof(int),
61833+ .mode = 0600,
61834+ .proc_handler = &proc_dointvec,
61835+ },
61836+ {
61837+ .procname = "audit_gid",
61838+ .data = &grsec_audit_gid,
61839+ .maxlen = sizeof(int),
61840+ .mode = 0600,
61841+ .proc_handler = &proc_dointvec,
61842+ },
61843+#endif
61844+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
61845+ {
61846+ .procname = "audit_chdir",
61847+ .data = &grsec_enable_chdir,
61848+ .maxlen = sizeof(int),
61849+ .mode = 0600,
61850+ .proc_handler = &proc_dointvec,
61851+ },
61852+#endif
61853+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
61854+ {
61855+ .procname = "audit_mount",
61856+ .data = &grsec_enable_mount,
61857+ .maxlen = sizeof(int),
61858+ .mode = 0600,
61859+ .proc_handler = &proc_dointvec,
61860+ },
61861+#endif
61862+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
61863+ {
61864+ .procname = "audit_textrel",
61865+ .data = &grsec_enable_audit_textrel,
61866+ .maxlen = sizeof(int),
61867+ .mode = 0600,
61868+ .proc_handler = &proc_dointvec,
61869+ },
61870+#endif
61871+#ifdef CONFIG_GRKERNSEC_DMESG
61872+ {
61873+ .procname = "dmesg",
61874+ .data = &grsec_enable_dmesg,
61875+ .maxlen = sizeof(int),
61876+ .mode = 0600,
61877+ .proc_handler = &proc_dointvec,
61878+ },
61879+#endif
61880+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
61881+ {
61882+ .procname = "chroot_findtask",
61883+ .data = &grsec_enable_chroot_findtask,
61884+ .maxlen = sizeof(int),
61885+ .mode = 0600,
61886+ .proc_handler = &proc_dointvec,
61887+ },
61888+#endif
61889+#ifdef CONFIG_GRKERNSEC_RESLOG
61890+ {
61891+ .procname = "resource_logging",
61892+ .data = &grsec_resource_logging,
61893+ .maxlen = sizeof(int),
61894+ .mode = 0600,
61895+ .proc_handler = &proc_dointvec,
61896+ },
61897+#endif
61898+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
61899+ {
61900+ .procname = "audit_ptrace",
61901+ .data = &grsec_enable_audit_ptrace,
61902+ .maxlen = sizeof(int),
61903+ .mode = 0600,
61904+ .proc_handler = &proc_dointvec,
61905+ },
61906+#endif
61907+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61908+ {
61909+ .procname = "harden_ptrace",
61910+ .data = &grsec_enable_harden_ptrace,
61911+ .maxlen = sizeof(int),
61912+ .mode = 0600,
61913+ .proc_handler = &proc_dointvec,
61914+ },
61915+#endif
61916+ {
61917+ .procname = "grsec_lock",
61918+ .data = &grsec_lock,
61919+ .maxlen = sizeof(int),
61920+ .mode = 0600,
61921+ .proc_handler = &proc_dointvec,
61922+ },
61923+#endif
61924+#ifdef CONFIG_GRKERNSEC_ROFS
61925+ {
61926+ .procname = "romount_protect",
61927+ .data = &grsec_enable_rofs,
61928+ .maxlen = sizeof(int),
61929+ .mode = 0600,
61930+ .proc_handler = &proc_dointvec_minmax,
61931+ .extra1 = &one,
61932+ .extra2 = &one,
61933+ },
61934+#endif
61935+ { }
61936+};
61937+#endif
61938diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
61939new file mode 100644
61940index 0000000..0dc13c3
61941--- /dev/null
61942+++ b/grsecurity/grsec_time.c
61943@@ -0,0 +1,16 @@
61944+#include <linux/kernel.h>
61945+#include <linux/sched.h>
61946+#include <linux/grinternal.h>
61947+#include <linux/module.h>
61948+
61949+void
61950+gr_log_timechange(void)
61951+{
61952+#ifdef CONFIG_GRKERNSEC_TIME
61953+ if (grsec_enable_time)
61954+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
61955+#endif
61956+ return;
61957+}
61958+
61959+EXPORT_SYMBOL(gr_log_timechange);
61960diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
61961new file mode 100644
61962index 0000000..07e0dc0
61963--- /dev/null
61964+++ b/grsecurity/grsec_tpe.c
61965@@ -0,0 +1,73 @@
61966+#include <linux/kernel.h>
61967+#include <linux/sched.h>
61968+#include <linux/file.h>
61969+#include <linux/fs.h>
61970+#include <linux/grinternal.h>
61971+
61972+extern int gr_acl_tpe_check(void);
61973+
61974+int
61975+gr_tpe_allow(const struct file *file)
61976+{
61977+#ifdef CONFIG_GRKERNSEC
61978+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
61979+ const struct cred *cred = current_cred();
61980+ char *msg = NULL;
61981+ char *msg2 = NULL;
61982+
61983+ // never restrict root
61984+ if (!cred->uid)
61985+ return 1;
61986+
61987+ if (grsec_enable_tpe) {
61988+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
61989+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
61990+ msg = "not being in trusted group";
61991+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
61992+ msg = "being in untrusted group";
61993+#else
61994+ if (in_group_p(grsec_tpe_gid))
61995+ msg = "being in untrusted group";
61996+#endif
61997+ }
61998+ if (!msg && gr_acl_tpe_check())
61999+ msg = "being in untrusted role";
62000+
62001+ // not in any affected group/role
62002+ if (!msg)
62003+ goto next_check;
62004+
62005+ if (inode->i_uid)
62006+ msg2 = "file in non-root-owned directory";
62007+ else if (inode->i_mode & S_IWOTH)
62008+ msg2 = "file in world-writable directory";
62009+ else if (inode->i_mode & S_IWGRP)
62010+ msg2 = "file in group-writable directory";
62011+
62012+ if (msg && msg2) {
62013+ char fullmsg[70] = {0};
62014+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
62015+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
62016+ return 0;
62017+ }
62018+ msg = NULL;
62019+next_check:
62020+#ifdef CONFIG_GRKERNSEC_TPE_ALL
62021+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
62022+ return 1;
62023+
62024+ if (inode->i_uid && (inode->i_uid != cred->uid))
62025+ msg = "directory not owned by user";
62026+ else if (inode->i_mode & S_IWOTH)
62027+ msg = "file in world-writable directory";
62028+ else if (inode->i_mode & S_IWGRP)
62029+ msg = "file in group-writable directory";
62030+
62031+ if (msg) {
62032+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
62033+ return 0;
62034+ }
62035+#endif
62036+#endif
62037+ return 1;
62038+}
62039diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
62040new file mode 100644
62041index 0000000..9f7b1ac
62042--- /dev/null
62043+++ b/grsecurity/grsum.c
62044@@ -0,0 +1,61 @@
62045+#include <linux/err.h>
62046+#include <linux/kernel.h>
62047+#include <linux/sched.h>
62048+#include <linux/mm.h>
62049+#include <linux/scatterlist.h>
62050+#include <linux/crypto.h>
62051+#include <linux/gracl.h>
62052+
62053+
62054+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
62055+#error "crypto and sha256 must be built into the kernel"
62056+#endif
62057+
62058+int
62059+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
62060+{
62061+ char *p;
62062+ struct crypto_hash *tfm;
62063+ struct hash_desc desc;
62064+ struct scatterlist sg;
62065+ unsigned char temp_sum[GR_SHA_LEN];
62066+ volatile int retval = 0;
62067+ volatile int dummy = 0;
62068+ unsigned int i;
62069+
62070+ sg_init_table(&sg, 1);
62071+
62072+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
62073+ if (IS_ERR(tfm)) {
62074+ /* should never happen, since sha256 should be built in */
62075+ return 1;
62076+ }
62077+
62078+ desc.tfm = tfm;
62079+ desc.flags = 0;
62080+
62081+ crypto_hash_init(&desc);
62082+
62083+ p = salt;
62084+ sg_set_buf(&sg, p, GR_SALT_LEN);
62085+ crypto_hash_update(&desc, &sg, sg.length);
62086+
62087+ p = entry->pw;
62088+ sg_set_buf(&sg, p, strlen(p));
62089+
62090+ crypto_hash_update(&desc, &sg, sg.length);
62091+
62092+ crypto_hash_final(&desc, temp_sum);
62093+
62094+ memset(entry->pw, 0, GR_PW_LEN);
62095+
62096+ for (i = 0; i < GR_SHA_LEN; i++)
62097+ if (sum[i] != temp_sum[i])
62098+ retval = 1;
62099+ else
62100+ dummy = 1; // waste a cycle
62101+
62102+ crypto_free_hash(tfm);
62103+
62104+ return retval;
62105+}
62106diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
62107index 77ff547..181834f 100644
62108--- a/include/asm-generic/4level-fixup.h
62109+++ b/include/asm-generic/4level-fixup.h
62110@@ -13,8 +13,10 @@
62111 #define pmd_alloc(mm, pud, address) \
62112 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
62113 NULL: pmd_offset(pud, address))
62114+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
62115
62116 #define pud_alloc(mm, pgd, address) (pgd)
62117+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
62118 #define pud_offset(pgd, start) (pgd)
62119 #define pud_none(pud) 0
62120 #define pud_bad(pud) 0
62121diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
62122index b7babf0..04ad282 100644
62123--- a/include/asm-generic/atomic-long.h
62124+++ b/include/asm-generic/atomic-long.h
62125@@ -22,6 +22,12 @@
62126
62127 typedef atomic64_t atomic_long_t;
62128
62129+#ifdef CONFIG_PAX_REFCOUNT
62130+typedef atomic64_unchecked_t atomic_long_unchecked_t;
62131+#else
62132+typedef atomic64_t atomic_long_unchecked_t;
62133+#endif
62134+
62135 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
62136
62137 static inline long atomic_long_read(atomic_long_t *l)
62138@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62139 return (long)atomic64_read(v);
62140 }
62141
62142+#ifdef CONFIG_PAX_REFCOUNT
62143+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62144+{
62145+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62146+
62147+ return (long)atomic64_read_unchecked(v);
62148+}
62149+#endif
62150+
62151 static inline void atomic_long_set(atomic_long_t *l, long i)
62152 {
62153 atomic64_t *v = (atomic64_t *)l;
62154@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62155 atomic64_set(v, i);
62156 }
62157
62158+#ifdef CONFIG_PAX_REFCOUNT
62159+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62160+{
62161+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62162+
62163+ atomic64_set_unchecked(v, i);
62164+}
62165+#endif
62166+
62167 static inline void atomic_long_inc(atomic_long_t *l)
62168 {
62169 atomic64_t *v = (atomic64_t *)l;
62170@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62171 atomic64_inc(v);
62172 }
62173
62174+#ifdef CONFIG_PAX_REFCOUNT
62175+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62176+{
62177+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62178+
62179+ atomic64_inc_unchecked(v);
62180+}
62181+#endif
62182+
62183 static inline void atomic_long_dec(atomic_long_t *l)
62184 {
62185 atomic64_t *v = (atomic64_t *)l;
62186@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62187 atomic64_dec(v);
62188 }
62189
62190+#ifdef CONFIG_PAX_REFCOUNT
62191+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62192+{
62193+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62194+
62195+ atomic64_dec_unchecked(v);
62196+}
62197+#endif
62198+
62199 static inline void atomic_long_add(long i, atomic_long_t *l)
62200 {
62201 atomic64_t *v = (atomic64_t *)l;
62202@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62203 atomic64_add(i, v);
62204 }
62205
62206+#ifdef CONFIG_PAX_REFCOUNT
62207+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62208+{
62209+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62210+
62211+ atomic64_add_unchecked(i, v);
62212+}
62213+#endif
62214+
62215 static inline void atomic_long_sub(long i, atomic_long_t *l)
62216 {
62217 atomic64_t *v = (atomic64_t *)l;
62218@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62219 atomic64_sub(i, v);
62220 }
62221
62222+#ifdef CONFIG_PAX_REFCOUNT
62223+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62224+{
62225+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62226+
62227+ atomic64_sub_unchecked(i, v);
62228+}
62229+#endif
62230+
62231 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62232 {
62233 atomic64_t *v = (atomic64_t *)l;
62234@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62235 return (long)atomic64_add_return(i, v);
62236 }
62237
62238+#ifdef CONFIG_PAX_REFCOUNT
62239+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62240+{
62241+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62242+
62243+ return (long)atomic64_add_return_unchecked(i, v);
62244+}
62245+#endif
62246+
62247 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62248 {
62249 atomic64_t *v = (atomic64_t *)l;
62250@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62251 return (long)atomic64_inc_return(v);
62252 }
62253
62254+#ifdef CONFIG_PAX_REFCOUNT
62255+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62256+{
62257+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
62258+
62259+ return (long)atomic64_inc_return_unchecked(v);
62260+}
62261+#endif
62262+
62263 static inline long atomic_long_dec_return(atomic_long_t *l)
62264 {
62265 atomic64_t *v = (atomic64_t *)l;
62266@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62267
62268 typedef atomic_t atomic_long_t;
62269
62270+#ifdef CONFIG_PAX_REFCOUNT
62271+typedef atomic_unchecked_t atomic_long_unchecked_t;
62272+#else
62273+typedef atomic_t atomic_long_unchecked_t;
62274+#endif
62275+
62276 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
62277 static inline long atomic_long_read(atomic_long_t *l)
62278 {
62279@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
62280 return (long)atomic_read(v);
62281 }
62282
62283+#ifdef CONFIG_PAX_REFCOUNT
62284+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
62285+{
62286+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62287+
62288+ return (long)atomic_read_unchecked(v);
62289+}
62290+#endif
62291+
62292 static inline void atomic_long_set(atomic_long_t *l, long i)
62293 {
62294 atomic_t *v = (atomic_t *)l;
62295@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
62296 atomic_set(v, i);
62297 }
62298
62299+#ifdef CONFIG_PAX_REFCOUNT
62300+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
62301+{
62302+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62303+
62304+ atomic_set_unchecked(v, i);
62305+}
62306+#endif
62307+
62308 static inline void atomic_long_inc(atomic_long_t *l)
62309 {
62310 atomic_t *v = (atomic_t *)l;
62311@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
62312 atomic_inc(v);
62313 }
62314
62315+#ifdef CONFIG_PAX_REFCOUNT
62316+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
62317+{
62318+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62319+
62320+ atomic_inc_unchecked(v);
62321+}
62322+#endif
62323+
62324 static inline void atomic_long_dec(atomic_long_t *l)
62325 {
62326 atomic_t *v = (atomic_t *)l;
62327@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
62328 atomic_dec(v);
62329 }
62330
62331+#ifdef CONFIG_PAX_REFCOUNT
62332+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
62333+{
62334+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62335+
62336+ atomic_dec_unchecked(v);
62337+}
62338+#endif
62339+
62340 static inline void atomic_long_add(long i, atomic_long_t *l)
62341 {
62342 atomic_t *v = (atomic_t *)l;
62343@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
62344 atomic_add(i, v);
62345 }
62346
62347+#ifdef CONFIG_PAX_REFCOUNT
62348+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
62349+{
62350+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62351+
62352+ atomic_add_unchecked(i, v);
62353+}
62354+#endif
62355+
62356 static inline void atomic_long_sub(long i, atomic_long_t *l)
62357 {
62358 atomic_t *v = (atomic_t *)l;
62359@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
62360 atomic_sub(i, v);
62361 }
62362
62363+#ifdef CONFIG_PAX_REFCOUNT
62364+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
62365+{
62366+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62367+
62368+ atomic_sub_unchecked(i, v);
62369+}
62370+#endif
62371+
62372 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
62373 {
62374 atomic_t *v = (atomic_t *)l;
62375@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
62376 return (long)atomic_add_return(i, v);
62377 }
62378
62379+#ifdef CONFIG_PAX_REFCOUNT
62380+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
62381+{
62382+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62383+
62384+ return (long)atomic_add_return_unchecked(i, v);
62385+}
62386+
62387+#endif
62388+
62389 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
62390 {
62391 atomic_t *v = (atomic_t *)l;
62392@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
62393 return (long)atomic_inc_return(v);
62394 }
62395
62396+#ifdef CONFIG_PAX_REFCOUNT
62397+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
62398+{
62399+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
62400+
62401+ return (long)atomic_inc_return_unchecked(v);
62402+}
62403+#endif
62404+
62405 static inline long atomic_long_dec_return(atomic_long_t *l)
62406 {
62407 atomic_t *v = (atomic_t *)l;
62408@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
62409
62410 #endif /* BITS_PER_LONG == 64 */
62411
62412+#ifdef CONFIG_PAX_REFCOUNT
62413+static inline void pax_refcount_needs_these_functions(void)
62414+{
62415+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
62416+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
62417+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
62418+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
62419+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
62420+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
62421+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
62422+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
62423+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
62424+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
62425+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
62426+#ifdef CONFIG_X86
62427+ atomic_clear_mask_unchecked(0, NULL);
62428+ atomic_set_mask_unchecked(0, NULL);
62429+#endif
62430+
62431+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
62432+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
62433+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
62434+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
62435+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
62436+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
62437+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
62438+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
62439+}
62440+#else
62441+#define atomic_read_unchecked(v) atomic_read(v)
62442+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
62443+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
62444+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
62445+#define atomic_inc_unchecked(v) atomic_inc(v)
62446+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
62447+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
62448+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
62449+#define atomic_dec_unchecked(v) atomic_dec(v)
62450+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
62451+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
62452+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
62453+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
62454+
62455+#define atomic_long_read_unchecked(v) atomic_long_read(v)
62456+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
62457+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
62458+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
62459+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
62460+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
62461+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
62462+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
62463+#endif
62464+
62465 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
62466diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
62467index 1ced641..c896ee8 100644
62468--- a/include/asm-generic/atomic.h
62469+++ b/include/asm-generic/atomic.h
62470@@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
62471 * Atomically clears the bits set in @mask from @v
62472 */
62473 #ifndef atomic_clear_mask
62474-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
62475+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
62476 {
62477 unsigned long flags;
62478
62479diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
62480index b18ce4f..2ee2843 100644
62481--- a/include/asm-generic/atomic64.h
62482+++ b/include/asm-generic/atomic64.h
62483@@ -16,6 +16,8 @@ typedef struct {
62484 long long counter;
62485 } atomic64_t;
62486
62487+typedef atomic64_t atomic64_unchecked_t;
62488+
62489 #define ATOMIC64_INIT(i) { (i) }
62490
62491 extern long long atomic64_read(const atomic64_t *v);
62492@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
62493 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
62494 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
62495
62496+#define atomic64_read_unchecked(v) atomic64_read(v)
62497+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
62498+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
62499+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
62500+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
62501+#define atomic64_inc_unchecked(v) atomic64_inc(v)
62502+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
62503+#define atomic64_dec_unchecked(v) atomic64_dec(v)
62504+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
62505+
62506 #endif /* _ASM_GENERIC_ATOMIC64_H */
62507diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
62508index 1bfcfe5..e04c5c9 100644
62509--- a/include/asm-generic/cache.h
62510+++ b/include/asm-generic/cache.h
62511@@ -6,7 +6,7 @@
62512 * cache lines need to provide their own cache.h.
62513 */
62514
62515-#define L1_CACHE_SHIFT 5
62516-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
62517+#define L1_CACHE_SHIFT 5UL
62518+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
62519
62520 #endif /* __ASM_GENERIC_CACHE_H */
62521diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
62522index 0d68a1e..b74a761 100644
62523--- a/include/asm-generic/emergency-restart.h
62524+++ b/include/asm-generic/emergency-restart.h
62525@@ -1,7 +1,7 @@
62526 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
62527 #define _ASM_GENERIC_EMERGENCY_RESTART_H
62528
62529-static inline void machine_emergency_restart(void)
62530+static inline __noreturn void machine_emergency_restart(void)
62531 {
62532 machine_restart(NULL);
62533 }
62534diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
62535index 90f99c7..00ce236 100644
62536--- a/include/asm-generic/kmap_types.h
62537+++ b/include/asm-generic/kmap_types.h
62538@@ -2,9 +2,9 @@
62539 #define _ASM_GENERIC_KMAP_TYPES_H
62540
62541 #ifdef __WITH_KM_FENCE
62542-# define KM_TYPE_NR 41
62543+# define KM_TYPE_NR 42
62544 #else
62545-# define KM_TYPE_NR 20
62546+# define KM_TYPE_NR 21
62547 #endif
62548
62549 #endif
62550diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
62551index 9ceb03b..62b0b8f 100644
62552--- a/include/asm-generic/local.h
62553+++ b/include/asm-generic/local.h
62554@@ -23,24 +23,37 @@ typedef struct
62555 atomic_long_t a;
62556 } local_t;
62557
62558+typedef struct {
62559+ atomic_long_unchecked_t a;
62560+} local_unchecked_t;
62561+
62562 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
62563
62564 #define local_read(l) atomic_long_read(&(l)->a)
62565+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
62566 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
62567+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
62568 #define local_inc(l) atomic_long_inc(&(l)->a)
62569+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
62570 #define local_dec(l) atomic_long_dec(&(l)->a)
62571+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
62572 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
62573+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
62574 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
62575+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
62576
62577 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
62578 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
62579 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
62580 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
62581 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
62582+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
62583 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
62584 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
62585+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
62586
62587 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62588+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
62589 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
62590 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
62591 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
62592diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
62593index 725612b..9cc513a 100644
62594--- a/include/asm-generic/pgtable-nopmd.h
62595+++ b/include/asm-generic/pgtable-nopmd.h
62596@@ -1,14 +1,19 @@
62597 #ifndef _PGTABLE_NOPMD_H
62598 #define _PGTABLE_NOPMD_H
62599
62600-#ifndef __ASSEMBLY__
62601-
62602 #include <asm-generic/pgtable-nopud.h>
62603
62604-struct mm_struct;
62605-
62606 #define __PAGETABLE_PMD_FOLDED
62607
62608+#define PMD_SHIFT PUD_SHIFT
62609+#define PTRS_PER_PMD 1
62610+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
62611+#define PMD_MASK (~(PMD_SIZE-1))
62612+
62613+#ifndef __ASSEMBLY__
62614+
62615+struct mm_struct;
62616+
62617 /*
62618 * Having the pmd type consist of a pud gets the size right, and allows
62619 * us to conceptually access the pud entry that this pmd is folded into
62620@@ -16,11 +21,6 @@ struct mm_struct;
62621 */
62622 typedef struct { pud_t pud; } pmd_t;
62623
62624-#define PMD_SHIFT PUD_SHIFT
62625-#define PTRS_PER_PMD 1
62626-#define PMD_SIZE (1UL << PMD_SHIFT)
62627-#define PMD_MASK (~(PMD_SIZE-1))
62628-
62629 /*
62630 * The "pud_xxx()" functions here are trivial for a folded two-level
62631 * setup: the pmd is never bad, and a pmd always exists (as it's folded
62632diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
62633index 810431d..0ec4804f 100644
62634--- a/include/asm-generic/pgtable-nopud.h
62635+++ b/include/asm-generic/pgtable-nopud.h
62636@@ -1,10 +1,15 @@
62637 #ifndef _PGTABLE_NOPUD_H
62638 #define _PGTABLE_NOPUD_H
62639
62640-#ifndef __ASSEMBLY__
62641-
62642 #define __PAGETABLE_PUD_FOLDED
62643
62644+#define PUD_SHIFT PGDIR_SHIFT
62645+#define PTRS_PER_PUD 1
62646+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
62647+#define PUD_MASK (~(PUD_SIZE-1))
62648+
62649+#ifndef __ASSEMBLY__
62650+
62651 /*
62652 * Having the pud type consist of a pgd gets the size right, and allows
62653 * us to conceptually access the pgd entry that this pud is folded into
62654@@ -12,11 +17,6 @@
62655 */
62656 typedef struct { pgd_t pgd; } pud_t;
62657
62658-#define PUD_SHIFT PGDIR_SHIFT
62659-#define PTRS_PER_PUD 1
62660-#define PUD_SIZE (1UL << PUD_SHIFT)
62661-#define PUD_MASK (~(PUD_SIZE-1))
62662-
62663 /*
62664 * The "pgd_xxx()" functions here are trivial for a folded two-level
62665 * setup: the pud is never bad, and a pud always exists (as it's folded
62666@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
62667 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
62668
62669 #define pgd_populate(mm, pgd, pud) do { } while (0)
62670+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
62671 /*
62672 * (puds are folded into pgds so this doesn't get actually called,
62673 * but the define is needed for a generic inline function.)
62674diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
62675index b36ce40..019426d 100644
62676--- a/include/asm-generic/pgtable.h
62677+++ b/include/asm-generic/pgtable.h
62678@@ -554,6 +554,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
62679 #endif
62680 }
62681
62682+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
62683+static inline unsigned long pax_open_kernel(void) { return 0; }
62684+#endif
62685+
62686+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
62687+static inline unsigned long pax_close_kernel(void) { return 0; }
62688+#endif
62689+
62690 #endif /* CONFIG_MMU */
62691
62692 #endif /* !__ASSEMBLY__ */
62693diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
62694index d1ea7ce..b1ebf2a 100644
62695--- a/include/asm-generic/vmlinux.lds.h
62696+++ b/include/asm-generic/vmlinux.lds.h
62697@@ -218,6 +218,7 @@
62698 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
62699 VMLINUX_SYMBOL(__start_rodata) = .; \
62700 *(.rodata) *(.rodata.*) \
62701+ *(.data..read_only) \
62702 *(__vermagic) /* Kernel version magic */ \
62703 . = ALIGN(8); \
62704 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
62705@@ -725,17 +726,18 @@
62706 * section in the linker script will go there too. @phdr should have
62707 * a leading colon.
62708 *
62709- * Note that this macros defines __per_cpu_load as an absolute symbol.
62710+ * Note that this macros defines per_cpu_load as an absolute symbol.
62711 * If there is no need to put the percpu section at a predetermined
62712 * address, use PERCPU_SECTION.
62713 */
62714 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
62715- VMLINUX_SYMBOL(__per_cpu_load) = .; \
62716- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
62717+ per_cpu_load = .; \
62718+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
62719 - LOAD_OFFSET) { \
62720+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
62721 PERCPU_INPUT(cacheline) \
62722 } phdr \
62723- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
62724+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
62725
62726 /**
62727 * PERCPU_SECTION - define output section for percpu area, simple version
62728diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
62729index 418d270..bfd2794 100644
62730--- a/include/crypto/algapi.h
62731+++ b/include/crypto/algapi.h
62732@@ -34,7 +34,7 @@ struct crypto_type {
62733 unsigned int maskclear;
62734 unsigned int maskset;
62735 unsigned int tfmsize;
62736-};
62737+} __do_const;
62738
62739 struct crypto_instance {
62740 struct crypto_alg alg;
62741diff --git a/include/drm/drmP.h b/include/drm/drmP.h
62742index 3fd8280..2b3c415 100644
62743--- a/include/drm/drmP.h
62744+++ b/include/drm/drmP.h
62745@@ -72,6 +72,7 @@
62746 #include <linux/workqueue.h>
62747 #include <linux/poll.h>
62748 #include <asm/pgalloc.h>
62749+#include <asm/local.h>
62750 #include <drm/drm.h>
62751 #include <drm/drm_sarea.h>
62752
62753@@ -1068,7 +1069,7 @@ struct drm_device {
62754
62755 /** \name Usage Counters */
62756 /*@{ */
62757- int open_count; /**< Outstanding files open */
62758+ local_t open_count; /**< Outstanding files open */
62759 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
62760 atomic_t vma_count; /**< Outstanding vma areas open */
62761 int buf_use; /**< Buffers in use -- cannot alloc */
62762@@ -1079,7 +1080,7 @@ struct drm_device {
62763 /*@{ */
62764 unsigned long counters;
62765 enum drm_stat_type types[15];
62766- atomic_t counts[15];
62767+ atomic_unchecked_t counts[15];
62768 /*@} */
62769
62770 struct list_head filelist;
62771diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
62772index e01cc80..6fb6f25 100644
62773--- a/include/drm/drm_crtc_helper.h
62774+++ b/include/drm/drm_crtc_helper.h
62775@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
62776 struct drm_connector *connector);
62777 /* disable encoder when not in use - more explicit than dpms off */
62778 void (*disable)(struct drm_encoder *encoder);
62779-};
62780+} __no_const;
62781
62782 /**
62783 * drm_connector_helper_funcs - helper operations for connectors
62784diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
62785index d6d1da4..fdd1ac5 100644
62786--- a/include/drm/ttm/ttm_memory.h
62787+++ b/include/drm/ttm/ttm_memory.h
62788@@ -48,7 +48,7 @@
62789
62790 struct ttm_mem_shrink {
62791 int (*do_shrink) (struct ttm_mem_shrink *);
62792-};
62793+} __no_const;
62794
62795 /**
62796 * struct ttm_mem_global - Global memory accounting structure.
62797diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
62798index 22ef21c..75904ba 100644
62799--- a/include/linux/atmdev.h
62800+++ b/include/linux/atmdev.h
62801@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
62802 #endif
62803
62804 struct k_atm_aal_stats {
62805-#define __HANDLE_ITEM(i) atomic_t i
62806+#define __HANDLE_ITEM(i) atomic_unchecked_t i
62807 __AAL_STAT_ITEMS
62808 #undef __HANDLE_ITEM
62809 };
62810diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
62811index de0628e..38f42eb 100644
62812--- a/include/linux/binfmts.h
62813+++ b/include/linux/binfmts.h
62814@@ -75,6 +75,7 @@ struct linux_binfmt {
62815 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
62816 int (*load_shlib)(struct file *);
62817 int (*core_dump)(struct coredump_params *cprm);
62818+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
62819 unsigned long min_coredump; /* minimal dump size */
62820 };
62821
62822diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
62823index 1756001..ab117ec 100644
62824--- a/include/linux/blkdev.h
62825+++ b/include/linux/blkdev.h
62826@@ -1478,7 +1478,7 @@ struct block_device_operations {
62827 /* this callback is with swap_lock and sometimes page table lock held */
62828 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
62829 struct module *owner;
62830-};
62831+} __do_const;
62832
62833 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
62834 unsigned long);
62835diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
62836index 7c2e030..b72475d 100644
62837--- a/include/linux/blktrace_api.h
62838+++ b/include/linux/blktrace_api.h
62839@@ -23,7 +23,7 @@ struct blk_trace {
62840 struct dentry *dir;
62841 struct dentry *dropped_file;
62842 struct dentry *msg_file;
62843- atomic_t dropped;
62844+ atomic_unchecked_t dropped;
62845 };
62846
62847 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
62848diff --git a/include/linux/cache.h b/include/linux/cache.h
62849index 4c57065..4307975 100644
62850--- a/include/linux/cache.h
62851+++ b/include/linux/cache.h
62852@@ -16,6 +16,10 @@
62853 #define __read_mostly
62854 #endif
62855
62856+#ifndef __read_only
62857+#define __read_only __read_mostly
62858+#endif
62859+
62860 #ifndef ____cacheline_aligned
62861 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
62862 #endif
62863diff --git a/include/linux/capability.h b/include/linux/capability.h
62864index 98503b7..cc36d18 100644
62865--- a/include/linux/capability.h
62866+++ b/include/linux/capability.h
62867@@ -211,8 +211,13 @@ extern bool capable(int cap);
62868 extern bool ns_capable(struct user_namespace *ns, int cap);
62869 extern bool nsown_capable(int cap);
62870 extern bool inode_capable(const struct inode *inode, int cap);
62871+extern bool capable_nolog(int cap);
62872+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
62873+extern bool inode_capable_nolog(const struct inode *inode, int cap);
62874
62875 /* audit system wants to get cap info from files as well */
62876 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
62877
62878+extern int is_privileged_binary(const struct dentry *dentry);
62879+
62880 #endif /* !_LINUX_CAPABILITY_H */
62881diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
62882index 8609d57..86e4d79 100644
62883--- a/include/linux/cdrom.h
62884+++ b/include/linux/cdrom.h
62885@@ -87,7 +87,6 @@ struct cdrom_device_ops {
62886
62887 /* driver specifications */
62888 const int capability; /* capability flags */
62889- int n_minors; /* number of active minor devices */
62890 /* handle uniform packets for scsi type devices (scsi,atapi) */
62891 int (*generic_packet) (struct cdrom_device_info *,
62892 struct packet_command *);
62893diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
62894index 42e55de..1cd0e66 100644
62895--- a/include/linux/cleancache.h
62896+++ b/include/linux/cleancache.h
62897@@ -31,7 +31,7 @@ struct cleancache_ops {
62898 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
62899 void (*invalidate_inode)(int, struct cleancache_filekey);
62900 void (*invalidate_fs)(int);
62901-};
62902+} __no_const;
62903
62904 extern struct cleancache_ops
62905 cleancache_register_ops(struct cleancache_ops *ops);
62906diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
62907index 412bc6c..c31666e 100644
62908--- a/include/linux/compiler-gcc4.h
62909+++ b/include/linux/compiler-gcc4.h
62910@@ -32,6 +32,21 @@
62911 #define __linktime_error(message) __attribute__((__error__(message)))
62912
62913 #if __GNUC_MINOR__ >= 5
62914+
62915+#ifdef CONSTIFY_PLUGIN
62916+#define __no_const __attribute__((no_const))
62917+#define __do_const __attribute__((do_const))
62918+#endif
62919+
62920+#ifdef SIZE_OVERFLOW_PLUGIN
62921+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
62922+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
62923+#endif
62924+
62925+#ifdef LATENT_ENTROPY_PLUGIN
62926+#define __latent_entropy __attribute__((latent_entropy))
62927+#endif
62928+
62929 /*
62930 * Mark a position in code as unreachable. This can be used to
62931 * suppress control flow warnings after asm blocks that transfer
62932@@ -47,6 +62,11 @@
62933 #define __noclone __attribute__((__noclone__))
62934
62935 #endif
62936+
62937+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
62938+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
62939+#define __bos0(ptr) __bos((ptr), 0)
62940+#define __bos1(ptr) __bos((ptr), 1)
62941 #endif
62942
62943 #if __GNUC_MINOR__ >= 6
62944diff --git a/include/linux/compiler.h b/include/linux/compiler.h
62945index f430e41..38be90f 100644
62946--- a/include/linux/compiler.h
62947+++ b/include/linux/compiler.h
62948@@ -5,31 +5,62 @@
62949
62950 #ifdef __CHECKER__
62951 # define __user __attribute__((noderef, address_space(1)))
62952+# define __force_user __force __user
62953 # define __kernel __attribute__((address_space(0)))
62954+# define __force_kernel __force __kernel
62955 # define __safe __attribute__((safe))
62956 # define __force __attribute__((force))
62957 # define __nocast __attribute__((nocast))
62958 # define __iomem __attribute__((noderef, address_space(2)))
62959+# define __force_iomem __force __iomem
62960 # define __acquires(x) __attribute__((context(x,0,1)))
62961 # define __releases(x) __attribute__((context(x,1,0)))
62962 # define __acquire(x) __context__(x,1)
62963 # define __release(x) __context__(x,-1)
62964 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
62965 # define __percpu __attribute__((noderef, address_space(3)))
62966+# define __force_percpu __force __percpu
62967 #ifdef CONFIG_SPARSE_RCU_POINTER
62968 # define __rcu __attribute__((noderef, address_space(4)))
62969+# define __force_rcu __force __rcu
62970 #else
62971 # define __rcu
62972+# define __force_rcu
62973 #endif
62974 extern void __chk_user_ptr(const volatile void __user *);
62975 extern void __chk_io_ptr(const volatile void __iomem *);
62976+#elif defined(CHECKER_PLUGIN)
62977+//# define __user
62978+//# define __force_user
62979+//# define __kernel
62980+//# define __force_kernel
62981+# define __safe
62982+# define __force
62983+# define __nocast
62984+# define __iomem
62985+# define __force_iomem
62986+# define __chk_user_ptr(x) (void)0
62987+# define __chk_io_ptr(x) (void)0
62988+# define __builtin_warning(x, y...) (1)
62989+# define __acquires(x)
62990+# define __releases(x)
62991+# define __acquire(x) (void)0
62992+# define __release(x) (void)0
62993+# define __cond_lock(x,c) (c)
62994+# define __percpu
62995+# define __force_percpu
62996+# define __rcu
62997+# define __force_rcu
62998 #else
62999 # define __user
63000+# define __force_user
63001 # define __kernel
63002+# define __force_kernel
63003 # define __safe
63004 # define __force
63005 # define __nocast
63006 # define __iomem
63007+# define __force_iomem
63008 # define __chk_user_ptr(x) (void)0
63009 # define __chk_io_ptr(x) (void)0
63010 # define __builtin_warning(x, y...) (1)
63011@@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
63012 # define __release(x) (void)0
63013 # define __cond_lock(x,c) (c)
63014 # define __percpu
63015+# define __force_percpu
63016 # define __rcu
63017+# define __force_rcu
63018 #endif
63019
63020 #ifdef __KERNEL__
63021@@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63022 # define __attribute_const__ /* unimplemented */
63023 #endif
63024
63025+#ifndef __no_const
63026+# define __no_const
63027+#endif
63028+
63029+#ifndef __do_const
63030+# define __do_const
63031+#endif
63032+
63033+#ifndef __size_overflow
63034+# define __size_overflow(...)
63035+#endif
63036+
63037+#ifndef __intentional_overflow
63038+# define __intentional_overflow(...)
63039+#endif
63040+
63041+#ifndef __latent_entropy
63042+# define __latent_entropy
63043+#endif
63044+
63045 /*
63046 * Tell gcc if a function is cold. The compiler will assume any path
63047 * directly leading to the call is unlikely.
63048@@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63049 #define __cold
63050 #endif
63051
63052+#ifndef __alloc_size
63053+#define __alloc_size(...)
63054+#endif
63055+
63056+#ifndef __bos
63057+#define __bos(ptr, arg)
63058+#endif
63059+
63060+#ifndef __bos0
63061+#define __bos0(ptr)
63062+#endif
63063+
63064+#ifndef __bos1
63065+#define __bos1(ptr)
63066+#endif
63067+
63068 /* Simple shorthand for a section definition */
63069 #ifndef __section
63070 # define __section(S) __attribute__ ((__section__(#S)))
63071@@ -312,6 +381,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
63072 * use is to mediate communication between process-level code and irq/NMI
63073 * handlers, all running on the same CPU.
63074 */
63075-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
63076+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
63077+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
63078
63079 #endif /* __LINUX_COMPILER_H */
63080diff --git a/include/linux/cred.h b/include/linux/cred.h
63081index ebbed2c..908cc2c 100644
63082--- a/include/linux/cred.h
63083+++ b/include/linux/cred.h
63084@@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
63085 static inline void validate_process_creds(void)
63086 {
63087 }
63088+static inline void validate_task_creds(struct task_struct *task)
63089+{
63090+}
63091 #endif
63092
63093 /**
63094diff --git a/include/linux/crypto.h b/include/linux/crypto.h
63095index b92eadf..b4ecdc1 100644
63096--- a/include/linux/crypto.h
63097+++ b/include/linux/crypto.h
63098@@ -373,7 +373,7 @@ struct cipher_tfm {
63099 const u8 *key, unsigned int keylen);
63100 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63101 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
63102-};
63103+} __no_const;
63104
63105 struct hash_tfm {
63106 int (*init)(struct hash_desc *desc);
63107@@ -394,13 +394,13 @@ struct compress_tfm {
63108 int (*cot_decompress)(struct crypto_tfm *tfm,
63109 const u8 *src, unsigned int slen,
63110 u8 *dst, unsigned int *dlen);
63111-};
63112+} __no_const;
63113
63114 struct rng_tfm {
63115 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
63116 unsigned int dlen);
63117 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
63118-};
63119+} __no_const;
63120
63121 #define crt_ablkcipher crt_u.ablkcipher
63122 #define crt_aead crt_u.aead
63123diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
63124index 7925bf0..d5143d2 100644
63125--- a/include/linux/decompress/mm.h
63126+++ b/include/linux/decompress/mm.h
63127@@ -77,7 +77,7 @@ static void free(void *where)
63128 * warnings when not needed (indeed large_malloc / large_free are not
63129 * needed by inflate */
63130
63131-#define malloc(a) kmalloc(a, GFP_KERNEL)
63132+#define malloc(a) kmalloc((a), GFP_KERNEL)
63133 #define free(a) kfree(a)
63134
63135 #define large_malloc(a) vmalloc(a)
63136diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
63137index 94af418..b1ca7a2 100644
63138--- a/include/linux/dma-mapping.h
63139+++ b/include/linux/dma-mapping.h
63140@@ -54,7 +54,7 @@ struct dma_map_ops {
63141 u64 (*get_required_mask)(struct device *dev);
63142 #endif
63143 int is_phys;
63144-};
63145+} __do_const;
63146
63147 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
63148
63149diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
63150index d3201e4..8281e63 100644
63151--- a/include/linux/dmaengine.h
63152+++ b/include/linux/dmaengine.h
63153@@ -1018,9 +1018,9 @@ struct dma_pinned_list {
63154 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
63155 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
63156
63157-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63158+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
63159 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
63160-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63161+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
63162 struct dma_pinned_list *pinned_list, struct page *page,
63163 unsigned int offset, size_t len);
63164
63165diff --git a/include/linux/elf.h b/include/linux/elf.h
63166index 8c9048e..16a4665 100644
63167--- a/include/linux/elf.h
63168+++ b/include/linux/elf.h
63169@@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
63170 #define elf_note elf32_note
63171 #define elf_addr_t Elf32_Off
63172 #define Elf_Half Elf32_Half
63173+#define elf_dyn Elf32_Dyn
63174
63175 #else
63176
63177@@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
63178 #define elf_note elf64_note
63179 #define elf_addr_t Elf64_Off
63180 #define Elf_Half Elf64_Half
63181+#define elf_dyn Elf64_Dyn
63182
63183 #endif
63184
63185diff --git a/include/linux/filter.h b/include/linux/filter.h
63186index 24d251f..7afb83d 100644
63187--- a/include/linux/filter.h
63188+++ b/include/linux/filter.h
63189@@ -20,6 +20,7 @@ struct compat_sock_fprog {
63190
63191 struct sk_buff;
63192 struct sock;
63193+struct bpf_jit_work;
63194
63195 struct sk_filter
63196 {
63197@@ -27,6 +28,9 @@ struct sk_filter
63198 unsigned int len; /* Number of filter blocks */
63199 unsigned int (*bpf_func)(const struct sk_buff *skb,
63200 const struct sock_filter *filter);
63201+#ifdef CONFIG_BPF_JIT
63202+ struct bpf_jit_work *work;
63203+#endif
63204 struct rcu_head rcu;
63205 struct sock_filter insns[0];
63206 };
63207diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
63208index 3044254..9767f41 100644
63209--- a/include/linux/frontswap.h
63210+++ b/include/linux/frontswap.h
63211@@ -11,7 +11,7 @@ struct frontswap_ops {
63212 int (*load)(unsigned, pgoff_t, struct page *);
63213 void (*invalidate_page)(unsigned, pgoff_t);
63214 void (*invalidate_area)(unsigned);
63215-};
63216+} __no_const;
63217
63218 extern bool frontswap_enabled;
63219 extern struct frontswap_ops
63220diff --git a/include/linux/fs.h b/include/linux/fs.h
63221index 75fe9a1..8417cac 100644
63222--- a/include/linux/fs.h
63223+++ b/include/linux/fs.h
63224@@ -1543,7 +1543,8 @@ struct file_operations {
63225 int (*setlease)(struct file *, long, struct file_lock **);
63226 long (*fallocate)(struct file *file, int mode, loff_t offset,
63227 loff_t len);
63228-};
63229+} __do_const;
63230+typedef struct file_operations __no_const file_operations_no_const;
63231
63232 struct inode_operations {
63233 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
63234@@ -2667,4 +2668,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
63235 inode->i_flags |= S_NOSEC;
63236 }
63237
63238+static inline bool is_sidechannel_device(const struct inode *inode)
63239+{
63240+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
63241+ umode_t mode = inode->i_mode;
63242+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
63243+#else
63244+ return false;
63245+#endif
63246+}
63247+
63248 #endif /* _LINUX_FS_H */
63249diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
63250index 003dc0f..3c4ea97 100644
63251--- a/include/linux/fs_struct.h
63252+++ b/include/linux/fs_struct.h
63253@@ -6,7 +6,7 @@
63254 #include <linux/seqlock.h>
63255
63256 struct fs_struct {
63257- int users;
63258+ atomic_t users;
63259 spinlock_t lock;
63260 seqcount_t seq;
63261 int umask;
63262diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
63263index ce31408..b1ad003 100644
63264--- a/include/linux/fscache-cache.h
63265+++ b/include/linux/fscache-cache.h
63266@@ -102,7 +102,7 @@ struct fscache_operation {
63267 fscache_operation_release_t release;
63268 };
63269
63270-extern atomic_t fscache_op_debug_id;
63271+extern atomic_unchecked_t fscache_op_debug_id;
63272 extern void fscache_op_work_func(struct work_struct *work);
63273
63274 extern void fscache_enqueue_operation(struct fscache_operation *);
63275@@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
63276 {
63277 INIT_WORK(&op->work, fscache_op_work_func);
63278 atomic_set(&op->usage, 1);
63279- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
63280+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63281 op->processor = processor;
63282 op->release = release;
63283 INIT_LIST_HEAD(&op->pend_link);
63284diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
63285index 0fbfb46..508eb0d 100644
63286--- a/include/linux/fsnotify.h
63287+++ b/include/linux/fsnotify.h
63288@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
63289 struct inode *inode = path->dentry->d_inode;
63290 __u32 mask = FS_ACCESS;
63291
63292+ if (is_sidechannel_device(inode))
63293+ return;
63294+
63295 if (S_ISDIR(inode->i_mode))
63296 mask |= FS_ISDIR;
63297
63298@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
63299 struct inode *inode = path->dentry->d_inode;
63300 __u32 mask = FS_MODIFY;
63301
63302+ if (is_sidechannel_device(inode))
63303+ return;
63304+
63305 if (S_ISDIR(inode->i_mode))
63306 mask |= FS_ISDIR;
63307
63308@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
63309 */
63310 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
63311 {
63312- return kstrdup(name, GFP_KERNEL);
63313+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
63314 }
63315
63316 /*
63317diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
63318index 642928c..93afe6a 100644
63319--- a/include/linux/ftrace_event.h
63320+++ b/include/linux/ftrace_event.h
63321@@ -266,7 +266,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
63322 extern int trace_add_event_call(struct ftrace_event_call *call);
63323 extern void trace_remove_event_call(struct ftrace_event_call *call);
63324
63325-#define is_signed_type(type) (((type)(-1)) < 0)
63326+#define is_signed_type(type) (((type)(-1)) < (type)1)
63327
63328 int trace_set_clr_event(const char *system, const char *event, int set);
63329
63330diff --git a/include/linux/genhd.h b/include/linux/genhd.h
63331index 4f440b3..342233a 100644
63332--- a/include/linux/genhd.h
63333+++ b/include/linux/genhd.h
63334@@ -190,7 +190,7 @@ struct gendisk {
63335 struct kobject *slave_dir;
63336
63337 struct timer_rand_state *random;
63338- atomic_t sync_io; /* RAID */
63339+ atomic_unchecked_t sync_io; /* RAID */
63340 struct disk_events *ev;
63341 #ifdef CONFIG_BLK_DEV_INTEGRITY
63342 struct blk_integrity *integrity;
63343diff --git a/include/linux/gfp.h b/include/linux/gfp.h
63344index d0a7967..63c4c47 100644
63345--- a/include/linux/gfp.h
63346+++ b/include/linux/gfp.h
63347@@ -35,6 +35,12 @@ struct vm_area_struct;
63348 #define ___GFP_OTHER_NODE 0x800000u
63349 #define ___GFP_WRITE 0x1000000u
63350
63351+#ifdef CONFIG_PAX_USERCOPY_SLABS
63352+#define ___GFP_USERCOPY 0x2000000u
63353+#else
63354+#define ___GFP_USERCOPY 0
63355+#endif
63356+
63357 /*
63358 * GFP bitmasks..
63359 *
63360@@ -89,6 +95,7 @@ struct vm_area_struct;
63361 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
63362 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
63363 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
63364+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
63365
63366 /*
63367 * This may seem redundant, but it's a way of annotating false positives vs.
63368@@ -96,7 +103,7 @@ struct vm_area_struct;
63369 */
63370 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
63371
63372-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
63373+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
63374 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
63375
63376 /* This equals 0, but use constants in case they ever change */
63377@@ -150,6 +157,8 @@ struct vm_area_struct;
63378 /* 4GB DMA on some platforms */
63379 #define GFP_DMA32 __GFP_DMA32
63380
63381+#define GFP_USERCOPY __GFP_USERCOPY
63382+
63383 /* Convert GFP flags to their corresponding migrate type */
63384 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
63385 {
63386diff --git a/include/linux/gracl.h b/include/linux/gracl.h
63387new file mode 100644
63388index 0000000..ebe6d72
63389--- /dev/null
63390+++ b/include/linux/gracl.h
63391@@ -0,0 +1,319 @@
63392+#ifndef GR_ACL_H
63393+#define GR_ACL_H
63394+
63395+#include <linux/grdefs.h>
63396+#include <linux/resource.h>
63397+#include <linux/capability.h>
63398+#include <linux/dcache.h>
63399+#include <asm/resource.h>
63400+
63401+/* Major status information */
63402+
63403+#define GR_VERSION "grsecurity 2.9.1"
63404+#define GRSECURITY_VERSION 0x2901
63405+
63406+enum {
63407+ GR_SHUTDOWN = 0,
63408+ GR_ENABLE = 1,
63409+ GR_SPROLE = 2,
63410+ GR_RELOAD = 3,
63411+ GR_SEGVMOD = 4,
63412+ GR_STATUS = 5,
63413+ GR_UNSPROLE = 6,
63414+ GR_PASSSET = 7,
63415+ GR_SPROLEPAM = 8,
63416+};
63417+
63418+/* Password setup definitions
63419+ * kernel/grhash.c */
63420+enum {
63421+ GR_PW_LEN = 128,
63422+ GR_SALT_LEN = 16,
63423+ GR_SHA_LEN = 32,
63424+};
63425+
63426+enum {
63427+ GR_SPROLE_LEN = 64,
63428+};
63429+
63430+enum {
63431+ GR_NO_GLOB = 0,
63432+ GR_REG_GLOB,
63433+ GR_CREATE_GLOB
63434+};
63435+
63436+#define GR_NLIMITS 32
63437+
63438+/* Begin Data Structures */
63439+
63440+struct sprole_pw {
63441+ unsigned char *rolename;
63442+ unsigned char salt[GR_SALT_LEN];
63443+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
63444+};
63445+
63446+struct name_entry {
63447+ __u32 key;
63448+ ino_t inode;
63449+ dev_t device;
63450+ char *name;
63451+ __u16 len;
63452+ __u8 deleted;
63453+ struct name_entry *prev;
63454+ struct name_entry *next;
63455+};
63456+
63457+struct inodev_entry {
63458+ struct name_entry *nentry;
63459+ struct inodev_entry *prev;
63460+ struct inodev_entry *next;
63461+};
63462+
63463+struct acl_role_db {
63464+ struct acl_role_label **r_hash;
63465+ __u32 r_size;
63466+};
63467+
63468+struct inodev_db {
63469+ struct inodev_entry **i_hash;
63470+ __u32 i_size;
63471+};
63472+
63473+struct name_db {
63474+ struct name_entry **n_hash;
63475+ __u32 n_size;
63476+};
63477+
63478+struct crash_uid {
63479+ uid_t uid;
63480+ unsigned long expires;
63481+};
63482+
63483+struct gr_hash_struct {
63484+ void **table;
63485+ void **nametable;
63486+ void *first;
63487+ __u32 table_size;
63488+ __u32 used_size;
63489+ int type;
63490+};
63491+
63492+/* Userspace Grsecurity ACL data structures */
63493+
63494+struct acl_subject_label {
63495+ char *filename;
63496+ ino_t inode;
63497+ dev_t device;
63498+ __u32 mode;
63499+ kernel_cap_t cap_mask;
63500+ kernel_cap_t cap_lower;
63501+ kernel_cap_t cap_invert_audit;
63502+
63503+ struct rlimit res[GR_NLIMITS];
63504+ __u32 resmask;
63505+
63506+ __u8 user_trans_type;
63507+ __u8 group_trans_type;
63508+ uid_t *user_transitions;
63509+ gid_t *group_transitions;
63510+ __u16 user_trans_num;
63511+ __u16 group_trans_num;
63512+
63513+ __u32 sock_families[2];
63514+ __u32 ip_proto[8];
63515+ __u32 ip_type;
63516+ struct acl_ip_label **ips;
63517+ __u32 ip_num;
63518+ __u32 inaddr_any_override;
63519+
63520+ __u32 crashes;
63521+ unsigned long expires;
63522+
63523+ struct acl_subject_label *parent_subject;
63524+ struct gr_hash_struct *hash;
63525+ struct acl_subject_label *prev;
63526+ struct acl_subject_label *next;
63527+
63528+ struct acl_object_label **obj_hash;
63529+ __u32 obj_hash_size;
63530+ __u16 pax_flags;
63531+};
63532+
63533+struct role_allowed_ip {
63534+ __u32 addr;
63535+ __u32 netmask;
63536+
63537+ struct role_allowed_ip *prev;
63538+ struct role_allowed_ip *next;
63539+};
63540+
63541+struct role_transition {
63542+ char *rolename;
63543+
63544+ struct role_transition *prev;
63545+ struct role_transition *next;
63546+};
63547+
63548+struct acl_role_label {
63549+ char *rolename;
63550+ uid_t uidgid;
63551+ __u16 roletype;
63552+
63553+ __u16 auth_attempts;
63554+ unsigned long expires;
63555+
63556+ struct acl_subject_label *root_label;
63557+ struct gr_hash_struct *hash;
63558+
63559+ struct acl_role_label *prev;
63560+ struct acl_role_label *next;
63561+
63562+ struct role_transition *transitions;
63563+ struct role_allowed_ip *allowed_ips;
63564+ uid_t *domain_children;
63565+ __u16 domain_child_num;
63566+
63567+ umode_t umask;
63568+
63569+ struct acl_subject_label **subj_hash;
63570+ __u32 subj_hash_size;
63571+};
63572+
63573+struct user_acl_role_db {
63574+ struct acl_role_label **r_table;
63575+ __u32 num_pointers; /* Number of allocations to track */
63576+ __u32 num_roles; /* Number of roles */
63577+ __u32 num_domain_children; /* Number of domain children */
63578+ __u32 num_subjects; /* Number of subjects */
63579+ __u32 num_objects; /* Number of objects */
63580+};
63581+
63582+struct acl_object_label {
63583+ char *filename;
63584+ ino_t inode;
63585+ dev_t device;
63586+ __u32 mode;
63587+
63588+ struct acl_subject_label *nested;
63589+ struct acl_object_label *globbed;
63590+
63591+ /* next two structures not used */
63592+
63593+ struct acl_object_label *prev;
63594+ struct acl_object_label *next;
63595+};
63596+
63597+struct acl_ip_label {
63598+ char *iface;
63599+ __u32 addr;
63600+ __u32 netmask;
63601+ __u16 low, high;
63602+ __u8 mode;
63603+ __u32 type;
63604+ __u32 proto[8];
63605+
63606+ /* next two structures not used */
63607+
63608+ struct acl_ip_label *prev;
63609+ struct acl_ip_label *next;
63610+};
63611+
63612+struct gr_arg {
63613+ struct user_acl_role_db role_db;
63614+ unsigned char pw[GR_PW_LEN];
63615+ unsigned char salt[GR_SALT_LEN];
63616+ unsigned char sum[GR_SHA_LEN];
63617+ unsigned char sp_role[GR_SPROLE_LEN];
63618+ struct sprole_pw *sprole_pws;
63619+ dev_t segv_device;
63620+ ino_t segv_inode;
63621+ uid_t segv_uid;
63622+ __u16 num_sprole_pws;
63623+ __u16 mode;
63624+};
63625+
63626+struct gr_arg_wrapper {
63627+ struct gr_arg *arg;
63628+ __u32 version;
63629+ __u32 size;
63630+};
63631+
63632+struct subject_map {
63633+ struct acl_subject_label *user;
63634+ struct acl_subject_label *kernel;
63635+ struct subject_map *prev;
63636+ struct subject_map *next;
63637+};
63638+
63639+struct acl_subj_map_db {
63640+ struct subject_map **s_hash;
63641+ __u32 s_size;
63642+};
63643+
63644+/* End Data Structures Section */
63645+
63646+/* Hash functions generated by empirical testing by Brad Spengler
63647+ Makes good use of the low bits of the inode. Generally 0-1 times
63648+ in loop for successful match. 0-3 for unsuccessful match.
63649+ Shift/add algorithm with modulus of table size and an XOR*/
63650+
63651+static __inline__ unsigned int
63652+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
63653+{
63654+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
63655+}
63656+
63657+ static __inline__ unsigned int
63658+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
63659+{
63660+ return ((const unsigned long)userp % sz);
63661+}
63662+
63663+static __inline__ unsigned int
63664+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
63665+{
63666+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
63667+}
63668+
63669+static __inline__ unsigned int
63670+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
63671+{
63672+ return full_name_hash((const unsigned char *)name, len) % sz;
63673+}
63674+
63675+#define FOR_EACH_ROLE_START(role) \
63676+ role = role_list; \
63677+ while (role) {
63678+
63679+#define FOR_EACH_ROLE_END(role) \
63680+ role = role->prev; \
63681+ }
63682+
63683+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
63684+ subj = NULL; \
63685+ iter = 0; \
63686+ while (iter < role->subj_hash_size) { \
63687+ if (subj == NULL) \
63688+ subj = role->subj_hash[iter]; \
63689+ if (subj == NULL) { \
63690+ iter++; \
63691+ continue; \
63692+ }
63693+
63694+#define FOR_EACH_SUBJECT_END(subj,iter) \
63695+ subj = subj->next; \
63696+ if (subj == NULL) \
63697+ iter++; \
63698+ }
63699+
63700+
63701+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
63702+ subj = role->hash->first; \
63703+ while (subj != NULL) {
63704+
63705+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
63706+ subj = subj->next; \
63707+ }
63708+
63709+#endif
63710+
63711diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
63712new file mode 100644
63713index 0000000..323ecf2
63714--- /dev/null
63715+++ b/include/linux/gralloc.h
63716@@ -0,0 +1,9 @@
63717+#ifndef __GRALLOC_H
63718+#define __GRALLOC_H
63719+
63720+void acl_free_all(void);
63721+int acl_alloc_stack_init(unsigned long size);
63722+void *acl_alloc(unsigned long len);
63723+void *acl_alloc_num(unsigned long num, unsigned long len);
63724+
63725+#endif
63726diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
63727new file mode 100644
63728index 0000000..be66033
63729--- /dev/null
63730+++ b/include/linux/grdefs.h
63731@@ -0,0 +1,140 @@
63732+#ifndef GRDEFS_H
63733+#define GRDEFS_H
63734+
63735+/* Begin grsecurity status declarations */
63736+
63737+enum {
63738+ GR_READY = 0x01,
63739+ GR_STATUS_INIT = 0x00 // disabled state
63740+};
63741+
63742+/* Begin ACL declarations */
63743+
63744+/* Role flags */
63745+
63746+enum {
63747+ GR_ROLE_USER = 0x0001,
63748+ GR_ROLE_GROUP = 0x0002,
63749+ GR_ROLE_DEFAULT = 0x0004,
63750+ GR_ROLE_SPECIAL = 0x0008,
63751+ GR_ROLE_AUTH = 0x0010,
63752+ GR_ROLE_NOPW = 0x0020,
63753+ GR_ROLE_GOD = 0x0040,
63754+ GR_ROLE_LEARN = 0x0080,
63755+ GR_ROLE_TPE = 0x0100,
63756+ GR_ROLE_DOMAIN = 0x0200,
63757+ GR_ROLE_PAM = 0x0400,
63758+ GR_ROLE_PERSIST = 0x0800
63759+};
63760+
63761+/* ACL Subject and Object mode flags */
63762+enum {
63763+ GR_DELETED = 0x80000000
63764+};
63765+
63766+/* ACL Object-only mode flags */
63767+enum {
63768+ GR_READ = 0x00000001,
63769+ GR_APPEND = 0x00000002,
63770+ GR_WRITE = 0x00000004,
63771+ GR_EXEC = 0x00000008,
63772+ GR_FIND = 0x00000010,
63773+ GR_INHERIT = 0x00000020,
63774+ GR_SETID = 0x00000040,
63775+ GR_CREATE = 0x00000080,
63776+ GR_DELETE = 0x00000100,
63777+ GR_LINK = 0x00000200,
63778+ GR_AUDIT_READ = 0x00000400,
63779+ GR_AUDIT_APPEND = 0x00000800,
63780+ GR_AUDIT_WRITE = 0x00001000,
63781+ GR_AUDIT_EXEC = 0x00002000,
63782+ GR_AUDIT_FIND = 0x00004000,
63783+ GR_AUDIT_INHERIT= 0x00008000,
63784+ GR_AUDIT_SETID = 0x00010000,
63785+ GR_AUDIT_CREATE = 0x00020000,
63786+ GR_AUDIT_DELETE = 0x00040000,
63787+ GR_AUDIT_LINK = 0x00080000,
63788+ GR_PTRACERD = 0x00100000,
63789+ GR_NOPTRACE = 0x00200000,
63790+ GR_SUPPRESS = 0x00400000,
63791+ GR_NOLEARN = 0x00800000,
63792+ GR_INIT_TRANSFER= 0x01000000
63793+};
63794+
63795+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
63796+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
63797+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
63798+
63799+/* ACL subject-only mode flags */
63800+enum {
63801+ GR_KILL = 0x00000001,
63802+ GR_VIEW = 0x00000002,
63803+ GR_PROTECTED = 0x00000004,
63804+ GR_LEARN = 0x00000008,
63805+ GR_OVERRIDE = 0x00000010,
63806+ /* just a placeholder, this mode is only used in userspace */
63807+ GR_DUMMY = 0x00000020,
63808+ GR_PROTSHM = 0x00000040,
63809+ GR_KILLPROC = 0x00000080,
63810+ GR_KILLIPPROC = 0x00000100,
63811+ /* just a placeholder, this mode is only used in userspace */
63812+ GR_NOTROJAN = 0x00000200,
63813+ GR_PROTPROCFD = 0x00000400,
63814+ GR_PROCACCT = 0x00000800,
63815+ GR_RELAXPTRACE = 0x00001000,
63816+ //GR_NESTED = 0x00002000,
63817+ GR_INHERITLEARN = 0x00004000,
63818+ GR_PROCFIND = 0x00008000,
63819+ GR_POVERRIDE = 0x00010000,
63820+ GR_KERNELAUTH = 0x00020000,
63821+ GR_ATSECURE = 0x00040000,
63822+ GR_SHMEXEC = 0x00080000
63823+};
63824+
63825+enum {
63826+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
63827+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
63828+ GR_PAX_ENABLE_MPROTECT = 0x0004,
63829+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
63830+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
63831+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
63832+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
63833+ GR_PAX_DISABLE_MPROTECT = 0x0400,
63834+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
63835+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
63836+};
63837+
63838+enum {
63839+ GR_ID_USER = 0x01,
63840+ GR_ID_GROUP = 0x02,
63841+};
63842+
63843+enum {
63844+ GR_ID_ALLOW = 0x01,
63845+ GR_ID_DENY = 0x02,
63846+};
63847+
63848+#define GR_CRASH_RES 31
63849+#define GR_UIDTABLE_MAX 500
63850+
63851+/* begin resource learning section */
63852+enum {
63853+ GR_RLIM_CPU_BUMP = 60,
63854+ GR_RLIM_FSIZE_BUMP = 50000,
63855+ GR_RLIM_DATA_BUMP = 10000,
63856+ GR_RLIM_STACK_BUMP = 1000,
63857+ GR_RLIM_CORE_BUMP = 10000,
63858+ GR_RLIM_RSS_BUMP = 500000,
63859+ GR_RLIM_NPROC_BUMP = 1,
63860+ GR_RLIM_NOFILE_BUMP = 5,
63861+ GR_RLIM_MEMLOCK_BUMP = 50000,
63862+ GR_RLIM_AS_BUMP = 500000,
63863+ GR_RLIM_LOCKS_BUMP = 2,
63864+ GR_RLIM_SIGPENDING_BUMP = 5,
63865+ GR_RLIM_MSGQUEUE_BUMP = 10000,
63866+ GR_RLIM_NICE_BUMP = 1,
63867+ GR_RLIM_RTPRIO_BUMP = 1,
63868+ GR_RLIM_RTTIME_BUMP = 1000000
63869+};
63870+
63871+#endif
63872diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
63873new file mode 100644
63874index 0000000..c9292f7
63875--- /dev/null
63876+++ b/include/linux/grinternal.h
63877@@ -0,0 +1,223 @@
63878+#ifndef __GRINTERNAL_H
63879+#define __GRINTERNAL_H
63880+
63881+#ifdef CONFIG_GRKERNSEC
63882+
63883+#include <linux/fs.h>
63884+#include <linux/mnt_namespace.h>
63885+#include <linux/nsproxy.h>
63886+#include <linux/gracl.h>
63887+#include <linux/grdefs.h>
63888+#include <linux/grmsg.h>
63889+
63890+void gr_add_learn_entry(const char *fmt, ...)
63891+ __attribute__ ((format (printf, 1, 2)));
63892+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
63893+ const struct vfsmount *mnt);
63894+__u32 gr_check_create(const struct dentry *new_dentry,
63895+ const struct dentry *parent,
63896+ const struct vfsmount *mnt, const __u32 mode);
63897+int gr_check_protected_task(const struct task_struct *task);
63898+__u32 to_gr_audit(const __u32 reqmode);
63899+int gr_set_acls(const int type);
63900+int gr_apply_subject_to_task(struct task_struct *task);
63901+int gr_acl_is_enabled(void);
63902+char gr_roletype_to_char(void);
63903+
63904+void gr_handle_alertkill(struct task_struct *task);
63905+char *gr_to_filename(const struct dentry *dentry,
63906+ const struct vfsmount *mnt);
63907+char *gr_to_filename1(const struct dentry *dentry,
63908+ const struct vfsmount *mnt);
63909+char *gr_to_filename2(const struct dentry *dentry,
63910+ const struct vfsmount *mnt);
63911+char *gr_to_filename3(const struct dentry *dentry,
63912+ const struct vfsmount *mnt);
63913+
63914+extern int grsec_enable_ptrace_readexec;
63915+extern int grsec_enable_harden_ptrace;
63916+extern int grsec_enable_link;
63917+extern int grsec_enable_fifo;
63918+extern int grsec_enable_execve;
63919+extern int grsec_enable_shm;
63920+extern int grsec_enable_execlog;
63921+extern int grsec_enable_signal;
63922+extern int grsec_enable_audit_ptrace;
63923+extern int grsec_enable_forkfail;
63924+extern int grsec_enable_time;
63925+extern int grsec_enable_rofs;
63926+extern int grsec_enable_chroot_shmat;
63927+extern int grsec_enable_chroot_mount;
63928+extern int grsec_enable_chroot_double;
63929+extern int grsec_enable_chroot_pivot;
63930+extern int grsec_enable_chroot_chdir;
63931+extern int grsec_enable_chroot_chmod;
63932+extern int grsec_enable_chroot_mknod;
63933+extern int grsec_enable_chroot_fchdir;
63934+extern int grsec_enable_chroot_nice;
63935+extern int grsec_enable_chroot_execlog;
63936+extern int grsec_enable_chroot_caps;
63937+extern int grsec_enable_chroot_sysctl;
63938+extern int grsec_enable_chroot_unix;
63939+extern int grsec_enable_symlinkown;
63940+extern int grsec_symlinkown_gid;
63941+extern int grsec_enable_tpe;
63942+extern int grsec_tpe_gid;
63943+extern int grsec_enable_tpe_all;
63944+extern int grsec_enable_tpe_invert;
63945+extern int grsec_enable_socket_all;
63946+extern int grsec_socket_all_gid;
63947+extern int grsec_enable_socket_client;
63948+extern int grsec_socket_client_gid;
63949+extern int grsec_enable_socket_server;
63950+extern int grsec_socket_server_gid;
63951+extern int grsec_audit_gid;
63952+extern int grsec_enable_group;
63953+extern int grsec_enable_audit_textrel;
63954+extern int grsec_enable_log_rwxmaps;
63955+extern int grsec_enable_mount;
63956+extern int grsec_enable_chdir;
63957+extern int grsec_resource_logging;
63958+extern int grsec_enable_blackhole;
63959+extern int grsec_lastack_retries;
63960+extern int grsec_enable_brute;
63961+extern int grsec_lock;
63962+
63963+extern spinlock_t grsec_alert_lock;
63964+extern unsigned long grsec_alert_wtime;
63965+extern unsigned long grsec_alert_fyet;
63966+
63967+extern spinlock_t grsec_audit_lock;
63968+
63969+extern rwlock_t grsec_exec_file_lock;
63970+
63971+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
63972+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
63973+ (tsk)->exec_file->f_vfsmnt) : "/")
63974+
63975+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
63976+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
63977+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63978+
63979+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
63980+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
63981+ (tsk)->exec_file->f_vfsmnt) : "/")
63982+
63983+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
63984+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
63985+ (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
63986+
63987+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
63988+
63989+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
63990+
63991+#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
63992+ (task)->pid, (cred)->uid, \
63993+ (cred)->euid, (cred)->gid, (cred)->egid, \
63994+ gr_parent_task_fullpath(task), \
63995+ (task)->real_parent->comm, (task)->real_parent->pid, \
63996+ (pcred)->uid, (pcred)->euid, \
63997+ (pcred)->gid, (pcred)->egid
63998+
63999+#define GR_CHROOT_CAPS {{ \
64000+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
64001+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
64002+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
64003+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
64004+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
64005+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
64006+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
64007+
64008+#define security_learn(normal_msg,args...) \
64009+({ \
64010+ read_lock(&grsec_exec_file_lock); \
64011+ gr_add_learn_entry(normal_msg "\n", ## args); \
64012+ read_unlock(&grsec_exec_file_lock); \
64013+})
64014+
64015+enum {
64016+ GR_DO_AUDIT,
64017+ GR_DONT_AUDIT,
64018+ /* used for non-audit messages that we shouldn't kill the task on */
64019+ GR_DONT_AUDIT_GOOD
64020+};
64021+
64022+enum {
64023+ GR_TTYSNIFF,
64024+ GR_RBAC,
64025+ GR_RBAC_STR,
64026+ GR_STR_RBAC,
64027+ GR_RBAC_MODE2,
64028+ GR_RBAC_MODE3,
64029+ GR_FILENAME,
64030+ GR_SYSCTL_HIDDEN,
64031+ GR_NOARGS,
64032+ GR_ONE_INT,
64033+ GR_ONE_INT_TWO_STR,
64034+ GR_ONE_STR,
64035+ GR_STR_INT,
64036+ GR_TWO_STR_INT,
64037+ GR_TWO_INT,
64038+ GR_TWO_U64,
64039+ GR_THREE_INT,
64040+ GR_FIVE_INT_TWO_STR,
64041+ GR_TWO_STR,
64042+ GR_THREE_STR,
64043+ GR_FOUR_STR,
64044+ GR_STR_FILENAME,
64045+ GR_FILENAME_STR,
64046+ GR_FILENAME_TWO_INT,
64047+ GR_FILENAME_TWO_INT_STR,
64048+ GR_TEXTREL,
64049+ GR_PTRACE,
64050+ GR_RESOURCE,
64051+ GR_CAP,
64052+ GR_SIG,
64053+ GR_SIG2,
64054+ GR_CRASH1,
64055+ GR_CRASH2,
64056+ GR_PSACCT,
64057+ GR_RWXMAP
64058+};
64059+
64060+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
64061+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
64062+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
64063+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
64064+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
64065+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
64066+#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)
64067+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
64068+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
64069+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
64070+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
64071+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
64072+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
64073+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
64074+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
64075+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
64076+#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)
64077+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
64078+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
64079+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
64080+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
64081+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
64082+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
64083+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
64084+#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)
64085+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
64086+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
64087+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
64088+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
64089+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
64090+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
64091+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
64092+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
64093+#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)
64094+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
64095+
64096+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
64097+
64098+#endif
64099+
64100+#endif
64101diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
64102new file mode 100644
64103index 0000000..2bd4c8d
64104--- /dev/null
64105+++ b/include/linux/grmsg.h
64106@@ -0,0 +1,111 @@
64107+#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"
64108+#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"
64109+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
64110+#define GR_STOPMOD_MSG "denied modification of module state by "
64111+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
64112+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
64113+#define GR_IOPERM_MSG "denied use of ioperm() by "
64114+#define GR_IOPL_MSG "denied use of iopl() by "
64115+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
64116+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
64117+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
64118+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
64119+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
64120+#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"
64121+#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"
64122+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
64123+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
64124+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
64125+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
64126+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
64127+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
64128+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
64129+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
64130+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
64131+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
64132+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
64133+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
64134+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
64135+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
64136+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
64137+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
64138+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
64139+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
64140+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
64141+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
64142+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
64143+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
64144+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
64145+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
64146+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
64147+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
64148+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
64149+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
64150+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
64151+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
64152+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
64153+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
64154+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
64155+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
64156+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
64157+#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"
64158+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
64159+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
64160+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
64161+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
64162+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
64163+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
64164+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
64165+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
64166+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
64167+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
64168+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
64169+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
64170+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
64171+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
64172+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
64173+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
64174+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
64175+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
64176+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
64177+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
64178+#define GR_FAILFORK_MSG "failed fork with errno %s by "
64179+#define GR_NICE_CHROOT_MSG "denied priority change by "
64180+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
64181+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
64182+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
64183+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
64184+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
64185+#define GR_TIME_MSG "time set by "
64186+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
64187+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
64188+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
64189+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
64190+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
64191+#define GR_BIND_MSG "denied bind() by "
64192+#define GR_CONNECT_MSG "denied connect() by "
64193+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
64194+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
64195+#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"
64196+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
64197+#define GR_CAP_ACL_MSG "use of %s denied for "
64198+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
64199+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
64200+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
64201+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
64202+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
64203+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
64204+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
64205+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
64206+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
64207+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
64208+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
64209+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
64210+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
64211+#define GR_VM86_MSG "denied use of vm86 by "
64212+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
64213+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
64214+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
64215+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
64216+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
64217+#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 "
64218diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
64219new file mode 100644
64220index 0000000..f2f5d5b
64221--- /dev/null
64222+++ b/include/linux/grsecurity.h
64223@@ -0,0 +1,239 @@
64224+#ifndef GR_SECURITY_H
64225+#define GR_SECURITY_H
64226+#include <linux/fs.h>
64227+#include <linux/fs_struct.h>
64228+#include <linux/binfmts.h>
64229+#include <linux/gracl.h>
64230+
64231+/* notify of brain-dead configs */
64232+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64233+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
64234+#endif
64235+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
64236+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
64237+#endif
64238+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
64239+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
64240+#endif
64241+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
64242+#error "CONFIG_PAX enabled, but no PaX options are enabled."
64243+#endif
64244+
64245+#include <linux/compat.h>
64246+
64247+struct user_arg_ptr {
64248+#ifdef CONFIG_COMPAT
64249+ bool is_compat;
64250+#endif
64251+ union {
64252+ const char __user *const __user *native;
64253+#ifdef CONFIG_COMPAT
64254+ const compat_uptr_t __user *compat;
64255+#endif
64256+ } ptr;
64257+};
64258+
64259+void gr_handle_brute_attach(unsigned long mm_flags);
64260+void gr_handle_brute_check(void);
64261+void gr_handle_kernel_exploit(void);
64262+int gr_process_user_ban(void);
64263+
64264+char gr_roletype_to_char(void);
64265+
64266+int gr_acl_enable_at_secure(void);
64267+
64268+int gr_check_user_change(int real, int effective, int fs);
64269+int gr_check_group_change(int real, int effective, int fs);
64270+
64271+void gr_del_task_from_ip_table(struct task_struct *p);
64272+
64273+int gr_pid_is_chrooted(struct task_struct *p);
64274+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
64275+int gr_handle_chroot_nice(void);
64276+int gr_handle_chroot_sysctl(const int op);
64277+int gr_handle_chroot_setpriority(struct task_struct *p,
64278+ const int niceval);
64279+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
64280+int gr_handle_chroot_chroot(const struct dentry *dentry,
64281+ const struct vfsmount *mnt);
64282+void gr_handle_chroot_chdir(struct path *path);
64283+int gr_handle_chroot_chmod(const struct dentry *dentry,
64284+ const struct vfsmount *mnt, const int mode);
64285+int gr_handle_chroot_mknod(const struct dentry *dentry,
64286+ const struct vfsmount *mnt, const int mode);
64287+int gr_handle_chroot_mount(const struct dentry *dentry,
64288+ const struct vfsmount *mnt,
64289+ const char *dev_name);
64290+int gr_handle_chroot_pivot(void);
64291+int gr_handle_chroot_unix(const pid_t pid);
64292+
64293+int gr_handle_rawio(const struct inode *inode);
64294+
64295+void gr_handle_ioperm(void);
64296+void gr_handle_iopl(void);
64297+
64298+umode_t gr_acl_umask(void);
64299+
64300+int gr_tpe_allow(const struct file *file);
64301+
64302+void gr_set_chroot_entries(struct task_struct *task, struct path *path);
64303+void gr_clear_chroot_entries(struct task_struct *task);
64304+
64305+void gr_log_forkfail(const int retval);
64306+void gr_log_timechange(void);
64307+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
64308+void gr_log_chdir(const struct dentry *dentry,
64309+ const struct vfsmount *mnt);
64310+void gr_log_chroot_exec(const struct dentry *dentry,
64311+ const struct vfsmount *mnt);
64312+void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
64313+void gr_log_remount(const char *devname, const int retval);
64314+void gr_log_unmount(const char *devname, const int retval);
64315+void gr_log_mount(const char *from, const char *to, const int retval);
64316+void gr_log_textrel(struct vm_area_struct *vma);
64317+void gr_log_rwxmmap(struct file *file);
64318+void gr_log_rwxmprotect(struct file *file);
64319+
64320+int gr_handle_follow_link(const struct inode *parent,
64321+ const struct inode *inode,
64322+ const struct dentry *dentry,
64323+ const struct vfsmount *mnt);
64324+int gr_handle_fifo(const struct dentry *dentry,
64325+ const struct vfsmount *mnt,
64326+ const struct dentry *dir, const int flag,
64327+ const int acc_mode);
64328+int gr_handle_hardlink(const struct dentry *dentry,
64329+ const struct vfsmount *mnt,
64330+ struct inode *inode,
64331+ const int mode, const struct filename *to);
64332+
64333+int gr_is_capable(const int cap);
64334+int gr_is_capable_nolog(const int cap);
64335+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64336+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
64337+
64338+void gr_learn_resource(const struct task_struct *task, const int limit,
64339+ const unsigned long wanted, const int gt);
64340+void gr_copy_label(struct task_struct *tsk);
64341+void gr_handle_crash(struct task_struct *task, const int sig);
64342+int gr_handle_signal(const struct task_struct *p, const int sig);
64343+int gr_check_crash_uid(const uid_t uid);
64344+int gr_check_protected_task(const struct task_struct *task);
64345+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
64346+int gr_acl_handle_mmap(const struct file *file,
64347+ const unsigned long prot);
64348+int gr_acl_handle_mprotect(const struct file *file,
64349+ const unsigned long prot);
64350+int gr_check_hidden_task(const struct task_struct *tsk);
64351+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
64352+ const struct vfsmount *mnt);
64353+__u32 gr_acl_handle_utime(const struct dentry *dentry,
64354+ const struct vfsmount *mnt);
64355+__u32 gr_acl_handle_access(const struct dentry *dentry,
64356+ const struct vfsmount *mnt, const int fmode);
64357+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
64358+ const struct vfsmount *mnt, umode_t *mode);
64359+__u32 gr_acl_handle_chown(const struct dentry *dentry,
64360+ const struct vfsmount *mnt);
64361+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
64362+ const struct vfsmount *mnt);
64363+int gr_handle_ptrace(struct task_struct *task, const long request);
64364+int gr_handle_proc_ptrace(struct task_struct *task);
64365+__u32 gr_acl_handle_execve(const struct dentry *dentry,
64366+ const struct vfsmount *mnt);
64367+int gr_check_crash_exec(const struct file *filp);
64368+int gr_acl_is_enabled(void);
64369+void gr_set_kernel_label(struct task_struct *task);
64370+void gr_set_role_label(struct task_struct *task, const uid_t uid,
64371+ const gid_t gid);
64372+int gr_set_proc_label(const struct dentry *dentry,
64373+ const struct vfsmount *mnt,
64374+ const int unsafe_flags);
64375+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
64376+ const struct vfsmount *mnt);
64377+__u32 gr_acl_handle_open(const struct dentry *dentry,
64378+ const struct vfsmount *mnt, int acc_mode);
64379+__u32 gr_acl_handle_creat(const struct dentry *dentry,
64380+ const struct dentry *p_dentry,
64381+ const struct vfsmount *p_mnt,
64382+ int open_flags, int acc_mode, const int imode);
64383+void gr_handle_create(const struct dentry *dentry,
64384+ const struct vfsmount *mnt);
64385+void gr_handle_proc_create(const struct dentry *dentry,
64386+ const struct inode *inode);
64387+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
64388+ const struct dentry *parent_dentry,
64389+ const struct vfsmount *parent_mnt,
64390+ const int mode);
64391+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
64392+ const struct dentry *parent_dentry,
64393+ const struct vfsmount *parent_mnt);
64394+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
64395+ const struct vfsmount *mnt);
64396+void gr_handle_delete(const ino_t ino, const dev_t dev);
64397+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
64398+ const struct vfsmount *mnt);
64399+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
64400+ const struct dentry *parent_dentry,
64401+ const struct vfsmount *parent_mnt,
64402+ const struct filename *from);
64403+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
64404+ const struct dentry *parent_dentry,
64405+ const struct vfsmount *parent_mnt,
64406+ const struct dentry *old_dentry,
64407+ const struct vfsmount *old_mnt, const struct filename *to);
64408+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
64409+int gr_acl_handle_rename(struct dentry *new_dentry,
64410+ struct dentry *parent_dentry,
64411+ const struct vfsmount *parent_mnt,
64412+ struct dentry *old_dentry,
64413+ struct inode *old_parent_inode,
64414+ struct vfsmount *old_mnt, const struct filename *newname);
64415+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64416+ struct dentry *old_dentry,
64417+ struct dentry *new_dentry,
64418+ struct vfsmount *mnt, const __u8 replace);
64419+__u32 gr_check_link(const struct dentry *new_dentry,
64420+ const struct dentry *parent_dentry,
64421+ const struct vfsmount *parent_mnt,
64422+ const struct dentry *old_dentry,
64423+ const struct vfsmount *old_mnt);
64424+int gr_acl_handle_filldir(const struct file *file, const char *name,
64425+ const unsigned int namelen, const ino_t ino);
64426+
64427+__u32 gr_acl_handle_unix(const struct dentry *dentry,
64428+ const struct vfsmount *mnt);
64429+void gr_acl_handle_exit(void);
64430+void gr_acl_handle_psacct(struct task_struct *task, const long code);
64431+int gr_acl_handle_procpidmem(const struct task_struct *task);
64432+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
64433+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
64434+void gr_audit_ptrace(struct task_struct *task);
64435+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
64436+void gr_put_exec_file(struct task_struct *task);
64437+
64438+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
64439+
64440+#ifdef CONFIG_GRKERNSEC
64441+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
64442+void gr_handle_vm86(void);
64443+void gr_handle_mem_readwrite(u64 from, u64 to);
64444+
64445+void gr_log_badprocpid(const char *entry);
64446+
64447+extern int grsec_enable_dmesg;
64448+extern int grsec_disable_privio;
64449+
64450+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64451+extern int grsec_proc_gid;
64452+#endif
64453+
64454+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64455+extern int grsec_enable_chroot_findtask;
64456+#endif
64457+#ifdef CONFIG_GRKERNSEC_SETXID
64458+extern int grsec_enable_setxid;
64459+#endif
64460+#endif
64461+
64462+#endif
64463diff --git a/include/linux/grsock.h b/include/linux/grsock.h
64464new file mode 100644
64465index 0000000..e7ffaaf
64466--- /dev/null
64467+++ b/include/linux/grsock.h
64468@@ -0,0 +1,19 @@
64469+#ifndef __GRSOCK_H
64470+#define __GRSOCK_H
64471+
64472+extern void gr_attach_curr_ip(const struct sock *sk);
64473+extern int gr_handle_sock_all(const int family, const int type,
64474+ const int protocol);
64475+extern int gr_handle_sock_server(const struct sockaddr *sck);
64476+extern int gr_handle_sock_server_other(const struct sock *sck);
64477+extern int gr_handle_sock_client(const struct sockaddr *sck);
64478+extern int gr_search_connect(struct socket * sock,
64479+ struct sockaddr_in * addr);
64480+extern int gr_search_bind(struct socket * sock,
64481+ struct sockaddr_in * addr);
64482+extern int gr_search_listen(struct socket * sock);
64483+extern int gr_search_accept(struct socket * sock);
64484+extern int gr_search_socket(const int domain, const int type,
64485+ const int protocol);
64486+
64487+#endif
64488diff --git a/include/linux/highmem.h b/include/linux/highmem.h
64489index ef788b5..ac41b7b 100644
64490--- a/include/linux/highmem.h
64491+++ b/include/linux/highmem.h
64492@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
64493 kunmap_atomic(kaddr);
64494 }
64495
64496+static inline void sanitize_highpage(struct page *page)
64497+{
64498+ void *kaddr;
64499+ unsigned long flags;
64500+
64501+ local_irq_save(flags);
64502+ kaddr = kmap_atomic(page);
64503+ clear_page(kaddr);
64504+ kunmap_atomic(kaddr);
64505+ local_irq_restore(flags);
64506+}
64507+
64508 static inline void zero_user_segments(struct page *page,
64509 unsigned start1, unsigned end1,
64510 unsigned start2, unsigned end2)
64511diff --git a/include/linux/i2c.h b/include/linux/i2c.h
64512index 800de22..7a2fa46 100644
64513--- a/include/linux/i2c.h
64514+++ b/include/linux/i2c.h
64515@@ -367,6 +367,7 @@ struct i2c_algorithm {
64516 /* To determine what the adapter supports */
64517 u32 (*functionality) (struct i2c_adapter *);
64518 };
64519+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
64520
64521 /*
64522 * i2c_adapter is the structure used to identify a physical i2c bus along
64523diff --git a/include/linux/i2o.h b/include/linux/i2o.h
64524index d23c3c2..eb63c81 100644
64525--- a/include/linux/i2o.h
64526+++ b/include/linux/i2o.h
64527@@ -565,7 +565,7 @@ struct i2o_controller {
64528 struct i2o_device *exec; /* Executive */
64529 #if BITS_PER_LONG == 64
64530 spinlock_t context_list_lock; /* lock for context_list */
64531- atomic_t context_list_counter; /* needed for unique contexts */
64532+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
64533 struct list_head context_list; /* list of context id's
64534 and pointers */
64535 #endif
64536diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
64537index aff7ad8..3942bbd 100644
64538--- a/include/linux/if_pppox.h
64539+++ b/include/linux/if_pppox.h
64540@@ -76,7 +76,7 @@ struct pppox_proto {
64541 int (*ioctl)(struct socket *sock, unsigned int cmd,
64542 unsigned long arg);
64543 struct module *owner;
64544-};
64545+} __do_const;
64546
64547 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
64548 extern void unregister_pppox_proto(int proto_num);
64549diff --git a/include/linux/init.h b/include/linux/init.h
64550index e59041e..df0a975 100644
64551--- a/include/linux/init.h
64552+++ b/include/linux/init.h
64553@@ -39,9 +39,36 @@
64554 * Also note, that this data cannot be "const".
64555 */
64556
64557+#ifdef MODULE
64558+#define add_init_latent_entropy
64559+#define add_devinit_latent_entropy
64560+#define add_cpuinit_latent_entropy
64561+#define add_meminit_latent_entropy
64562+#else
64563+#define add_init_latent_entropy __latent_entropy
64564+
64565+#ifdef CONFIG_HOTPLUG
64566+#define add_devinit_latent_entropy
64567+#else
64568+#define add_devinit_latent_entropy __latent_entropy
64569+#endif
64570+
64571+#ifdef CONFIG_HOTPLUG_CPU
64572+#define add_cpuinit_latent_entropy
64573+#else
64574+#define add_cpuinit_latent_entropy __latent_entropy
64575+#endif
64576+
64577+#ifdef CONFIG_MEMORY_HOTPLUG
64578+#define add_meminit_latent_entropy
64579+#else
64580+#define add_meminit_latent_entropy __latent_entropy
64581+#endif
64582+#endif
64583+
64584 /* These are for everybody (although not all archs will actually
64585 discard it in modules) */
64586-#define __init __section(.init.text) __cold notrace
64587+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
64588 #define __initdata __section(.init.data)
64589 #define __initconst __constsection(.init.rodata)
64590 #define __exitdata __section(.exit.data)
64591@@ -94,7 +121,7 @@
64592 #define __exit __section(.exit.text) __exitused __cold notrace
64593
64594 /* Used for HOTPLUG */
64595-#define __devinit __section(.devinit.text) __cold notrace
64596+#define __devinit __section(.devinit.text) __cold notrace add_devinit_latent_entropy
64597 #define __devinitdata __section(.devinit.data)
64598 #define __devinitconst __constsection(.devinit.rodata)
64599 #define __devexit __section(.devexit.text) __exitused __cold notrace
64600@@ -102,7 +129,7 @@
64601 #define __devexitconst __constsection(.devexit.rodata)
64602
64603 /* Used for HOTPLUG_CPU */
64604-#define __cpuinit __section(.cpuinit.text) __cold notrace
64605+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
64606 #define __cpuinitdata __section(.cpuinit.data)
64607 #define __cpuinitconst __constsection(.cpuinit.rodata)
64608 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
64609@@ -110,7 +137,7 @@
64610 #define __cpuexitconst __constsection(.cpuexit.rodata)
64611
64612 /* Used for MEMORY_HOTPLUG */
64613-#define __meminit __section(.meminit.text) __cold notrace
64614+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
64615 #define __meminitdata __section(.meminit.data)
64616 #define __meminitconst __constsection(.meminit.rodata)
64617 #define __memexit __section(.memexit.text) __exitused __cold notrace
64618diff --git a/include/linux/init_task.h b/include/linux/init_task.h
64619index 6d087c5..401cab8 100644
64620--- a/include/linux/init_task.h
64621+++ b/include/linux/init_task.h
64622@@ -143,6 +143,12 @@ extern struct task_group root_task_group;
64623
64624 #define INIT_TASK_COMM "swapper"
64625
64626+#ifdef CONFIG_X86
64627+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
64628+#else
64629+#define INIT_TASK_THREAD_INFO
64630+#endif
64631+
64632 /*
64633 * INIT_TASK is used to set up the first task table, touch at
64634 * your own risk!. Base=0, limit=0x1fffff (=2MB)
64635@@ -182,6 +188,7 @@ extern struct task_group root_task_group;
64636 RCU_POINTER_INITIALIZER(cred, &init_cred), \
64637 .comm = INIT_TASK_COMM, \
64638 .thread = INIT_THREAD, \
64639+ INIT_TASK_THREAD_INFO \
64640 .fs = &init_fs, \
64641 .files = &init_files, \
64642 .signal = &init_signals, \
64643diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
64644index 5e4e617..eee383d 100644
64645--- a/include/linux/interrupt.h
64646+++ b/include/linux/interrupt.h
64647@@ -435,7 +435,7 @@ enum
64648 /* map softirq index to softirq name. update 'softirq_to_name' in
64649 * kernel/softirq.c when adding a new softirq.
64650 */
64651-extern char *softirq_to_name[NR_SOFTIRQS];
64652+extern const char * const softirq_to_name[NR_SOFTIRQS];
64653
64654 /* softirq mask and active fields moved to irq_cpustat_t in
64655 * asm/hardirq.h to get better cache usage. KAO
64656@@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
64657
64658 struct softirq_action
64659 {
64660- void (*action)(struct softirq_action *);
64661+ void (*action)(void);
64662 };
64663
64664 asmlinkage void do_softirq(void);
64665 asmlinkage void __do_softirq(void);
64666-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
64667+extern void open_softirq(int nr, void (*action)(void));
64668 extern void softirq_init(void);
64669 extern void __raise_softirq_irqoff(unsigned int nr);
64670
64671diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
64672index 6883e19..06992b1 100644
64673--- a/include/linux/kallsyms.h
64674+++ b/include/linux/kallsyms.h
64675@@ -15,7 +15,8 @@
64676
64677 struct module;
64678
64679-#ifdef CONFIG_KALLSYMS
64680+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
64681+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
64682 /* Lookup the address for a symbol. Returns 0 if not found. */
64683 unsigned long kallsyms_lookup_name(const char *name);
64684
64685@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
64686 /* Stupid that this does nothing, but I didn't create this mess. */
64687 #define __print_symbol(fmt, addr)
64688 #endif /*CONFIG_KALLSYMS*/
64689+#else /* when included by kallsyms.c, vsnprintf.c, or
64690+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
64691+extern void __print_symbol(const char *fmt, unsigned long address);
64692+extern int sprint_backtrace(char *buffer, unsigned long address);
64693+extern int sprint_symbol(char *buffer, unsigned long address);
64694+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
64695+const char *kallsyms_lookup(unsigned long addr,
64696+ unsigned long *symbolsize,
64697+ unsigned long *offset,
64698+ char **modname, char *namebuf);
64699+#endif
64700
64701 /* This macro allows us to keep printk typechecking */
64702 static __printf(1, 2)
64703diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
64704index 4dff0c6..1ca9b72 100644
64705--- a/include/linux/kgdb.h
64706+++ b/include/linux/kgdb.h
64707@@ -53,7 +53,7 @@ extern int kgdb_connected;
64708 extern int kgdb_io_module_registered;
64709
64710 extern atomic_t kgdb_setting_breakpoint;
64711-extern atomic_t kgdb_cpu_doing_single_step;
64712+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
64713
64714 extern struct task_struct *kgdb_usethread;
64715 extern struct task_struct *kgdb_contthread;
64716@@ -255,7 +255,7 @@ struct kgdb_arch {
64717 void (*correct_hw_break)(void);
64718
64719 void (*enable_nmi)(bool on);
64720-};
64721+} __do_const;
64722
64723 /**
64724 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
64725@@ -280,7 +280,7 @@ struct kgdb_io {
64726 void (*pre_exception) (void);
64727 void (*post_exception) (void);
64728 int is_console;
64729-};
64730+} __do_const;
64731
64732 extern struct kgdb_arch arch_kgdb_ops;
64733
64734diff --git a/include/linux/kmod.h b/include/linux/kmod.h
64735index 5398d58..5883a34 100644
64736--- a/include/linux/kmod.h
64737+++ b/include/linux/kmod.h
64738@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
64739 * usually useless though. */
64740 extern __printf(2, 3)
64741 int __request_module(bool wait, const char *name, ...);
64742+extern __printf(3, 4)
64743+int ___request_module(bool wait, char *param_name, const char *name, ...);
64744 #define request_module(mod...) __request_module(true, mod)
64745 #define request_module_nowait(mod...) __request_module(false, mod)
64746 #define try_then_request_module(x, mod...) \
64747diff --git a/include/linux/kobject.h b/include/linux/kobject.h
64748index 1e57449..4fede7b 100644
64749--- a/include/linux/kobject.h
64750+++ b/include/linux/kobject.h
64751@@ -111,7 +111,7 @@ struct kobj_type {
64752 struct attribute **default_attrs;
64753 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
64754 const void *(*namespace)(struct kobject *kobj);
64755-};
64756+} __do_const;
64757
64758 struct kobj_uevent_env {
64759 char *envp[UEVENT_NUM_ENVP];
64760diff --git a/include/linux/kref.h b/include/linux/kref.h
64761index 65af688..0592677 100644
64762--- a/include/linux/kref.h
64763+++ b/include/linux/kref.h
64764@@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
64765 static inline int kref_sub(struct kref *kref, unsigned int count,
64766 void (*release)(struct kref *kref))
64767 {
64768- WARN_ON(release == NULL);
64769+ BUG_ON(release == NULL);
64770
64771 if (atomic_sub_and_test((int) count, &kref->refcount)) {
64772 release(kref);
64773diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
64774index ecc5543..0e96bcc 100644
64775--- a/include/linux/kvm_host.h
64776+++ b/include/linux/kvm_host.h
64777@@ -403,7 +403,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
64778 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
64779 void vcpu_put(struct kvm_vcpu *vcpu);
64780
64781-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64782+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
64783 struct module *module);
64784 void kvm_exit(void);
64785
64786@@ -558,7 +558,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
64787 struct kvm_guest_debug *dbg);
64788 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
64789
64790-int kvm_arch_init(void *opaque);
64791+int kvm_arch_init(const void *opaque);
64792 void kvm_arch_exit(void);
64793
64794 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
64795diff --git a/include/linux/libata.h b/include/linux/libata.h
64796index 1e36c63..0c5046e 100644
64797--- a/include/linux/libata.h
64798+++ b/include/linux/libata.h
64799@@ -915,7 +915,7 @@ struct ata_port_operations {
64800 * fields must be pointers.
64801 */
64802 const struct ata_port_operations *inherits;
64803-};
64804+} __do_const;
64805
64806 struct ata_port_info {
64807 unsigned long flags;
64808diff --git a/include/linux/list.h b/include/linux/list.h
64809index cc6d2aa..71febca 100644
64810--- a/include/linux/list.h
64811+++ b/include/linux/list.h
64812@@ -112,6 +112,9 @@ extern void __list_del_entry(struct list_head *entry);
64813 extern void list_del(struct list_head *entry);
64814 #endif
64815
64816+extern void pax_list_add_tail(struct list_head *new, struct list_head *head);
64817+extern void pax_list_del(struct list_head *entry);
64818+
64819 /**
64820 * list_replace - replace old entry by new one
64821 * @old : the element to be replaced
64822diff --git a/include/linux/mm.h b/include/linux/mm.h
64823index 280dae5..39046ec 100644
64824--- a/include/linux/mm.h
64825+++ b/include/linux/mm.h
64826@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
64827 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
64828 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
64829 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
64830+
64831+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
64832+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
64833+#endif
64834+
64835 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
64836
64837 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
64838@@ -1039,34 +1044,6 @@ int set_page_dirty(struct page *page);
64839 int set_page_dirty_lock(struct page *page);
64840 int clear_page_dirty_for_io(struct page *page);
64841
64842-/* Is the vma a continuation of the stack vma above it? */
64843-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
64844-{
64845- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
64846-}
64847-
64848-static inline int stack_guard_page_start(struct vm_area_struct *vma,
64849- unsigned long addr)
64850-{
64851- return (vma->vm_flags & VM_GROWSDOWN) &&
64852- (vma->vm_start == addr) &&
64853- !vma_growsdown(vma->vm_prev, addr);
64854-}
64855-
64856-/* Is the vma a continuation of the stack vma below it? */
64857-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
64858-{
64859- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
64860-}
64861-
64862-static inline int stack_guard_page_end(struct vm_area_struct *vma,
64863- unsigned long addr)
64864-{
64865- return (vma->vm_flags & VM_GROWSUP) &&
64866- (vma->vm_end == addr) &&
64867- !vma_growsup(vma->vm_next, addr);
64868-}
64869-
64870 extern pid_t
64871 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
64872
64873@@ -1166,6 +1143,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
64874 }
64875 #endif
64876
64877+#ifdef CONFIG_MMU
64878+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
64879+#else
64880+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
64881+{
64882+ return __pgprot(0);
64883+}
64884+#endif
64885+
64886 int vma_wants_writenotify(struct vm_area_struct *vma);
64887
64888 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
64889@@ -1184,8 +1170,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
64890 {
64891 return 0;
64892 }
64893+
64894+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
64895+ unsigned long address)
64896+{
64897+ return 0;
64898+}
64899 #else
64900 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64901+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
64902 #endif
64903
64904 #ifdef __PAGETABLE_PMD_FOLDED
64905@@ -1194,8 +1187,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
64906 {
64907 return 0;
64908 }
64909+
64910+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
64911+ unsigned long address)
64912+{
64913+ return 0;
64914+}
64915 #else
64916 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
64917+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
64918 #endif
64919
64920 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
64921@@ -1213,11 +1213,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
64922 NULL: pud_offset(pgd, address);
64923 }
64924
64925+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
64926+{
64927+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
64928+ NULL: pud_offset(pgd, address);
64929+}
64930+
64931 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
64932 {
64933 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
64934 NULL: pmd_offset(pud, address);
64935 }
64936+
64937+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
64938+{
64939+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
64940+ NULL: pmd_offset(pud, address);
64941+}
64942 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
64943
64944 #if USE_SPLIT_PTLOCKS
64945@@ -1447,6 +1459,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
64946 unsigned long, unsigned long,
64947 unsigned long, unsigned long);
64948 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
64949+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
64950
64951 /* These take the mm semaphore themselves */
64952 extern unsigned long vm_brk(unsigned long, unsigned long);
64953@@ -1510,6 +1523,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
64954 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
64955 struct vm_area_struct **pprev);
64956
64957+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
64958+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
64959+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
64960+
64961 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
64962 NULL if none. Assume start_addr < end_addr. */
64963 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
64964@@ -1538,15 +1555,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
64965 return vma;
64966 }
64967
64968-#ifdef CONFIG_MMU
64969-pgprot_t vm_get_page_prot(unsigned long vm_flags);
64970-#else
64971-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
64972-{
64973- return __pgprot(0);
64974-}
64975-#endif
64976-
64977 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
64978 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
64979 unsigned long pfn, unsigned long size, pgprot_t);
64980@@ -1652,7 +1660,7 @@ extern int unpoison_memory(unsigned long pfn);
64981 extern int sysctl_memory_failure_early_kill;
64982 extern int sysctl_memory_failure_recovery;
64983 extern void shake_page(struct page *p, int access);
64984-extern atomic_long_t mce_bad_pages;
64985+extern atomic_long_unchecked_t mce_bad_pages;
64986 extern int soft_offline_page(struct page *page, int flags);
64987
64988 extern void dump_page(struct page *page);
64989@@ -1683,5 +1691,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
64990 static inline bool page_is_guard(struct page *page) { return false; }
64991 #endif /* CONFIG_DEBUG_PAGEALLOC */
64992
64993+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64994+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
64995+#else
64996+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
64997+#endif
64998+
64999 #endif /* __KERNEL__ */
65000 #endif /* _LINUX_MM_H */
65001diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
65002index 31f8a3a..499f1db 100644
65003--- a/include/linux/mm_types.h
65004+++ b/include/linux/mm_types.h
65005@@ -275,6 +275,8 @@ struct vm_area_struct {
65006 #ifdef CONFIG_NUMA
65007 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
65008 #endif
65009+
65010+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
65011 };
65012
65013 struct core_thread {
65014@@ -348,7 +350,7 @@ struct mm_struct {
65015 unsigned long def_flags;
65016 unsigned long nr_ptes; /* Page table pages */
65017 unsigned long start_code, end_code, start_data, end_data;
65018- unsigned long start_brk, brk, start_stack;
65019+ unsigned long brk_gap, start_brk, brk, start_stack;
65020 unsigned long arg_start, arg_end, env_start, env_end;
65021
65022 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
65023@@ -399,6 +401,24 @@ struct mm_struct {
65024 struct cpumask cpumask_allocation;
65025 #endif
65026 struct uprobes_state uprobes_state;
65027+
65028+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65029+ unsigned long pax_flags;
65030+#endif
65031+
65032+#ifdef CONFIG_PAX_DLRESOLVE
65033+ unsigned long call_dl_resolve;
65034+#endif
65035+
65036+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
65037+ unsigned long call_syscall;
65038+#endif
65039+
65040+#ifdef CONFIG_PAX_ASLR
65041+ unsigned long delta_mmap; /* randomized offset */
65042+ unsigned long delta_stack; /* randomized offset */
65043+#endif
65044+
65045 };
65046
65047 static inline void mm_init_cpumask(struct mm_struct *mm)
65048diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
65049index c5d5278..f0b68c8 100644
65050--- a/include/linux/mmiotrace.h
65051+++ b/include/linux/mmiotrace.h
65052@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
65053 /* Called from ioremap.c */
65054 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
65055 void __iomem *addr);
65056-extern void mmiotrace_iounmap(volatile void __iomem *addr);
65057+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
65058
65059 /* For anyone to insert markers. Remember trailing newline. */
65060 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
65061@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
65062 {
65063 }
65064
65065-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
65066+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
65067 {
65068 }
65069
65070diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
65071index a23923b..073fee4 100644
65072--- a/include/linux/mmzone.h
65073+++ b/include/linux/mmzone.h
65074@@ -421,7 +421,7 @@ struct zone {
65075 unsigned long flags; /* zone flags, see below */
65076
65077 /* Zone statistics */
65078- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65079+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65080
65081 /*
65082 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
65083diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
65084index fed3def..7cc3f93 100644
65085--- a/include/linux/mod_devicetable.h
65086+++ b/include/linux/mod_devicetable.h
65087@@ -12,7 +12,7 @@
65088 typedef unsigned long kernel_ulong_t;
65089 #endif
65090
65091-#define PCI_ANY_ID (~0)
65092+#define PCI_ANY_ID ((__u16)~0)
65093
65094 struct pci_device_id {
65095 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
65096@@ -139,7 +139,7 @@ struct usb_device_id {
65097 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
65098 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
65099
65100-#define HID_ANY_ID (~0)
65101+#define HID_ANY_ID (~0U)
65102 #define HID_BUS_ANY 0xffff
65103 #define HID_GROUP_ANY 0x0000
65104
65105diff --git a/include/linux/module.h b/include/linux/module.h
65106index 1375ee3..d631af0 100644
65107--- a/include/linux/module.h
65108+++ b/include/linux/module.h
65109@@ -17,9 +17,11 @@
65110 #include <linux/moduleparam.h>
65111 #include <linux/tracepoint.h>
65112 #include <linux/export.h>
65113+#include <linux/fs.h>
65114
65115 #include <linux/percpu.h>
65116 #include <asm/module.h>
65117+#include <asm/pgtable.h>
65118
65119 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
65120 #define MODULE_SIG_STRING "~Module signature appended~\n"
65121@@ -281,19 +283,16 @@ struct module
65122 int (*init)(void);
65123
65124 /* If this is non-NULL, vfree after init() returns */
65125- void *module_init;
65126+ void *module_init_rx, *module_init_rw;
65127
65128 /* Here is the actual code + data, vfree'd on unload. */
65129- void *module_core;
65130+ void *module_core_rx, *module_core_rw;
65131
65132 /* Here are the sizes of the init and core sections */
65133- unsigned int init_size, core_size;
65134+ unsigned int init_size_rw, core_size_rw;
65135
65136 /* The size of the executable code in each section. */
65137- unsigned int init_text_size, core_text_size;
65138-
65139- /* Size of RO sections of the module (text+rodata) */
65140- unsigned int init_ro_size, core_ro_size;
65141+ unsigned int init_size_rx, core_size_rx;
65142
65143 /* Arch-specific module values */
65144 struct mod_arch_specific arch;
65145@@ -349,6 +348,10 @@ struct module
65146 #ifdef CONFIG_EVENT_TRACING
65147 struct ftrace_event_call **trace_events;
65148 unsigned int num_trace_events;
65149+ struct file_operations trace_id;
65150+ struct file_operations trace_enable;
65151+ struct file_operations trace_format;
65152+ struct file_operations trace_filter;
65153 #endif
65154 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
65155 unsigned int num_ftrace_callsites;
65156@@ -396,16 +399,46 @@ bool is_module_address(unsigned long addr);
65157 bool is_module_percpu_address(unsigned long addr);
65158 bool is_module_text_address(unsigned long addr);
65159
65160+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
65161+{
65162+
65163+#ifdef CONFIG_PAX_KERNEXEC
65164+ if (ktla_ktva(addr) >= (unsigned long)start &&
65165+ ktla_ktva(addr) < (unsigned long)start + size)
65166+ return 1;
65167+#endif
65168+
65169+ return ((void *)addr >= start && (void *)addr < start + size);
65170+}
65171+
65172+static inline int within_module_core_rx(unsigned long addr, struct module *mod)
65173+{
65174+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
65175+}
65176+
65177+static inline int within_module_core_rw(unsigned long addr, struct module *mod)
65178+{
65179+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
65180+}
65181+
65182+static inline int within_module_init_rx(unsigned long addr, struct module *mod)
65183+{
65184+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
65185+}
65186+
65187+static inline int within_module_init_rw(unsigned long addr, struct module *mod)
65188+{
65189+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
65190+}
65191+
65192 static inline int within_module_core(unsigned long addr, struct module *mod)
65193 {
65194- return (unsigned long)mod->module_core <= addr &&
65195- addr < (unsigned long)mod->module_core + mod->core_size;
65196+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
65197 }
65198
65199 static inline int within_module_init(unsigned long addr, struct module *mod)
65200 {
65201- return (unsigned long)mod->module_init <= addr &&
65202- addr < (unsigned long)mod->module_init + mod->init_size;
65203+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
65204 }
65205
65206 /* Search for module by name: must hold module_mutex. */
65207diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
65208index 560ca53..5ee8d73 100644
65209--- a/include/linux/moduleloader.h
65210+++ b/include/linux/moduleloader.h
65211@@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
65212
65213 /* Allocator used for allocating struct module, core sections and init
65214 sections. Returns NULL on failure. */
65215-void *module_alloc(unsigned long size);
65216+void *module_alloc(unsigned long size) __size_overflow(1);
65217+
65218+#ifdef CONFIG_PAX_KERNEXEC
65219+void *module_alloc_exec(unsigned long size) __size_overflow(1);
65220+#else
65221+#define module_alloc_exec(x) module_alloc(x)
65222+#endif
65223
65224 /* Free memory returned from module_alloc. */
65225 void module_free(struct module *mod, void *module_region);
65226
65227+#ifdef CONFIG_PAX_KERNEXEC
65228+void module_free_exec(struct module *mod, void *module_region);
65229+#else
65230+#define module_free_exec(x, y) module_free((x), (y))
65231+#endif
65232+
65233 /*
65234 * Apply the given relocation to the (simplified) ELF. Return -error
65235 * or 0.
65236@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
65237 unsigned int relsec,
65238 struct module *me)
65239 {
65240+#ifdef CONFIG_MODULES
65241 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65242+#endif
65243 return -ENOEXEC;
65244 }
65245 #endif
65246@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
65247 unsigned int relsec,
65248 struct module *me)
65249 {
65250+#ifdef CONFIG_MODULES
65251 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
65252+#endif
65253 return -ENOEXEC;
65254 }
65255 #endif
65256diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
65257index d6a5806..7c13347 100644
65258--- a/include/linux/moduleparam.h
65259+++ b/include/linux/moduleparam.h
65260@@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
65261 * @len is usually just sizeof(string).
65262 */
65263 #define module_param_string(name, string, len, perm) \
65264- static const struct kparam_string __param_string_##name \
65265+ static const struct kparam_string __param_string_##name __used \
65266 = { len, string }; \
65267 __module_param_call(MODULE_PARAM_PREFIX, name, \
65268 &param_ops_string, \
65269@@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
65270 */
65271 #define module_param_array_named(name, array, type, nump, perm) \
65272 param_check_##type(name, &(array)[0]); \
65273- static const struct kparam_array __param_arr_##name \
65274+ static const struct kparam_array __param_arr_##name __used \
65275 = { .max = ARRAY_SIZE(array), .num = nump, \
65276 .ops = &param_ops_##type, \
65277 .elemsize = sizeof(array[0]), .elem = array }; \
65278diff --git a/include/linux/namei.h b/include/linux/namei.h
65279index 4bf19d8..5268cea 100644
65280--- a/include/linux/namei.h
65281+++ b/include/linux/namei.h
65282@@ -18,7 +18,7 @@ struct nameidata {
65283 unsigned seq;
65284 int last_type;
65285 unsigned depth;
65286- char *saved_names[MAX_NESTED_LINKS + 1];
65287+ const char *saved_names[MAX_NESTED_LINKS + 1];
65288 };
65289
65290 /*
65291@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
65292
65293 extern void nd_jump_link(struct nameidata *nd, struct path *path);
65294
65295-static inline void nd_set_link(struct nameidata *nd, char *path)
65296+static inline void nd_set_link(struct nameidata *nd, const char *path)
65297 {
65298 nd->saved_names[nd->depth] = path;
65299 }
65300
65301-static inline char *nd_get_link(struct nameidata *nd)
65302+static inline const char *nd_get_link(const struct nameidata *nd)
65303 {
65304 return nd->saved_names[nd->depth];
65305 }
65306diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
65307index a848ffc..3bbbaee 100644
65308--- a/include/linux/netdevice.h
65309+++ b/include/linux/netdevice.h
65310@@ -999,6 +999,7 @@ struct net_device_ops {
65311 struct net_device *dev,
65312 int idx);
65313 };
65314+typedef struct net_device_ops __no_const net_device_ops_no_const;
65315
65316 /*
65317 * The DEVICE structure.
65318@@ -1059,7 +1060,7 @@ struct net_device {
65319 int iflink;
65320
65321 struct net_device_stats stats;
65322- atomic_long_t rx_dropped; /* dropped packets by core network
65323+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
65324 * Do not use this in drivers.
65325 */
65326
65327diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
65328index 7958e84..ed74d7a 100644
65329--- a/include/linux/netfilter/ipset/ip_set.h
65330+++ b/include/linux/netfilter/ipset/ip_set.h
65331@@ -98,7 +98,7 @@ struct ip_set_type_variant {
65332 /* Return true if "b" set is the same as "a"
65333 * according to the create set parameters */
65334 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
65335-};
65336+} __do_const;
65337
65338 /* The core set type structure */
65339 struct ip_set_type {
65340diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
65341index 4966dde..7d8ce06 100644
65342--- a/include/linux/netfilter/nfnetlink.h
65343+++ b/include/linux/netfilter/nfnetlink.h
65344@@ -16,7 +16,7 @@ struct nfnl_callback {
65345 const struct nlattr * const cda[]);
65346 const struct nla_policy *policy; /* netlink attribute policy */
65347 const u_int16_t attr_count; /* number of nlattr's */
65348-};
65349+} __do_const;
65350
65351 struct nfnetlink_subsystem {
65352 const char *name;
65353diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
65354new file mode 100644
65355index 0000000..33f4af8
65356--- /dev/null
65357+++ b/include/linux/netfilter/xt_gradm.h
65358@@ -0,0 +1,9 @@
65359+#ifndef _LINUX_NETFILTER_XT_GRADM_H
65360+#define _LINUX_NETFILTER_XT_GRADM_H 1
65361+
65362+struct xt_gradm_mtinfo {
65363+ __u16 flags;
65364+ __u16 invflags;
65365+};
65366+
65367+#endif
65368diff --git a/include/linux/notifier.h b/include/linux/notifier.h
65369index d65746e..62e72c2 100644
65370--- a/include/linux/notifier.h
65371+++ b/include/linux/notifier.h
65372@@ -51,7 +51,8 @@ struct notifier_block {
65373 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
65374 struct notifier_block __rcu *next;
65375 int priority;
65376-};
65377+} __do_const;
65378+typedef struct notifier_block __no_const notifier_block_no_const;
65379
65380 struct atomic_notifier_head {
65381 spinlock_t lock;
65382diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
65383index a4c5624..79d6d88 100644
65384--- a/include/linux/oprofile.h
65385+++ b/include/linux/oprofile.h
65386@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
65387 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
65388 char const * name, ulong * val);
65389
65390-/** Create a file for read-only access to an atomic_t. */
65391+/** Create a file for read-only access to an atomic_unchecked_t. */
65392 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
65393- char const * name, atomic_t * val);
65394+ char const * name, atomic_unchecked_t * val);
65395
65396 /** create a directory */
65397 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
65398diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
65399index 6bfb2faa..1204767 100644
65400--- a/include/linux/perf_event.h
65401+++ b/include/linux/perf_event.h
65402@@ -328,8 +328,8 @@ struct perf_event {
65403
65404 enum perf_event_active_state state;
65405 unsigned int attach_state;
65406- local64_t count;
65407- atomic64_t child_count;
65408+ local64_t count; /* PaX: fix it one day */
65409+ atomic64_unchecked_t child_count;
65410
65411 /*
65412 * These are the total time in nanoseconds that the event
65413@@ -380,8 +380,8 @@ struct perf_event {
65414 * These accumulate total time (in nanoseconds) that children
65415 * events have been enabled and running, respectively.
65416 */
65417- atomic64_t child_total_time_enabled;
65418- atomic64_t child_total_time_running;
65419+ atomic64_unchecked_t child_total_time_enabled;
65420+ atomic64_unchecked_t child_total_time_running;
65421
65422 /*
65423 * Protect attach/detach and child_list:
65424diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
65425index ad1a427..6419649 100644
65426--- a/include/linux/pipe_fs_i.h
65427+++ b/include/linux/pipe_fs_i.h
65428@@ -45,9 +45,9 @@ struct pipe_buffer {
65429 struct pipe_inode_info {
65430 wait_queue_head_t wait;
65431 unsigned int nrbufs, curbuf, buffers;
65432- unsigned int readers;
65433- unsigned int writers;
65434- unsigned int waiting_writers;
65435+ atomic_t readers;
65436+ atomic_t writers;
65437+ atomic_t waiting_writers;
65438 unsigned int r_counter;
65439 unsigned int w_counter;
65440 struct page *tmp_page;
65441diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
65442index 5f28cae..3d23723 100644
65443--- a/include/linux/platform_data/usb-ehci-s5p.h
65444+++ b/include/linux/platform_data/usb-ehci-s5p.h
65445@@ -14,7 +14,7 @@
65446 struct s5p_ehci_platdata {
65447 int (*phy_init)(struct platform_device *pdev, int type);
65448 int (*phy_exit)(struct platform_device *pdev, int type);
65449-};
65450+} __no_const;
65451
65452 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
65453
65454diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
65455index f271860..6b3bec5 100644
65456--- a/include/linux/pm_runtime.h
65457+++ b/include/linux/pm_runtime.h
65458@@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
65459
65460 static inline void pm_runtime_mark_last_busy(struct device *dev)
65461 {
65462- ACCESS_ONCE(dev->power.last_busy) = jiffies;
65463+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
65464 }
65465
65466 #else /* !CONFIG_PM_RUNTIME */
65467diff --git a/include/linux/poison.h b/include/linux/poison.h
65468index 2110a81..13a11bb 100644
65469--- a/include/linux/poison.h
65470+++ b/include/linux/poison.h
65471@@ -19,8 +19,8 @@
65472 * under normal circumstances, used to verify that nobody uses
65473 * non-initialized list entries.
65474 */
65475-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
65476-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
65477+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
65478+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
65479
65480 /********** include/linux/timer.h **********/
65481 /*
65482diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
65483index 4a496eb..d9c5659 100644
65484--- a/include/linux/power/smartreflex.h
65485+++ b/include/linux/power/smartreflex.h
65486@@ -238,7 +238,7 @@ struct omap_sr_class_data {
65487 int (*notify)(struct omap_sr *sr, u32 status);
65488 u8 notify_flags;
65489 u8 class_type;
65490-};
65491+} __do_const;
65492
65493 /**
65494 * struct omap_sr_nvalue_table - Smartreflex n-target value info
65495diff --git a/include/linux/printk.h b/include/linux/printk.h
65496index 9afc01e..92c32e8 100644
65497--- a/include/linux/printk.h
65498+++ b/include/linux/printk.h
65499@@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
65500 extern int printk_needs_cpu(int cpu);
65501 extern void printk_tick(void);
65502
65503+extern int kptr_restrict;
65504+
65505 #ifdef CONFIG_PRINTK
65506 asmlinkage __printf(5, 0)
65507 int vprintk_emit(int facility, int level,
65508@@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
65509
65510 extern int printk_delay_msec;
65511 extern int dmesg_restrict;
65512-extern int kptr_restrict;
65513
65514 void log_buf_kexec_setup(void);
65515 void __init setup_log_buf(int early);
65516diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
65517index 3fd2e87..75db910 100644
65518--- a/include/linux/proc_fs.h
65519+++ b/include/linux/proc_fs.h
65520@@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
65521 return proc_create_data(name, mode, parent, proc_fops, NULL);
65522 }
65523
65524+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
65525+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
65526+{
65527+#ifdef CONFIG_GRKERNSEC_PROC_USER
65528+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
65529+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
65530+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
65531+#else
65532+ return proc_create_data(name, mode, parent, proc_fops, NULL);
65533+#endif
65534+}
65535+
65536 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
65537 umode_t mode, struct proc_dir_entry *base,
65538 read_proc_t *read_proc, void * data)
65539diff --git a/include/linux/random.h b/include/linux/random.h
65540index 6330ed4..419c6c3 100644
65541--- a/include/linux/random.h
65542+++ b/include/linux/random.h
65543@@ -30,12 +30,17 @@ void srandom32(u32 seed);
65544
65545 u32 prandom32(struct rnd_state *);
65546
65547+static inline unsigned long pax_get_random_long(void)
65548+{
65549+ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
65550+}
65551+
65552 /*
65553 * Handle minimum values for seeds
65554 */
65555 static inline u32 __seed(u32 x, u32 m)
65556 {
65557- return (x < m) ? x + m : x;
65558+ return (x <= m) ? x + m + 1 : x;
65559 }
65560
65561 /**
65562diff --git a/include/linux/reboot.h b/include/linux/reboot.h
65563index 23b3630..e1bc12b 100644
65564--- a/include/linux/reboot.h
65565+++ b/include/linux/reboot.h
65566@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
65567 * Architecture-specific implementations of sys_reboot commands.
65568 */
65569
65570-extern void machine_restart(char *cmd);
65571-extern void machine_halt(void);
65572-extern void machine_power_off(void);
65573+extern void machine_restart(char *cmd) __noreturn;
65574+extern void machine_halt(void) __noreturn;
65575+extern void machine_power_off(void) __noreturn;
65576
65577 extern void machine_shutdown(void);
65578 struct pt_regs;
65579@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
65580 */
65581
65582 extern void kernel_restart_prepare(char *cmd);
65583-extern void kernel_restart(char *cmd);
65584-extern void kernel_halt(void);
65585-extern void kernel_power_off(void);
65586+extern void kernel_restart(char *cmd) __noreturn;
65587+extern void kernel_halt(void) __noreturn;
65588+extern void kernel_power_off(void) __noreturn;
65589
65590 extern int C_A_D; /* for sysctl */
65591 void ctrl_alt_del(void);
65592@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
65593 * Emergency restart, callable from an interrupt handler.
65594 */
65595
65596-extern void emergency_restart(void);
65597+extern void emergency_restart(void) __noreturn;
65598 #include <asm/emergency-restart.h>
65599
65600 #endif /* _LINUX_REBOOT_H */
65601diff --git a/include/linux/regset.h b/include/linux/regset.h
65602index 8e0c9fe..fdb64bc 100644
65603--- a/include/linux/regset.h
65604+++ b/include/linux/regset.h
65605@@ -161,7 +161,7 @@ struct user_regset {
65606 unsigned int align;
65607 unsigned int bias;
65608 unsigned int core_note_type;
65609-};
65610+} __do_const;
65611
65612 /**
65613 * struct user_regset_view - available regsets
65614diff --git a/include/linux/relay.h b/include/linux/relay.h
65615index 91cacc3..b55ff74 100644
65616--- a/include/linux/relay.h
65617+++ b/include/linux/relay.h
65618@@ -160,7 +160,7 @@ struct rchan_callbacks
65619 * The callback should return 0 if successful, negative if not.
65620 */
65621 int (*remove_buf_file)(struct dentry *dentry);
65622-};
65623+} __no_const;
65624
65625 /*
65626 * CONFIG_RELAY kernel API, kernel/relay.c
65627diff --git a/include/linux/rio.h b/include/linux/rio.h
65628index a3e7842..d973ca6 100644
65629--- a/include/linux/rio.h
65630+++ b/include/linux/rio.h
65631@@ -339,7 +339,7 @@ struct rio_ops {
65632 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
65633 u64 rstart, u32 size, u32 flags);
65634 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
65635-};
65636+} __no_const;
65637
65638 #define RIO_RESOURCE_MEM 0x00000100
65639 #define RIO_RESOURCE_DOORBELL 0x00000200
65640diff --git a/include/linux/rmap.h b/include/linux/rmap.h
65641index bfe1f47..6a33ee3 100644
65642--- a/include/linux/rmap.h
65643+++ b/include/linux/rmap.h
65644@@ -134,8 +134,8 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
65645 void anon_vma_init(void); /* create anon_vma_cachep */
65646 int anon_vma_prepare(struct vm_area_struct *);
65647 void unlink_anon_vmas(struct vm_area_struct *);
65648-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
65649-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
65650+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
65651+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
65652
65653 static inline void anon_vma_merge(struct vm_area_struct *vma,
65654 struct vm_area_struct *next)
65655diff --git a/include/linux/sched.h b/include/linux/sched.h
65656index 3e63925..1d69dff 100644
65657--- a/include/linux/sched.h
65658+++ b/include/linux/sched.h
65659@@ -61,6 +61,7 @@ struct bio_list;
65660 struct fs_struct;
65661 struct perf_event_context;
65662 struct blk_plug;
65663+struct linux_binprm;
65664
65665 /*
65666 * List of flags we want to share for kernel threads,
65667@@ -344,10 +345,23 @@ struct user_namespace;
65668 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
65669
65670 extern int sysctl_max_map_count;
65671+extern unsigned long sysctl_heap_stack_gap;
65672
65673 #include <linux/aio.h>
65674
65675 #ifdef CONFIG_MMU
65676+
65677+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
65678+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
65679+#else
65680+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
65681+{
65682+ return 0;
65683+}
65684+#endif
65685+
65686+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
65687+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
65688 extern void arch_pick_mmap_layout(struct mm_struct *mm);
65689 extern unsigned long
65690 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
65691@@ -614,6 +628,17 @@ struct signal_struct {
65692 #ifdef CONFIG_TASKSTATS
65693 struct taskstats *stats;
65694 #endif
65695+
65696+#ifdef CONFIG_GRKERNSEC
65697+ u32 curr_ip;
65698+ u32 saved_ip;
65699+ u32 gr_saddr;
65700+ u32 gr_daddr;
65701+ u16 gr_sport;
65702+ u16 gr_dport;
65703+ u8 used_accept:1;
65704+#endif
65705+
65706 #ifdef CONFIG_AUDIT
65707 unsigned audit_tty;
65708 struct tty_audit_buf *tty_audit_buf;
65709@@ -691,6 +716,11 @@ struct user_struct {
65710 struct key *session_keyring; /* UID's default session keyring */
65711 #endif
65712
65713+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
65714+ unsigned int banned;
65715+ unsigned long ban_expires;
65716+#endif
65717+
65718 /* Hash table maintenance information */
65719 struct hlist_node uidhash_node;
65720 kuid_t uid;
65721@@ -1312,8 +1342,8 @@ struct task_struct {
65722 struct list_head thread_group;
65723
65724 struct completion *vfork_done; /* for vfork() */
65725- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
65726- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65727+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
65728+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
65729
65730 cputime_t utime, stime, utimescaled, stimescaled;
65731 cputime_t gtime;
65732@@ -1329,11 +1359,6 @@ struct task_struct {
65733 struct task_cputime cputime_expires;
65734 struct list_head cpu_timers[3];
65735
65736-/* process credentials */
65737- const struct cred __rcu *real_cred; /* objective and real subjective task
65738- * credentials (COW) */
65739- const struct cred __rcu *cred; /* effective (overridable) subjective task
65740- * credentials (COW) */
65741 char comm[TASK_COMM_LEN]; /* executable name excluding path
65742 - access with [gs]et_task_comm (which lock
65743 it with task_lock())
65744@@ -1350,6 +1375,10 @@ struct task_struct {
65745 #endif
65746 /* CPU-specific state of this task */
65747 struct thread_struct thread;
65748+/* thread_info moved to task_struct */
65749+#ifdef CONFIG_X86
65750+ struct thread_info tinfo;
65751+#endif
65752 /* filesystem information */
65753 struct fs_struct *fs;
65754 /* open file information */
65755@@ -1423,6 +1452,10 @@ struct task_struct {
65756 gfp_t lockdep_reclaim_gfp;
65757 #endif
65758
65759+/* process credentials */
65760+ const struct cred __rcu *real_cred; /* objective and real subjective task
65761+ * credentials (COW) */
65762+
65763 /* journalling filesystem info */
65764 void *journal_info;
65765
65766@@ -1461,6 +1494,10 @@ struct task_struct {
65767 /* cg_list protected by css_set_lock and tsk->alloc_lock */
65768 struct list_head cg_list;
65769 #endif
65770+
65771+ const struct cred __rcu *cred; /* effective (overridable) subjective task
65772+ * credentials (COW) */
65773+
65774 #ifdef CONFIG_FUTEX
65775 struct robust_list_head __user *robust_list;
65776 #ifdef CONFIG_COMPAT
65777@@ -1548,8 +1585,75 @@ struct task_struct {
65778 #ifdef CONFIG_UPROBES
65779 struct uprobe_task *utask;
65780 #endif
65781+
65782+#ifdef CONFIG_GRKERNSEC
65783+ /* grsecurity */
65784+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65785+ u64 exec_id;
65786+#endif
65787+#ifdef CONFIG_GRKERNSEC_SETXID
65788+ const struct cred *delayed_cred;
65789+#endif
65790+ struct dentry *gr_chroot_dentry;
65791+ struct acl_subject_label *acl;
65792+ struct acl_role_label *role;
65793+ struct file *exec_file;
65794+ unsigned long brute_expires;
65795+ u16 acl_role_id;
65796+ /* is this the task that authenticated to the special role */
65797+ u8 acl_sp_role;
65798+ u8 is_writable;
65799+ u8 brute;
65800+ u8 gr_is_chrooted;
65801+#endif
65802+
65803 };
65804
65805+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
65806+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
65807+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
65808+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
65809+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
65810+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
65811+
65812+#ifdef CONFIG_PAX_SOFTMODE
65813+extern int pax_softmode;
65814+#endif
65815+
65816+extern int pax_check_flags(unsigned long *);
65817+
65818+/* if tsk != current then task_lock must be held on it */
65819+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65820+static inline unsigned long pax_get_flags(struct task_struct *tsk)
65821+{
65822+ if (likely(tsk->mm))
65823+ return tsk->mm->pax_flags;
65824+ else
65825+ return 0UL;
65826+}
65827+
65828+/* if tsk != current then task_lock must be held on it */
65829+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
65830+{
65831+ if (likely(tsk->mm)) {
65832+ tsk->mm->pax_flags = flags;
65833+ return 0;
65834+ }
65835+ return -EINVAL;
65836+}
65837+#endif
65838+
65839+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
65840+extern void pax_set_initial_flags(struct linux_binprm *bprm);
65841+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
65842+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
65843+#endif
65844+
65845+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
65846+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
65847+extern void pax_report_refcount_overflow(struct pt_regs *regs);
65848+extern void check_object_size(const void *ptr, unsigned long n, bool to);
65849+
65850 /* Future-safe accessor for struct task_struct's cpus_allowed. */
65851 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
65852
65853@@ -2092,7 +2196,9 @@ void yield(void);
65854 extern struct exec_domain default_exec_domain;
65855
65856 union thread_union {
65857+#ifndef CONFIG_X86
65858 struct thread_info thread_info;
65859+#endif
65860 unsigned long stack[THREAD_SIZE/sizeof(long)];
65861 };
65862
65863@@ -2125,6 +2231,7 @@ extern struct pid_namespace init_pid_ns;
65864 */
65865
65866 extern struct task_struct *find_task_by_vpid(pid_t nr);
65867+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
65868 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
65869 struct pid_namespace *ns);
65870
65871@@ -2281,7 +2388,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
65872 extern void exit_itimers(struct signal_struct *);
65873 extern void flush_itimer_signals(void);
65874
65875-extern void do_group_exit(int);
65876+extern __noreturn void do_group_exit(int);
65877
65878 extern void daemonize(const char *, ...);
65879 extern int allow_signal(int);
65880@@ -2485,9 +2592,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
65881
65882 #endif
65883
65884-static inline int object_is_on_stack(void *obj)
65885+static inline int object_starts_on_stack(void *obj)
65886 {
65887- void *stack = task_stack_page(current);
65888+ const void *stack = task_stack_page(current);
65889
65890 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
65891 }
65892diff --git a/include/linux/security.h b/include/linux/security.h
65893index 05e88bd..5cda002 100644
65894--- a/include/linux/security.h
65895+++ b/include/linux/security.h
65896@@ -26,6 +26,7 @@
65897 #include <linux/capability.h>
65898 #include <linux/slab.h>
65899 #include <linux/err.h>
65900+#include <linux/grsecurity.h>
65901
65902 struct linux_binprm;
65903 struct cred;
65904diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
65905index 68a04a3..866e6a1 100644
65906--- a/include/linux/seq_file.h
65907+++ b/include/linux/seq_file.h
65908@@ -26,6 +26,9 @@ struct seq_file {
65909 struct mutex lock;
65910 const struct seq_operations *op;
65911 int poll_event;
65912+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65913+ u64 exec_id;
65914+#endif
65915 #ifdef CONFIG_USER_NS
65916 struct user_namespace *user_ns;
65917 #endif
65918@@ -38,6 +41,7 @@ struct seq_operations {
65919 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
65920 int (*show) (struct seq_file *m, void *v);
65921 };
65922+typedef struct seq_operations __no_const seq_operations_no_const;
65923
65924 #define SEQ_SKIP 1
65925
65926diff --git a/include/linux/shm.h b/include/linux/shm.h
65927index bcf8a6a..4d0af77 100644
65928--- a/include/linux/shm.h
65929+++ b/include/linux/shm.h
65930@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
65931
65932 /* The task created the shm object. NULL if the task is dead. */
65933 struct task_struct *shm_creator;
65934+#ifdef CONFIG_GRKERNSEC
65935+ time_t shm_createtime;
65936+ pid_t shm_lapid;
65937+#endif
65938 };
65939
65940 /* shm_mode upper byte flags */
65941diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
65942index 6a2c34e..a1f320f 100644
65943--- a/include/linux/skbuff.h
65944+++ b/include/linux/skbuff.h
65945@@ -577,7 +577,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
65946 extern struct sk_buff *__alloc_skb(unsigned int size,
65947 gfp_t priority, int flags, int node);
65948 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
65949-static inline struct sk_buff *alloc_skb(unsigned int size,
65950+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
65951 gfp_t priority)
65952 {
65953 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
65954@@ -687,7 +687,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
65955 */
65956 static inline int skb_queue_empty(const struct sk_buff_head *list)
65957 {
65958- return list->next == (struct sk_buff *)list;
65959+ return list->next == (const struct sk_buff *)list;
65960 }
65961
65962 /**
65963@@ -700,7 +700,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
65964 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65965 const struct sk_buff *skb)
65966 {
65967- return skb->next == (struct sk_buff *)list;
65968+ return skb->next == (const struct sk_buff *)list;
65969 }
65970
65971 /**
65972@@ -713,7 +713,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
65973 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
65974 const struct sk_buff *skb)
65975 {
65976- return skb->prev == (struct sk_buff *)list;
65977+ return skb->prev == (const struct sk_buff *)list;
65978 }
65979
65980 /**
65981@@ -1626,7 +1626,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
65982 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
65983 */
65984 #ifndef NET_SKB_PAD
65985-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
65986+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
65987 #endif
65988
65989 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
65990@@ -2204,7 +2204,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
65991 int noblock, int *err);
65992 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
65993 struct poll_table_struct *wait);
65994-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
65995+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
65996 int offset, struct iovec *to,
65997 int size);
65998 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
65999diff --git a/include/linux/slab.h b/include/linux/slab.h
66000index 83d1a14..209e1a6 100644
66001--- a/include/linux/slab.h
66002+++ b/include/linux/slab.h
66003@@ -11,12 +11,20 @@
66004
66005 #include <linux/gfp.h>
66006 #include <linux/types.h>
66007+#include <linux/err.h>
66008
66009 /*
66010 * Flags to pass to kmem_cache_create().
66011 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
66012 */
66013 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
66014+
66015+#ifdef CONFIG_PAX_USERCOPY_SLABS
66016+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
66017+#else
66018+#define SLAB_USERCOPY 0x00000000UL
66019+#endif
66020+
66021 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
66022 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
66023 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
66024@@ -87,10 +95,13 @@
66025 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
66026 * Both make kfree a no-op.
66027 */
66028-#define ZERO_SIZE_PTR ((void *)16)
66029+#define ZERO_SIZE_PTR \
66030+({ \
66031+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
66032+ (void *)(-MAX_ERRNO-1L); \
66033+})
66034
66035-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
66036- (unsigned long)ZERO_SIZE_PTR)
66037+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
66038
66039 /*
66040 * Common fields provided in kmem_cache by all slab allocators
66041@@ -110,7 +121,7 @@ struct kmem_cache {
66042 unsigned int align; /* Alignment as calculated */
66043 unsigned long flags; /* Active flags on the slab */
66044 const char *name; /* Slab name for sysfs */
66045- int refcount; /* Use counter */
66046+ atomic_t refcount; /* Use counter */
66047 void (*ctor)(void *); /* Called on object slot creation */
66048 struct list_head list; /* List of all slab caches on the system */
66049 };
66050@@ -185,6 +196,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
66051 void kfree(const void *);
66052 void kzfree(const void *);
66053 size_t ksize(const void *);
66054+const char *check_heap_object(const void *ptr, unsigned long n);
66055+bool is_usercopy_object(const void *ptr);
66056
66057 /*
66058 * Allocator specific definitions. These are mainly used to establish optimized
66059@@ -323,7 +336,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
66060 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66061 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66062 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66063-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66064+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
66065 #define kmalloc_track_caller(size, flags) \
66066 __kmalloc_track_caller(size, flags, _RET_IP_)
66067 #else
66068@@ -343,7 +356,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
66069 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
66070 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
66071 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
66072-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
66073+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
66074 #define kmalloc_node_track_caller(size, flags, node) \
66075 __kmalloc_node_track_caller(size, flags, node, \
66076 _RET_IP_)
66077diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
66078index cc290f0..0ba60931 100644
66079--- a/include/linux/slab_def.h
66080+++ b/include/linux/slab_def.h
66081@@ -52,7 +52,7 @@ struct kmem_cache {
66082 /* 4) cache creation/removal */
66083 const char *name;
66084 struct list_head list;
66085- int refcount;
66086+ atomic_t refcount;
66087 int object_size;
66088 int align;
66089
66090@@ -68,10 +68,10 @@ struct kmem_cache {
66091 unsigned long node_allocs;
66092 unsigned long node_frees;
66093 unsigned long node_overflow;
66094- atomic_t allochit;
66095- atomic_t allocmiss;
66096- atomic_t freehit;
66097- atomic_t freemiss;
66098+ atomic_unchecked_t allochit;
66099+ atomic_unchecked_t allocmiss;
66100+ atomic_unchecked_t freehit;
66101+ atomic_unchecked_t freemiss;
66102
66103 /*
66104 * If debugging is enabled, then the allocator can add additional
66105@@ -104,11 +104,16 @@ struct cache_sizes {
66106 #ifdef CONFIG_ZONE_DMA
66107 struct kmem_cache *cs_dmacachep;
66108 #endif
66109+
66110+#ifdef CONFIG_PAX_USERCOPY_SLABS
66111+ struct kmem_cache *cs_usercopycachep;
66112+#endif
66113+
66114 };
66115 extern struct cache_sizes malloc_sizes[];
66116
66117 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66118-void *__kmalloc(size_t size, gfp_t flags);
66119+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
66120
66121 #ifdef CONFIG_TRACING
66122 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
66123@@ -145,6 +150,13 @@ found:
66124 cachep = malloc_sizes[i].cs_dmacachep;
66125 else
66126 #endif
66127+
66128+#ifdef CONFIG_PAX_USERCOPY_SLABS
66129+ if (flags & GFP_USERCOPY)
66130+ cachep = malloc_sizes[i].cs_usercopycachep;
66131+ else
66132+#endif
66133+
66134 cachep = malloc_sizes[i].cs_cachep;
66135
66136 ret = kmem_cache_alloc_trace(cachep, flags, size);
66137@@ -155,7 +167,7 @@ found:
66138 }
66139
66140 #ifdef CONFIG_NUMA
66141-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
66142+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66143 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66144
66145 #ifdef CONFIG_TRACING
66146@@ -198,6 +210,13 @@ found:
66147 cachep = malloc_sizes[i].cs_dmacachep;
66148 else
66149 #endif
66150+
66151+#ifdef CONFIG_PAX_USERCOPY_SLABS
66152+ if (flags & GFP_USERCOPY)
66153+ cachep = malloc_sizes[i].cs_usercopycachep;
66154+ else
66155+#endif
66156+
66157 cachep = malloc_sizes[i].cs_cachep;
66158
66159 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
66160diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
66161index f28e14a..7831211 100644
66162--- a/include/linux/slob_def.h
66163+++ b/include/linux/slob_def.h
66164@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
66165 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
66166 }
66167
66168-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66169+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66170
66171 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
66172 {
66173@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66174 return __kmalloc_node(size, flags, NUMA_NO_NODE);
66175 }
66176
66177-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
66178+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
66179 {
66180 return kmalloc(size, flags);
66181 }
66182diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
66183index df448ad..b99e7f6 100644
66184--- a/include/linux/slub_def.h
66185+++ b/include/linux/slub_def.h
66186@@ -91,7 +91,7 @@ struct kmem_cache {
66187 struct kmem_cache_order_objects max;
66188 struct kmem_cache_order_objects min;
66189 gfp_t allocflags; /* gfp flags to use on each alloc */
66190- int refcount; /* Refcount for slab cache destroy */
66191+ atomic_t refcount; /* Refcount for slab cache destroy */
66192 void (*ctor)(void *);
66193 int inuse; /* Offset to metadata */
66194 int align; /* Alignment */
66195@@ -152,7 +152,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
66196 * Sorry that the following has to be that ugly but some versions of GCC
66197 * have trouble with constant propagation and loops.
66198 */
66199-static __always_inline int kmalloc_index(size_t size)
66200+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
66201 {
66202 if (!size)
66203 return 0;
66204@@ -217,7 +217,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
66205 }
66206
66207 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
66208-void *__kmalloc(size_t size, gfp_t flags);
66209+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
66210
66211 static __always_inline void *
66212 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
66213@@ -258,7 +258,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
66214 }
66215 #endif
66216
66217-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
66218+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
66219 {
66220 unsigned int order = get_order(size);
66221 return kmalloc_order_trace(size, flags, order);
66222@@ -283,7 +283,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
66223 }
66224
66225 #ifdef CONFIG_NUMA
66226-void *__kmalloc_node(size_t size, gfp_t flags, int node);
66227+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
66228 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
66229
66230 #ifdef CONFIG_TRACING
66231diff --git a/include/linux/sonet.h b/include/linux/sonet.h
66232index 680f9a3..f13aeb0 100644
66233--- a/include/linux/sonet.h
66234+++ b/include/linux/sonet.h
66235@@ -7,7 +7,7 @@
66236 #include <uapi/linux/sonet.h>
66237
66238 struct k_sonet_stats {
66239-#define __HANDLE_ITEM(i) atomic_t i
66240+#define __HANDLE_ITEM(i) atomic_unchecked_t i
66241 __SONET_ITEMS
66242 #undef __HANDLE_ITEM
66243 };
66244diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
66245index 34206b8..f019e06 100644
66246--- a/include/linux/sunrpc/clnt.h
66247+++ b/include/linux/sunrpc/clnt.h
66248@@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
66249 {
66250 switch (sap->sa_family) {
66251 case AF_INET:
66252- return ntohs(((struct sockaddr_in *)sap)->sin_port);
66253+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
66254 case AF_INET6:
66255- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
66256+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
66257 }
66258 return 0;
66259 }
66260@@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
66261 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
66262 const struct sockaddr *src)
66263 {
66264- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
66265+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
66266 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
66267
66268 dsin->sin_family = ssin->sin_family;
66269@@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
66270 if (sa->sa_family != AF_INET6)
66271 return 0;
66272
66273- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
66274+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
66275 }
66276
66277 #endif /* __KERNEL__ */
66278diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
66279index 0b8e3e6..33e0a01 100644
66280--- a/include/linux/sunrpc/svc_rdma.h
66281+++ b/include/linux/sunrpc/svc_rdma.h
66282@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
66283 extern unsigned int svcrdma_max_requests;
66284 extern unsigned int svcrdma_max_req_size;
66285
66286-extern atomic_t rdma_stat_recv;
66287-extern atomic_t rdma_stat_read;
66288-extern atomic_t rdma_stat_write;
66289-extern atomic_t rdma_stat_sq_starve;
66290-extern atomic_t rdma_stat_rq_starve;
66291-extern atomic_t rdma_stat_rq_poll;
66292-extern atomic_t rdma_stat_rq_prod;
66293-extern atomic_t rdma_stat_sq_poll;
66294-extern atomic_t rdma_stat_sq_prod;
66295+extern atomic_unchecked_t rdma_stat_recv;
66296+extern atomic_unchecked_t rdma_stat_read;
66297+extern atomic_unchecked_t rdma_stat_write;
66298+extern atomic_unchecked_t rdma_stat_sq_starve;
66299+extern atomic_unchecked_t rdma_stat_rq_starve;
66300+extern atomic_unchecked_t rdma_stat_rq_poll;
66301+extern atomic_unchecked_t rdma_stat_rq_prod;
66302+extern atomic_unchecked_t rdma_stat_sq_poll;
66303+extern atomic_unchecked_t rdma_stat_sq_prod;
66304
66305 #define RPCRDMA_VERSION 1
66306
66307diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
66308index cd844a6..3ca3592 100644
66309--- a/include/linux/sysctl.h
66310+++ b/include/linux/sysctl.h
66311@@ -41,6 +41,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
66312
66313 extern int proc_dostring(struct ctl_table *, int,
66314 void __user *, size_t *, loff_t *);
66315+extern int proc_dostring_modpriv(struct ctl_table *, int,
66316+ void __user *, size_t *, loff_t *);
66317 extern int proc_dointvec(struct ctl_table *, int,
66318 void __user *, size_t *, loff_t *);
66319 extern int proc_dointvec_minmax(struct ctl_table *, int,
66320diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
66321index 7faf933..eb6f5e3 100644
66322--- a/include/linux/sysrq.h
66323+++ b/include/linux/sysrq.h
66324@@ -36,7 +36,7 @@ struct sysrq_key_op {
66325 char *help_msg;
66326 char *action_msg;
66327 int enable_mask;
66328-};
66329+} __do_const;
66330
66331 #ifdef CONFIG_MAGIC_SYSRQ
66332
66333diff --git a/include/linux/tty.h b/include/linux/tty.h
66334index f0b4eb4..1c4854e 100644
66335--- a/include/linux/tty.h
66336+++ b/include/linux/tty.h
66337@@ -192,7 +192,7 @@ struct tty_port {
66338 const struct tty_port_operations *ops; /* Port operations */
66339 spinlock_t lock; /* Lock protecting tty field */
66340 int blocked_open; /* Waiting to open */
66341- int count; /* Usage count */
66342+ atomic_t count; /* Usage count */
66343 wait_queue_head_t open_wait; /* Open waiters */
66344 wait_queue_head_t close_wait; /* Close waiters */
66345 wait_queue_head_t delta_msr_wait; /* Modem status change */
66346@@ -513,7 +513,7 @@ extern int tty_port_open(struct tty_port *port,
66347 struct tty_struct *tty, struct file *filp);
66348 static inline int tty_port_users(struct tty_port *port)
66349 {
66350- return port->count + port->blocked_open;
66351+ return atomic_read(&port->count) + port->blocked_open;
66352 }
66353
66354 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
66355diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
66356index dd976cf..e272742 100644
66357--- a/include/linux/tty_driver.h
66358+++ b/include/linux/tty_driver.h
66359@@ -284,7 +284,7 @@ struct tty_operations {
66360 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
66361 #endif
66362 const struct file_operations *proc_fops;
66363-};
66364+} __do_const;
66365
66366 struct tty_driver {
66367 int magic; /* magic number for this structure */
66368diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
66369index fb79dd8d..07d4773 100644
66370--- a/include/linux/tty_ldisc.h
66371+++ b/include/linux/tty_ldisc.h
66372@@ -149,7 +149,7 @@ struct tty_ldisc_ops {
66373
66374 struct module *owner;
66375
66376- int refcount;
66377+ atomic_t refcount;
66378 };
66379
66380 struct tty_ldisc {
66381diff --git a/include/linux/types.h b/include/linux/types.h
66382index 1cc0e4b..0d50edf 100644
66383--- a/include/linux/types.h
66384+++ b/include/linux/types.h
66385@@ -175,10 +175,26 @@ typedef struct {
66386 int counter;
66387 } atomic_t;
66388
66389+#ifdef CONFIG_PAX_REFCOUNT
66390+typedef struct {
66391+ int counter;
66392+} atomic_unchecked_t;
66393+#else
66394+typedef atomic_t atomic_unchecked_t;
66395+#endif
66396+
66397 #ifdef CONFIG_64BIT
66398 typedef struct {
66399 long counter;
66400 } atomic64_t;
66401+
66402+#ifdef CONFIG_PAX_REFCOUNT
66403+typedef struct {
66404+ long counter;
66405+} atomic64_unchecked_t;
66406+#else
66407+typedef atomic64_t atomic64_unchecked_t;
66408+#endif
66409 #endif
66410
66411 struct list_head {
66412diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
66413index 5ca0951..ab496a5 100644
66414--- a/include/linux/uaccess.h
66415+++ b/include/linux/uaccess.h
66416@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
66417 long ret; \
66418 mm_segment_t old_fs = get_fs(); \
66419 \
66420- set_fs(KERNEL_DS); \
66421 pagefault_disable(); \
66422- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
66423- pagefault_enable(); \
66424+ set_fs(KERNEL_DS); \
66425+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
66426 set_fs(old_fs); \
66427+ pagefault_enable(); \
66428 ret; \
66429 })
66430
66431diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
66432index 99c1b4d..bb94261 100644
66433--- a/include/linux/unaligned/access_ok.h
66434+++ b/include/linux/unaligned/access_ok.h
66435@@ -6,32 +6,32 @@
66436
66437 static inline u16 get_unaligned_le16(const void *p)
66438 {
66439- return le16_to_cpup((__le16 *)p);
66440+ return le16_to_cpup((const __le16 *)p);
66441 }
66442
66443 static inline u32 get_unaligned_le32(const void *p)
66444 {
66445- return le32_to_cpup((__le32 *)p);
66446+ return le32_to_cpup((const __le32 *)p);
66447 }
66448
66449 static inline u64 get_unaligned_le64(const void *p)
66450 {
66451- return le64_to_cpup((__le64 *)p);
66452+ return le64_to_cpup((const __le64 *)p);
66453 }
66454
66455 static inline u16 get_unaligned_be16(const void *p)
66456 {
66457- return be16_to_cpup((__be16 *)p);
66458+ return be16_to_cpup((const __be16 *)p);
66459 }
66460
66461 static inline u32 get_unaligned_be32(const void *p)
66462 {
66463- return be32_to_cpup((__be32 *)p);
66464+ return be32_to_cpup((const __be32 *)p);
66465 }
66466
66467 static inline u64 get_unaligned_be64(const void *p)
66468 {
66469- return be64_to_cpup((__be64 *)p);
66470+ return be64_to_cpup((const __be64 *)p);
66471 }
66472
66473 static inline void put_unaligned_le16(u16 val, void *p)
66474diff --git a/include/linux/usb.h b/include/linux/usb.h
66475index 10278d1..e21ec3c 100644
66476--- a/include/linux/usb.h
66477+++ b/include/linux/usb.h
66478@@ -551,7 +551,7 @@ struct usb_device {
66479 int maxchild;
66480
66481 u32 quirks;
66482- atomic_t urbnum;
66483+ atomic_unchecked_t urbnum;
66484
66485 unsigned long active_duration;
66486
66487diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
66488index c5d36c6..108f4f9 100644
66489--- a/include/linux/usb/renesas_usbhs.h
66490+++ b/include/linux/usb/renesas_usbhs.h
66491@@ -39,7 +39,7 @@ enum {
66492 */
66493 struct renesas_usbhs_driver_callback {
66494 int (*notify_hotplug)(struct platform_device *pdev);
66495-};
66496+} __no_const;
66497
66498 /*
66499 * callback functions for platform
66500diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
66501index 6f8fbcf..8259001 100644
66502--- a/include/linux/vermagic.h
66503+++ b/include/linux/vermagic.h
66504@@ -25,9 +25,35 @@
66505 #define MODULE_ARCH_VERMAGIC ""
66506 #endif
66507
66508+#ifdef CONFIG_PAX_REFCOUNT
66509+#define MODULE_PAX_REFCOUNT "REFCOUNT "
66510+#else
66511+#define MODULE_PAX_REFCOUNT ""
66512+#endif
66513+
66514+#ifdef CONSTIFY_PLUGIN
66515+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
66516+#else
66517+#define MODULE_CONSTIFY_PLUGIN ""
66518+#endif
66519+
66520+#ifdef STACKLEAK_PLUGIN
66521+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
66522+#else
66523+#define MODULE_STACKLEAK_PLUGIN ""
66524+#endif
66525+
66526+#ifdef CONFIG_GRKERNSEC
66527+#define MODULE_GRSEC "GRSEC "
66528+#else
66529+#define MODULE_GRSEC ""
66530+#endif
66531+
66532 #define VERMAGIC_STRING \
66533 UTS_RELEASE " " \
66534 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
66535 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
66536- MODULE_ARCH_VERMAGIC
66537+ MODULE_ARCH_VERMAGIC \
66538+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
66539+ MODULE_GRSEC
66540
66541diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
66542index 6071e91..ca6a489 100644
66543--- a/include/linux/vmalloc.h
66544+++ b/include/linux/vmalloc.h
66545@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
66546 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
66547 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
66548 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
66549+
66550+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
66551+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
66552+#endif
66553+
66554 /* bits [20..32] reserved for arch specific ioremap internals */
66555
66556 /*
66557@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
66558 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
66559 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
66560 unsigned long start, unsigned long end, gfp_t gfp_mask,
66561- pgprot_t prot, int node, const void *caller);
66562+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
66563 extern void vfree(const void *addr);
66564
66565 extern void *vmap(struct page **pages, unsigned int count,
66566@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
66567 extern void free_vm_area(struct vm_struct *area);
66568
66569 /* for /dev/kmem */
66570-extern long vread(char *buf, char *addr, unsigned long count);
66571-extern long vwrite(char *buf, char *addr, unsigned long count);
66572+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
66573+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
66574
66575 /*
66576 * Internals. Dont't use..
66577diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
66578index 92a86b2..1d9eb3c 100644
66579--- a/include/linux/vmstat.h
66580+++ b/include/linux/vmstat.h
66581@@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
66582 /*
66583 * Zone based page accounting with per cpu differentials.
66584 */
66585-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66586+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
66587
66588 static inline void zone_page_state_add(long x, struct zone *zone,
66589 enum zone_stat_item item)
66590 {
66591- atomic_long_add(x, &zone->vm_stat[item]);
66592- atomic_long_add(x, &vm_stat[item]);
66593+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
66594+ atomic_long_add_unchecked(x, &vm_stat[item]);
66595 }
66596
66597 static inline unsigned long global_page_state(enum zone_stat_item item)
66598 {
66599- long x = atomic_long_read(&vm_stat[item]);
66600+ long x = atomic_long_read_unchecked(&vm_stat[item]);
66601 #ifdef CONFIG_SMP
66602 if (x < 0)
66603 x = 0;
66604@@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
66605 static inline unsigned long zone_page_state(struct zone *zone,
66606 enum zone_stat_item item)
66607 {
66608- long x = atomic_long_read(&zone->vm_stat[item]);
66609+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66610 #ifdef CONFIG_SMP
66611 if (x < 0)
66612 x = 0;
66613@@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
66614 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
66615 enum zone_stat_item item)
66616 {
66617- long x = atomic_long_read(&zone->vm_stat[item]);
66618+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
66619
66620 #ifdef CONFIG_SMP
66621 int cpu;
66622@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
66623
66624 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
66625 {
66626- atomic_long_inc(&zone->vm_stat[item]);
66627- atomic_long_inc(&vm_stat[item]);
66628+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
66629+ atomic_long_inc_unchecked(&vm_stat[item]);
66630 }
66631
66632 static inline void __inc_zone_page_state(struct page *page,
66633@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
66634
66635 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
66636 {
66637- atomic_long_dec(&zone->vm_stat[item]);
66638- atomic_long_dec(&vm_stat[item]);
66639+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
66640+ atomic_long_dec_unchecked(&vm_stat[item]);
66641 }
66642
66643 static inline void __dec_zone_page_state(struct page *page,
66644diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
66645index 95d1c91..6798cca 100644
66646--- a/include/media/v4l2-dev.h
66647+++ b/include/media/v4l2-dev.h
66648@@ -76,7 +76,7 @@ struct v4l2_file_operations {
66649 int (*mmap) (struct file *, struct vm_area_struct *);
66650 int (*open) (struct file *);
66651 int (*release) (struct file *);
66652-};
66653+} __do_const;
66654
66655 /*
66656 * Newer version of video_device, handled by videodev2.c
66657diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
66658index e48b571..7e40de4 100644
66659--- a/include/media/v4l2-ioctl.h
66660+++ b/include/media/v4l2-ioctl.h
66661@@ -282,7 +282,6 @@ struct v4l2_ioctl_ops {
66662 bool valid_prio, int cmd, void *arg);
66663 };
66664
66665-
66666 /* v4l debugging and diagnostics */
66667
66668 /* Debug bitmask flags to be used on V4L2 */
66669diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
66670index 9e5425b..8136ffc 100644
66671--- a/include/net/caif/cfctrl.h
66672+++ b/include/net/caif/cfctrl.h
66673@@ -52,7 +52,7 @@ struct cfctrl_rsp {
66674 void (*radioset_rsp)(void);
66675 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
66676 struct cflayer *client_layer);
66677-};
66678+} __no_const;
66679
66680 /* Link Setup Parameters for CAIF-Links. */
66681 struct cfctrl_link_param {
66682@@ -101,8 +101,8 @@ struct cfctrl_request_info {
66683 struct cfctrl {
66684 struct cfsrvl serv;
66685 struct cfctrl_rsp res;
66686- atomic_t req_seq_no;
66687- atomic_t rsp_seq_no;
66688+ atomic_unchecked_t req_seq_no;
66689+ atomic_unchecked_t rsp_seq_no;
66690 struct list_head list;
66691 /* Protects from simultaneous access to first_req list */
66692 spinlock_t info_list_lock;
66693diff --git a/include/net/flow.h b/include/net/flow.h
66694index 628e11b..4c475df 100644
66695--- a/include/net/flow.h
66696+++ b/include/net/flow.h
66697@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
66698
66699 extern void flow_cache_flush(void);
66700 extern void flow_cache_flush_deferred(void);
66701-extern atomic_t flow_cache_genid;
66702+extern atomic_unchecked_t flow_cache_genid;
66703
66704 #endif
66705diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
66706index e5062c9..e709988 100644
66707--- a/include/net/gro_cells.h
66708+++ b/include/net/gro_cells.h
66709@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
66710 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
66711
66712 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
66713- atomic_long_inc(&dev->rx_dropped);
66714+ atomic_long_inc_unchecked(&dev->rx_dropped);
66715 kfree_skb(skb);
66716 return;
66717 }
66718diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
66719index 1832927..ce39aea 100644
66720--- a/include/net/inet_connection_sock.h
66721+++ b/include/net/inet_connection_sock.h
66722@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
66723 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
66724 int (*bind_conflict)(const struct sock *sk,
66725 const struct inet_bind_bucket *tb, bool relax);
66726-};
66727+} __do_const;
66728
66729 /** inet_connection_sock - INET connection oriented sock
66730 *
66731diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
66732index 53f464d..ba76aaa 100644
66733--- a/include/net/inetpeer.h
66734+++ b/include/net/inetpeer.h
66735@@ -47,8 +47,8 @@ struct inet_peer {
66736 */
66737 union {
66738 struct {
66739- atomic_t rid; /* Frag reception counter */
66740- atomic_t ip_id_count; /* IP ID for the next packet */
66741+ atomic_unchecked_t rid; /* Frag reception counter */
66742+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
66743 };
66744 struct rcu_head rcu;
66745 struct inet_peer *gc_next;
66746@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
66747 more++;
66748 inet_peer_refcheck(p);
66749 do {
66750- old = atomic_read(&p->ip_id_count);
66751+ old = atomic_read_unchecked(&p->ip_id_count);
66752 new = old + more;
66753 if (!new)
66754 new = 1;
66755- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
66756+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
66757 return new;
66758 }
66759
66760diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
66761index 9497be1..5a4fafe 100644
66762--- a/include/net/ip_fib.h
66763+++ b/include/net/ip_fib.h
66764@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
66765
66766 #define FIB_RES_SADDR(net, res) \
66767 ((FIB_RES_NH(res).nh_saddr_genid == \
66768- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
66769+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
66770 FIB_RES_NH(res).nh_saddr : \
66771 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
66772 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
66773diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
66774index ee75ccd..2cc2b95 100644
66775--- a/include/net/ip_vs.h
66776+++ b/include/net/ip_vs.h
66777@@ -510,7 +510,7 @@ struct ip_vs_conn {
66778 struct ip_vs_conn *control; /* Master control connection */
66779 atomic_t n_control; /* Number of controlled ones */
66780 struct ip_vs_dest *dest; /* real server */
66781- atomic_t in_pkts; /* incoming packet counter */
66782+ atomic_unchecked_t in_pkts; /* incoming packet counter */
66783
66784 /* packet transmitter for different forwarding methods. If it
66785 mangles the packet, it must return NF_DROP or better NF_STOLEN,
66786@@ -648,7 +648,7 @@ struct ip_vs_dest {
66787 __be16 port; /* port number of the server */
66788 union nf_inet_addr addr; /* IP address of the server */
66789 volatile unsigned int flags; /* dest status flags */
66790- atomic_t conn_flags; /* flags to copy to conn */
66791+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
66792 atomic_t weight; /* server weight */
66793
66794 atomic_t refcnt; /* reference counter */
66795diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
66796index 80ffde3..968b0f4 100644
66797--- a/include/net/irda/ircomm_tty.h
66798+++ b/include/net/irda/ircomm_tty.h
66799@@ -35,6 +35,7 @@
66800 #include <linux/termios.h>
66801 #include <linux/timer.h>
66802 #include <linux/tty.h> /* struct tty_struct */
66803+#include <asm/local.h>
66804
66805 #include <net/irda/irias_object.h>
66806 #include <net/irda/ircomm_core.h>
66807diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
66808index cc7c197..9f2da2a 100644
66809--- a/include/net/iucv/af_iucv.h
66810+++ b/include/net/iucv/af_iucv.h
66811@@ -141,7 +141,7 @@ struct iucv_sock {
66812 struct iucv_sock_list {
66813 struct hlist_head head;
66814 rwlock_t lock;
66815- atomic_t autobind_name;
66816+ atomic_unchecked_t autobind_name;
66817 };
66818
66819 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
66820diff --git a/include/net/neighbour.h b/include/net/neighbour.h
66821index 0dab173..1b76af0 100644
66822--- a/include/net/neighbour.h
66823+++ b/include/net/neighbour.h
66824@@ -123,7 +123,7 @@ struct neigh_ops {
66825 void (*error_report)(struct neighbour *, struct sk_buff *);
66826 int (*output)(struct neighbour *, struct sk_buff *);
66827 int (*connected_output)(struct neighbour *, struct sk_buff *);
66828-};
66829+} __do_const;
66830
66831 struct pneigh_entry {
66832 struct pneigh_entry *next;
66833diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
66834index 95e6466..251016d 100644
66835--- a/include/net/net_namespace.h
66836+++ b/include/net/net_namespace.h
66837@@ -110,7 +110,7 @@ struct net {
66838 #endif
66839 struct netns_ipvs *ipvs;
66840 struct sock *diag_nlsk;
66841- atomic_t rt_genid;
66842+ atomic_unchecked_t rt_genid;
66843 };
66844
66845 /*
66846@@ -320,12 +320,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
66847
66848 static inline int rt_genid(struct net *net)
66849 {
66850- return atomic_read(&net->rt_genid);
66851+ return atomic_read_unchecked(&net->rt_genid);
66852 }
66853
66854 static inline void rt_genid_bump(struct net *net)
66855 {
66856- atomic_inc(&net->rt_genid);
66857+ atomic_inc_unchecked(&net->rt_genid);
66858 }
66859
66860 #endif /* __NET_NET_NAMESPACE_H */
66861diff --git a/include/net/netdma.h b/include/net/netdma.h
66862index 8ba8ce2..99b7fff 100644
66863--- a/include/net/netdma.h
66864+++ b/include/net/netdma.h
66865@@ -24,7 +24,7 @@
66866 #include <linux/dmaengine.h>
66867 #include <linux/skbuff.h>
66868
66869-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66870+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
66871 struct sk_buff *skb, int offset, struct iovec *to,
66872 size_t len, struct dma_pinned_list *pinned_list);
66873
66874diff --git a/include/net/netfilter/nf_queue.h b/include/net/netfilter/nf_queue.h
66875index 252fd10..aa1421f 100644
66876--- a/include/net/netfilter/nf_queue.h
66877+++ b/include/net/netfilter/nf_queue.h
66878@@ -22,7 +22,7 @@ struct nf_queue_handler {
66879 int (*outfn)(struct nf_queue_entry *entry,
66880 unsigned int queuenum);
66881 char *name;
66882-};
66883+} __do_const;
66884
66885 extern int nf_register_queue_handler(u_int8_t pf,
66886 const struct nf_queue_handler *qh);
66887diff --git a/include/net/netlink.h b/include/net/netlink.h
66888index 9690b0f..87aded7 100644
66889--- a/include/net/netlink.h
66890+++ b/include/net/netlink.h
66891@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
66892 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
66893 {
66894 if (mark)
66895- skb_trim(skb, (unsigned char *) mark - skb->data);
66896+ skb_trim(skb, (const unsigned char *) mark - skb->data);
66897 }
66898
66899 /**
66900diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
66901index 2ae2b83..dbdc85e 100644
66902--- a/include/net/netns/ipv4.h
66903+++ b/include/net/netns/ipv4.h
66904@@ -64,7 +64,7 @@ struct netns_ipv4 {
66905 kgid_t sysctl_ping_group_range[2];
66906 long sysctl_tcp_mem[3];
66907
66908- atomic_t dev_addr_genid;
66909+ atomic_unchecked_t dev_addr_genid;
66910
66911 #ifdef CONFIG_IP_MROUTE
66912 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
66913diff --git a/include/net/protocol.h b/include/net/protocol.h
66914index 929528c..c84d4f6 100644
66915--- a/include/net/protocol.h
66916+++ b/include/net/protocol.h
66917@@ -48,7 +48,7 @@ struct net_protocol {
66918 int (*gro_complete)(struct sk_buff *skb);
66919 unsigned int no_policy:1,
66920 netns_ok:1;
66921-};
66922+} __do_const;
66923
66924 #if IS_ENABLED(CONFIG_IPV6)
66925 struct inet6_protocol {
66926@@ -69,7 +69,7 @@ struct inet6_protocol {
66927 int (*gro_complete)(struct sk_buff *skb);
66928
66929 unsigned int flags; /* INET6_PROTO_xxx */
66930-};
66931+} __do_const;
66932
66933 #define INET6_PROTO_NOPOLICY 0x1
66934 #define INET6_PROTO_FINAL 0x2
66935diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
66936index 9c6414f..fbd0524 100644
66937--- a/include/net/sctp/sctp.h
66938+++ b/include/net/sctp/sctp.h
66939@@ -318,9 +318,9 @@ do { \
66940
66941 #else /* SCTP_DEBUG */
66942
66943-#define SCTP_DEBUG_PRINTK(whatever...)
66944-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
66945-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
66946+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
66947+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
66948+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
66949 #define SCTP_ENABLE_DEBUG
66950 #define SCTP_DISABLE_DEBUG
66951 #define SCTP_ASSERT(expr, str, func)
66952diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
66953index 64158aa..b65533c 100644
66954--- a/include/net/sctp/structs.h
66955+++ b/include/net/sctp/structs.h
66956@@ -496,7 +496,7 @@ struct sctp_af {
66957 int sockaddr_len;
66958 sa_family_t sa_family;
66959 struct list_head list;
66960-};
66961+} __do_const;
66962
66963 struct sctp_af *sctp_get_af_specific(sa_family_t);
66964 int sctp_register_af(struct sctp_af *);
66965@@ -516,7 +516,7 @@ struct sctp_pf {
66966 struct sctp_association *asoc);
66967 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
66968 struct sctp_af *af;
66969-};
66970+} __do_const;
66971
66972
66973 /* Structure to track chunk fragments that have been acked, but peer
66974diff --git a/include/net/sock.h b/include/net/sock.h
66975index c945fba..e162e56 100644
66976--- a/include/net/sock.h
66977+++ b/include/net/sock.h
66978@@ -304,7 +304,7 @@ struct sock {
66979 #ifdef CONFIG_RPS
66980 __u32 sk_rxhash;
66981 #endif
66982- atomic_t sk_drops;
66983+ atomic_unchecked_t sk_drops;
66984 int sk_rcvbuf;
66985
66986 struct sk_filter __rcu *sk_filter;
66987@@ -1763,7 +1763,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
66988 }
66989
66990 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
66991- char __user *from, char *to,
66992+ char __user *from, unsigned char *to,
66993 int copy, int offset)
66994 {
66995 if (skb->ip_summed == CHECKSUM_NONE) {
66996@@ -2022,7 +2022,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
66997 }
66998 }
66999
67000-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67001+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
67002
67003 /**
67004 * sk_page_frag - return an appropriate page_frag
67005diff --git a/include/net/tcp.h b/include/net/tcp.h
67006index 4af45e3..af97861 100644
67007--- a/include/net/tcp.h
67008+++ b/include/net/tcp.h
67009@@ -531,7 +531,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
67010 extern void tcp_xmit_retransmit_queue(struct sock *);
67011 extern void tcp_simple_retransmit(struct sock *);
67012 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
67013-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67014+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
67015
67016 extern void tcp_send_probe0(struct sock *);
67017 extern void tcp_send_partial(struct sock *);
67018@@ -702,8 +702,8 @@ struct tcp_skb_cb {
67019 struct inet6_skb_parm h6;
67020 #endif
67021 } header; /* For incoming frames */
67022- __u32 seq; /* Starting sequence number */
67023- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
67024+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
67025+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
67026 __u32 when; /* used to compute rtt's */
67027 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
67028
67029@@ -717,7 +717,7 @@ struct tcp_skb_cb {
67030
67031 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
67032 /* 1 byte hole */
67033- __u32 ack_seq; /* Sequence number ACK'd */
67034+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
67035 };
67036
67037 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
67038diff --git a/include/net/xfrm.h b/include/net/xfrm.h
67039index 63445ed..74ef61d 100644
67040--- a/include/net/xfrm.h
67041+++ b/include/net/xfrm.h
67042@@ -423,7 +423,7 @@ struct xfrm_mode {
67043 struct module *owner;
67044 unsigned int encap;
67045 int flags;
67046-};
67047+} __do_const;
67048
67049 /* Flags for xfrm_mode. */
67050 enum {
67051@@ -514,7 +514,7 @@ struct xfrm_policy {
67052 struct timer_list timer;
67053
67054 struct flow_cache_object flo;
67055- atomic_t genid;
67056+ atomic_unchecked_t genid;
67057 u32 priority;
67058 u32 index;
67059 struct xfrm_mark mark;
67060diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
67061index 1a046b1..ee0bef0 100644
67062--- a/include/rdma/iw_cm.h
67063+++ b/include/rdma/iw_cm.h
67064@@ -122,7 +122,7 @@ struct iw_cm_verbs {
67065 int backlog);
67066
67067 int (*destroy_listen)(struct iw_cm_id *cm_id);
67068-};
67069+} __no_const;
67070
67071 /**
67072 * iw_create_cm_id - Create an IW CM identifier.
67073diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
67074index 399162b..b337f1a 100644
67075--- a/include/scsi/libfc.h
67076+++ b/include/scsi/libfc.h
67077@@ -762,6 +762,7 @@ struct libfc_function_template {
67078 */
67079 void (*disc_stop_final) (struct fc_lport *);
67080 };
67081+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
67082
67083 /**
67084 * struct fc_disc - Discovery context
67085@@ -866,7 +867,7 @@ struct fc_lport {
67086 struct fc_vport *vport;
67087
67088 /* Operational Information */
67089- struct libfc_function_template tt;
67090+ libfc_function_template_no_const tt;
67091 u8 link_up;
67092 u8 qfull;
67093 enum fc_lport_state state;
67094diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
67095index 55367b0..d97bd2a 100644
67096--- a/include/scsi/scsi_device.h
67097+++ b/include/scsi/scsi_device.h
67098@@ -169,9 +169,9 @@ struct scsi_device {
67099 unsigned int max_device_blocked; /* what device_blocked counts down from */
67100 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
67101
67102- atomic_t iorequest_cnt;
67103- atomic_t iodone_cnt;
67104- atomic_t ioerr_cnt;
67105+ atomic_unchecked_t iorequest_cnt;
67106+ atomic_unchecked_t iodone_cnt;
67107+ atomic_unchecked_t ioerr_cnt;
67108
67109 struct device sdev_gendev,
67110 sdev_dev;
67111diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
67112index b797e8f..8e2c3aa 100644
67113--- a/include/scsi/scsi_transport_fc.h
67114+++ b/include/scsi/scsi_transport_fc.h
67115@@ -751,7 +751,8 @@ struct fc_function_template {
67116 unsigned long show_host_system_hostname:1;
67117
67118 unsigned long disable_target_scan:1;
67119-};
67120+} __do_const;
67121+typedef struct fc_function_template __no_const fc_function_template_no_const;
67122
67123
67124 /**
67125diff --git a/include/sound/soc.h b/include/sound/soc.h
67126index 91244a0..89ca1a7 100644
67127--- a/include/sound/soc.h
67128+++ b/include/sound/soc.h
67129@@ -769,7 +769,7 @@ struct snd_soc_codec_driver {
67130 /* probe ordering - for components with runtime dependencies */
67131 int probe_order;
67132 int remove_order;
67133-};
67134+} __do_const;
67135
67136 /* SoC platform interface */
67137 struct snd_soc_platform_driver {
67138@@ -815,7 +815,7 @@ struct snd_soc_platform_driver {
67139 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
67140 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
67141 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
67142-};
67143+} __do_const;
67144
67145 struct snd_soc_platform {
67146 const char *name;
67147diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
67148index fca8bbe..c0242ea 100644
67149--- a/include/target/target_core_base.h
67150+++ b/include/target/target_core_base.h
67151@@ -760,7 +760,7 @@ struct se_device {
67152 spinlock_t stats_lock;
67153 /* Active commands on this virtual SE device */
67154 atomic_t simple_cmds;
67155- atomic_t dev_ordered_id;
67156+ atomic_unchecked_t dev_ordered_id;
67157 atomic_t dev_ordered_sync;
67158 atomic_t dev_qf_count;
67159 struct se_obj dev_obj;
67160diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
67161new file mode 100644
67162index 0000000..fb634b7
67163--- /dev/null
67164+++ b/include/trace/events/fs.h
67165@@ -0,0 +1,53 @@
67166+#undef TRACE_SYSTEM
67167+#define TRACE_SYSTEM fs
67168+
67169+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
67170+#define _TRACE_FS_H
67171+
67172+#include <linux/fs.h>
67173+#include <linux/tracepoint.h>
67174+
67175+TRACE_EVENT(do_sys_open,
67176+
67177+ TP_PROTO(const char *filename, int flags, int mode),
67178+
67179+ TP_ARGS(filename, flags, mode),
67180+
67181+ TP_STRUCT__entry(
67182+ __string( filename, filename )
67183+ __field( int, flags )
67184+ __field( int, mode )
67185+ ),
67186+
67187+ TP_fast_assign(
67188+ __assign_str(filename, filename);
67189+ __entry->flags = flags;
67190+ __entry->mode = mode;
67191+ ),
67192+
67193+ TP_printk("\"%s\" %x %o",
67194+ __get_str(filename), __entry->flags, __entry->mode)
67195+);
67196+
67197+TRACE_EVENT(open_exec,
67198+
67199+ TP_PROTO(const char *filename),
67200+
67201+ TP_ARGS(filename),
67202+
67203+ TP_STRUCT__entry(
67204+ __string( filename, filename )
67205+ ),
67206+
67207+ TP_fast_assign(
67208+ __assign_str(filename, filename);
67209+ ),
67210+
67211+ TP_printk("\"%s\"",
67212+ __get_str(filename))
67213+);
67214+
67215+#endif /* _TRACE_FS_H */
67216+
67217+/* This part must be outside protection */
67218+#include <trace/define_trace.h>
67219diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
67220index 1c09820..7f5ec79 100644
67221--- a/include/trace/events/irq.h
67222+++ b/include/trace/events/irq.h
67223@@ -36,7 +36,7 @@ struct softirq_action;
67224 */
67225 TRACE_EVENT(irq_handler_entry,
67226
67227- TP_PROTO(int irq, struct irqaction *action),
67228+ TP_PROTO(int irq, const struct irqaction *action),
67229
67230 TP_ARGS(irq, action),
67231
67232@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
67233 */
67234 TRACE_EVENT(irq_handler_exit,
67235
67236- TP_PROTO(int irq, struct irqaction *action, int ret),
67237+ TP_PROTO(int irq, const struct irqaction *action, int ret),
67238
67239 TP_ARGS(irq, action, ret),
67240
67241diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
67242index 7caf44c..23c6f27 100644
67243--- a/include/uapi/linux/a.out.h
67244+++ b/include/uapi/linux/a.out.h
67245@@ -39,6 +39,14 @@ enum machine_type {
67246 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
67247 };
67248
67249+/* Constants for the N_FLAGS field */
67250+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67251+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
67252+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
67253+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
67254+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67255+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67256+
67257 #if !defined (N_MAGIC)
67258 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
67259 #endif
67260diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
67261index d876736..b36014e 100644
67262--- a/include/uapi/linux/byteorder/little_endian.h
67263+++ b/include/uapi/linux/byteorder/little_endian.h
67264@@ -42,51 +42,51 @@
67265
67266 static inline __le64 __cpu_to_le64p(const __u64 *p)
67267 {
67268- return (__force __le64)*p;
67269+ return (__force const __le64)*p;
67270 }
67271 static inline __u64 __le64_to_cpup(const __le64 *p)
67272 {
67273- return (__force __u64)*p;
67274+ return (__force const __u64)*p;
67275 }
67276 static inline __le32 __cpu_to_le32p(const __u32 *p)
67277 {
67278- return (__force __le32)*p;
67279+ return (__force const __le32)*p;
67280 }
67281 static inline __u32 __le32_to_cpup(const __le32 *p)
67282 {
67283- return (__force __u32)*p;
67284+ return (__force const __u32)*p;
67285 }
67286 static inline __le16 __cpu_to_le16p(const __u16 *p)
67287 {
67288- return (__force __le16)*p;
67289+ return (__force const __le16)*p;
67290 }
67291 static inline __u16 __le16_to_cpup(const __le16 *p)
67292 {
67293- return (__force __u16)*p;
67294+ return (__force const __u16)*p;
67295 }
67296 static inline __be64 __cpu_to_be64p(const __u64 *p)
67297 {
67298- return (__force __be64)__swab64p(p);
67299+ return (__force const __be64)__swab64p(p);
67300 }
67301 static inline __u64 __be64_to_cpup(const __be64 *p)
67302 {
67303- return __swab64p((__u64 *)p);
67304+ return __swab64p((const __u64 *)p);
67305 }
67306 static inline __be32 __cpu_to_be32p(const __u32 *p)
67307 {
67308- return (__force __be32)__swab32p(p);
67309+ return (__force const __be32)__swab32p(p);
67310 }
67311 static inline __u32 __be32_to_cpup(const __be32 *p)
67312 {
67313- return __swab32p((__u32 *)p);
67314+ return __swab32p((const __u32 *)p);
67315 }
67316 static inline __be16 __cpu_to_be16p(const __u16 *p)
67317 {
67318- return (__force __be16)__swab16p(p);
67319+ return (__force const __be16)__swab16p(p);
67320 }
67321 static inline __u16 __be16_to_cpup(const __be16 *p)
67322 {
67323- return __swab16p((__u16 *)p);
67324+ return __swab16p((const __u16 *)p);
67325 }
67326 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
67327 #define __le64_to_cpus(x) do { (void)(x); } while (0)
67328diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
67329index 126a817..d522bd1 100644
67330--- a/include/uapi/linux/elf.h
67331+++ b/include/uapi/linux/elf.h
67332@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
67333 #define PT_GNU_EH_FRAME 0x6474e550
67334
67335 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
67336+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
67337+
67338+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
67339+
67340+/* Constants for the e_flags field */
67341+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
67342+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
67343+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
67344+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
67345+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
67346+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
67347
67348 /*
67349 * Extended Numbering
67350@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
67351 #define DT_DEBUG 21
67352 #define DT_TEXTREL 22
67353 #define DT_JMPREL 23
67354+#define DT_FLAGS 30
67355+ #define DF_TEXTREL 0x00000004
67356 #define DT_ENCODING 32
67357 #define OLD_DT_LOOS 0x60000000
67358 #define DT_LOOS 0x6000000d
67359@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
67360 #define PF_W 0x2
67361 #define PF_X 0x1
67362
67363+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
67364+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
67365+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
67366+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
67367+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
67368+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
67369+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
67370+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
67371+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
67372+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
67373+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
67374+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
67375+
67376 typedef struct elf32_phdr{
67377 Elf32_Word p_type;
67378 Elf32_Off p_offset;
67379@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
67380 #define EI_OSABI 7
67381 #define EI_PAD 8
67382
67383+#define EI_PAX 14
67384+
67385 #define ELFMAG0 0x7f /* EI_MAG */
67386 #define ELFMAG1 'E'
67387 #define ELFMAG2 'L'
67388diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
67389index aa169c4..6a2771d 100644
67390--- a/include/uapi/linux/personality.h
67391+++ b/include/uapi/linux/personality.h
67392@@ -30,6 +30,7 @@ enum {
67393 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
67394 ADDR_NO_RANDOMIZE | \
67395 ADDR_COMPAT_LAYOUT | \
67396+ ADDR_LIMIT_3GB | \
67397 MMAP_PAGE_ZERO)
67398
67399 /*
67400diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
67401index 7530e74..e714828 100644
67402--- a/include/uapi/linux/screen_info.h
67403+++ b/include/uapi/linux/screen_info.h
67404@@ -43,7 +43,8 @@ struct screen_info {
67405 __u16 pages; /* 0x32 */
67406 __u16 vesa_attributes; /* 0x34 */
67407 __u32 capabilities; /* 0x36 */
67408- __u8 _reserved[6]; /* 0x3a */
67409+ __u16 vesapm_size; /* 0x3a */
67410+ __u8 _reserved[4]; /* 0x3c */
67411 } __attribute__((packed));
67412
67413 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
67414diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
67415index 6d67213..8dab561 100644
67416--- a/include/uapi/linux/sysctl.h
67417+++ b/include/uapi/linux/sysctl.h
67418@@ -155,7 +155,11 @@ enum
67419 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
67420 };
67421
67422-
67423+#ifdef CONFIG_PAX_SOFTMODE
67424+enum {
67425+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
67426+};
67427+#endif
67428
67429 /* CTL_VM names: */
67430 enum
67431diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
67432index 26607bd..588b65f 100644
67433--- a/include/uapi/linux/xattr.h
67434+++ b/include/uapi/linux/xattr.h
67435@@ -60,5 +60,9 @@
67436 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
67437 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
67438
67439+/* User namespace */
67440+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
67441+#define XATTR_PAX_FLAGS_SUFFIX "flags"
67442+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
67443
67444 #endif /* _UAPI_LINUX_XATTR_H */
67445diff --git a/include/video/omapdss.h b/include/video/omapdss.h
67446index 3729173..7b2df7e 100644
67447--- a/include/video/omapdss.h
67448+++ b/include/video/omapdss.h
67449@@ -323,7 +323,7 @@ struct omap_dss_board_info {
67450 int (*dsi_enable_pads)(int dsi_id, unsigned lane_mask);
67451 void (*dsi_disable_pads)(int dsi_id, unsigned lane_mask);
67452 int (*set_min_bus_tput)(struct device *dev, unsigned long r);
67453-};
67454+} __do_const;
67455
67456 /* Init with the board info */
67457 extern int omap_display_init(struct omap_dss_board_info *board_data);
67458diff --git a/include/video/udlfb.h b/include/video/udlfb.h
67459index f9466fa..f4e2b81 100644
67460--- a/include/video/udlfb.h
67461+++ b/include/video/udlfb.h
67462@@ -53,10 +53,10 @@ struct dlfb_data {
67463 u32 pseudo_palette[256];
67464 int blank_mode; /*one of FB_BLANK_ */
67465 /* blit-only rendering path metrics, exposed through sysfs */
67466- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67467- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
67468- atomic_t bytes_sent; /* to usb, after compression including overhead */
67469- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
67470+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
67471+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
67472+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
67473+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
67474 };
67475
67476 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
67477diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
67478index 0993a22..32ba2fe 100644
67479--- a/include/video/uvesafb.h
67480+++ b/include/video/uvesafb.h
67481@@ -177,6 +177,7 @@ struct uvesafb_par {
67482 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
67483 u8 pmi_setpal; /* PMI for palette changes */
67484 u16 *pmi_base; /* protected mode interface location */
67485+ u8 *pmi_code; /* protected mode code location */
67486 void *pmi_start;
67487 void *pmi_pal;
67488 u8 *vbe_state_orig; /*
67489diff --git a/init/Kconfig b/init/Kconfig
67490index 6fdd6e3..5b01610 100644
67491--- a/init/Kconfig
67492+++ b/init/Kconfig
67493@@ -925,6 +925,7 @@ endif # CGROUPS
67494
67495 config CHECKPOINT_RESTORE
67496 bool "Checkpoint/restore support" if EXPERT
67497+ depends on !GRKERNSEC
67498 default n
67499 help
67500 Enables additional kernel features in a sake of checkpoint/restore.
67501@@ -1016,6 +1017,8 @@ config UIDGID_CONVERTED
67502 depends on OCFS2_FS = n
67503 depends on XFS_FS = n
67504
67505+ depends on GRKERNSEC = n
67506+
67507 config UIDGID_STRICT_TYPE_CHECKS
67508 bool "Require conversions between uid/gids and their internal representation"
67509 depends on UIDGID_CONVERTED
67510@@ -1405,7 +1408,7 @@ config SLUB_DEBUG
67511
67512 config COMPAT_BRK
67513 bool "Disable heap randomization"
67514- default y
67515+ default n
67516 help
67517 Randomizing heap placement makes heap exploits harder, but it
67518 also breaks ancient binaries (including anything libc5 based).
67519@@ -1648,7 +1651,7 @@ config INIT_ALL_POSSIBLE
67520 config STOP_MACHINE
67521 bool
67522 default y
67523- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
67524+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
67525 help
67526 Need stop_machine() primitive.
67527
67528diff --git a/init/Makefile b/init/Makefile
67529index 7bc47ee..6da2dc7 100644
67530--- a/init/Makefile
67531+++ b/init/Makefile
67532@@ -2,6 +2,9 @@
67533 # Makefile for the linux kernel.
67534 #
67535
67536+ccflags-y := $(GCC_PLUGINS_CFLAGS)
67537+asflags-y := $(GCC_PLUGINS_AFLAGS)
67538+
67539 obj-y := main.o version.o mounts.o
67540 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
67541 obj-y += noinitramfs.o
67542diff --git a/init/do_mounts.c b/init/do_mounts.c
67543index f8a6642..4e5ee1b 100644
67544--- a/init/do_mounts.c
67545+++ b/init/do_mounts.c
67546@@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
67547 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
67548 {
67549 struct super_block *s;
67550- int err = sys_mount(name, "/root", fs, flags, data);
67551+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
67552 if (err)
67553 return err;
67554
67555- sys_chdir("/root");
67556+ sys_chdir((const char __force_user *)"/root");
67557 s = current->fs->pwd.dentry->d_sb;
67558 ROOT_DEV = s->s_dev;
67559 printk(KERN_INFO
67560@@ -461,18 +461,18 @@ void __init change_floppy(char *fmt, ...)
67561 va_start(args, fmt);
67562 vsprintf(buf, fmt, args);
67563 va_end(args);
67564- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
67565+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
67566 if (fd >= 0) {
67567 sys_ioctl(fd, FDEJECT, 0);
67568 sys_close(fd);
67569 }
67570 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
67571- fd = sys_open("/dev/console", O_RDWR, 0);
67572+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
67573 if (fd >= 0) {
67574 sys_ioctl(fd, TCGETS, (long)&termios);
67575 termios.c_lflag &= ~ICANON;
67576 sys_ioctl(fd, TCSETSF, (long)&termios);
67577- sys_read(fd, &c, 1);
67578+ sys_read(fd, (char __user *)&c, 1);
67579 termios.c_lflag |= ICANON;
67580 sys_ioctl(fd, TCSETSF, (long)&termios);
67581 sys_close(fd);
67582@@ -566,6 +566,6 @@ void __init prepare_namespace(void)
67583 mount_root();
67584 out:
67585 devtmpfs_mount("dev");
67586- sys_mount(".", "/", NULL, MS_MOVE, NULL);
67587- sys_chroot(".");
67588+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
67589+ sys_chroot((const char __force_user *)".");
67590 }
67591diff --git a/init/do_mounts.h b/init/do_mounts.h
67592index f5b978a..69dbfe8 100644
67593--- a/init/do_mounts.h
67594+++ b/init/do_mounts.h
67595@@ -15,15 +15,15 @@ extern int root_mountflags;
67596
67597 static inline int create_dev(char *name, dev_t dev)
67598 {
67599- sys_unlink(name);
67600- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
67601+ sys_unlink((char __force_user *)name);
67602+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
67603 }
67604
67605 #if BITS_PER_LONG == 32
67606 static inline u32 bstat(char *name)
67607 {
67608 struct stat64 stat;
67609- if (sys_stat64(name, &stat) != 0)
67610+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
67611 return 0;
67612 if (!S_ISBLK(stat.st_mode))
67613 return 0;
67614@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
67615 static inline u32 bstat(char *name)
67616 {
67617 struct stat stat;
67618- if (sys_newstat(name, &stat) != 0)
67619+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
67620 return 0;
67621 if (!S_ISBLK(stat.st_mode))
67622 return 0;
67623diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
67624index f9acf71..1e19144 100644
67625--- a/init/do_mounts_initrd.c
67626+++ b/init/do_mounts_initrd.c
67627@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
67628 create_dev("/dev/root.old", Root_RAM0);
67629 /* mount initrd on rootfs' /root */
67630 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
67631- sys_mkdir("/old", 0700);
67632- sys_chdir("/old");
67633+ sys_mkdir((const char __force_user *)"/old", 0700);
67634+ sys_chdir((const char __force_user *)"/old");
67635
67636 /*
67637 * In case that a resume from disk is carried out by linuxrc or one of
67638@@ -73,31 +73,31 @@ static void __init handle_initrd(void)
67639 current->flags &= ~PF_FREEZER_SKIP;
67640
67641 /* move initrd to rootfs' /old */
67642- sys_mount("..", ".", NULL, MS_MOVE, NULL);
67643+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
67644 /* switch root and cwd back to / of rootfs */
67645- sys_chroot("..");
67646+ sys_chroot((const char __force_user *)"..");
67647
67648 if (new_decode_dev(real_root_dev) == Root_RAM0) {
67649- sys_chdir("/old");
67650+ sys_chdir((const char __force_user *)"/old");
67651 return;
67652 }
67653
67654- sys_chdir("/");
67655+ sys_chdir((const char __force_user *)"/");
67656 ROOT_DEV = new_decode_dev(real_root_dev);
67657 mount_root();
67658
67659 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
67660- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
67661+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
67662 if (!error)
67663 printk("okay\n");
67664 else {
67665- int fd = sys_open("/dev/root.old", O_RDWR, 0);
67666+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
67667 if (error == -ENOENT)
67668 printk("/initrd does not exist. Ignored.\n");
67669 else
67670 printk("failed\n");
67671 printk(KERN_NOTICE "Unmounting old root\n");
67672- sys_umount("/old", MNT_DETACH);
67673+ sys_umount((char __force_user *)"/old", MNT_DETACH);
67674 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
67675 if (fd < 0) {
67676 error = fd;
67677@@ -120,11 +120,11 @@ int __init initrd_load(void)
67678 * mounted in the normal path.
67679 */
67680 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
67681- sys_unlink("/initrd.image");
67682+ sys_unlink((const char __force_user *)"/initrd.image");
67683 handle_initrd();
67684 return 1;
67685 }
67686 }
67687- sys_unlink("/initrd.image");
67688+ sys_unlink((const char __force_user *)"/initrd.image");
67689 return 0;
67690 }
67691diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
67692index 8cb6db5..d729f50 100644
67693--- a/init/do_mounts_md.c
67694+++ b/init/do_mounts_md.c
67695@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
67696 partitioned ? "_d" : "", minor,
67697 md_setup_args[ent].device_names);
67698
67699- fd = sys_open(name, 0, 0);
67700+ fd = sys_open((char __force_user *)name, 0, 0);
67701 if (fd < 0) {
67702 printk(KERN_ERR "md: open failed - cannot start "
67703 "array %s\n", name);
67704@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
67705 * array without it
67706 */
67707 sys_close(fd);
67708- fd = sys_open(name, 0, 0);
67709+ fd = sys_open((char __force_user *)name, 0, 0);
67710 sys_ioctl(fd, BLKRRPART, 0);
67711 }
67712 sys_close(fd);
67713@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
67714
67715 wait_for_device_probe();
67716
67717- fd = sys_open("/dev/md0", 0, 0);
67718+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
67719 if (fd >= 0) {
67720 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
67721 sys_close(fd);
67722diff --git a/init/init_task.c b/init/init_task.c
67723index 8b2f399..f0797c9 100644
67724--- a/init/init_task.c
67725+++ b/init/init_task.c
67726@@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
67727 * Initial thread structure. Alignment of this is handled by a special
67728 * linker map entry.
67729 */
67730+#ifdef CONFIG_X86
67731+union thread_union init_thread_union __init_task_data;
67732+#else
67733 union thread_union init_thread_union __init_task_data =
67734 { INIT_THREAD_INFO(init_task) };
67735+#endif
67736diff --git a/init/initramfs.c b/init/initramfs.c
67737index 84c6bf1..8899338 100644
67738--- a/init/initramfs.c
67739+++ b/init/initramfs.c
67740@@ -84,7 +84,7 @@ static void __init free_hash(void)
67741 }
67742 }
67743
67744-static long __init do_utime(char *filename, time_t mtime)
67745+static long __init do_utime(char __force_user *filename, time_t mtime)
67746 {
67747 struct timespec t[2];
67748
67749@@ -119,7 +119,7 @@ static void __init dir_utime(void)
67750 struct dir_entry *de, *tmp;
67751 list_for_each_entry_safe(de, tmp, &dir_list, list) {
67752 list_del(&de->list);
67753- do_utime(de->name, de->mtime);
67754+ do_utime((char __force_user *)de->name, de->mtime);
67755 kfree(de->name);
67756 kfree(de);
67757 }
67758@@ -281,7 +281,7 @@ static int __init maybe_link(void)
67759 if (nlink >= 2) {
67760 char *old = find_link(major, minor, ino, mode, collected);
67761 if (old)
67762- return (sys_link(old, collected) < 0) ? -1 : 1;
67763+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
67764 }
67765 return 0;
67766 }
67767@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
67768 {
67769 struct stat st;
67770
67771- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
67772+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
67773 if (S_ISDIR(st.st_mode))
67774- sys_rmdir(path);
67775+ sys_rmdir((char __force_user *)path);
67776 else
67777- sys_unlink(path);
67778+ sys_unlink((char __force_user *)path);
67779 }
67780 }
67781
67782@@ -315,7 +315,7 @@ static int __init do_name(void)
67783 int openflags = O_WRONLY|O_CREAT;
67784 if (ml != 1)
67785 openflags |= O_TRUNC;
67786- wfd = sys_open(collected, openflags, mode);
67787+ wfd = sys_open((char __force_user *)collected, openflags, mode);
67788
67789 if (wfd >= 0) {
67790 sys_fchown(wfd, uid, gid);
67791@@ -327,17 +327,17 @@ static int __init do_name(void)
67792 }
67793 }
67794 } else if (S_ISDIR(mode)) {
67795- sys_mkdir(collected, mode);
67796- sys_chown(collected, uid, gid);
67797- sys_chmod(collected, mode);
67798+ sys_mkdir((char __force_user *)collected, mode);
67799+ sys_chown((char __force_user *)collected, uid, gid);
67800+ sys_chmod((char __force_user *)collected, mode);
67801 dir_add(collected, mtime);
67802 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
67803 S_ISFIFO(mode) || S_ISSOCK(mode)) {
67804 if (maybe_link() == 0) {
67805- sys_mknod(collected, mode, rdev);
67806- sys_chown(collected, uid, gid);
67807- sys_chmod(collected, mode);
67808- do_utime(collected, mtime);
67809+ sys_mknod((char __force_user *)collected, mode, rdev);
67810+ sys_chown((char __force_user *)collected, uid, gid);
67811+ sys_chmod((char __force_user *)collected, mode);
67812+ do_utime((char __force_user *)collected, mtime);
67813 }
67814 }
67815 return 0;
67816@@ -346,15 +346,15 @@ static int __init do_name(void)
67817 static int __init do_copy(void)
67818 {
67819 if (count >= body_len) {
67820- sys_write(wfd, victim, body_len);
67821+ sys_write(wfd, (char __force_user *)victim, body_len);
67822 sys_close(wfd);
67823- do_utime(vcollected, mtime);
67824+ do_utime((char __force_user *)vcollected, mtime);
67825 kfree(vcollected);
67826 eat(body_len);
67827 state = SkipIt;
67828 return 0;
67829 } else {
67830- sys_write(wfd, victim, count);
67831+ sys_write(wfd, (char __force_user *)victim, count);
67832 body_len -= count;
67833 eat(count);
67834 return 1;
67835@@ -365,9 +365,9 @@ static int __init do_symlink(void)
67836 {
67837 collected[N_ALIGN(name_len) + body_len] = '\0';
67838 clean_path(collected, 0);
67839- sys_symlink(collected + N_ALIGN(name_len), collected);
67840- sys_lchown(collected, uid, gid);
67841- do_utime(collected, mtime);
67842+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
67843+ sys_lchown((char __force_user *)collected, uid, gid);
67844+ do_utime((char __force_user *)collected, mtime);
67845 state = SkipIt;
67846 next_state = Reset;
67847 return 0;
67848diff --git a/init/main.c b/init/main.c
67849index cd147a9..12ce8c2 100644
67850--- a/init/main.c
67851+++ b/init/main.c
67852@@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
67853 extern void tc_init(void);
67854 #endif
67855
67856+extern void grsecurity_init(void);
67857+
67858 /*
67859 * Debug helper: via this flag we know that we are in 'early bootup code'
67860 * where only the boot processor is running with IRQ disabled. This means
67861@@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
67862
67863 __setup("reset_devices", set_reset_devices);
67864
67865+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67866+int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
67867+static int __init setup_grsec_proc_gid(char *str)
67868+{
67869+ grsec_proc_gid = (int)simple_strtol(str, NULL, 0);
67870+ return 1;
67871+}
67872+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
67873+#endif
67874+
67875+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
67876+extern char pax_enter_kernel_user[];
67877+extern char pax_exit_kernel_user[];
67878+extern pgdval_t clone_pgd_mask;
67879+#endif
67880+
67881+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
67882+static int __init setup_pax_nouderef(char *str)
67883+{
67884+#ifdef CONFIG_X86_32
67885+ unsigned int cpu;
67886+ struct desc_struct *gdt;
67887+
67888+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
67889+ gdt = get_cpu_gdt_table(cpu);
67890+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
67891+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
67892+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
67893+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
67894+ }
67895+ loadsegment(ds, __KERNEL_DS);
67896+ loadsegment(es, __KERNEL_DS);
67897+ loadsegment(ss, __KERNEL_DS);
67898+#else
67899+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
67900+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
67901+ clone_pgd_mask = ~(pgdval_t)0UL;
67902+#endif
67903+
67904+ return 0;
67905+}
67906+early_param("pax_nouderef", setup_pax_nouderef);
67907+#endif
67908+
67909+#ifdef CONFIG_PAX_SOFTMODE
67910+int pax_softmode;
67911+
67912+static int __init setup_pax_softmode(char *str)
67913+{
67914+ get_option(&str, &pax_softmode);
67915+ return 1;
67916+}
67917+__setup("pax_softmode=", setup_pax_softmode);
67918+#endif
67919+
67920 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
67921 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
67922 static const char *panic_later, *panic_param;
67923@@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
67924 {
67925 int count = preempt_count();
67926 int ret;
67927+ const char *msg1 = "", *msg2 = "";
67928
67929 if (initcall_debug)
67930 ret = do_one_initcall_debug(fn);
67931@@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
67932 sprintf(msgbuf, "error code %d ", ret);
67933
67934 if (preempt_count() != count) {
67935- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
67936+ msg1 = " preemption imbalance";
67937 preempt_count() = count;
67938 }
67939 if (irqs_disabled()) {
67940- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
67941+ msg2 = " disabled interrupts";
67942 local_irq_enable();
67943 }
67944- if (msgbuf[0]) {
67945- printk("initcall %pF returned with %s\n", fn, msgbuf);
67946+ if (msgbuf[0] || *msg1 || *msg2) {
67947+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
67948 }
67949
67950 return ret;
67951@@ -743,6 +801,10 @@ static char *initcall_level_names[] __initdata = {
67952 "late",
67953 };
67954
67955+#ifdef CONFIG_PAX_LATENT_ENTROPY
67956+u64 latent_entropy;
67957+#endif
67958+
67959 static void __init do_initcall_level(int level)
67960 {
67961 extern const struct kernel_param __start___param[], __stop___param[];
67962@@ -755,8 +817,14 @@ static void __init do_initcall_level(int level)
67963 level, level,
67964 &repair_env_string);
67965
67966- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
67967+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
67968 do_one_initcall(*fn);
67969+
67970+#ifdef CONFIG_PAX_LATENT_ENTROPY
67971+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67972+#endif
67973+
67974+ }
67975 }
67976
67977 static void __init do_initcalls(void)
67978@@ -790,8 +858,14 @@ static void __init do_pre_smp_initcalls(void)
67979 {
67980 initcall_t *fn;
67981
67982- for (fn = __initcall_start; fn < __initcall0_start; fn++)
67983+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
67984 do_one_initcall(*fn);
67985+
67986+#ifdef CONFIG_PAX_LATENT_ENTROPY
67987+ add_device_randomness(&latent_entropy, sizeof(latent_entropy));
67988+#endif
67989+
67990+ }
67991 }
67992
67993 static int run_init_process(const char *init_filename)
67994@@ -876,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
67995 do_basic_setup();
67996
67997 /* Open the /dev/console on the rootfs, this should never fail */
67998- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
67999+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
68000 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
68001
68002 (void) sys_dup(0);
68003@@ -889,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
68004 if (!ramdisk_execute_command)
68005 ramdisk_execute_command = "/init";
68006
68007- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
68008+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
68009 ramdisk_execute_command = NULL;
68010 prepare_namespace();
68011 }
68012
68013+ grsecurity_init();
68014+
68015 /*
68016 * Ok, we have completed the initial bootup, and
68017 * we're essentially up and running. Get rid of the
68018diff --git a/ipc/mqueue.c b/ipc/mqueue.c
68019index 71a3ca1..cc330ee 100644
68020--- a/ipc/mqueue.c
68021+++ b/ipc/mqueue.c
68022@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
68023 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
68024 info->attr.mq_msgsize);
68025
68026+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
68027 spin_lock(&mq_lock);
68028 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
68029 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
68030diff --git a/ipc/msg.c b/ipc/msg.c
68031index a71af5a..a90a110 100644
68032--- a/ipc/msg.c
68033+++ b/ipc/msg.c
68034@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
68035 return security_msg_queue_associate(msq, msgflg);
68036 }
68037
68038+static struct ipc_ops msg_ops = {
68039+ .getnew = newque,
68040+ .associate = msg_security,
68041+ .more_checks = NULL
68042+};
68043+
68044 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
68045 {
68046 struct ipc_namespace *ns;
68047- struct ipc_ops msg_ops;
68048 struct ipc_params msg_params;
68049
68050 ns = current->nsproxy->ipc_ns;
68051
68052- msg_ops.getnew = newque;
68053- msg_ops.associate = msg_security;
68054- msg_ops.more_checks = NULL;
68055-
68056 msg_params.key = key;
68057 msg_params.flg = msgflg;
68058
68059diff --git a/ipc/sem.c b/ipc/sem.c
68060index 58d31f1..cce7a55 100644
68061--- a/ipc/sem.c
68062+++ b/ipc/sem.c
68063@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
68064 return 0;
68065 }
68066
68067+static struct ipc_ops sem_ops = {
68068+ .getnew = newary,
68069+ .associate = sem_security,
68070+ .more_checks = sem_more_checks
68071+};
68072+
68073 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68074 {
68075 struct ipc_namespace *ns;
68076- struct ipc_ops sem_ops;
68077 struct ipc_params sem_params;
68078
68079 ns = current->nsproxy->ipc_ns;
68080@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
68081 if (nsems < 0 || nsems > ns->sc_semmsl)
68082 return -EINVAL;
68083
68084- sem_ops.getnew = newary;
68085- sem_ops.associate = sem_security;
68086- sem_ops.more_checks = sem_more_checks;
68087-
68088 sem_params.key = key;
68089 sem_params.flg = semflg;
68090 sem_params.u.nsems = nsems;
68091diff --git a/ipc/shm.c b/ipc/shm.c
68092index dff40c9..9450e27 100644
68093--- a/ipc/shm.c
68094+++ b/ipc/shm.c
68095@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
68096 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
68097 #endif
68098
68099+#ifdef CONFIG_GRKERNSEC
68100+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68101+ const time_t shm_createtime, const uid_t cuid,
68102+ const int shmid);
68103+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68104+ const time_t shm_createtime);
68105+#endif
68106+
68107 void shm_init_ns(struct ipc_namespace *ns)
68108 {
68109 ns->shm_ctlmax = SHMMAX;
68110@@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
68111 shp->shm_lprid = 0;
68112 shp->shm_atim = shp->shm_dtim = 0;
68113 shp->shm_ctim = get_seconds();
68114+#ifdef CONFIG_GRKERNSEC
68115+ {
68116+ struct timespec timeval;
68117+ do_posix_clock_monotonic_gettime(&timeval);
68118+
68119+ shp->shm_createtime = timeval.tv_sec;
68120+ }
68121+#endif
68122 shp->shm_segsz = size;
68123 shp->shm_nattch = 0;
68124 shp->shm_file = file;
68125@@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
68126 return 0;
68127 }
68128
68129+static struct ipc_ops shm_ops = {
68130+ .getnew = newseg,
68131+ .associate = shm_security,
68132+ .more_checks = shm_more_checks
68133+};
68134+
68135 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
68136 {
68137 struct ipc_namespace *ns;
68138- struct ipc_ops shm_ops;
68139 struct ipc_params shm_params;
68140
68141 ns = current->nsproxy->ipc_ns;
68142
68143- shm_ops.getnew = newseg;
68144- shm_ops.associate = shm_security;
68145- shm_ops.more_checks = shm_more_checks;
68146-
68147 shm_params.key = key;
68148 shm_params.flg = shmflg;
68149 shm_params.u.size = size;
68150@@ -1003,6 +1020,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68151 f_mode = FMODE_READ | FMODE_WRITE;
68152 }
68153 if (shmflg & SHM_EXEC) {
68154+
68155+#ifdef CONFIG_PAX_MPROTECT
68156+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
68157+ goto out;
68158+#endif
68159+
68160 prot |= PROT_EXEC;
68161 acc_mode |= S_IXUGO;
68162 }
68163@@ -1026,9 +1049,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
68164 if (err)
68165 goto out_unlock;
68166
68167+#ifdef CONFIG_GRKERNSEC
68168+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
68169+ shp->shm_perm.cuid, shmid) ||
68170+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
68171+ err = -EACCES;
68172+ goto out_unlock;
68173+ }
68174+#endif
68175+
68176 path = shp->shm_file->f_path;
68177 path_get(&path);
68178 shp->shm_nattch++;
68179+#ifdef CONFIG_GRKERNSEC
68180+ shp->shm_lapid = current->pid;
68181+#endif
68182 size = i_size_read(path.dentry->d_inode);
68183 shm_unlock(shp);
68184
68185diff --git a/kernel/acct.c b/kernel/acct.c
68186index 051e071..15e0920 100644
68187--- a/kernel/acct.c
68188+++ b/kernel/acct.c
68189@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
68190 */
68191 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
68192 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
68193- file->f_op->write(file, (char *)&ac,
68194+ file->f_op->write(file, (char __force_user *)&ac,
68195 sizeof(acct_t), &file->f_pos);
68196 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
68197 set_fs(fs);
68198diff --git a/kernel/audit.c b/kernel/audit.c
68199index 40414e9..c920b72 100644
68200--- a/kernel/audit.c
68201+++ b/kernel/audit.c
68202@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
68203 3) suppressed due to audit_rate_limit
68204 4) suppressed due to audit_backlog_limit
68205 */
68206-static atomic_t audit_lost = ATOMIC_INIT(0);
68207+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
68208
68209 /* The netlink socket. */
68210 static struct sock *audit_sock;
68211@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
68212 unsigned long now;
68213 int print;
68214
68215- atomic_inc(&audit_lost);
68216+ atomic_inc_unchecked(&audit_lost);
68217
68218 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
68219
68220@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
68221 printk(KERN_WARNING
68222 "audit: audit_lost=%d audit_rate_limit=%d "
68223 "audit_backlog_limit=%d\n",
68224- atomic_read(&audit_lost),
68225+ atomic_read_unchecked(&audit_lost),
68226 audit_rate_limit,
68227 audit_backlog_limit);
68228 audit_panic(message);
68229@@ -677,7 +677,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
68230 status_set.pid = audit_pid;
68231 status_set.rate_limit = audit_rate_limit;
68232 status_set.backlog_limit = audit_backlog_limit;
68233- status_set.lost = atomic_read(&audit_lost);
68234+ status_set.lost = atomic_read_unchecked(&audit_lost);
68235 status_set.backlog = skb_queue_len(&audit_skb_queue);
68236 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
68237 &status_set, sizeof(status_set));
68238diff --git a/kernel/auditsc.c b/kernel/auditsc.c
68239index 157e989..b28b365 100644
68240--- a/kernel/auditsc.c
68241+++ b/kernel/auditsc.c
68242@@ -2352,7 +2352,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
68243 }
68244
68245 /* global counter which is incremented every time something logs in */
68246-static atomic_t session_id = ATOMIC_INIT(0);
68247+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
68248
68249 /**
68250 * audit_set_loginuid - set current task's audit_context loginuid
68251@@ -2376,7 +2376,7 @@ int audit_set_loginuid(kuid_t loginuid)
68252 return -EPERM;
68253 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
68254
68255- sessionid = atomic_inc_return(&session_id);
68256+ sessionid = atomic_inc_return_unchecked(&session_id);
68257 if (context && context->in_syscall) {
68258 struct audit_buffer *ab;
68259
68260diff --git a/kernel/capability.c b/kernel/capability.c
68261index 493d972..ea17248 100644
68262--- a/kernel/capability.c
68263+++ b/kernel/capability.c
68264@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
68265 * before modification is attempted and the application
68266 * fails.
68267 */
68268+ if (tocopy > ARRAY_SIZE(kdata))
68269+ return -EFAULT;
68270+
68271 if (copy_to_user(dataptr, kdata, tocopy
68272 * sizeof(struct __user_cap_data_struct))) {
68273 return -EFAULT;
68274@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
68275 int ret;
68276
68277 rcu_read_lock();
68278- ret = security_capable(__task_cred(t), ns, cap);
68279+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
68280+ gr_task_is_capable(t, __task_cred(t), cap);
68281 rcu_read_unlock();
68282
68283- return (ret == 0);
68284+ return ret;
68285 }
68286
68287 /**
68288@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
68289 int ret;
68290
68291 rcu_read_lock();
68292- ret = security_capable_noaudit(__task_cred(t), ns, cap);
68293+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
68294 rcu_read_unlock();
68295
68296- return (ret == 0);
68297+ return ret;
68298 }
68299
68300 /**
68301@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
68302 BUG();
68303 }
68304
68305- if (security_capable(current_cred(), ns, cap) == 0) {
68306+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
68307 current->flags |= PF_SUPERPRIV;
68308 return true;
68309 }
68310@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
68311 }
68312 EXPORT_SYMBOL(ns_capable);
68313
68314+bool ns_capable_nolog(struct user_namespace *ns, int cap)
68315+{
68316+ if (unlikely(!cap_valid(cap))) {
68317+ printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
68318+ BUG();
68319+ }
68320+
68321+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
68322+ current->flags |= PF_SUPERPRIV;
68323+ return true;
68324+ }
68325+ return false;
68326+}
68327+EXPORT_SYMBOL(ns_capable_nolog);
68328+
68329 /**
68330 * capable - Determine if the current task has a superior capability in effect
68331 * @cap: The capability to be tested for
68332@@ -408,6 +427,12 @@ bool capable(int cap)
68333 }
68334 EXPORT_SYMBOL(capable);
68335
68336+bool capable_nolog(int cap)
68337+{
68338+ return ns_capable_nolog(&init_user_ns, cap);
68339+}
68340+EXPORT_SYMBOL(capable_nolog);
68341+
68342 /**
68343 * nsown_capable - Check superior capability to one's own user_ns
68344 * @cap: The capability in question
68345@@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
68346
68347 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68348 }
68349+
68350+bool inode_capable_nolog(const struct inode *inode, int cap)
68351+{
68352+ struct user_namespace *ns = current_user_ns();
68353+
68354+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
68355+}
68356diff --git a/kernel/cgroup.c b/kernel/cgroup.c
68357index ad99830..992d8a7 100644
68358--- a/kernel/cgroup.c
68359+++ b/kernel/cgroup.c
68360@@ -5514,7 +5514,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
68361 struct css_set *cg = link->cg;
68362 struct task_struct *task;
68363 int count = 0;
68364- seq_printf(seq, "css_set %p\n", cg);
68365+ seq_printf(seq, "css_set %pK\n", cg);
68366 list_for_each_entry(task, &cg->tasks, cg_list) {
68367 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
68368 seq_puts(seq, " ...\n");
68369diff --git a/kernel/compat.c b/kernel/compat.c
68370index c28a306..b4d0cf3 100644
68371--- a/kernel/compat.c
68372+++ b/kernel/compat.c
68373@@ -13,6 +13,7 @@
68374
68375 #include <linux/linkage.h>
68376 #include <linux/compat.h>
68377+#include <linux/module.h>
68378 #include <linux/errno.h>
68379 #include <linux/time.h>
68380 #include <linux/signal.h>
68381@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
68382 mm_segment_t oldfs;
68383 long ret;
68384
68385- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
68386+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
68387 oldfs = get_fs();
68388 set_fs(KERNEL_DS);
68389 ret = hrtimer_nanosleep_restart(restart);
68390@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
68391 oldfs = get_fs();
68392 set_fs(KERNEL_DS);
68393 ret = hrtimer_nanosleep(&tu,
68394- rmtp ? (struct timespec __user *)&rmt : NULL,
68395+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
68396 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
68397 set_fs(oldfs);
68398
68399@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
68400 mm_segment_t old_fs = get_fs();
68401
68402 set_fs(KERNEL_DS);
68403- ret = sys_sigpending((old_sigset_t __user *) &s);
68404+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
68405 set_fs(old_fs);
68406 if (ret == 0)
68407 ret = put_user(s, set);
68408@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
68409 mm_segment_t old_fs = get_fs();
68410
68411 set_fs(KERNEL_DS);
68412- ret = sys_old_getrlimit(resource, &r);
68413+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
68414 set_fs(old_fs);
68415
68416 if (!ret) {
68417@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
68418 mm_segment_t old_fs = get_fs();
68419
68420 set_fs(KERNEL_DS);
68421- ret = sys_getrusage(who, (struct rusage __user *) &r);
68422+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
68423 set_fs(old_fs);
68424
68425 if (ret)
68426@@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
68427 set_fs (KERNEL_DS);
68428 ret = sys_wait4(pid,
68429 (stat_addr ?
68430- (unsigned int __user *) &status : NULL),
68431- options, (struct rusage __user *) &r);
68432+ (unsigned int __force_user *) &status : NULL),
68433+ options, (struct rusage __force_user *) &r);
68434 set_fs (old_fs);
68435
68436 if (ret > 0) {
68437@@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
68438 memset(&info, 0, sizeof(info));
68439
68440 set_fs(KERNEL_DS);
68441- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
68442- uru ? (struct rusage __user *)&ru : NULL);
68443+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
68444+ uru ? (struct rusage __force_user *)&ru : NULL);
68445 set_fs(old_fs);
68446
68447 if ((ret < 0) || (info.si_signo == 0))
68448@@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
68449 oldfs = get_fs();
68450 set_fs(KERNEL_DS);
68451 err = sys_timer_settime(timer_id, flags,
68452- (struct itimerspec __user *) &newts,
68453- (struct itimerspec __user *) &oldts);
68454+ (struct itimerspec __force_user *) &newts,
68455+ (struct itimerspec __force_user *) &oldts);
68456 set_fs(oldfs);
68457 if (!err && old && put_compat_itimerspec(old, &oldts))
68458 return -EFAULT;
68459@@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
68460 oldfs = get_fs();
68461 set_fs(KERNEL_DS);
68462 err = sys_timer_gettime(timer_id,
68463- (struct itimerspec __user *) &ts);
68464+ (struct itimerspec __force_user *) &ts);
68465 set_fs(oldfs);
68466 if (!err && put_compat_itimerspec(setting, &ts))
68467 return -EFAULT;
68468@@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
68469 oldfs = get_fs();
68470 set_fs(KERNEL_DS);
68471 err = sys_clock_settime(which_clock,
68472- (struct timespec __user *) &ts);
68473+ (struct timespec __force_user *) &ts);
68474 set_fs(oldfs);
68475 return err;
68476 }
68477@@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
68478 oldfs = get_fs();
68479 set_fs(KERNEL_DS);
68480 err = sys_clock_gettime(which_clock,
68481- (struct timespec __user *) &ts);
68482+ (struct timespec __force_user *) &ts);
68483 set_fs(oldfs);
68484 if (!err && put_compat_timespec(&ts, tp))
68485 return -EFAULT;
68486@@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
68487
68488 oldfs = get_fs();
68489 set_fs(KERNEL_DS);
68490- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
68491+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
68492 set_fs(oldfs);
68493
68494 err = compat_put_timex(utp, &txc);
68495@@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
68496 oldfs = get_fs();
68497 set_fs(KERNEL_DS);
68498 err = sys_clock_getres(which_clock,
68499- (struct timespec __user *) &ts);
68500+ (struct timespec __force_user *) &ts);
68501 set_fs(oldfs);
68502 if (!err && tp && put_compat_timespec(&ts, tp))
68503 return -EFAULT;
68504@@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
68505 long err;
68506 mm_segment_t oldfs;
68507 struct timespec tu;
68508- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
68509+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
68510
68511- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
68512+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
68513 oldfs = get_fs();
68514 set_fs(KERNEL_DS);
68515 err = clock_nanosleep_restart(restart);
68516@@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
68517 oldfs = get_fs();
68518 set_fs(KERNEL_DS);
68519 err = sys_clock_nanosleep(which_clock, flags,
68520- (struct timespec __user *) &in,
68521- (struct timespec __user *) &out);
68522+ (struct timespec __force_user *) &in,
68523+ (struct timespec __force_user *) &out);
68524 set_fs(oldfs);
68525
68526 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
68527diff --git a/kernel/configs.c b/kernel/configs.c
68528index 42e8fa0..9e7406b 100644
68529--- a/kernel/configs.c
68530+++ b/kernel/configs.c
68531@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
68532 struct proc_dir_entry *entry;
68533
68534 /* create the current config file */
68535+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
68536+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
68537+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
68538+ &ikconfig_file_ops);
68539+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68540+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
68541+ &ikconfig_file_ops);
68542+#endif
68543+#else
68544 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
68545 &ikconfig_file_ops);
68546+#endif
68547+
68548 if (!entry)
68549 return -ENOMEM;
68550
68551diff --git a/kernel/cred.c b/kernel/cred.c
68552index 48cea3d..3476734 100644
68553--- a/kernel/cred.c
68554+++ b/kernel/cred.c
68555@@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
68556 validate_creds(cred);
68557 alter_cred_subscribers(cred, -1);
68558 put_cred(cred);
68559+
68560+#ifdef CONFIG_GRKERNSEC_SETXID
68561+ cred = (struct cred *) tsk->delayed_cred;
68562+ if (cred != NULL) {
68563+ tsk->delayed_cred = NULL;
68564+ validate_creds(cred);
68565+ alter_cred_subscribers(cred, -1);
68566+ put_cred(cred);
68567+ }
68568+#endif
68569 }
68570
68571 /**
68572@@ -469,7 +479,7 @@ error_put:
68573 * Always returns 0 thus allowing this function to be tail-called at the end
68574 * of, say, sys_setgid().
68575 */
68576-int commit_creds(struct cred *new)
68577+static int __commit_creds(struct cred *new)
68578 {
68579 struct task_struct *task = current;
68580 const struct cred *old = task->real_cred;
68581@@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
68582
68583 get_cred(new); /* we will require a ref for the subj creds too */
68584
68585+ gr_set_role_label(task, new->uid, new->gid);
68586+
68587 /* dumpability changes */
68588 if (!uid_eq(old->euid, new->euid) ||
68589 !gid_eq(old->egid, new->egid) ||
68590@@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
68591 put_cred(old);
68592 return 0;
68593 }
68594+#ifdef CONFIG_GRKERNSEC_SETXID
68595+extern int set_user(struct cred *new);
68596+
68597+void gr_delayed_cred_worker(void)
68598+{
68599+ const struct cred *new = current->delayed_cred;
68600+ struct cred *ncred;
68601+
68602+ current->delayed_cred = NULL;
68603+
68604+ if (current_uid() && new != NULL) {
68605+ // from doing get_cred on it when queueing this
68606+ put_cred(new);
68607+ return;
68608+ } else if (new == NULL)
68609+ return;
68610+
68611+ ncred = prepare_creds();
68612+ if (!ncred)
68613+ goto die;
68614+ // uids
68615+ ncred->uid = new->uid;
68616+ ncred->euid = new->euid;
68617+ ncred->suid = new->suid;
68618+ ncred->fsuid = new->fsuid;
68619+ // gids
68620+ ncred->gid = new->gid;
68621+ ncred->egid = new->egid;
68622+ ncred->sgid = new->sgid;
68623+ ncred->fsgid = new->fsgid;
68624+ // groups
68625+ if (set_groups(ncred, new->group_info) < 0) {
68626+ abort_creds(ncred);
68627+ goto die;
68628+ }
68629+ // caps
68630+ ncred->securebits = new->securebits;
68631+ ncred->cap_inheritable = new->cap_inheritable;
68632+ ncred->cap_permitted = new->cap_permitted;
68633+ ncred->cap_effective = new->cap_effective;
68634+ ncred->cap_bset = new->cap_bset;
68635+
68636+ if (set_user(ncred)) {
68637+ abort_creds(ncred);
68638+ goto die;
68639+ }
68640+
68641+ // from doing get_cred on it when queueing this
68642+ put_cred(new);
68643+
68644+ __commit_creds(ncred);
68645+ return;
68646+die:
68647+ // from doing get_cred on it when queueing this
68648+ put_cred(new);
68649+ do_group_exit(SIGKILL);
68650+}
68651+#endif
68652+
68653+int commit_creds(struct cred *new)
68654+{
68655+#ifdef CONFIG_GRKERNSEC_SETXID
68656+ int ret;
68657+ int schedule_it = 0;
68658+ struct task_struct *t;
68659+
68660+ /* we won't get called with tasklist_lock held for writing
68661+ and interrupts disabled as the cred struct in that case is
68662+ init_cred
68663+ */
68664+ if (grsec_enable_setxid && !current_is_single_threaded() &&
68665+ !current_uid() && new->uid) {
68666+ schedule_it = 1;
68667+ }
68668+ ret = __commit_creds(new);
68669+ if (schedule_it) {
68670+ rcu_read_lock();
68671+ read_lock(&tasklist_lock);
68672+ for (t = next_thread(current); t != current;
68673+ t = next_thread(t)) {
68674+ if (t->delayed_cred == NULL) {
68675+ t->delayed_cred = get_cred(new);
68676+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
68677+ set_tsk_need_resched(t);
68678+ }
68679+ }
68680+ read_unlock(&tasklist_lock);
68681+ rcu_read_unlock();
68682+ }
68683+ return ret;
68684+#else
68685+ return __commit_creds(new);
68686+#endif
68687+}
68688+
68689 EXPORT_SYMBOL(commit_creds);
68690
68691 /**
68692diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
68693index 9a61738..c5c8f3a 100644
68694--- a/kernel/debug/debug_core.c
68695+++ b/kernel/debug/debug_core.c
68696@@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
68697 */
68698 static atomic_t masters_in_kgdb;
68699 static atomic_t slaves_in_kgdb;
68700-static atomic_t kgdb_break_tasklet_var;
68701+static atomic_unchecked_t kgdb_break_tasklet_var;
68702 atomic_t kgdb_setting_breakpoint;
68703
68704 struct task_struct *kgdb_usethread;
68705@@ -132,7 +132,7 @@ int kgdb_single_step;
68706 static pid_t kgdb_sstep_pid;
68707
68708 /* to keep track of the CPU which is doing the single stepping*/
68709-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68710+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
68711
68712 /*
68713 * If you are debugging a problem where roundup (the collection of
68714@@ -540,7 +540,7 @@ return_normal:
68715 * kernel will only try for the value of sstep_tries before
68716 * giving up and continuing on.
68717 */
68718- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
68719+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
68720 (kgdb_info[cpu].task &&
68721 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
68722 atomic_set(&kgdb_active, -1);
68723@@ -634,8 +634,8 @@ cpu_master_loop:
68724 }
68725
68726 kgdb_restore:
68727- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
68728- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
68729+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
68730+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
68731 if (kgdb_info[sstep_cpu].task)
68732 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
68733 else
68734@@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
68735 static void kgdb_tasklet_bpt(unsigned long ing)
68736 {
68737 kgdb_breakpoint();
68738- atomic_set(&kgdb_break_tasklet_var, 0);
68739+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
68740 }
68741
68742 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
68743
68744 void kgdb_schedule_breakpoint(void)
68745 {
68746- if (atomic_read(&kgdb_break_tasklet_var) ||
68747+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
68748 atomic_read(&kgdb_active) != -1 ||
68749 atomic_read(&kgdb_setting_breakpoint))
68750 return;
68751- atomic_inc(&kgdb_break_tasklet_var);
68752+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
68753 tasklet_schedule(&kgdb_tasklet_breakpoint);
68754 }
68755 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
68756diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
68757index 8875254..7cf4928 100644
68758--- a/kernel/debug/kdb/kdb_main.c
68759+++ b/kernel/debug/kdb/kdb_main.c
68760@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
68761 continue;
68762
68763 kdb_printf("%-20s%8u 0x%p ", mod->name,
68764- mod->core_size, (void *)mod);
68765+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
68766 #ifdef CONFIG_MODULE_UNLOAD
68767 kdb_printf("%4ld ", module_refcount(mod));
68768 #endif
68769@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
68770 kdb_printf(" (Loading)");
68771 else
68772 kdb_printf(" (Live)");
68773- kdb_printf(" 0x%p", mod->module_core);
68774+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
68775
68776 #ifdef CONFIG_MODULE_UNLOAD
68777 {
68778diff --git a/kernel/events/core.c b/kernel/events/core.c
68779index dbccf83..8c66482 100644
68780--- a/kernel/events/core.c
68781+++ b/kernel/events/core.c
68782@@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
68783 return 0;
68784 }
68785
68786-static atomic64_t perf_event_id;
68787+static atomic64_unchecked_t perf_event_id;
68788
68789 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
68790 enum event_type_t event_type);
68791@@ -2668,7 +2668,7 @@ static void __perf_event_read(void *info)
68792
68793 static inline u64 perf_event_count(struct perf_event *event)
68794 {
68795- return local64_read(&event->count) + atomic64_read(&event->child_count);
68796+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
68797 }
68798
68799 static u64 perf_event_read(struct perf_event *event)
68800@@ -2998,9 +2998,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
68801 mutex_lock(&event->child_mutex);
68802 total += perf_event_read(event);
68803 *enabled += event->total_time_enabled +
68804- atomic64_read(&event->child_total_time_enabled);
68805+ atomic64_read_unchecked(&event->child_total_time_enabled);
68806 *running += event->total_time_running +
68807- atomic64_read(&event->child_total_time_running);
68808+ atomic64_read_unchecked(&event->child_total_time_running);
68809
68810 list_for_each_entry(child, &event->child_list, child_list) {
68811 total += perf_event_read(child);
68812@@ -3403,10 +3403,10 @@ void perf_event_update_userpage(struct perf_event *event)
68813 userpg->offset -= local64_read(&event->hw.prev_count);
68814
68815 userpg->time_enabled = enabled +
68816- atomic64_read(&event->child_total_time_enabled);
68817+ atomic64_read_unchecked(&event->child_total_time_enabled);
68818
68819 userpg->time_running = running +
68820- atomic64_read(&event->child_total_time_running);
68821+ atomic64_read_unchecked(&event->child_total_time_running);
68822
68823 arch_perf_update_userpage(userpg, now);
68824
68825@@ -3965,11 +3965,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
68826 values[n++] = perf_event_count(event);
68827 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
68828 values[n++] = enabled +
68829- atomic64_read(&event->child_total_time_enabled);
68830+ atomic64_read_unchecked(&event->child_total_time_enabled);
68831 }
68832 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
68833 values[n++] = running +
68834- atomic64_read(&event->child_total_time_running);
68835+ atomic64_read_unchecked(&event->child_total_time_running);
68836 }
68837 if (read_format & PERF_FORMAT_ID)
68838 values[n++] = primary_event_id(event);
68839@@ -4712,12 +4712,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
68840 * need to add enough zero bytes after the string to handle
68841 * the 64bit alignment we do later.
68842 */
68843- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
68844+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
68845 if (!buf) {
68846 name = strncpy(tmp, "//enomem", sizeof(tmp));
68847 goto got_name;
68848 }
68849- name = d_path(&file->f_path, buf, PATH_MAX);
68850+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
68851 if (IS_ERR(name)) {
68852 name = strncpy(tmp, "//toolong", sizeof(tmp));
68853 goto got_name;
68854@@ -6156,7 +6156,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
68855 event->parent = parent_event;
68856
68857 event->ns = get_pid_ns(current->nsproxy->pid_ns);
68858- event->id = atomic64_inc_return(&perf_event_id);
68859+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
68860
68861 event->state = PERF_EVENT_STATE_INACTIVE;
68862
68863@@ -6774,10 +6774,10 @@ static void sync_child_event(struct perf_event *child_event,
68864 /*
68865 * Add back the child's count to the parent's count:
68866 */
68867- atomic64_add(child_val, &parent_event->child_count);
68868- atomic64_add(child_event->total_time_enabled,
68869+ atomic64_add_unchecked(child_val, &parent_event->child_count);
68870+ atomic64_add_unchecked(child_event->total_time_enabled,
68871 &parent_event->child_total_time_enabled);
68872- atomic64_add(child_event->total_time_running,
68873+ atomic64_add_unchecked(child_event->total_time_running,
68874 &parent_event->child_total_time_running);
68875
68876 /*
68877diff --git a/kernel/exit.c b/kernel/exit.c
68878index 346616c..f103b28 100644
68879--- a/kernel/exit.c
68880+++ b/kernel/exit.c
68881@@ -182,6 +182,10 @@ void release_task(struct task_struct * p)
68882 struct task_struct *leader;
68883 int zap_leader;
68884 repeat:
68885+#ifdef CONFIG_NET
68886+ gr_del_task_from_ip_table(p);
68887+#endif
68888+
68889 /* don't need to get the RCU readlock here - the process is dead and
68890 * can't be modifying its own credentials. But shut RCU-lockdep up */
68891 rcu_read_lock();
68892@@ -394,7 +398,7 @@ int allow_signal(int sig)
68893 * know it'll be handled, so that they don't get converted to
68894 * SIGKILL or just silently dropped.
68895 */
68896- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
68897+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
68898 recalc_sigpending();
68899 spin_unlock_irq(&current->sighand->siglock);
68900 return 0;
68901@@ -430,6 +434,9 @@ void daemonize(const char *name, ...)
68902 vsnprintf(current->comm, sizeof(current->comm), name, args);
68903 va_end(args);
68904
68905+ gr_put_exec_file(current);
68906+ gr_set_kernel_label(current);
68907+
68908 /*
68909 * If we were started as result of loading a module, close all of the
68910 * user space pages. We don't need them, and if we didn't close them
68911@@ -812,6 +819,8 @@ void do_exit(long code)
68912 struct task_struct *tsk = current;
68913 int group_dead;
68914
68915+ set_fs(USER_DS);
68916+
68917 profile_task_exit(tsk);
68918
68919 WARN_ON(blk_needs_flush_plug(tsk));
68920@@ -828,7 +837,6 @@ void do_exit(long code)
68921 * mm_release()->clear_child_tid() from writing to a user-controlled
68922 * kernel address.
68923 */
68924- set_fs(USER_DS);
68925
68926 ptrace_event(PTRACE_EVENT_EXIT, code);
68927
68928@@ -887,6 +895,9 @@ void do_exit(long code)
68929 tsk->exit_code = code;
68930 taskstats_exit(tsk, group_dead);
68931
68932+ gr_acl_handle_psacct(tsk, code);
68933+ gr_acl_handle_exit();
68934+
68935 exit_mm(tsk);
68936
68937 if (group_dead)
68938@@ -1007,7 +1018,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
68939 * Take down every thread in the group. This is called by fatal signals
68940 * as well as by sys_exit_group (below).
68941 */
68942-void
68943+__noreturn void
68944 do_group_exit(int exit_code)
68945 {
68946 struct signal_struct *sig = current->signal;
68947diff --git a/kernel/fork.c b/kernel/fork.c
68948index acc4cb6..b524cb5 100644
68949--- a/kernel/fork.c
68950+++ b/kernel/fork.c
68951@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
68952 *stackend = STACK_END_MAGIC; /* for overflow detection */
68953
68954 #ifdef CONFIG_CC_STACKPROTECTOR
68955- tsk->stack_canary = get_random_int();
68956+ tsk->stack_canary = pax_get_random_long();
68957 #endif
68958
68959 /*
68960@@ -344,13 +344,81 @@ free_tsk:
68961 }
68962
68963 #ifdef CONFIG_MMU
68964+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
68965+{
68966+ struct vm_area_struct *tmp;
68967+ unsigned long charge;
68968+ struct mempolicy *pol;
68969+ struct file *file;
68970+
68971+ charge = 0;
68972+ if (mpnt->vm_flags & VM_ACCOUNT) {
68973+ unsigned long len = vma_pages(mpnt);
68974+
68975+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
68976+ goto fail_nomem;
68977+ charge = len;
68978+ }
68979+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
68980+ if (!tmp)
68981+ goto fail_nomem;
68982+ *tmp = *mpnt;
68983+ tmp->vm_mm = mm;
68984+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
68985+ pol = mpol_dup(vma_policy(mpnt));
68986+ if (IS_ERR(pol))
68987+ goto fail_nomem_policy;
68988+ vma_set_policy(tmp, pol);
68989+ if (anon_vma_fork(tmp, mpnt))
68990+ goto fail_nomem_anon_vma_fork;
68991+ tmp->vm_flags &= ~VM_LOCKED;
68992+ tmp->vm_next = tmp->vm_prev = NULL;
68993+ tmp->vm_mirror = NULL;
68994+ file = tmp->vm_file;
68995+ if (file) {
68996+ struct inode *inode = file->f_path.dentry->d_inode;
68997+ struct address_space *mapping = file->f_mapping;
68998+
68999+ get_file(file);
69000+ if (tmp->vm_flags & VM_DENYWRITE)
69001+ atomic_dec(&inode->i_writecount);
69002+ mutex_lock(&mapping->i_mmap_mutex);
69003+ if (tmp->vm_flags & VM_SHARED)
69004+ mapping->i_mmap_writable++;
69005+ flush_dcache_mmap_lock(mapping);
69006+ /* insert tmp into the share list, just after mpnt */
69007+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69008+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
69009+ else
69010+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
69011+ flush_dcache_mmap_unlock(mapping);
69012+ mutex_unlock(&mapping->i_mmap_mutex);
69013+ }
69014+
69015+ /*
69016+ * Clear hugetlb-related page reserves for children. This only
69017+ * affects MAP_PRIVATE mappings. Faults generated by the child
69018+ * are not guaranteed to succeed, even if read-only
69019+ */
69020+ if (is_vm_hugetlb_page(tmp))
69021+ reset_vma_resv_huge_pages(tmp);
69022+
69023+ return tmp;
69024+
69025+fail_nomem_anon_vma_fork:
69026+ mpol_put(pol);
69027+fail_nomem_policy:
69028+ kmem_cache_free(vm_area_cachep, tmp);
69029+fail_nomem:
69030+ vm_unacct_memory(charge);
69031+ return NULL;
69032+}
69033+
69034 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69035 {
69036 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
69037 struct rb_node **rb_link, *rb_parent;
69038 int retval;
69039- unsigned long charge;
69040- struct mempolicy *pol;
69041
69042 down_write(&oldmm->mmap_sem);
69043 flush_cache_dup_mm(oldmm);
69044@@ -363,8 +431,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69045 mm->locked_vm = 0;
69046 mm->mmap = NULL;
69047 mm->mmap_cache = NULL;
69048- mm->free_area_cache = oldmm->mmap_base;
69049- mm->cached_hole_size = ~0UL;
69050+ mm->free_area_cache = oldmm->free_area_cache;
69051+ mm->cached_hole_size = oldmm->cached_hole_size;
69052 mm->map_count = 0;
69053 cpumask_clear(mm_cpumask(mm));
69054 mm->mm_rb = RB_ROOT;
69055@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69056
69057 prev = NULL;
69058 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
69059- struct file *file;
69060-
69061 if (mpnt->vm_flags & VM_DONTCOPY) {
69062 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
69063 -vma_pages(mpnt));
69064 continue;
69065 }
69066- charge = 0;
69067- if (mpnt->vm_flags & VM_ACCOUNT) {
69068- unsigned long len = vma_pages(mpnt);
69069-
69070- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
69071- goto fail_nomem;
69072- charge = len;
69073- }
69074- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
69075- if (!tmp)
69076- goto fail_nomem;
69077- *tmp = *mpnt;
69078- INIT_LIST_HEAD(&tmp->anon_vma_chain);
69079- pol = mpol_dup(vma_policy(mpnt));
69080- retval = PTR_ERR(pol);
69081- if (IS_ERR(pol))
69082- goto fail_nomem_policy;
69083- vma_set_policy(tmp, pol);
69084- tmp->vm_mm = mm;
69085- if (anon_vma_fork(tmp, mpnt))
69086- goto fail_nomem_anon_vma_fork;
69087- tmp->vm_flags &= ~VM_LOCKED;
69088- tmp->vm_next = tmp->vm_prev = NULL;
69089- file = tmp->vm_file;
69090- if (file) {
69091- struct inode *inode = file->f_path.dentry->d_inode;
69092- struct address_space *mapping = file->f_mapping;
69093-
69094- get_file(file);
69095- if (tmp->vm_flags & VM_DENYWRITE)
69096- atomic_dec(&inode->i_writecount);
69097- mutex_lock(&mapping->i_mmap_mutex);
69098- if (tmp->vm_flags & VM_SHARED)
69099- mapping->i_mmap_writable++;
69100- flush_dcache_mmap_lock(mapping);
69101- /* insert tmp into the share list, just after mpnt */
69102- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
69103- vma_nonlinear_insert(tmp,
69104- &mapping->i_mmap_nonlinear);
69105- else
69106- vma_interval_tree_insert_after(tmp, mpnt,
69107- &mapping->i_mmap);
69108- flush_dcache_mmap_unlock(mapping);
69109- mutex_unlock(&mapping->i_mmap_mutex);
69110+ tmp = dup_vma(mm, oldmm, mpnt);
69111+ if (!tmp) {
69112+ retval = -ENOMEM;
69113+ goto out;
69114 }
69115
69116 /*
69117@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
69118 if (retval)
69119 goto out;
69120 }
69121+
69122+#ifdef CONFIG_PAX_SEGMEXEC
69123+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
69124+ struct vm_area_struct *mpnt_m;
69125+
69126+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
69127+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
69128+
69129+ if (!mpnt->vm_mirror)
69130+ continue;
69131+
69132+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
69133+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
69134+ mpnt->vm_mirror = mpnt_m;
69135+ } else {
69136+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
69137+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
69138+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
69139+ mpnt->vm_mirror->vm_mirror = mpnt;
69140+ }
69141+ }
69142+ BUG_ON(mpnt_m);
69143+ }
69144+#endif
69145+
69146 /* a new mm has just been created */
69147 arch_dup_mmap(oldmm, mm);
69148 retval = 0;
69149@@ -470,14 +521,6 @@ out:
69150 flush_tlb_mm(oldmm);
69151 up_write(&oldmm->mmap_sem);
69152 return retval;
69153-fail_nomem_anon_vma_fork:
69154- mpol_put(pol);
69155-fail_nomem_policy:
69156- kmem_cache_free(vm_area_cachep, tmp);
69157-fail_nomem:
69158- retval = -ENOMEM;
69159- vm_unacct_memory(charge);
69160- goto out;
69161 }
69162
69163 static inline int mm_alloc_pgd(struct mm_struct *mm)
69164@@ -692,8 +735,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
69165 return ERR_PTR(err);
69166
69167 mm = get_task_mm(task);
69168- if (mm && mm != current->mm &&
69169- !ptrace_may_access(task, mode)) {
69170+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
69171+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
69172 mmput(mm);
69173 mm = ERR_PTR(-EACCES);
69174 }
69175@@ -912,13 +955,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
69176 spin_unlock(&fs->lock);
69177 return -EAGAIN;
69178 }
69179- fs->users++;
69180+ atomic_inc(&fs->users);
69181 spin_unlock(&fs->lock);
69182 return 0;
69183 }
69184 tsk->fs = copy_fs_struct(fs);
69185 if (!tsk->fs)
69186 return -ENOMEM;
69187+ /* Carry through gr_chroot_dentry and is_chrooted instead
69188+ of recomputing it here. Already copied when the task struct
69189+ is duplicated. This allows pivot_root to not be treated as
69190+ a chroot
69191+ */
69192+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
69193+
69194 return 0;
69195 }
69196
69197@@ -1183,6 +1233,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69198 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
69199 #endif
69200 retval = -EAGAIN;
69201+
69202+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
69203+
69204 if (atomic_read(&p->real_cred->user->processes) >=
69205 task_rlimit(p, RLIMIT_NPROC)) {
69206 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
69207@@ -1422,6 +1475,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
69208 goto bad_fork_free_pid;
69209 }
69210
69211+ /* synchronizes with gr_set_acls()
69212+ we need to call this past the point of no return for fork()
69213+ */
69214+ gr_copy_label(p);
69215+
69216 if (clone_flags & CLONE_THREAD) {
69217 current->signal->nr_threads++;
69218 atomic_inc(&current->signal->live);
69219@@ -1505,6 +1563,8 @@ bad_fork_cleanup_count:
69220 bad_fork_free:
69221 free_task(p);
69222 fork_out:
69223+ gr_log_forkfail(retval);
69224+
69225 return ERR_PTR(retval);
69226 }
69227
69228@@ -1605,6 +1665,8 @@ long do_fork(unsigned long clone_flags,
69229 if (clone_flags & CLONE_PARENT_SETTID)
69230 put_user(nr, parent_tidptr);
69231
69232+ gr_handle_brute_check();
69233+
69234 if (clone_flags & CLONE_VFORK) {
69235 p->vfork_done = &vfork;
69236 init_completion(&vfork);
69237@@ -1714,7 +1776,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
69238 return 0;
69239
69240 /* don't need lock here; in the worst case we'll do useless copy */
69241- if (fs->users == 1)
69242+ if (atomic_read(&fs->users) == 1)
69243 return 0;
69244
69245 *new_fsp = copy_fs_struct(fs);
69246@@ -1803,7 +1865,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
69247 fs = current->fs;
69248 spin_lock(&fs->lock);
69249 current->fs = new_fs;
69250- if (--fs->users)
69251+ gr_set_chroot_entries(current, &current->fs->root);
69252+ if (atomic_dec_return(&fs->users))
69253 new_fs = NULL;
69254 else
69255 new_fs = fs;
69256diff --git a/kernel/futex.c b/kernel/futex.c
69257index 19eb089..b8c65ea 100644
69258--- a/kernel/futex.c
69259+++ b/kernel/futex.c
69260@@ -54,6 +54,7 @@
69261 #include <linux/mount.h>
69262 #include <linux/pagemap.h>
69263 #include <linux/syscalls.h>
69264+#include <linux/ptrace.h>
69265 #include <linux/signal.h>
69266 #include <linux/export.h>
69267 #include <linux/magic.h>
69268@@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
69269 struct page *page, *page_head;
69270 int err, ro = 0;
69271
69272+#ifdef CONFIG_PAX_SEGMEXEC
69273+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
69274+ return -EFAULT;
69275+#endif
69276+
69277 /*
69278 * The futex address must be "naturally" aligned.
69279 */
69280@@ -2733,6 +2739,7 @@ static int __init futex_init(void)
69281 {
69282 u32 curval;
69283 int i;
69284+ mm_segment_t oldfs;
69285
69286 /*
69287 * This will fail and we want it. Some arch implementations do
69288@@ -2744,8 +2751,11 @@ static int __init futex_init(void)
69289 * implementation, the non-functional ones will return
69290 * -ENOSYS.
69291 */
69292+ oldfs = get_fs();
69293+ set_fs(USER_DS);
69294 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
69295 futex_cmpxchg_enabled = 1;
69296+ set_fs(oldfs);
69297
69298 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
69299 plist_head_init(&futex_queues[i].chain);
69300diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
69301index 9b22d03..6295b62 100644
69302--- a/kernel/gcov/base.c
69303+++ b/kernel/gcov/base.c
69304@@ -102,11 +102,6 @@ void gcov_enable_events(void)
69305 }
69306
69307 #ifdef CONFIG_MODULES
69308-static inline int within(void *addr, void *start, unsigned long size)
69309-{
69310- return ((addr >= start) && (addr < start + size));
69311-}
69312-
69313 /* Update list and generate events when modules are unloaded. */
69314 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69315 void *data)
69316@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
69317 prev = NULL;
69318 /* Remove entries located in module from linked list. */
69319 for (info = gcov_info_head; info; info = info->next) {
69320- if (within(info, mod->module_core, mod->core_size)) {
69321+ if (within_module_core_rw((unsigned long)info, mod)) {
69322 if (prev)
69323 prev->next = info->next;
69324 else
69325diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
69326index 6db7a5e..25b6648 100644
69327--- a/kernel/hrtimer.c
69328+++ b/kernel/hrtimer.c
69329@@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
69330 local_irq_restore(flags);
69331 }
69332
69333-static void run_hrtimer_softirq(struct softirq_action *h)
69334+static void run_hrtimer_softirq(void)
69335 {
69336 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
69337
69338diff --git a/kernel/jump_label.c b/kernel/jump_label.c
69339index 60f48fa..7f3a770 100644
69340--- a/kernel/jump_label.c
69341+++ b/kernel/jump_label.c
69342@@ -13,6 +13,7 @@
69343 #include <linux/sort.h>
69344 #include <linux/err.h>
69345 #include <linux/static_key.h>
69346+#include <linux/mm.h>
69347
69348 #ifdef HAVE_JUMP_LABEL
69349
69350@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
69351
69352 size = (((unsigned long)stop - (unsigned long)start)
69353 / sizeof(struct jump_entry));
69354+ pax_open_kernel();
69355 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
69356+ pax_close_kernel();
69357 }
69358
69359 static void jump_label_update(struct static_key *key, int enable);
69360@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
69361 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
69362 struct jump_entry *iter;
69363
69364+ pax_open_kernel();
69365 for (iter = iter_start; iter < iter_stop; iter++) {
69366 if (within_module_init(iter->code, mod))
69367 iter->code = 0;
69368 }
69369+ pax_close_kernel();
69370 }
69371
69372 static int
69373diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
69374index 2169fee..45c017a 100644
69375--- a/kernel/kallsyms.c
69376+++ b/kernel/kallsyms.c
69377@@ -11,6 +11,9 @@
69378 * Changed the compression method from stem compression to "table lookup"
69379 * compression (see scripts/kallsyms.c for a more complete description)
69380 */
69381+#ifdef CONFIG_GRKERNSEC_HIDESYM
69382+#define __INCLUDED_BY_HIDESYM 1
69383+#endif
69384 #include <linux/kallsyms.h>
69385 #include <linux/module.h>
69386 #include <linux/init.h>
69387@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
69388
69389 static inline int is_kernel_inittext(unsigned long addr)
69390 {
69391+ if (system_state != SYSTEM_BOOTING)
69392+ return 0;
69393+
69394 if (addr >= (unsigned long)_sinittext
69395 && addr <= (unsigned long)_einittext)
69396 return 1;
69397 return 0;
69398 }
69399
69400+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69401+#ifdef CONFIG_MODULES
69402+static inline int is_module_text(unsigned long addr)
69403+{
69404+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
69405+ return 1;
69406+
69407+ addr = ktla_ktva(addr);
69408+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
69409+}
69410+#else
69411+static inline int is_module_text(unsigned long addr)
69412+{
69413+ return 0;
69414+}
69415+#endif
69416+#endif
69417+
69418 static inline int is_kernel_text(unsigned long addr)
69419 {
69420 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
69421@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
69422
69423 static inline int is_kernel(unsigned long addr)
69424 {
69425+
69426+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69427+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
69428+ return 1;
69429+
69430+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
69431+#else
69432 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
69433+#endif
69434+
69435 return 1;
69436 return in_gate_area_no_mm(addr);
69437 }
69438
69439 static int is_ksym_addr(unsigned long addr)
69440 {
69441+
69442+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
69443+ if (is_module_text(addr))
69444+ return 0;
69445+#endif
69446+
69447 if (all_var)
69448 return is_kernel(addr);
69449
69450@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
69451
69452 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
69453 {
69454- iter->name[0] = '\0';
69455 iter->nameoff = get_symbol_offset(new_pos);
69456 iter->pos = new_pos;
69457 }
69458@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
69459 {
69460 struct kallsym_iter *iter = m->private;
69461
69462+#ifdef CONFIG_GRKERNSEC_HIDESYM
69463+ if (current_uid())
69464+ return 0;
69465+#endif
69466+
69467 /* Some debugging symbols have no name. Ignore them. */
69468 if (!iter->name[0])
69469 return 0;
69470@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
69471 */
69472 type = iter->exported ? toupper(iter->type) :
69473 tolower(iter->type);
69474+
69475 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
69476 type, iter->name, iter->module_name);
69477 } else
69478@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
69479 struct kallsym_iter *iter;
69480 int ret;
69481
69482- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
69483+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
69484 if (!iter)
69485 return -ENOMEM;
69486 reset_iter(iter, 0);
69487diff --git a/kernel/kcmp.c b/kernel/kcmp.c
69488index 30b7b22..c726387 100644
69489--- a/kernel/kcmp.c
69490+++ b/kernel/kcmp.c
69491@@ -98,6 +98,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
69492 struct task_struct *task1, *task2;
69493 int ret;
69494
69495+#ifdef CONFIG_GRKERNSEC
69496+ return -ENOSYS;
69497+#endif
69498+
69499 rcu_read_lock();
69500
69501 /*
69502diff --git a/kernel/kexec.c b/kernel/kexec.c
69503index 5e4bd78..00c5b91 100644
69504--- a/kernel/kexec.c
69505+++ b/kernel/kexec.c
69506@@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
69507 unsigned long flags)
69508 {
69509 struct compat_kexec_segment in;
69510- struct kexec_segment out, __user *ksegments;
69511+ struct kexec_segment out;
69512+ struct kexec_segment __user *ksegments;
69513 unsigned long i, result;
69514
69515 /* Don't allow clients that don't understand the native
69516diff --git a/kernel/kmod.c b/kernel/kmod.c
69517index 1c317e3..4a92a55 100644
69518--- a/kernel/kmod.c
69519+++ b/kernel/kmod.c
69520@@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
69521 kfree(info->argv);
69522 }
69523
69524-static int call_modprobe(char *module_name, int wait)
69525+static int call_modprobe(char *module_name, char *module_param, int wait)
69526 {
69527 static char *envp[] = {
69528 "HOME=/",
69529@@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
69530 NULL
69531 };
69532
69533- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
69534+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
69535 if (!argv)
69536 goto out;
69537
69538@@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
69539 argv[1] = "-q";
69540 argv[2] = "--";
69541 argv[3] = module_name; /* check free_modprobe_argv() */
69542- argv[4] = NULL;
69543+ argv[4] = module_param;
69544+ argv[5] = NULL;
69545
69546 return call_usermodehelper_fns(modprobe_path, argv, envp,
69547 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
69548@@ -120,9 +121,8 @@ out:
69549 * If module auto-loading support is disabled then this function
69550 * becomes a no-operation.
69551 */
69552-int __request_module(bool wait, const char *fmt, ...)
69553+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
69554 {
69555- va_list args;
69556 char module_name[MODULE_NAME_LEN];
69557 unsigned int max_modprobes;
69558 int ret;
69559@@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
69560 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
69561 static int kmod_loop_msg;
69562
69563- va_start(args, fmt);
69564- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
69565- va_end(args);
69566+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
69567 if (ret >= MODULE_NAME_LEN)
69568 return -ENAMETOOLONG;
69569
69570@@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
69571 if (ret)
69572 return ret;
69573
69574+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69575+ if (!current_uid()) {
69576+ /* hack to workaround consolekit/udisks stupidity */
69577+ read_lock(&tasklist_lock);
69578+ if (!strcmp(current->comm, "mount") &&
69579+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
69580+ read_unlock(&tasklist_lock);
69581+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
69582+ return -EPERM;
69583+ }
69584+ read_unlock(&tasklist_lock);
69585+ }
69586+#endif
69587+
69588 /* If modprobe needs a service that is in a module, we get a recursive
69589 * loop. Limit the number of running kmod threads to max_threads/2 or
69590 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
69591@@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
69592
69593 trace_module_request(module_name, wait, _RET_IP_);
69594
69595- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69596+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
69597
69598 atomic_dec(&kmod_concurrent);
69599 return ret;
69600 }
69601+
69602+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
69603+{
69604+ va_list args;
69605+ int ret;
69606+
69607+ va_start(args, fmt);
69608+ ret = ____request_module(wait, module_param, fmt, args);
69609+ va_end(args);
69610+
69611+ return ret;
69612+}
69613+
69614+int __request_module(bool wait, const char *fmt, ...)
69615+{
69616+ va_list args;
69617+ int ret;
69618+
69619+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69620+ if (current_uid()) {
69621+ char module_param[MODULE_NAME_LEN];
69622+
69623+ memset(module_param, 0, sizeof(module_param));
69624+
69625+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
69626+
69627+ va_start(args, fmt);
69628+ ret = ____request_module(wait, module_param, fmt, args);
69629+ va_end(args);
69630+
69631+ return ret;
69632+ }
69633+#endif
69634+
69635+ va_start(args, fmt);
69636+ ret = ____request_module(wait, NULL, fmt, args);
69637+ va_end(args);
69638+
69639+ return ret;
69640+}
69641+
69642 EXPORT_SYMBOL(__request_module);
69643 #endif /* CONFIG_MODULES */
69644
69645@@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
69646 *
69647 * Thus the __user pointer cast is valid here.
69648 */
69649- sys_wait4(pid, (int __user *)&ret, 0, NULL);
69650+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
69651
69652 /*
69653 * If ret is 0, either ____call_usermodehelper failed and the
69654diff --git a/kernel/kprobes.c b/kernel/kprobes.c
69655index 098f396..fe85ff1 100644
69656--- a/kernel/kprobes.c
69657+++ b/kernel/kprobes.c
69658@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
69659 * kernel image and loaded module images reside. This is required
69660 * so x86_64 can correctly handle the %rip-relative fixups.
69661 */
69662- kip->insns = module_alloc(PAGE_SIZE);
69663+ kip->insns = module_alloc_exec(PAGE_SIZE);
69664 if (!kip->insns) {
69665 kfree(kip);
69666 return NULL;
69667@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
69668 */
69669 if (!list_is_singular(&kip->list)) {
69670 list_del(&kip->list);
69671- module_free(NULL, kip->insns);
69672+ module_free_exec(NULL, kip->insns);
69673 kfree(kip);
69674 }
69675 return 1;
69676@@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
69677 {
69678 int i, err = 0;
69679 unsigned long offset = 0, size = 0;
69680- char *modname, namebuf[128];
69681+ char *modname, namebuf[KSYM_NAME_LEN];
69682 const char *symbol_name;
69683 void *addr;
69684 struct kprobe_blackpoint *kb;
69685@@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
69686 kprobe_type = "k";
69687
69688 if (sym)
69689- seq_printf(pi, "%p %s %s+0x%x %s ",
69690+ seq_printf(pi, "%pK %s %s+0x%x %s ",
69691 p->addr, kprobe_type, sym, offset,
69692 (modname ? modname : " "));
69693 else
69694- seq_printf(pi, "%p %s %p ",
69695+ seq_printf(pi, "%pK %s %pK ",
69696 p->addr, kprobe_type, p->addr);
69697
69698 if (!pp)
69699@@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
69700 const char *sym = NULL;
69701 unsigned int i = *(loff_t *) v;
69702 unsigned long offset = 0;
69703- char *modname, namebuf[128];
69704+ char *modname, namebuf[KSYM_NAME_LEN];
69705
69706 head = &kprobe_table[i];
69707 preempt_disable();
69708diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
69709index 4e316e1..5501eef 100644
69710--- a/kernel/ksysfs.c
69711+++ b/kernel/ksysfs.c
69712@@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
69713 {
69714 if (count+1 > UEVENT_HELPER_PATH_LEN)
69715 return -ENOENT;
69716+ if (!capable(CAP_SYS_ADMIN))
69717+ return -EPERM;
69718 memcpy(uevent_helper, buf, count);
69719 uevent_helper[count] = '\0';
69720 if (count && uevent_helper[count-1] == '\n')
69721diff --git a/kernel/lockdep.c b/kernel/lockdep.c
69722index 7981e5b..7f2105c 100644
69723--- a/kernel/lockdep.c
69724+++ b/kernel/lockdep.c
69725@@ -590,6 +590,10 @@ static int static_obj(void *obj)
69726 end = (unsigned long) &_end,
69727 addr = (unsigned long) obj;
69728
69729+#ifdef CONFIG_PAX_KERNEXEC
69730+ start = ktla_ktva(start);
69731+#endif
69732+
69733 /*
69734 * static variable?
69735 */
69736@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
69737 if (!static_obj(lock->key)) {
69738 debug_locks_off();
69739 printk("INFO: trying to register non-static key.\n");
69740+ printk("lock:%pS key:%pS.\n", lock, lock->key);
69741 printk("the code is fine but needs lockdep annotation.\n");
69742 printk("turning off the locking correctness validator.\n");
69743 dump_stack();
69744@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
69745 if (!class)
69746 return 0;
69747 }
69748- atomic_inc((atomic_t *)&class->ops);
69749+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
69750 if (very_verbose(class)) {
69751 printk("\nacquire class [%p] %s", class->key, class->name);
69752 if (class->name_version > 1)
69753diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
69754index 91c32a0..7b88d63 100644
69755--- a/kernel/lockdep_proc.c
69756+++ b/kernel/lockdep_proc.c
69757@@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
69758
69759 static void print_name(struct seq_file *m, struct lock_class *class)
69760 {
69761- char str[128];
69762+ char str[KSYM_NAME_LEN];
69763 const char *name = class->name;
69764
69765 if (!name) {
69766@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
69767 return 0;
69768 }
69769
69770- seq_printf(m, "%p", class->key);
69771+ seq_printf(m, "%pK", class->key);
69772 #ifdef CONFIG_DEBUG_LOCKDEP
69773 seq_printf(m, " OPS:%8ld", class->ops);
69774 #endif
69775@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
69776
69777 list_for_each_entry(entry, &class->locks_after, entry) {
69778 if (entry->distance == 1) {
69779- seq_printf(m, " -> [%p] ", entry->class->key);
69780+ seq_printf(m, " -> [%pK] ", entry->class->key);
69781 print_name(m, entry->class);
69782 seq_puts(m, "\n");
69783 }
69784@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
69785 if (!class->key)
69786 continue;
69787
69788- seq_printf(m, "[%p] ", class->key);
69789+ seq_printf(m, "[%pK] ", class->key);
69790 print_name(m, class);
69791 seq_puts(m, "\n");
69792 }
69793@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69794 if (!i)
69795 seq_line(m, '-', 40-namelen, namelen);
69796
69797- snprintf(ip, sizeof(ip), "[<%p>]",
69798+ snprintf(ip, sizeof(ip), "[<%pK>]",
69799 (void *)class->contention_point[i]);
69800 seq_printf(m, "%40s %14lu %29s %pS\n",
69801 name, stats->contention_point[i],
69802@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
69803 if (!i)
69804 seq_line(m, '-', 40-namelen, namelen);
69805
69806- snprintf(ip, sizeof(ip), "[<%p>]",
69807+ snprintf(ip, sizeof(ip), "[<%pK>]",
69808 (void *)class->contending_point[i]);
69809 seq_printf(m, "%40s %14lu %29s %pS\n",
69810 name, stats->contending_point[i],
69811diff --git a/kernel/module.c b/kernel/module.c
69812index 3e544f4..096cb73 100644
69813--- a/kernel/module.c
69814+++ b/kernel/module.c
69815@@ -59,6 +59,7 @@
69816 #include <linux/pfn.h>
69817 #include <linux/bsearch.h>
69818 #include <linux/fips.h>
69819+#include <linux/grsecurity.h>
69820 #include "module-internal.h"
69821
69822 #define CREATE_TRACE_POINTS
69823@@ -153,7 +154,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
69824
69825 /* Bounds of module allocation, for speeding __module_address.
69826 * Protected by module_mutex. */
69827-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
69828+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
69829+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
69830
69831 int register_module_notifier(struct notifier_block * nb)
69832 {
69833@@ -319,7 +321,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69834 return true;
69835
69836 list_for_each_entry_rcu(mod, &modules, list) {
69837- struct symsearch arr[] = {
69838+ struct symsearch modarr[] = {
69839 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
69840 NOT_GPL_ONLY, false },
69841 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
69842@@ -344,7 +346,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
69843 if (mod->state == MODULE_STATE_UNFORMED)
69844 continue;
69845
69846- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
69847+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
69848 return true;
69849 }
69850 return false;
69851@@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
69852 static int percpu_modalloc(struct module *mod,
69853 unsigned long size, unsigned long align)
69854 {
69855- if (align > PAGE_SIZE) {
69856+ if (align-1 >= PAGE_SIZE) {
69857 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
69858 mod->name, align, PAGE_SIZE);
69859 align = PAGE_SIZE;
69860@@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
69861 static ssize_t show_coresize(struct module_attribute *mattr,
69862 struct module_kobject *mk, char *buffer)
69863 {
69864- return sprintf(buffer, "%u\n", mk->mod->core_size);
69865+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
69866 }
69867
69868 static struct module_attribute modinfo_coresize =
69869@@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
69870 static ssize_t show_initsize(struct module_attribute *mattr,
69871 struct module_kobject *mk, char *buffer)
69872 {
69873- return sprintf(buffer, "%u\n", mk->mod->init_size);
69874+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
69875 }
69876
69877 static struct module_attribute modinfo_initsize =
69878@@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
69879 */
69880 #ifdef CONFIG_SYSFS
69881
69882-#ifdef CONFIG_KALLSYMS
69883+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
69884 static inline bool sect_empty(const Elf_Shdr *sect)
69885 {
69886 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
69887@@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
69888
69889 static void unset_module_core_ro_nx(struct module *mod)
69890 {
69891- set_page_attributes(mod->module_core + mod->core_text_size,
69892- mod->module_core + mod->core_size,
69893+ set_page_attributes(mod->module_core_rw,
69894+ mod->module_core_rw + mod->core_size_rw,
69895 set_memory_x);
69896- set_page_attributes(mod->module_core,
69897- mod->module_core + mod->core_ro_size,
69898+ set_page_attributes(mod->module_core_rx,
69899+ mod->module_core_rx + mod->core_size_rx,
69900 set_memory_rw);
69901 }
69902
69903 static void unset_module_init_ro_nx(struct module *mod)
69904 {
69905- set_page_attributes(mod->module_init + mod->init_text_size,
69906- mod->module_init + mod->init_size,
69907+ set_page_attributes(mod->module_init_rw,
69908+ mod->module_init_rw + mod->init_size_rw,
69909 set_memory_x);
69910- set_page_attributes(mod->module_init,
69911- mod->module_init + mod->init_ro_size,
69912+ set_page_attributes(mod->module_init_rx,
69913+ mod->module_init_rx + mod->init_size_rx,
69914 set_memory_rw);
69915 }
69916
69917@@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
69918 list_for_each_entry_rcu(mod, &modules, list) {
69919 if (mod->state == MODULE_STATE_UNFORMED)
69920 continue;
69921- if ((mod->module_core) && (mod->core_text_size)) {
69922- set_page_attributes(mod->module_core,
69923- mod->module_core + mod->core_text_size,
69924+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
69925+ set_page_attributes(mod->module_core_rx,
69926+ mod->module_core_rx + mod->core_size_rx,
69927 set_memory_rw);
69928 }
69929- if ((mod->module_init) && (mod->init_text_size)) {
69930- set_page_attributes(mod->module_init,
69931- mod->module_init + mod->init_text_size,
69932+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
69933+ set_page_attributes(mod->module_init_rx,
69934+ mod->module_init_rx + mod->init_size_rx,
69935 set_memory_rw);
69936 }
69937 }
69938@@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
69939 list_for_each_entry_rcu(mod, &modules, list) {
69940 if (mod->state == MODULE_STATE_UNFORMED)
69941 continue;
69942- if ((mod->module_core) && (mod->core_text_size)) {
69943- set_page_attributes(mod->module_core,
69944- mod->module_core + mod->core_text_size,
69945+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
69946+ set_page_attributes(mod->module_core_rx,
69947+ mod->module_core_rx + mod->core_size_rx,
69948 set_memory_ro);
69949 }
69950- if ((mod->module_init) && (mod->init_text_size)) {
69951- set_page_attributes(mod->module_init,
69952- mod->module_init + mod->init_text_size,
69953+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
69954+ set_page_attributes(mod->module_init_rx,
69955+ mod->module_init_rx + mod->init_size_rx,
69956 set_memory_ro);
69957 }
69958 }
69959@@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
69960
69961 /* This may be NULL, but that's OK */
69962 unset_module_init_ro_nx(mod);
69963- module_free(mod, mod->module_init);
69964+ module_free(mod, mod->module_init_rw);
69965+ module_free_exec(mod, mod->module_init_rx);
69966 kfree(mod->args);
69967 percpu_modfree(mod);
69968
69969 /* Free lock-classes: */
69970- lockdep_free_key_range(mod->module_core, mod->core_size);
69971+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
69972+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
69973
69974 /* Finally, free the core (containing the module structure) */
69975 unset_module_core_ro_nx(mod);
69976- module_free(mod, mod->module_core);
69977+ module_free_exec(mod, mod->module_core_rx);
69978+ module_free(mod, mod->module_core_rw);
69979
69980 #ifdef CONFIG_MPU
69981 update_protections(current->mm);
69982@@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
69983 int ret = 0;
69984 const struct kernel_symbol *ksym;
69985
69986+#ifdef CONFIG_GRKERNSEC_MODHARDEN
69987+ int is_fs_load = 0;
69988+ int register_filesystem_found = 0;
69989+ char *p;
69990+
69991+ p = strstr(mod->args, "grsec_modharden_fs");
69992+ if (p) {
69993+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
69994+ /* copy \0 as well */
69995+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
69996+ is_fs_load = 1;
69997+ }
69998+#endif
69999+
70000 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
70001 const char *name = info->strtab + sym[i].st_name;
70002
70003+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70004+ /* it's a real shame this will never get ripped and copied
70005+ upstream! ;(
70006+ */
70007+ if (is_fs_load && !strcmp(name, "register_filesystem"))
70008+ register_filesystem_found = 1;
70009+#endif
70010+
70011 switch (sym[i].st_shndx) {
70012 case SHN_COMMON:
70013 /* We compiled with -fno-common. These are not
70014@@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70015 ksym = resolve_symbol_wait(mod, info, name);
70016 /* Ok if resolved. */
70017 if (ksym && !IS_ERR(ksym)) {
70018+ pax_open_kernel();
70019 sym[i].st_value = ksym->value;
70020+ pax_close_kernel();
70021 break;
70022 }
70023
70024@@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
70025 secbase = (unsigned long)mod_percpu(mod);
70026 else
70027 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
70028+ pax_open_kernel();
70029 sym[i].st_value += secbase;
70030+ pax_close_kernel();
70031 break;
70032 }
70033 }
70034
70035+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70036+ if (is_fs_load && !register_filesystem_found) {
70037+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
70038+ ret = -EPERM;
70039+ }
70040+#endif
70041+
70042 return ret;
70043 }
70044
70045@@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
70046 || s->sh_entsize != ~0UL
70047 || strstarts(sname, ".init"))
70048 continue;
70049- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
70050+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70051+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
70052+ else
70053+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
70054 pr_debug("\t%s\n", sname);
70055 }
70056- switch (m) {
70057- case 0: /* executable */
70058- mod->core_size = debug_align(mod->core_size);
70059- mod->core_text_size = mod->core_size;
70060- break;
70061- case 1: /* RO: text and ro-data */
70062- mod->core_size = debug_align(mod->core_size);
70063- mod->core_ro_size = mod->core_size;
70064- break;
70065- case 3: /* whole core */
70066- mod->core_size = debug_align(mod->core_size);
70067- break;
70068- }
70069 }
70070
70071 pr_debug("Init section allocation order:\n");
70072@@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
70073 || s->sh_entsize != ~0UL
70074 || !strstarts(sname, ".init"))
70075 continue;
70076- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
70077- | INIT_OFFSET_MASK);
70078+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
70079+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
70080+ else
70081+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
70082+ s->sh_entsize |= INIT_OFFSET_MASK;
70083 pr_debug("\t%s\n", sname);
70084 }
70085- switch (m) {
70086- case 0: /* executable */
70087- mod->init_size = debug_align(mod->init_size);
70088- mod->init_text_size = mod->init_size;
70089- break;
70090- case 1: /* RO: text and ro-data */
70091- mod->init_size = debug_align(mod->init_size);
70092- mod->init_ro_size = mod->init_size;
70093- break;
70094- case 3: /* whole init */
70095- mod->init_size = debug_align(mod->init_size);
70096- break;
70097- }
70098 }
70099 }
70100
70101@@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70102
70103 /* Put symbol section at end of init part of module. */
70104 symsect->sh_flags |= SHF_ALLOC;
70105- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
70106+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
70107 info->index.sym) | INIT_OFFSET_MASK;
70108 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
70109
70110@@ -2326,13 +2344,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
70111 }
70112
70113 /* Append room for core symbols at end of core part. */
70114- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
70115- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
70116- mod->core_size += strtab_size;
70117+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
70118+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
70119+ mod->core_size_rx += strtab_size;
70120
70121 /* Put string table section at end of init part of module. */
70122 strsect->sh_flags |= SHF_ALLOC;
70123- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
70124+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
70125 info->index.str) | INIT_OFFSET_MASK;
70126 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
70127 }
70128@@ -2350,12 +2368,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70129 /* Make sure we get permanent strtab: don't use info->strtab. */
70130 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
70131
70132+ pax_open_kernel();
70133+
70134 /* Set types up while we still have access to sections. */
70135 for (i = 0; i < mod->num_symtab; i++)
70136 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
70137
70138- mod->core_symtab = dst = mod->module_core + info->symoffs;
70139- mod->core_strtab = s = mod->module_core + info->stroffs;
70140+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
70141+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
70142 src = mod->symtab;
70143 *s++ = 0;
70144 for (ndst = i = 0; i < mod->num_symtab; i++) {
70145@@ -2368,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
70146 }
70147 }
70148 mod->core_num_syms = ndst;
70149+
70150+ pax_close_kernel();
70151 }
70152 #else
70153 static inline void layout_symtab(struct module *mod, struct load_info *info)
70154@@ -2401,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
70155 return size == 0 ? NULL : vmalloc_exec(size);
70156 }
70157
70158-static void *module_alloc_update_bounds(unsigned long size)
70159+static void *module_alloc_update_bounds_rw(unsigned long size)
70160 {
70161 void *ret = module_alloc(size);
70162
70163 if (ret) {
70164 mutex_lock(&module_mutex);
70165 /* Update module bounds. */
70166- if ((unsigned long)ret < module_addr_min)
70167- module_addr_min = (unsigned long)ret;
70168- if ((unsigned long)ret + size > module_addr_max)
70169- module_addr_max = (unsigned long)ret + size;
70170+ if ((unsigned long)ret < module_addr_min_rw)
70171+ module_addr_min_rw = (unsigned long)ret;
70172+ if ((unsigned long)ret + size > module_addr_max_rw)
70173+ module_addr_max_rw = (unsigned long)ret + size;
70174+ mutex_unlock(&module_mutex);
70175+ }
70176+ return ret;
70177+}
70178+
70179+static void *module_alloc_update_bounds_rx(unsigned long size)
70180+{
70181+ void *ret = module_alloc_exec(size);
70182+
70183+ if (ret) {
70184+ mutex_lock(&module_mutex);
70185+ /* Update module bounds. */
70186+ if ((unsigned long)ret < module_addr_min_rx)
70187+ module_addr_min_rx = (unsigned long)ret;
70188+ if ((unsigned long)ret + size > module_addr_max_rx)
70189+ module_addr_max_rx = (unsigned long)ret + size;
70190 mutex_unlock(&module_mutex);
70191 }
70192 return ret;
70193@@ -2630,8 +2668,14 @@ static struct module *setup_load_info(struct load_info *info)
70194 static int check_modinfo(struct module *mod, struct load_info *info)
70195 {
70196 const char *modmagic = get_modinfo(info, "vermagic");
70197+ const char *license = get_modinfo(info, "license");
70198 int err;
70199
70200+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
70201+ if (!license || !license_is_gpl_compatible(license))
70202+ return -ENOEXEC;
70203+#endif
70204+
70205 /* This is allowed: modprobe --force will invalidate it. */
70206 if (!modmagic) {
70207 err = try_to_force_load(mod, "bad vermagic");
70208@@ -2654,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
70209 }
70210
70211 /* Set up license info based on the info section */
70212- set_license(mod, get_modinfo(info, "license"));
70213+ set_license(mod, license);
70214
70215 return 0;
70216 }
70217@@ -2748,7 +2792,7 @@ static int move_module(struct module *mod, struct load_info *info)
70218 void *ptr;
70219
70220 /* Do the allocs. */
70221- ptr = module_alloc_update_bounds(mod->core_size);
70222+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
70223 /*
70224 * The pointer to this block is stored in the module structure
70225 * which is inside the block. Just mark it as not being a
70226@@ -2758,23 +2802,50 @@ static int move_module(struct module *mod, struct load_info *info)
70227 if (!ptr)
70228 return -ENOMEM;
70229
70230- memset(ptr, 0, mod->core_size);
70231- mod->module_core = ptr;
70232+ memset(ptr, 0, mod->core_size_rw);
70233+ mod->module_core_rw = ptr;
70234
70235- ptr = module_alloc_update_bounds(mod->init_size);
70236+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
70237 /*
70238 * The pointer to this block is stored in the module structure
70239 * which is inside the block. This block doesn't need to be
70240 * scanned as it contains data and code that will be freed
70241 * after the module is initialized.
70242 */
70243- kmemleak_ignore(ptr);
70244- if (!ptr && mod->init_size) {
70245- module_free(mod, mod->module_core);
70246+ kmemleak_not_leak(ptr);
70247+ if (!ptr && mod->init_size_rw) {
70248+ module_free(mod, mod->module_core_rw);
70249 return -ENOMEM;
70250 }
70251- memset(ptr, 0, mod->init_size);
70252- mod->module_init = ptr;
70253+ memset(ptr, 0, mod->init_size_rw);
70254+ mod->module_init_rw = ptr;
70255+
70256+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
70257+ kmemleak_not_leak(ptr);
70258+ if (!ptr) {
70259+ module_free(mod, mod->module_init_rw);
70260+ module_free(mod, mod->module_core_rw);
70261+ return -ENOMEM;
70262+ }
70263+
70264+ pax_open_kernel();
70265+ memset(ptr, 0, mod->core_size_rx);
70266+ pax_close_kernel();
70267+ mod->module_core_rx = ptr;
70268+
70269+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
70270+ kmemleak_not_leak(ptr);
70271+ if (!ptr && mod->init_size_rx) {
70272+ module_free_exec(mod, mod->module_core_rx);
70273+ module_free(mod, mod->module_init_rw);
70274+ module_free(mod, mod->module_core_rw);
70275+ return -ENOMEM;
70276+ }
70277+
70278+ pax_open_kernel();
70279+ memset(ptr, 0, mod->init_size_rx);
70280+ pax_close_kernel();
70281+ mod->module_init_rx = ptr;
70282
70283 /* Transfer each section which specifies SHF_ALLOC */
70284 pr_debug("final section addresses:\n");
70285@@ -2785,16 +2856,45 @@ static int move_module(struct module *mod, struct load_info *info)
70286 if (!(shdr->sh_flags & SHF_ALLOC))
70287 continue;
70288
70289- if (shdr->sh_entsize & INIT_OFFSET_MASK)
70290- dest = mod->module_init
70291- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70292- else
70293- dest = mod->module_core + shdr->sh_entsize;
70294+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
70295+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70296+ dest = mod->module_init_rw
70297+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70298+ else
70299+ dest = mod->module_init_rx
70300+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
70301+ } else {
70302+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
70303+ dest = mod->module_core_rw + shdr->sh_entsize;
70304+ else
70305+ dest = mod->module_core_rx + shdr->sh_entsize;
70306+ }
70307+
70308+ if (shdr->sh_type != SHT_NOBITS) {
70309+
70310+#ifdef CONFIG_PAX_KERNEXEC
70311+#ifdef CONFIG_X86_64
70312+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
70313+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
70314+#endif
70315+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
70316+ pax_open_kernel();
70317+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70318+ pax_close_kernel();
70319+ } else
70320+#endif
70321
70322- if (shdr->sh_type != SHT_NOBITS)
70323 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
70324+ }
70325 /* Update sh_addr to point to copy in image. */
70326- shdr->sh_addr = (unsigned long)dest;
70327+
70328+#ifdef CONFIG_PAX_KERNEXEC
70329+ if (shdr->sh_flags & SHF_EXECINSTR)
70330+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
70331+ else
70332+#endif
70333+
70334+ shdr->sh_addr = (unsigned long)dest;
70335 pr_debug("\t0x%lx %s\n",
70336 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
70337 }
70338@@ -2849,12 +2949,12 @@ static void flush_module_icache(const struct module *mod)
70339 * Do it before processing of module parameters, so the module
70340 * can provide parameter accessor functions of its own.
70341 */
70342- if (mod->module_init)
70343- flush_icache_range((unsigned long)mod->module_init,
70344- (unsigned long)mod->module_init
70345- + mod->init_size);
70346- flush_icache_range((unsigned long)mod->module_core,
70347- (unsigned long)mod->module_core + mod->core_size);
70348+ if (mod->module_init_rx)
70349+ flush_icache_range((unsigned long)mod->module_init_rx,
70350+ (unsigned long)mod->module_init_rx
70351+ + mod->init_size_rx);
70352+ flush_icache_range((unsigned long)mod->module_core_rx,
70353+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
70354
70355 set_fs(old_fs);
70356 }
70357@@ -2924,8 +3024,10 @@ out:
70358 static void module_deallocate(struct module *mod, struct load_info *info)
70359 {
70360 percpu_modfree(mod);
70361- module_free(mod, mod->module_init);
70362- module_free(mod, mod->module_core);
70363+ module_free_exec(mod, mod->module_init_rx);
70364+ module_free_exec(mod, mod->module_core_rx);
70365+ module_free(mod, mod->module_init_rw);
70366+ module_free(mod, mod->module_core_rw);
70367 }
70368
70369 int __weak module_finalize(const Elf_Ehdr *hdr,
70370@@ -2938,7 +3040,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
70371 static int post_relocation(struct module *mod, const struct load_info *info)
70372 {
70373 /* Sort exception table now relocations are done. */
70374+ pax_open_kernel();
70375 sort_extable(mod->extable, mod->extable + mod->num_exentries);
70376+ pax_close_kernel();
70377
70378 /* Copy relocated percpu area over. */
70379 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
70380@@ -3036,9 +3140,38 @@ again:
70381 if (err)
70382 goto free_unload;
70383
70384+ /* Now copy in args */
70385+ mod->args = strndup_user(uargs, ~0UL >> 1);
70386+ if (IS_ERR(mod->args)) {
70387+ err = PTR_ERR(mod->args);
70388+ goto free_unload;
70389+ }
70390+
70391 /* Set up MODINFO_ATTR fields */
70392 setup_modinfo(mod, &info);
70393
70394+#ifdef CONFIG_GRKERNSEC_MODHARDEN
70395+ {
70396+ char *p, *p2;
70397+
70398+ if (strstr(mod->args, "grsec_modharden_netdev")) {
70399+ 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);
70400+ err = -EPERM;
70401+ goto free_modinfo;
70402+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
70403+ p += sizeof("grsec_modharden_normal") - 1;
70404+ p2 = strstr(p, "_");
70405+ if (p2) {
70406+ *p2 = '\0';
70407+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
70408+ *p2 = '_';
70409+ }
70410+ err = -EPERM;
70411+ goto free_modinfo;
70412+ }
70413+ }
70414+#endif
70415+
70416 /* Fix up syms, so that st_value is a pointer to location. */
70417 err = simplify_symbols(mod, &info);
70418 if (err < 0)
70419@@ -3104,11 +3237,11 @@ again:
70420 mutex_unlock(&module_mutex);
70421 dynamic_debug_remove(info.debug);
70422 synchronize_sched();
70423- kfree(mod->args);
70424 free_arch_cleanup:
70425 module_arch_cleanup(mod);
70426 free_modinfo:
70427 free_modinfo(mod);
70428+ kfree(mod->args);
70429 free_unload:
70430 module_unload_free(mod);
70431 unlink_mod:
70432@@ -3155,16 +3288,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70433 MODULE_STATE_COMING, mod);
70434
70435 /* Set RO and NX regions for core */
70436- set_section_ro_nx(mod->module_core,
70437- mod->core_text_size,
70438- mod->core_ro_size,
70439- mod->core_size);
70440+ set_section_ro_nx(mod->module_core_rx,
70441+ mod->core_size_rx,
70442+ mod->core_size_rx,
70443+ mod->core_size_rx);
70444
70445 /* Set RO and NX regions for init */
70446- set_section_ro_nx(mod->module_init,
70447- mod->init_text_size,
70448- mod->init_ro_size,
70449- mod->init_size);
70450+ set_section_ro_nx(mod->module_init_rx,
70451+ mod->init_size_rx,
70452+ mod->init_size_rx,
70453+ mod->init_size_rx);
70454
70455 do_mod_ctors(mod);
70456 /* Start the module */
70457@@ -3209,11 +3342,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
70458 mod->strtab = mod->core_strtab;
70459 #endif
70460 unset_module_init_ro_nx(mod);
70461- module_free(mod, mod->module_init);
70462- mod->module_init = NULL;
70463- mod->init_size = 0;
70464- mod->init_ro_size = 0;
70465- mod->init_text_size = 0;
70466+ module_free(mod, mod->module_init_rw);
70467+ module_free_exec(mod, mod->module_init_rx);
70468+ mod->module_init_rw = NULL;
70469+ mod->module_init_rx = NULL;
70470+ mod->init_size_rw = 0;
70471+ mod->init_size_rx = 0;
70472 mutex_unlock(&module_mutex);
70473 wake_up_all(&module_wq);
70474
70475@@ -3245,10 +3379,16 @@ static const char *get_ksymbol(struct module *mod,
70476 unsigned long nextval;
70477
70478 /* At worse, next value is at end of module */
70479- if (within_module_init(addr, mod))
70480- nextval = (unsigned long)mod->module_init+mod->init_text_size;
70481+ if (within_module_init_rx(addr, mod))
70482+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
70483+ else if (within_module_init_rw(addr, mod))
70484+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
70485+ else if (within_module_core_rx(addr, mod))
70486+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
70487+ else if (within_module_core_rw(addr, mod))
70488+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
70489 else
70490- nextval = (unsigned long)mod->module_core+mod->core_text_size;
70491+ return NULL;
70492
70493 /* Scan for closest preceding symbol, and next symbol. (ELF
70494 starts real symbols at 1). */
70495@@ -3501,7 +3641,7 @@ static int m_show(struct seq_file *m, void *p)
70496 return 0;
70497
70498 seq_printf(m, "%s %u",
70499- mod->name, mod->init_size + mod->core_size);
70500+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
70501 print_unload_info(m, mod);
70502
70503 /* Informative for users. */
70504@@ -3510,7 +3650,7 @@ static int m_show(struct seq_file *m, void *p)
70505 mod->state == MODULE_STATE_COMING ? "Loading":
70506 "Live");
70507 /* Used by oprofile and other similar tools. */
70508- seq_printf(m, " 0x%pK", mod->module_core);
70509+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
70510
70511 /* Taints info */
70512 if (mod->taints)
70513@@ -3546,7 +3686,17 @@ static const struct file_operations proc_modules_operations = {
70514
70515 static int __init proc_modules_init(void)
70516 {
70517+#ifndef CONFIG_GRKERNSEC_HIDESYM
70518+#ifdef CONFIG_GRKERNSEC_PROC_USER
70519+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70520+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
70521+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
70522+#else
70523 proc_create("modules", 0, NULL, &proc_modules_operations);
70524+#endif
70525+#else
70526+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
70527+#endif
70528 return 0;
70529 }
70530 module_init(proc_modules_init);
70531@@ -3607,14 +3757,14 @@ struct module *__module_address(unsigned long addr)
70532 {
70533 struct module *mod;
70534
70535- if (addr < module_addr_min || addr > module_addr_max)
70536+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
70537+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
70538 return NULL;
70539
70540 list_for_each_entry_rcu(mod, &modules, list) {
70541 if (mod->state == MODULE_STATE_UNFORMED)
70542 continue;
70543- if (within_module_core(addr, mod)
70544- || within_module_init(addr, mod))
70545+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
70546 return mod;
70547 }
70548 return NULL;
70549@@ -3649,11 +3799,20 @@ bool is_module_text_address(unsigned long addr)
70550 */
70551 struct module *__module_text_address(unsigned long addr)
70552 {
70553- struct module *mod = __module_address(addr);
70554+ struct module *mod;
70555+
70556+#ifdef CONFIG_X86_32
70557+ addr = ktla_ktva(addr);
70558+#endif
70559+
70560+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
70561+ return NULL;
70562+
70563+ mod = __module_address(addr);
70564+
70565 if (mod) {
70566 /* Make sure it's within the text section. */
70567- if (!within(addr, mod->module_init, mod->init_text_size)
70568- && !within(addr, mod->module_core, mod->core_text_size))
70569+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
70570 mod = NULL;
70571 }
70572 return mod;
70573diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
70574index 7e3443f..b2a1e6b 100644
70575--- a/kernel/mutex-debug.c
70576+++ b/kernel/mutex-debug.c
70577@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
70578 }
70579
70580 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70581- struct thread_info *ti)
70582+ struct task_struct *task)
70583 {
70584 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
70585
70586 /* Mark the current thread as blocked on the lock: */
70587- ti->task->blocked_on = waiter;
70588+ task->blocked_on = waiter;
70589 }
70590
70591 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70592- struct thread_info *ti)
70593+ struct task_struct *task)
70594 {
70595 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
70596- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
70597- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
70598- ti->task->blocked_on = NULL;
70599+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
70600+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
70601+ task->blocked_on = NULL;
70602
70603 list_del_init(&waiter->list);
70604 waiter->task = NULL;
70605diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
70606index 0799fd3..d06ae3b 100644
70607--- a/kernel/mutex-debug.h
70608+++ b/kernel/mutex-debug.h
70609@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
70610 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
70611 extern void debug_mutex_add_waiter(struct mutex *lock,
70612 struct mutex_waiter *waiter,
70613- struct thread_info *ti);
70614+ struct task_struct *task);
70615 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
70616- struct thread_info *ti);
70617+ struct task_struct *task);
70618 extern void debug_mutex_unlock(struct mutex *lock);
70619 extern void debug_mutex_init(struct mutex *lock, const char *name,
70620 struct lock_class_key *key);
70621diff --git a/kernel/mutex.c b/kernel/mutex.c
70622index a307cc9..27fd2e9 100644
70623--- a/kernel/mutex.c
70624+++ b/kernel/mutex.c
70625@@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70626 spin_lock_mutex(&lock->wait_lock, flags);
70627
70628 debug_mutex_lock_common(lock, &waiter);
70629- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
70630+ debug_mutex_add_waiter(lock, &waiter, task);
70631
70632 /* add waiting tasks to the end of the waitqueue (FIFO): */
70633 list_add_tail(&waiter.list, &lock->wait_list);
70634@@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70635 * TASK_UNINTERRUPTIBLE case.)
70636 */
70637 if (unlikely(signal_pending_state(state, task))) {
70638- mutex_remove_waiter(lock, &waiter,
70639- task_thread_info(task));
70640+ mutex_remove_waiter(lock, &waiter, task);
70641 mutex_release(&lock->dep_map, 1, ip);
70642 spin_unlock_mutex(&lock->wait_lock, flags);
70643
70644@@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
70645 done:
70646 lock_acquired(&lock->dep_map, ip);
70647 /* got the lock - rejoice! */
70648- mutex_remove_waiter(lock, &waiter, current_thread_info());
70649+ mutex_remove_waiter(lock, &waiter, task);
70650 mutex_set_owner(lock);
70651
70652 /* set it to 0 if there are no waiters left: */
70653diff --git a/kernel/notifier.c b/kernel/notifier.c
70654index 2d5cc4c..d9ea600 100644
70655--- a/kernel/notifier.c
70656+++ b/kernel/notifier.c
70657@@ -5,6 +5,7 @@
70658 #include <linux/rcupdate.h>
70659 #include <linux/vmalloc.h>
70660 #include <linux/reboot.h>
70661+#include <linux/mm.h>
70662
70663 /*
70664 * Notifier list for kernel code which wants to be called
70665@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
70666 while ((*nl) != NULL) {
70667 if (n->priority > (*nl)->priority)
70668 break;
70669- nl = &((*nl)->next);
70670+ nl = (struct notifier_block **)&((*nl)->next);
70671 }
70672- n->next = *nl;
70673+ pax_open_kernel();
70674+ *(const void **)&n->next = *nl;
70675 rcu_assign_pointer(*nl, n);
70676+ pax_close_kernel();
70677 return 0;
70678 }
70679
70680@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
70681 return 0;
70682 if (n->priority > (*nl)->priority)
70683 break;
70684- nl = &((*nl)->next);
70685+ nl = (struct notifier_block **)&((*nl)->next);
70686 }
70687- n->next = *nl;
70688+ pax_open_kernel();
70689+ *(const void **)&n->next = *nl;
70690 rcu_assign_pointer(*nl, n);
70691+ pax_close_kernel();
70692 return 0;
70693 }
70694
70695@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
70696 {
70697 while ((*nl) != NULL) {
70698 if ((*nl) == n) {
70699+ pax_open_kernel();
70700 rcu_assign_pointer(*nl, n->next);
70701+ pax_close_kernel();
70702 return 0;
70703 }
70704- nl = &((*nl)->next);
70705+ nl = (struct notifier_block **)&((*nl)->next);
70706 }
70707 return -ENOENT;
70708 }
70709diff --git a/kernel/panic.c b/kernel/panic.c
70710index e1b2822..5edc1d9 100644
70711--- a/kernel/panic.c
70712+++ b/kernel/panic.c
70713@@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
70714 const char *board;
70715
70716 printk(KERN_WARNING "------------[ cut here ]------------\n");
70717- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
70718+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
70719 board = dmi_get_system_info(DMI_PRODUCT_NAME);
70720 if (board)
70721 printk(KERN_WARNING "Hardware name: %s\n", board);
70722@@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
70723 */
70724 void __stack_chk_fail(void)
70725 {
70726- panic("stack-protector: Kernel stack is corrupted in: %p\n",
70727+ dump_stack();
70728+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
70729 __builtin_return_address(0));
70730 }
70731 EXPORT_SYMBOL(__stack_chk_fail);
70732diff --git a/kernel/pid.c b/kernel/pid.c
70733index aebd4f5..1693c13 100644
70734--- a/kernel/pid.c
70735+++ b/kernel/pid.c
70736@@ -33,6 +33,7 @@
70737 #include <linux/rculist.h>
70738 #include <linux/bootmem.h>
70739 #include <linux/hash.h>
70740+#include <linux/security.h>
70741 #include <linux/pid_namespace.h>
70742 #include <linux/init_task.h>
70743 #include <linux/syscalls.h>
70744@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
70745
70746 int pid_max = PID_MAX_DEFAULT;
70747
70748-#define RESERVED_PIDS 300
70749+#define RESERVED_PIDS 500
70750
70751 int pid_max_min = RESERVED_PIDS + 1;
70752 int pid_max_max = PID_MAX_LIMIT;
70753@@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
70754 */
70755 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
70756 {
70757+ struct task_struct *task;
70758+
70759 rcu_lockdep_assert(rcu_read_lock_held(),
70760 "find_task_by_pid_ns() needs rcu_read_lock()"
70761 " protection");
70762- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70763+
70764+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
70765+
70766+ if (gr_pid_is_chrooted(task))
70767+ return NULL;
70768+
70769+ return task;
70770 }
70771
70772 struct task_struct *find_task_by_vpid(pid_t vnr)
70773@@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
70774 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
70775 }
70776
70777+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
70778+{
70779+ rcu_lockdep_assert(rcu_read_lock_held(),
70780+ "find_task_by_pid_ns() needs rcu_read_lock()"
70781+ " protection");
70782+ return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
70783+}
70784+
70785 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
70786 {
70787 struct pid *pid;
70788diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
70789index 125cb67..2e5c8ad 100644
70790--- a/kernel/posix-cpu-timers.c
70791+++ b/kernel/posix-cpu-timers.c
70792@@ -6,9 +6,11 @@
70793 #include <linux/posix-timers.h>
70794 #include <linux/errno.h>
70795 #include <linux/math64.h>
70796+#include <linux/security.h>
70797 #include <asm/uaccess.h>
70798 #include <linux/kernel_stat.h>
70799 #include <trace/events/timer.h>
70800+#include <linux/random.h>
70801
70802 /*
70803 * Called after updating RLIMIT_CPU to run cpu timer and update
70804@@ -494,6 +496,8 @@ static void cleanup_timers(struct list_head *head,
70805 */
70806 void posix_cpu_timers_exit(struct task_struct *tsk)
70807 {
70808+ add_device_randomness((const void*) &tsk->se.sum_exec_runtime,
70809+ sizeof(unsigned long long));
70810 cleanup_timers(tsk->cpu_timers,
70811 tsk->utime, tsk->stime, tsk->se.sum_exec_runtime);
70812
70813@@ -1578,14 +1582,14 @@ struct k_clock clock_posix_cpu = {
70814
70815 static __init int init_posix_cpu_timers(void)
70816 {
70817- struct k_clock process = {
70818+ static struct k_clock process = {
70819 .clock_getres = process_cpu_clock_getres,
70820 .clock_get = process_cpu_clock_get,
70821 .timer_create = process_cpu_timer_create,
70822 .nsleep = process_cpu_nsleep,
70823 .nsleep_restart = process_cpu_nsleep_restart,
70824 };
70825- struct k_clock thread = {
70826+ static struct k_clock thread = {
70827 .clock_getres = thread_cpu_clock_getres,
70828 .clock_get = thread_cpu_clock_get,
70829 .timer_create = thread_cpu_timer_create,
70830diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
70831index 69185ae..cc2847a 100644
70832--- a/kernel/posix-timers.c
70833+++ b/kernel/posix-timers.c
70834@@ -43,6 +43,7 @@
70835 #include <linux/idr.h>
70836 #include <linux/posix-clock.h>
70837 #include <linux/posix-timers.h>
70838+#include <linux/grsecurity.h>
70839 #include <linux/syscalls.h>
70840 #include <linux/wait.h>
70841 #include <linux/workqueue.h>
70842@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
70843 * which we beg off on and pass to do_sys_settimeofday().
70844 */
70845
70846-static struct k_clock posix_clocks[MAX_CLOCKS];
70847+static struct k_clock *posix_clocks[MAX_CLOCKS];
70848
70849 /*
70850 * These ones are defined below.
70851@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
70852 */
70853 static __init int init_posix_timers(void)
70854 {
70855- struct k_clock clock_realtime = {
70856+ static struct k_clock clock_realtime = {
70857 .clock_getres = hrtimer_get_res,
70858 .clock_get = posix_clock_realtime_get,
70859 .clock_set = posix_clock_realtime_set,
70860@@ -239,7 +240,7 @@ 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 = {
70865+ static struct k_clock clock_monotonic = {
70866 .clock_getres = hrtimer_get_res,
70867 .clock_get = posix_ktime_get_ts,
70868 .nsleep = common_nsleep,
70869@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
70870 .timer_get = common_timer_get,
70871 .timer_del = common_timer_del,
70872 };
70873- struct k_clock clock_monotonic_raw = {
70874+ static struct k_clock clock_monotonic_raw = {
70875 .clock_getres = hrtimer_get_res,
70876 .clock_get = posix_get_monotonic_raw,
70877 };
70878- struct k_clock clock_realtime_coarse = {
70879+ static struct k_clock clock_realtime_coarse = {
70880 .clock_getres = posix_get_coarse_res,
70881 .clock_get = posix_get_realtime_coarse,
70882 };
70883- struct k_clock clock_monotonic_coarse = {
70884+ static struct k_clock clock_monotonic_coarse = {
70885 .clock_getres = posix_get_coarse_res,
70886 .clock_get = posix_get_monotonic_coarse,
70887 };
70888- struct k_clock clock_boottime = {
70889+ static struct k_clock clock_boottime = {
70890 .clock_getres = hrtimer_get_res,
70891 .clock_get = posix_get_boottime,
70892 .nsleep = common_nsleep,
70893@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
70894 return;
70895 }
70896
70897- posix_clocks[clock_id] = *new_clock;
70898+ posix_clocks[clock_id] = new_clock;
70899 }
70900 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
70901
70902@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
70903 return (id & CLOCKFD_MASK) == CLOCKFD ?
70904 &clock_posix_dynamic : &clock_posix_cpu;
70905
70906- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
70907+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
70908 return NULL;
70909- return &posix_clocks[id];
70910+ return posix_clocks[id];
70911 }
70912
70913 static int common_timer_create(struct k_itimer *new_timer)
70914@@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
70915 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
70916 return -EFAULT;
70917
70918+ /* only the CLOCK_REALTIME clock can be set, all other clocks
70919+ have their clock_set fptr set to a nosettime dummy function
70920+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
70921+ call common_clock_set, which calls do_sys_settimeofday, which
70922+ we hook
70923+ */
70924+
70925 return kc->clock_set(which_clock, &new_tp);
70926 }
70927
70928diff --git a/kernel/power/process.c b/kernel/power/process.c
70929index 87da817..30ddd13 100644
70930--- a/kernel/power/process.c
70931+++ b/kernel/power/process.c
70932@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
70933 u64 elapsed_csecs64;
70934 unsigned int elapsed_csecs;
70935 bool wakeup = false;
70936+ bool timedout = false;
70937
70938 do_gettimeofday(&start);
70939
70940@@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
70941
70942 while (true) {
70943 todo = 0;
70944+ if (time_after(jiffies, end_time))
70945+ timedout = true;
70946 read_lock(&tasklist_lock);
70947 do_each_thread(g, p) {
70948 if (p == current || !freeze_task(p))
70949@@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
70950 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
70951 * transition can't race with task state testing here.
70952 */
70953- if (!task_is_stopped_or_traced(p) &&
70954- !freezer_should_skip(p))
70955+ if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
70956 todo++;
70957+ if (timedout) {
70958+ printk(KERN_ERR "Task refusing to freeze:\n");
70959+ sched_show_task(p);
70960+ }
70961+ }
70962 } while_each_thread(g, p);
70963 read_unlock(&tasklist_lock);
70964
70965@@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
70966 todo += wq_busy;
70967 }
70968
70969- if (!todo || time_after(jiffies, end_time))
70970+ if (!todo || timedout)
70971 break;
70972
70973 if (pm_wakeup_pending()) {
70974diff --git a/kernel/printk.c b/kernel/printk.c
70975index f8e0b5a..dda2a5c 100644
70976--- a/kernel/printk.c
70977+++ b/kernel/printk.c
70978@@ -817,6 +817,11 @@ static int check_syslog_permissions(int type, bool from_file)
70979 if (from_file && type != SYSLOG_ACTION_OPEN)
70980 return 0;
70981
70982+#ifdef CONFIG_GRKERNSEC_DMESG
70983+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
70984+ return -EPERM;
70985+#endif
70986+
70987 if (syslog_action_restricted(type)) {
70988 if (capable(CAP_SYSLOG))
70989 return 0;
70990diff --git a/kernel/profile.c b/kernel/profile.c
70991index 76b8e77..a2930e8 100644
70992--- a/kernel/profile.c
70993+++ b/kernel/profile.c
70994@@ -39,7 +39,7 @@ struct profile_hit {
70995 /* Oprofile timer tick hook */
70996 static int (*timer_hook)(struct pt_regs *) __read_mostly;
70997
70998-static atomic_t *prof_buffer;
70999+static atomic_unchecked_t *prof_buffer;
71000 static unsigned long prof_len, prof_shift;
71001
71002 int prof_on __read_mostly;
71003@@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
71004 hits[i].pc = 0;
71005 continue;
71006 }
71007- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71008+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71009 hits[i].hits = hits[i].pc = 0;
71010 }
71011 }
71012@@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71013 * Add the current hit(s) and flush the write-queue out
71014 * to the global buffer:
71015 */
71016- atomic_add(nr_hits, &prof_buffer[pc]);
71017+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
71018 for (i = 0; i < NR_PROFILE_HIT; ++i) {
71019- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
71020+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
71021 hits[i].pc = hits[i].hits = 0;
71022 }
71023 out:
71024@@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
71025 {
71026 unsigned long pc;
71027 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
71028- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71029+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
71030 }
71031 #endif /* !CONFIG_SMP */
71032
71033@@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
71034 return -EFAULT;
71035 buf++; p++; count--; read++;
71036 }
71037- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
71038+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
71039 if (copy_to_user(buf, (void *)pnt, count))
71040 return -EFAULT;
71041 read += count;
71042@@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
71043 }
71044 #endif
71045 profile_discard_flip_buffers();
71046- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
71047+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
71048 return count;
71049 }
71050
71051diff --git a/kernel/ptrace.c b/kernel/ptrace.c
71052index fbea91d..9bf15e8 100644
71053--- a/kernel/ptrace.c
71054+++ b/kernel/ptrace.c
71055@@ -319,7 +319,7 @@ static int ptrace_attach(struct task_struct *task, long request,
71056
71057 if (seize)
71058 flags |= PT_SEIZED;
71059- if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
71060+ if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
71061 flags |= PT_PTRACE_CAP;
71062 task->ptrace = flags;
71063
71064@@ -526,7 +526,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
71065 break;
71066 return -EIO;
71067 }
71068- if (copy_to_user(dst, buf, retval))
71069+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
71070 return -EFAULT;
71071 copied += retval;
71072 src += retval;
71073@@ -711,7 +711,7 @@ int ptrace_request(struct task_struct *child, long request,
71074 bool seized = child->ptrace & PT_SEIZED;
71075 int ret = -EIO;
71076 siginfo_t siginfo, *si;
71077- void __user *datavp = (void __user *) data;
71078+ void __user *datavp = (__force void __user *) data;
71079 unsigned long __user *datalp = datavp;
71080 unsigned long flags;
71081
71082@@ -913,14 +913,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
71083 goto out;
71084 }
71085
71086+ if (gr_handle_ptrace(child, request)) {
71087+ ret = -EPERM;
71088+ goto out_put_task_struct;
71089+ }
71090+
71091 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71092 ret = ptrace_attach(child, request, addr, data);
71093 /*
71094 * Some architectures need to do book-keeping after
71095 * a ptrace attach.
71096 */
71097- if (!ret)
71098+ if (!ret) {
71099 arch_ptrace_attach(child);
71100+ gr_audit_ptrace(child);
71101+ }
71102 goto out_put_task_struct;
71103 }
71104
71105@@ -948,7 +955,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
71106 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
71107 if (copied != sizeof(tmp))
71108 return -EIO;
71109- return put_user(tmp, (unsigned long __user *)data);
71110+ return put_user(tmp, (__force unsigned long __user *)data);
71111 }
71112
71113 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
71114@@ -1058,14 +1065,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
71115 goto out;
71116 }
71117
71118+ if (gr_handle_ptrace(child, request)) {
71119+ ret = -EPERM;
71120+ goto out_put_task_struct;
71121+ }
71122+
71123 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71124 ret = ptrace_attach(child, request, addr, data);
71125 /*
71126 * Some architectures need to do book-keeping after
71127 * a ptrace attach.
71128 */
71129- if (!ret)
71130+ if (!ret) {
71131 arch_ptrace_attach(child);
71132+ gr_audit_ptrace(child);
71133+ }
71134 goto out_put_task_struct;
71135 }
71136
71137diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
71138index e4c6a59..c86621a 100644
71139--- a/kernel/rcutiny.c
71140+++ b/kernel/rcutiny.c
71141@@ -46,7 +46,7 @@
71142 struct rcu_ctrlblk;
71143 static void invoke_rcu_callbacks(void);
71144 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
71145-static void rcu_process_callbacks(struct softirq_action *unused);
71146+static void rcu_process_callbacks(void);
71147 static void __call_rcu(struct rcu_head *head,
71148 void (*func)(struct rcu_head *rcu),
71149 struct rcu_ctrlblk *rcp);
71150@@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
71151 rcu_is_callbacks_kthread()));
71152 }
71153
71154-static void rcu_process_callbacks(struct softirq_action *unused)
71155+static void rcu_process_callbacks(void)
71156 {
71157 __rcu_process_callbacks(&rcu_sched_ctrlblk);
71158 __rcu_process_callbacks(&rcu_bh_ctrlblk);
71159diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
71160index 3d01902..afbf46e 100644
71161--- a/kernel/rcutiny_plugin.h
71162+++ b/kernel/rcutiny_plugin.h
71163@@ -893,7 +893,7 @@ static int rcu_kthread(void *arg)
71164 have_rcu_kthread_work = morework;
71165 local_irq_restore(flags);
71166 if (work)
71167- rcu_process_callbacks(NULL);
71168+ rcu_process_callbacks();
71169 schedule_timeout_interruptible(1); /* Leave CPU for others. */
71170 }
71171
71172diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
71173index aaa7b9f..055ff1e 100644
71174--- a/kernel/rcutorture.c
71175+++ b/kernel/rcutorture.c
71176@@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
71177 { 0 };
71178 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
71179 { 0 };
71180-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71181-static atomic_t n_rcu_torture_alloc;
71182-static atomic_t n_rcu_torture_alloc_fail;
71183-static atomic_t n_rcu_torture_free;
71184-static atomic_t n_rcu_torture_mberror;
71185-static atomic_t n_rcu_torture_error;
71186+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
71187+static atomic_unchecked_t n_rcu_torture_alloc;
71188+static atomic_unchecked_t n_rcu_torture_alloc_fail;
71189+static atomic_unchecked_t n_rcu_torture_free;
71190+static atomic_unchecked_t n_rcu_torture_mberror;
71191+static atomic_unchecked_t n_rcu_torture_error;
71192 static long n_rcu_torture_barrier_error;
71193 static long n_rcu_torture_boost_ktrerror;
71194 static long n_rcu_torture_boost_rterror;
71195@@ -272,11 +272,11 @@ rcu_torture_alloc(void)
71196
71197 spin_lock_bh(&rcu_torture_lock);
71198 if (list_empty(&rcu_torture_freelist)) {
71199- atomic_inc(&n_rcu_torture_alloc_fail);
71200+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
71201 spin_unlock_bh(&rcu_torture_lock);
71202 return NULL;
71203 }
71204- atomic_inc(&n_rcu_torture_alloc);
71205+ atomic_inc_unchecked(&n_rcu_torture_alloc);
71206 p = rcu_torture_freelist.next;
71207 list_del_init(p);
71208 spin_unlock_bh(&rcu_torture_lock);
71209@@ -289,7 +289,7 @@ rcu_torture_alloc(void)
71210 static void
71211 rcu_torture_free(struct rcu_torture *p)
71212 {
71213- atomic_inc(&n_rcu_torture_free);
71214+ atomic_inc_unchecked(&n_rcu_torture_free);
71215 spin_lock_bh(&rcu_torture_lock);
71216 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
71217 spin_unlock_bh(&rcu_torture_lock);
71218@@ -410,7 +410,7 @@ rcu_torture_cb(struct rcu_head *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 rcu_torture_free(rp);
71227@@ -459,7 +459,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
71228 i = 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 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
71234 rp->rtort_mbtest = 0;
71235 list_del(&rp->rtort_free);
71236@@ -1002,7 +1002,7 @@ rcu_torture_writer(void *arg)
71237 i = old_rp->rtort_pipe_count;
71238 if (i > RCU_TORTURE_PIPE_LEN)
71239 i = RCU_TORTURE_PIPE_LEN;
71240- atomic_inc(&rcu_torture_wcount[i]);
71241+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
71242 old_rp->rtort_pipe_count++;
71243 cur_ops->deferred_free(old_rp);
71244 }
71245@@ -1087,7 +1087,7 @@ static void rcu_torture_timer(unsigned long unused)
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 spin_lock(&rand_lock);
71252 cur_ops->read_delay(&rand);
71253 n_rcu_torture_timers++;
71254@@ -1151,7 +1151,7 @@ rcu_torture_reader(void *arg)
71255 }
71256 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
71257 if (p->rtort_mbtest == 0)
71258- atomic_inc(&n_rcu_torture_mberror);
71259+ atomic_inc_unchecked(&n_rcu_torture_mberror);
71260 cur_ops->read_delay(&rand);
71261 preempt_disable();
71262 pipe_count = p->rtort_pipe_count;
71263@@ -1210,11 +1210,11 @@ rcu_torture_printk(char *page)
71264 rcu_torture_current,
71265 rcu_torture_current_version,
71266 list_empty(&rcu_torture_freelist),
71267- atomic_read(&n_rcu_torture_alloc),
71268- atomic_read(&n_rcu_torture_alloc_fail),
71269- atomic_read(&n_rcu_torture_free));
71270+ atomic_read_unchecked(&n_rcu_torture_alloc),
71271+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
71272+ atomic_read_unchecked(&n_rcu_torture_free));
71273 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
71274- atomic_read(&n_rcu_torture_mberror),
71275+ atomic_read_unchecked(&n_rcu_torture_mberror),
71276 n_rcu_torture_boost_ktrerror,
71277 n_rcu_torture_boost_rterror);
71278 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
71279@@ -1233,14 +1233,14 @@ rcu_torture_printk(char *page)
71280 n_barrier_attempts,
71281 n_rcu_torture_barrier_error);
71282 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
71283- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
71284+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
71285 n_rcu_torture_barrier_error != 0 ||
71286 n_rcu_torture_boost_ktrerror != 0 ||
71287 n_rcu_torture_boost_rterror != 0 ||
71288 n_rcu_torture_boost_failure != 0 ||
71289 i > 1) {
71290 cnt += sprintf(&page[cnt], "!!! ");
71291- atomic_inc(&n_rcu_torture_error);
71292+ atomic_inc_unchecked(&n_rcu_torture_error);
71293 WARN_ON_ONCE(1);
71294 }
71295 cnt += sprintf(&page[cnt], "Reader Pipe: ");
71296@@ -1254,7 +1254,7 @@ rcu_torture_printk(char *page)
71297 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
71298 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71299 cnt += sprintf(&page[cnt], " %d",
71300- atomic_read(&rcu_torture_wcount[i]));
71301+ atomic_read_unchecked(&rcu_torture_wcount[i]));
71302 }
71303 cnt += sprintf(&page[cnt], "\n");
71304 if (cur_ops->stats)
71305@@ -1938,7 +1938,7 @@ rcu_torture_cleanup(void)
71306
71307 if (cur_ops->cleanup)
71308 cur_ops->cleanup();
71309- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71310+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
71311 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
71312 else if (n_online_successes != n_online_attempts ||
71313 n_offline_successes != n_offline_attempts)
71314@@ -2007,18 +2007,18 @@ rcu_torture_init(void)
71315
71316 rcu_torture_current = NULL;
71317 rcu_torture_current_version = 0;
71318- atomic_set(&n_rcu_torture_alloc, 0);
71319- atomic_set(&n_rcu_torture_alloc_fail, 0);
71320- atomic_set(&n_rcu_torture_free, 0);
71321- atomic_set(&n_rcu_torture_mberror, 0);
71322- atomic_set(&n_rcu_torture_error, 0);
71323+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
71324+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
71325+ atomic_set_unchecked(&n_rcu_torture_free, 0);
71326+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
71327+ atomic_set_unchecked(&n_rcu_torture_error, 0);
71328 n_rcu_torture_barrier_error = 0;
71329 n_rcu_torture_boost_ktrerror = 0;
71330 n_rcu_torture_boost_rterror = 0;
71331 n_rcu_torture_boost_failure = 0;
71332 n_rcu_torture_boosts = 0;
71333 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
71334- atomic_set(&rcu_torture_wcount[i], 0);
71335+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
71336 for_each_possible_cpu(cpu) {
71337 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
71338 per_cpu(rcu_torture_count, cpu)[i] = 0;
71339diff --git a/kernel/rcutree.c b/kernel/rcutree.c
71340index 2682295..0f2297e 100644
71341--- a/kernel/rcutree.c
71342+++ b/kernel/rcutree.c
71343@@ -348,9 +348,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
71344 rcu_prepare_for_idle(smp_processor_id());
71345 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71346 smp_mb__before_atomic_inc(); /* See above. */
71347- atomic_inc(&rdtp->dynticks);
71348+ atomic_inc_unchecked(&rdtp->dynticks);
71349 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
71350- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71351+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71352
71353 /*
71354 * It is illegal to enter an extended quiescent state while
71355@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
71356 int user)
71357 {
71358 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
71359- atomic_inc(&rdtp->dynticks);
71360+ atomic_inc_unchecked(&rdtp->dynticks);
71361 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71362 smp_mb__after_atomic_inc(); /* See above. */
71363- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71364+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71365 rcu_cleanup_after_idle(smp_processor_id());
71366 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
71367 if (!user && !is_idle_task(current)) {
71368@@ -670,14 +670,14 @@ void rcu_nmi_enter(void)
71369 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
71370
71371 if (rdtp->dynticks_nmi_nesting == 0 &&
71372- (atomic_read(&rdtp->dynticks) & 0x1))
71373+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
71374 return;
71375 rdtp->dynticks_nmi_nesting++;
71376 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
71377- atomic_inc(&rdtp->dynticks);
71378+ atomic_inc_unchecked(&rdtp->dynticks);
71379 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
71380 smp_mb__after_atomic_inc(); /* See above. */
71381- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
71382+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
71383 }
71384
71385 /**
71386@@ -696,9 +696,9 @@ void rcu_nmi_exit(void)
71387 return;
71388 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
71389 smp_mb__before_atomic_inc(); /* See above. */
71390- atomic_inc(&rdtp->dynticks);
71391+ atomic_inc_unchecked(&rdtp->dynticks);
71392 smp_mb__after_atomic_inc(); /* Force delay to next write. */
71393- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
71394+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
71395 }
71396
71397 /**
71398@@ -712,7 +712,7 @@ int rcu_is_cpu_idle(void)
71399 int ret;
71400
71401 preempt_disable();
71402- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71403+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
71404 preempt_enable();
71405 return ret;
71406 }
71407@@ -795,7 +795,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
71408 */
71409 static int dyntick_save_progress_counter(struct rcu_data *rdp)
71410 {
71411- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
71412+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71413 return (rdp->dynticks_snap & 0x1) == 0;
71414 }
71415
71416@@ -810,7 +810,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
71417 unsigned int curr;
71418 unsigned int snap;
71419
71420- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
71421+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
71422 snap = (unsigned int)rdp->dynticks_snap;
71423
71424 /*
71425@@ -858,10 +858,10 @@ static int jiffies_till_stall_check(void)
71426 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
71427 */
71428 if (till_stall_check < 3) {
71429- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
71430+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
71431 till_stall_check = 3;
71432 } else if (till_stall_check > 300) {
71433- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
71434+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
71435 till_stall_check = 300;
71436 }
71437 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
71438@@ -1589,7 +1589,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
71439 rsp->qlen += rdp->qlen;
71440 rdp->n_cbs_orphaned += rdp->qlen;
71441 rdp->qlen_lazy = 0;
71442- ACCESS_ONCE(rdp->qlen) = 0;
71443+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71444 }
71445
71446 /*
71447@@ -1831,7 +1831,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
71448 }
71449 smp_mb(); /* List handling before counting for rcu_barrier(). */
71450 rdp->qlen_lazy -= count_lazy;
71451- ACCESS_ONCE(rdp->qlen) -= count;
71452+ ACCESS_ONCE_RW(rdp->qlen) -= count;
71453 rdp->n_cbs_invoked += count;
71454
71455 /* Reinstate batch limit if we have worked down the excess. */
71456@@ -2024,7 +2024,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
71457 /*
71458 * Do RCU core processing for the current CPU.
71459 */
71460-static void rcu_process_callbacks(struct softirq_action *unused)
71461+static void rcu_process_callbacks(void)
71462 {
71463 struct rcu_state *rsp;
71464
71465@@ -2136,7 +2136,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
71466 local_irq_restore(flags);
71467 return;
71468 }
71469- ACCESS_ONCE(rdp->qlen)++;
71470+ ACCESS_ONCE_RW(rdp->qlen)++;
71471 if (lazy)
71472 rdp->qlen_lazy++;
71473 else
71474@@ -2250,8 +2250,8 @@ void synchronize_rcu_bh(void)
71475 }
71476 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
71477
71478-static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
71479-static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
71480+static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
71481+static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
71482
71483 static int synchronize_sched_expedited_cpu_stop(void *data)
71484 {
71485@@ -2312,7 +2312,7 @@ void synchronize_sched_expedited(void)
71486 int firstsnap, s, snap, trycount = 0;
71487
71488 /* Note that atomic_inc_return() implies full memory barrier. */
71489- firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
71490+ firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
71491 get_online_cpus();
71492 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
71493
71494@@ -2334,7 +2334,7 @@ void synchronize_sched_expedited(void)
71495 }
71496
71497 /* Check to see if someone else did our work for us. */
71498- s = atomic_read(&sync_sched_expedited_done);
71499+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71500 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
71501 smp_mb(); /* ensure test happens before caller kfree */
71502 return;
71503@@ -2349,7 +2349,7 @@ void synchronize_sched_expedited(void)
71504 * grace period works for us.
71505 */
71506 get_online_cpus();
71507- snap = atomic_read(&sync_sched_expedited_started);
71508+ snap = atomic_read_unchecked(&sync_sched_expedited_started);
71509 smp_mb(); /* ensure read is before try_stop_cpus(). */
71510 }
71511
71512@@ -2360,12 +2360,12 @@ void synchronize_sched_expedited(void)
71513 * than we did beat us to the punch.
71514 */
71515 do {
71516- s = atomic_read(&sync_sched_expedited_done);
71517+ s = atomic_read_unchecked(&sync_sched_expedited_done);
71518 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
71519 smp_mb(); /* ensure test happens before caller kfree */
71520 break;
71521 }
71522- } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
71523+ } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
71524
71525 put_online_cpus();
71526 }
71527@@ -2539,7 +2539,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71528 * ACCESS_ONCE() to prevent the compiler from speculating
71529 * the increment to precede the early-exit check.
71530 */
71531- ACCESS_ONCE(rsp->n_barrier_done)++;
71532+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71533 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
71534 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
71535 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
71536@@ -2581,7 +2581,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
71537
71538 /* Increment ->n_barrier_done to prevent duplicate work. */
71539 smp_mb(); /* Keep increment after above mechanism. */
71540- ACCESS_ONCE(rsp->n_barrier_done)++;
71541+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
71542 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
71543 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
71544 smp_mb(); /* Keep increment before caller's subsequent code. */
71545@@ -2626,10 +2626,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
71546 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
71547 init_callback_list(rdp);
71548 rdp->qlen_lazy = 0;
71549- ACCESS_ONCE(rdp->qlen) = 0;
71550+ ACCESS_ONCE_RW(rdp->qlen) = 0;
71551 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
71552 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
71553- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
71554+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
71555 #ifdef CONFIG_RCU_USER_QS
71556 WARN_ON_ONCE(rdp->dynticks->in_user);
71557 #endif
71558@@ -2664,8 +2664,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
71559 rdp->blimit = blimit;
71560 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
71561 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
71562- atomic_set(&rdp->dynticks->dynticks,
71563- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
71564+ atomic_set_unchecked(&rdp->dynticks->dynticks,
71565+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
71566 rcu_prepare_for_idle_init(cpu);
71567 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
71568
71569diff --git a/kernel/rcutree.h b/kernel/rcutree.h
71570index a240f03..d469618 100644
71571--- a/kernel/rcutree.h
71572+++ b/kernel/rcutree.h
71573@@ -86,7 +86,7 @@ struct rcu_dynticks {
71574 long long dynticks_nesting; /* Track irq/process nesting level. */
71575 /* Process level is worth LLONG_MAX/2. */
71576 int dynticks_nmi_nesting; /* Track NMI nesting level. */
71577- atomic_t dynticks; /* Even value for idle, else odd. */
71578+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
71579 #ifdef CONFIG_RCU_FAST_NO_HZ
71580 int dyntick_drain; /* Prepare-for-idle state variable. */
71581 unsigned long dyntick_holdoff;
71582diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
71583index f921154..34c4873 100644
71584--- a/kernel/rcutree_plugin.h
71585+++ b/kernel/rcutree_plugin.h
71586@@ -865,7 +865,7 @@ void synchronize_rcu_expedited(void)
71587
71588 /* Clean up and exit. */
71589 smp_mb(); /* ensure expedited GP seen before counter increment. */
71590- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
71591+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
71592 unlock_mb_ret:
71593 mutex_unlock(&sync_rcu_preempt_exp_mutex);
71594 mb_ret:
71595@@ -2040,7 +2040,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
71596 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
71597 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
71598 cpu, ticks_value, ticks_title,
71599- atomic_read(&rdtp->dynticks) & 0xfff,
71600+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
71601 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
71602 fast_no_hz);
71603 }
71604diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
71605index 693513b..b9f1d63 100644
71606--- a/kernel/rcutree_trace.c
71607+++ b/kernel/rcutree_trace.c
71608@@ -92,7 +92,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
71609 rdp->completed, rdp->gpnum,
71610 rdp->passed_quiesce, rdp->qs_pending);
71611 seq_printf(m, " dt=%d/%llx/%d df=%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);
71617@@ -154,7 +154,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
71618 rdp->completed, rdp->gpnum,
71619 rdp->passed_quiesce, rdp->qs_pending);
71620 seq_printf(m, ",%d,%llx,%d,%lu",
71621- atomic_read(&rdp->dynticks->dynticks),
71622+ atomic_read_unchecked(&rdp->dynticks->dynticks),
71623 rdp->dynticks->dynticks_nesting,
71624 rdp->dynticks->dynticks_nmi_nesting,
71625 rdp->dynticks_fqs);
71626diff --git a/kernel/resource.c b/kernel/resource.c
71627index 73f35d4..4684fc4 100644
71628--- a/kernel/resource.c
71629+++ b/kernel/resource.c
71630@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
71631
71632 static int __init ioresources_init(void)
71633 {
71634+#ifdef CONFIG_GRKERNSEC_PROC_ADD
71635+#ifdef CONFIG_GRKERNSEC_PROC_USER
71636+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
71637+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
71638+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71639+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
71640+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
71641+#endif
71642+#else
71643 proc_create("ioports", 0, NULL, &proc_ioports_operations);
71644 proc_create("iomem", 0, NULL, &proc_iomem_operations);
71645+#endif
71646 return 0;
71647 }
71648 __initcall(ioresources_init);
71649diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
71650index 98ec494..4241d6d 100644
71651--- a/kernel/rtmutex-tester.c
71652+++ b/kernel/rtmutex-tester.c
71653@@ -20,7 +20,7 @@
71654 #define MAX_RT_TEST_MUTEXES 8
71655
71656 static spinlock_t rttest_lock;
71657-static atomic_t rttest_event;
71658+static atomic_unchecked_t rttest_event;
71659
71660 struct test_thread_data {
71661 int opcode;
71662@@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71663
71664 case RTTEST_LOCKCONT:
71665 td->mutexes[td->opdata] = 1;
71666- td->event = atomic_add_return(1, &rttest_event);
71667+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71668 return 0;
71669
71670 case RTTEST_RESET:
71671@@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71672 return 0;
71673
71674 case RTTEST_RESETEVENT:
71675- atomic_set(&rttest_event, 0);
71676+ atomic_set_unchecked(&rttest_event, 0);
71677 return 0;
71678
71679 default:
71680@@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71681 return ret;
71682
71683 td->mutexes[id] = 1;
71684- td->event = atomic_add_return(1, &rttest_event);
71685+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71686 rt_mutex_lock(&mutexes[id]);
71687- td->event = atomic_add_return(1, &rttest_event);
71688+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71689 td->mutexes[id] = 4;
71690 return 0;
71691
71692@@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71693 return ret;
71694
71695 td->mutexes[id] = 1;
71696- td->event = atomic_add_return(1, &rttest_event);
71697+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71698 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
71699- td->event = atomic_add_return(1, &rttest_event);
71700+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71701 td->mutexes[id] = ret ? 0 : 4;
71702 return ret ? -EINTR : 0;
71703
71704@@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
71705 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
71706 return ret;
71707
71708- td->event = atomic_add_return(1, &rttest_event);
71709+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71710 rt_mutex_unlock(&mutexes[id]);
71711- td->event = atomic_add_return(1, &rttest_event);
71712+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71713 td->mutexes[id] = 0;
71714 return 0;
71715
71716@@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71717 break;
71718
71719 td->mutexes[dat] = 2;
71720- td->event = atomic_add_return(1, &rttest_event);
71721+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71722 break;
71723
71724 default:
71725@@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71726 return;
71727
71728 td->mutexes[dat] = 3;
71729- td->event = atomic_add_return(1, &rttest_event);
71730+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71731 break;
71732
71733 case RTTEST_LOCKNOWAIT:
71734@@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
71735 return;
71736
71737 td->mutexes[dat] = 1;
71738- td->event = atomic_add_return(1, &rttest_event);
71739+ td->event = atomic_add_return_unchecked(1, &rttest_event);
71740 return;
71741
71742 default:
71743diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
71744index 15f60d0..7e50319 100644
71745--- a/kernel/sched/auto_group.c
71746+++ b/kernel/sched/auto_group.c
71747@@ -11,7 +11,7 @@
71748
71749 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
71750 static struct autogroup autogroup_default;
71751-static atomic_t autogroup_seq_nr;
71752+static atomic_unchecked_t autogroup_seq_nr;
71753
71754 void __init autogroup_init(struct task_struct *init_task)
71755 {
71756@@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
71757
71758 kref_init(&ag->kref);
71759 init_rwsem(&ag->lock);
71760- ag->id = atomic_inc_return(&autogroup_seq_nr);
71761+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
71762 ag->tg = tg;
71763 #ifdef CONFIG_RT_GROUP_SCHED
71764 /*
71765diff --git a/kernel/sched/core.c b/kernel/sched/core.c
71766index c529d00..d00b4f3 100644
71767--- a/kernel/sched/core.c
71768+++ b/kernel/sched/core.c
71769@@ -3563,6 +3563,8 @@ int can_nice(const struct task_struct *p, const int nice)
71770 /* convert nice value [19,-20] to rlimit style value [1,40] */
71771 int nice_rlim = 20 - nice;
71772
71773+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
71774+
71775 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
71776 capable(CAP_SYS_NICE));
71777 }
71778@@ -3596,7 +3598,8 @@ SYSCALL_DEFINE1(nice, int, increment)
71779 if (nice > 19)
71780 nice = 19;
71781
71782- if (increment < 0 && !can_nice(current, nice))
71783+ if (increment < 0 && (!can_nice(current, nice) ||
71784+ gr_handle_chroot_nice()))
71785 return -EPERM;
71786
71787 retval = security_task_setnice(current, nice);
71788@@ -3750,6 +3753,7 @@ recheck:
71789 unsigned long rlim_rtprio =
71790 task_rlimit(p, RLIMIT_RTPRIO);
71791
71792+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
71793 /* can't set/change the rt policy */
71794 if (policy != p->policy && !rlim_rtprio)
71795 return -EPERM;
71796diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
71797index 6b800a1..0c36227 100644
71798--- a/kernel/sched/fair.c
71799+++ b/kernel/sched/fair.c
71800@@ -4890,7 +4890,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
71801 * run_rebalance_domains is triggered when needed from the scheduler tick.
71802 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
71803 */
71804-static void run_rebalance_domains(struct softirq_action *h)
71805+static void run_rebalance_domains(void)
71806 {
71807 int this_cpu = smp_processor_id();
71808 struct rq *this_rq = cpu_rq(this_cpu);
71809diff --git a/kernel/signal.c b/kernel/signal.c
71810index 57dde52..2c561f0 100644
71811--- a/kernel/signal.c
71812+++ b/kernel/signal.c
71813@@ -49,12 +49,12 @@ static struct kmem_cache *sigqueue_cachep;
71814
71815 int print_fatal_signals __read_mostly;
71816
71817-static void __user *sig_handler(struct task_struct *t, int sig)
71818+static __sighandler_t sig_handler(struct task_struct *t, int sig)
71819 {
71820 return t->sighand->action[sig - 1].sa.sa_handler;
71821 }
71822
71823-static int sig_handler_ignored(void __user *handler, int sig)
71824+static int sig_handler_ignored(__sighandler_t handler, int sig)
71825 {
71826 /* Is it explicitly or implicitly ignored? */
71827 return handler == SIG_IGN ||
71828@@ -63,7 +63,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
71829
71830 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
71831 {
71832- void __user *handler;
71833+ __sighandler_t handler;
71834
71835 handler = sig_handler(t, sig);
71836
71837@@ -367,6 +367,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
71838 atomic_inc(&user->sigpending);
71839 rcu_read_unlock();
71840
71841+ if (!override_rlimit)
71842+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
71843+
71844 if (override_rlimit ||
71845 atomic_read(&user->sigpending) <=
71846 task_rlimit(t, RLIMIT_SIGPENDING)) {
71847@@ -491,7 +494,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
71848
71849 int unhandled_signal(struct task_struct *tsk, int sig)
71850 {
71851- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
71852+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
71853 if (is_global_init(tsk))
71854 return 1;
71855 if (handler != SIG_IGN && handler != SIG_DFL)
71856@@ -811,6 +814,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
71857 }
71858 }
71859
71860+ /* allow glibc communication via tgkill to other threads in our
71861+ thread group */
71862+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
71863+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
71864+ && gr_handle_signal(t, sig))
71865+ return -EPERM;
71866+
71867 return security_task_kill(t, info, sig, 0);
71868 }
71869
71870@@ -1192,7 +1202,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71871 return send_signal(sig, info, p, 1);
71872 }
71873
71874-static int
71875+int
71876 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71877 {
71878 return send_signal(sig, info, t, 0);
71879@@ -1229,6 +1239,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71880 unsigned long int flags;
71881 int ret, blocked, ignored;
71882 struct k_sigaction *action;
71883+ int is_unhandled = 0;
71884
71885 spin_lock_irqsave(&t->sighand->siglock, flags);
71886 action = &t->sighand->action[sig-1];
71887@@ -1243,9 +1254,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
71888 }
71889 if (action->sa.sa_handler == SIG_DFL)
71890 t->signal->flags &= ~SIGNAL_UNKILLABLE;
71891+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
71892+ is_unhandled = 1;
71893 ret = specific_send_sig_info(sig, info, t);
71894 spin_unlock_irqrestore(&t->sighand->siglock, flags);
71895
71896+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
71897+ normal operation */
71898+ if (is_unhandled) {
71899+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
71900+ gr_handle_crash(t, sig);
71901+ }
71902+
71903 return ret;
71904 }
71905
71906@@ -1312,8 +1332,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
71907 ret = check_kill_permission(sig, info, p);
71908 rcu_read_unlock();
71909
71910- if (!ret && sig)
71911+ if (!ret && sig) {
71912 ret = do_send_sig_info(sig, info, p, true);
71913+ if (!ret)
71914+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
71915+ }
71916
71917 return ret;
71918 }
71919@@ -2863,7 +2886,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
71920 int error = -ESRCH;
71921
71922 rcu_read_lock();
71923- p = find_task_by_vpid(pid);
71924+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71925+ /* allow glibc communication via tgkill to other threads in our
71926+ thread group */
71927+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
71928+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
71929+ p = find_task_by_vpid_unrestricted(pid);
71930+ else
71931+#endif
71932+ p = find_task_by_vpid(pid);
71933 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
71934 error = check_kill_permission(sig, info, p);
71935 /*
71936diff --git a/kernel/softirq.c b/kernel/softirq.c
71937index cc96bdc..8bb9750 100644
71938--- a/kernel/softirq.c
71939+++ b/kernel/softirq.c
71940@@ -57,7 +57,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
71941
71942 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
71943
71944-char *softirq_to_name[NR_SOFTIRQS] = {
71945+const char * const softirq_to_name[NR_SOFTIRQS] = {
71946 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
71947 "TASKLET", "SCHED", "HRTIMER", "RCU"
71948 };
71949@@ -244,7 +244,7 @@ restart:
71950 kstat_incr_softirqs_this_cpu(vec_nr);
71951
71952 trace_softirq_entry(vec_nr);
71953- h->action(h);
71954+ h->action();
71955 trace_softirq_exit(vec_nr);
71956 if (unlikely(prev_count != preempt_count())) {
71957 printk(KERN_ERR "huh, entered softirq %u %s %p"
71958@@ -391,9 +391,11 @@ void __raise_softirq_irqoff(unsigned int nr)
71959 or_softirq_pending(1UL << nr);
71960 }
71961
71962-void open_softirq(int nr, void (*action)(struct softirq_action *))
71963+void open_softirq(int nr, void (*action)(void))
71964 {
71965- softirq_vec[nr].action = action;
71966+ pax_open_kernel();
71967+ *(void **)&softirq_vec[nr].action = action;
71968+ pax_close_kernel();
71969 }
71970
71971 /*
71972@@ -447,7 +449,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
71973
71974 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
71975
71976-static void tasklet_action(struct softirq_action *a)
71977+static void tasklet_action(void)
71978 {
71979 struct tasklet_struct *list;
71980
71981@@ -482,7 +484,7 @@ static void tasklet_action(struct softirq_action *a)
71982 }
71983 }
71984
71985-static void tasklet_hi_action(struct softirq_action *a)
71986+static void tasklet_hi_action(void)
71987 {
71988 struct tasklet_struct *list;
71989
71990diff --git a/kernel/srcu.c b/kernel/srcu.c
71991index 97c465e..d83f3bb 100644
71992--- a/kernel/srcu.c
71993+++ b/kernel/srcu.c
71994@@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
71995 preempt_disable();
71996 idx = rcu_dereference_index_check(sp->completed,
71997 rcu_read_lock_sched_held()) & 0x1;
71998- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
71999+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
72000 smp_mb(); /* B */ /* Avoid leaking the critical section. */
72001- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72002+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
72003 preempt_enable();
72004 return idx;
72005 }
72006@@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
72007 {
72008 preempt_disable();
72009 smp_mb(); /* C */ /* Avoid leaking the critical section. */
72010- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72011+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
72012 preempt_enable();
72013 }
72014 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
72015diff --git a/kernel/sys.c b/kernel/sys.c
72016index e6e0ece..1f2e413 100644
72017--- a/kernel/sys.c
72018+++ b/kernel/sys.c
72019@@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
72020 error = -EACCES;
72021 goto out;
72022 }
72023+
72024+ if (gr_handle_chroot_setpriority(p, niceval)) {
72025+ error = -EACCES;
72026+ goto out;
72027+ }
72028+
72029 no_nice = security_task_setnice(p, niceval);
72030 if (no_nice) {
72031 error = no_nice;
72032@@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
72033 goto error;
72034 }
72035
72036+ if (gr_check_group_change(new->gid, new->egid, -1))
72037+ goto error;
72038+
72039 if (rgid != (gid_t) -1 ||
72040 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
72041 new->sgid = new->egid;
72042@@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
72043 old = current_cred();
72044
72045 retval = -EPERM;
72046+
72047+ if (gr_check_group_change(kgid, kgid, kgid))
72048+ goto error;
72049+
72050 if (nsown_capable(CAP_SETGID))
72051 new->gid = new->egid = new->sgid = new->fsgid = kgid;
72052 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
72053@@ -647,7 +660,7 @@ error:
72054 /*
72055 * change the user struct in a credentials set to match the new UID
72056 */
72057-static int set_user(struct cred *new)
72058+int set_user(struct cred *new)
72059 {
72060 struct user_struct *new_user;
72061
72062@@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
72063 goto error;
72064 }
72065
72066+ if (gr_check_user_change(new->uid, new->euid, -1))
72067+ goto error;
72068+
72069 if (!uid_eq(new->uid, old->uid)) {
72070 retval = set_user(new);
72071 if (retval < 0)
72072@@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
72073 old = current_cred();
72074
72075 retval = -EPERM;
72076+
72077+ if (gr_check_crash_uid(kuid))
72078+ goto error;
72079+ if (gr_check_user_change(kuid, kuid, kuid))
72080+ goto error;
72081+
72082 if (nsown_capable(CAP_SETUID)) {
72083 new->suid = new->uid = kuid;
72084 if (!uid_eq(kuid, old->uid)) {
72085@@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
72086 goto error;
72087 }
72088
72089+ if (gr_check_user_change(kruid, keuid, -1))
72090+ goto error;
72091+
72092 if (ruid != (uid_t) -1) {
72093 new->uid = kruid;
72094 if (!uid_eq(kruid, old->uid)) {
72095@@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
72096 goto error;
72097 }
72098
72099+ if (gr_check_group_change(krgid, kegid, -1))
72100+ goto error;
72101+
72102 if (rgid != (gid_t) -1)
72103 new->gid = krgid;
72104 if (egid != (gid_t) -1)
72105@@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72106 if (!uid_valid(kuid))
72107 return old_fsuid;
72108
72109+ if (gr_check_user_change(-1, -1, kuid))
72110+ goto error;
72111+
72112 new = prepare_creds();
72113 if (!new)
72114 return old_fsuid;
72115@@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
72116 }
72117 }
72118
72119+error:
72120 abort_creds(new);
72121 return old_fsuid;
72122
72123@@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
72124 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
72125 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
72126 nsown_capable(CAP_SETGID)) {
72127+ if (gr_check_group_change(-1, -1, kgid))
72128+ goto error;
72129+
72130 if (!gid_eq(kgid, old->fsgid)) {
72131 new->fsgid = kgid;
72132 goto change_okay;
72133 }
72134 }
72135
72136+error:
72137 abort_creds(new);
72138 return old_fsgid;
72139
72140@@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
72141 return -EFAULT;
72142
72143 down_read(&uts_sem);
72144- error = __copy_to_user(&name->sysname, &utsname()->sysname,
72145+ error = __copy_to_user(name->sysname, &utsname()->sysname,
72146 __OLD_UTS_LEN);
72147 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
72148- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
72149+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
72150 __OLD_UTS_LEN);
72151 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
72152- error |= __copy_to_user(&name->release, &utsname()->release,
72153+ error |= __copy_to_user(name->release, &utsname()->release,
72154 __OLD_UTS_LEN);
72155 error |= __put_user(0, name->release + __OLD_UTS_LEN);
72156- error |= __copy_to_user(&name->version, &utsname()->version,
72157+ error |= __copy_to_user(name->version, &utsname()->version,
72158 __OLD_UTS_LEN);
72159 error |= __put_user(0, name->version + __OLD_UTS_LEN);
72160- error |= __copy_to_user(&name->machine, &utsname()->machine,
72161+ error |= __copy_to_user(name->machine, &utsname()->machine,
72162 __OLD_UTS_LEN);
72163 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
72164 up_read(&uts_sem);
72165@@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
72166 error = get_dumpable(me->mm);
72167 break;
72168 case PR_SET_DUMPABLE:
72169- if (arg2 < 0 || arg2 > 1) {
72170+ if (arg2 > 1) {
72171 error = -EINVAL;
72172 break;
72173 }
72174diff --git a/kernel/sysctl.c b/kernel/sysctl.c
72175index 26f65ea..df8e5ad 100644
72176--- a/kernel/sysctl.c
72177+++ b/kernel/sysctl.c
72178@@ -92,7 +92,6 @@
72179
72180
72181 #if defined(CONFIG_SYSCTL)
72182-
72183 /* External variables not in a header file. */
72184 extern int sysctl_overcommit_memory;
72185 extern int sysctl_overcommit_ratio;
72186@@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
72187 void __user *buffer, size_t *lenp, loff_t *ppos);
72188 #endif
72189
72190-#ifdef CONFIG_PRINTK
72191 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72192 void __user *buffer, size_t *lenp, loff_t *ppos);
72193-#endif
72194
72195 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
72196 void __user *buffer, size_t *lenp, loff_t *ppos);
72197@@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
72198
72199 #endif
72200
72201+extern struct ctl_table grsecurity_table[];
72202+
72203 static struct ctl_table kern_table[];
72204 static struct ctl_table vm_table[];
72205 static struct ctl_table fs_table[];
72206@@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
72207 int sysctl_legacy_va_layout;
72208 #endif
72209
72210+#ifdef CONFIG_PAX_SOFTMODE
72211+static ctl_table pax_table[] = {
72212+ {
72213+ .procname = "softmode",
72214+ .data = &pax_softmode,
72215+ .maxlen = sizeof(unsigned int),
72216+ .mode = 0600,
72217+ .proc_handler = &proc_dointvec,
72218+ },
72219+
72220+ { }
72221+};
72222+#endif
72223+
72224 /* The default sysctl tables: */
72225
72226 static struct ctl_table sysctl_base_table[] = {
72227@@ -266,6 +279,22 @@ static int max_extfrag_threshold = 1000;
72228 #endif
72229
72230 static struct ctl_table kern_table[] = {
72231+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
72232+ {
72233+ .procname = "grsecurity",
72234+ .mode = 0500,
72235+ .child = grsecurity_table,
72236+ },
72237+#endif
72238+
72239+#ifdef CONFIG_PAX_SOFTMODE
72240+ {
72241+ .procname = "pax",
72242+ .mode = 0500,
72243+ .child = pax_table,
72244+ },
72245+#endif
72246+
72247 {
72248 .procname = "sched_child_runs_first",
72249 .data = &sysctl_sched_child_runs_first,
72250@@ -552,7 +581,7 @@ static struct ctl_table kern_table[] = {
72251 .data = &modprobe_path,
72252 .maxlen = KMOD_PATH_LEN,
72253 .mode = 0644,
72254- .proc_handler = proc_dostring,
72255+ .proc_handler = proc_dostring_modpriv,
72256 },
72257 {
72258 .procname = "modules_disabled",
72259@@ -719,16 +748,20 @@ static struct ctl_table kern_table[] = {
72260 .extra1 = &zero,
72261 .extra2 = &one,
72262 },
72263+#endif
72264 {
72265 .procname = "kptr_restrict",
72266 .data = &kptr_restrict,
72267 .maxlen = sizeof(int),
72268 .mode = 0644,
72269 .proc_handler = proc_dointvec_minmax_sysadmin,
72270+#ifdef CONFIG_GRKERNSEC_HIDESYM
72271+ .extra1 = &two,
72272+#else
72273 .extra1 = &zero,
72274+#endif
72275 .extra2 = &two,
72276 },
72277-#endif
72278 {
72279 .procname = "ngroups_max",
72280 .data = &ngroups_max,
72281@@ -1225,6 +1258,13 @@ static struct ctl_table vm_table[] = {
72282 .proc_handler = proc_dointvec_minmax,
72283 .extra1 = &zero,
72284 },
72285+ {
72286+ .procname = "heap_stack_gap",
72287+ .data = &sysctl_heap_stack_gap,
72288+ .maxlen = sizeof(sysctl_heap_stack_gap),
72289+ .mode = 0644,
72290+ .proc_handler = proc_doulongvec_minmax,
72291+ },
72292 #else
72293 {
72294 .procname = "nr_trim_pages",
72295@@ -1675,6 +1715,16 @@ int proc_dostring(struct ctl_table *table, int write,
72296 buffer, lenp, ppos);
72297 }
72298
72299+int proc_dostring_modpriv(struct ctl_table *table, int write,
72300+ void __user *buffer, size_t *lenp, loff_t *ppos)
72301+{
72302+ if (write && !capable(CAP_SYS_MODULE))
72303+ return -EPERM;
72304+
72305+ return _proc_do_string(table->data, table->maxlen, write,
72306+ buffer, lenp, ppos);
72307+}
72308+
72309 static size_t proc_skip_spaces(char **buf)
72310 {
72311 size_t ret;
72312@@ -1780,6 +1830,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
72313 len = strlen(tmp);
72314 if (len > *size)
72315 len = *size;
72316+ if (len > sizeof(tmp))
72317+ len = sizeof(tmp);
72318 if (copy_to_user(*buf, tmp, len))
72319 return -EFAULT;
72320 *size -= len;
72321@@ -1972,7 +2024,6 @@ static int proc_taint(struct ctl_table *table, int write,
72322 return err;
72323 }
72324
72325-#ifdef CONFIG_PRINTK
72326 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72327 void __user *buffer, size_t *lenp, loff_t *ppos)
72328 {
72329@@ -1981,7 +2032,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
72330
72331 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
72332 }
72333-#endif
72334
72335 struct do_proc_dointvec_minmax_conv_param {
72336 int *min;
72337@@ -2128,8 +2178,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
72338 *i = val;
72339 } else {
72340 val = convdiv * (*i) / convmul;
72341- if (!first)
72342+ if (!first) {
72343 err = proc_put_char(&buffer, &left, '\t');
72344+ if (err)
72345+ break;
72346+ }
72347 err = proc_put_long(&buffer, &left, val, false);
72348 if (err)
72349 break;
72350@@ -2521,6 +2574,12 @@ int proc_dostring(struct ctl_table *table, int write,
72351 return -ENOSYS;
72352 }
72353
72354+int proc_dostring_modpriv(struct ctl_table *table, int write,
72355+ void __user *buffer, size_t *lenp, loff_t *ppos)
72356+{
72357+ return -ENOSYS;
72358+}
72359+
72360 int proc_dointvec(struct ctl_table *table, int write,
72361 void __user *buffer, size_t *lenp, loff_t *ppos)
72362 {
72363@@ -2577,5 +2636,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
72364 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
72365 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
72366 EXPORT_SYMBOL(proc_dostring);
72367+EXPORT_SYMBOL(proc_dostring_modpriv);
72368 EXPORT_SYMBOL(proc_doulongvec_minmax);
72369 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
72370diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
72371index 65bdcf1..21eb831 100644
72372--- a/kernel/sysctl_binary.c
72373+++ b/kernel/sysctl_binary.c
72374@@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
72375 int i;
72376
72377 set_fs(KERNEL_DS);
72378- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72379+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72380 set_fs(old_fs);
72381 if (result < 0)
72382 goto out_kfree;
72383@@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
72384 }
72385
72386 set_fs(KERNEL_DS);
72387- result = vfs_write(file, buffer, str - buffer, &pos);
72388+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72389 set_fs(old_fs);
72390 if (result < 0)
72391 goto out_kfree;
72392@@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
72393 int i;
72394
72395 set_fs(KERNEL_DS);
72396- result = vfs_read(file, buffer, BUFSZ - 1, &pos);
72397+ result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
72398 set_fs(old_fs);
72399 if (result < 0)
72400 goto out_kfree;
72401@@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
72402 }
72403
72404 set_fs(KERNEL_DS);
72405- result = vfs_write(file, buffer, str - buffer, &pos);
72406+ result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
72407 set_fs(old_fs);
72408 if (result < 0)
72409 goto out_kfree;
72410@@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
72411 int i;
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@@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72420 __le16 dnaddr;
72421
72422 set_fs(KERNEL_DS);
72423- result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
72424+ result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
72425 set_fs(old_fs);
72426 if (result < 0)
72427 goto out;
72428@@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
72429 le16_to_cpu(dnaddr) & 0x3ff);
72430
72431 set_fs(KERNEL_DS);
72432- result = vfs_write(file, buf, len, &pos);
72433+ result = vfs_write(file, (const char __force_user *)buf, len, &pos);
72434 set_fs(old_fs);
72435 if (result < 0)
72436 goto out;
72437diff --git a/kernel/taskstats.c b/kernel/taskstats.c
72438index 145bb4d..b2aa969 100644
72439--- a/kernel/taskstats.c
72440+++ b/kernel/taskstats.c
72441@@ -28,9 +28,12 @@
72442 #include <linux/fs.h>
72443 #include <linux/file.h>
72444 #include <linux/pid_namespace.h>
72445+#include <linux/grsecurity.h>
72446 #include <net/genetlink.h>
72447 #include <linux/atomic.h>
72448
72449+extern int gr_is_taskstats_denied(int pid);
72450+
72451 /*
72452 * Maximum length of a cpumask that can be specified in
72453 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
72454@@ -570,6 +573,9 @@ err:
72455
72456 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
72457 {
72458+ if (gr_is_taskstats_denied(current->pid))
72459+ return -EACCES;
72460+
72461 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
72462 return cmd_attr_register_cpumask(info);
72463 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
72464diff --git a/kernel/time.c b/kernel/time.c
72465index d226c6a..c7c0960 100644
72466--- a/kernel/time.c
72467+++ b/kernel/time.c
72468@@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
72469 return error;
72470
72471 if (tz) {
72472+ /* we log in do_settimeofday called below, so don't log twice
72473+ */
72474+ if (!tv)
72475+ gr_log_timechange();
72476+
72477 sys_tz = *tz;
72478 update_vsyscall_tz();
72479 if (firsttime) {
72480diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
72481index f11d83b..d016d91 100644
72482--- a/kernel/time/alarmtimer.c
72483+++ b/kernel/time/alarmtimer.c
72484@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
72485 struct platform_device *pdev;
72486 int error = 0;
72487 int i;
72488- struct k_clock alarm_clock = {
72489+ static struct k_clock alarm_clock = {
72490 .clock_getres = alarm_clock_getres,
72491 .clock_get = alarm_clock_get,
72492 .timer_create = alarm_timer_create,
72493diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
72494index f113755..ec24223 100644
72495--- a/kernel/time/tick-broadcast.c
72496+++ b/kernel/time/tick-broadcast.c
72497@@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
72498 * then clear the broadcast bit.
72499 */
72500 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
72501- int cpu = smp_processor_id();
72502+ cpu = smp_processor_id();
72503
72504 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
72505 tick_broadcast_clear_oneshot(cpu);
72506diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
72507index e424970..4c7962b 100644
72508--- a/kernel/time/timekeeping.c
72509+++ b/kernel/time/timekeeping.c
72510@@ -15,6 +15,7 @@
72511 #include <linux/init.h>
72512 #include <linux/mm.h>
72513 #include <linux/sched.h>
72514+#include <linux/grsecurity.h>
72515 #include <linux/syscore_ops.h>
72516 #include <linux/clocksource.h>
72517 #include <linux/jiffies.h>
72518@@ -368,6 +369,8 @@ int do_settimeofday(const struct timespec *tv)
72519 if (!timespec_valid_strict(tv))
72520 return -EINVAL;
72521
72522+ gr_log_timechange();
72523+
72524 write_seqlock_irqsave(&tk->lock, flags);
72525
72526 timekeeping_forward_now(tk);
72527diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
72528index af5a7e9..715611a 100644
72529--- a/kernel/time/timer_list.c
72530+++ b/kernel/time/timer_list.c
72531@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
72532
72533 static void print_name_offset(struct seq_file *m, void *sym)
72534 {
72535+#ifdef CONFIG_GRKERNSEC_HIDESYM
72536+ SEQ_printf(m, "<%p>", NULL);
72537+#else
72538 char symname[KSYM_NAME_LEN];
72539
72540 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
72541 SEQ_printf(m, "<%pK>", sym);
72542 else
72543 SEQ_printf(m, "%s", symname);
72544+#endif
72545 }
72546
72547 static void
72548@@ -112,7 +116,11 @@ next_one:
72549 static void
72550 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
72551 {
72552+#ifdef CONFIG_GRKERNSEC_HIDESYM
72553+ SEQ_printf(m, " .base: %p\n", NULL);
72554+#else
72555 SEQ_printf(m, " .base: %pK\n", base);
72556+#endif
72557 SEQ_printf(m, " .index: %d\n",
72558 base->index);
72559 SEQ_printf(m, " .resolution: %Lu nsecs\n",
72560@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
72561 {
72562 struct proc_dir_entry *pe;
72563
72564+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72565+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
72566+#else
72567 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
72568+#endif
72569 if (!pe)
72570 return -ENOMEM;
72571 return 0;
72572diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
72573index 0b537f2..40d6c20 100644
72574--- a/kernel/time/timer_stats.c
72575+++ b/kernel/time/timer_stats.c
72576@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
72577 static unsigned long nr_entries;
72578 static struct entry entries[MAX_ENTRIES];
72579
72580-static atomic_t overflow_count;
72581+static atomic_unchecked_t overflow_count;
72582
72583 /*
72584 * The entries are in a hash-table, for fast lookup:
72585@@ -140,7 +140,7 @@ static void reset_entries(void)
72586 nr_entries = 0;
72587 memset(entries, 0, sizeof(entries));
72588 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
72589- atomic_set(&overflow_count, 0);
72590+ atomic_set_unchecked(&overflow_count, 0);
72591 }
72592
72593 static struct entry *alloc_entry(void)
72594@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72595 if (likely(entry))
72596 entry->count++;
72597 else
72598- atomic_inc(&overflow_count);
72599+ atomic_inc_unchecked(&overflow_count);
72600
72601 out_unlock:
72602 raw_spin_unlock_irqrestore(lock, flags);
72603@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
72604
72605 static void print_name_offset(struct seq_file *m, unsigned long addr)
72606 {
72607+#ifdef CONFIG_GRKERNSEC_HIDESYM
72608+ seq_printf(m, "<%p>", NULL);
72609+#else
72610 char symname[KSYM_NAME_LEN];
72611
72612 if (lookup_symbol_name(addr, symname) < 0)
72613- seq_printf(m, "<%p>", (void *)addr);
72614+ seq_printf(m, "<%pK>", (void *)addr);
72615 else
72616 seq_printf(m, "%s", symname);
72617+#endif
72618 }
72619
72620 static int tstats_show(struct seq_file *m, void *v)
72621@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
72622
72623 seq_puts(m, "Timer Stats Version: v0.2\n");
72624 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
72625- if (atomic_read(&overflow_count))
72626+ if (atomic_read_unchecked(&overflow_count))
72627 seq_printf(m, "Overflow: %d entries\n",
72628- atomic_read(&overflow_count));
72629+ atomic_read_unchecked(&overflow_count));
72630
72631 for (i = 0; i < nr_entries; i++) {
72632 entry = entries + i;
72633@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
72634 {
72635 struct proc_dir_entry *pe;
72636
72637+#ifdef CONFIG_GRKERNSEC_PROC_ADD
72638+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
72639+#else
72640 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
72641+#endif
72642 if (!pe)
72643 return -ENOMEM;
72644 return 0;
72645diff --git a/kernel/timer.c b/kernel/timer.c
72646index 367d008..46857a0 100644
72647--- a/kernel/timer.c
72648+++ b/kernel/timer.c
72649@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
72650 /*
72651 * This function runs timers and the timer-tq in bottom half context.
72652 */
72653-static void run_timer_softirq(struct softirq_action *h)
72654+static void run_timer_softirq(void)
72655 {
72656 struct tvec_base *base = __this_cpu_read(tvec_bases);
72657
72658@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
72659 return NOTIFY_OK;
72660 }
72661
72662-static struct notifier_block __cpuinitdata timers_nb = {
72663+static struct notifier_block __cpuinitconst timers_nb = {
72664 .notifier_call = timer_cpu_notify,
72665 };
72666
72667diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
72668index c0bd030..62a1927 100644
72669--- a/kernel/trace/blktrace.c
72670+++ b/kernel/trace/blktrace.c
72671@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
72672 struct blk_trace *bt = filp->private_data;
72673 char buf[16];
72674
72675- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
72676+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
72677
72678 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
72679 }
72680@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
72681 return 1;
72682
72683 bt = buf->chan->private_data;
72684- atomic_inc(&bt->dropped);
72685+ atomic_inc_unchecked(&bt->dropped);
72686 return 0;
72687 }
72688
72689@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
72690
72691 bt->dir = dir;
72692 bt->dev = dev;
72693- atomic_set(&bt->dropped, 0);
72694+ atomic_set_unchecked(&bt->dropped, 0);
72695
72696 ret = -EIO;
72697 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
72698diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
72699index 356bc2f..7c94fc0 100644
72700--- a/kernel/trace/ftrace.c
72701+++ b/kernel/trace/ftrace.c
72702@@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
72703 if (unlikely(ftrace_disabled))
72704 return 0;
72705
72706+ ret = ftrace_arch_code_modify_prepare();
72707+ FTRACE_WARN_ON(ret);
72708+ if (ret)
72709+ return 0;
72710+
72711 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
72712+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
72713 if (ret) {
72714 ftrace_bug(ret, ip);
72715- return 0;
72716 }
72717- return 1;
72718+ return ret ? 0 : 1;
72719 }
72720
72721 /*
72722@@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
72723
72724 int
72725 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
72726- void *data)
72727+ void *data)
72728 {
72729 struct ftrace_func_probe *entry;
72730 struct ftrace_page *pg;
72731@@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
72732 if (!count)
72733 return 0;
72734
72735+ pax_open_kernel();
72736 sort(start, count, sizeof(*start),
72737 ftrace_cmp_ips, ftrace_swap_ips);
72738+ pax_close_kernel();
72739
72740 start_pg = ftrace_allocate_pages(count);
72741 if (!start_pg)
72742@@ -4541,8 +4548,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
72743 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
72744
72745 static int ftrace_graph_active;
72746-static struct notifier_block ftrace_suspend_notifier;
72747-
72748 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
72749 {
72750 return 0;
72751@@ -4686,6 +4691,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
72752 return NOTIFY_DONE;
72753 }
72754
72755+static struct notifier_block ftrace_suspend_notifier = {
72756+ .notifier_call = ftrace_suspend_notifier_call
72757+};
72758+
72759 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72760 trace_func_graph_ent_t entryfunc)
72761 {
72762@@ -4699,7 +4708,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
72763 goto out;
72764 }
72765
72766- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
72767 register_pm_notifier(&ftrace_suspend_notifier);
72768
72769 ftrace_graph_active++;
72770diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
72771index 4cb5e51..e7e05d9 100644
72772--- a/kernel/trace/ring_buffer.c
72773+++ b/kernel/trace/ring_buffer.c
72774@@ -346,9 +346,9 @@ struct buffer_data_page {
72775 */
72776 struct buffer_page {
72777 struct list_head list; /* list of buffer pages */
72778- local_t write; /* index for next write */
72779+ local_unchecked_t write; /* index for next write */
72780 unsigned read; /* index for next read */
72781- local_t entries; /* entries on this page */
72782+ local_unchecked_t entries; /* entries on this page */
72783 unsigned long real_end; /* real end of data */
72784 struct buffer_data_page *page; /* Actual data page */
72785 };
72786@@ -460,8 +460,8 @@ struct ring_buffer_per_cpu {
72787 unsigned long lost_events;
72788 unsigned long last_overrun;
72789 local_t entries_bytes;
72790- local_t commit_overrun;
72791- local_t overrun;
72792+ local_unchecked_t commit_overrun;
72793+ local_unchecked_t overrun;
72794 local_t entries;
72795 local_t committing;
72796 local_t commits;
72797@@ -860,8 +860,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72798 *
72799 * We add a counter to the write field to denote this.
72800 */
72801- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
72802- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
72803+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
72804+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
72805
72806 /*
72807 * Just make sure we have seen our old_write and synchronize
72808@@ -889,8 +889,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
72809 * cmpxchg to only update if an interrupt did not already
72810 * do it for us. If the cmpxchg fails, we don't care.
72811 */
72812- (void)local_cmpxchg(&next_page->write, old_write, val);
72813- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
72814+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
72815+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
72816
72817 /*
72818 * No need to worry about races with clearing out the commit.
72819@@ -1249,12 +1249,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
72820
72821 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
72822 {
72823- return local_read(&bpage->entries) & RB_WRITE_MASK;
72824+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
72825 }
72826
72827 static inline unsigned long rb_page_write(struct buffer_page *bpage)
72828 {
72829- return local_read(&bpage->write) & RB_WRITE_MASK;
72830+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
72831 }
72832
72833 static int
72834@@ -1349,7 +1349,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
72835 * bytes consumed in ring buffer from here.
72836 * Increment overrun to account for the lost events.
72837 */
72838- local_add(page_entries, &cpu_buffer->overrun);
72839+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
72840 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72841 }
72842
72843@@ -1905,7 +1905,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
72844 * it is our responsibility to update
72845 * the counters.
72846 */
72847- local_add(entries, &cpu_buffer->overrun);
72848+ local_add_unchecked(entries, &cpu_buffer->overrun);
72849 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
72850
72851 /*
72852@@ -2055,7 +2055,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72853 if (tail == BUF_PAGE_SIZE)
72854 tail_page->real_end = 0;
72855
72856- local_sub(length, &tail_page->write);
72857+ local_sub_unchecked(length, &tail_page->write);
72858 return;
72859 }
72860
72861@@ -2090,7 +2090,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72862 rb_event_set_padding(event);
72863
72864 /* Set the write back to the previous setting */
72865- local_sub(length, &tail_page->write);
72866+ local_sub_unchecked(length, &tail_page->write);
72867 return;
72868 }
72869
72870@@ -2102,7 +2102,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
72871
72872 /* Set write to end of buffer */
72873 length = (tail + length) - BUF_PAGE_SIZE;
72874- local_sub(length, &tail_page->write);
72875+ local_sub_unchecked(length, &tail_page->write);
72876 }
72877
72878 /*
72879@@ -2128,7 +2128,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72880 * about it.
72881 */
72882 if (unlikely(next_page == commit_page)) {
72883- local_inc(&cpu_buffer->commit_overrun);
72884+ local_inc_unchecked(&cpu_buffer->commit_overrun);
72885 goto out_reset;
72886 }
72887
72888@@ -2182,7 +2182,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
72889 cpu_buffer->tail_page) &&
72890 (cpu_buffer->commit_page ==
72891 cpu_buffer->reader_page))) {
72892- local_inc(&cpu_buffer->commit_overrun);
72893+ local_inc_unchecked(&cpu_buffer->commit_overrun);
72894 goto out_reset;
72895 }
72896 }
72897@@ -2230,7 +2230,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72898 length += RB_LEN_TIME_EXTEND;
72899
72900 tail_page = cpu_buffer->tail_page;
72901- write = local_add_return(length, &tail_page->write);
72902+ write = local_add_return_unchecked(length, &tail_page->write);
72903
72904 /* set write to only the index of the write */
72905 write &= RB_WRITE_MASK;
72906@@ -2247,7 +2247,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
72907 kmemcheck_annotate_bitfield(event, bitfield);
72908 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
72909
72910- local_inc(&tail_page->entries);
72911+ local_inc_unchecked(&tail_page->entries);
72912
72913 /*
72914 * If this is the first commit on the page, then update
72915@@ -2280,7 +2280,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72916
72917 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
72918 unsigned long write_mask =
72919- local_read(&bpage->write) & ~RB_WRITE_MASK;
72920+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
72921 unsigned long event_length = rb_event_length(event);
72922 /*
72923 * This is on the tail page. It is possible that
72924@@ -2290,7 +2290,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
72925 */
72926 old_index += write_mask;
72927 new_index += write_mask;
72928- index = local_cmpxchg(&bpage->write, old_index, new_index);
72929+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
72930 if (index == old_index) {
72931 /* update counters */
72932 local_sub(event_length, &cpu_buffer->entries_bytes);
72933@@ -2629,7 +2629,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72934
72935 /* Do the likely case first */
72936 if (likely(bpage->page == (void *)addr)) {
72937- local_dec(&bpage->entries);
72938+ local_dec_unchecked(&bpage->entries);
72939 return;
72940 }
72941
72942@@ -2641,7 +2641,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
72943 start = bpage;
72944 do {
72945 if (bpage->page == (void *)addr) {
72946- local_dec(&bpage->entries);
72947+ local_dec_unchecked(&bpage->entries);
72948 return;
72949 }
72950 rb_inc_page(cpu_buffer, &bpage);
72951@@ -2923,7 +2923,7 @@ static inline unsigned long
72952 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
72953 {
72954 return local_read(&cpu_buffer->entries) -
72955- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
72956+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
72957 }
72958
72959 /**
72960@@ -3011,7 +3011,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
72961 return 0;
72962
72963 cpu_buffer = buffer->buffers[cpu];
72964- ret = local_read(&cpu_buffer->overrun);
72965+ ret = local_read_unchecked(&cpu_buffer->overrun);
72966
72967 return ret;
72968 }
72969@@ -3032,7 +3032,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
72970 return 0;
72971
72972 cpu_buffer = buffer->buffers[cpu];
72973- ret = local_read(&cpu_buffer->commit_overrun);
72974+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
72975
72976 return ret;
72977 }
72978@@ -3077,7 +3077,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
72979 /* if you care about this being correct, lock the buffer */
72980 for_each_buffer_cpu(buffer, cpu) {
72981 cpu_buffer = buffer->buffers[cpu];
72982- overruns += local_read(&cpu_buffer->overrun);
72983+ overruns += local_read_unchecked(&cpu_buffer->overrun);
72984 }
72985
72986 return overruns;
72987@@ -3253,8 +3253,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72988 /*
72989 * Reset the reader page to size zero.
72990 */
72991- local_set(&cpu_buffer->reader_page->write, 0);
72992- local_set(&cpu_buffer->reader_page->entries, 0);
72993+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
72994+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
72995 local_set(&cpu_buffer->reader_page->page->commit, 0);
72996 cpu_buffer->reader_page->real_end = 0;
72997
72998@@ -3288,7 +3288,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
72999 * want to compare with the last_overrun.
73000 */
73001 smp_mb();
73002- overwrite = local_read(&(cpu_buffer->overrun));
73003+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
73004
73005 /*
73006 * Here's the tricky part.
73007@@ -3858,8 +3858,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73008
73009 cpu_buffer->head_page
73010 = list_entry(cpu_buffer->pages, struct buffer_page, list);
73011- local_set(&cpu_buffer->head_page->write, 0);
73012- local_set(&cpu_buffer->head_page->entries, 0);
73013+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
73014+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
73015 local_set(&cpu_buffer->head_page->page->commit, 0);
73016
73017 cpu_buffer->head_page->read = 0;
73018@@ -3869,14 +3869,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
73019
73020 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
73021 INIT_LIST_HEAD(&cpu_buffer->new_pages);
73022- local_set(&cpu_buffer->reader_page->write, 0);
73023- local_set(&cpu_buffer->reader_page->entries, 0);
73024+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
73025+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
73026 local_set(&cpu_buffer->reader_page->page->commit, 0);
73027 cpu_buffer->reader_page->read = 0;
73028
73029- local_set(&cpu_buffer->commit_overrun, 0);
73030+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
73031 local_set(&cpu_buffer->entries_bytes, 0);
73032- local_set(&cpu_buffer->overrun, 0);
73033+ local_set_unchecked(&cpu_buffer->overrun, 0);
73034 local_set(&cpu_buffer->entries, 0);
73035 local_set(&cpu_buffer->committing, 0);
73036 local_set(&cpu_buffer->commits, 0);
73037@@ -4279,8 +4279,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
73038 rb_init_page(bpage);
73039 bpage = reader->page;
73040 reader->page = *data_page;
73041- local_set(&reader->write, 0);
73042- local_set(&reader->entries, 0);
73043+ local_set_unchecked(&reader->write, 0);
73044+ local_set_unchecked(&reader->entries, 0);
73045 reader->read = 0;
73046 *data_page = bpage;
73047
73048diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
73049index 31e4f55..62da00f 100644
73050--- a/kernel/trace/trace.c
73051+++ b/kernel/trace/trace.c
73052@@ -4436,10 +4436,9 @@ static const struct file_operations tracing_dyn_info_fops = {
73053 };
73054 #endif
73055
73056-static struct dentry *d_tracer;
73057-
73058 struct dentry *tracing_init_dentry(void)
73059 {
73060+ static struct dentry *d_tracer;
73061 static int once;
73062
73063 if (d_tracer)
73064@@ -4459,10 +4458,9 @@ struct dentry *tracing_init_dentry(void)
73065 return d_tracer;
73066 }
73067
73068-static struct dentry *d_percpu;
73069-
73070 struct dentry *tracing_dentry_percpu(void)
73071 {
73072+ static struct dentry *d_percpu;
73073 static int once;
73074 struct dentry *d_tracer;
73075
73076diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
73077index d608d09..7eddcb1 100644
73078--- a/kernel/trace/trace_events.c
73079+++ b/kernel/trace/trace_events.c
73080@@ -1320,10 +1320,6 @@ static LIST_HEAD(ftrace_module_file_list);
73081 struct ftrace_module_file_ops {
73082 struct list_head list;
73083 struct module *mod;
73084- struct file_operations id;
73085- struct file_operations enable;
73086- struct file_operations format;
73087- struct file_operations filter;
73088 };
73089
73090 static struct ftrace_module_file_ops *
73091@@ -1344,17 +1340,12 @@ trace_create_file_ops(struct module *mod)
73092
73093 file_ops->mod = mod;
73094
73095- file_ops->id = ftrace_event_id_fops;
73096- file_ops->id.owner = mod;
73097-
73098- file_ops->enable = ftrace_enable_fops;
73099- file_ops->enable.owner = mod;
73100-
73101- file_ops->filter = ftrace_event_filter_fops;
73102- file_ops->filter.owner = mod;
73103-
73104- file_ops->format = ftrace_event_format_fops;
73105- file_ops->format.owner = mod;
73106+ pax_open_kernel();
73107+ *(void **)&mod->trace_id.owner = mod;
73108+ *(void **)&mod->trace_enable.owner = mod;
73109+ *(void **)&mod->trace_filter.owner = mod;
73110+ *(void **)&mod->trace_format.owner = mod;
73111+ pax_close_kernel();
73112
73113 list_add(&file_ops->list, &ftrace_module_file_list);
73114
73115@@ -1378,8 +1369,8 @@ static void trace_module_add_events(struct module *mod)
73116
73117 for_each_event(call, start, end) {
73118 __trace_add_event_call(*call, mod,
73119- &file_ops->id, &file_ops->enable,
73120- &file_ops->filter, &file_ops->format);
73121+ &mod->trace_id, &mod->trace_enable,
73122+ &mod->trace_filter, &mod->trace_format);
73123 }
73124 }
73125
73126diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
73127index fd3c8aa..5f324a6 100644
73128--- a/kernel/trace/trace_mmiotrace.c
73129+++ b/kernel/trace/trace_mmiotrace.c
73130@@ -24,7 +24,7 @@ struct header_iter {
73131 static struct trace_array *mmio_trace_array;
73132 static bool overrun_detected;
73133 static unsigned long prev_overruns;
73134-static atomic_t dropped_count;
73135+static atomic_unchecked_t dropped_count;
73136
73137 static void mmio_reset_data(struct trace_array *tr)
73138 {
73139@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
73140
73141 static unsigned long count_overruns(struct trace_iterator *iter)
73142 {
73143- unsigned long cnt = atomic_xchg(&dropped_count, 0);
73144+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
73145 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
73146
73147 if (over > prev_overruns)
73148@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
73149 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
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);
73157@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
73158 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
73159 sizeof(*entry), 0, pc);
73160 if (!event) {
73161- atomic_inc(&dropped_count);
73162+ atomic_inc_unchecked(&dropped_count);
73163 return;
73164 }
73165 entry = ring_buffer_event_data(event);
73166diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
73167index 123b189..1e9e2a6 100644
73168--- a/kernel/trace/trace_output.c
73169+++ b/kernel/trace/trace_output.c
73170@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
73171
73172 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
73173 if (!IS_ERR(p)) {
73174- p = mangle_path(s->buffer + s->len, p, "\n");
73175+ p = mangle_path(s->buffer + s->len, p, "\n\\");
73176 if (p) {
73177 s->len = p - s->buffer;
73178 return 1;
73179@@ -824,14 +824,16 @@ int register_ftrace_event(struct trace_event *event)
73180 goto out;
73181 }
73182
73183+ pax_open_kernel();
73184 if (event->funcs->trace == NULL)
73185- event->funcs->trace = trace_nop_print;
73186+ *(void **)&event->funcs->trace = trace_nop_print;
73187 if (event->funcs->raw == NULL)
73188- event->funcs->raw = trace_nop_print;
73189+ *(void **)&event->funcs->raw = trace_nop_print;
73190 if (event->funcs->hex == NULL)
73191- event->funcs->hex = trace_nop_print;
73192+ *(void **)&event->funcs->hex = trace_nop_print;
73193 if (event->funcs->binary == NULL)
73194- event->funcs->binary = trace_nop_print;
73195+ *(void **)&event->funcs->binary = trace_nop_print;
73196+ pax_close_kernel();
73197
73198 key = event->type & (EVENT_HASHSIZE - 1);
73199
73200diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
73201index 0c1b1657..95337e9 100644
73202--- a/kernel/trace/trace_stack.c
73203+++ b/kernel/trace/trace_stack.c
73204@@ -53,7 +53,7 @@ static inline void check_stack(void)
73205 return;
73206
73207 /* we do not handle interrupt stacks yet */
73208- if (!object_is_on_stack(&this_size))
73209+ if (!object_starts_on_stack(&this_size))
73210 return;
73211
73212 local_irq_save(flags);
73213diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
73214index 28e9d6c9..50381bd 100644
73215--- a/lib/Kconfig.debug
73216+++ b/lib/Kconfig.debug
73217@@ -1278,6 +1278,7 @@ config LATENCYTOP
73218 depends on DEBUG_KERNEL
73219 depends on STACKTRACE_SUPPORT
73220 depends on PROC_FS
73221+ depends on !GRKERNSEC_HIDESYM
73222 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
73223 select KALLSYMS
73224 select KALLSYMS_ALL
73225@@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
73226
73227 config PROVIDE_OHCI1394_DMA_INIT
73228 bool "Remote debugging over FireWire early on boot"
73229- depends on PCI && X86
73230+ depends on PCI && X86 && !GRKERNSEC
73231 help
73232 If you want to debug problems which hang or crash the kernel early
73233 on boot and the crashing machine has a FireWire port, you can use
73234@@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
73235
73236 config FIREWIRE_OHCI_REMOTE_DMA
73237 bool "Remote debugging over FireWire with firewire-ohci"
73238- depends on FIREWIRE_OHCI
73239+ depends on FIREWIRE_OHCI && !GRKERNSEC
73240 help
73241 This option lets you use the FireWire bus for remote debugging
73242 with help of the firewire-ohci driver. It enables unfiltered
73243diff --git a/lib/Makefile b/lib/Makefile
73244index a08b791..a3ff1eb 100644
73245--- a/lib/Makefile
73246+++ b/lib/Makefile
73247@@ -46,7 +46,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
73248
73249 obj-$(CONFIG_BTREE) += btree.o
73250 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
73251-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
73252+obj-y += list_debug.o
73253 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
73254
73255 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
73256diff --git a/lib/bitmap.c b/lib/bitmap.c
73257index 06fdfa1..97c5c7d 100644
73258--- a/lib/bitmap.c
73259+++ b/lib/bitmap.c
73260@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
73261 {
73262 int c, old_c, totaldigits, ndigits, nchunks, nbits;
73263 u32 chunk;
73264- const char __user __force *ubuf = (const char __user __force *)buf;
73265+ const char __user *ubuf = (const char __force_user *)buf;
73266
73267 bitmap_zero(maskp, nmaskbits);
73268
73269@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
73270 {
73271 if (!access_ok(VERIFY_READ, ubuf, ulen))
73272 return -EFAULT;
73273- return __bitmap_parse((const char __force *)ubuf,
73274+ return __bitmap_parse((const char __force_kernel *)ubuf,
73275 ulen, 1, maskp, nmaskbits);
73276
73277 }
73278@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
73279 {
73280 unsigned a, b;
73281 int c, old_c, totaldigits;
73282- const char __user __force *ubuf = (const char __user __force *)buf;
73283+ const char __user *ubuf = (const char __force_user *)buf;
73284 int exp_digit, in_range;
73285
73286 totaldigits = c = 0;
73287@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
73288 {
73289 if (!access_ok(VERIFY_READ, ubuf, ulen))
73290 return -EFAULT;
73291- return __bitmap_parselist((const char __force *)ubuf,
73292+ return __bitmap_parselist((const char __force_kernel *)ubuf,
73293 ulen, 1, maskp, nmaskbits);
73294 }
73295 EXPORT_SYMBOL(bitmap_parselist_user);
73296diff --git a/lib/bug.c b/lib/bug.c
73297index d0cdf14..4d07bd2 100644
73298--- a/lib/bug.c
73299+++ b/lib/bug.c
73300@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
73301 return BUG_TRAP_TYPE_NONE;
73302
73303 bug = find_bug(bugaddr);
73304+ if (!bug)
73305+ return BUG_TRAP_TYPE_NONE;
73306
73307 file = NULL;
73308 line = 0;
73309diff --git a/lib/debugobjects.c b/lib/debugobjects.c
73310index d11808c..dc2d6f8 100644
73311--- a/lib/debugobjects.c
73312+++ b/lib/debugobjects.c
73313@@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
73314 if (limit > 4)
73315 return;
73316
73317- is_on_stack = object_is_on_stack(addr);
73318+ is_on_stack = object_starts_on_stack(addr);
73319 if (is_on_stack == onstack)
73320 return;
73321
73322diff --git a/lib/devres.c b/lib/devres.c
73323index 80b9c76..9e32279 100644
73324--- a/lib/devres.c
73325+++ b/lib/devres.c
73326@@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
73327 void devm_iounmap(struct device *dev, void __iomem *addr)
73328 {
73329 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
73330- (void *)addr));
73331+ (void __force *)addr));
73332 iounmap(addr);
73333 }
73334 EXPORT_SYMBOL(devm_iounmap);
73335@@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
73336 {
73337 ioport_unmap(addr);
73338 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
73339- devm_ioport_map_match, (void *)addr));
73340+ devm_ioport_map_match, (void __force *)addr));
73341 }
73342 EXPORT_SYMBOL(devm_ioport_unmap);
73343
73344diff --git a/lib/dma-debug.c b/lib/dma-debug.c
73345index d84beb9..da44791 100644
73346--- a/lib/dma-debug.c
73347+++ b/lib/dma-debug.c
73348@@ -754,7 +754,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
73349
73350 void dma_debug_add_bus(struct bus_type *bus)
73351 {
73352- struct notifier_block *nb;
73353+ notifier_block_no_const *nb;
73354
73355 if (global_disable)
73356 return;
73357@@ -919,7 +919,7 @@ out:
73358
73359 static void check_for_stack(struct device *dev, void *addr)
73360 {
73361- if (object_is_on_stack(addr))
73362+ if (object_starts_on_stack(addr))
73363 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
73364 "stack [addr=%p]\n", addr);
73365 }
73366diff --git a/lib/inflate.c b/lib/inflate.c
73367index 013a761..c28f3fc 100644
73368--- a/lib/inflate.c
73369+++ b/lib/inflate.c
73370@@ -269,7 +269,7 @@ static void free(void *where)
73371 malloc_ptr = free_mem_ptr;
73372 }
73373 #else
73374-#define malloc(a) kmalloc(a, GFP_KERNEL)
73375+#define malloc(a) kmalloc((a), GFP_KERNEL)
73376 #define free(a) kfree(a)
73377 #endif
73378
73379diff --git a/lib/ioremap.c b/lib/ioremap.c
73380index 0c9216c..863bd89 100644
73381--- a/lib/ioremap.c
73382+++ b/lib/ioremap.c
73383@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
73384 unsigned long next;
73385
73386 phys_addr -= addr;
73387- pmd = pmd_alloc(&init_mm, pud, addr);
73388+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
73389 if (!pmd)
73390 return -ENOMEM;
73391 do {
73392@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
73393 unsigned long next;
73394
73395 phys_addr -= addr;
73396- pud = pud_alloc(&init_mm, pgd, addr);
73397+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
73398 if (!pud)
73399 return -ENOMEM;
73400 do {
73401diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
73402index bd2bea9..6b3c95e 100644
73403--- a/lib/is_single_threaded.c
73404+++ b/lib/is_single_threaded.c
73405@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
73406 struct task_struct *p, *t;
73407 bool ret;
73408
73409+ if (!mm)
73410+ return true;
73411+
73412 if (atomic_read(&task->signal->live) != 1)
73413 return false;
73414
73415diff --git a/lib/list_debug.c b/lib/list_debug.c
73416index c24c2f7..3fc5da0 100644
73417--- a/lib/list_debug.c
73418+++ b/lib/list_debug.c
73419@@ -11,7 +11,9 @@
73420 #include <linux/bug.h>
73421 #include <linux/kernel.h>
73422 #include <linux/rculist.h>
73423+#include <linux/mm.h>
73424
73425+#ifdef CONFIG_DEBUG_LIST
73426 /*
73427 * Insert a new entry between two known consecutive entries.
73428 *
73429@@ -19,21 +21,32 @@
73430 * the prev/next entries already!
73431 */
73432
73433-void __list_add(struct list_head *new,
73434- struct list_head *prev,
73435- struct list_head *next)
73436+static bool __list_add_debug(struct list_head *new,
73437+ struct list_head *prev,
73438+ struct list_head *next)
73439 {
73440- WARN(next->prev != prev,
73441+ if (WARN(next->prev != prev,
73442 "list_add corruption. next->prev should be "
73443 "prev (%p), but was %p. (next=%p).\n",
73444- prev, next->prev, next);
73445- WARN(prev->next != next,
73446+ prev, next->prev, next) ||
73447+ WARN(prev->next != next,
73448 "list_add corruption. prev->next should be "
73449 "next (%p), but was %p. (prev=%p).\n",
73450- next, prev->next, prev);
73451- WARN(new == prev || new == next,
73452+ next, prev->next, prev) ||
73453+ WARN(new == prev || new == next,
73454 "list_add double add: new=%p, prev=%p, next=%p.\n",
73455- new, prev, next);
73456+ new, prev, next))
73457+ return false;
73458+ return true;
73459+}
73460+
73461+void __list_add(struct list_head *new,
73462+ struct list_head *prev,
73463+ struct list_head *next)
73464+{
73465+ if (!__list_add_debug(new, prev, next))
73466+ return;
73467+
73468 next->prev = new;
73469 new->next = next;
73470 new->prev = prev;
73471@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
73472 }
73473 EXPORT_SYMBOL(__list_add);
73474
73475-void __list_del_entry(struct list_head *entry)
73476+static bool __list_del_entry_debug(struct list_head *entry)
73477 {
73478 struct list_head *prev, *next;
73479
73480@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
73481 WARN(next->prev != entry,
73482 "list_del corruption. next->prev should be %p, "
73483 "but was %p\n", entry, next->prev))
73484+ return false;
73485+ return true;
73486+}
73487+
73488+void __list_del_entry(struct list_head *entry)
73489+{
73490+ if (!__list_del_entry_debug(entry))
73491 return;
73492
73493- __list_del(prev, next);
73494+ __list_del(entry->prev, entry->next);
73495 }
73496 EXPORT_SYMBOL(__list_del_entry);
73497
73498@@ -86,15 +106,54 @@ EXPORT_SYMBOL(list_del);
73499 void __list_add_rcu(struct list_head *new,
73500 struct list_head *prev, struct list_head *next)
73501 {
73502- WARN(next->prev != prev,
73503+ if (WARN(next->prev != prev,
73504 "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
73505- prev, next->prev, next);
73506- WARN(prev->next != next,
73507+ prev, next->prev, next) ||
73508+ WARN(prev->next != next,
73509 "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
73510- next, prev->next, prev);
73511+ next, prev->next, prev))
73512+ return;
73513+
73514 new->next = next;
73515 new->prev = prev;
73516 rcu_assign_pointer(list_next_rcu(prev), new);
73517 next->prev = new;
73518 }
73519 EXPORT_SYMBOL(__list_add_rcu);
73520+#endif
73521+
73522+void pax_list_add_tail(struct list_head *new, struct list_head *head)
73523+{
73524+ struct list_head *prev, *next;
73525+
73526+ prev = head->prev;
73527+ next = head;
73528+
73529+#ifdef CONFIG_DEBUG_LIST
73530+ if (!__list_add_debug(new, prev, next))
73531+ return;
73532+#endif
73533+
73534+ pax_open_kernel();
73535+ next->prev = new;
73536+ new->next = next;
73537+ new->prev = prev;
73538+ prev->next = new;
73539+ pax_close_kernel();
73540+}
73541+EXPORT_SYMBOL(pax_list_add_tail);
73542+
73543+void pax_list_del(struct list_head *entry)
73544+{
73545+#ifdef CONFIG_DEBUG_LIST
73546+ if (!__list_del_entry_debug(entry))
73547+ return;
73548+#endif
73549+
73550+ pax_open_kernel();
73551+ __list_del(entry->prev, entry->next);
73552+ entry->next = LIST_POISON1;
73553+ entry->prev = LIST_POISON2;
73554+ pax_close_kernel();
73555+}
73556+EXPORT_SYMBOL(pax_list_del);
73557diff --git a/lib/radix-tree.c b/lib/radix-tree.c
73558index e796429..6e38f9f 100644
73559--- a/lib/radix-tree.c
73560+++ b/lib/radix-tree.c
73561@@ -92,7 +92,7 @@ struct radix_tree_preload {
73562 int nr;
73563 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
73564 };
73565-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
73566+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
73567
73568 static inline void *ptr_to_indirect(void *ptr)
73569 {
73570diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
73571index bb2b201..46abaf9 100644
73572--- a/lib/strncpy_from_user.c
73573+++ b/lib/strncpy_from_user.c
73574@@ -21,7 +21,7 @@
73575 */
73576 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
73577 {
73578- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73579+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73580 long res = 0;
73581
73582 /*
73583diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
73584index a28df52..3d55877 100644
73585--- a/lib/strnlen_user.c
73586+++ b/lib/strnlen_user.c
73587@@ -26,7 +26,7 @@
73588 */
73589 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
73590 {
73591- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73592+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
73593 long align, res = 0;
73594 unsigned long c;
73595
73596diff --git a/lib/vsprintf.c b/lib/vsprintf.c
73597index 39c99fe..18f060b 100644
73598--- a/lib/vsprintf.c
73599+++ b/lib/vsprintf.c
73600@@ -16,6 +16,9 @@
73601 * - scnprintf and vscnprintf
73602 */
73603
73604+#ifdef CONFIG_GRKERNSEC_HIDESYM
73605+#define __INCLUDED_BY_HIDESYM 1
73606+#endif
73607 #include <stdarg.h>
73608 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
73609 #include <linux/types.h>
73610@@ -533,7 +536,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
73611 char sym[KSYM_SYMBOL_LEN];
73612 if (ext == 'B')
73613 sprint_backtrace(sym, value);
73614- else if (ext != 'f' && ext != 's')
73615+ else if (ext != 'f' && ext != 's' && ext != 'a')
73616 sprint_symbol(sym, value);
73617 else
73618 sprint_symbol_no_offset(sym, value);
73619@@ -966,7 +969,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
73620 return number(buf, end, *(const netdev_features_t *)addr, spec);
73621 }
73622
73623+#ifdef CONFIG_GRKERNSEC_HIDESYM
73624+int kptr_restrict __read_mostly = 2;
73625+#else
73626 int kptr_restrict __read_mostly;
73627+#endif
73628
73629 /*
73630 * Show a '%p' thing. A kernel extension is that the '%p' is followed
73631@@ -980,6 +987,8 @@ int kptr_restrict __read_mostly;
73632 * - 'S' For symbolic direct pointers with offset
73633 * - 's' For symbolic direct pointers without offset
73634 * - 'B' For backtraced symbolic direct pointers with offset
73635+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
73636+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
73637 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
73638 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
73639 * - 'M' For a 6-byte MAC address, it prints the address in the
73640@@ -1035,12 +1044,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73641
73642 if (!ptr && *fmt != 'K') {
73643 /*
73644- * Print (null) with the same width as a pointer so it makes
73645+ * Print (nil) with the same width as a pointer so it makes
73646 * tabular output look nice.
73647 */
73648 if (spec.field_width == -1)
73649 spec.field_width = default_width;
73650- return string(buf, end, "(null)", spec);
73651+ return string(buf, end, "(nil)", spec);
73652 }
73653
73654 switch (*fmt) {
73655@@ -1050,6 +1059,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73656 /* Fallthrough */
73657 case 'S':
73658 case 's':
73659+#ifdef CONFIG_GRKERNSEC_HIDESYM
73660+ break;
73661+#else
73662+ return symbol_string(buf, end, ptr, spec, *fmt);
73663+#endif
73664+ case 'A':
73665+ case 'a':
73666 case 'B':
73667 return symbol_string(buf, end, ptr, spec, *fmt);
73668 case 'R':
73669@@ -1090,6 +1106,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73670 va_end(va);
73671 return buf;
73672 }
73673+ case 'P':
73674+ break;
73675 case 'K':
73676 /*
73677 * %pK cannot be used in IRQ context because its test
73678@@ -1113,6 +1131,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
73679 }
73680 break;
73681 }
73682+
73683+#ifdef CONFIG_GRKERNSEC_HIDESYM
73684+ /* 'P' = approved pointers to copy to userland,
73685+ as in the /proc/kallsyms case, as we make it display nothing
73686+ for non-root users, and the real contents for root users
73687+ Also ignore 'K' pointers, since we force their NULLing for non-root users
73688+ above
73689+ */
73690+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
73691+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
73692+ dump_stack();
73693+ ptr = NULL;
73694+ }
73695+#endif
73696+
73697 spec.flags |= SMALL;
73698 if (spec.field_width == -1) {
73699 spec.field_width = default_width;
73700@@ -1831,11 +1864,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73701 typeof(type) value; \
73702 if (sizeof(type) == 8) { \
73703 args = PTR_ALIGN(args, sizeof(u32)); \
73704- *(u32 *)&value = *(u32 *)args; \
73705- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
73706+ *(u32 *)&value = *(const u32 *)args; \
73707+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
73708 } else { \
73709 args = PTR_ALIGN(args, sizeof(type)); \
73710- value = *(typeof(type) *)args; \
73711+ value = *(const typeof(type) *)args; \
73712 } \
73713 args += sizeof(type); \
73714 value; \
73715@@ -1898,7 +1931,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
73716 case FORMAT_TYPE_STR: {
73717 const char *str_arg = args;
73718 args += strlen(str_arg) + 1;
73719- str = string(str, end, (char *)str_arg, spec);
73720+ str = string(str, end, str_arg, spec);
73721 break;
73722 }
73723
73724diff --git a/localversion-grsec b/localversion-grsec
73725new file mode 100644
73726index 0000000..7cd6065
73727--- /dev/null
73728+++ b/localversion-grsec
73729@@ -0,0 +1 @@
73730+-grsec
73731diff --git a/mm/Kconfig b/mm/Kconfig
73732index a3f8ddd..f31e92e 100644
73733--- a/mm/Kconfig
73734+++ b/mm/Kconfig
73735@@ -252,10 +252,10 @@ config KSM
73736 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
73737
73738 config DEFAULT_MMAP_MIN_ADDR
73739- int "Low address space to protect from user allocation"
73740+ int "Low address space to protect from user allocation"
73741 depends on MMU
73742- default 4096
73743- help
73744+ default 65536
73745+ help
73746 This is the portion of low virtual memory which should be protected
73747 from userspace allocation. Keeping a user from writing to low pages
73748 can help reduce the impact of kernel NULL pointer bugs.
73749@@ -286,7 +286,7 @@ config MEMORY_FAILURE
73750
73751 config HWPOISON_INJECT
73752 tristate "HWPoison pages injector"
73753- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
73754+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
73755 select PROC_PAGE_MONITOR
73756
73757 config NOMMU_INITIAL_TRIM_EXCESS
73758diff --git a/mm/filemap.c b/mm/filemap.c
73759index 83efee7..3f99381 100644
73760--- a/mm/filemap.c
73761+++ b/mm/filemap.c
73762@@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
73763 struct address_space *mapping = file->f_mapping;
73764
73765 if (!mapping->a_ops->readpage)
73766- return -ENOEXEC;
73767+ return -ENODEV;
73768 file_accessed(file);
73769 vma->vm_ops = &generic_file_vm_ops;
73770 return 0;
73771@@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
73772 *pos = i_size_read(inode);
73773
73774 if (limit != RLIM_INFINITY) {
73775+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
73776 if (*pos >= limit) {
73777 send_sig(SIGXFSZ, current, 0);
73778 return -EFBIG;
73779diff --git a/mm/fremap.c b/mm/fremap.c
73780index a0aaf0e..20325c3 100644
73781--- a/mm/fremap.c
73782+++ b/mm/fremap.c
73783@@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
73784 retry:
73785 vma = find_vma(mm, start);
73786
73787+#ifdef CONFIG_PAX_SEGMEXEC
73788+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
73789+ goto out;
73790+#endif
73791+
73792 /*
73793 * Make sure the vma is shared, that it supports prefaulting,
73794 * and that the remapped range is valid and fully within
73795diff --git a/mm/highmem.c b/mm/highmem.c
73796index 09fc744..3936897 100644
73797--- a/mm/highmem.c
73798+++ b/mm/highmem.c
73799@@ -138,9 +138,10 @@ static void flush_all_zero_pkmaps(void)
73800 * So no dangers, even with speculative execution.
73801 */
73802 page = pte_page(pkmap_page_table[i]);
73803+ pax_open_kernel();
73804 pte_clear(&init_mm, (unsigned long)page_address(page),
73805 &pkmap_page_table[i]);
73806-
73807+ pax_close_kernel();
73808 set_page_address(page, NULL);
73809 need_flush = 1;
73810 }
73811@@ -199,9 +200,11 @@ start:
73812 }
73813 }
73814 vaddr = PKMAP_ADDR(last_pkmap_nr);
73815+
73816+ pax_open_kernel();
73817 set_pte_at(&init_mm, vaddr,
73818 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
73819-
73820+ pax_close_kernel();
73821 pkmap_count[last_pkmap_nr] = 1;
73822 set_page_address(page, (void *)vaddr);
73823
73824diff --git a/mm/huge_memory.c b/mm/huge_memory.c
73825index 40f17c3..c1cc011 100644
73826--- a/mm/huge_memory.c
73827+++ b/mm/huge_memory.c
73828@@ -710,7 +710,7 @@ out:
73829 * run pte_offset_map on the pmd, if an huge pmd could
73830 * materialize from under us from a different thread.
73831 */
73832- if (unlikely(__pte_alloc(mm, vma, pmd, address)))
73833+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
73834 return VM_FAULT_OOM;
73835 /* if an huge pmd materialized from under us just retry later */
73836 if (unlikely(pmd_trans_huge(*pmd)))
73837diff --git a/mm/hugetlb.c b/mm/hugetlb.c
73838index f198aca..a19a5a5 100644
73839--- a/mm/hugetlb.c
73840+++ b/mm/hugetlb.c
73841@@ -2509,6 +2509,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
73842 return 1;
73843 }
73844
73845+#ifdef CONFIG_PAX_SEGMEXEC
73846+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
73847+{
73848+ struct mm_struct *mm = vma->vm_mm;
73849+ struct vm_area_struct *vma_m;
73850+ unsigned long address_m;
73851+ pte_t *ptep_m;
73852+
73853+ vma_m = pax_find_mirror_vma(vma);
73854+ if (!vma_m)
73855+ return;
73856+
73857+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
73858+ address_m = address + SEGMEXEC_TASK_SIZE;
73859+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
73860+ get_page(page_m);
73861+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
73862+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
73863+}
73864+#endif
73865+
73866 /*
73867 * Hugetlb_cow() should be called with page lock of the original hugepage held.
73868 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
73869@@ -2627,6 +2648,11 @@ retry_avoidcopy:
73870 make_huge_pte(vma, new_page, 1));
73871 page_remove_rmap(old_page);
73872 hugepage_add_new_anon_rmap(new_page, vma, address);
73873+
73874+#ifdef CONFIG_PAX_SEGMEXEC
73875+ pax_mirror_huge_pte(vma, address, new_page);
73876+#endif
73877+
73878 /* Make the old page be freed below */
73879 new_page = old_page;
73880 }
73881@@ -2786,6 +2812,10 @@ retry:
73882 && (vma->vm_flags & VM_SHARED)));
73883 set_huge_pte_at(mm, address, ptep, new_pte);
73884
73885+#ifdef CONFIG_PAX_SEGMEXEC
73886+ pax_mirror_huge_pte(vma, address, page);
73887+#endif
73888+
73889 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
73890 /* Optimization, do the COW without a second fault */
73891 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
73892@@ -2815,6 +2845,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73893 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
73894 struct hstate *h = hstate_vma(vma);
73895
73896+#ifdef CONFIG_PAX_SEGMEXEC
73897+ struct vm_area_struct *vma_m;
73898+#endif
73899+
73900 address &= huge_page_mask(h);
73901
73902 ptep = huge_pte_offset(mm, address);
73903@@ -2828,6 +2862,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
73904 VM_FAULT_SET_HINDEX(hstate_index(h));
73905 }
73906
73907+#ifdef CONFIG_PAX_SEGMEXEC
73908+ vma_m = pax_find_mirror_vma(vma);
73909+ if (vma_m) {
73910+ unsigned long address_m;
73911+
73912+ if (vma->vm_start > vma_m->vm_start) {
73913+ address_m = address;
73914+ address -= SEGMEXEC_TASK_SIZE;
73915+ vma = vma_m;
73916+ h = hstate_vma(vma);
73917+ } else
73918+ address_m = address + SEGMEXEC_TASK_SIZE;
73919+
73920+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
73921+ return VM_FAULT_OOM;
73922+ address_m &= HPAGE_MASK;
73923+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
73924+ }
73925+#endif
73926+
73927 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
73928 if (!ptep)
73929 return VM_FAULT_OOM;
73930diff --git a/mm/internal.h b/mm/internal.h
73931index 3c5197d..08d0065 100644
73932--- a/mm/internal.h
73933+++ b/mm/internal.h
73934@@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
73935 * in mm/page_alloc.c
73936 */
73937 extern void __free_pages_bootmem(struct page *page, unsigned int order);
73938+extern void free_compound_page(struct page *page);
73939 extern void prep_compound_page(struct page *page, unsigned long order);
73940 #ifdef CONFIG_MEMORY_FAILURE
73941 extern bool is_free_buddy_page(struct page *page);
73942diff --git a/mm/kmemleak.c b/mm/kmemleak.c
73943index a217cc5..44b2b35 100644
73944--- a/mm/kmemleak.c
73945+++ b/mm/kmemleak.c
73946@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
73947
73948 for (i = 0; i < object->trace_len; i++) {
73949 void *ptr = (void *)object->trace[i];
73950- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
73951+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
73952 }
73953 }
73954
73955@@ -1852,7 +1852,7 @@ static int __init kmemleak_late_init(void)
73956 return -ENOMEM;
73957 }
73958
73959- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
73960+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
73961 &kmemleak_fops);
73962 if (!dentry)
73963 pr_warning("Failed to create the debugfs kmemleak file\n");
73964diff --git a/mm/maccess.c b/mm/maccess.c
73965index d53adf9..03a24bf 100644
73966--- a/mm/maccess.c
73967+++ b/mm/maccess.c
73968@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
73969 set_fs(KERNEL_DS);
73970 pagefault_disable();
73971 ret = __copy_from_user_inatomic(dst,
73972- (__force const void __user *)src, size);
73973+ (const void __force_user *)src, size);
73974 pagefault_enable();
73975 set_fs(old_fs);
73976
73977@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
73978
73979 set_fs(KERNEL_DS);
73980 pagefault_disable();
73981- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
73982+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
73983 pagefault_enable();
73984 set_fs(old_fs);
73985
73986diff --git a/mm/madvise.c b/mm/madvise.c
73987index 03dfa5c..b032917 100644
73988--- a/mm/madvise.c
73989+++ b/mm/madvise.c
73990@@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
73991 pgoff_t pgoff;
73992 unsigned long new_flags = vma->vm_flags;
73993
73994+#ifdef CONFIG_PAX_SEGMEXEC
73995+ struct vm_area_struct *vma_m;
73996+#endif
73997+
73998 switch (behavior) {
73999 case MADV_NORMAL:
74000 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
74001@@ -123,6 +127,13 @@ success:
74002 /*
74003 * vm_flags is protected by the mmap_sem held in write mode.
74004 */
74005+
74006+#ifdef CONFIG_PAX_SEGMEXEC
74007+ vma_m = pax_find_mirror_vma(vma);
74008+ if (vma_m)
74009+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
74010+#endif
74011+
74012 vma->vm_flags = new_flags;
74013
74014 out:
74015@@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74016 struct vm_area_struct ** prev,
74017 unsigned long start, unsigned long end)
74018 {
74019+
74020+#ifdef CONFIG_PAX_SEGMEXEC
74021+ struct vm_area_struct *vma_m;
74022+#endif
74023+
74024 *prev = vma;
74025 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
74026 return -EINVAL;
74027@@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
74028 zap_page_range(vma, start, end - start, &details);
74029 } else
74030 zap_page_range(vma, start, end - start, NULL);
74031+
74032+#ifdef CONFIG_PAX_SEGMEXEC
74033+ vma_m = pax_find_mirror_vma(vma);
74034+ if (vma_m) {
74035+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
74036+ struct zap_details details = {
74037+ .nonlinear_vma = vma_m,
74038+ .last_index = ULONG_MAX,
74039+ };
74040+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
74041+ } else
74042+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
74043+ }
74044+#endif
74045+
74046 return 0;
74047 }
74048
74049@@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
74050 if (end < start)
74051 goto out;
74052
74053+#ifdef CONFIG_PAX_SEGMEXEC
74054+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74055+ if (end > SEGMEXEC_TASK_SIZE)
74056+ goto out;
74057+ } else
74058+#endif
74059+
74060+ if (end > TASK_SIZE)
74061+ goto out;
74062+
74063 error = 0;
74064 if (end == start)
74065 goto out;
74066diff --git a/mm/memory-failure.c b/mm/memory-failure.c
74067index 8b20278..05dac18 100644
74068--- a/mm/memory-failure.c
74069+++ b/mm/memory-failure.c
74070@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
74071
74072 int sysctl_memory_failure_recovery __read_mostly = 1;
74073
74074-atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74075+atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
74076
74077 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
74078
74079@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
74080 pfn, t->comm, t->pid);
74081 si.si_signo = SIGBUS;
74082 si.si_errno = 0;
74083- si.si_addr = (void *)addr;
74084+ si.si_addr = (void __user *)addr;
74085 #ifdef __ARCH_SI_TRAPNO
74086 si.si_trapno = trapno;
74087 #endif
74088@@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74089 }
74090
74091 nr_pages = 1 << compound_trans_order(hpage);
74092- atomic_long_add(nr_pages, &mce_bad_pages);
74093+ atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
74094
74095 /*
74096 * We need/can do nothing about count=0 pages.
74097@@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74098 if (!PageHWPoison(hpage)
74099 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
74100 || (p != hpage && TestSetPageHWPoison(hpage))) {
74101- atomic_long_sub(nr_pages, &mce_bad_pages);
74102+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74103 return 0;
74104 }
74105 set_page_hwpoison_huge_page(hpage);
74106@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
74107 }
74108 if (hwpoison_filter(p)) {
74109 if (TestClearPageHWPoison(p))
74110- atomic_long_sub(nr_pages, &mce_bad_pages);
74111+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74112 unlock_page(hpage);
74113 put_page(hpage);
74114 return 0;
74115@@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
74116 return 0;
74117 }
74118 if (TestClearPageHWPoison(p))
74119- atomic_long_sub(nr_pages, &mce_bad_pages);
74120+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74121 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
74122 return 0;
74123 }
74124@@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
74125 */
74126 if (TestClearPageHWPoison(page)) {
74127 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
74128- atomic_long_sub(nr_pages, &mce_bad_pages);
74129+ atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
74130 freeit = 1;
74131 if (PageHuge(page))
74132 clear_page_hwpoison_huge_page(page);
74133@@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
74134 }
74135 done:
74136 if (!PageHWPoison(hpage))
74137- atomic_long_add(1 << compound_trans_order(hpage),
74138+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
74139 &mce_bad_pages);
74140 set_page_hwpoison_huge_page(hpage);
74141 dequeue_hwpoisoned_huge_page(hpage);
74142@@ -1582,7 +1582,7 @@ int soft_offline_page(struct page *page, int flags)
74143 return ret;
74144
74145 done:
74146- atomic_long_add(1, &mce_bad_pages);
74147+ atomic_long_add_unchecked(1, &mce_bad_pages);
74148 SetPageHWPoison(page);
74149 /* keep elevated page count for bad page */
74150 return ret;
74151diff --git a/mm/memory.c b/mm/memory.c
74152index f2973b2..fd020a7 100644
74153--- a/mm/memory.c
74154+++ b/mm/memory.c
74155@@ -431,6 +431,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74156 free_pte_range(tlb, pmd, addr);
74157 } while (pmd++, addr = next, addr != end);
74158
74159+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
74160 start &= PUD_MASK;
74161 if (start < floor)
74162 return;
74163@@ -445,6 +446,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
74164 pmd = pmd_offset(pud, start);
74165 pud_clear(pud);
74166 pmd_free_tlb(tlb, pmd, start);
74167+#endif
74168+
74169 }
74170
74171 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74172@@ -464,6 +467,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74173 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
74174 } while (pud++, addr = next, addr != end);
74175
74176+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
74177 start &= PGDIR_MASK;
74178 if (start < floor)
74179 return;
74180@@ -478,6 +482,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
74181 pud = pud_offset(pgd, start);
74182 pgd_clear(pgd);
74183 pud_free_tlb(tlb, pud, start);
74184+#endif
74185+
74186 }
74187
74188 /*
74189@@ -1626,12 +1632,6 @@ no_page_table:
74190 return page;
74191 }
74192
74193-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
74194-{
74195- return stack_guard_page_start(vma, addr) ||
74196- stack_guard_page_end(vma, addr+PAGE_SIZE);
74197-}
74198-
74199 /**
74200 * __get_user_pages() - pin user pages in memory
74201 * @tsk: task_struct of target task
74202@@ -1704,10 +1704,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74203 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
74204 i = 0;
74205
74206- do {
74207+ while (nr_pages) {
74208 struct vm_area_struct *vma;
74209
74210- vma = find_extend_vma(mm, start);
74211+ vma = find_vma(mm, start);
74212 if (!vma && in_gate_area(mm, start)) {
74213 unsigned long pg = start & PAGE_MASK;
74214 pgd_t *pgd;
74215@@ -1755,7 +1755,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74216 goto next_page;
74217 }
74218
74219- if (!vma ||
74220+ if (!vma || start < vma->vm_start ||
74221 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
74222 !(vm_flags & vma->vm_flags))
74223 return i ? : -EFAULT;
74224@@ -1782,11 +1782,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
74225 int ret;
74226 unsigned int fault_flags = 0;
74227
74228- /* For mlock, just skip the stack guard page. */
74229- if (foll_flags & FOLL_MLOCK) {
74230- if (stack_guard_page(vma, start))
74231- goto next_page;
74232- }
74233 if (foll_flags & FOLL_WRITE)
74234 fault_flags |= FAULT_FLAG_WRITE;
74235 if (nonblocking)
74236@@ -1860,7 +1855,7 @@ next_page:
74237 start += PAGE_SIZE;
74238 nr_pages--;
74239 } while (nr_pages && start < vma->vm_end);
74240- } while (nr_pages);
74241+ }
74242 return i;
74243 }
74244 EXPORT_SYMBOL(__get_user_pages);
74245@@ -2067,6 +2062,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
74246 page_add_file_rmap(page);
74247 set_pte_at(mm, addr, pte, mk_pte(page, prot));
74248
74249+#ifdef CONFIG_PAX_SEGMEXEC
74250+ pax_mirror_file_pte(vma, addr, page, ptl);
74251+#endif
74252+
74253 retval = 0;
74254 pte_unmap_unlock(pte, ptl);
74255 return retval;
74256@@ -2111,9 +2110,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
74257 if (!page_count(page))
74258 return -EINVAL;
74259 if (!(vma->vm_flags & VM_MIXEDMAP)) {
74260+
74261+#ifdef CONFIG_PAX_SEGMEXEC
74262+ struct vm_area_struct *vma_m;
74263+#endif
74264+
74265 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
74266 BUG_ON(vma->vm_flags & VM_PFNMAP);
74267 vma->vm_flags |= VM_MIXEDMAP;
74268+
74269+#ifdef CONFIG_PAX_SEGMEXEC
74270+ vma_m = pax_find_mirror_vma(vma);
74271+ if (vma_m)
74272+ vma_m->vm_flags |= VM_MIXEDMAP;
74273+#endif
74274+
74275 }
74276 return insert_page(vma, addr, page, vma->vm_page_prot);
74277 }
74278@@ -2196,6 +2207,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
74279 unsigned long pfn)
74280 {
74281 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
74282+ BUG_ON(vma->vm_mirror);
74283
74284 if (addr < vma->vm_start || addr >= vma->vm_end)
74285 return -EFAULT;
74286@@ -2396,7 +2408,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
74287
74288 BUG_ON(pud_huge(*pud));
74289
74290- pmd = pmd_alloc(mm, pud, addr);
74291+ pmd = (mm == &init_mm) ?
74292+ pmd_alloc_kernel(mm, pud, addr) :
74293+ pmd_alloc(mm, pud, addr);
74294 if (!pmd)
74295 return -ENOMEM;
74296 do {
74297@@ -2416,7 +2430,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
74298 unsigned long next;
74299 int err;
74300
74301- pud = pud_alloc(mm, pgd, addr);
74302+ pud = (mm == &init_mm) ?
74303+ pud_alloc_kernel(mm, pgd, addr) :
74304+ pud_alloc(mm, pgd, addr);
74305 if (!pud)
74306 return -ENOMEM;
74307 do {
74308@@ -2504,6 +2520,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
74309 copy_user_highpage(dst, src, va, vma);
74310 }
74311
74312+#ifdef CONFIG_PAX_SEGMEXEC
74313+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
74314+{
74315+ struct mm_struct *mm = vma->vm_mm;
74316+ spinlock_t *ptl;
74317+ pte_t *pte, entry;
74318+
74319+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
74320+ entry = *pte;
74321+ if (!pte_present(entry)) {
74322+ if (!pte_none(entry)) {
74323+ BUG_ON(pte_file(entry));
74324+ free_swap_and_cache(pte_to_swp_entry(entry));
74325+ pte_clear_not_present_full(mm, address, pte, 0);
74326+ }
74327+ } else {
74328+ struct page *page;
74329+
74330+ flush_cache_page(vma, address, pte_pfn(entry));
74331+ entry = ptep_clear_flush(vma, address, pte);
74332+ BUG_ON(pte_dirty(entry));
74333+ page = vm_normal_page(vma, address, entry);
74334+ if (page) {
74335+ update_hiwater_rss(mm);
74336+ if (PageAnon(page))
74337+ dec_mm_counter_fast(mm, MM_ANONPAGES);
74338+ else
74339+ dec_mm_counter_fast(mm, MM_FILEPAGES);
74340+ page_remove_rmap(page);
74341+ page_cache_release(page);
74342+ }
74343+ }
74344+ pte_unmap_unlock(pte, ptl);
74345+}
74346+
74347+/* PaX: if vma is mirrored, synchronize the mirror's PTE
74348+ *
74349+ * the ptl of the lower mapped page is held on entry and is not released on exit
74350+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
74351+ */
74352+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74353+{
74354+ struct mm_struct *mm = vma->vm_mm;
74355+ unsigned long address_m;
74356+ spinlock_t *ptl_m;
74357+ struct vm_area_struct *vma_m;
74358+ pmd_t *pmd_m;
74359+ pte_t *pte_m, entry_m;
74360+
74361+ BUG_ON(!page_m || !PageAnon(page_m));
74362+
74363+ vma_m = pax_find_mirror_vma(vma);
74364+ if (!vma_m)
74365+ return;
74366+
74367+ BUG_ON(!PageLocked(page_m));
74368+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74369+ address_m = address + SEGMEXEC_TASK_SIZE;
74370+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74371+ pte_m = pte_offset_map(pmd_m, address_m);
74372+ ptl_m = pte_lockptr(mm, pmd_m);
74373+ if (ptl != ptl_m) {
74374+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74375+ if (!pte_none(*pte_m))
74376+ goto out;
74377+ }
74378+
74379+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74380+ page_cache_get(page_m);
74381+ page_add_anon_rmap(page_m, vma_m, address_m);
74382+ inc_mm_counter_fast(mm, MM_ANONPAGES);
74383+ set_pte_at(mm, address_m, pte_m, entry_m);
74384+ update_mmu_cache(vma_m, address_m, entry_m);
74385+out:
74386+ if (ptl != ptl_m)
74387+ spin_unlock(ptl_m);
74388+ pte_unmap(pte_m);
74389+ unlock_page(page_m);
74390+}
74391+
74392+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
74393+{
74394+ struct mm_struct *mm = vma->vm_mm;
74395+ unsigned long address_m;
74396+ spinlock_t *ptl_m;
74397+ struct vm_area_struct *vma_m;
74398+ pmd_t *pmd_m;
74399+ pte_t *pte_m, entry_m;
74400+
74401+ BUG_ON(!page_m || PageAnon(page_m));
74402+
74403+ vma_m = pax_find_mirror_vma(vma);
74404+ if (!vma_m)
74405+ return;
74406+
74407+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74408+ address_m = address + SEGMEXEC_TASK_SIZE;
74409+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74410+ pte_m = pte_offset_map(pmd_m, address_m);
74411+ ptl_m = pte_lockptr(mm, pmd_m);
74412+ if (ptl != ptl_m) {
74413+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74414+ if (!pte_none(*pte_m))
74415+ goto out;
74416+ }
74417+
74418+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
74419+ page_cache_get(page_m);
74420+ page_add_file_rmap(page_m);
74421+ inc_mm_counter_fast(mm, MM_FILEPAGES);
74422+ set_pte_at(mm, address_m, pte_m, entry_m);
74423+ update_mmu_cache(vma_m, address_m, entry_m);
74424+out:
74425+ if (ptl != ptl_m)
74426+ spin_unlock(ptl_m);
74427+ pte_unmap(pte_m);
74428+}
74429+
74430+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
74431+{
74432+ struct mm_struct *mm = vma->vm_mm;
74433+ unsigned long address_m;
74434+ spinlock_t *ptl_m;
74435+ struct vm_area_struct *vma_m;
74436+ pmd_t *pmd_m;
74437+ pte_t *pte_m, entry_m;
74438+
74439+ vma_m = pax_find_mirror_vma(vma);
74440+ if (!vma_m)
74441+ return;
74442+
74443+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
74444+ address_m = address + SEGMEXEC_TASK_SIZE;
74445+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
74446+ pte_m = pte_offset_map(pmd_m, address_m);
74447+ ptl_m = pte_lockptr(mm, pmd_m);
74448+ if (ptl != ptl_m) {
74449+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
74450+ if (!pte_none(*pte_m))
74451+ goto out;
74452+ }
74453+
74454+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
74455+ set_pte_at(mm, address_m, pte_m, entry_m);
74456+out:
74457+ if (ptl != ptl_m)
74458+ spin_unlock(ptl_m);
74459+ pte_unmap(pte_m);
74460+}
74461+
74462+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
74463+{
74464+ struct page *page_m;
74465+ pte_t entry;
74466+
74467+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
74468+ goto out;
74469+
74470+ entry = *pte;
74471+ page_m = vm_normal_page(vma, address, entry);
74472+ if (!page_m)
74473+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
74474+ else if (PageAnon(page_m)) {
74475+ if (pax_find_mirror_vma(vma)) {
74476+ pte_unmap_unlock(pte, ptl);
74477+ lock_page(page_m);
74478+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
74479+ if (pte_same(entry, *pte))
74480+ pax_mirror_anon_pte(vma, address, page_m, ptl);
74481+ else
74482+ unlock_page(page_m);
74483+ }
74484+ } else
74485+ pax_mirror_file_pte(vma, address, page_m, ptl);
74486+
74487+out:
74488+ pte_unmap_unlock(pte, ptl);
74489+}
74490+#endif
74491+
74492 /*
74493 * This routine handles present pages, when users try to write
74494 * to a shared page. It is done by copying the page to a new address
74495@@ -2720,6 +2916,12 @@ gotten:
74496 */
74497 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74498 if (likely(pte_same(*page_table, orig_pte))) {
74499+
74500+#ifdef CONFIG_PAX_SEGMEXEC
74501+ if (pax_find_mirror_vma(vma))
74502+ BUG_ON(!trylock_page(new_page));
74503+#endif
74504+
74505 if (old_page) {
74506 if (!PageAnon(old_page)) {
74507 dec_mm_counter_fast(mm, MM_FILEPAGES);
74508@@ -2771,6 +2973,10 @@ gotten:
74509 page_remove_rmap(old_page);
74510 }
74511
74512+#ifdef CONFIG_PAX_SEGMEXEC
74513+ pax_mirror_anon_pte(vma, address, new_page, ptl);
74514+#endif
74515+
74516 /* Free the old page.. */
74517 new_page = old_page;
74518 ret |= VM_FAULT_WRITE;
74519@@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74520 swap_free(entry);
74521 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
74522 try_to_free_swap(page);
74523+
74524+#ifdef CONFIG_PAX_SEGMEXEC
74525+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
74526+#endif
74527+
74528 unlock_page(page);
74529 if (swapcache) {
74530 /*
74531@@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
74532
74533 /* No need to invalidate - it was non-present before */
74534 update_mmu_cache(vma, address, page_table);
74535+
74536+#ifdef CONFIG_PAX_SEGMEXEC
74537+ pax_mirror_anon_pte(vma, address, page, ptl);
74538+#endif
74539+
74540 unlock:
74541 pte_unmap_unlock(page_table, ptl);
74542 out:
74543@@ -3093,40 +3309,6 @@ out_release:
74544 }
74545
74546 /*
74547- * This is like a special single-page "expand_{down|up}wards()",
74548- * except we must first make sure that 'address{-|+}PAGE_SIZE'
74549- * doesn't hit another vma.
74550- */
74551-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
74552-{
74553- address &= PAGE_MASK;
74554- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
74555- struct vm_area_struct *prev = vma->vm_prev;
74556-
74557- /*
74558- * Is there a mapping abutting this one below?
74559- *
74560- * That's only ok if it's the same stack mapping
74561- * that has gotten split..
74562- */
74563- if (prev && prev->vm_end == address)
74564- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
74565-
74566- expand_downwards(vma, address - PAGE_SIZE);
74567- }
74568- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
74569- struct vm_area_struct *next = vma->vm_next;
74570-
74571- /* As VM_GROWSDOWN but s/below/above/ */
74572- if (next && next->vm_start == address + PAGE_SIZE)
74573- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
74574-
74575- expand_upwards(vma, address + PAGE_SIZE);
74576- }
74577- return 0;
74578-}
74579-
74580-/*
74581 * We enter with non-exclusive mmap_sem (to exclude vma changes,
74582 * but allow concurrent faults), and pte mapped but not yet locked.
74583 * We return with mmap_sem still held, but pte unmapped and unlocked.
74584@@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74585 unsigned long address, pte_t *page_table, pmd_t *pmd,
74586 unsigned int flags)
74587 {
74588- struct page *page;
74589+ struct page *page = NULL;
74590 spinlock_t *ptl;
74591 pte_t entry;
74592
74593- pte_unmap(page_table);
74594-
74595- /* Check if we need to add a guard page to the stack */
74596- if (check_stack_guard_page(vma, address) < 0)
74597- return VM_FAULT_SIGBUS;
74598-
74599- /* Use the zero-page for reads */
74600 if (!(flags & FAULT_FLAG_WRITE)) {
74601 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
74602 vma->vm_page_prot));
74603- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
74604+ ptl = pte_lockptr(mm, pmd);
74605+ spin_lock(ptl);
74606 if (!pte_none(*page_table))
74607 goto unlock;
74608 goto setpte;
74609 }
74610
74611 /* Allocate our own private page. */
74612+ pte_unmap(page_table);
74613+
74614 if (unlikely(anon_vma_prepare(vma)))
74615 goto oom;
74616 page = alloc_zeroed_user_highpage_movable(vma, address);
74617@@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
74618 if (!pte_none(*page_table))
74619 goto release;
74620
74621+#ifdef CONFIG_PAX_SEGMEXEC
74622+ if (pax_find_mirror_vma(vma))
74623+ BUG_ON(!trylock_page(page));
74624+#endif
74625+
74626 inc_mm_counter_fast(mm, MM_ANONPAGES);
74627 page_add_new_anon_rmap(page, vma, address);
74628 setpte:
74629@@ -3181,6 +3364,12 @@ setpte:
74630
74631 /* No need to invalidate - it was non-present before */
74632 update_mmu_cache(vma, address, page_table);
74633+
74634+#ifdef CONFIG_PAX_SEGMEXEC
74635+ if (page)
74636+ pax_mirror_anon_pte(vma, address, page, ptl);
74637+#endif
74638+
74639 unlock:
74640 pte_unmap_unlock(page_table, ptl);
74641 return 0;
74642@@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74643 */
74644 /* Only go through if we didn't race with anybody else... */
74645 if (likely(pte_same(*page_table, orig_pte))) {
74646+
74647+#ifdef CONFIG_PAX_SEGMEXEC
74648+ if (anon && pax_find_mirror_vma(vma))
74649+ BUG_ON(!trylock_page(page));
74650+#endif
74651+
74652 flush_icache_page(vma, page);
74653 entry = mk_pte(page, vma->vm_page_prot);
74654 if (flags & FAULT_FLAG_WRITE)
74655@@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74656
74657 /* no need to invalidate: a not-present page won't be cached */
74658 update_mmu_cache(vma, address, page_table);
74659+
74660+#ifdef CONFIG_PAX_SEGMEXEC
74661+ if (anon)
74662+ pax_mirror_anon_pte(vma, address, page, ptl);
74663+ else
74664+ pax_mirror_file_pte(vma, address, page, ptl);
74665+#endif
74666+
74667 } else {
74668 if (cow_page)
74669 mem_cgroup_uncharge_page(cow_page);
74670@@ -3497,6 +3700,12 @@ int handle_pte_fault(struct mm_struct *mm,
74671 if (flags & FAULT_FLAG_WRITE)
74672 flush_tlb_fix_spurious_fault(vma, address);
74673 }
74674+
74675+#ifdef CONFIG_PAX_SEGMEXEC
74676+ pax_mirror_pte(vma, address, pte, pmd, ptl);
74677+ return 0;
74678+#endif
74679+
74680 unlock:
74681 pte_unmap_unlock(pte, ptl);
74682 return 0;
74683@@ -3513,6 +3722,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74684 pmd_t *pmd;
74685 pte_t *pte;
74686
74687+#ifdef CONFIG_PAX_SEGMEXEC
74688+ struct vm_area_struct *vma_m;
74689+#endif
74690+
74691 __set_current_state(TASK_RUNNING);
74692
74693 count_vm_event(PGFAULT);
74694@@ -3524,6 +3737,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
74695 if (unlikely(is_vm_hugetlb_page(vma)))
74696 return hugetlb_fault(mm, vma, address, flags);
74697
74698+#ifdef CONFIG_PAX_SEGMEXEC
74699+ vma_m = pax_find_mirror_vma(vma);
74700+ if (vma_m) {
74701+ unsigned long address_m;
74702+ pgd_t *pgd_m;
74703+ pud_t *pud_m;
74704+ pmd_t *pmd_m;
74705+
74706+ if (vma->vm_start > vma_m->vm_start) {
74707+ address_m = address;
74708+ address -= SEGMEXEC_TASK_SIZE;
74709+ vma = vma_m;
74710+ } else
74711+ address_m = address + SEGMEXEC_TASK_SIZE;
74712+
74713+ pgd_m = pgd_offset(mm, address_m);
74714+ pud_m = pud_alloc(mm, pgd_m, address_m);
74715+ if (!pud_m)
74716+ return VM_FAULT_OOM;
74717+ pmd_m = pmd_alloc(mm, pud_m, address_m);
74718+ if (!pmd_m)
74719+ return VM_FAULT_OOM;
74720+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
74721+ return VM_FAULT_OOM;
74722+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
74723+ }
74724+#endif
74725+
74726 retry:
74727 pgd = pgd_offset(mm, address);
74728 pud = pud_alloc(mm, pgd, address);
74729@@ -3565,7 +3806,7 @@ retry:
74730 * run pte_offset_map on the pmd, if an huge pmd could
74731 * materialize from under us from a different thread.
74732 */
74733- if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
74734+ if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
74735 return VM_FAULT_OOM;
74736 /* if an huge pmd materialized from under us just retry later */
74737 if (unlikely(pmd_trans_huge(*pmd)))
74738@@ -3602,6 +3843,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74739 spin_unlock(&mm->page_table_lock);
74740 return 0;
74741 }
74742+
74743+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
74744+{
74745+ pud_t *new = pud_alloc_one(mm, address);
74746+ if (!new)
74747+ return -ENOMEM;
74748+
74749+ smp_wmb(); /* See comment in __pte_alloc */
74750+
74751+ spin_lock(&mm->page_table_lock);
74752+ if (pgd_present(*pgd)) /* Another has populated it */
74753+ pud_free(mm, new);
74754+ else
74755+ pgd_populate_kernel(mm, pgd, new);
74756+ spin_unlock(&mm->page_table_lock);
74757+ return 0;
74758+}
74759 #endif /* __PAGETABLE_PUD_FOLDED */
74760
74761 #ifndef __PAGETABLE_PMD_FOLDED
74762@@ -3632,6 +3890,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
74763 spin_unlock(&mm->page_table_lock);
74764 return 0;
74765 }
74766+
74767+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
74768+{
74769+ pmd_t *new = pmd_alloc_one(mm, address);
74770+ if (!new)
74771+ return -ENOMEM;
74772+
74773+ smp_wmb(); /* See comment in __pte_alloc */
74774+
74775+ spin_lock(&mm->page_table_lock);
74776+#ifndef __ARCH_HAS_4LEVEL_HACK
74777+ if (pud_present(*pud)) /* Another has populated it */
74778+ pmd_free(mm, new);
74779+ else
74780+ pud_populate_kernel(mm, pud, new);
74781+#else
74782+ if (pgd_present(*pud)) /* Another has populated it */
74783+ pmd_free(mm, new);
74784+ else
74785+ pgd_populate_kernel(mm, pud, new);
74786+#endif /* __ARCH_HAS_4LEVEL_HACK */
74787+ spin_unlock(&mm->page_table_lock);
74788+ return 0;
74789+}
74790 #endif /* __PAGETABLE_PMD_FOLDED */
74791
74792 int make_pages_present(unsigned long addr, unsigned long end)
74793@@ -3669,7 +3951,7 @@ static int __init gate_vma_init(void)
74794 gate_vma.vm_start = FIXADDR_USER_START;
74795 gate_vma.vm_end = FIXADDR_USER_END;
74796 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
74797- gate_vma.vm_page_prot = __P101;
74798+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
74799
74800 return 0;
74801 }
74802diff --git a/mm/mempolicy.c b/mm/mempolicy.c
74803index 002c281..9429765 100644
74804--- a/mm/mempolicy.c
74805+++ b/mm/mempolicy.c
74806@@ -655,6 +655,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74807 unsigned long vmstart;
74808 unsigned long vmend;
74809
74810+#ifdef CONFIG_PAX_SEGMEXEC
74811+ struct vm_area_struct *vma_m;
74812+#endif
74813+
74814 vma = find_vma(mm, start);
74815 if (!vma || vma->vm_start > start)
74816 return -EFAULT;
74817@@ -691,9 +695,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
74818 if (err)
74819 goto out;
74820 }
74821+
74822 err = vma_replace_policy(vma, new_pol);
74823 if (err)
74824 goto out;
74825+
74826+#ifdef CONFIG_PAX_SEGMEXEC
74827+ vma_m = pax_find_mirror_vma(vma);
74828+ if (vma_m) {
74829+ err = vma_replace_policy(vma_m, new_pol);
74830+ if (err)
74831+ goto out;
74832+ }
74833+#endif
74834+
74835 }
74836
74837 out:
74838@@ -1150,6 +1165,17 @@ static long do_mbind(unsigned long start, unsigned long len,
74839
74840 if (end < start)
74841 return -EINVAL;
74842+
74843+#ifdef CONFIG_PAX_SEGMEXEC
74844+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
74845+ if (end > SEGMEXEC_TASK_SIZE)
74846+ return -EINVAL;
74847+ } else
74848+#endif
74849+
74850+ if (end > TASK_SIZE)
74851+ return -EINVAL;
74852+
74853 if (end == start)
74854 return 0;
74855
74856@@ -1373,8 +1399,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74857 */
74858 tcred = __task_cred(task);
74859 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74860- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74861- !capable(CAP_SYS_NICE)) {
74862+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74863 rcu_read_unlock();
74864 err = -EPERM;
74865 goto out_put;
74866@@ -1405,6 +1430,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
74867 goto out;
74868 }
74869
74870+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
74871+ if (mm != current->mm &&
74872+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
74873+ mmput(mm);
74874+ err = -EPERM;
74875+ goto out;
74876+ }
74877+#endif
74878+
74879 err = do_migrate_pages(mm, old, new,
74880 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
74881
74882diff --git a/mm/migrate.c b/mm/migrate.c
74883index 77ed2d7..317d528 100644
74884--- a/mm/migrate.c
74885+++ b/mm/migrate.c
74886@@ -1350,8 +1350,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
74887 */
74888 tcred = __task_cred(task);
74889 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
74890- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
74891- !capable(CAP_SYS_NICE)) {
74892+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
74893 rcu_read_unlock();
74894 err = -EPERM;
74895 goto out;
74896diff --git a/mm/mlock.c b/mm/mlock.c
74897index f0b9ce5..da8d069 100644
74898--- a/mm/mlock.c
74899+++ b/mm/mlock.c
74900@@ -13,6 +13,7 @@
74901 #include <linux/pagemap.h>
74902 #include <linux/mempolicy.h>
74903 #include <linux/syscalls.h>
74904+#include <linux/security.h>
74905 #include <linux/sched.h>
74906 #include <linux/export.h>
74907 #include <linux/rmap.h>
74908@@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
74909 {
74910 unsigned long nstart, end, tmp;
74911 struct vm_area_struct * vma, * prev;
74912- int error;
74913+ int error = 0;
74914
74915 VM_BUG_ON(start & ~PAGE_MASK);
74916 VM_BUG_ON(len != PAGE_ALIGN(len));
74917@@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
74918 return -EINVAL;
74919 if (end == start)
74920 return 0;
74921+ if (end > TASK_SIZE)
74922+ return -EINVAL;
74923+
74924 vma = find_vma(current->mm, start);
74925 if (!vma || vma->vm_start > start)
74926 return -ENOMEM;
74927@@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
74928 for (nstart = start ; ; ) {
74929 vm_flags_t newflags;
74930
74931+#ifdef CONFIG_PAX_SEGMEXEC
74932+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74933+ break;
74934+#endif
74935+
74936 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
74937
74938 newflags = vma->vm_flags | VM_LOCKED;
74939@@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
74940 lock_limit >>= PAGE_SHIFT;
74941
74942 /* check against resource limits */
74943+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
74944 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
74945 error = do_mlock(start, len, 1);
74946 up_write(&current->mm->mmap_sem);
74947@@ -517,17 +527,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
74948 static int do_mlockall(int flags)
74949 {
74950 struct vm_area_struct * vma, * prev = NULL;
74951- unsigned int def_flags = 0;
74952
74953 if (flags & MCL_FUTURE)
74954- def_flags = VM_LOCKED;
74955- current->mm->def_flags = def_flags;
74956+ current->mm->def_flags |= VM_LOCKED;
74957+ else
74958+ current->mm->def_flags &= ~VM_LOCKED;
74959 if (flags == MCL_FUTURE)
74960 goto out;
74961
74962 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
74963 vm_flags_t newflags;
74964
74965+#ifdef CONFIG_PAX_SEGMEXEC
74966+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
74967+ break;
74968+#endif
74969+
74970+ BUG_ON(vma->vm_end > TASK_SIZE);
74971 newflags = vma->vm_flags | VM_LOCKED;
74972 if (!(flags & MCL_CURRENT))
74973 newflags &= ~VM_LOCKED;
74974@@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
74975 lock_limit >>= PAGE_SHIFT;
74976
74977 ret = -ENOMEM;
74978+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
74979 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
74980 capable(CAP_IPC_LOCK))
74981 ret = do_mlockall(flags);
74982diff --git a/mm/mmap.c b/mm/mmap.c
74983index 9a796c4..21f8e50 100644
74984--- a/mm/mmap.c
74985+++ b/mm/mmap.c
74986@@ -31,6 +31,7 @@
74987 #include <linux/audit.h>
74988 #include <linux/khugepaged.h>
74989 #include <linux/uprobes.h>
74990+#include <linux/random.h>
74991
74992 #include <asm/uaccess.h>
74993 #include <asm/cacheflush.h>
74994@@ -47,6 +48,16 @@
74995 #define arch_rebalance_pgtables(addr, len) (addr)
74996 #endif
74997
74998+static inline void verify_mm_writelocked(struct mm_struct *mm)
74999+{
75000+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
75001+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
75002+ up_read(&mm->mmap_sem);
75003+ BUG();
75004+ }
75005+#endif
75006+}
75007+
75008 static void unmap_region(struct mm_struct *mm,
75009 struct vm_area_struct *vma, struct vm_area_struct *prev,
75010 unsigned long start, unsigned long end);
75011@@ -66,22 +77,32 @@ static void unmap_region(struct mm_struct *mm,
75012 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
75013 *
75014 */
75015-pgprot_t protection_map[16] = {
75016+pgprot_t protection_map[16] __read_only = {
75017 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
75018 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
75019 };
75020
75021-pgprot_t vm_get_page_prot(unsigned long vm_flags)
75022+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75023 {
75024- return __pgprot(pgprot_val(protection_map[vm_flags &
75025+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
75026 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
75027 pgprot_val(arch_vm_get_page_prot(vm_flags)));
75028+
75029+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75030+ if (!(__supported_pte_mask & _PAGE_NX) &&
75031+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
75032+ (vm_flags & (VM_READ | VM_WRITE)))
75033+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
75034+#endif
75035+
75036+ return prot;
75037 }
75038 EXPORT_SYMBOL(vm_get_page_prot);
75039
75040 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
75041 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
75042 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
75043+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
75044 /*
75045 * Make sure vm_committed_as in one cacheline and not cacheline shared with
75046 * other variables. It can be updated by several CPUs frequently.
75047@@ -223,6 +244,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
75048 struct vm_area_struct *next = vma->vm_next;
75049
75050 might_sleep();
75051+ BUG_ON(vma->vm_mirror);
75052 if (vma->vm_ops && vma->vm_ops->close)
75053 vma->vm_ops->close(vma);
75054 if (vma->vm_file)
75055@@ -266,6 +288,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
75056 * not page aligned -Ram Gupta
75057 */
75058 rlim = rlimit(RLIMIT_DATA);
75059+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
75060 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
75061 (mm->end_data - mm->start_data) > rlim)
75062 goto out;
75063@@ -736,6 +759,12 @@ static int
75064 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
75065 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75066 {
75067+
75068+#ifdef CONFIG_PAX_SEGMEXEC
75069+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
75070+ return 0;
75071+#endif
75072+
75073 if (is_mergeable_vma(vma, file, vm_flags) &&
75074 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75075 if (vma->vm_pgoff == vm_pgoff)
75076@@ -755,6 +784,12 @@ static int
75077 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75078 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
75079 {
75080+
75081+#ifdef CONFIG_PAX_SEGMEXEC
75082+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
75083+ return 0;
75084+#endif
75085+
75086 if (is_mergeable_vma(vma, file, vm_flags) &&
75087 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
75088 pgoff_t vm_pglen;
75089@@ -797,13 +832,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
75090 struct vm_area_struct *vma_merge(struct mm_struct *mm,
75091 struct vm_area_struct *prev, unsigned long addr,
75092 unsigned long end, unsigned long vm_flags,
75093- struct anon_vma *anon_vma, struct file *file,
75094+ struct anon_vma *anon_vma, struct file *file,
75095 pgoff_t pgoff, struct mempolicy *policy)
75096 {
75097 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
75098 struct vm_area_struct *area, *next;
75099 int err;
75100
75101+#ifdef CONFIG_PAX_SEGMEXEC
75102+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
75103+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
75104+
75105+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
75106+#endif
75107+
75108 /*
75109 * We later require that vma->vm_flags == vm_flags,
75110 * so this tests vma->vm_flags & VM_SPECIAL, too.
75111@@ -819,6 +861,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75112 if (next && next->vm_end == end) /* cases 6, 7, 8 */
75113 next = next->vm_next;
75114
75115+#ifdef CONFIG_PAX_SEGMEXEC
75116+ if (prev)
75117+ prev_m = pax_find_mirror_vma(prev);
75118+ if (area)
75119+ area_m = pax_find_mirror_vma(area);
75120+ if (next)
75121+ next_m = pax_find_mirror_vma(next);
75122+#endif
75123+
75124 /*
75125 * Can it merge with the predecessor?
75126 */
75127@@ -838,9 +889,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75128 /* cases 1, 6 */
75129 err = vma_adjust(prev, prev->vm_start,
75130 next->vm_end, prev->vm_pgoff, NULL);
75131- } else /* cases 2, 5, 7 */
75132+
75133+#ifdef CONFIG_PAX_SEGMEXEC
75134+ if (!err && prev_m)
75135+ err = vma_adjust(prev_m, prev_m->vm_start,
75136+ next_m->vm_end, prev_m->vm_pgoff, NULL);
75137+#endif
75138+
75139+ } else { /* cases 2, 5, 7 */
75140 err = vma_adjust(prev, prev->vm_start,
75141 end, prev->vm_pgoff, NULL);
75142+
75143+#ifdef CONFIG_PAX_SEGMEXEC
75144+ if (!err && prev_m)
75145+ err = vma_adjust(prev_m, prev_m->vm_start,
75146+ end_m, prev_m->vm_pgoff, NULL);
75147+#endif
75148+
75149+ }
75150 if (err)
75151 return NULL;
75152 khugepaged_enter_vma_merge(prev);
75153@@ -854,12 +920,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
75154 mpol_equal(policy, vma_policy(next)) &&
75155 can_vma_merge_before(next, vm_flags,
75156 anon_vma, file, pgoff+pglen)) {
75157- if (prev && addr < prev->vm_end) /* case 4 */
75158+ if (prev && addr < prev->vm_end) { /* case 4 */
75159 err = vma_adjust(prev, prev->vm_start,
75160 addr, prev->vm_pgoff, NULL);
75161- else /* cases 3, 8 */
75162+
75163+#ifdef CONFIG_PAX_SEGMEXEC
75164+ if (!err && prev_m)
75165+ err = vma_adjust(prev_m, prev_m->vm_start,
75166+ addr_m, prev_m->vm_pgoff, NULL);
75167+#endif
75168+
75169+ } else { /* cases 3, 8 */
75170 err = vma_adjust(area, addr, next->vm_end,
75171 next->vm_pgoff - pglen, NULL);
75172+
75173+#ifdef CONFIG_PAX_SEGMEXEC
75174+ if (!err && area_m)
75175+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
75176+ next_m->vm_pgoff - pglen, NULL);
75177+#endif
75178+
75179+ }
75180 if (err)
75181 return NULL;
75182 khugepaged_enter_vma_merge(area);
75183@@ -968,16 +1049,13 @@ none:
75184 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
75185 struct file *file, long pages)
75186 {
75187- const unsigned long stack_flags
75188- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
75189-
75190 mm->total_vm += pages;
75191
75192 if (file) {
75193 mm->shared_vm += pages;
75194 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
75195 mm->exec_vm += pages;
75196- } else if (flags & stack_flags)
75197+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
75198 mm->stack_vm += pages;
75199 }
75200 #endif /* CONFIG_PROC_FS */
75201@@ -1013,7 +1091,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75202 * (the exception is when the underlying filesystem is noexec
75203 * mounted, in which case we dont add PROT_EXEC.)
75204 */
75205- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
75206+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
75207 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
75208 prot |= PROT_EXEC;
75209
75210@@ -1039,7 +1117,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75211 /* Obtain the address to map to. we verify (or select) it and ensure
75212 * that it represents a valid section of the address space.
75213 */
75214- addr = get_unmapped_area(file, addr, len, pgoff, flags);
75215+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
75216 if (addr & ~PAGE_MASK)
75217 return addr;
75218
75219@@ -1050,6 +1128,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75220 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
75221 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
75222
75223+#ifdef CONFIG_PAX_MPROTECT
75224+ if (mm->pax_flags & MF_PAX_MPROTECT) {
75225+#ifndef CONFIG_PAX_MPROTECT_COMPAT
75226+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
75227+ gr_log_rwxmmap(file);
75228+
75229+#ifdef CONFIG_PAX_EMUPLT
75230+ vm_flags &= ~VM_EXEC;
75231+#else
75232+ return -EPERM;
75233+#endif
75234+
75235+ }
75236+
75237+ if (!(vm_flags & VM_EXEC))
75238+ vm_flags &= ~VM_MAYEXEC;
75239+#else
75240+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
75241+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
75242+#endif
75243+ else
75244+ vm_flags &= ~VM_MAYWRITE;
75245+ }
75246+#endif
75247+
75248+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75249+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
75250+ vm_flags &= ~VM_PAGEEXEC;
75251+#endif
75252+
75253 if (flags & MAP_LOCKED)
75254 if (!can_do_mlock())
75255 return -EPERM;
75256@@ -1061,6 +1169,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75257 locked += mm->locked_vm;
75258 lock_limit = rlimit(RLIMIT_MEMLOCK);
75259 lock_limit >>= PAGE_SHIFT;
75260+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
75261 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
75262 return -EAGAIN;
75263 }
75264@@ -1127,6 +1236,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75265 }
75266 }
75267
75268+ if (!gr_acl_handle_mmap(file, prot))
75269+ return -EACCES;
75270+
75271 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
75272 }
75273
75274@@ -1203,7 +1315,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
75275 vm_flags_t vm_flags = vma->vm_flags;
75276
75277 /* If it was private or non-writable, the write bit is already clear */
75278- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
75279+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
75280 return 0;
75281
75282 /* The backer wishes to know when pages are first written to? */
75283@@ -1252,13 +1364,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
75284 unsigned long charged = 0;
75285 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
75286
75287+#ifdef CONFIG_PAX_SEGMEXEC
75288+ struct vm_area_struct *vma_m = NULL;
75289+#endif
75290+
75291+ /*
75292+ * mm->mmap_sem is required to protect against another thread
75293+ * changing the mappings in case we sleep.
75294+ */
75295+ verify_mm_writelocked(mm);
75296+
75297 /* Clear old maps */
75298 error = -ENOMEM;
75299-munmap_back:
75300 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
75301 if (do_munmap(mm, addr, len))
75302 return -ENOMEM;
75303- goto munmap_back;
75304+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
75305 }
75306
75307 /* Check against address space limit. */
75308@@ -1307,6 +1428,16 @@ munmap_back:
75309 goto unacct_error;
75310 }
75311
75312+#ifdef CONFIG_PAX_SEGMEXEC
75313+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
75314+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
75315+ if (!vma_m) {
75316+ error = -ENOMEM;
75317+ goto free_vma;
75318+ }
75319+ }
75320+#endif
75321+
75322 vma->vm_mm = mm;
75323 vma->vm_start = addr;
75324 vma->vm_end = addr + len;
75325@@ -1331,6 +1462,13 @@ munmap_back:
75326 if (error)
75327 goto unmap_and_free_vma;
75328
75329+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75330+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
75331+ vma->vm_flags |= VM_PAGEEXEC;
75332+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
75333+ }
75334+#endif
75335+
75336 /* Can addr have changed??
75337 *
75338 * Answer: Yes, several device drivers can do it in their
75339@@ -1365,6 +1503,11 @@ munmap_back:
75340 vma_link(mm, vma, prev, rb_link, rb_parent);
75341 file = vma->vm_file;
75342
75343+#ifdef CONFIG_PAX_SEGMEXEC
75344+ if (vma_m)
75345+ BUG_ON(pax_mirror_vma(vma_m, vma));
75346+#endif
75347+
75348 /* Once vma denies write, undo our temporary denial count */
75349 if (correct_wcount)
75350 atomic_inc(&inode->i_writecount);
75351@@ -1372,6 +1515,7 @@ out:
75352 perf_event_mmap(vma);
75353
75354 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
75355+ track_exec_limit(mm, addr, addr + len, vm_flags);
75356 if (vm_flags & VM_LOCKED) {
75357 if (!mlock_vma_pages_range(vma, addr, addr + len))
75358 mm->locked_vm += (len >> PAGE_SHIFT);
75359@@ -1393,6 +1537,12 @@ unmap_and_free_vma:
75360 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
75361 charged = 0;
75362 free_vma:
75363+
75364+#ifdef CONFIG_PAX_SEGMEXEC
75365+ if (vma_m)
75366+ kmem_cache_free(vm_area_cachep, vma_m);
75367+#endif
75368+
75369 kmem_cache_free(vm_area_cachep, vma);
75370 unacct_error:
75371 if (charged)
75372@@ -1400,6 +1550,62 @@ unacct_error:
75373 return error;
75374 }
75375
75376+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
75377+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
75378+{
75379+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
75380+ return (random32() & 0xFF) << PAGE_SHIFT;
75381+
75382+ return 0;
75383+}
75384+#endif
75385+
75386+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
75387+{
75388+ if (!vma) {
75389+#ifdef CONFIG_STACK_GROWSUP
75390+ if (addr > sysctl_heap_stack_gap)
75391+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
75392+ else
75393+ vma = find_vma(current->mm, 0);
75394+ if (vma && (vma->vm_flags & VM_GROWSUP))
75395+ return false;
75396+#endif
75397+ return true;
75398+ }
75399+
75400+ if (addr + len > vma->vm_start)
75401+ return false;
75402+
75403+ if (vma->vm_flags & VM_GROWSDOWN)
75404+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
75405+#ifdef CONFIG_STACK_GROWSUP
75406+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
75407+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
75408+#endif
75409+ else if (offset)
75410+ return offset <= vma->vm_start - addr - len;
75411+
75412+ return true;
75413+}
75414+
75415+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
75416+{
75417+ if (vma->vm_start < len)
75418+ return -ENOMEM;
75419+
75420+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
75421+ if (offset <= vma->vm_start - len)
75422+ return vma->vm_start - len - offset;
75423+ else
75424+ return -ENOMEM;
75425+ }
75426+
75427+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
75428+ return vma->vm_start - len - sysctl_heap_stack_gap;
75429+ return -ENOMEM;
75430+}
75431+
75432 /* Get an address range which is currently unmapped.
75433 * For shmat() with addr=0.
75434 *
75435@@ -1426,18 +1632,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
75436 if (flags & MAP_FIXED)
75437 return addr;
75438
75439+#ifdef CONFIG_PAX_RANDMMAP
75440+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
75441+#endif
75442+
75443 if (addr) {
75444 addr = PAGE_ALIGN(addr);
75445- vma = find_vma(mm, addr);
75446- if (TASK_SIZE - len >= addr &&
75447- (!vma || addr + len <= vma->vm_start))
75448- return addr;
75449+ if (TASK_SIZE - len >= addr) {
75450+ vma = find_vma(mm, addr);
75451+ if (check_heap_stack_gap(vma, addr, len))
75452+ return addr;
75453+ }
75454 }
75455 if (len > mm->cached_hole_size) {
75456- start_addr = addr = mm->free_area_cache;
75457+ start_addr = addr = mm->free_area_cache;
75458 } else {
75459- start_addr = addr = TASK_UNMAPPED_BASE;
75460- mm->cached_hole_size = 0;
75461+ start_addr = addr = mm->mmap_base;
75462+ mm->cached_hole_size = 0;
75463 }
75464
75465 full_search:
75466@@ -1448,34 +1659,40 @@ full_search:
75467 * Start a new search - just in case we missed
75468 * some holes.
75469 */
75470- if (start_addr != TASK_UNMAPPED_BASE) {
75471- addr = TASK_UNMAPPED_BASE;
75472- start_addr = addr;
75473+ if (start_addr != mm->mmap_base) {
75474+ start_addr = addr = mm->mmap_base;
75475 mm->cached_hole_size = 0;
75476 goto full_search;
75477 }
75478 return -ENOMEM;
75479 }
75480- if (!vma || addr + len <= vma->vm_start) {
75481- /*
75482- * Remember the place where we stopped the search:
75483- */
75484- mm->free_area_cache = addr + len;
75485- return addr;
75486- }
75487+ if (check_heap_stack_gap(vma, addr, len))
75488+ break;
75489 if (addr + mm->cached_hole_size < vma->vm_start)
75490 mm->cached_hole_size = vma->vm_start - addr;
75491 addr = vma->vm_end;
75492 }
75493+
75494+ /*
75495+ * Remember the place where we stopped the search:
75496+ */
75497+ mm->free_area_cache = addr + len;
75498+ return addr;
75499 }
75500 #endif
75501
75502 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
75503 {
75504+
75505+#ifdef CONFIG_PAX_SEGMEXEC
75506+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
75507+ return;
75508+#endif
75509+
75510 /*
75511 * Is this a new hole at the lowest possible address?
75512 */
75513- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
75514+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
75515 mm->free_area_cache = addr;
75516 }
75517
75518@@ -1491,7 +1708,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
75519 {
75520 struct vm_area_struct *vma;
75521 struct mm_struct *mm = current->mm;
75522- unsigned long addr = addr0, start_addr;
75523+ unsigned long base = mm->mmap_base, addr = addr0, start_addr;
75524
75525 /* requested length too big for entire address space */
75526 if (len > TASK_SIZE)
75527@@ -1500,13 +1717,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))
75545+ return addr;
75546+ }
75547 }
75548
75549 /* check if free_area_cache is useful for us */
75550@@ -1530,7 +1752,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))
75556 /* remember the address as a hint for next time */
75557 return (mm->free_area_cache = addr);
75558
75559@@ -1539,8 +1761,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);
75566+ } while (!IS_ERR_VALUE(addr));
75567
75568 fail:
75569 /*
75570@@ -1563,13 +1785,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 +1808,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 +1821,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 +1923,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 +1961,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 +1972,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 +2002,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 +2060,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 +2076,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 +2091,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 +2109,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 +2131,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 +2219,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 +2271,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 +2309,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 +2348,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 +2386,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 +2425,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 +2449,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 +2469,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 +2567,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 +2577,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 +2597,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 +2610,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 +2618,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 +2658,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 +2685,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 +2699,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 +2762,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 +2779,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 +2809,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 +2843,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 +2911,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 +2955,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 +3031,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..93c6810 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_dma;
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 a0d6984..e280e5d 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@@ -3342,6 +3348,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
77540 return kmalloc_dma_caches[index];
77541
77542 #endif
77543+
77544+#ifdef CONFIG_PAX_USERCOPY_SLABS
77545+ if (flags & SLAB_USERCOPY)
77546+ return kmalloc_usercopy_caches[index];
77547+
77548+#endif
77549+
77550 return kmalloc_caches[index];
77551 }
77552
77553@@ -3410,6 +3423,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
77554 EXPORT_SYMBOL(__kmalloc_node);
77555 #endif
77556
77557+bool is_usercopy_object(const void *ptr)
77558+{
77559+ struct page *page;
77560+ struct kmem_cache *s;
77561+
77562+ if (ZERO_OR_NULL_PTR(ptr))
77563+ return false;
77564+
77565+ if (!slab_is_available())
77566+ return false;
77567+
77568+ if (!virt_addr_valid(ptr))
77569+ return false;
77570+
77571+ page = virt_to_head_page(ptr);
77572+
77573+ if (!PageSlab(page))
77574+ return false;
77575+
77576+ s = page->slab;
77577+ return s->flags & SLAB_USERCOPY;
77578+}
77579+
77580+#ifdef CONFIG_PAX_USERCOPY
77581+const char *check_heap_object(const void *ptr, unsigned long n)
77582+{
77583+ struct page *page;
77584+ struct kmem_cache *s;
77585+ unsigned long offset;
77586+
77587+ if (ZERO_OR_NULL_PTR(ptr))
77588+ return "<null>";
77589+
77590+ if (!virt_addr_valid(ptr))
77591+ return NULL;
77592+
77593+ page = virt_to_head_page(ptr);
77594+
77595+ if (!PageSlab(page))
77596+ return NULL;
77597+
77598+ s = page->slab;
77599+ if (!(s->flags & SLAB_USERCOPY))
77600+ return s->name;
77601+
77602+ offset = (ptr - page_address(page)) % s->size;
77603+ if (offset <= s->object_size && n <= s->object_size - offset)
77604+ return NULL;
77605+
77606+ return s->name;
77607+}
77608+#endif
77609+
77610 size_t ksize(const void *object)
77611 {
77612 struct page *page;
77613@@ -3684,7 +3750,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
77614 int node;
77615
77616 list_add(&s->list, &slab_caches);
77617- s->refcount = -1;
77618+ atomic_set(&s->refcount, -1);
77619
77620 for_each_node_state(node, N_NORMAL_MEMORY) {
77621 struct kmem_cache_node *n = get_node(s, node);
77622@@ -3807,17 +3873,17 @@ void __init kmem_cache_init(void)
77623
77624 /* Caches that are not of the two-to-the-power-of size */
77625 if (KMALLOC_MIN_SIZE <= 32) {
77626- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
77627+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
77628 caches++;
77629 }
77630
77631 if (KMALLOC_MIN_SIZE <= 64) {
77632- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
77633+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
77634 caches++;
77635 }
77636
77637 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
77638- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
77639+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
77640 caches++;
77641 }
77642
77643@@ -3859,6 +3925,22 @@ void __init kmem_cache_init(void)
77644 }
77645 }
77646 #endif
77647+
77648+#ifdef CONFIG_PAX_USERCOPY_SLABS
77649+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
77650+ struct kmem_cache *s = kmalloc_caches[i];
77651+
77652+ if (s && s->size) {
77653+ char *name = kasprintf(GFP_NOWAIT,
77654+ "usercopy-kmalloc-%d", s->object_size);
77655+
77656+ BUG_ON(!name);
77657+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
77658+ s->object_size, SLAB_USERCOPY);
77659+ }
77660+ }
77661+#endif
77662+
77663 printk(KERN_INFO
77664 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
77665 " CPUs=%d, Nodes=%d\n",
77666@@ -3885,7 +3967,7 @@ static int slab_unmergeable(struct kmem_cache *s)
77667 /*
77668 * We may have set a slab to be unmergeable during bootstrap.
77669 */
77670- if (s->refcount < 0)
77671+ if (atomic_read(&s->refcount) < 0)
77672 return 1;
77673
77674 return 0;
77675@@ -3939,7 +4021,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77676
77677 s = find_mergeable(size, align, flags, name, ctor);
77678 if (s) {
77679- s->refcount++;
77680+ atomic_inc(&s->refcount);
77681 /*
77682 * Adjust the object sizes so that we clear
77683 * the complete object on kzalloc.
77684@@ -3948,7 +4030,7 @@ struct kmem_cache *__kmem_cache_alias(const char *name, size_t size,
77685 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
77686
77687 if (sysfs_slab_alias(s, name)) {
77688- s->refcount--;
77689+ atomic_dec(&s->refcount);
77690 s = NULL;
77691 }
77692 }
77693@@ -4063,7 +4145,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
77694 }
77695 #endif
77696
77697-#ifdef CONFIG_SYSFS
77698+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77699 static int count_inuse(struct page *page)
77700 {
77701 return page->inuse;
77702@@ -4450,12 +4532,12 @@ static void resiliency_test(void)
77703 validate_slab_cache(kmalloc_caches[9]);
77704 }
77705 #else
77706-#ifdef CONFIG_SYSFS
77707+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77708 static void resiliency_test(void) {};
77709 #endif
77710 #endif
77711
77712-#ifdef CONFIG_SYSFS
77713+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77714 enum slab_stat_type {
77715 SL_ALL, /* All slabs */
77716 SL_PARTIAL, /* Only partially allocated slabs */
77717@@ -4699,7 +4781,7 @@ SLAB_ATTR_RO(ctor);
77718
77719 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
77720 {
77721- return sprintf(buf, "%d\n", s->refcount - 1);
77722+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
77723 }
77724 SLAB_ATTR_RO(aliases);
77725
77726@@ -5261,6 +5343,7 @@ static char *create_unique_id(struct kmem_cache *s)
77727 return name;
77728 }
77729
77730+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77731 static int sysfs_slab_add(struct kmem_cache *s)
77732 {
77733 int err;
77734@@ -5323,6 +5406,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
77735 kobject_del(&s->kobj);
77736 kobject_put(&s->kobj);
77737 }
77738+#endif
77739
77740 /*
77741 * Need to buffer aliases during bootup until sysfs becomes
77742@@ -5336,6 +5420,7 @@ struct saved_alias {
77743
77744 static struct saved_alias *alias_list;
77745
77746+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
77747 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77748 {
77749 struct saved_alias *al;
77750@@ -5358,6 +5443,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
77751 alias_list = al;
77752 return 0;
77753 }
77754+#endif
77755
77756 static int __init slab_sysfs_init(void)
77757 {
77758diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
77759index 1b7e22a..3fcd4f3 100644
77760--- a/mm/sparse-vmemmap.c
77761+++ b/mm/sparse-vmemmap.c
77762@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
77763 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77764 if (!p)
77765 return NULL;
77766- pud_populate(&init_mm, pud, p);
77767+ pud_populate_kernel(&init_mm, pud, p);
77768 }
77769 return pud;
77770 }
77771@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
77772 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
77773 if (!p)
77774 return NULL;
77775- pgd_populate(&init_mm, pgd, p);
77776+ pgd_populate_kernel(&init_mm, pgd, p);
77777 }
77778 return pgd;
77779 }
77780diff --git a/mm/swap.c b/mm/swap.c
77781index 6310dc2..3662b3f 100644
77782--- a/mm/swap.c
77783+++ b/mm/swap.c
77784@@ -30,6 +30,7 @@
77785 #include <linux/backing-dev.h>
77786 #include <linux/memcontrol.h>
77787 #include <linux/gfp.h>
77788+#include <linux/hugetlb.h>
77789
77790 #include "internal.h"
77791
77792@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
77793
77794 __page_cache_release(page);
77795 dtor = get_compound_page_dtor(page);
77796+ if (!PageHuge(page))
77797+ BUG_ON(dtor != free_compound_page);
77798 (*dtor)(page);
77799 }
77800
77801diff --git a/mm/swapfile.c b/mm/swapfile.c
77802index f91a255..9dcac21 100644
77803--- a/mm/swapfile.c
77804+++ b/mm/swapfile.c
77805@@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
77806
77807 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
77808 /* Activity counter to indicate that a swapon or swapoff has occurred */
77809-static atomic_t proc_poll_event = ATOMIC_INIT(0);
77810+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
77811
77812 static inline unsigned char swap_count(unsigned char ent)
77813 {
77814@@ -1601,7 +1601,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
77815 }
77816 filp_close(swap_file, NULL);
77817 err = 0;
77818- atomic_inc(&proc_poll_event);
77819+ atomic_inc_unchecked(&proc_poll_event);
77820 wake_up_interruptible(&proc_poll_wait);
77821
77822 out_dput:
77823@@ -1618,8 +1618,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
77824
77825 poll_wait(file, &proc_poll_wait, wait);
77826
77827- if (seq->poll_event != atomic_read(&proc_poll_event)) {
77828- seq->poll_event = atomic_read(&proc_poll_event);
77829+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
77830+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77831 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
77832 }
77833
77834@@ -1717,7 +1717,7 @@ static int swaps_open(struct inode *inode, struct file *file)
77835 return ret;
77836
77837 seq = file->private_data;
77838- seq->poll_event = atomic_read(&proc_poll_event);
77839+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
77840 return 0;
77841 }
77842
77843@@ -2059,7 +2059,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
77844 (frontswap_map) ? "FS" : "");
77845
77846 mutex_unlock(&swapon_mutex);
77847- atomic_inc(&proc_poll_event);
77848+ atomic_inc_unchecked(&proc_poll_event);
77849 wake_up_interruptible(&proc_poll_wait);
77850
77851 if (S_ISREG(inode->i_mode))
77852diff --git a/mm/util.c b/mm/util.c
77853index dc3036c..b6c7c9d 100644
77854--- a/mm/util.c
77855+++ b/mm/util.c
77856@@ -292,6 +292,12 @@ done:
77857 void arch_pick_mmap_layout(struct mm_struct *mm)
77858 {
77859 mm->mmap_base = TASK_UNMAPPED_BASE;
77860+
77861+#ifdef CONFIG_PAX_RANDMMAP
77862+ if (mm->pax_flags & MF_PAX_RANDMMAP)
77863+ mm->mmap_base += mm->delta_mmap;
77864+#endif
77865+
77866 mm->get_unmapped_area = arch_get_unmapped_area;
77867 mm->unmap_area = arch_unmap_area;
77868 }
77869diff --git a/mm/vmalloc.c b/mm/vmalloc.c
77870index 78e0830..bc6bbd8 100644
77871--- a/mm/vmalloc.c
77872+++ b/mm/vmalloc.c
77873@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
77874
77875 pte = pte_offset_kernel(pmd, addr);
77876 do {
77877- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77878- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77879+
77880+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77881+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
77882+ BUG_ON(!pte_exec(*pte));
77883+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
77884+ continue;
77885+ }
77886+#endif
77887+
77888+ {
77889+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
77890+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
77891+ }
77892 } while (pte++, addr += PAGE_SIZE, addr != end);
77893 }
77894
77895@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
77896 pte = pte_alloc_kernel(pmd, addr);
77897 if (!pte)
77898 return -ENOMEM;
77899+
77900+ pax_open_kernel();
77901 do {
77902 struct page *page = pages[*nr];
77903
77904- if (WARN_ON(!pte_none(*pte)))
77905+#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77906+ if (pgprot_val(prot) & _PAGE_NX)
77907+#endif
77908+
77909+ if (!pte_none(*pte)) {
77910+ pax_close_kernel();
77911+ WARN_ON(1);
77912 return -EBUSY;
77913- if (WARN_ON(!page))
77914+ }
77915+ if (!page) {
77916+ pax_close_kernel();
77917+ WARN_ON(1);
77918 return -ENOMEM;
77919+ }
77920 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
77921 (*nr)++;
77922 } while (pte++, addr += PAGE_SIZE, addr != end);
77923+ pax_close_kernel();
77924 return 0;
77925 }
77926
77927@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
77928 pmd_t *pmd;
77929 unsigned long next;
77930
77931- pmd = pmd_alloc(&init_mm, pud, addr);
77932+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
77933 if (!pmd)
77934 return -ENOMEM;
77935 do {
77936@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
77937 pud_t *pud;
77938 unsigned long next;
77939
77940- pud = pud_alloc(&init_mm, pgd, addr);
77941+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
77942 if (!pud)
77943 return -ENOMEM;
77944 do {
77945@@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
77946 * and fall back on vmalloc() if that fails. Others
77947 * just put it in the vmalloc space.
77948 */
77949-#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
77950+#ifdef CONFIG_MODULES
77951+#ifdef MODULES_VADDR
77952 unsigned long addr = (unsigned long)x;
77953 if (addr >= MODULES_VADDR && addr < MODULES_END)
77954 return 1;
77955 #endif
77956+
77957+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
77958+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
77959+ return 1;
77960+#endif
77961+
77962+#endif
77963+
77964 return is_vmalloc_addr(x);
77965 }
77966
77967@@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
77968
77969 if (!pgd_none(*pgd)) {
77970 pud_t *pud = pud_offset(pgd, addr);
77971+#ifdef CONFIG_X86
77972+ if (!pud_large(*pud))
77973+#endif
77974 if (!pud_none(*pud)) {
77975 pmd_t *pmd = pmd_offset(pud, addr);
77976+#ifdef CONFIG_X86
77977+ if (!pmd_large(*pmd))
77978+#endif
77979 if (!pmd_none(*pmd)) {
77980 pte_t *ptep, pte;
77981
77982@@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
77983 * Allocate a region of KVA of the specified size and alignment, within the
77984 * vstart and vend.
77985 */
77986-static struct vmap_area *alloc_vmap_area(unsigned long size,
77987+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
77988 unsigned long align,
77989 unsigned long vstart, unsigned long vend,
77990 int node, gfp_t gfp_mask)
77991@@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
77992 struct vm_struct *area;
77993
77994 BUG_ON(in_interrupt());
77995+
77996+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77997+ if (flags & VM_KERNEXEC) {
77998+ if (start != VMALLOC_START || end != VMALLOC_END)
77999+ return NULL;
78000+ start = (unsigned long)MODULES_EXEC_VADDR;
78001+ end = (unsigned long)MODULES_EXEC_END;
78002+ }
78003+#endif
78004+
78005 if (flags & VM_IOREMAP) {
78006 int bit = fls(size);
78007
78008@@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
78009 if (count > totalram_pages)
78010 return NULL;
78011
78012+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78013+ if (!(pgprot_val(prot) & _PAGE_NX))
78014+ flags |= VM_KERNEXEC;
78015+#endif
78016+
78017 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
78018 __builtin_return_address(0));
78019 if (!area)
78020@@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
78021 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
78022 goto fail;
78023
78024+#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
78025+ if (!(pgprot_val(prot) & _PAGE_NX))
78026+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
78027+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
78028+ else
78029+#endif
78030+
78031 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
78032 start, end, node, gfp_mask, caller);
78033 if (!area)
78034@@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
78035 * For tight control over page level allocator and protection flags
78036 * use __vmalloc() instead.
78037 */
78038-
78039 void *vmalloc_exec(unsigned long size)
78040 {
78041- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
78042+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
78043 -1, __builtin_return_address(0));
78044 }
78045
78046@@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
78047 unsigned long uaddr = vma->vm_start;
78048 unsigned long usize = vma->vm_end - vma->vm_start;
78049
78050+ BUG_ON(vma->vm_mirror);
78051+
78052 if ((PAGE_SIZE-1) & (unsigned long)addr)
78053 return -EINVAL;
78054
78055@@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
78056 v->addr, v->addr + v->size, v->size);
78057
78058 if (v->caller)
78059+#ifdef CONFIG_GRKERNSEC_HIDESYM
78060+ seq_printf(m, " %pK", v->caller);
78061+#else
78062 seq_printf(m, " %pS", v->caller);
78063+#endif
78064
78065 if (v->nr_pages)
78066 seq_printf(m, " pages=%d", v->nr_pages);
78067diff --git a/mm/vmstat.c b/mm/vmstat.c
78068index c737057..a49753a 100644
78069--- a/mm/vmstat.c
78070+++ b/mm/vmstat.c
78071@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
78072 *
78073 * vm_stat contains the global counters
78074 */
78075-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78076+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
78077 EXPORT_SYMBOL(vm_stat);
78078
78079 #ifdef CONFIG_SMP
78080@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
78081 v = p->vm_stat_diff[i];
78082 p->vm_stat_diff[i] = 0;
78083 local_irq_restore(flags);
78084- atomic_long_add(v, &zone->vm_stat[i]);
78085+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78086 global_diff[i] += v;
78087 #ifdef CONFIG_NUMA
78088 /* 3 seconds idle till flush */
78089@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
78090
78091 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
78092 if (global_diff[i])
78093- atomic_long_add(global_diff[i], &vm_stat[i]);
78094+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
78095 }
78096
78097 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78098@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
78099 if (pset->vm_stat_diff[i]) {
78100 int v = pset->vm_stat_diff[i];
78101 pset->vm_stat_diff[i] = 0;
78102- atomic_long_add(v, &zone->vm_stat[i]);
78103- atomic_long_add(v, &vm_stat[i]);
78104+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
78105+ atomic_long_add_unchecked(v, &vm_stat[i]);
78106 }
78107 }
78108 #endif
78109@@ -1224,10 +1224,20 @@ static int __init setup_vmstat(void)
78110 start_cpu_timer(cpu);
78111 #endif
78112 #ifdef CONFIG_PROC_FS
78113- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
78114- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
78115- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
78116- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
78117+ {
78118+ mode_t gr_mode = S_IRUGO;
78119+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78120+ gr_mode = S_IRUSR;
78121+#endif
78122+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
78123+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
78124+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78125+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
78126+#else
78127+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
78128+#endif
78129+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
78130+ }
78131 #endif
78132 return 0;
78133 }
78134diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
78135index ee07072..593e3fd 100644
78136--- a/net/8021q/vlan.c
78137+++ b/net/8021q/vlan.c
78138@@ -484,7 +484,7 @@ out:
78139 return NOTIFY_DONE;
78140 }
78141
78142-static struct notifier_block vlan_notifier_block __read_mostly = {
78143+static struct notifier_block vlan_notifier_block = {
78144 .notifier_call = vlan_device_event,
78145 };
78146
78147@@ -559,8 +559,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
78148 err = -EPERM;
78149 if (!capable(CAP_NET_ADMIN))
78150 break;
78151- if ((args.u.name_type >= 0) &&
78152- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
78153+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
78154 struct vlan_net *vn;
78155
78156 vn = net_generic(net, vlan_net_id);
78157diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
78158index 02efb25..41541a9 100644
78159--- a/net/9p/trans_fd.c
78160+++ b/net/9p/trans_fd.c
78161@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
78162 oldfs = get_fs();
78163 set_fs(get_ds());
78164 /* The cast to a user pointer is valid due to the set_fs() */
78165- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
78166+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
78167 set_fs(oldfs);
78168
78169 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
78170diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
78171index 876fbe8..8bbea9f 100644
78172--- a/net/atm/atm_misc.c
78173+++ b/net/atm/atm_misc.c
78174@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
78175 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
78176 return 1;
78177 atm_return(vcc, truesize);
78178- atomic_inc(&vcc->stats->rx_drop);
78179+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78180 return 0;
78181 }
78182 EXPORT_SYMBOL(atm_charge);
78183@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
78184 }
78185 }
78186 atm_return(vcc, guess);
78187- atomic_inc(&vcc->stats->rx_drop);
78188+ atomic_inc_unchecked(&vcc->stats->rx_drop);
78189 return NULL;
78190 }
78191 EXPORT_SYMBOL(atm_alloc_charge);
78192@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
78193
78194 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78195 {
78196-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78197+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78198 __SONET_ITEMS
78199 #undef __HANDLE_ITEM
78200 }
78201@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
78202
78203 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
78204 {
78205-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78206+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
78207 __SONET_ITEMS
78208 #undef __HANDLE_ITEM
78209 }
78210diff --git a/net/atm/lec.h b/net/atm/lec.h
78211index a86aff9..3a0d6f6 100644
78212--- a/net/atm/lec.h
78213+++ b/net/atm/lec.h
78214@@ -48,7 +48,7 @@ struct lane2_ops {
78215 const u8 *tlvs, u32 sizeoftlvs);
78216 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
78217 const u8 *tlvs, u32 sizeoftlvs);
78218-};
78219+} __no_const;
78220
78221 /*
78222 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
78223diff --git a/net/atm/proc.c b/net/atm/proc.c
78224index 0d020de..011c7bb 100644
78225--- a/net/atm/proc.c
78226+++ b/net/atm/proc.c
78227@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
78228 const struct k_atm_aal_stats *stats)
78229 {
78230 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
78231- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
78232- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
78233- atomic_read(&stats->rx_drop));
78234+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
78235+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
78236+ atomic_read_unchecked(&stats->rx_drop));
78237 }
78238
78239 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
78240diff --git a/net/atm/resources.c b/net/atm/resources.c
78241index 0447d5d..3cf4728 100644
78242--- a/net/atm/resources.c
78243+++ b/net/atm/resources.c
78244@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
78245 static void copy_aal_stats(struct k_atm_aal_stats *from,
78246 struct atm_aal_stats *to)
78247 {
78248-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
78249+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
78250 __AAL_STAT_ITEMS
78251 #undef __HANDLE_ITEM
78252 }
78253@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
78254 static void subtract_aal_stats(struct k_atm_aal_stats *from,
78255 struct atm_aal_stats *to)
78256 {
78257-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
78258+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
78259 __AAL_STAT_ITEMS
78260 #undef __HANDLE_ITEM
78261 }
78262diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
78263index c6fcc76..1270d14 100644
78264--- a/net/batman-adv/bat_iv_ogm.c
78265+++ b/net/batman-adv/bat_iv_ogm.c
78266@@ -62,7 +62,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
78267
78268 /* randomize initial seqno to avoid collision */
78269 get_random_bytes(&random_seqno, sizeof(random_seqno));
78270- atomic_set(&hard_iface->seqno, random_seqno);
78271+ atomic_set_unchecked(&hard_iface->seqno, random_seqno);
78272
78273 hard_iface->packet_len = BATADV_OGM_HLEN;
78274 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
78275@@ -608,9 +608,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
78276 batadv_ogm_packet = (struct batadv_ogm_packet *)hard_iface->packet_buff;
78277
78278 /* change sequence number to network order */
78279- seqno = (uint32_t)atomic_read(&hard_iface->seqno);
78280+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->seqno);
78281 batadv_ogm_packet->seqno = htonl(seqno);
78282- atomic_inc(&hard_iface->seqno);
78283+ atomic_inc_unchecked(&hard_iface->seqno);
78284
78285 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
78286 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
78287@@ -1015,7 +1015,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
78288 return;
78289
78290 /* could be changed by schedule_own_packet() */
78291- if_incoming_seqno = atomic_read(&if_incoming->seqno);
78292+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
78293
78294 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
78295 has_directlink_flag = 1;
78296diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
78297index d112fd6..686a447 100644
78298--- a/net/batman-adv/hard-interface.c
78299+++ b/net/batman-adv/hard-interface.c
78300@@ -327,7 +327,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
78301 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
78302 dev_add_pack(&hard_iface->batman_adv_ptype);
78303
78304- atomic_set(&hard_iface->frag_seqno, 1);
78305+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
78306 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
78307 hard_iface->net_dev->name);
78308
78309@@ -450,7 +450,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
78310 /* This can't be called via a bat_priv callback because
78311 * we have no bat_priv yet.
78312 */
78313- atomic_set(&hard_iface->seqno, 1);
78314+ atomic_set_unchecked(&hard_iface->seqno, 1);
78315 hard_iface->packet_buff = NULL;
78316
78317 return hard_iface;
78318diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
78319index ce0684a..4a0cbf1 100644
78320--- a/net/batman-adv/soft-interface.c
78321+++ b/net/batman-adv/soft-interface.c
78322@@ -234,7 +234,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
78323 primary_if->net_dev->dev_addr, ETH_ALEN);
78324
78325 /* set broadcast sequence number */
78326- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
78327+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
78328 bcast_packet->seqno = htonl(seqno);
78329
78330 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
78331@@ -427,7 +427,7 @@ struct net_device *batadv_softif_create(const char *name)
78332 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
78333
78334 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
78335- atomic_set(&bat_priv->bcast_seqno, 1);
78336+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
78337 atomic_set(&bat_priv->tt.vn, 0);
78338 atomic_set(&bat_priv->tt.local_changes, 0);
78339 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
78340diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
78341index ac1e07a..4c846e2 100644
78342--- a/net/batman-adv/types.h
78343+++ b/net/batman-adv/types.h
78344@@ -33,8 +33,8 @@ struct batadv_hard_iface {
78345 int16_t if_num;
78346 char if_status;
78347 struct net_device *net_dev;
78348- atomic_t seqno;
78349- atomic_t frag_seqno;
78350+ atomic_unchecked_t seqno;
78351+ atomic_unchecked_t frag_seqno;
78352 unsigned char *packet_buff;
78353 int packet_len;
78354 struct kobject *hardif_obj;
78355@@ -244,7 +244,7 @@ struct batadv_priv {
78356 atomic_t orig_interval; /* uint */
78357 atomic_t hop_penalty; /* uint */
78358 atomic_t log_level; /* uint */
78359- atomic_t bcast_seqno;
78360+ atomic_unchecked_t bcast_seqno;
78361 atomic_t bcast_queue_left;
78362 atomic_t batman_queue_left;
78363 char num_ifaces;
78364diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
78365index f397232..3206a33 100644
78366--- a/net/batman-adv/unicast.c
78367+++ b/net/batman-adv/unicast.c
78368@@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
78369 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
78370 frag2->flags = large_tail;
78371
78372- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
78373+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
78374 frag1->seqno = htons(seqno - 1);
78375 frag2->seqno = htons(seqno);
78376
78377diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
78378index 07f0739..3c42e34 100644
78379--- a/net/bluetooth/hci_sock.c
78380+++ b/net/bluetooth/hci_sock.c
78381@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
78382 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
78383 }
78384
78385- len = min_t(unsigned int, len, sizeof(uf));
78386+ len = min((size_t)len, sizeof(uf));
78387 if (copy_from_user(&uf, optval, len)) {
78388 err = -EFAULT;
78389 break;
78390diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
78391index a91239d..d7ed533 100644
78392--- a/net/bluetooth/l2cap_core.c
78393+++ b/net/bluetooth/l2cap_core.c
78394@@ -3183,8 +3183,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
78395 break;
78396
78397 case L2CAP_CONF_RFC:
78398- if (olen == sizeof(rfc))
78399- memcpy(&rfc, (void *)val, olen);
78400+ if (olen != sizeof(rfc))
78401+ break;
78402+
78403+ memcpy(&rfc, (void *)val, olen);
78404
78405 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
78406 rfc.mode != chan->mode)
78407diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
78408index 083f2bf..799f9448 100644
78409--- a/net/bluetooth/l2cap_sock.c
78410+++ b/net/bluetooth/l2cap_sock.c
78411@@ -471,7 +471,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78412 struct sock *sk = sock->sk;
78413 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
78414 struct l2cap_options opts;
78415- int len, err = 0;
78416+ int err = 0;
78417+ size_t len = optlen;
78418 u32 opt;
78419
78420 BT_DBG("sk %p", sk);
78421@@ -493,7 +494,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
78422 opts.max_tx = chan->max_tx;
78423 opts.txwin_size = chan->tx_win;
78424
78425- len = min_t(unsigned int, sizeof(opts), optlen);
78426+ len = min(sizeof(opts), len);
78427 if (copy_from_user((char *) &opts, optval, len)) {
78428 err = -EFAULT;
78429 break;
78430@@ -571,7 +572,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78431 struct bt_security sec;
78432 struct bt_power pwr;
78433 struct l2cap_conn *conn;
78434- int len, err = 0;
78435+ int err = 0;
78436+ size_t len = optlen;
78437 u32 opt;
78438
78439 BT_DBG("sk %p", sk);
78440@@ -594,7 +596,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78441
78442 sec.level = BT_SECURITY_LOW;
78443
78444- len = min_t(unsigned int, sizeof(sec), optlen);
78445+ len = min(sizeof(sec), len);
78446 if (copy_from_user((char *) &sec, optval, len)) {
78447 err = -EFAULT;
78448 break;
78449@@ -691,7 +693,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
78450
78451 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
78452
78453- len = min_t(unsigned int, sizeof(pwr), optlen);
78454+ len = min(sizeof(pwr), len);
78455 if (copy_from_user((char *) &pwr, optval, len)) {
78456 err = -EFAULT;
78457 break;
78458diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
78459index 868a909..d044bc3 100644
78460--- a/net/bluetooth/rfcomm/sock.c
78461+++ b/net/bluetooth/rfcomm/sock.c
78462@@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78463 struct sock *sk = sock->sk;
78464 struct bt_security sec;
78465 int err = 0;
78466- size_t len;
78467+ size_t len = optlen;
78468 u32 opt;
78469
78470 BT_DBG("sk %p", sk);
78471@@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
78472
78473 sec.level = BT_SECURITY_LOW;
78474
78475- len = min_t(unsigned int, sizeof(sec), optlen);
78476+ len = min(sizeof(sec), len);
78477 if (copy_from_user((char *) &sec, optval, len)) {
78478 err = -EFAULT;
78479 break;
78480diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
78481index ccc2487..921073d 100644
78482--- a/net/bluetooth/rfcomm/tty.c
78483+++ b/net/bluetooth/rfcomm/tty.c
78484@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
78485 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
78486
78487 spin_lock_irqsave(&dev->port.lock, flags);
78488- if (dev->port.count > 0) {
78489+ if (atomic_read(&dev->port.count) > 0) {
78490 spin_unlock_irqrestore(&dev->port.lock, flags);
78491 return;
78492 }
78493@@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
78494 return -ENODEV;
78495
78496 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
78497- dev->channel, dev->port.count);
78498+ dev->channel, atomic_read(&dev->port.count));
78499
78500 spin_lock_irqsave(&dev->port.lock, flags);
78501- if (++dev->port.count > 1) {
78502+ if (atomic_inc_return(&dev->port.count) > 1) {
78503 spin_unlock_irqrestore(&dev->port.lock, flags);
78504 return 0;
78505 }
78506@@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
78507 return;
78508
78509 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
78510- dev->port.count);
78511+ atomic_read(&dev->port.count));
78512
78513 spin_lock_irqsave(&dev->port.lock, flags);
78514- if (!--dev->port.count) {
78515+ if (!atomic_dec_return(&dev->port.count)) {
78516 spin_unlock_irqrestore(&dev->port.lock, flags);
78517 if (dev->tty_dev->parent)
78518 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
78519diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
78520index 5fe2ff3..121d696 100644
78521--- a/net/bridge/netfilter/ebtables.c
78522+++ b/net/bridge/netfilter/ebtables.c
78523@@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
78524 tmp.valid_hooks = t->table->valid_hooks;
78525 }
78526 mutex_unlock(&ebt_mutex);
78527- if (copy_to_user(user, &tmp, *len) != 0){
78528+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
78529 BUGPRINT("c2u Didn't work\n");
78530 ret = -EFAULT;
78531 break;
78532@@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78533 goto out;
78534 tmp.valid_hooks = t->valid_hooks;
78535
78536- if (copy_to_user(user, &tmp, *len) != 0) {
78537+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
78538 ret = -EFAULT;
78539 break;
78540 }
78541@@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
78542 tmp.entries_size = t->table->entries_size;
78543 tmp.valid_hooks = t->table->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 }
78550diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
78551index 44f270f..1f5602d 100644
78552--- a/net/caif/cfctrl.c
78553+++ b/net/caif/cfctrl.c
78554@@ -10,6 +10,7 @@
78555 #include <linux/spinlock.h>
78556 #include <linux/slab.h>
78557 #include <linux/pkt_sched.h>
78558+#include <linux/sched.h>
78559 #include <net/caif/caif_layer.h>
78560 #include <net/caif/cfpkt.h>
78561 #include <net/caif/cfctrl.h>
78562@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
78563 memset(&dev_info, 0, sizeof(dev_info));
78564 dev_info.id = 0xff;
78565 cfsrvl_init(&this->serv, 0, &dev_info, false);
78566- atomic_set(&this->req_seq_no, 1);
78567- atomic_set(&this->rsp_seq_no, 1);
78568+ atomic_set_unchecked(&this->req_seq_no, 1);
78569+ atomic_set_unchecked(&this->rsp_seq_no, 1);
78570 this->serv.layer.receive = cfctrl_recv;
78571 sprintf(this->serv.layer.name, "ctrl");
78572 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
78573@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
78574 struct cfctrl_request_info *req)
78575 {
78576 spin_lock_bh(&ctrl->info_list_lock);
78577- atomic_inc(&ctrl->req_seq_no);
78578- req->sequence_no = atomic_read(&ctrl->req_seq_no);
78579+ atomic_inc_unchecked(&ctrl->req_seq_no);
78580+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
78581 list_add_tail(&req->list, &ctrl->list);
78582 spin_unlock_bh(&ctrl->info_list_lock);
78583 }
78584@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
78585 if (p != first)
78586 pr_warn("Requests are not received in order\n");
78587
78588- atomic_set(&ctrl->rsp_seq_no,
78589+ atomic_set_unchecked(&ctrl->rsp_seq_no,
78590 p->sequence_no);
78591 list_del(&p->list);
78592 goto out;
78593diff --git a/net/can/af_can.c b/net/can/af_can.c
78594index ddac1ee..3ee0a78 100644
78595--- a/net/can/af_can.c
78596+++ b/net/can/af_can.c
78597@@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
78598 };
78599
78600 /* notifier block for netdevice event */
78601-static struct notifier_block can_netdev_notifier __read_mostly = {
78602+static struct notifier_block can_netdev_notifier = {
78603 .notifier_call = can_notifier,
78604 };
78605
78606diff --git a/net/can/gw.c b/net/can/gw.c
78607index 1f5c978..ef714c7 100644
78608--- a/net/can/gw.c
78609+++ b/net/can/gw.c
78610@@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
78611 MODULE_ALIAS("can-gw");
78612
78613 static HLIST_HEAD(cgw_list);
78614-static struct notifier_block notifier;
78615
78616 static struct kmem_cache *cgw_cache __read_mostly;
78617
78618@@ -887,6 +886,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
78619 return err;
78620 }
78621
78622+static struct notifier_block notifier = {
78623+ .notifier_call = cgw_notifier
78624+};
78625+
78626 static __init int cgw_module_init(void)
78627 {
78628 printk(banner);
78629@@ -898,7 +901,6 @@ static __init int cgw_module_init(void)
78630 return -ENOMEM;
78631
78632 /* set notifier */
78633- notifier.notifier_call = cgw_notifier;
78634 register_netdevice_notifier(&notifier);
78635
78636 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
78637diff --git a/net/compat.c b/net/compat.c
78638index 79ae884..17c5c09 100644
78639--- a/net/compat.c
78640+++ b/net/compat.c
78641@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
78642 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
78643 __get_user(kmsg->msg_flags, &umsg->msg_flags))
78644 return -EFAULT;
78645- kmsg->msg_name = compat_ptr(tmp1);
78646- kmsg->msg_iov = compat_ptr(tmp2);
78647- kmsg->msg_control = compat_ptr(tmp3);
78648+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
78649+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
78650+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
78651 return 0;
78652 }
78653
78654@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78655
78656 if (kern_msg->msg_namelen) {
78657 if (mode == VERIFY_READ) {
78658- int err = move_addr_to_kernel(kern_msg->msg_name,
78659+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
78660 kern_msg->msg_namelen,
78661 kern_address);
78662 if (err < 0)
78663@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78664 kern_msg->msg_name = NULL;
78665
78666 tot_len = iov_from_user_compat_to_kern(kern_iov,
78667- (struct compat_iovec __user *)kern_msg->msg_iov,
78668+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
78669 kern_msg->msg_iovlen);
78670 if (tot_len >= 0)
78671 kern_msg->msg_iov = kern_iov;
78672@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
78673
78674 #define CMSG_COMPAT_FIRSTHDR(msg) \
78675 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
78676- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
78677+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
78678 (struct compat_cmsghdr __user *)NULL)
78679
78680 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
78681 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
78682 (ucmlen) <= (unsigned long) \
78683 ((mhdr)->msg_controllen - \
78684- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
78685+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
78686
78687 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
78688 struct compat_cmsghdr __user *cmsg, int cmsg_len)
78689 {
78690 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
78691- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
78692+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
78693 msg->msg_controllen)
78694 return NULL;
78695 return (struct compat_cmsghdr __user *)ptr;
78696@@ -219,7 +219,7 @@ Efault:
78697
78698 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
78699 {
78700- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
78701+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
78702 struct compat_cmsghdr cmhdr;
78703 struct compat_timeval ctv;
78704 struct compat_timespec cts[3];
78705@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
78706
78707 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
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 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
78712 int fdnum = scm->fp->count;
78713 struct file **fp = scm->fp->fp;
78714@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
78715 return -EFAULT;
78716 old_fs = get_fs();
78717 set_fs(KERNEL_DS);
78718- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
78719+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
78720 set_fs(old_fs);
78721
78722 return err;
78723@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
78724 len = sizeof(ktime);
78725 old_fs = get_fs();
78726 set_fs(KERNEL_DS);
78727- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
78728+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
78729 set_fs(old_fs);
78730
78731 if (!err) {
78732@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78733 case MCAST_JOIN_GROUP:
78734 case MCAST_LEAVE_GROUP:
78735 {
78736- struct compat_group_req __user *gr32 = (void *)optval;
78737+ struct compat_group_req __user *gr32 = (void __user *)optval;
78738 struct group_req __user *kgr =
78739 compat_alloc_user_space(sizeof(struct group_req));
78740 u32 interface;
78741@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78742 case MCAST_BLOCK_SOURCE:
78743 case MCAST_UNBLOCK_SOURCE:
78744 {
78745- struct compat_group_source_req __user *gsr32 = (void *)optval;
78746+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
78747 struct group_source_req __user *kgsr = compat_alloc_user_space(
78748 sizeof(struct group_source_req));
78749 u32 interface;
78750@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
78751 }
78752 case MCAST_MSFILTER:
78753 {
78754- struct compat_group_filter __user *gf32 = (void *)optval;
78755+ struct compat_group_filter __user *gf32 = (void __user *)optval;
78756 struct group_filter __user *kgf;
78757 u32 interface, fmode, numsrc;
78758
78759@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
78760 char __user *optval, int __user *optlen,
78761 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
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 int __user *koptlen;
78767 u32 interface, fmode, numsrc;
78768@@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
78769
78770 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
78771 return -EINVAL;
78772- if (copy_from_user(a, args, nas[call]))
78773+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
78774 return -EFAULT;
78775 a0 = a[0];
78776 a1 = a[1];
78777diff --git a/net/core/datagram.c b/net/core/datagram.c
78778index 0337e2b..47914a0 100644
78779--- a/net/core/datagram.c
78780+++ b/net/core/datagram.c
78781@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
78782 }
78783
78784 kfree_skb(skb);
78785- atomic_inc(&sk->sk_drops);
78786+ atomic_inc_unchecked(&sk->sk_drops);
78787 sk_mem_reclaim_partial(sk);
78788
78789 return err;
78790diff --git a/net/core/dev.c b/net/core/dev.c
78791index e5942bf..25998c3 100644
78792--- a/net/core/dev.c
78793+++ b/net/core/dev.c
78794@@ -1162,9 +1162,13 @@ void dev_load(struct net *net, const char *name)
78795 if (no_module && capable(CAP_NET_ADMIN))
78796 no_module = request_module("netdev-%s", name);
78797 if (no_module && capable(CAP_SYS_MODULE)) {
78798+#ifdef CONFIG_GRKERNSEC_MODHARDEN
78799+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
78800+#else
78801 if (!request_module("%s", name))
78802 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
78803 name);
78804+#endif
78805 }
78806 }
78807 EXPORT_SYMBOL(dev_load);
78808@@ -1627,7 +1631,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78809 {
78810 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
78811 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
78812- atomic_long_inc(&dev->rx_dropped);
78813+ atomic_long_inc_unchecked(&dev->rx_dropped);
78814 kfree_skb(skb);
78815 return NET_RX_DROP;
78816 }
78817@@ -1637,7 +1641,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
78818 nf_reset(skb);
78819
78820 if (unlikely(!is_skb_forwardable(dev, skb))) {
78821- atomic_long_inc(&dev->rx_dropped);
78822+ atomic_long_inc_unchecked(&dev->rx_dropped);
78823 kfree_skb(skb);
78824 return NET_RX_DROP;
78825 }
78826@@ -2093,7 +2097,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
78827
78828 struct dev_gso_cb {
78829 void (*destructor)(struct sk_buff *skb);
78830-};
78831+} __no_const;
78832
78833 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
78834
78835@@ -2955,7 +2959,7 @@ enqueue:
78836
78837 local_irq_restore(flags);
78838
78839- atomic_long_inc(&skb->dev->rx_dropped);
78840+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78841 kfree_skb(skb);
78842 return NET_RX_DROP;
78843 }
78844@@ -3027,7 +3031,7 @@ int netif_rx_ni(struct sk_buff *skb)
78845 }
78846 EXPORT_SYMBOL(netif_rx_ni);
78847
78848-static void net_tx_action(struct softirq_action *h)
78849+static void net_tx_action(void)
78850 {
78851 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78852
78853@@ -3358,7 +3362,7 @@ ncls:
78854 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
78855 } else {
78856 drop:
78857- atomic_long_inc(&skb->dev->rx_dropped);
78858+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
78859 kfree_skb(skb);
78860 /* Jamal, now you will not able to escape explaining
78861 * me how you were going to use this. :-)
78862@@ -3944,7 +3948,7 @@ void netif_napi_del(struct napi_struct *napi)
78863 }
78864 EXPORT_SYMBOL(netif_napi_del);
78865
78866-static void net_rx_action(struct softirq_action *h)
78867+static void net_rx_action(void)
78868 {
78869 struct softnet_data *sd = &__get_cpu_var(softnet_data);
78870 unsigned long time_limit = jiffies + 2;
78871@@ -4423,8 +4427,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
78872 else
78873 seq_printf(seq, "%04x", ntohs(pt->type));
78874
78875+#ifdef CONFIG_GRKERNSEC_HIDESYM
78876+ seq_printf(seq, " %-8s %p\n",
78877+ pt->dev ? pt->dev->name : "", NULL);
78878+#else
78879 seq_printf(seq, " %-8s %pF\n",
78880 pt->dev ? pt->dev->name : "", pt->func);
78881+#endif
78882 }
78883
78884 return 0;
78885@@ -5987,7 +5996,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
78886 } else {
78887 netdev_stats_to_stats64(storage, &dev->stats);
78888 }
78889- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
78890+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
78891 return storage;
78892 }
78893 EXPORT_SYMBOL(dev_get_stats);
78894diff --git a/net/core/flow.c b/net/core/flow.c
78895index e318c7e..168b1d0 100644
78896--- a/net/core/flow.c
78897+++ b/net/core/flow.c
78898@@ -61,7 +61,7 @@ struct flow_cache {
78899 struct timer_list rnd_timer;
78900 };
78901
78902-atomic_t flow_cache_genid = ATOMIC_INIT(0);
78903+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
78904 EXPORT_SYMBOL(flow_cache_genid);
78905 static struct flow_cache flow_cache_global;
78906 static struct kmem_cache *flow_cachep __read_mostly;
78907@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
78908
78909 static int flow_entry_valid(struct flow_cache_entry *fle)
78910 {
78911- if (atomic_read(&flow_cache_genid) != fle->genid)
78912+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
78913 return 0;
78914 if (fle->object && !fle->object->ops->check(fle->object))
78915 return 0;
78916@@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
78917 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
78918 fcp->hash_count++;
78919 }
78920- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
78921+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
78922 flo = fle->object;
78923 if (!flo)
78924 goto ret_object;
78925@@ -280,7 +280,7 @@ nocache:
78926 }
78927 flo = resolver(net, key, family, dir, flo, ctx);
78928 if (fle) {
78929- fle->genid = atomic_read(&flow_cache_genid);
78930+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
78931 if (!IS_ERR(flo))
78932 fle->object = flo;
78933 else
78934diff --git a/net/core/iovec.c b/net/core/iovec.c
78935index 7e7aeb0..2a998cb 100644
78936--- a/net/core/iovec.c
78937+++ b/net/core/iovec.c
78938@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78939 if (m->msg_namelen) {
78940 if (mode == VERIFY_READ) {
78941 void __user *namep;
78942- namep = (void __user __force *) m->msg_name;
78943+ namep = (void __force_user *) m->msg_name;
78944 err = move_addr_to_kernel(namep, m->msg_namelen,
78945 address);
78946 if (err < 0)
78947@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
78948 }
78949
78950 size = m->msg_iovlen * sizeof(struct iovec);
78951- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
78952+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
78953 return -EFAULT;
78954
78955 m->msg_iov = iov;
78956diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
78957index fad649a..f2fdac4 100644
78958--- a/net/core/rtnetlink.c
78959+++ b/net/core/rtnetlink.c
78960@@ -198,14 +198,16 @@ int __rtnl_register(int protocol, int msgtype,
78961 rtnl_msg_handlers[protocol] = tab;
78962 }
78963
78964+ pax_open_kernel();
78965 if (doit)
78966- tab[msgindex].doit = doit;
78967+ *(void **)&tab[msgindex].doit = doit;
78968
78969 if (dumpit)
78970- tab[msgindex].dumpit = dumpit;
78971+ *(void **)&tab[msgindex].dumpit = dumpit;
78972
78973 if (calcit)
78974- tab[msgindex].calcit = calcit;
78975+ *(void **)&tab[msgindex].calcit = calcit;
78976+ pax_close_kernel();
78977
78978 return 0;
78979 }
78980@@ -248,8 +250,10 @@ int rtnl_unregister(int protocol, int msgtype)
78981 if (rtnl_msg_handlers[protocol] == NULL)
78982 return -ENOENT;
78983
78984- rtnl_msg_handlers[protocol][msgindex].doit = NULL;
78985- rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
78986+ pax_open_kernel();
78987+ *(void **)&rtnl_msg_handlers[protocol][msgindex].doit = NULL;
78988+ *(void **)&rtnl_msg_handlers[protocol][msgindex].dumpit = NULL;
78989+ pax_close_kernel();
78990
78991 return 0;
78992 }
78993diff --git a/net/core/scm.c b/net/core/scm.c
78994index ab57084..0190c8f 100644
78995--- a/net/core/scm.c
78996+++ b/net/core/scm.c
78997@@ -223,7 +223,7 @@ EXPORT_SYMBOL(__scm_send);
78998 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
78999 {
79000 struct cmsghdr __user *cm
79001- = (__force struct cmsghdr __user *)msg->msg_control;
79002+ = (struct cmsghdr __force_user *)msg->msg_control;
79003 struct cmsghdr cmhdr;
79004 int cmlen = CMSG_LEN(len);
79005 int err;
79006@@ -246,7 +246,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
79007 err = -EFAULT;
79008 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
79009 goto out;
79010- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
79011+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
79012 goto out;
79013 cmlen = CMSG_SPACE(len);
79014 if (msg->msg_controllen < cmlen)
79015@@ -262,7 +262,7 @@ EXPORT_SYMBOL(put_cmsg);
79016 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79017 {
79018 struct cmsghdr __user *cm
79019- = (__force struct cmsghdr __user*)msg->msg_control;
79020+ = (struct cmsghdr __force_user *)msg->msg_control;
79021
79022 int fdmax = 0;
79023 int fdnum = scm->fp->count;
79024@@ -282,7 +282,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
79025 if (fdnum < fdmax)
79026 fdmax = fdnum;
79027
79028- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
79029+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
79030 i++, cmfptr++)
79031 {
79032 struct socket *sock;
79033diff --git a/net/core/sock.c b/net/core/sock.c
79034index 8a146cf..ee08914d 100644
79035--- a/net/core/sock.c
79036+++ b/net/core/sock.c
79037@@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79038 struct sk_buff_head *list = &sk->sk_receive_queue;
79039
79040 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
79041- atomic_inc(&sk->sk_drops);
79042+ atomic_inc_unchecked(&sk->sk_drops);
79043 trace_sock_rcvqueue_full(sk, skb);
79044 return -ENOMEM;
79045 }
79046@@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79047 return err;
79048
79049 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
79050- atomic_inc(&sk->sk_drops);
79051+ atomic_inc_unchecked(&sk->sk_drops);
79052 return -ENOBUFS;
79053 }
79054
79055@@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79056 skb_dst_force(skb);
79057
79058 spin_lock_irqsave(&list->lock, flags);
79059- skb->dropcount = atomic_read(&sk->sk_drops);
79060+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
79061 __skb_queue_tail(list, skb);
79062 spin_unlock_irqrestore(&list->lock, flags);
79063
79064@@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79065 skb->dev = NULL;
79066
79067 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
79068- atomic_inc(&sk->sk_drops);
79069+ atomic_inc_unchecked(&sk->sk_drops);
79070 goto discard_and_relse;
79071 }
79072 if (nested)
79073@@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
79074 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
79075 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
79076 bh_unlock_sock(sk);
79077- atomic_inc(&sk->sk_drops);
79078+ atomic_inc_unchecked(&sk->sk_drops);
79079 goto discard_and_relse;
79080 }
79081
79082@@ -875,12 +875,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79083 struct timeval tm;
79084 } v;
79085
79086- int lv = sizeof(int);
79087- int len;
79088+ unsigned int lv = sizeof(int);
79089+ unsigned int len;
79090
79091 if (get_user(len, optlen))
79092 return -EFAULT;
79093- if (len < 0)
79094+ if (len > INT_MAX)
79095 return -EINVAL;
79096
79097 memset(&v, 0, sizeof(v));
79098@@ -1028,11 +1028,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79099
79100 case SO_PEERNAME:
79101 {
79102- char address[128];
79103+ char address[_K_SS_MAXSIZE];
79104
79105 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
79106 return -ENOTCONN;
79107- if (lv < len)
79108+ if (lv < len || sizeof address < len)
79109 return -EINVAL;
79110 if (copy_to_user(optval, address, len))
79111 return -EFAULT;
79112@@ -1080,7 +1080,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
79113
79114 if (len > lv)
79115 len = lv;
79116- if (copy_to_user(optval, &v, len))
79117+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
79118 return -EFAULT;
79119 lenout:
79120 if (put_user(len, optlen))
79121@@ -2212,7 +2212,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
79122 */
79123 smp_wmb();
79124 atomic_set(&sk->sk_refcnt, 1);
79125- atomic_set(&sk->sk_drops, 0);
79126+ atomic_set_unchecked(&sk->sk_drops, 0);
79127 }
79128 EXPORT_SYMBOL(sock_init_data);
79129
79130diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
79131index 602cd63..05c6c60 100644
79132--- a/net/core/sock_diag.c
79133+++ b/net/core/sock_diag.c
79134@@ -15,20 +15,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
79135
79136 int sock_diag_check_cookie(void *sk, __u32 *cookie)
79137 {
79138+#ifndef CONFIG_GRKERNSEC_HIDESYM
79139 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
79140 cookie[1] != INET_DIAG_NOCOOKIE) &&
79141 ((u32)(unsigned long)sk != cookie[0] ||
79142 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
79143 return -ESTALE;
79144 else
79145+#endif
79146 return 0;
79147 }
79148 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
79149
79150 void sock_diag_save_cookie(void *sk, __u32 *cookie)
79151 {
79152+#ifdef CONFIG_GRKERNSEC_HIDESYM
79153+ cookie[0] = 0;
79154+ cookie[1] = 0;
79155+#else
79156 cookie[0] = (u32)(unsigned long)sk;
79157 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
79158+#endif
79159 }
79160 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
79161
79162diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
79163index a55eecc..dd8428c 100644
79164--- a/net/decnet/sysctl_net_decnet.c
79165+++ b/net/decnet/sysctl_net_decnet.c
79166@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
79167
79168 if (len > *lenp) len = *lenp;
79169
79170- if (copy_to_user(buffer, addr, len))
79171+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
79172 return -EFAULT;
79173
79174 *lenp = len;
79175@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
79176
79177 if (len > *lenp) len = *lenp;
79178
79179- if (copy_to_user(buffer, devname, len))
79180+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
79181 return -EFAULT;
79182
79183 *lenp = len;
79184diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
79185index 2a6abc1..c379ba7 100644
79186--- a/net/ipv4/devinet.c
79187+++ b/net/ipv4/devinet.c
79188@@ -822,9 +822,9 @@ int devinet_ioctl(struct net *net, unsigned int cmd, void __user *arg)
79189 if (!ifa) {
79190 ret = -ENOBUFS;
79191 ifa = inet_alloc_ifa();
79192+ if (!ifa)
79193+ break;
79194 INIT_HLIST_NODE(&ifa->hash);
79195- if (!ifa)
79196- break;
79197 if (colon)
79198 memcpy(ifa->ifa_label, ifr.ifr_name, IFNAMSIZ);
79199 else
79200diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
79201index 825c608..750ff29 100644
79202--- a/net/ipv4/fib_frontend.c
79203+++ b/net/ipv4/fib_frontend.c
79204@@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
79205 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79206 fib_sync_up(dev);
79207 #endif
79208- atomic_inc(&net->ipv4.dev_addr_genid);
79209+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79210 rt_cache_flush(dev_net(dev));
79211 break;
79212 case NETDEV_DOWN:
79213 fib_del_ifaddr(ifa, NULL);
79214- atomic_inc(&net->ipv4.dev_addr_genid);
79215+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79216 if (ifa->ifa_dev->ifa_list == NULL) {
79217 /* Last address was deleted from this interface.
79218 * Disable IP.
79219@@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
79220 #ifdef CONFIG_IP_ROUTE_MULTIPATH
79221 fib_sync_up(dev);
79222 #endif
79223- atomic_inc(&net->ipv4.dev_addr_genid);
79224+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
79225 rt_cache_flush(net);
79226 break;
79227 case NETDEV_DOWN:
79228diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
79229index 71b125c..f4c70b0 100644
79230--- a/net/ipv4/fib_semantics.c
79231+++ b/net/ipv4/fib_semantics.c
79232@@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
79233 nh->nh_saddr = inet_select_addr(nh->nh_dev,
79234 nh->nh_gw,
79235 nh->nh_parent->fib_scope);
79236- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
79237+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
79238
79239 return nh->nh_saddr;
79240 }
79241diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
79242index 7880af9..70f92a3 100644
79243--- a/net/ipv4/inet_hashtables.c
79244+++ b/net/ipv4/inet_hashtables.c
79245@@ -18,12 +18,15 @@
79246 #include <linux/sched.h>
79247 #include <linux/slab.h>
79248 #include <linux/wait.h>
79249+#include <linux/security.h>
79250
79251 #include <net/inet_connection_sock.h>
79252 #include <net/inet_hashtables.h>
79253 #include <net/secure_seq.h>
79254 #include <net/ip.h>
79255
79256+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
79257+
79258 /*
79259 * Allocate and initialize a new local port bind bucket.
79260 * The bindhash mutex for snum's hash chain must be held here.
79261@@ -530,6 +533,8 @@ ok:
79262 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
79263 spin_unlock(&head->lock);
79264
79265+ gr_update_task_in_ip_table(current, inet_sk(sk));
79266+
79267 if (tw) {
79268 inet_twsk_deschedule(tw, death_row);
79269 while (twrefcnt) {
79270diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
79271index 000e3d2..5472da3 100644
79272--- a/net/ipv4/inetpeer.c
79273+++ b/net/ipv4/inetpeer.c
79274@@ -503,8 +503,8 @@ relookup:
79275 if (p) {
79276 p->daddr = *daddr;
79277 atomic_set(&p->refcnt, 1);
79278- atomic_set(&p->rid, 0);
79279- atomic_set(&p->ip_id_count,
79280+ atomic_set_unchecked(&p->rid, 0);
79281+ atomic_set_unchecked(&p->ip_id_count,
79282 (daddr->family == AF_INET) ?
79283 secure_ip_id(daddr->addr.a4) :
79284 secure_ipv6_id(daddr->addr.a6));
79285diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
79286index 8d5cc75..821fd11 100644
79287--- a/net/ipv4/ip_fragment.c
79288+++ b/net/ipv4/ip_fragment.c
79289@@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
79290 return 0;
79291
79292 start = qp->rid;
79293- end = atomic_inc_return(&peer->rid);
79294+ end = atomic_inc_return_unchecked(&peer->rid);
79295 qp->rid = end;
79296
79297 rc = qp->q.fragments && (end - start) > max;
79298diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
79299index 14bbfcf..644f472 100644
79300--- a/net/ipv4/ip_sockglue.c
79301+++ b/net/ipv4/ip_sockglue.c
79302@@ -1151,7 +1151,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79303 len = min_t(unsigned int, len, opt->optlen);
79304 if (put_user(len, optlen))
79305 return -EFAULT;
79306- if (copy_to_user(optval, opt->__data, len))
79307+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
79308+ copy_to_user(optval, opt->__data, len))
79309 return -EFAULT;
79310 return 0;
79311 }
79312@@ -1282,7 +1283,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
79313 if (sk->sk_type != SOCK_STREAM)
79314 return -ENOPROTOOPT;
79315
79316- msg.msg_control = optval;
79317+ msg.msg_control = (void __force_kernel *)optval;
79318 msg.msg_controllen = len;
79319 msg.msg_flags = flags;
79320
79321diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
79322index 798358b..73570b7 100644
79323--- a/net/ipv4/ipconfig.c
79324+++ b/net/ipv4/ipconfig.c
79325@@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
79326
79327 mm_segment_t oldfs = get_fs();
79328 set_fs(get_ds());
79329- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79330+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79331 set_fs(oldfs);
79332 return res;
79333 }
79334@@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
79335
79336 mm_segment_t oldfs = get_fs();
79337 set_fs(get_ds());
79338- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
79339+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
79340 set_fs(oldfs);
79341 return res;
79342 }
79343@@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
79344
79345 mm_segment_t oldfs = get_fs();
79346 set_fs(get_ds());
79347- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
79348+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
79349 set_fs(oldfs);
79350 return res;
79351 }
79352diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
79353index 97e61ea..cac1bbb 100644
79354--- a/net/ipv4/netfilter/arp_tables.c
79355+++ b/net/ipv4/netfilter/arp_tables.c
79356@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
79357 #endif
79358
79359 static int get_info(struct net *net, void __user *user,
79360- const int *len, int compat)
79361+ int len, int compat)
79362 {
79363 char name[XT_TABLE_MAXNAMELEN];
79364 struct xt_table *t;
79365 int ret;
79366
79367- if (*len != sizeof(struct arpt_getinfo)) {
79368- duprintf("length %u != %Zu\n", *len,
79369+ if (len != sizeof(struct arpt_getinfo)) {
79370+ duprintf("length %u != %Zu\n", len,
79371 sizeof(struct arpt_getinfo));
79372 return -EINVAL;
79373 }
79374@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
79375 info.size = private->size;
79376 strcpy(info.name, name);
79377
79378- if (copy_to_user(user, &info, *len) != 0)
79379+ if (copy_to_user(user, &info, len) != 0)
79380 ret = -EFAULT;
79381 else
79382 ret = 0;
79383@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
79384
79385 switch (cmd) {
79386 case ARPT_SO_GET_INFO:
79387- ret = get_info(sock_net(sk), user, len, 1);
79388+ ret = get_info(sock_net(sk), user, *len, 1);
79389 break;
79390 case ARPT_SO_GET_ENTRIES:
79391 ret = compat_get_entries(sock_net(sk), user, len);
79392@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
79393
79394 switch (cmd) {
79395 case ARPT_SO_GET_INFO:
79396- ret = get_info(sock_net(sk), user, len, 0);
79397+ ret = get_info(sock_net(sk), user, *len, 0);
79398 break;
79399
79400 case ARPT_SO_GET_ENTRIES:
79401diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
79402index 170b1fd..6105b91 100644
79403--- a/net/ipv4/netfilter/ip_tables.c
79404+++ b/net/ipv4/netfilter/ip_tables.c
79405@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
79406 #endif
79407
79408 static int get_info(struct net *net, void __user *user,
79409- const int *len, int compat)
79410+ int len, int compat)
79411 {
79412 char name[XT_TABLE_MAXNAMELEN];
79413 struct xt_table *t;
79414 int ret;
79415
79416- if (*len != sizeof(struct ipt_getinfo)) {
79417- duprintf("length %u != %zu\n", *len,
79418+ if (len != sizeof(struct ipt_getinfo)) {
79419+ duprintf("length %u != %zu\n", len,
79420 sizeof(struct ipt_getinfo));
79421 return -EINVAL;
79422 }
79423@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
79424 info.size = private->size;
79425 strcpy(info.name, name);
79426
79427- if (copy_to_user(user, &info, *len) != 0)
79428+ if (copy_to_user(user, &info, len) != 0)
79429 ret = -EFAULT;
79430 else
79431 ret = 0;
79432@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79433
79434 switch (cmd) {
79435 case IPT_SO_GET_INFO:
79436- ret = get_info(sock_net(sk), user, len, 1);
79437+ ret = get_info(sock_net(sk), user, *len, 1);
79438 break;
79439 case IPT_SO_GET_ENTRIES:
79440 ret = compat_get_entries(sock_net(sk), user, len);
79441@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79442
79443 switch (cmd) {
79444 case IPT_SO_GET_INFO:
79445- ret = get_info(sock_net(sk), user, len, 0);
79446+ ret = get_info(sock_net(sk), user, *len, 0);
79447 break;
79448
79449 case IPT_SO_GET_ENTRIES:
79450diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
79451index 8f3d054..c58d05d 100644
79452--- a/net/ipv4/ping.c
79453+++ b/net/ipv4/ping.c
79454@@ -843,7 +843,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
79455 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79456 0, sock_i_ino(sp),
79457 atomic_read(&sp->sk_refcnt), sp,
79458- atomic_read(&sp->sk_drops), len);
79459+ atomic_read_unchecked(&sp->sk_drops), len);
79460 }
79461
79462 static int ping_seq_show(struct seq_file *seq, void *v)
79463diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
79464index 73d1e4d..3af0e8f 100644
79465--- a/net/ipv4/raw.c
79466+++ b/net/ipv4/raw.c
79467@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
79468 int raw_rcv(struct sock *sk, struct sk_buff *skb)
79469 {
79470 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
79471- atomic_inc(&sk->sk_drops);
79472+ atomic_inc_unchecked(&sk->sk_drops);
79473 kfree_skb(skb);
79474 return NET_RX_DROP;
79475 }
79476@@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
79477
79478 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
79479 {
79480+ struct icmp_filter filter;
79481+
79482 if (optlen > sizeof(struct icmp_filter))
79483 optlen = sizeof(struct icmp_filter);
79484- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
79485+ if (copy_from_user(&filter, optval, optlen))
79486 return -EFAULT;
79487+ raw_sk(sk)->filter = filter;
79488 return 0;
79489 }
79490
79491 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
79492 {
79493 int len, ret = -EFAULT;
79494+ struct icmp_filter filter;
79495
79496 if (get_user(len, optlen))
79497 goto out;
79498@@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
79499 if (len > sizeof(struct icmp_filter))
79500 len = sizeof(struct icmp_filter);
79501 ret = -EFAULT;
79502- if (put_user(len, optlen) ||
79503- copy_to_user(optval, &raw_sk(sk)->filter, len))
79504+ filter = raw_sk(sk)->filter;
79505+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
79506 goto out;
79507 ret = 0;
79508 out: return ret;
79509@@ -997,7 +1001,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
79510 0, 0L, 0,
79511 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
79512 0, sock_i_ino(sp),
79513- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
79514+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
79515 }
79516
79517 static int raw_seq_show(struct seq_file *seq, void *v)
79518diff --git a/net/ipv4/route.c b/net/ipv4/route.c
79519index df25142..e92a82a 100644
79520--- a/net/ipv4/route.c
79521+++ b/net/ipv4/route.c
79522@@ -2529,7 +2529,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
79523
79524 static __net_init int rt_genid_init(struct net *net)
79525 {
79526- atomic_set(&net->rt_genid, 0);
79527+ atomic_set_unchecked(&net->rt_genid, 0);
79528 get_random_bytes(&net->ipv4.dev_addr_genid,
79529 sizeof(net->ipv4.dev_addr_genid));
79530 return 0;
79531diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
79532index 181fc82..cc95f8c 100644
79533--- a/net/ipv4/tcp_input.c
79534+++ b/net/ipv4/tcp_input.c
79535@@ -4704,7 +4704,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
79536 * simplifies code)
79537 */
79538 static void
79539-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79540+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
79541 struct sk_buff *head, struct sk_buff *tail,
79542 u32 start, u32 end)
79543 {
79544@@ -5536,6 +5536,9 @@ slow_path:
79545 if (len < (th->doff << 2) || tcp_checksum_complete_user(sk, skb))
79546 goto csum_error;
79547
79548+ if (!th->ack)
79549+ goto discard;
79550+
79551 /*
79552 * Standard slow path.
79553 */
79554@@ -5544,7 +5547,7 @@ slow_path:
79555 return 0;
79556
79557 step5:
79558- if (th->ack && tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79559+ if (tcp_ack(sk, skb, FLAG_SLOWPATH) < 0)
79560 goto discard;
79561
79562 /* ts_recent update must be made after we are sure that the packet
79563@@ -5836,6 +5839,7 @@ discard:
79564 tcp_paws_reject(&tp->rx_opt, 0))
79565 goto discard_and_undo;
79566
79567+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
79568 if (th->syn) {
79569 /* We see SYN without ACK. It is attempt of
79570 * simultaneous connect with crossed SYNs.
79571@@ -5886,6 +5890,7 @@ discard:
79572 goto discard;
79573 #endif
79574 }
79575+#endif
79576 /* "fifth, if neither of the SYN or RST bits is set then
79577 * drop the segment and return."
79578 */
79579@@ -5930,7 +5935,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79580 goto discard;
79581
79582 if (th->syn) {
79583- if (th->fin)
79584+ if (th->fin || th->urg || th->psh)
79585 goto discard;
79586 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
79587 return 1;
79588@@ -5977,11 +5982,15 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79589 if (tcp_check_req(sk, skb, req, NULL, true) == NULL)
79590 goto discard;
79591 }
79592+
79593+ if (!th->ack)
79594+ goto discard;
79595+
79596 if (!tcp_validate_incoming(sk, skb, th, 0))
79597 return 0;
79598
79599 /* step 5: check the ACK field */
79600- if (th->ack) {
79601+ if (true) {
79602 int acceptable = tcp_ack(sk, skb, FLAG_SLOWPATH) > 0;
79603
79604 switch (sk->sk_state) {
79605@@ -6131,8 +6140,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
79606 }
79607 break;
79608 }
79609- } else
79610- goto discard;
79611+ }
79612
79613 /* ts_recent update must be made after we are sure that the packet
79614 * is in window.
79615diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
79616index bc3cb46..815ccd6 100644
79617--- a/net/ipv4/tcp_ipv4.c
79618+++ b/net/ipv4/tcp_ipv4.c
79619@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
79620 EXPORT_SYMBOL(sysctl_tcp_low_latency);
79621
79622
79623+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79624+extern int grsec_enable_blackhole;
79625+#endif
79626+
79627 #ifdef CONFIG_TCP_MD5SIG
79628 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
79629 __be32 daddr, __be32 saddr, const struct tcphdr *th);
79630@@ -1899,6 +1903,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
79631 return 0;
79632
79633 reset:
79634+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79635+ if (!grsec_enable_blackhole)
79636+#endif
79637 tcp_v4_send_reset(rsk, skb);
79638 discard:
79639 kfree_skb(skb);
79640@@ -1999,12 +2006,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
79641 TCP_SKB_CB(skb)->sacked = 0;
79642
79643 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
79644- if (!sk)
79645+ if (!sk) {
79646+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79647+ ret = 1;
79648+#endif
79649 goto no_tcp_socket;
79650-
79651+ }
79652 process:
79653- if (sk->sk_state == TCP_TIME_WAIT)
79654+ if (sk->sk_state == TCP_TIME_WAIT) {
79655+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79656+ ret = 2;
79657+#endif
79658 goto do_time_wait;
79659+ }
79660
79661 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
79662 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
79663@@ -2055,6 +2069,10 @@ no_tcp_socket:
79664 bad_packet:
79665 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
79666 } else {
79667+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79668+ if (!grsec_enable_blackhole || (ret == 1 &&
79669+ (skb->dev->flags & IFF_LOOPBACK)))
79670+#endif
79671 tcp_v4_send_reset(NULL, skb);
79672 }
79673
79674diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
79675index a7302d9..e3ec754 100644
79676--- a/net/ipv4/tcp_minisocks.c
79677+++ b/net/ipv4/tcp_minisocks.c
79678@@ -27,6 +27,10 @@
79679 #include <net/inet_common.h>
79680 #include <net/xfrm.h>
79681
79682+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79683+extern int grsec_enable_blackhole;
79684+#endif
79685+
79686 int sysctl_tcp_syncookies __read_mostly = 1;
79687 EXPORT_SYMBOL(sysctl_tcp_syncookies);
79688
79689@@ -742,7 +746,10 @@ embryonic_reset:
79690 * avoid becoming vulnerable to outside attack aiming at
79691 * resetting legit local connections.
79692 */
79693- req->rsk_ops->send_reset(sk, skb);
79694+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79695+ if (!grsec_enable_blackhole)
79696+#endif
79697+ req->rsk_ops->send_reset(sk, skb);
79698 } else if (fastopen) { /* received a valid RST pkt */
79699 reqsk_fastopen_remove(sk, req, true);
79700 tcp_reset(sk);
79701diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
79702index 4526fe6..1a34e43 100644
79703--- a/net/ipv4/tcp_probe.c
79704+++ b/net/ipv4/tcp_probe.c
79705@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
79706 if (cnt + width >= len)
79707 break;
79708
79709- if (copy_to_user(buf + cnt, tbuf, width))
79710+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
79711 return -EFAULT;
79712 cnt += width;
79713 }
79714diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
79715index d47c1b4..b0584de 100644
79716--- a/net/ipv4/tcp_timer.c
79717+++ b/net/ipv4/tcp_timer.c
79718@@ -22,6 +22,10 @@
79719 #include <linux/gfp.h>
79720 #include <net/tcp.h>
79721
79722+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79723+extern int grsec_lastack_retries;
79724+#endif
79725+
79726 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
79727 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
79728 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
79729@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
79730 }
79731 }
79732
79733+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79734+ if ((sk->sk_state == TCP_LAST_ACK) &&
79735+ (grsec_lastack_retries > 0) &&
79736+ (grsec_lastack_retries < retry_until))
79737+ retry_until = grsec_lastack_retries;
79738+#endif
79739+
79740 if (retransmits_timed_out(sk, retry_until,
79741 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
79742 /* Has it gone just too far? */
79743diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
79744index 79c8dbe..aceb1b6 100644
79745--- a/net/ipv4/udp.c
79746+++ b/net/ipv4/udp.c
79747@@ -87,6 +87,7 @@
79748 #include <linux/types.h>
79749 #include <linux/fcntl.h>
79750 #include <linux/module.h>
79751+#include <linux/security.h>
79752 #include <linux/socket.h>
79753 #include <linux/sockios.h>
79754 #include <linux/igmp.h>
79755@@ -111,6 +112,10 @@
79756 #include <trace/events/skb.h>
79757 #include "udp_impl.h"
79758
79759+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79760+extern int grsec_enable_blackhole;
79761+#endif
79762+
79763 struct udp_table udp_table __read_mostly;
79764 EXPORT_SYMBOL(udp_table);
79765
79766@@ -569,6 +574,9 @@ found:
79767 return s;
79768 }
79769
79770+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
79771+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
79772+
79773 /*
79774 * This routine is called by the ICMP module when it gets some
79775 * sort of error condition. If err < 0 then the socket should
79776@@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
79777 dport = usin->sin_port;
79778 if (dport == 0)
79779 return -EINVAL;
79780+
79781+ err = gr_search_udp_sendmsg(sk, usin);
79782+ if (err)
79783+ return err;
79784 } else {
79785 if (sk->sk_state != TCP_ESTABLISHED)
79786 return -EDESTADDRREQ;
79787+
79788+ err = gr_search_udp_sendmsg(sk, NULL);
79789+ if (err)
79790+ return err;
79791+
79792 daddr = inet->inet_daddr;
79793 dport = inet->inet_dport;
79794 /* Open fast path for connected socket.
79795@@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
79796 udp_lib_checksum_complete(skb)) {
79797 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79798 IS_UDPLITE(sk));
79799- atomic_inc(&sk->sk_drops);
79800+ atomic_inc_unchecked(&sk->sk_drops);
79801 __skb_unlink(skb, rcvq);
79802 __skb_queue_tail(&list_kill, skb);
79803 }
79804@@ -1194,6 +1211,10 @@ try_again:
79805 if (!skb)
79806 goto out;
79807
79808+ err = gr_search_udp_recvmsg(sk, skb);
79809+ if (err)
79810+ goto out_free;
79811+
79812 ulen = skb->len - sizeof(struct udphdr);
79813 copied = len;
79814 if (copied > ulen)
79815@@ -1227,7 +1248,7 @@ try_again:
79816 if (unlikely(err)) {
79817 trace_kfree_skb(skb, udp_recvmsg);
79818 if (!peeked) {
79819- atomic_inc(&sk->sk_drops);
79820+ atomic_inc_unchecked(&sk->sk_drops);
79821 UDP_INC_STATS_USER(sock_net(sk),
79822 UDP_MIB_INERRORS, is_udplite);
79823 }
79824@@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
79825
79826 drop:
79827 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
79828- atomic_inc(&sk->sk_drops);
79829+ atomic_inc_unchecked(&sk->sk_drops);
79830 kfree_skb(skb);
79831 return -1;
79832 }
79833@@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
79834 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
79835
79836 if (!skb1) {
79837- atomic_inc(&sk->sk_drops);
79838+ atomic_inc_unchecked(&sk->sk_drops);
79839 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
79840 IS_UDPLITE(sk));
79841 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
79842@@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
79843 goto csum_error;
79844
79845 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
79846+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
79847+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
79848+#endif
79849 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
79850
79851 /*
79852@@ -2119,7 +2143,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
79853 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
79854 0, sock_i_ino(sp),
79855 atomic_read(&sp->sk_refcnt), sp,
79856- atomic_read(&sp->sk_drops), len);
79857+ atomic_read_unchecked(&sp->sk_drops), len);
79858 }
79859
79860 int udp4_seq_show(struct seq_file *seq, void *v)
79861diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
79862index 0424e4e..308dd43 100644
79863--- a/net/ipv6/addrconf.c
79864+++ b/net/ipv6/addrconf.c
79865@@ -2121,7 +2121,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
79866 p.iph.ihl = 5;
79867 p.iph.protocol = IPPROTO_IPV6;
79868 p.iph.ttl = 64;
79869- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
79870+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
79871
79872 if (ops->ndo_do_ioctl) {
79873 mm_segment_t oldfs = get_fs();
79874diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
79875index d5cb3c4..b3e38d0 100644
79876--- a/net/ipv6/ip6_gre.c
79877+++ b/net/ipv6/ip6_gre.c
79878@@ -1353,7 +1353,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
79879 }
79880
79881
79882-static struct inet6_protocol ip6gre_protocol __read_mostly = {
79883+static struct inet6_protocol ip6gre_protocol = {
79884 .handler = ip6gre_rcv,
79885 .err_handler = ip6gre_err,
79886 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
79887diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
79888index e02faed..9780f28 100644
79889--- a/net/ipv6/ipv6_sockglue.c
79890+++ b/net/ipv6/ipv6_sockglue.c
79891@@ -990,7 +990,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
79892 if (sk->sk_type != SOCK_STREAM)
79893 return -ENOPROTOOPT;
79894
79895- msg.msg_control = optval;
79896+ msg.msg_control = (void __force_kernel *)optval;
79897 msg.msg_controllen = len;
79898 msg.msg_flags = flags;
79899
79900diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
79901index d7cb045..8c0ded6 100644
79902--- a/net/ipv6/netfilter/ip6_tables.c
79903+++ b/net/ipv6/netfilter/ip6_tables.c
79904@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
79905 #endif
79906
79907 static int get_info(struct net *net, void __user *user,
79908- const int *len, int compat)
79909+ int len, int compat)
79910 {
79911 char name[XT_TABLE_MAXNAMELEN];
79912 struct xt_table *t;
79913 int ret;
79914
79915- if (*len != sizeof(struct ip6t_getinfo)) {
79916- duprintf("length %u != %zu\n", *len,
79917+ if (len != sizeof(struct ip6t_getinfo)) {
79918+ duprintf("length %u != %zu\n", len,
79919 sizeof(struct ip6t_getinfo));
79920 return -EINVAL;
79921 }
79922@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
79923 info.size = private->size;
79924 strcpy(info.name, name);
79925
79926- if (copy_to_user(user, &info, *len) != 0)
79927+ if (copy_to_user(user, &info, len) != 0)
79928 ret = -EFAULT;
79929 else
79930 ret = 0;
79931@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79932
79933 switch (cmd) {
79934 case IP6T_SO_GET_INFO:
79935- ret = get_info(sock_net(sk), user, len, 1);
79936+ ret = get_info(sock_net(sk), user, *len, 1);
79937 break;
79938 case IP6T_SO_GET_ENTRIES:
79939 ret = compat_get_entries(sock_net(sk), user, len);
79940@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
79941
79942 switch (cmd) {
79943 case IP6T_SO_GET_INFO:
79944- ret = get_info(sock_net(sk), user, len, 0);
79945+ ret = get_info(sock_net(sk), user, *len, 0);
79946 break;
79947
79948 case IP6T_SO_GET_ENTRIES:
79949diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
79950index d8e95c7..81422bc 100644
79951--- a/net/ipv6/raw.c
79952+++ b/net/ipv6/raw.c
79953@@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
79954 {
79955 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
79956 skb_checksum_complete(skb)) {
79957- atomic_inc(&sk->sk_drops);
79958+ atomic_inc_unchecked(&sk->sk_drops);
79959 kfree_skb(skb);
79960 return NET_RX_DROP;
79961 }
79962@@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79963 struct raw6_sock *rp = raw6_sk(sk);
79964
79965 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
79966- atomic_inc(&sk->sk_drops);
79967+ atomic_inc_unchecked(&sk->sk_drops);
79968 kfree_skb(skb);
79969 return NET_RX_DROP;
79970 }
79971@@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
79972
79973 if (inet->hdrincl) {
79974 if (skb_checksum_complete(skb)) {
79975- atomic_inc(&sk->sk_drops);
79976+ atomic_inc_unchecked(&sk->sk_drops);
79977 kfree_skb(skb);
79978 return NET_RX_DROP;
79979 }
79980@@ -604,7 +604,7 @@ out:
79981 return err;
79982 }
79983
79984-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
79985+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
79986 struct flowi6 *fl6, struct dst_entry **dstp,
79987 unsigned int flags)
79988 {
79989@@ -916,12 +916,15 @@ do_confirm:
79990 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
79991 char __user *optval, int optlen)
79992 {
79993+ struct icmp6_filter filter;
79994+
79995 switch (optname) {
79996 case ICMPV6_FILTER:
79997 if (optlen > sizeof(struct icmp6_filter))
79998 optlen = sizeof(struct icmp6_filter);
79999- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
80000+ if (copy_from_user(&filter, optval, optlen))
80001 return -EFAULT;
80002+ raw6_sk(sk)->filter = filter;
80003 return 0;
80004 default:
80005 return -ENOPROTOOPT;
80006@@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80007 char __user *optval, int __user *optlen)
80008 {
80009 int len;
80010+ struct icmp6_filter filter;
80011
80012 switch (optname) {
80013 case ICMPV6_FILTER:
80014@@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
80015 len = sizeof(struct icmp6_filter);
80016 if (put_user(len, optlen))
80017 return -EFAULT;
80018- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
80019+ filter = raw6_sk(sk)->filter;
80020+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
80021 return -EFAULT;
80022 return 0;
80023 default:
80024@@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
80025 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
80026 0,
80027 sock_i_ino(sp),
80028- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
80029+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
80030 }
80031
80032 static int raw6_seq_show(struct seq_file *seq, void *v)
80033diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
80034index 73f2a6b..f8049a1 100644
80035--- a/net/ipv6/tcp_ipv6.c
80036+++ b/net/ipv6/tcp_ipv6.c
80037@@ -106,6 +106,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
80038 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
80039 }
80040
80041+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80042+extern int grsec_enable_blackhole;
80043+#endif
80044+
80045 static void tcp_v6_hash(struct sock *sk)
80046 {
80047 if (sk->sk_state != TCP_CLOSE) {
80048@@ -1525,6 +1529,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
80049 return 0;
80050
80051 reset:
80052+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80053+ if (!grsec_enable_blackhole)
80054+#endif
80055 tcp_v6_send_reset(sk, skb);
80056 discard:
80057 if (opt_skb)
80058@@ -1606,12 +1613,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
80059 TCP_SKB_CB(skb)->sacked = 0;
80060
80061 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
80062- if (!sk)
80063+ if (!sk) {
80064+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80065+ ret = 1;
80066+#endif
80067 goto no_tcp_socket;
80068+ }
80069
80070 process:
80071- if (sk->sk_state == TCP_TIME_WAIT)
80072+ if (sk->sk_state == TCP_TIME_WAIT) {
80073+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80074+ ret = 2;
80075+#endif
80076 goto do_time_wait;
80077+ }
80078
80079 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
80080 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
80081@@ -1660,6 +1675,10 @@ no_tcp_socket:
80082 bad_packet:
80083 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
80084 } else {
80085+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80086+ if (!grsec_enable_blackhole || (ret == 1 &&
80087+ (skb->dev->flags & IFF_LOOPBACK)))
80088+#endif
80089 tcp_v6_send_reset(NULL, skb);
80090 }
80091
80092diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
80093index fc99972..69397e8 100644
80094--- a/net/ipv6/udp.c
80095+++ b/net/ipv6/udp.c
80096@@ -51,6 +51,10 @@
80097 #include <trace/events/skb.h>
80098 #include "udp_impl.h"
80099
80100+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80101+extern int grsec_enable_blackhole;
80102+#endif
80103+
80104 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
80105 {
80106 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
80107@@ -395,7 +399,7 @@ try_again:
80108 if (unlikely(err)) {
80109 trace_kfree_skb(skb, udpv6_recvmsg);
80110 if (!peeked) {
80111- atomic_inc(&sk->sk_drops);
80112+ atomic_inc_unchecked(&sk->sk_drops);
80113 if (is_udp4)
80114 UDP_INC_STATS_USER(sock_net(sk),
80115 UDP_MIB_INERRORS,
80116@@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
80117 return rc;
80118 drop:
80119 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
80120- atomic_inc(&sk->sk_drops);
80121+ atomic_inc_unchecked(&sk->sk_drops);
80122 kfree_skb(skb);
80123 return -1;
80124 }
80125@@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
80126 if (likely(skb1 == NULL))
80127 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
80128 if (!skb1) {
80129- atomic_inc(&sk->sk_drops);
80130+ atomic_inc_unchecked(&sk->sk_drops);
80131 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
80132 IS_UDPLITE(sk));
80133 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
80134@@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
80135 goto discard;
80136
80137 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
80138+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
80139+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
80140+#endif
80141 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
80142
80143 kfree_skb(skb);
80144@@ -1473,7 +1480,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
80145 0,
80146 sock_i_ino(sp),
80147 atomic_read(&sp->sk_refcnt), sp,
80148- atomic_read(&sp->sk_drops));
80149+ atomic_read_unchecked(&sp->sk_drops));
80150 }
80151
80152 int udp6_seq_show(struct seq_file *seq, void *v)
80153diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
80154index 496ce2c..f79fac8 100644
80155--- a/net/irda/ircomm/ircomm_tty.c
80156+++ b/net/irda/ircomm/ircomm_tty.c
80157@@ -311,12 +311,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80158 add_wait_queue(&port->open_wait, &wait);
80159
80160 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
80161- __FILE__, __LINE__, tty->driver->name, port->count);
80162+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80163
80164 spin_lock_irqsave(&port->lock, flags);
80165 if (!tty_hung_up_p(filp)) {
80166 extra_count = 1;
80167- port->count--;
80168+ atomic_dec(&port->count);
80169 }
80170 spin_unlock_irqrestore(&port->lock, flags);
80171 port->blocked_open++;
80172@@ -352,7 +352,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80173 }
80174
80175 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
80176- __FILE__, __LINE__, tty->driver->name, port->count);
80177+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80178
80179 schedule();
80180 }
80181@@ -363,13 +363,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
80182 if (extra_count) {
80183 /* ++ is not atomic, so this should be protected - Jean II */
80184 spin_lock_irqsave(&port->lock, flags);
80185- port->count++;
80186+ atomic_inc(&port->count);
80187 spin_unlock_irqrestore(&port->lock, flags);
80188 }
80189 port->blocked_open--;
80190
80191 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
80192- __FILE__, __LINE__, tty->driver->name, port->count);
80193+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
80194
80195 if (!retval)
80196 port->flags |= ASYNC_NORMAL_ACTIVE;
80197@@ -443,12 +443,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
80198
80199 /* ++ is not atomic, so this should be protected - Jean II */
80200 spin_lock_irqsave(&self->port.lock, flags);
80201- self->port.count++;
80202+ atomic_inc(&self->port.count);
80203 spin_unlock_irqrestore(&self->port.lock, flags);
80204 tty_port_tty_set(&self->port, tty);
80205
80206 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
80207- self->line, self->port.count);
80208+ self->line, atomic_read(&self->port.count));
80209
80210 /* Not really used by us, but lets do it anyway */
80211 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
80212@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
80213 tty_kref_put(port->tty);
80214 }
80215 port->tty = NULL;
80216- port->count = 0;
80217+ atomic_set(&port->count, 0);
80218 spin_unlock_irqrestore(&port->lock, flags);
80219
80220 wake_up_interruptible(&port->open_wait);
80221@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
80222 seq_putc(m, '\n');
80223
80224 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
80225- seq_printf(m, "Open count: %d\n", self->port.count);
80226+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
80227 seq_printf(m, "Max data size: %d\n", self->max_data_size);
80228 seq_printf(m, "Max header size: %d\n", self->max_header_size);
80229
80230diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
80231index cd6f7a9..e63fe89 100644
80232--- a/net/iucv/af_iucv.c
80233+++ b/net/iucv/af_iucv.c
80234@@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
80235
80236 write_lock_bh(&iucv_sk_list.lock);
80237
80238- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
80239+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80240 while (__iucv_get_sock_by_name(name)) {
80241 sprintf(name, "%08x",
80242- atomic_inc_return(&iucv_sk_list.autobind_name));
80243+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
80244 }
80245
80246 write_unlock_bh(&iucv_sk_list.lock);
80247diff --git a/net/key/af_key.c b/net/key/af_key.c
80248index 08897a3..0b812ab 100644
80249--- a/net/key/af_key.c
80250+++ b/net/key/af_key.c
80251@@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
80252 static u32 get_acqseq(void)
80253 {
80254 u32 res;
80255- static atomic_t acqseq;
80256+ static atomic_unchecked_t acqseq;
80257
80258 do {
80259- res = atomic_inc_return(&acqseq);
80260+ res = atomic_inc_return_unchecked(&acqseq);
80261 } while (!res);
80262 return res;
80263 }
80264diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
80265index 7371f67..9897314 100644
80266--- a/net/mac80211/cfg.c
80267+++ b/net/mac80211/cfg.c
80268@@ -2594,7 +2594,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
80269 else
80270 local->probe_req_reg--;
80271
80272- if (!local->open_count)
80273+ if (!local_read(&local->open_count))
80274 break;
80275
80276 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
80277diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
80278index 3da215c..497a6e3 100644
80279--- a/net/mac80211/ieee80211_i.h
80280+++ b/net/mac80211/ieee80211_i.h
80281@@ -28,6 +28,7 @@
80282 #include <net/ieee80211_radiotap.h>
80283 #include <net/cfg80211.h>
80284 #include <net/mac80211.h>
80285+#include <asm/local.h>
80286 #include "key.h"
80287 #include "sta_info.h"
80288 #include "debug.h"
80289@@ -852,7 +853,7 @@ struct ieee80211_local {
80290 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
80291 spinlock_t queue_stop_reason_lock;
80292
80293- int open_count;
80294+ local_t open_count;
80295 int monitors, cooked_mntrs;
80296 /* number of interfaces with corresponding FIF_ flags */
80297 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
80298diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
80299index 0f5af91..4dba9e7 100644
80300--- a/net/mac80211/iface.c
80301+++ b/net/mac80211/iface.c
80302@@ -465,7 +465,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80303 break;
80304 }
80305
80306- if (local->open_count == 0) {
80307+ if (local_read(&local->open_count) == 0) {
80308 res = drv_start(local);
80309 if (res)
80310 goto err_del_bss;
80311@@ -508,7 +508,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80312 break;
80313 }
80314
80315- if (local->monitors == 0 && local->open_count == 0) {
80316+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
80317 res = ieee80211_add_virtual_monitor(local);
80318 if (res)
80319 goto err_stop;
80320@@ -616,7 +616,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80321 mutex_unlock(&local->mtx);
80322
80323 if (coming_up)
80324- local->open_count++;
80325+ local_inc(&local->open_count);
80326
80327 if (hw_reconf_flags)
80328 ieee80211_hw_config(local, hw_reconf_flags);
80329@@ -630,7 +630,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
80330 err_del_interface:
80331 drv_remove_interface(local, sdata);
80332 err_stop:
80333- if (!local->open_count)
80334+ if (!local_read(&local->open_count))
80335 drv_stop(local);
80336 err_del_bss:
80337 sdata->bss = NULL;
80338@@ -762,7 +762,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80339 }
80340
80341 if (going_down)
80342- local->open_count--;
80343+ local_dec(&local->open_count);
80344
80345 switch (sdata->vif.type) {
80346 case NL80211_IFTYPE_AP_VLAN:
80347@@ -818,7 +818,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80348
80349 ieee80211_recalc_ps(local, -1);
80350
80351- if (local->open_count == 0) {
80352+ if (local_read(&local->open_count) == 0) {
80353 if (local->ops->napi_poll)
80354 napi_disable(&local->napi);
80355 ieee80211_clear_tx_pending(local);
80356@@ -850,7 +850,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
80357 }
80358 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
80359
80360- if (local->monitors == local->open_count && local->monitors > 0)
80361+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
80362 ieee80211_add_virtual_monitor(local);
80363 }
80364
80365diff --git a/net/mac80211/main.c b/net/mac80211/main.c
80366index f57f597..e0a7c03 100644
80367--- a/net/mac80211/main.c
80368+++ b/net/mac80211/main.c
80369@@ -164,7 +164,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
80370 local->hw.conf.power_level = power;
80371 }
80372
80373- if (changed && local->open_count) {
80374+ if (changed && local_read(&local->open_count)) {
80375 ret = drv_config(local, changed);
80376 /*
80377 * Goal:
80378diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
80379index 5c572e7..ecf75ce 100644
80380--- a/net/mac80211/pm.c
80381+++ b/net/mac80211/pm.c
80382@@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80383 struct ieee80211_sub_if_data *sdata;
80384 struct sta_info *sta;
80385
80386- if (!local->open_count)
80387+ if (!local_read(&local->open_count))
80388 goto suspend;
80389
80390 ieee80211_scan_cancel(local);
80391@@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80392 cancel_work_sync(&local->dynamic_ps_enable_work);
80393 del_timer_sync(&local->dynamic_ps_timer);
80394
80395- local->wowlan = wowlan && local->open_count;
80396+ local->wowlan = wowlan && local_read(&local->open_count);
80397 if (local->wowlan) {
80398 int err = drv_suspend(local, wowlan);
80399 if (err < 0) {
80400@@ -143,7 +143,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
80401 drv_remove_interface(local, sdata);
80402
80403 /* stop hardware - this must stop RX */
80404- if (local->open_count)
80405+ if (local_read(&local->open_count))
80406 ieee80211_stop_device(local);
80407
80408 suspend:
80409diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
80410index 3313c11..bec9f17 100644
80411--- a/net/mac80211/rate.c
80412+++ b/net/mac80211/rate.c
80413@@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
80414
80415 ASSERT_RTNL();
80416
80417- if (local->open_count)
80418+ if (local_read(&local->open_count))
80419 return -EBUSY;
80420
80421 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
80422diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
80423index c97a065..ff61928 100644
80424--- a/net/mac80211/rc80211_pid_debugfs.c
80425+++ b/net/mac80211/rc80211_pid_debugfs.c
80426@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
80427
80428 spin_unlock_irqrestore(&events->lock, status);
80429
80430- if (copy_to_user(buf, pb, p))
80431+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
80432 return -EFAULT;
80433
80434 return p;
80435diff --git a/net/mac80211/util.c b/net/mac80211/util.c
80436index 0151ae3..26709d3 100644
80437--- a/net/mac80211/util.c
80438+++ b/net/mac80211/util.c
80439@@ -1332,7 +1332,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
80440 }
80441 #endif
80442 /* everything else happens only if HW was up & running */
80443- if (!local->open_count)
80444+ if (!local_read(&local->open_count))
80445 goto wake_up;
80446
80447 /*
80448diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
80449index fefa514..0755f23 100644
80450--- a/net/netfilter/Kconfig
80451+++ b/net/netfilter/Kconfig
80452@@ -929,6 +929,16 @@ config NETFILTER_XT_MATCH_ESP
80453
80454 To compile it as a module, choose M here. If unsure, say N.
80455
80456+config NETFILTER_XT_MATCH_GRADM
80457+ tristate '"gradm" match support'
80458+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
80459+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
80460+ ---help---
80461+ The gradm match allows to match on grsecurity RBAC being enabled.
80462+ It is useful when iptables rules are applied early on bootup to
80463+ prevent connections to the machine (except from a trusted host)
80464+ while the RBAC system is disabled.
80465+
80466 config NETFILTER_XT_MATCH_HASHLIMIT
80467 tristate '"hashlimit" match support'
80468 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
80469diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
80470index 3259697..54d5393 100644
80471--- a/net/netfilter/Makefile
80472+++ b/net/netfilter/Makefile
80473@@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
80474 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
80475 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
80476 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
80477+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
80478 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
80479 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
80480 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
80481diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
80482index 1548df9..98ad9b4 100644
80483--- a/net/netfilter/ipvs/ip_vs_conn.c
80484+++ b/net/netfilter/ipvs/ip_vs_conn.c
80485@@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
80486 /* Increase the refcnt counter of the dest */
80487 atomic_inc(&dest->refcnt);
80488
80489- conn_flags = atomic_read(&dest->conn_flags);
80490+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
80491 if (cp->protocol != IPPROTO_UDP)
80492 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
80493 flags = cp->flags;
80494@@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
80495 atomic_set(&cp->refcnt, 1);
80496
80497 atomic_set(&cp->n_control, 0);
80498- atomic_set(&cp->in_pkts, 0);
80499+ atomic_set_unchecked(&cp->in_pkts, 0);
80500
80501 atomic_inc(&ipvs->conn_count);
80502 if (flags & IP_VS_CONN_F_NO_CPORT)
80503@@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
80504
80505 /* Don't drop the entry if its number of incoming packets is not
80506 located in [0, 8] */
80507- i = atomic_read(&cp->in_pkts);
80508+ i = atomic_read_unchecked(&cp->in_pkts);
80509 if (i > 8 || i < 0) return 0;
80510
80511 if (!todrop_rate[i]) return 0;
80512diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
80513index 58918e2..4d177a9 100644
80514--- a/net/netfilter/ipvs/ip_vs_core.c
80515+++ b/net/netfilter/ipvs/ip_vs_core.c
80516@@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
80517 ret = cp->packet_xmit(skb, cp, pd->pp);
80518 /* do not touch skb anymore */
80519
80520- atomic_inc(&cp->in_pkts);
80521+ atomic_inc_unchecked(&cp->in_pkts);
80522 ip_vs_conn_put(cp);
80523 return ret;
80524 }
80525@@ -1681,7 +1681,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
80526 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
80527 pkts = sysctl_sync_threshold(ipvs);
80528 else
80529- pkts = atomic_add_return(1, &cp->in_pkts);
80530+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80531
80532 if (ipvs->sync_state & IP_VS_STATE_MASTER)
80533 ip_vs_sync_conn(net, cp, pkts);
80534diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
80535index c4ee437..a774a74 100644
80536--- a/net/netfilter/ipvs/ip_vs_ctl.c
80537+++ b/net/netfilter/ipvs/ip_vs_ctl.c
80538@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
80539 ip_vs_rs_hash(ipvs, dest);
80540 write_unlock_bh(&ipvs->rs_lock);
80541 }
80542- atomic_set(&dest->conn_flags, conn_flags);
80543+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
80544
80545 /* bind the service */
80546 if (!dest->svc) {
80547@@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80548 " %-7s %-6d %-10d %-10d\n",
80549 &dest->addr.in6,
80550 ntohs(dest->port),
80551- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80552+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80553 atomic_read(&dest->weight),
80554 atomic_read(&dest->activeconns),
80555 atomic_read(&dest->inactconns));
80556@@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
80557 "%-7s %-6d %-10d %-10d\n",
80558 ntohl(dest->addr.ip),
80559 ntohs(dest->port),
80560- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
80561+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
80562 atomic_read(&dest->weight),
80563 atomic_read(&dest->activeconns),
80564 atomic_read(&dest->inactconns));
80565@@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
80566
80567 entry.addr = dest->addr.ip;
80568 entry.port = dest->port;
80569- entry.conn_flags = atomic_read(&dest->conn_flags);
80570+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
80571 entry.weight = atomic_read(&dest->weight);
80572 entry.u_threshold = dest->u_threshold;
80573 entry.l_threshold = dest->l_threshold;
80574@@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
80575 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
80576 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
80577 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
80578- (atomic_read(&dest->conn_flags) &
80579+ (atomic_read_unchecked(&dest->conn_flags) &
80580 IP_VS_CONN_F_FWD_MASK)) ||
80581 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
80582 atomic_read(&dest->weight)) ||
80583diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
80584index effa10c..9058928 100644
80585--- a/net/netfilter/ipvs/ip_vs_sync.c
80586+++ b/net/netfilter/ipvs/ip_vs_sync.c
80587@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
80588 cp = cp->control;
80589 if (cp) {
80590 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80591- pkts = atomic_add_return(1, &cp->in_pkts);
80592+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80593 else
80594 pkts = sysctl_sync_threshold(ipvs);
80595 ip_vs_sync_conn(net, cp->control, pkts);
80596@@ -758,7 +758,7 @@ control:
80597 if (!cp)
80598 return;
80599 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
80600- pkts = atomic_add_return(1, &cp->in_pkts);
80601+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
80602 else
80603 pkts = sysctl_sync_threshold(ipvs);
80604 goto sloop;
80605@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
80606
80607 if (opt)
80608 memcpy(&cp->in_seq, opt, sizeof(*opt));
80609- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80610+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
80611 cp->state = state;
80612 cp->old_state = cp->state;
80613 /*
80614diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
80615index cc4c809..50f8fe5 100644
80616--- a/net/netfilter/ipvs/ip_vs_xmit.c
80617+++ b/net/netfilter/ipvs/ip_vs_xmit.c
80618@@ -1202,7 +1202,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
80619 else
80620 rc = NF_ACCEPT;
80621 /* do not touch skb anymore */
80622- atomic_inc(&cp->in_pkts);
80623+ atomic_inc_unchecked(&cp->in_pkts);
80624 goto out;
80625 }
80626
80627@@ -1323,7 +1323,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
80628 else
80629 rc = NF_ACCEPT;
80630 /* do not touch skb anymore */
80631- atomic_inc(&cp->in_pkts);
80632+ atomic_inc_unchecked(&cp->in_pkts);
80633 goto out;
80634 }
80635
80636diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
80637index 0f241be..2c9be6d 100644
80638--- a/net/netfilter/nf_conntrack_core.c
80639+++ b/net/netfilter/nf_conntrack_core.c
80640@@ -1532,6 +1532,10 @@ err_extend:
80641 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
80642 #define DYING_NULLS_VAL ((1<<30)+1)
80643
80644+#ifdef CONFIG_GRKERNSEC_HIDESYM
80645+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
80646+#endif
80647+
80648 static int nf_conntrack_init_net(struct net *net)
80649 {
80650 int ret;
80651@@ -1545,7 +1549,11 @@ static int nf_conntrack_init_net(struct net *net)
80652 goto err_stat;
80653 }
80654
80655+#ifdef CONFIG_GRKERNSEC_HIDESYM
80656+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
80657+#else
80658 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
80659+#endif
80660 if (!net->ct.slabname) {
80661 ret = -ENOMEM;
80662 goto err_slabname;
80663diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
80664index 9f199f2..719ad23 100644
80665--- a/net/netfilter/nfnetlink_log.c
80666+++ b/net/netfilter/nfnetlink_log.c
80667@@ -71,7 +71,7 @@ struct nfulnl_instance {
80668 };
80669
80670 static DEFINE_SPINLOCK(instances_lock);
80671-static atomic_t global_seq;
80672+static atomic_unchecked_t global_seq;
80673
80674 #define INSTANCE_BUCKETS 16
80675 static struct hlist_head instance_table[INSTANCE_BUCKETS];
80676@@ -527,7 +527,7 @@ __build_packet_message(struct nfulnl_instance *inst,
80677 /* global sequence number */
80678 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
80679 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
80680- htonl(atomic_inc_return(&global_seq))))
80681+ htonl(atomic_inc_return_unchecked(&global_seq))))
80682 goto nla_put_failure;
80683
80684 if (data_len) {
80685diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
80686new file mode 100644
80687index 0000000..c566332
80688--- /dev/null
80689+++ b/net/netfilter/xt_gradm.c
80690@@ -0,0 +1,51 @@
80691+/*
80692+ * gradm match for netfilter
80693